Skip to content

Commit 7f9047f

Browse files
committed
Separate train car animations from PrepareFrame
1 parent 6858f87 commit 7f9047f

File tree

7 files changed

+185
-155
lines changed

7 files changed

+185
-155
lines changed

Source/RunActivity/Viewer3D/Cameras.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -893,6 +893,11 @@ public virtual void LastCar()
893893
SetCameraCar(trainCars.Last());
894894
}
895895

896+
public bool RefreshCarViewer()
897+
{
898+
return Viewer.World.Trains.Cars.TryGetValue(attachedCar, out attachedCarViewer);
899+
}
900+
896901
public void UpdateLocation(WorldPosition worldPosition)
897902
{
898903
if (worldPosition != null)

Source/RunActivity/Viewer3D/RollingStock/MSTSElectricLocomotiveViewer.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,6 @@ public override void InitializeUserInputCommands()
110110
/// </summary>
111111
public override void PrepareFrame(RenderFrame frame, ElapsedTime elapsedTime)
112112
{
113-
114113
base.PrepareFrame(frame, elapsedTime);
115114
}
116115
}

Source/RunActivity/Viewer3D/RollingStock/MSTSLocomotiveViewer.cs

Lines changed: 24 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -337,37 +337,36 @@ public override void HandleUserInput(ElapsedTime elapsedTime)
337337
}
338338

339339
/// <summary>
340-
/// We are about to display a video frame. Calculate positions for
341-
/// animated objects, and add their primitives to the RenderFrame list.
340+
/// We are about to display a video frame add primitives to the RenderFrame list.
342341
/// </summary>
343342
public override void PrepareFrame(RenderFrame frame, ElapsedTime elapsedTime)
344343
{
345-
if (Viewer.Camera.AttachedCar == this.MSTSWagon && Viewer.Camera.Style == Camera.Styles.ThreeDimCab)
344+
if (ThreeDimentionCabViewer != null && Viewer.Camera.AttachedCar == this.MSTSWagon && Viewer.Camera.Style == Camera.Styles.ThreeDimCab)
345+
{
346+
ThreeDimentionCabViewer.PrepareFrame(frame, elapsedTime);
347+
}
348+
349+
// Draw 2D CAB View - by GeorgeS
350+
if (_CabRenderer != null && Viewer.Camera.AttachedCar == this.MSTSWagon && Viewer.Camera.Style == Camera.Styles.Cab)
346351
{
347-
if (ThreeDimentionCabViewer != null)
348-
ThreeDimentionCabViewer.PrepareFrame(frame, elapsedTime);
352+
_CabRenderer.PrepareFrame(frame, elapsedTime);
349353
}
350354

355+
base.PrepareFrame(frame, elapsedTime);
356+
}
357+
358+
/// <summary>
359+
/// Calculate positions for animated objects. Call before PrepareFrame.
360+
/// </summary>
361+
public override void UpdateAnimations(ElapsedTime elapsedTime)
362+
{
351363
// Wipers and bell animation
352364
Wipers.UpdateLoop(Locomotive.Wiper, elapsedTime);
353365
Bell.UpdateLoop(Locomotive.Bell, elapsedTime, TrainCarShape.SharedShape.CustomAnimationFPS);
354366
Item1Continuous.UpdateLoop(Locomotive.GenericItem1, elapsedTime, TrainCarShape.SharedShape.CustomAnimationFPS);
355367
Item2Continuous.UpdateLoop(Locomotive.GenericItem2, elapsedTime, TrainCarShape.SharedShape.CustomAnimationFPS);
356368

357-
// Draw 2D CAB View - by GeorgeS
358-
if (Viewer.Camera.AttachedCar == this.MSTSWagon &&
359-
Viewer.Camera.Style == Camera.Styles.Cab)
360-
{
361-
if (_CabRenderer != null)
362-
{
363-
// Locomotive's TrainCarShape.ResultMatrices won't be updated automatically, force manual update
364-
TrainCarShape.UpdateResultMatrices();
365-
366-
_CabRenderer.PrepareFrame(frame, elapsedTime);
367-
}
368-
}
369-
370-
base.PrepareFrame(frame, elapsedTime);
369+
base.UpdateAnimations(elapsedTime);
371370
}
372371

373372
internal override void LoadForPlayer()
@@ -3758,17 +3757,19 @@ public override void PrepareFrame(RenderFrame frame, ElapsedTime elapsedTime)
37583757
TrainCarShape.Location.TileX = Car.WorldPosition.TileX;
37593758
TrainCarShape.Location.TileZ = Car.WorldPosition.TileZ;
37603759

3761-
// Locomotive's TrainCarShape.ResultMatrices won't be updated automatically, force manual update
3762-
LocoViewer.TrainCarShape.UpdateResultMatrices();
3763-
37643760
TrainCarShape.XNAMatrices[0].Translation = Car.CabViewpoints[viewPoint].ShapeOffset;
3765-
if (Car.CabViewpoints[viewPoint].ShapeIndex < LocoViewer.TrainCarShape.ResultMatrices.Length)
3761+
if (Car.CabViewpoints[viewPoint].ShapeIndex >= 0 && Car.CabViewpoints[viewPoint].ShapeIndex < LocoViewer.TrainCarShape.ResultMatrices.Length)
37663762
TrainCarShape.Location.XNAMatrix = LocoViewer.TrainCarShape.ResultMatrices[Car.CabViewpoints[viewPoint].ShapeIndex] * TrainCarShape.Location.XNAMatrix;
37673763

37683764
TrainCarShape.ConditionallyPrepareFrame(frame, elapsedTime, MatrixVisible);
37693765
}
37703766
}
37713767

3768+
public override void UpdateAnimations(ElapsedTime elapsedTime)
3769+
{
3770+
// 3D Cabs don't handle animations in the same way that other train car shapes do
3771+
}
3772+
37723773
internal void PrepareFrameForWindow(int windowIndex, AnimatedPartMultiState anim, ElapsedTime elapsedTime)
37733774
{
37743775
if (Locomotive.WindowStates[windowIndex] == MSTSWagon.WindowState.Closed) anim.SetState(false);

0 commit comments

Comments
 (0)