Skip to content

Commit 42ea7ad

Browse files
committed
Added a scale of 280 km/h used in Switzerland
1 parent 01614a1 commit 42ea7ad

File tree

3 files changed

+125
-4
lines changed

3 files changed

+125
-4
lines changed

Source/RunActivity/Viewer3D/RollingStock/MSTSLocomotiveViewer.cs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3256,6 +3256,7 @@ public class ThreeDimentionCabViewer : TrainCarViewer
32563256
//Dictionary<int, DigitalDisplay> DigitParts = null;
32573257
Dictionary<(CabViewControlType, int), ThreeDimCabDigit> DigitParts3D = null;
32583258
Dictionary<(CabViewControlType, int), ThreeDimCabDPI> DPIDisplays3D = null;
3259+
Dictionary<(CabViewControlType, int), ThreeDimCabScreen> ScreenDisplays3D = null;
32593260
AnimatedPart ExternalWipers = null; // setting to zero to prevent a warning. Probably this will be used later. TODO
32603261
protected MSTSLocomotive MSTSLocomotive { get { return (MSTSLocomotive)Car; } }
32613262
MSTSLocomotiveViewer LocoViewer;
@@ -3279,6 +3280,7 @@ public ThreeDimentionCabViewer(Viewer viewer, MSTSLocomotive car, MSTSLocomotive
32793280
DigitParts3D = new Dictionary<(CabViewControlType, int), ThreeDimCabDigit>();
32803281
Gauges = new Dictionary<(CabViewControlType, int), ThreeDimCabGaugeNative>();
32813282
DPIDisplays3D = new Dictionary<(CabViewControlType, int), ThreeDimCabDPI>();
3283+
ScreenDisplays3D = new Dictionary<(CabViewControlType, int), ThreeDimCabScreen>();
32823284
OnDemandAnimateParts = new Dictionary<(CabViewControlType, int), AnimatedPart>();
32833285

32843286
// Find the animated parts
@@ -3373,6 +3375,10 @@ public ThreeDimentionCabViewer(Viewer viewer, MSTSLocomotive car, MSTSLocomotive
33733375
{
33743376
DPIDisplays3D.Add(key, new ThreeDimCabDPI(viewer, iMatrix, parameter1, parameter2, this.TrainCarShape, locoViewer.ThreeDimentionCabRenderer.ControlMap[key]));
33753377
}
3378+
else if (style is CircularSpeedGaugeRenderer || style is DriverMachineInterfaceRenderer)
3379+
{
3380+
ScreenDisplays3D.Add(key, new ThreeDimCabScreen(viewer, iMatrix, TrainCarShape, locoViewer.ThreeDimentionCabRenderer.ControlMap[key]));
3381+
}
33763382
else
33773383
{
33783384
//if there is a part already, will insert this into it, otherwise, create a new
@@ -3525,6 +3531,24 @@ public override void PrepareFrame(RenderFrame frame, ElapsedTime elapsedTime)
35253531
p.Value.PrepareFrame(frame, elapsedTime);
35263532
}
35273533

3534+
foreach (var p in ScreenDisplays3D)
3535+
{
3536+
var dpdisplay = p.Value.CVFR.Control;
3537+
if (dpdisplay.Screens != null && dpdisplay.Screens[0] != "all")
3538+
{
3539+
foreach (var screen in dpdisplay.Screens)
3540+
{
3541+
if (LocoViewer.ThreeDimentionCabRenderer.ActiveScreen[dpdisplay.Display] == screen)
3542+
{
3543+
p.Value.PrepareFrame(frame, elapsedTime);
3544+
break;
3545+
}
3546+
}
3547+
continue;
3548+
}
3549+
p.Value.PrepareFrame(frame, elapsedTime);
3550+
}
3551+
35283552
foreach (var p in Gauges)
35293553
{
35303554
var gauge = p.Value.CVFR.Control;
@@ -3578,6 +3602,10 @@ internal override void Mark()
35783602
{
35793603
threeDimCabDPI.Mark();
35803604
}
3605+
foreach (var threeDimCabControl in ScreenDisplays3D.Values)
3606+
{
3607+
threeDimCabControl.Mark();
3608+
}
35813609
}
35823610
}
35833611

Source/RunActivity/Viewer3D/RollingStock/SubSystems/ETCS/DriverMachineInterface.cs

Lines changed: 77 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -754,7 +754,8 @@ public override void Draw(SpriteBatch spriteBatch, Point drawPosition)
754754

755755
public class CircularSpeedGaugeRenderer : CabViewDigitalRenderer
756756
{
757-
DriverMachineInterface DMI;
757+
public DriverMachineInterface DMI;
758+
758759
[CallOnThread("Loader")]
759760
public CircularSpeedGaugeRenderer(Viewer viewer, MSTSLocomotive locomotive, CVCDigital control, CabShader shader)
760761
: base(viewer, locomotive, control, shader)
@@ -864,4 +865,79 @@ public override void Draw(GraphicsDevice graphicsDevice)
864865
ControlView.SpriteBatch.Begin(SpriteSortMode.Deferred, BlendState.NonPremultiplied, null, DepthStencilState.Default, null, Shader);
865866
}
866867
}
868+
869+
public class ScreenMaterial : SceneryMaterial
870+
{
871+
CircularSpeedGaugeRenderer CircularSpeedGaugeRenderer;
872+
SpriteBatch SpriteBatch;
873+
874+
public ScreenMaterial(Viewer viewer, string key, CircularSpeedGaugeRenderer circularSpeedGaugeRenderer)
875+
: base(viewer, key, SceneryMaterialOptions.ShaderFullBright, 0)
876+
{
877+
CircularSpeedGaugeRenderer = circularSpeedGaugeRenderer;
878+
Texture = new RenderTarget2D(viewer.GraphicsDevice,
879+
CircularSpeedGaugeRenderer.DMI.Width, CircularSpeedGaugeRenderer.DMI.Height, false, SurfaceFormat.Color, DepthFormat.None);
880+
SpriteBatch = new SpriteBatch(viewer.GraphicsDevice);
881+
}
882+
883+
public override void Render(GraphicsDevice graphicsDevice, IEnumerable<RenderItem> renderItems, ref Matrix XNAViewMatrix, ref Matrix XNAProjectionMatrix)
884+
{
885+
var originalRenderTargets = graphicsDevice.GetRenderTargets();
886+
graphicsDevice.SetRenderTarget(Texture as RenderTarget2D);
887+
SpriteBatch.Begin(); // Dummy Begin(), gets closed immediately
888+
CircularSpeedGaugeRenderer.Draw(graphicsDevice);
889+
SpriteBatch.End();
890+
graphicsDevice.SetRenderTargets(originalRenderTargets);
891+
892+
base.Render(graphicsDevice, renderItems, ref XNAViewMatrix, ref XNAProjectionMatrix);
893+
}
894+
}
895+
896+
public class ThreeDimCabScreen
897+
{
898+
PoseableShape TrainCarShape;
899+
Matrix XNAMatrix;
900+
Viewer Viewer;
901+
ShapePrimitive ShapePrimitive;
902+
public CircularSpeedGaugeRenderer CVFR;
903+
ScreenMaterial Material;
904+
public ThreeDimCabScreen(Viewer viewer, int iMatrix, PoseableShape trainCarShape, CabViewControlRenderer c)
905+
{
906+
CVFR = (CircularSpeedGaugeRenderer)c;
907+
Viewer = viewer;
908+
TrainCarShape = trainCarShape;
909+
XNAMatrix = TrainCarShape.SharedShape.Matrices[iMatrix];
910+
Material = new ScreenMaterial(viewer, "ETCS_SCREEN", CVFR);
911+
912+
var vertices = new[]
913+
{
914+
new VertexPositionNormalTexture(new Vector3(0, 0, 0), new Vector3(0, 0, -1), new Vector2(0, 0)),
915+
new VertexPositionNormalTexture(new Vector3(0, 0, 1), new Vector3(0, 0, -1), new Vector2(0, 1)),
916+
new VertexPositionNormalTexture(new Vector3(1, 0, 0), new Vector3(0, 0, -1), new Vector2(1, 0)),
917+
new VertexPositionNormalTexture(new Vector3(1, 0, 1), new Vector3(0, 0, -1), new Vector2(1, 1)),
918+
};
919+
var indices = new short[] { 0, 1, 2, 2, 1, 3 };
920+
var indexBuffer = new IndexBuffer(viewer.GraphicsDevice, IndexElementSize.SixteenBits, indices.Length, BufferUsage.WriteOnly);
921+
indexBuffer.SetData(indices);
922+
ShapePrimitive = new ShapePrimitive(Material, new SharedShape.VertexBufferSet(vertices, viewer.GraphicsDevice), indexBuffer, 2, new[] { -1 }, 0);
923+
}
924+
925+
public void PrepareFrame(RenderFrame frame, ElapsedTime elapsedTime)
926+
{
927+
if (!CVFR.IsPowered && CVFR.Control.HideIfDisabled)
928+
return;
929+
930+
Matrix mx = TrainCarShape.Location.XNAMatrix;
931+
mx.M41 += (TrainCarShape.Location.TileX - Viewer.Camera.TileX) * 2048;
932+
mx.M43 += (-TrainCarShape.Location.TileZ + Viewer.Camera.TileZ) * 2048;
933+
Matrix m = XNAMatrix * mx;
934+
935+
frame.AddPrimitive(ShapePrimitive.Material, ShapePrimitive, RenderPrimitiveGroup.Interior, ref m, ShapeFlags.None);
936+
}
937+
938+
internal void Mark()
939+
{
940+
ShapePrimitive.Mark();
941+
}
942+
}
867943
}

Source/RunActivity/Viewer3D/RollingStock/SubSystems/ETCS/SpeedDistanceMonitoring.cs

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ public class CircularSpeedGauge : DMIArea
5353
readonly Point ReleaseSpeedPosition = new Point(26 - 6, 274 - 8);
5454
readonly int[] UnitCenterPosition = new int[] { 140, 204 };
5555
// 240 and 260 are non-standard scales by ETA, but national railways often use one of these instead of 250
56-
readonly int[] StandardScalesKMpH = new int[] { 140, 180, 240, 250, 260, 400 };
56+
readonly int[] StandardScalesKMpH = new int[] { 140, 180, 240, 250, 260, 280, 400 };
5757
readonly int[] StandardScalesMpH = new int[] { 87, 111, 155, 248 };
5858

5959
const string UnitMetricString = "km/h";
@@ -222,21 +222,38 @@ public void SetRange(int maxSpeed)
222222
y -= textHeight / 2f * (1f - (float)Math.Cos(angle));
223223
// Cheating for better outlook:
224224
if (UnitMetric && 240 <= MaxSpeed && MaxSpeed <= 260)
225+
{
225226
switch (speed)
226227
{
227228
case 100: x -= textWidth / 4f; break;
228229
case 120: x -= textWidth / 10f; y -= textHeight / 6f; break;
229230
case 140: x += textWidth / 6f; y -= textHeight / 6f; break;
230231
}
231-
232+
}
232233
DialSpeeds.Add(new TextPrimitive(new Point((int)x, (int)y), Color.White, speed.ToString(), FontDialSpeeds));
233234
}
234235
}
235236
else
237+
{
236238
DialLineCoords.Add(new Vector4(x, y, LineHalf, angle + MathHelper.PiOver2));
239+
}
240+
241+
var longLineEach = 2;
242+
if (MaxSpeed == 280 && UnitMetric)
243+
{
244+
longLineEach = 4;
245+
}
246+
if (MaxSpeed > 300 && UnitMetric)
247+
{
248+
longLineEach = 5;
249+
}
250+
if (MaxSpeed > 200 && !UnitMetric)
251+
{
252+
longLineEach = (speed + 5 > MidSpeed) ? 4 : 2;
253+
}
237254

238255
longLine++;
239-
longLine %= MaxSpeed != StandardScales[StandardScales.Length - 1] ? 2 : UnitMetric ? 5 : (speed + 5 > MidSpeed) ? 4 : 2;
256+
longLine %= longLineEach;
240257
}
241258
else if (UnitMetric && (MaxSpeed == 240 || MaxSpeed == 260))
242259
{

0 commit comments

Comments
 (0)