Skip to content

Commit 1a99f43

Browse files
committed
1 parent 0ab7ebf commit 1a99f43

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

Source/Orts.Simulation/Simulation/Turntables.cs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -352,6 +352,7 @@ public class Turntable : MovingTable
352352
public List<float> Angles = new List<float>();
353353
public float StartingY = 0; // starting yaw angle
354354
public float ThresholdForTarget; // Threshold to check if we can now go to the target
355+
public float MaxAngle = -1; // max angle extension for partial turntables (in radians)
355356
// Dynamic data
356357
public bool Clockwise; // clockwise motion on
357358
public bool Counterclockwise; // counterclockwise motion on
@@ -392,6 +393,7 @@ public Turntable(STFReader stf, Simulator simulator)
392393
TrackShapeIndex = stf.ReadIntBlock(-1);
393394
InitializeAnglesAndTrackNodes();
394395
}),
396+
new STFReader.TokenProcessor("maxangle", ()=>{ MaxAngle = MathHelper.ToRadians(stf.ReadFloatBlock(STFReader.UNITS.None , null));}),
395397
});
396398
}
397399

@@ -636,6 +638,18 @@ public override void StartContinuous(bool isClockwise)
636638

637639
public void GeneralStartContinuous(bool isClockwise)
638640
{
641+
if (MaxAngle > 0)
642+
{
643+
var positiveYAngle = YAngle >= 0 ? YAngle : YAngle + 2 * (float)Math.PI;
644+
if (!isClockwise && positiveYAngle < 0.2 || isClockwise && positiveYAngle <= 2 * (float)Math.PI - MaxAngle && positiveYAngle > 0.2)
645+
{
646+
Clockwise = false;
647+
Counterclockwise = false;
648+
Continuous = false;
649+
if (SendNotifications) Simulator.Confirmer.Warning(Simulator.Catalog.GetStringFmt("Turntable is at its bound, can't rotate"));
650+
return;
651+
}
652+
}
639653
if (TrainsOnMovingTable.Count > 1 || (TrainsOnMovingTable.Count == 1 && TrainsOnMovingTable[0].FrontOnBoard ^ TrainsOnMovingTable[0].BackOnBoard))
640654
{
641655
Clockwise = false;

Source/RunActivity/Viewer3D/Shapes.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1594,6 +1594,17 @@ public override void PrepareFrame(RenderFrame frame, ElapsedTime elapsedTime)
15941594
AnimationKey = nextKey % animation.FrameCount;
15951595
if (AnimationKey < 0)
15961596
AnimationKey += animation.FrameCount;
1597+
// used if Turntable cannot turn 360 degrees
1598+
if (Turntable.MaxAngle > 0 && AnimationKey != 0)
1599+
{
1600+
if (AnimationKey < -SharedShape.Animations[0].FrameCount * Turntable.MaxAngle / (2 * Math.PI) + animation.FrameCount)
1601+
{
1602+
if (AnimationKey > 20)
1603+
AnimationKey = -SharedShape.Animations[0].FrameCount * Turntable.MaxAngle / (float)(2 * Math.PI) + animation.FrameCount;
1604+
else
1605+
AnimationKey = 0;
1606+
}
1607+
}
15971608
Turntable.YAngle = MathHelper.WrapAngle(nextKey / animation.FrameCount * 2 * (float)Math.PI);
15981609

15991610
if ((Turntable.Clockwise || Turntable.Counterclockwise || Turntable.AutoClockwise || Turntable.AutoCounterclockwise) && !Rotating)

0 commit comments

Comments
 (0)