Skip to content

Commit 599b980

Browse files
committed
Initial addition of advanced track sounds
1 parent 2634ac3 commit 599b980

File tree

7 files changed

+214
-52
lines changed

7 files changed

+214
-52
lines changed

Source/Orts.Formats.Msts/RouteFile.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,8 @@ public Tr_RouteFile(STFReader stf)
123123
new STFReader.TokenProcessor("ortscurvesmsnumber", ()=>{ CurveSMSNumber = stf.ReadIntBlock(null); }),
124124
new STFReader.TokenProcessor("ortscurveswitchsmsnumber", ()=>{ CurveSwitchSMSNumber = stf.ReadIntBlock(null); }),
125125
new STFReader.TokenProcessor("ortsopendoorsinaitrains", ()=>{ OpenDoorsInAITrains = stf.ReadBoolBlock(false); }),
126+
new STFReader.TokenProcessor("ortsplaytracksoundsbasecontinuous", ()=>{ TrackSoundDefaultContinuousPlay = stf.ReadBoolBlock(false); }),
127+
new STFReader.TokenProcessor("ortsdistancebetweentrackjoints", ()=>{ DistanceBetweenTrackJointsM = stf.ReadFloatBlock(STFReader.UNITS.Distance, null); }),
126128

127129
});
128130
//TODO This should be changed to STFException.TraceError() with defaults values created
@@ -151,6 +153,8 @@ public Tr_RouteFile(STFReader stf)
151153
public string DefaultSignalSMS;
152154
public float TempRestrictedSpeed = -1f;
153155
public Interpolator SuperElevationHgtpRadiusM; // Superelevation of tracks
156+
public bool TrackSoundDefaultContinuousPlay = false;
157+
public float DistanceBetweenTrackJointsM;
154158

155159
// Values for calculating Tunnel Resistance - will override default values.
156160
public float SingleTunnelAreaM2;

Source/Orts.Formats.Msts/SoundManagmentFile.cs

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@ public class SharedSMSFileManager
3737
public static int CurveSMSNumber;
3838
public static int CurveSwitchSMSNumber;
3939
public static bool AutoTrackSound = false;
40+
public static bool PlayDefaultTrackSoundsContinuous = false;
41+
public static float DistanceBetweenTrackJointsM;
42+
public static bool CarOnSwitch = false;
4043

4144
public static SoundManagmentFile Get(string path)
4245
{
@@ -198,7 +201,7 @@ public struct CurvePoint
198201

199202
public class VolumeCurve
200203
{
201-
public enum Controls { None, DistanceControlled, SpeedControlled, Variable1Controlled, Variable1_2Controlled, Variable1_3Controlled, Variable1_4Controlled, Variable2Controlled, Variable2BoosterControlled, Variable3Controlled, BrakeCylControlled, CurveForceControlled };
204+
public enum Controls { None, DistanceControlled, SpeedControlled, Variable1Controlled, Variable1_2Controlled, Variable1_3Controlled, Variable1_4Controlled, Variable2Controlled, Variable2BoosterControlled, Variable3Controlled, BrakeCylControlled, CurveForceControlled, AngleofAttackControlled, CarFrictionControlled, WheelRpMControlled, TrackJointControlled, SwitchControlled };
202205

203206
public Controls Control = Controls.None;
204207
public float Granularity = 1.0f;
@@ -222,6 +225,11 @@ public VolumeCurve(STFReader stf)
222225
case "variable3controlled": Control = Controls.Variable3Controlled; break;
223226
case "brakecylcontrolled": Control = Controls.BrakeCylControlled; break;
224227
case "curveforcecontrolled": Control = Controls.CurveForceControlled; break;
228+
case "angleofattackcontrolled": Control = Controls.AngleofAttackControlled; break;
229+
case "carfrictioncontrolled": Control = Controls.CarFrictionControlled; break;
230+
case "wheelrpmcontrolled": Control = Controls.WheelRpMControlled; break;
231+
case "trackjointcontrolled": Control = Controls.TrackJointControlled; break;
232+
case "switchcontrolled": Control = Controls.SwitchControlled; break;
225233
default: STFException.TraceWarning(stf, "Crash expected: Skipped unknown VolumeCurve/Frequencycurve type " + type); stf.SkipRestOfBlock(); return;
226234
}
227235
stf.ParseBlock(new STFReader.TokenProcessor[] {
@@ -343,7 +351,7 @@ public Discrete_Trigger(STFReader f)
343351
public class Variable_Trigger : Trigger
344352
{
345353
public enum Events { Speed_Inc_Past, Speed_Dec_Past, Distance_Inc_Past, Distance_Dec_Past,
346-
Variable1_Inc_Past, Variable1_2_Inc_Past, Variable1_3_Inc_Past, Variable1_4_Inc_Past, Variable1_Dec_Past, Variable1_2_Dec_Past, Variable1_3_Dec_Past, Variable1_4_Dec_Past, Variable2_Inc_Past, Variable2_Dec_Past, Variable3_Inc_Past, Variable3_Dec_Past, BrakeCyl_Inc_Past, BrakeCyl_Dec_Past, CurveForce_Inc_Past, CurveForce_Dec_Past
354+
Variable1_Inc_Past, Variable1_2_Inc_Past, Variable1_3_Inc_Past, Variable1_4_Inc_Past, Variable1_Dec_Past, Variable1_2_Dec_Past, Variable1_3_Dec_Past, Variable1_4_Dec_Past, Variable2_Inc_Past, Variable2_Dec_Past, Variable3_Inc_Past, Variable3_Dec_Past, BrakeCyl_Inc_Past, BrakeCyl_Dec_Past, CurveForce_Inc_Past, CurveForce_Dec_Past, AngleofAttack_Inc_Past, AngleofAttack_Dec_Past, WheelRpM_Dec_Past, WheelRPM_Inc_Past, TrackJoints_Inc_Past, TrackJoints_Dec_Past, CarOnSwitch_Inc_Past, CarOnSwitch_Dec_Past,
347355
};
348356

349357
public Events Event;
@@ -389,6 +397,14 @@ public Variable_Trigger(STFReader f)
389397
case "brakecyl_dec_past": Event = Events.BrakeCyl_Dec_Past; break;
390398
case "curveforce_inc_past": Event = Events.CurveForce_Inc_Past; break;
391399
case "curveforce_dec_past": Event = Events.CurveForce_Dec_Past; break;
400+
case "angleofattack_inc_past": Event = Events.AngleofAttack_Inc_Past; break;
401+
case "angleofattack_dec_past": Event = Events.AngleofAttack_Dec_Past; break;
402+
case "wheelrpm_inc_past": Event = Events.WheelRPM_Inc_Past; break;
403+
case "wheelrpm_dec_past": Event = Events.WheelRpM_Dec_Past; break;
404+
case "trackjoints_inc_past": Event = Events.TrackJoints_Inc_Past; break;
405+
case "trackjoints_dec_past": Event = Events.TrackJoints_Dec_Past; break;
406+
case "caronswitch_inc_past": Event = Events.CarOnSwitch_Inc_Past; break;
407+
case "caronswitch_dec_past": Event = Events.CarOnSwitch_Dec_Past; break;
392408
}
393409

394410

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1863,7 +1863,7 @@ public override void Save(BinaryWriter outf)
18631863

18641864
outf.Write(WheelBrakeSlideProtectionActive);
18651865
outf.Write(WheelBrakeSlideProtectionTimerS);
1866-
outf.Write(AngleOfAttackRad);
1866+
outf.Write(AngleOfAttackmRad);
18671867
outf.Write(DerailClimbDistanceM);
18681868
outf.Write(DerailPossible);
18691869
outf.Write(DerailExpected);
@@ -1920,7 +1920,7 @@ public override void Restore(BinaryReader inf)
19201920

19211921
WheelBrakeSlideProtectionActive = inf.ReadBoolean();
19221922
WheelBrakeSlideProtectionTimerS = inf.ReadInt32();
1923-
AngleOfAttackRad = inf.ReadSingle();
1923+
AngleOfAttackmRad = inf.ReadSingle();
19241924
DerailClimbDistanceM = inf.ReadSingle();
19251925
DerailPossible = inf.ReadBoolean();
19261926
DerailExpected = inf.ReadBoolean();

Source/Orts.Simulation/Simulation/RollingStocks/TrainCar.cs

Lines changed: 32 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ public static Interpolator SteamHeatBoilerFuelUsageGalukpH()
204204
public bool DerailmentCoefficientEnabled = true;
205205
public float MaximumWheelFlangeAngleRad;
206206
public float WheelFlangeLengthM;
207-
public float AngleOfAttackRad;
207+
public float AngleOfAttackmRad;
208208
public float DerailClimbDistanceM;
209209
public bool DerailPossible = false;
210210
public bool DerailExpected = false;
@@ -583,6 +583,9 @@ public Direction Direction
583583
protected SmoothedData CurveForceFilter = new SmoothedData(0.75f);
584584
public float CurveForceNFiltered;
585585

586+
protected SmoothedData CurveSquealAoAmRadFilter = new SmoothedData(0.75f);
587+
public float CurveSquealAoAmRadFiltered;
588+
586589
public float TunnelForceN; // Resistive force due to tunnel, in Newtons
587590
public float FrictionForceN; // in Newtons ( kg.m/s^2 ) unsigned, includes effects of curvature
588591
public float BrakeForceN; // current braking force applied to slow train (Newtons) - will be impacted by wheel/rail friction
@@ -980,6 +983,11 @@ public virtual void Update(float elapsedClockSeconds)
980983
CurrentElevationPercent = -CurrentElevationPercent;
981984
}
982985

986+
AngleOfAttackmRad = GetAngleofAttackmRad();
987+
988+
CurveSquealAoAmRadFilter.Update(elapsedClockSeconds, AngleOfAttackmRad);
989+
CurveSquealAoAmRadFiltered = CurveSquealAoAmRadFilter.SmoothedValue;
990+
983991
UpdateCurveSpeedLimit(); // call this first as it will provide inputs for the curve force.
984992
UpdateCurveForce(elapsedClockSeconds);
985993
UpdateTunnelForce();
@@ -1693,10 +1701,6 @@ public void UpdateTrainDerailmentRisk(float elapsedClockSeconds)
16931701
// Calculate Nadal derailment coefficient limit
16941702
NadalDerailmentCoefficient = ((float) Math.Tan(MaximumWheelFlangeAngleRad) - wagonAdhesion) / (1f + wagonAdhesion * (float) Math.Tan(MaximumWheelFlangeAngleRad));
16951703

1696-
// Calculate Angle of Attack - AOA = sin-1(2 * bogie wheel base / curve radius)
1697-
AngleOfAttackRad = (float)Math.Asin(2 * RigidWheelBaseM / CurrentCurveRadiusM);
1698-
var angleofAttackmRad = AngleOfAttackRad * 1000f; // Convert to micro radians
1699-
17001704
// Calculate the derail climb distance - uses the general form equation 2.4 from the above publication
17011705
var parameterA_1 = ((100 / (-1.9128f * MathHelper.ToDegrees(MaximumWheelFlangeAngleRad) + 146.56f)) + 3.1f) * Me.ToIn(WheelFlangeLengthM);
17021706

@@ -1710,7 +1714,7 @@ public void UpdateTrainDerailmentRisk(float elapsedClockSeconds)
17101714

17111715
var parameterB = parameterB_1 + parameterB_2;
17121716

1713-
DerailClimbDistanceM = Me.FromFt( (float)((parameterA * parameterB * Me.ToIn(WheelFlangeLengthM)) / ((angleofAttackmRad + (parameterB * Me.ToIn(WheelFlangeLengthM))))) );
1717+
DerailClimbDistanceM = Me.FromFt((float)((parameterA * parameterB * Me.ToIn(WheelFlangeLengthM)) / ((AngleOfAttackmRad + (parameterB * Me.ToIn(WheelFlangeLengthM))))));
17141718

17151719
// calculate the time taken to travel the derail climb distance
17161720
var derailTimeS = DerailClimbDistanceM / AbsSpeedMpS;
@@ -1781,6 +1785,25 @@ public void UpdateTrainDerailmentRisk(float elapsedClockSeconds)
17811785

17821786
#endregion
17831787

1788+
/// <summary>
1789+
/// Get the Angle of attack for a car as it goes through a curve
1790+
/// </summary>
1791+
/// <returns>angle in micro radians</returns>
1792+
///
1793+
public float GetAngleofAttackmRad()
1794+
{
1795+
if (CurrentCurveRadiusM > 0)
1796+
{
1797+
// Calculate Angle of Attack - AOA = sin-1(2 * bogie wheel base / curve radius)
1798+
var angleofAttackmRad = (float)Math.Asin(2 * RigidWheelBaseM / CurrentCurveRadiusM) * 1000f; // Convert to micro radians
1799+
return angleofAttackmRad;
1800+
}
1801+
else
1802+
{
1803+
return 0;
1804+
}
1805+
}
1806+
17841807
/// <summary>
17851808
/// Get the current direction that curve is heading relative to the train.
17861809
/// </summary>
@@ -2259,6 +2282,7 @@ public virtual void Save(BinaryWriter outf)
22592282
outf.Write(CarHeatCurrentCompartmentHeatJ);
22602283
outf.Write(CarSteamHeatMainPipeSteamPressurePSI);
22612284
outf.Write(CarHeatCompartmentHeaterOn);
2285+
outf.Write(CurveSquealAoAmRadFiltered);
22622286
}
22632287

22642288
// Game restore
@@ -2282,6 +2306,8 @@ public virtual void Restore(BinaryReader inf)
22822306
CarHeatCurrentCompartmentHeatJ = inf.ReadSingle();
22832307
CarSteamHeatMainPipeSteamPressurePSI = inf.ReadSingle();
22842308
CarHeatCompartmentHeaterOn = inf.ReadBoolean();
2309+
CurveSquealAoAmRadFiltered = inf.ReadSingle();
2310+
CurveSquealAoAmRadFilter.ForceSmoothValue(CurveSquealAoAmRadFiltered);
22852311
FreightAnimations?.LoadDataList?.Clear();
22862312
}
22872313

Source/RunActivity/Viewer3D/Popups/HUDWindow.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1236,8 +1236,9 @@ void TextPageForceInfo(TableData table)
12361236
Viewer.Catalog.GetString("Brk Slide"),
12371237
Viewer.Catalog.GetString("Bear Temp"),
12381238
Viewer.Catalog.GetString(" "),
1239-
Viewer.Catalog.GetString("DerailCoeff")
1240-
1239+
Viewer.Catalog.GetString("DrailCof"),
1240+
Viewer.Catalog.GetString("AoA")
1241+
12411242
);
12421243
TableAddLine(table);
12431244

@@ -1266,6 +1267,7 @@ void TextPageForceInfo(TableData table)
12661267
TableSetCell(table, 17, "{0} {1}", FormatStrings.FormatTemperature(car.WheelBearingTemperatureDegC, car.IsMetric, false), car.DisplayWheelBearingTemperatureStatus);
12671268
TableSetCell(table, 18, car.Flipped ? Viewer.Catalog.GetString("Flipped") : "");
12681269
TableSetCell(table, 19, "{0:F2}{1}", car.DerailmentCoefficient, car.DerailExpected ? "!!!" : car.DerailPossible ? "???" : "");
1270+
TableSetCell(table, 20, "{0:F2}", car.AngleOfAttackmRad);
12691271
TableAddLine(table);
12701272

12711273
}

0 commit comments

Comments
 (0)