Skip to content

Commit dbddb68

Browse files
committed
Reduce allocations for DieselEngines
1 parent bdb34ba commit dbddb68

File tree

1 file changed

+6
-10
lines changed

1 file changed

+6
-10
lines changed

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

+6-10
Original file line numberDiff line numberDiff line change
@@ -2004,23 +2004,19 @@ public override void Update(float elapsedClockSeconds)
20042004
if (RemoteControlGroup != -1)
20052005
{
20062006
if (!LocomotivePowerSupply.MainPowerSupplyOn)
2007-
{
20082007
Train.SignalEvent(PowerSupplyEvent.RaisePantograph, 1);
20092008

2010-
if (this is MSTSDieselLocomotive)
2009+
if (this is MSTSDieselLocomotive dieselLocomotive)
2010+
{
2011+
for (var i = 0; i < dieselLocomotive.DieselEngines.Count; i++)
20112012
{
2012-
foreach (DieselEngine de in (this as MSTSDieselLocomotive).DieselEngines)
2013+
var de = dieselLocomotive.DieselEngines[i];
2014+
if (!LocomotivePowerSupply.MainPowerSupplyOn)
20132015
{
20142016
if (de.State != DieselEngineState.Running)
20152017
de.Initialize();
20162018
}
2017-
}
2018-
}
2019-
if (this is MSTSDieselLocomotive)
2020-
{
2021-
foreach (DieselEngine de in (this as MSTSDieselLocomotive).DieselEngines)
2022-
{
2023-
if (de.GearBox != null)
2019+
if (de.GearBox != null)
20242020
de.GearBox.GearBoxOperation = GearBoxOperation.Automatic;
20252021
}
20262022
}

0 commit comments

Comments
 (0)