Skip to content

Commit 9c051da

Browse files
committed
Automatic merge of T1.5.1-368-g38888b34f and 10 pull requests
- Pull request #570 at de7a14f: Experimental glTF 2.0 support with PBR lighting - Pull request #732 at 22f66dc: Improvements for air brakes - Pull request #751 at 00981a2: Web interface to control cab controls with external hardware - Pull request #799 at dc03850: Consolidated wind simulation - Pull request #803 at 7157e08: Various adjustments to steam adhesion - Pull request #813 at 0bb067a: Refactored garbage generators - Pull request #814 at b102c1c: Bug fix for https://bugs.launchpad.net/or/+bug/2013969 Crash after uncoupling player loco of a train with EOT - Pull request #815 at a5cc165: chore: Add GitHub automatic release notes configuration - Pull request #816 at eae646d: Bug fix for https://bugs.launchpad.net/or/+bug/2014992 EOT can't be dismounted after train reversal - Pull request #817 at 9c17435: weblink updated
12 parents 88f7a46 + 38888b3 + de7a14f + 22f66dc + 00981a2 + dc03850 + 7157e08 + 0bb067a + b102c1c + a5cc165 + eae646d + 9c17435 commit 9c051da

File tree

2 files changed

+21
-17
lines changed

2 files changed

+21
-17
lines changed

Source/Orts.Simulation/Simulation/LevelCrossing.cs

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -108,8 +108,12 @@ void UpdateCrossings(Train train, float elapsedTime)
108108
// Separate tests are performed for present speed and for possible maximum speed to avoid anomolies if train accelerates.
109109
// Special test is also done to check on section availability to avoid closure beyond signal at danger.
110110

111-
foreach (var crossing in TrackCrossingItems.Values.Where(ci => ci.CrossingGroup != null))
111+
foreach (var key in TrackCrossingItems.Keys)
112112
{
113+
var crossing = TrackCrossingItems[key];
114+
if (crossing?.CrossingGroup == null)
115+
continue;
116+
113117
var predictedDist = crossing.CrossingGroup.WarningTime * absSpeedMpS;
114118
var maxPredictedDist = crossing.CrossingGroup.WarningTime * (maxSpeedMpS - absSpeedMpS) / 2; // added distance if train accelerates to maxspeed
115119
var minimumDist = crossing.CrossingGroup.MinimumDistance;
@@ -299,11 +303,15 @@ void UpdateCrossings(Train train, float elapsedTime)
299303
public LevelCrossingItem SearchNearLevelCrossing(Train train, float reqDist, bool trainForwards, out float frontDist)
300304
{
301305
LevelCrossingItem roadItem = LevelCrossingItem.None;
302-
frontDist = -1;
306+
frontDist = -1;
303307
Traveller traveller = trainForwards ? train.FrontTDBTraveller :
304308
new Traveller(train.RearTDBTraveller, Traveller.TravellerDirection.Backward);
305-
foreach (var crossing in TrackCrossingItems.Values.Where(ci => ci.CrossingGroup != null))
309+
foreach (var key in TrackCrossingItems.Keys)
306310
{
311+
var crossing = TrackCrossingItems[key];
312+
if (crossing?.CrossingGroup == null)
313+
continue;
314+
307315
if (crossing.Trains.Contains(train))
308316
{
309317
frontDist = crossing.DistanceTo(traveller, reqDist);
@@ -445,14 +453,10 @@ public bool HasTrain
445453
{
446454
get
447455
{
448-
bool trains = Items.Any(i => i.Trains.Count > 0);
449-
bool staticconsists = Items.Any(i => i.StaticConsists.Count > 0);
450-
if (trains && staticconsists)
451-
return true;
452-
else if (trains || staticconsists)
453-
return true;
454-
else
455-
return false;
456+
foreach (var item in Items)
457+
if (item.Trains.Count > 0 || item.StaticConsists.Count > 0)
458+
return true;
459+
return false;
456460
}
457461
}
458462
}

Source/RunActivity/Viewer3D/RoadCars.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -255,13 +255,13 @@ public void Update(ElapsedTime elapsedTime)
255255
}
256256

257257
// Calculate all the distances to items we need to stop at (level crossings, other cars).
258-
var stopDistances = new List<float>();
258+
var stopDistance = float.MaxValue;
259259
for (var crossing = NextCrossingIndex; crossing < crossings.Count; crossing++)
260260
{
261261
if (crossings[crossing].Item.CrossingGroup != null && crossings[crossing].Item.CrossingGroup.HasTrain)
262262
{
263263
// TODO: Stopping distance for level crossings!
264-
stopDistances.Add(crossings[crossing].Distance - RoadCarSpawner.StopDistance);
264+
stopDistance = Math.Min(stopDistance, crossings[crossing].Distance - RoadCarSpawner.StopDistance);
265265
break;
266266
}
267267
}
@@ -271,13 +271,13 @@ public void Update(ElapsedTime elapsedTime)
271271
if (spawnerIndex > 0)
272272
{
273273
if (!cars[spawnerIndex - 1].CarriesCamera)
274-
stopDistances.Add(cars[spawnerIndex - 1].Travelled - cars[spawnerIndex - 1].Length / 2);
274+
stopDistance = Math.Min(stopDistance, cars[spawnerIndex - 1].Travelled - cars[spawnerIndex - 1].Length / 2);
275275
else
276-
stopDistances.Add(cars[spawnerIndex - 1].Travelled - cars[spawnerIndex - 1].Length * 0.65f - 4 - cars[spawnerIndex - 1].Speed * 0.5f);
277-
}
276+
stopDistance = Math.Min(stopDistance, cars[spawnerIndex - 1].Travelled - cars[spawnerIndex - 1].Length * 0.65f - 4 - cars[spawnerIndex - 1].Speed * 0.5f);
277+
}
278278

279279
// Calculate whether we're too close to the minimum stopping distance (and need to slow down) or going too slowly (and need to speed up).
280-
var stopDistance = stopDistances.Count > 0 ? stopDistances.Min() - Travelled - Length / 2 : float.MaxValue;
280+
stopDistance = stopDistance - Travelled - Length / 2;
281281
var slowingDistance = BrakingFactor * Length;
282282
if (stopDistance < slowingDistance)
283283
Speed = SpeedMax * (float)Math.Sin((Math.PI / 2) * (stopDistance / slowingDistance));

0 commit comments

Comments
 (0)