make time travel plugin handle loading savestates

This commit is contained in:
Dustin Carlino 2018-11-23 10:48:29 -08:00
parent 9368c42c6e
commit 1ce55ada04
2 changed files with 9 additions and 5 deletions

View File

@ -9,6 +9,7 @@ use std::collections::BTreeMap;
pub struct TimeTravel { pub struct TimeTravel {
state_per_tick: Vec<StateAtTime>, state_per_tick: Vec<StateAtTime>,
current_tick: Option<Tick>, current_tick: Option<Tick>,
// Determines the tick of state_per_tick[0]
first_tick: Tick, first_tick: Tick,
} }
@ -20,11 +21,11 @@ struct StateAtTime {
} }
impl TimeTravel { impl TimeTravel {
pub fn new(first_tick: Tick) -> TimeTravel { pub fn new() -> TimeTravel {
TimeTravel { TimeTravel {
state_per_tick: Vec::new(), state_per_tick: Vec::new(),
current_tick: None, current_tick: None,
first_tick, first_tick: Tick::zero(),
} }
} }
@ -38,7 +39,11 @@ impl TimeTravel {
if tick + 1 == self.first_tick.as_usize() + self.state_per_tick.len() { if tick + 1 == self.first_tick.as_usize() + self.state_per_tick.len() {
return; return;
} }
assert_eq!(tick, self.first_tick.as_usize() + self.state_per_tick.len()); if tick != self.first_tick.as_usize() + self.state_per_tick.len() {
// We just loaded a new savestate or something. Clear out our memory.
self.state_per_tick.clear();
self.first_tick = sim.time;
}
let mut state = StateAtTime { let mut state = StateAtTime {
cars: BTreeMap::new(), cars: BTreeMap::new(),

View File

@ -227,7 +227,6 @@ impl PerMapUI {
let steepness_viz = plugins::steep::SteepnessVisualizer::new(&map); let steepness_viz = plugins::steep::SteepnessVisualizer::new(&map);
let neighborhood_summary = let neighborhood_summary =
plugins::neighborhood_summary::NeighborhoodSummary::new(&map, &draw_map, &mut timer); plugins::neighborhood_summary::NeighborhoodSummary::new(&map, &draw_map, &mut timer);
let time_travel = plugins::time_travel::TimeTravel::new(sim.time);
timer.done(); timer.done();
@ -248,7 +247,7 @@ impl PerMapUI {
Box::new(StopSignEditor::new()), Box::new(StopSignEditor::new()),
Box::new(TrafficSignalEditor::new()), Box::new(TrafficSignalEditor::new()),
Box::new(plugins::turn_cycler::TurnCyclerState::new()), Box::new(plugins::turn_cycler::TurnCyclerState::new()),
Box::new(time_travel), Box::new(plugins::time_travel::TimeTravel::new()),
Box::new(plugins::debug_objects::DebugObjectsState::new()), Box::new(plugins::debug_objects::DebugObjectsState::new()),
Box::new(plugins::follow::FollowState::new()), Box::new(plugins::follow::FollowState::new()),
Box::new(plugins::show_route::ShowRouteState::new()), Box::new(plugins::show_route::ShowRouteState::new()),