Skip to content

Commit fca9546

Browse files
authored
Merge pull request #65 from Csantucci/Animate-bell
Animate bell Blueprint https://blueprints.launchpad.net/or/+spec/bell-animation Trello box https://trello.com/c/48ya6M3Y/423-bell-animation
2 parents 3dbd52d + f6f2e97 commit fca9546

File tree

7 files changed

+20
-8
lines changed

7 files changed

+20
-8
lines changed

Source/Orts.Formats.Msts/ShapeDescriptorFile.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ public SDShape(STFReader stf)
6464
ESD_Bounding_Box = null;
6565
}),
6666
new STFReader.TokenProcessor("esd_ortssoundfilename", ()=>{ ESD_SoundFileName = stf.ReadStringBlock(null); }),
67+
new STFReader.TokenProcessor("esd_ortsbellanimationfps", ()=>{ ESD_BellAnimationFPS = stf.ReadFloatBlock(STFReader.UNITS.Frequency, null); }),
6768
});
6869
// TODO - some objects have no bounding box - ie JP2BillboardTree1.sd
6970
//if (ESD_Bounding_Box == null) throw new STFException(stf, "Missing ESD_Bound_Box statement");
@@ -75,6 +76,7 @@ public SDShape(STFReader stf)
7576
public bool ESD_Snapable;
7677
public bool ESD_SubObj;
7778
public string ESD_SoundFileName = "";
79+
public float ESD_BellAnimationFPS = 8;
7880
}
7981

8082
public class ESD_Bounding_Box

Source/Orts.Simulation/MultiPlayer/Message.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2093,8 +2093,9 @@ public override void HandleMsg()
20932093
}
20942094
else if (EventName == "BELL")
20952095
{
2096-
if (t.LeadLocomotive != null)
2096+
if (t.LeadLocomotive != null && t.LeadLocomotive is MSTSLocomotive)
20972097
{
2098+
(t.LeadLocomotive as MSTSLocomotive).Bell = (EventState == 0 ? false : true);
20982099
t.LeadLocomotive.SignalEvent(EventState == 0 ? Event.BellOff : Event.BellOn);
20992100
MPManager.BroadCast(this.ToString()); //if the server, will broadcast
21002101
}

Source/Orts.Simulation/Simulation/RollingStocks/MSTSLocomotive.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1895,12 +1895,12 @@ protected virtual void UpdateHornAndBell(float elapsedClockSeconds)
18951895
if (Bell && !PreviousBell)
18961896
{
18971897
SignalEvent(Event.BellOn);
1898-
if (MPManager.IsMultiPlayer()) MPManager.Notify((new MSGEvent(MPManager.GetUserName(), "BELL", 1)).ToString());
1898+
if (Train.TrainType != Train.TRAINTYPE.REMOTE && MPManager.IsMultiPlayer()) MPManager.Notify((new MSGEvent(MPManager.GetUserName(), "BELL", 1)).ToString());
18991899
}
19001900
else if (!Bell && PreviousBell)
19011901
{
19021902
SignalEvent(Event.BellOff);
1903-
if (MPManager.IsMultiPlayer()) MPManager.Notify((new MSGEvent(MPManager.GetUserName(), "BELL", 0)).ToString());
1903+
if (Train.TrainType != Train.TRAINTYPE.REMOTE && MPManager.IsMultiPlayer()) MPManager.Notify((new MSGEvent(MPManager.GetUserName(), "BELL", 0)).ToString());
19041904
}
19051905

19061906
PreviousHorn = Horn;

Source/RunActivity/Viewer3D/AnimatedPart.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -156,14 +156,14 @@ public void UpdateLoop(float change)
156156
/// <summary>
157157
/// Updates an animated part that loops only when enabled (e.g. wipers).
158158
/// </summary>
159-
public void UpdateLoop(bool running, ElapsedTime elapsedTime)
159+
public void UpdateLoop(bool running, ElapsedTime elapsedTime, float frameRateMultiplier = 1.5f)
160160
{
161161
if (PoseableShape.SharedShape.Animations == null || PoseableShape.SharedShape.Animations.Count == 0 || FrameCount == 0)
162162
return;
163163

164-
// The speed of cycling is set at 1.5 frames of animation per second at 30 FPS.
165-
var frameRate = PoseableShape.SharedShape.Animations[0].FrameRate * 1.5f / 30f;
166-
if (running || (AnimationKey > 0 && AnimationKey + elapsedTime.ClockSeconds < FrameCount))
164+
// The speed of cycling is as default 1.5 frames of animation per second at 30 FPS.
165+
var frameRate = PoseableShape.SharedShape.Animations[0].FrameRate * frameRateMultiplier / 30f;
166+
if (running || (AnimationKey > 0 && AnimationKey + elapsedTime.ClockSeconds * frameRate < FrameCount))
167167
SetFrameWrap(AnimationKey + elapsedTime.ClockSeconds * frameRate);
168168
else
169169
SetFrame(0);

Source/RunActivity/Viewer3D/RollingStock/MSTSLocomotiveViewer.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -266,8 +266,9 @@ public override void PrepareFrame(RenderFrame frame, ElapsedTime elapsedTime)
266266
return;
267267
}
268268

269-
// Wiper animation
269+
// Wipers and bell animation
270270
Wipers.UpdateLoop(Locomotive.Wiper, elapsedTime);
271+
Bell.UpdateLoop(Locomotive.Bell, elapsedTime, TrainCarShape.SharedShape.BellAnimationFPS);
271272

272273
// Draw 2D CAB View - by GeorgeS
273274
if (Viewer.Camera.AttachedCar == this.MSTSWagon &&

Source/RunActivity/Viewer3D/RollingStock/MSTSWagonViewer.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ public class MSTSWagonViewer : TrainCarViewer
6060
AnimatedPart RightDoor;
6161
AnimatedPart Mirrors;
6262
protected AnimatedPart Wipers;
63+
protected AnimatedPart Bell;
6364
AnimatedPart UnloadingParts;
6465

6566
public Dictionary<string, List<ParticleEmitterViewer>> ParticleDrawers = new Dictionary<string, List<ParticleEmitterViewer>>();
@@ -182,6 +183,7 @@ from data in effect.Value
182183
Mirrors = new AnimatedPart(TrainCarShape);
183184
Wipers = new AnimatedPart(TrainCarShape);
184185
UnloadingParts = new AnimatedPart(TrainCarShape);
186+
Bell = new AnimatedPart(TrainCarShape);
185187

186188
if (car.FreightAnimations != null)
187189
FreightAnimations = new FreightAnimationsViewer(viewer, car, wagonFolderSlash);
@@ -407,6 +409,10 @@ void MatchMatrixToPart(MSTSWagon car, int matrix, int bogieMatrix)
407409
else Pantograph2.AddMatrix(matrix);
408410
}
409411
}
412+
else if (matrixName.StartsWith("ORTSBELL")) // wipers
413+
{
414+
Bell.AddMatrix(matrix);
415+
}
410416
else
411417
{
412418
if (matrixAnimated && matrix != 0)

Source/RunActivity/Viewer3D/Shapes.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1386,6 +1386,7 @@ public class SharedShape
13861386
public int RootSubObjectIndex = 0;
13871387
//public bool negativeBogie = false;
13881388
public string SoundFileName = "";
1389+
public float BellAnimationFPS = 8;
13891390

13901391

13911392
readonly Viewer Viewer;
@@ -1449,6 +1450,7 @@ void LoadContent()
14491450
if ((textureFlags & Helpers.TextureFlags.Night) != 0 && FilePath.Contains("\\trainset\\"))
14501451
textureFlags |= Helpers.TextureFlags.Underground;
14511452
SoundFileName = sdFile.shape.ESD_SoundFileName;
1453+
BellAnimationFPS = sdFile.shape.ESD_BellAnimationFPS;
14521454
}
14531455

14541456
var matrixCount = sFile.shape.matrices.Count;

0 commit comments

Comments
 (0)