mirror of
https://github.com/a-b-street/abstreet.git
synced 2024-12-26 07:52:05 +03:00
make time travel plugin handle loading savestates
This commit is contained in:
parent
9368c42c6e
commit
1ce55ada04
@ -9,6 +9,7 @@ use std::collections::BTreeMap;
|
||||
pub struct TimeTravel {
|
||||
state_per_tick: Vec<StateAtTime>,
|
||||
current_tick: Option<Tick>,
|
||||
// Determines the tick of state_per_tick[0]
|
||||
first_tick: Tick,
|
||||
}
|
||||
|
||||
@ -20,11 +21,11 @@ struct StateAtTime {
|
||||
}
|
||||
|
||||
impl TimeTravel {
|
||||
pub fn new(first_tick: Tick) -> TimeTravel {
|
||||
pub fn new() -> TimeTravel {
|
||||
TimeTravel {
|
||||
state_per_tick: Vec::new(),
|
||||
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() {
|
||||
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 {
|
||||
cars: BTreeMap::new(),
|
||||
|
@ -227,7 +227,6 @@ impl PerMapUI {
|
||||
let steepness_viz = plugins::steep::SteepnessVisualizer::new(&map);
|
||||
let neighborhood_summary =
|
||||
plugins::neighborhood_summary::NeighborhoodSummary::new(&map, &draw_map, &mut timer);
|
||||
let time_travel = plugins::time_travel::TimeTravel::new(sim.time);
|
||||
|
||||
timer.done();
|
||||
|
||||
@ -248,7 +247,7 @@ impl PerMapUI {
|
||||
Box::new(StopSignEditor::new()),
|
||||
Box::new(TrafficSignalEditor::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::follow::FollowState::new()),
|
||||
Box::new(plugins::show_route::ShowRouteState::new()),
|
||||
|
Loading…
Reference in New Issue
Block a user