Skip to content

Commit 92191ed

Browse files
committed
Allowing for more visibility options
1 parent 27c2c8f commit 92191ed

File tree

2 files changed

+65
-29
lines changed

2 files changed

+65
-29
lines changed

Source/Orts.Simulation/Simulation/RollingStocks/SubSystems/FreightAnimations.cs

Lines changed: 56 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -302,13 +302,21 @@ public enum Type
302302
{
303303
DEFAULT
304304
}
305+
// index of visibility flag vector
306+
public enum VisibleFrom
307+
{
308+
Outside,
309+
Cab2D,
310+
Cab3D
311+
}
305312
public Type SubType;
306313
public float XOffset = 0;
307314
public float YOffset = 0;
308315
public float ZOffset = 0;
309316
public float FreightWeight = 0;
310317
public bool Flipped = false;
311318
public bool Cab3DFreightAnim = false;
319+
public bool[] Visibility = { true, false, false };
312320

313321
// additions to manage consequences of variable weight on friction and brake forces
314322
public float FullStaticORTSDavis_A = -9999;
@@ -325,35 +333,55 @@ public FreightAnimationStatic(STFReader stf)
325333
stf.MustMatch("(");
326334
stf.ParseBlock(new STFReader.TokenProcessor[] {
327335
new STFReader.TokenProcessor("subtype", ()=>
336+
{
337+
var typeString = stf.ReadStringBlock(null);
338+
switch (typeString)
339+
{
340+
default:
341+
SubType = FreightAnimationStatic.Type.DEFAULT;
342+
break;
343+
}
344+
}),
345+
new STFReader.TokenProcessor("shape", ()=>{ ShapeFileName = stf.ReadStringBlock(null); }),
346+
new STFReader.TokenProcessor("freightweight", ()=>{ FreightWeight = stf.ReadFloatBlock(STFReader.UNITS.Mass, 0); }),
347+
new STFReader.TokenProcessor("offset", ()=>{
348+
stf.MustMatch("(");
349+
XOffset = stf.ReadFloat(STFReader.UNITS.Distance, 0);
350+
YOffset = stf.ReadFloat(STFReader.UNITS.Distance, 0);
351+
ZOffset = stf.ReadFloat(STFReader.UNITS.Distance, 0);
352+
stf.MustMatch(")");
353+
}),
354+
new STFReader.TokenProcessor("flip", ()=>{ Flipped = stf.ReadBoolBlock(true);}),
355+
new STFReader.TokenProcessor("visibility", ()=>{
356+
for (int index = 0; index < 3; index++)
357+
Visibility[index] = false;
358+
foreach (var visibilityPlace in stf.ReadStringBlock("").ToLower().Replace(" ", "").Split(','))
328359
{
329-
var typeString = stf.ReadStringBlock(null);
330-
switch (typeString)
331-
{
360+
switch (visibilityPlace)
361+
{
362+
case "outside":
363+
Visibility[(int)VisibleFrom.Outside] = true;
364+
break;
365+
case "cab2d":
366+
Visibility[(int)VisibleFrom.Cab2D] = true;
367+
break;
368+
case "cab3d":
369+
Visibility[(int)VisibleFrom.Cab3D] = true;
370+
break;
332371
default:
333-
SubType = FreightAnimationStatic.Type.DEFAULT;
334372
break;
335-
}
336-
}),
337-
new STFReader.TokenProcessor("shape", ()=>{ ShapeFileName = stf.ReadStringBlock(null); }),
338-
new STFReader.TokenProcessor("freightweight", ()=>{ FreightWeight = stf.ReadFloatBlock(STFReader.UNITS.Mass, 0); }),
339-
new STFReader.TokenProcessor("offset", ()=>{
340-
stf.MustMatch("(");
341-
XOffset = stf.ReadFloat(STFReader.UNITS.Distance, 0);
342-
YOffset = stf.ReadFloat(STFReader.UNITS.Distance, 0);
343-
ZOffset = stf.ReadFloat(STFReader.UNITS.Distance, 0);
344-
stf.MustMatch(")");
345-
}),
346-
new STFReader.TokenProcessor("flip", ()=>{ Flipped = stf.ReadBoolBlock(true);}),
347-
new STFReader.TokenProcessor("cab3dfreightanim", ()=>{ Cab3DFreightAnim = stf.ReadBoolBlock(true);}),
348-
// additions to manage consequences of variable weight on friction and brake forces
349-
new STFReader.TokenProcessor("fullortsdavis_a", ()=>{ FullStaticORTSDavis_A = stf.ReadFloatBlock(STFReader.UNITS.Force, -1); }),
350-
new STFReader.TokenProcessor("fullortsdavis_b", ()=>{ FullStaticORTSDavis_B = stf.ReadFloatBlock(STFReader.UNITS.Resistance, -1); }),
351-
new STFReader.TokenProcessor("fullortsdavis_c", ()=>{ FullStaticORTSDavis_C = stf.ReadFloatBlock(STFReader.UNITS.ResistanceDavisC, -1); }),
352-
new STFReader.TokenProcessor("fullortswagonfrontalarea", ()=>{ FullStaticORTSWagonFrontalAreaM2 = stf.ReadFloatBlock(STFReader.UNITS.AreaDefaultFT2, -1); }),
353-
new STFReader.TokenProcessor("fullortsdavisdragconstant", ()=>{ FullStaticORTSDavisDragConstant = stf.ReadFloatBlock(STFReader.UNITS.Any, -1); }),
354-
new STFReader.TokenProcessor("fullmaxbrakeforce", ()=>{ FullStaticMaxBrakeForceN = stf.ReadFloatBlock(STFReader.UNITS.Force, -1); }),
355-
new STFReader.TokenProcessor("fullmaxhandbrakeforce", ()=>{ FullStaticMaxHandbrakeForceN = stf.ReadFloatBlock(STFReader.UNITS.Force, -1); }),
356-
new STFReader.TokenProcessor("fullcentreofgravity_y", ()=>{ FullStaticCentreOfGravityM_Y = stf.ReadFloatBlock(STFReader.UNITS.Distance, -1); })
373+
}
374+
}
375+
}),
376+
// additions to manage consequences of variable weight on friction and brake forces
377+
new STFReader.TokenProcessor("fullortsdavis_a", ()=>{ FullStaticORTSDavis_A = stf.ReadFloatBlock(STFReader.UNITS.Force, -1); }),
378+
new STFReader.TokenProcessor("fullortsdavis_b", ()=>{ FullStaticORTSDavis_B = stf.ReadFloatBlock(STFReader.UNITS.Resistance, -1); }),
379+
new STFReader.TokenProcessor("fullortsdavis_c", ()=>{ FullStaticORTSDavis_C = stf.ReadFloatBlock(STFReader.UNITS.ResistanceDavisC, -1); }),
380+
new STFReader.TokenProcessor("fullortswagonfrontalarea", ()=>{ FullStaticORTSWagonFrontalAreaM2 = stf.ReadFloatBlock(STFReader.UNITS.AreaDefaultFT2, -1); }),
381+
new STFReader.TokenProcessor("fullortsdavisdragconstant", ()=>{ FullStaticORTSDavisDragConstant = stf.ReadFloatBlock(STFReader.UNITS.Any, -1); }),
382+
new STFReader.TokenProcessor("fullmaxbrakeforce", ()=>{ FullStaticMaxBrakeForceN = stf.ReadFloatBlock(STFReader.UNITS.Force, -1); }),
383+
new STFReader.TokenProcessor("fullmaxhandbrakeforce", ()=>{ FullStaticMaxHandbrakeForceN = stf.ReadFloatBlock(STFReader.UNITS.Force, -1); }),
384+
new STFReader.TokenProcessor("fullcentreofgravity_y", ()=>{ FullStaticCentreOfGravityM_Y = stf.ReadFloatBlock(STFReader.UNITS.Distance, -1); })
357385
});
358386
}
359387

@@ -366,7 +394,8 @@ public FreightAnimationStatic(FreightAnimationStatic freightAnimStatic)
366394
YOffset = freightAnimStatic.YOffset;
367395
ZOffset = freightAnimStatic.ZOffset;
368396
Flipped = freightAnimStatic.Flipped;
369-
Cab3DFreightAnim = freightAnimStatic.Cab3DFreightAnim;
397+
for (int index = 0; index < 3; index++)
398+
Visibility[index] = freightAnimStatic.Visibility[index];
370399
FreightWeight = freightAnimStatic.FreightWeight;
371400

372401
// additions to manage consequences of variable weight on friction and brake forces

Source/RunActivity/Viewer3D/RollingStock/MSTSWagonViewer.cs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -656,8 +656,15 @@ private void UpdateAnimation(RenderFrame frame, ElapsedTime elapsedTime)
656656
foreach (var freightAnim in FreightAnimations.Animations)
657657
{
658658
if (freightAnim.Animation is FreightAnimationStatic)
659-
if ((freightAnim.Animation as FreightAnimationStatic).Cab3DFreightAnim ^
660-
(Viewer.Camera.AttachedCar == this.MSTSWagon && Viewer.Camera.Style == Camera.Styles.ThreeDimCab)) continue;
659+
{
660+
var animation = freightAnim.Animation as FreightAnimationStatic;
661+
if (!((animation.Visibility[(int)FreightAnimationStatic.VisibleFrom.Cab3D] &&
662+
Viewer.Camera.AttachedCar == this.MSTSWagon && Viewer.Camera.Style == Camera.Styles.ThreeDimCab) ||
663+
(animation.Visibility[(int)FreightAnimationStatic.VisibleFrom.Cab2D] &&
664+
Viewer.Camera.AttachedCar == this.MSTSWagon && Viewer.Camera.Style == Camera.Styles.Cab) ||
665+
(animation.Visibility[(int)FreightAnimationStatic.VisibleFrom.Outside] && (Viewer.Camera.AttachedCar != this.MSTSWagon ||
666+
(Viewer.Camera.Style != Camera.Styles.ThreeDimCab && Viewer.Camera.Style != Camera.Styles.Cab))))) continue;
667+
}
661668
if (freightAnim.FreightShape != null && !((freightAnim.Animation is FreightAnimationContinuous) && (freightAnim.Animation as FreightAnimationContinuous).LoadPerCent == 0))
662669
{
663670
freightAnim.FreightShape.Location.XNAMatrix = Car.WorldPosition.XNAMatrix;

0 commit comments

Comments
 (0)