Skip to content

Commit 109aec4

Browse files
committed
Initialize cars before restore
1 parent 7f7dd99 commit 109aec4

File tree

11 files changed

+14
-67
lines changed

11 files changed

+14
-67
lines changed

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -952,9 +952,8 @@ private void RestoreCars(Simulator simulator, BinaryReader inf)
952952
{
953953
for (int i = 0; i < count; ++i)
954954
{
955-
TrainCar car = RollingStock.Load(simulator, this, inf.ReadString(), false);
955+
TrainCar car = RollingStock.Load(simulator, this, inf.ReadString());
956956
car.Restore(inf);
957-
car.Initialize();
958957
}
959958
}
960959
SetDPUnitIDs(true);

Source/Orts.Simulation/Simulation/RollingStocks/MSTSDieselLocomotive.cs

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -91,11 +91,6 @@ public float DieselLevelL
9191

9292
public float LocomotiveMaxRailOutputPowerW;
9393

94-
public int currentGearIndexRestore = -1;
95-
public int currentnextGearRestore = -1;
96-
public bool gearSaved;
97-
public int dieselEngineRestoreState;
98-
9994
public float EngineRPM;
10095
public SmoothedData ExhaustParticles = new SmoothedData(1);
10196
public SmoothedData ExhaustMagnitude = new SmoothedData(1);
@@ -476,17 +471,6 @@ public override void Initialize()
476471
}
477472
}
478473

479-
// TO BE LOOKED AT - fix restoration process for gearbox and gear controller
480-
// It appears that the gearbox is initialised in two different places to cater for Basic and Advanced ENG file configurations(?).
481-
// Hence the restore values recovered in gearbox class are being overwritten , and resume was not working correctly
482-
// Hence restore gear position values are read as part of the diesel and restored at this point.
483-
if (gearSaved)
484-
{
485-
DieselEngines[0].GearBox.nextGearIndex = currentnextGearRestore;
486-
DieselEngines[0].GearBox.currentGearIndex = currentGearIndexRestore;
487-
GearBoxController.SetValue((float)DieselEngines[0].GearBox.currentGearIndex);
488-
}
489-
490474
if (Simulator.Settings.VerboseConfigurationMessages)
491475
{
492476
if (DieselEngines.HasGearBox)

Source/Orts.Simulation/Simulation/RollingStocks/SubSystems/PowerSupplies/CircuitBreaker.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,6 @@ public void HandleEvent(PowerSupplyEvent evt)
188188

189189
public void Save(BinaryWriter outf)
190190
{
191-
outf.Write(ScriptName);
192191
outf.Write(DelayS);
193192
outf.Write(State.ToString());
194193
outf.Write(DriverClosingOrder);
@@ -199,7 +198,6 @@ public void Save(BinaryWriter outf)
199198

200199
public void Restore(BinaryReader inf)
201200
{
202-
ScriptName = inf.ReadString();
203201
DelayS = inf.ReadSingle();
204202
State = (CircuitBreakerState)Enum.Parse(typeof(CircuitBreakerState), inf.ReadString());
205203
DriverClosingOrder = inf.ReadBoolean();

Source/Orts.Simulation/Simulation/RollingStocks/SubSystems/PowerSupplies/DieselEngine.cs

Lines changed: 6 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,6 @@ public void Parse(string lowercasetoken, STFReader stf)
109109
DEList.Add(new DieselEngine(Locomotive));
110110

111111
DEList[i].Parse(stf);
112-
DEList[i].Initialize();
113112

114113
// sets flag to indicate that a diesel eng prime mover code block has been defined by user, otherwise OR will define one through the next code section using "MSTS" values
115114
DEList[i].DieselEngineConfigured = true;
@@ -119,7 +118,6 @@ public void Parse(string lowercasetoken, STFReader stf)
119118
{
120119
STFException.TraceWarning(stf, "Diesel engine model has some errors - loading MSTS format");
121120
DEList[i].InitFromMSTS();
122-
DEList[i].Initialize();
123121
}
124122
}
125123
break;
@@ -993,15 +991,11 @@ public void Copy(DieselEngine other)
993991

994992
public void Initialize()
995993
{
996-
if (!Simulator.Settings.NoDieselEngineStart && !Locomotive.gearSaved)
994+
if (!Simulator.Settings.NoDieselEngineStart)
997995
{
998996
RealRPM = IdleRPM;
999997
State = DieselEngineState.Running;
1000998
}
1001-
else if (Locomotive.gearSaved)
1002-
{
1003-
State = (DieselEngineState)Locomotive.dieselEngineRestoreState;
1004-
}
1005999

10061000
RPMRange = MaxRPM - IdleRPM;
10071001
MagnitudeRange = MaxMagnitude - InitialMagnitude;
@@ -1018,15 +1012,8 @@ public void Initialize()
10181012

10191013
public void InitializeMoving()
10201014
{
1021-
if (!Simulator.Settings.NoDieselEngineStart && !Locomotive.gearSaved)
1022-
{
1023-
RealRPM = IdleRPM;
1024-
State = DieselEngineState.Running;
1025-
}
1026-
else if (Locomotive.gearSaved)
1027-
{
1028-
State = (DieselEngineState)Locomotive.dieselEngineRestoreState;
1029-
}
1015+
RealRPM = IdleRPM;
1016+
State = DieselEngineState.Running;
10301017

10311018
GearBox?.InitializeMoving();
10321019
}
@@ -1594,16 +1581,15 @@ public void HandleEvent(PowerSupplyEvent evt)
15941581

15951582
public void Restore(BinaryReader inf)
15961583
{
1597-
Locomotive.dieselEngineRestoreState = inf.ReadInt32();
1598-
State = (DieselEngineState)Locomotive.dieselEngineRestoreState;
1584+
State = (DieselEngineState)inf.ReadInt32();
15991585
RealRPM = inf.ReadSingle();
16001586
OutputPowerW = inf.ReadSingle();
16011587
DieselTemperatureDeg = inf.ReadSingle();
16021588
GovernorEnabled = inf.ReadBoolean();
16031589

1604-
Locomotive.gearSaved = inf.ReadBoolean(); // read boolean which indicates gear data was saved
1590+
bool gearSaved = inf.ReadBoolean(); // read boolean which indicates gear data was saved
16051591

1606-
if (Locomotive.gearSaved)
1592+
if (gearSaved)
16071593
{
16081594
GearBox = new GearBox(this);
16091595
GearBox.Restore(inf);

Source/Orts.Simulation/Simulation/RollingStocks/SubSystems/PowerSupplies/DieselPowerSupply.cs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -110,16 +110,12 @@ public override void InitializeMoving()
110110

111111
public override void Save(BinaryWriter outf)
112112
{
113-
outf.Write(ScriptName);
114-
115113
base.Save(outf);
116114
TractionCutOffRelay.Save(outf);
117115
}
118116

119117
public override void Restore(BinaryReader inf)
120118
{
121-
ScriptName = inf.ReadString();
122-
123119
base.Restore(inf);
124120
TractionCutOffRelay.Restore(inf);
125121
}

Source/Orts.Simulation/Simulation/RollingStocks/SubSystems/PowerSupplies/DualModePowerSupply.cs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -112,17 +112,13 @@ public override void InitializeMoving()
112112

113113
public override void Save(BinaryWriter outf)
114114
{
115-
outf.Write(ScriptName);
116-
117115
base.Save(outf);
118116
CircuitBreaker.Save(outf);
119117
TractionCutOffRelay.Save(outf);
120118
}
121119

122120
public override void Restore(BinaryReader inf)
123121
{
124-
ScriptName = inf.ReadString();
125-
126122
base.Restore(inf);
127123
CircuitBreaker.Restore(inf);
128124
TractionCutOffRelay.Restore(inf);

Source/Orts.Simulation/Simulation/RollingStocks/SubSystems/PowerSupplies/ElectricPowerSupply.cs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -108,16 +108,12 @@ public override void InitializeMoving()
108108

109109
public override void Save(BinaryWriter outf)
110110
{
111-
outf.Write(ScriptName);
112-
113111
base.Save(outf);
114112
CircuitBreaker.Save(outf);
115113
}
116114

117115
public override void Restore(BinaryReader inf)
118116
{
119-
ScriptName = inf.ReadString();
120-
121117
base.Restore(inf);
122118
CircuitBreaker.Restore(inf);
123119
}

Source/Orts.Simulation/Simulation/RollingStocks/SubSystems/PowerSupplies/Pantograph.cs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -79,13 +79,14 @@ public void Copy(Pantographs pantographs)
7979

8080
public void Restore(BinaryReader inf)
8181
{
82-
List.Clear();
83-
8482
int n = inf.ReadInt32();
8583
for (int i = 0; i < n; i++)
8684
{
87-
List.Add(new Pantograph(Wagon));
88-
List.Last().Restore(inf);
85+
if (i >= List.Count)
86+
{
87+
List.Add(new Pantograph(Wagon));
88+
}
89+
List[i].Restore(inf);
8990
}
9091
}
9192

Source/Orts.Simulation/Simulation/RollingStocks/SubSystems/PowerSupplies/TractionCutOffRelay.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,6 @@ public void HandleEvent(PowerSupplyEvent evt)
165165

166166
public void Save(BinaryWriter outf)
167167
{
168-
outf.Write(ScriptName);
169168
outf.Write(DelayS);
170169
outf.Write(State.ToString());
171170
outf.Write(DriverClosingOrder);
@@ -176,7 +175,6 @@ public void Save(BinaryWriter outf)
176175

177176
public void Restore(BinaryReader inf)
178177
{
179-
ScriptName = inf.ReadString();
180178
DelayS = inf.ReadSingle();
181179
State = (TractionCutOffRelayState)Enum.Parse(typeof(TractionCutOffRelayState), inf.ReadString());
182180
DriverClosingOrder = inf.ReadBoolean();

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -751,9 +751,7 @@ public void Copy(GearBox copy)
751751
public void Restore(BinaryReader inf)
752752
{
753753
currentGearIndex = inf.ReadInt32();
754-
Locomotive.currentGearIndexRestore = currentGearIndex;
755754
nextGearIndex = inf.ReadInt32();
756-
Locomotive.currentnextGearRestore = nextGearIndex;
757755
gearedUp = inf.ReadBoolean();
758756
gearedDown = inf.ReadBoolean();
759757
clutchOn = inf.ReadBoolean();

0 commit comments

Comments
 (0)