Skip to content

Commit b56a862

Browse files
committed
Automatic merge of T1.5.1-791-gffaeec028 and 15 pull requests
- Pull request #570 at 3539862: Experimental glTF 2.0 support with PBR lighting - Pull request #839 at d00beb9: First phase of https://blueprints.launchpad.net/or/+spec/additional-cruise-control-parameters - Pull request #876 at f92de76: docs: add source for documents previously on website to source Documentation folder - Pull request #882 at a055bca: Blueprint/train car operations UI window - Pull request #885 at d9ce84b: feat: Add notifications to Menu - Pull request #886 at 6c0785b: Scene viewer extension to TrackViewer - Pull request #892 at 1f5ba4c: Signal Function OPP_SIG_ID_TRAINPATH - Pull request #893 at bf8876b: Signal errors - Pull request #896 at 5866028: First implementation of https://blueprints.launchpad.net/or/+spec/specific-sounds-for-ai-trains - Pull request #897 at 0a9d939: feat: Improved system information collection - Pull request #899 at 0fb4d1c: Duplex steam engines - Booster Engine addition - Pull request #903 at d5b3639: Downloading route content from Github - Pull request #906 at 0e0aa8b: Bug fix for https://bugs.launchpad.net/or/+bug/2047299 Crash loading a 3Dcab-only loco - Pull request #907 at 9b0b04f: Bug fix for https://bugs.launchpad.net/or/+bug/2047300 Dynamic tracks disappear after long tunnel - Pull request #908 at a325039: feat: supports switching adhesion precisions
17 parents 8b98c02 + ffaeec0 + 3539862 + d00beb9 + f92de76 + a055bca + d9ce84b + 6c0785b + 1f5ba4c + bf8876b + 5866028 + 0a9d939 + 0fb4d1c + d5b3639 + 0e0aa8b + 9b0b04f + a325039 commit b56a862

File tree

1 file changed

+36
-11
lines changed
  • Source/Orts.Simulation/Simulation/RollingStocks/SubSystems/PowerTransmissions

1 file changed

+36
-11
lines changed

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

Lines changed: 36 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -437,6 +437,7 @@ public float InertiaKgm2
437437
/// switch between Polach and Pacha adhesion calculation
438438
/// </summary>
439439
public static bool UsePolachAdhesion = false; // "static" so it's shared by all axles of the Player's loco
440+
public double GameTime; // Set by MSTSLocomotive and used by AdhesionPrecision.IsPrecisionHigh
440441

441442
/// <summary>
442443
/// Pre-calculation of slip characteristics at 0 slip speed
@@ -1022,7 +1023,7 @@ void Integrate(float elapsedClockSeconds)
10221023
/// <param name="elapsedSeconds"></param>
10231024
public virtual void Update(float elapsedSeconds)
10241025
{
1025-
UsePolachAdhesion = AdhesionPrecision.IsPrecisionHigh(elapsedSeconds);
1026+
UsePolachAdhesion = AdhesionPrecision.IsPrecisionHigh(elapsedSeconds, GameTime);
10261027
if (UsePolachAdhesion)
10271028
{
10281029
forceToAccelerationFactor = WheelRadiusM * WheelRadiusM / totalInertiaKgm2;
@@ -1134,25 +1135,29 @@ enum AdhesionPrecisionLevel
11341135
/// <summary>
11351136
/// Initial level uses Polach algorithm
11361137
/// </summary>
1137-
High,
1138+
High = 0,
11381139
/// <summary>
11391140
/// Low-performance PCs use Pacha's algorithm
11401141
/// </summary>
1141-
Low
1142+
Low = 1,
1143+
/// <summary>
1144+
/// After frequent transitions, low-performance PCs are locked to Pacha's algorithm
1145+
/// </summary>
1146+
LowLocked = 2
11421147
}
11431148

1144-
static AdhesionPrecisionLevel PrecisionLevel = AdhesionPrecisionLevel.High;
1145-
static double TimeOfLatestDowngrade = 0;
1146-
11471149
// Adjustable limits
1150+
const float LowerLimitS = 0.025f; // timespan 0.025 = 40 fps screen rate, low timeSpan and high FPS
11481151
const float UpperLimitS = 0.033f; // timespan 0.033 = 30 fps screen rate, high timeSpan and low FPS
1152+
const double IntervalBetweenDowngradesLimitS = 5 * 60; // Locks in low precision if < 5 mins between downgrades
1153+
1154+
static AdhesionPrecisionLevel PrecisionLevel = AdhesionPrecisionLevel.High;
1155+
static double TimeOfLatestDowngrade = 0 - IntervalBetweenDowngradesLimitS; // Starts at -5 mins
11491156

11501157
// Tested by varying the framerate interactively. Did this by opening and closing the HelpWindow after inserting
11511158
// Threading.Thread.Sleep(40);
11521159
// into HelpWindow.PrepareFrame() temporarily.
1153-
public static bool IsPrecisionHigh(float elapsedSeconds)
1154-
{
1155-
if (elapsedSeconds > 0) // Ignore period with elapsedSeconds == 0 until user starts game.
1160+
public static bool IsPrecisionHigh(float elapsedSeconds, double gameTime)
11561161
{
11571162
// Switches between Polach (high precision) adhesion model and Pacha (low precision) adhesion model depending upon the PC performance
11581163
switch (PrecisionLevel)
@@ -1161,16 +1166,36 @@ public static bool IsPrecisionHigh(float elapsedSeconds)
11611166
if (elapsedSeconds > UpperLimitS)
11621167
{
11631168
var screenFrameRate = 1 / elapsedSeconds;
1169+
var timeSincePreviousDowngradeS = gameTime - TimeOfLatestDowngrade;
1170+
if (timeSincePreviousDowngradeS < IntervalBetweenDowngradesLimitS)
11641171
{
1165-
Trace.TraceInformation($"Advanced adhesion model switched to low precision permanently after low frame rate {screenFrameRate:F1} below limit {1 / UpperLimitS:F0}");
1172+
Trace.TraceInformation($"At {gameTime:F0} secs, advanced adhesion model switched to low precision permanently after {timeSincePreviousDowngradeS:F0} secs since previous switch (less than limit of {IntervalBetweenDowngradesLimitS})");
1173+
PrecisionLevel = AdhesionPrecisionLevel.LowLocked;
1174+
}
1175+
else
1176+
{
1177+
TimeOfLatestDowngrade = gameTime;
1178+
1179+
Trace.TraceInformation($"At {gameTime:F0} secs, advanced adhesion model switched to low precision after low frame rate {screenFrameRate:F1} below limit {1 / UpperLimitS:F0}");
11661180
PrecisionLevel = AdhesionPrecisionLevel.Low;
1181+
11671182
}
11681183
}
11691184
break;
11701185

11711186
case AdhesionPrecisionLevel.Low:
1172-
break;
1187+
if (elapsedSeconds > 0 // When debugging step by step, elapsedSeconds == 0, so test for that
1188+
&& elapsedSeconds < LowerLimitS)
1189+
{
1190+
PrecisionLevel = AdhesionPrecisionLevel.High;
1191+
var ScreenFrameRate = 1 / elapsedSeconds;
1192+
Trace.TraceInformation($"At {gameTime:F0} secs, advanced adhesion model switched to high precision after high frame rate {ScreenFrameRate:F1} above limit {1 / LowerLimitS:F0}");
11731193
}
1194+
break;
1195+
1196+
case AdhesionPrecisionLevel.LowLocked:
1197+
break;
1198+
11741199
}
11751200
return (PrecisionLevel == AdhesionPrecisionLevel.High);
11761201
}

0 commit comments

Comments
 (0)