Skip to content

Commit e4af801

Browse files
committed
Reduce unnecessary operations
1 parent 7a9fc6c commit e4af801

File tree

2 files changed

+14
-14
lines changed

2 files changed

+14
-14
lines changed

Source/Orts.Simulation/Simulation/RollingStocks/SubSystems/Door.cs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -183,22 +183,20 @@ public virtual void Update(float elapsedClockSeconds)
183183
switch(State)
184184
{
185185
case DoorState.Opening:
186-
ClosingTimer.Stop();
187186
if (!OpeningTimer.Started) OpeningTimer.Start();
188-
if (OpeningTimer.Triggered) State = DoorState.Open;
187+
if (OpeningTimer.Triggered)
188+
{
189+
State = DoorState.Open;
190+
OpeningTimer.Stop();
191+
}
189192
break;
190193
case DoorState.Closing:
191-
OpeningTimer.Stop();
192194
if (!ClosingTimer.Started) ClosingTimer.Start();
193-
if (ClosingTimer.Triggered) State = DoorState.Closed;
194-
break;
195-
case DoorState.Closed:
196-
ClosingTimer.Stop();
197-
OpeningTimer.Stop();
198-
break;
199-
case DoorState.Open:
200-
ClosingTimer.Stop();
201-
OpeningTimer.Stop();
195+
if (ClosingTimer.Triggered)
196+
{
197+
State = DoorState.Closed;
198+
ClosingTimer.Stop();
199+
}
202200
break;
203201
}
204202
}
@@ -215,6 +213,7 @@ public void SetDoor(bool open)
215213
case DoorState.Closing:
216214
if (!Locked && open)
217215
{
216+
ClosingTimer.Stop();
218217
State = DoorState.Opening;
219218
Wagon.SignalEvent(Event.DoorOpen);
220219
bool driverRightSide = (Side == DoorSide.Right) ^ Wagon.GetCabFlipped();
@@ -225,6 +224,7 @@ public void SetDoor(bool open)
225224
case DoorState.Opening:
226225
if (!open)
227226
{
227+
OpeningTimer.Stop();
228228
State = DoorState.Closing;
229229
Wagon.SignalEvent(Event.DoorClose);
230230
bool driverRightSide = (Side == DoorSide.Right) ^ Wagon.GetCabFlipped();

Source/RunActivity/Viewer3D/RollingStock/MSTSLocomotiveViewer.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2433,7 +2433,7 @@ public void HandleUserInput()
24332433
{
24342434
bool right = (Control.ControlType == CABViewControlTypes.ORTS_RIGHTDOOR) ^ Locomotive.Flipped ^ Locomotive.GetCabFlipped();
24352435
var state = Locomotive.Train.DoorState(right ? DoorSide.Right : DoorSide.Left);
2436-
int open = (state == DoorState.Opening || state == DoorState.Open) ? 1 : 0;
2436+
int open = state >= DoorState.Open ? 1 : 0;
24372437
if (open != ChangedValue(open))
24382438
{
24392439
if (right) new ToggleDoorsRightCommand(Viewer.Log);
@@ -3156,7 +3156,7 @@ public override void PrepareFrame(RenderFrame frame, ElapsedTime elapsedTime)
31563156
{
31573157
bool right = (p.Value.Type == CABViewControlTypes.RIGHTDOOR) ^ Locomotive.Flipped ^ Locomotive.GetCabFlipped();
31583158
var state = (right ? Locomotive.RightDoor : Locomotive.LeftDoor).State;
3159-
p.Value.UpdateState(state == DoorState.Open || state == DoorState.Opening, elapsedTime);
3159+
p.Value.UpdateState(state >= DoorState.Open, elapsedTime);
31603160
}
31613161
break;
31623162
case CABViewControlTypes.MIRRORS:

0 commit comments

Comments
 (0)