Skip to content

Commit 5e975cb

Browse files
committed
Change adhesion algorithm switch to trigger off elapsedClock, and fix calculation of dynamic adhesion (drive wheel) weight.
1 parent 8a6acee commit 5e975cb

File tree

5 files changed

+31
-28
lines changed

5 files changed

+31
-28
lines changed

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

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,17 @@ public float CombinedTenderWaterVolumeUKG // Decreased by running injec
186186

187187
public float CurrentLocomotiveSteamHeatBoilerWaterCapacityL
188188
{
189-
get { return WaterController.CurrentValue * MaximumSteamHeatBoilerWaterTankCapacityL; }
189+
get {
190+
if (IsSteamHeatFitted)
191+
{
192+
return WaterController.CurrentValue * MaximumSteamHeatBoilerWaterTankCapacityL;
193+
}
194+
else
195+
{
196+
return 0;
197+
}
198+
}
199+
190200
set { WaterController.CurrentValue = value / MaximumSteamHeatBoilerWaterTankCapacityL; }
191201
}
192202
public float IsTenderRequired = 1.0f; // Flag indicates that a tender is required for operation of the locomotive. Typically tank locomotives do not require a tender. Assume by default that tender is required.
@@ -239,10 +249,11 @@ public enum SlipControlType
239249

240250
// parameters for Track Sander based upon compressor air and abrasive table for 1/2" sand blasting nozzle @ 50psi
241251
public float MaxTrackSandBoxCapacityM3 = Me3.FromFt3(40.0f); // Capacity of sandbox - assume 40.0 cu ft
242-
public float CurrentTrackSandBoxCapacityM3 = 5.0f; // This value needs to be initialised to the value above, as it reduces as sand is used.
252+
public float CurrentTrackSandBoxCapacityM3;
243253
public float TrackSanderAirComsumptionM3pS = Me3.FromFt3(195.0f) / 60.0f; // Default value - cubic feet per min (CFM) 195 ft3/m
244254
public float TrackSanderAirPressurePSI = 50.0f;
245255
public float TrackSanderSandConsumptionM3pS = Me3.FromFt3(11.6f) / 3600.0f; // Default value - 11.6 ft3/h
256+
public float SandWeightKgpM3 = 1600; // One cubic metre of sand weighs about 1.54-1.78 tonnes.
246257

247258
// Vacuum Braking parameters
248259
readonly static float OneAtmospherePSI = Bar.ToPSI(1);
@@ -1112,9 +1123,16 @@ public override void Parse(string lowercasetoken, STFReader stf)
11121123
case "engine(ortswaterscoopfillelevation": WaterScoopFillElevationM = stf.ReadFloatBlock(STFReader.UNITS.Distance, 0.0f); break;
11131124
case "engine(ortswaterscoopdepth": WaterScoopDepthM = stf.ReadFloatBlock(STFReader.UNITS.Distance, 0.0f); break;
11141125
case "engine(ortswaterscoopwidth": WaterScoopWidthM = stf.ReadFloatBlock(STFReader.UNITS.Distance, 0.0f); break;
1115-
case "engine(ortsmaxtracksanderboxcapacity": MaxTrackSandBoxCapacityM3 = stf.ReadFloatBlock(STFReader.UNITS.Volume, null); break;
1116-
case "engine(ortsmaxtracksandersandconsumption": TrackSanderSandConsumptionM3pS = stf.ReadFloatBlock(STFReader.UNITS.Volume, null); break;
1117-
case "engine(ortsmaxtracksanderairconsumption": TrackSanderAirComsumptionM3pS = stf.ReadFloatBlock(STFReader.UNITS.Volume, null); break;
1126+
// Convert the following default ft^3 to Me^3 units
1127+
case "engine(ortsmaxtracksanderboxcapacity": MaxTrackSandBoxCapacityM3 = stf.ReadFloatBlock(STFReader.UNITS.VolumeDefaultFT3, null);
1128+
MaxTrackSandBoxCapacityM3 = Me3.FromFt3(MaxTrackSandBoxCapacityM3);
1129+
break;
1130+
case "engine(ortsmaxtracksandersandconsumption": Me3.FromFt3( TrackSanderSandConsumptionM3pS = stf.ReadFloatBlock(STFReader.UNITS.VolumeDefaultFT3, null) );
1131+
TrackSanderSandConsumptionM3pS = Me3.FromFt3(TrackSanderSandConsumptionM3pS);
1132+
break;
1133+
case "engine(ortsmaxtracksanderairconsumption": Me3.FromFt3( TrackSanderAirComsumptionM3pS = stf.ReadFloatBlock(STFReader.UNITS.VolumeDefaultFT3, null) );
1134+
TrackSanderAirComsumptionM3pS = Me3.FromFt3(TrackSanderAirComsumptionM3pS);
1135+
break;
11181136
case "engine(ortscruisecontrol": SetUpCruiseControl(stf); break;
11191137
case "engine(ortsmultipositioncontroller": SetUpMPC(stf); break;
11201138
default:

Source/Orts.Simulation/Simulation/RollingStocks/MSTSWagon.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2177,7 +2177,7 @@ private void UpdateLocomotiveLoadPhysics()
21772177
// This is a tender locomotive. A tender locomotive does not have any fuel onboard.
21782178
// Thus the loco weight only changes as boiler level goes up and down, and coal mass varies in the fire
21792179
{
2180-
MassKG = LoadEmptyMassKg + Kg.FromLb(SteamLocomotiveIdentification.BoilerMassLB) + SteamLocomotiveIdentification.FireMassKG;
2180+
MassKG = LoadEmptyMassKg + Kg.FromLb(SteamLocomotiveIdentification.BoilerMassLB) + SteamLocomotiveIdentification.FireMassKG + +(SteamLocomotiveIdentification.CurrentTrackSandBoxCapacityM3 * SteamLocomotiveIdentification.SandWeightKgpM3);
21812181
MassKG = MathHelper.Clamp(MassKG, LoadEmptyMassKg, LoadFullMassKg); // Clamp Mass to between the empty and full wagon values
21822182
// Adjust drive wheel weight
21832183
SteamLocomotiveIdentification.DrvWheelWeightKg = (MassKG / InitialMassKG) * SteamLocomotiveIdentification.InitialDrvWheelWeightKg;
@@ -2223,7 +2223,7 @@ private void UpdateLocomotiveLoadPhysics()
22232223
if (DieselLocomotiveIdentification != null)
22242224
{
22252225

2226-
MassKG = LoadEmptyMassKg + (DieselLocomotiveIdentification.DieselLevelL * DieselLocomotiveIdentification.DieselWeightKgpL) + DieselLocomotiveIdentification.CurrentLocomotiveSteamHeatBoilerWaterCapacityL;
2226+
MassKG = LoadEmptyMassKg + (DieselLocomotiveIdentification.DieselLevelL * DieselLocomotiveIdentification.DieselWeightKgpL) + DieselLocomotiveIdentification.CurrentLocomotiveSteamHeatBoilerWaterCapacityL + (DieselLocomotiveIdentification.CurrentTrackSandBoxCapacityM3 * DieselLocomotiveIdentification.SandWeightKgpM3);
22272227
MassKG = MathHelper.Clamp(MassKG, LoadEmptyMassKg, LoadFullMassKg); // Clamp Mass to between the empty and full wagon values
22282228
// Adjust drive wheel weight
22292229
DieselLocomotiveIdentification.DrvWheelWeightKg = (MassKG / InitialMassKG) * DieselLocomotiveIdentification.InitialDrvWheelWeightKg;

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

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -955,19 +955,20 @@ void Integrate(float elapsedClockSeconds)
955955
public virtual void Update(float timeSpan)
956956
{
957957
// Test to determine whether to use Polach or Pacha adhesion
958-
var ScreenFrameRate = Simulator.SmoothedFrameRate;
959-
960-
// Switches between Polach (high performance) adhesion model and Pacha (low performance) adhesion model
961-
if(ScreenFrameRate > 59)
958+
959+
// Switches between Polach (high performance) adhesion model and Pacha (low performance) adhesion model depending upon the PC performance
960+
if(timeSpan < 0.025) // timespan 0.025 = 40 fps screen rate, low timeSpan and high FPS
962961
{
963962
UsePolachAdhesion = true;
964963
}
965-
else if(ScreenFrameRate < 55)
964+
else if(timeSpan > 0.033) // timespan 0.033 = 30 fps screen rate, high timeSpan and low FPS
966965
{
967966
UsePolachAdhesion = false;
968967
if (TrainSpeedMpS > 0 )
969968
{
969+
var ScreenFrameRate = 1 / timeSpan;
970970
Trace.TraceInformation("Advanced adhesion model switched to low performance option due to low frame rate {0} at ElapsedClockSeconds of {1}", ScreenFrameRate, timeSpan);
971+
971972
}
972973

973974
// Set values for Pacha adhesion

Source/Orts.Simulation/Simulation/Simulator.cs

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@
3737
using System.Collections.Generic;
3838
using System.Diagnostics;
3939
using System.IO;
40-
using System.Runtime.Remoting.Messaging;
4140
using Event = Orts.Common.Event;
4241

4342
namespace Orts.Simulation
@@ -60,19 +59,6 @@ namespace Orts.Simulation
6059
/// </summary>
6160
public class Simulator
6261
{
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;
7662

7763
public static GettextResourceManager Catalog { get; private set; }
7864
public static Random Random { get; private set; }

Source/RunActivity/Viewer3D/Viewer.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -363,8 +363,6 @@ 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);
368366

369367
Initialize();
370368
}

0 commit comments

Comments
 (0)