mirror of
https://github.com/a-b-street/abstreet.git
synced 2024-11-28 20:29:04 +03:00
savestate regularly
This commit is contained in:
parent
891b07bec4
commit
fe8a28ff34
@ -8,7 +8,7 @@
|
||||
- document pieces that're stabilizing
|
||||
- run clippy everywhere
|
||||
- presubmit script
|
||||
- also enforce consistent style (import order, extern crate only in mod.rs or lib.rs, derive order)
|
||||
- also enforce consistent style (import order, extern crate only in mod.rs or lib.rs, derive order, struct initialization order)
|
||||
|
||||
## Conga line idea
|
||||
|
||||
|
@ -64,7 +64,7 @@ fn main() {
|
||||
let mut benchmark = sim.start_benchmark();
|
||||
loop {
|
||||
sim.step(&map, &control_map);
|
||||
if sim.time.is_multiple_of_minute() {
|
||||
if sim.time.is_multiple_of(sim::Tick::from_secs(60)) {
|
||||
let speed = sim.measure_speed(&mut benchmark);
|
||||
println!("{0}, speed = {1:.2}x", sim.summary(), speed);
|
||||
}
|
||||
|
@ -79,8 +79,8 @@ impl Tick {
|
||||
Tick(0)
|
||||
}
|
||||
|
||||
pub fn from_raw(ticks: u32) -> Tick {
|
||||
Tick(ticks)
|
||||
pub fn from_seconds(secs: u32) -> Tick {
|
||||
Tick(10 * secs)
|
||||
}
|
||||
|
||||
pub fn parse(string: &str) -> Option<Tick> {
|
||||
@ -124,9 +124,8 @@ impl Tick {
|
||||
Tick(self.0 + 1)
|
||||
}
|
||||
|
||||
// TODO er, little weird
|
||||
pub fn is_multiple_of_minute(&self) -> bool {
|
||||
self.0 % 600 == 0
|
||||
pub fn is_multiple_of(&self, other: Tick) -> bool {
|
||||
self.0 % other.0 == 0
|
||||
}
|
||||
|
||||
fn get_parts(&self) -> (u32, u32, u32, u32) {
|
||||
|
@ -29,6 +29,8 @@ pub struct Sim {
|
||||
pub time: Tick,
|
||||
pub(crate) map_name: String,
|
||||
scenario_name: String,
|
||||
// TODO not quite the right type to represent durations
|
||||
savestate_every: Option<Tick>,
|
||||
|
||||
spawner: Spawner,
|
||||
intersection_state: IntersectionSimState,
|
||||
@ -40,7 +42,8 @@ pub struct Sim {
|
||||
}
|
||||
|
||||
impl Sim {
|
||||
pub fn new(map: &Map, scenario_name: String, rng_seed: Option<u8>) -> Sim {
|
||||
// TODO Options struct might be nicer, especially since we could glue it to structopt?
|
||||
pub fn new(map: &Map, scenario_name: String, rng_seed: Option<u8>, savestate_every: Option<Tick>) -> Sim {
|
||||
let mut rng = XorShiftRng::from_entropy();
|
||||
if let Some(seed) = rng_seed {
|
||||
rng = XorShiftRng::from_seed([seed; 16]);
|
||||
@ -56,6 +59,7 @@ impl Sim {
|
||||
time: Tick::zero(),
|
||||
map_name: map.get_name().to_string(),
|
||||
scenario_name,
|
||||
savestate_every,
|
||||
car_properties: BTreeMap::new(),
|
||||
}
|
||||
}
|
||||
@ -209,6 +213,13 @@ impl Sim {
|
||||
self.intersection_state
|
||||
.step(self.time, map, control_map, info);
|
||||
|
||||
// Savestate?
|
||||
if let Some(t) = self.savestate_every {
|
||||
if self.time.is_multiple_of(t) {
|
||||
self.save();
|
||||
}
|
||||
}
|
||||
|
||||
cars_parked_this_step
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user