Skip to content

Commit

Permalink
Safer fallback when state is not found
Browse files Browse the repository at this point in the history
  • Loading branch information
cam72cam committed Oct 9, 2023
1 parent 0304887 commit 7320c49
Showing 1 changed file with 10 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -88,18 +88,19 @@ public void simulateTick(int iteration) {
for (EntityCoupleableRollingStock stock : loaded) {

if (!stateMap.containsKey(stock.getUUID())) {
if (stock.states.isEmpty()) {
for (SimulationState state : stock.states) {
int stateIteration = state.tickID - tickID;
if (stateIteration >= 0) {
state.update(stock);
stateMaps.get(stateIteration).put(stock.getUUID(), state);
}
}

if (!stateMap.containsKey(stock.getUUID())) {
// This should only ever happen right after stock is placed.
SimulationState state = new SimulationState(stock);
state.tickID = tickID;
stateMap.put(stock.getUUID(), state);
} else {
for (SimulationState state : stock.states) {
int stateIteration = state.tickID - tickID;
if (stateIteration >= 0) {
state.update(stock);
stateMaps.get(stateIteration).put(stock.getUUID(), state);
}
}
}
}

Expand Down

0 comments on commit 7320c49

Please sign in to comment.