Skip to content

Commit 76ee5ae

Browse files
committed
Initial build of track sounds
1 parent 2eb7441 commit 76ee5ae

File tree

7 files changed

+1391
-47
lines changed

7 files changed

+1391
-47
lines changed

Source/Orts.Formats.Msts/RouteFile.cs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,9 +86,9 @@ public Tr_RouteFile(STFReader stf)
8686
new STFReader.TokenProcessor("routestart", ()=>{ if (RouteStart == null) RouteStart = new RouteStart(stf); }),
8787
new STFReader.TokenProcessor("environment", ()=>{ Environment = new TRKEnvironment(stf); }),
8888
new STFReader.TokenProcessor("milepostunitskilometers", ()=>{ MilepostUnitsMetric = true; }),
89-
new STFReader.TokenProcessor("electrified", ()=>{ Electrified = stf.ReadBoolBlock(false); }),
89+
new STFReader.TokenProcessor("electrified", ()=>{ Electrified = stf.ReadBoolBlock(false); }),
9090
new STFReader.TokenProcessor("overheadwireheight", ()=>{ OverheadWireHeight = stf.ReadFloatBlock(STFReader.UNITS.Distance, 6.0f);}),
91-
new STFReader.TokenProcessor("speedlimit", ()=>{ SpeedLimit = stf.ReadFloatBlock(STFReader.UNITS.Speed, 500.0f); }),
91+
new STFReader.TokenProcessor("speedlimit", ()=>{ SpeedLimit = stf.ReadFloatBlock(STFReader.UNITS.Speed, 500.0f); }),
9292
new STFReader.TokenProcessor("defaultcrossingsms", ()=>{ DefaultCrossingSMS = stf.ReadStringBlock(null); }),
9393
new STFReader.TokenProcessor("defaultcoaltowersms", ()=>{ DefaultCoalTowerSMS = stf.ReadStringBlock(null); }),
9494
new STFReader.TokenProcessor("defaultdieseltowersms", ()=>{ DefaultDieselTowerSMS = stf.ReadStringBlock(null); }),
@@ -127,6 +127,9 @@ public Tr_RouteFile(STFReader stf)
127127
new STFReader.TokenProcessor("ortscurveswitchsmsnumber", ()=>{ CurveSwitchSMSNumber = stf.ReadIntBlock(null); }),
128128
new STFReader.TokenProcessor("ortsopendoorsinaitrains", ()=>{ OpenDoorsInAITrains = stf.ReadBoolBlock(false); }),
129129

130+
new STFReader.TokenProcessor("ortsplaytracksoundsbasecontinuous", ()=>{ TrackSoundDefaultContinuousPlay = stf.ReadBoolBlock(false); }),
131+
new STFReader.TokenProcessor("ortsdistancebetweentrackjoints", ()=>{ DistanceBetweenTrackJointsM = stf.ReadFloatBlock(STFReader.UNITS.Distance, null); }),
132+
new STFReader.TokenProcessor("ortsconcretesleepers", ()=>{ ConcreteSleepers = stf.ReadFloatBlock(STFReader.UNITS.None, null); }),
130133
});
131134
//TODO This should be changed to STFException.TraceError() with defaults values created
132135
if (RouteID == null) throw new STFException(stf, "Missing RouteID");
@@ -175,6 +178,11 @@ public Tr_RouteFile(STFReader stf)
175178
public float ForestClearDistance = 0;
176179
public bool RemoveForestTreesFromRoads = false;
177180

181+
// Track based sounds
182+
public bool TrackSoundDefaultContinuousPlay = false;
183+
public float DistanceBetweenTrackJointsM;
184+
public float ConcreteSleepers;
185+
178186
// images
179187
public string Thumbnail;
180188
public string LoadingScreen;

Source/Orts.Formats.Msts/SoundManagmentFile.cs

Lines changed: 363 additions & 4 deletions
Large diffs are not rendered by default.

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

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,8 @@ public TrainCar LastCar
163163
public bool HuDIsWheelSlip;
164164
public bool IsBrakeSkid;
165165

166+
public bool TrackJointSoundSetUpInitialise = true;
167+
166168
public bool HotBoxSetOnTrain = false;
167169
public int ActivityDurationS
168170
{
@@ -2009,6 +2011,84 @@ public virtual void Update(float elapsedClockSeconds, bool auxiliaryUpdate = tru
20092011
LogTrainSpeed(Simulator.ClockTime);
20102012
}
20112013

2014+
// Initialise track joint trigger points. Sets the trigger point for the track joint reletative to other cars.
2015+
// This is then reset every time a track joint is triggered, and positioned the same distance apart, hence reletative positions are maintained.
2016+
// Only runs once at start up.
2017+
if (TrackJointSoundSetUpInitialise && (float)Simulator.TRK.Tr_RouteFile.DistanceBetweenTrackJointsM > 0 && Simulator.TRK.Tr_RouteFile.TrackSoundDefaultContinuousPlay)
2018+
{
2019+
var trackjointdistanceM = (float)Simulator.TRK.Tr_RouteFile.DistanceBetweenTrackJointsM;
2020+
var trainLengthM = 0.0f;
2021+
var cummulativeTrackJointDistanceM = 0.0f;
2022+
var remainDistanceM = (float)Simulator.TRK.Tr_RouteFile.DistanceBetweenTrackJointsM;
2023+
2024+
foreach (var car in Cars)
2025+
{
2026+
// Initialise from the next track joint
2027+
2028+
// if remain distance has gone negative then car has moved over the next track joint
2029+
if (trackjointdistanceM > car.CarLengthM)
2030+
{
2031+
2032+
car.realTimeTrackJointDistanceM = cummulativeTrackJointDistanceM;
2033+
trainLengthM += car.CarLengthM;
2034+
cummulativeTrackJointDistanceM += car.CarLengthM;
2035+
remainDistanceM -= car.CarLengthM;
2036+
2037+
// Set values for printing values initially applied
2038+
bool concretesleepers = false;
2039+
2040+
if ((float)Simulator.TRK.Tr_RouteFile.ConcreteSleepers == 1)
2041+
{
2042+
concretesleepers = true;
2043+
}
2044+
2045+
if (Simulator.Settings.VerboseConfigurationMessages && Simulator.TRK.Tr_RouteFile.TrackSoundDefaultContinuousPlay)
2046+
{
2047+
Trace.TraceInformation("======================================================================================================================");
2048+
Trace.TraceInformation("TType Track Sounds Initialisation - Concrete Sleepers = {0}, Track Joint Distance = {1} m", concretesleepers, (float)Simulator.TRK.Tr_RouteFile.DistanceBetweenTrackJointsM);
2049+
}
2050+
2051+
// the next track joint has been reached reset all parameters in preparation for the next pass
2052+
if (remainDistanceM < 0.0f)
2053+
{
2054+
cummulativeTrackJointDistanceM = Math.Abs(remainDistanceM);
2055+
remainDistanceM = trackjointdistanceM - cummulativeTrackJointDistanceM;
2056+
}
2057+
2058+
}
2059+
// Trackjoint less then Car length
2060+
else if (trackjointdistanceM < car.CarLengthM)
2061+
{
2062+
car.realTimeTrackJointDistanceM = cummulativeTrackJointDistanceM;
2063+
trainLengthM += car.CarLengthM;
2064+
cummulativeTrackJointDistanceM += trackjointdistanceM;
2065+
remainDistanceM -= car.CarLengthM;
2066+
2067+
if (remainDistanceM < 0.0f)
2068+
{
2069+
2070+
while (Math.Abs(remainDistanceM) > trackjointdistanceM)
2071+
{
2072+
remainDistanceM += trackjointdistanceM;
2073+
}
2074+
2075+
cummulativeTrackJointDistanceM = Math.Abs(remainDistanceM);
2076+
remainDistanceM = trackjointdistanceM - cummulativeTrackJointDistanceM;
2077+
}
2078+
}
2079+
2080+
if (Simulator.Settings.VerboseConfigurationMessages && Simulator.TRK.Tr_RouteFile.TrackSoundDefaultContinuousPlay)
2081+
{
2082+
Trace.TraceInformation("CarID {0}, Dist from Joint = {1} m, Car Length = {2} m, Train Length = {3} m, Axle Count = {4}", car.CarID, car.realTimeTrackJointDistanceM, car.CarLengthM, trainLengthM, car.SoundAxleCount);
2083+
}
2084+
2085+
}
2086+
2087+
Trace.TraceInformation("======================================================================================================================");
2088+
2089+
TrackJointSoundSetUpInitialise = false;
2090+
}
2091+
20122092
} // end Update
20132093

20142094
//================================================================================================//

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

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

18911891
outf.Write(WheelBrakeSlideProtectionActive);
18921892
outf.Write(WheelBrakeSlideProtectionTimerS);
1893-
outf.Write(AngleOfAttackRad);
1893+
outf.Write(AngleOfAttackmRad);
18941894
outf.Write(DerailClimbDistanceM);
18951895
outf.Write(DerailPossible);
18961896
outf.Write(DerailExpected);
@@ -1947,7 +1947,7 @@ public override void Restore(BinaryReader inf)
19471947

19481948
WheelBrakeSlideProtectionActive = inf.ReadBoolean();
19491949
WheelBrakeSlideProtectionTimerS = inf.ReadInt32();
1950-
AngleOfAttackRad = inf.ReadSingle();
1950+
AngleOfAttackmRad = inf.ReadSingle();
19511951
DerailClimbDistanceM = inf.ReadSingle();
19521952
DerailPossible = inf.ReadBoolean();
19531953
DerailExpected = inf.ReadBoolean();

0 commit comments

Comments
 (0)