Skip to content

Commit 25f5e06

Browse files
committed
Update frame rate so that it is always visible and not just when HuD is switched on.
1 parent b19b5a1 commit 25f5e06

File tree

6 files changed

+28
-20
lines changed

6 files changed

+28
-20
lines changed

Source/Orts.Simulation/Simulation/Physics/Train.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -195,8 +195,6 @@ public int ActivityDurationS
195195

196196
public bool HasControlCarWithGear = false;
197197

198-
public float ScreenFrameRate;
199-
200198
//To investigate coupler breaks on route
201199
private bool numOfCouplerBreaksNoted = false;
202200
public static int NumOfCouplerBreaks = 0;//Debrief Eval

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2807,7 +2807,6 @@ public virtual void AdvancedAdhesion(float elapsedClockSeconds)
28072807
axle.CurrentCurveRadiusM = CurrentCurveRadiusM;
28082808
axle.BogieRigidWheelBaseM = RigidWheelBaseM;
28092809
axle.CurtiusKnifflerZeroSpeed = ZeroSpeedAdhesionBase;
2810-
axle.ScreenFrameRate = Train.ScreenFrameRate;
28112810
}
28122811

28132812
LocomotiveAxles.Update(elapsedClockSeconds);

Source/Orts.Simulation/Simulation/RollingStocks/SubSystems/PowerTransmissions/Axle.cs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -519,11 +519,6 @@ public float TransmissionEfficiency
519519
/// </summary>
520520
public float CurtiusKnifflerZeroSpeed;
521521

522-
/// <summary>
523-
/// Simulator FPS
524-
/// </summary>
525-
public float ScreenFrameRate;
526-
527522
/// <summary>
528523
/// Wheel adhesion as calculated by Polach
529524
/// </summary>
@@ -863,6 +858,8 @@ void Integrate(float elapsedClockSeconds)
863858
float screenFrameUpperLimit = 60;
864859
float screenFrameLowerLimit = 40;
865860

861+
var ScreenFrameRate = Simulator.SmoothedFrameRate;
862+
866863
// Reduces the number of substeps if screen FPS drops below a nominal rate of 60 fps
867864
if ( (int)ScreenFrameRate >= screenFrameUpperLimit) // Screen FPS > 60, hold substeps @ maximum value
868865
{

Source/Orts.Simulation/Simulation/Simulator.cs

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,12 @@
3232
using ORTS.Common;
3333
using ORTS.Scripting.Api;
3434
using ORTS.Settings;
35+
using SharpDX.MediaFoundation;
3536
using System;
3637
using System.Collections.Generic;
3738
using System.Diagnostics;
3839
using System.IO;
40+
using System.Runtime.Remoting.Messaging;
3941
using Event = Orts.Common.Event;
4042

4143
namespace Orts.Simulation
@@ -58,6 +60,20 @@ namespace Orts.Simulation
5860
/// </summary>
5961
public class Simulator
6062
{
63+
/// <summary>
64+
/// Sets the frame rate object so its value can be read from anywhere in the Simulator and used to tune simulation algorithms.
65+
/// </summary>
66+
/// <param name="frameRate"></param>
67+
public static void SetFrameRate(SmoothedData frameRate)
68+
{
69+
FrameRate = frameRate;
70+
}
71+
public static float SmoothedFrameRate
72+
{
73+
get { return FrameRate.SmoothedValue; }
74+
}
75+
private static SmoothedData FrameRate;
76+
6177
public static GettextResourceManager Catalog { get; private set; }
6278
public static Random Random { get; private set; }
6379
public static double Resolution = 1000000; // resolution for calculation of random value with a pseudo-gaussian distribution
@@ -1355,8 +1371,8 @@ private Train InitializePlayerTrain()
13551371
train.AITrainBrakePercent = 100; //<CSComment> This seems a tricky way for the brake modules to test if it is an AI train or not
13561372
train.EqualReservoirPressurePSIorInHg = prevEQres; // The previous command modifies EQ reservoir pressure, causing issues with EP brake systems, so restore to prev value
13571373

1358-
// if ((PlayerLocomotive as MSTSLocomotive).EOTEnabled != MSTSLocomotive.EOTenabled.no)
1359-
// train.EOT = new EOT((PlayerLocomotive as MSTSLocomotive).EOTEnabled, false, train);
1374+
// if ((PlayerLocomotive as MSTSLocomotive).EOTEnabled != MSTSLocomotive.EOTenabled.no)
1375+
// train.EOT = new EOT((PlayerLocomotive as MSTSLocomotive).EOTEnabled, false, train);
13601376

13611377
return (train);
13621378
}
@@ -1432,8 +1448,8 @@ private AITrain InitializeAPPlayerTrain()
14321448

14331449
if (conFileName.Contains("tilted")) train.IsTilting = true;
14341450

1435-
// if ((PlayerLocomotive as MSTSLocomotive).EOTEnabled != MSTSLocomotive.EOTenabled.no)
1436-
// train.EOT = new EOT((PlayerLocomotive as MSTSLocomotive).EOTEnabled, false, train);
1451+
// if ((PlayerLocomotive as MSTSLocomotive).EOTEnabled != MSTSLocomotive.EOTenabled.no)
1452+
// train.EOT = new EOT((PlayerLocomotive as MSTSLocomotive).EOTEnabled, false, train);
14371453

14381454
return train;
14391455
}
@@ -1487,7 +1503,7 @@ private void InitializeStaticConsists()
14871503

14881504
if (!File.Exists(wagonFilePath))
14891505
{
1490-
Trace.TraceWarning($"Ignored missing {(wagon.IsEngine? "engine" : "wagon")} {wagonFilePath} in activity definition {activityObject.Train_Config.TrainCfg.Name}");
1506+
Trace.TraceWarning($"Ignored missing {(wagon.IsEngine ? "engine" : "wagon")} {wagonFilePath} in activity definition {activityObject.Train_Config.TrainCfg.Name}");
14911507
continue;
14921508
}
14931509

@@ -1897,7 +1913,7 @@ private void StartSwitchPlayerTrain()
18971913
if (playerTrain != null)
18981914
{
18991915
if (playerTrain.ControlMode == Train.TRAIN_CONTROL.MANUAL) TrainSwitcher.SuspendOldPlayer = true; // force suspend state to avoid disappearing of train;
1900-
if (TrainSwitcher.SuspendOldPlayer &&
1916+
if (TrainSwitcher.SuspendOldPlayer &&
19011917
(playerTrain.SpeedMpS < -0.025 || playerTrain.SpeedMpS > 0.025 || playerTrain.PresentPosition[0].TCOffset != playerTrain.PreviousPosition[0].TCOffset))
19021918
{
19031919
Confirmer.Message(ConfirmLevel.Warning, Catalog.GetString("Train can't be suspended with speed not equal 0"));
@@ -2116,10 +2132,10 @@ public void RestartWaitingTrain(RestartWaitingTrain restartWaitingTrain)
21162132
}
21172133
}
21182134
if (trainToRestart == null)
2119-
Trace.TraceWarning("Train {0} to restart not found", restartWaitingTrain.WaitingTrainToRestart);
2135+
Trace.TraceWarning("Train {0} to restart not found", restartWaitingTrain.WaitingTrainToRestart);
21202136
}
21212137

2122-
2138+
21232139

21242140
/// <summary>
21252141
/// Derive log-file name from route path and activity name

Source/RunActivity/Viewer3D/Popups/HUDWindow.cs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -474,10 +474,6 @@ void TextPageCommon(TableData table)
474474
TableAddLabelValue(table, Viewer.Catalog.GetString("FPS"), "{0:F0}", Viewer.RenderProcess.FrameRate.SmoothedValue);
475475
TableAddLine(table);
476476

477-
// Used in axle module to adjust substeps for frame rate drops
478-
var mstsLocomotive = Viewer.PlayerLocomotive as MSTSLocomotive;
479-
Viewer.PlayerTrain.ScreenFrameRate = Viewer.RenderProcess.FrameRate.SmoothedValue;
480-
481477
if (Viewer.PlayerLocomotive.Train.TrainType == Train.TRAINTYPE.AI_PLAYERHOSTING)
482478
TableAddLine(table, Viewer.Catalog.GetString("Autopilot") + "???");
483479

Source/RunActivity/Viewer3D/Viewer.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -363,6 +363,8 @@ public Viewer(Simulator simulator, Orts.Viewer3D.Processes.Game game)
363363
SpeedpostDatFile = new SpeedpostDatFile(Simulator.RoutePath + @"\speedpost.dat", Simulator.RoutePath + @"\shapes\");
364364
}
365365
}
366+
// So the frame rate can be read from anywhere in the Simulator and used to tune simulation algorithms.
367+
Simulator.SetFrameRate(this.RenderProcess.FrameRate);
366368

367369
Initialize();
368370
}

0 commit comments

Comments
 (0)