mirror of
https://github.com/a-b-street/abstreet.git
synced 2024-12-25 07:25:47 +03:00
exploring the feasibility of recording prebaked savestates (to use for
quick previews in edit mode). reduced size of savestates significantly by ommitting analytics...
This commit is contained in:
parent
892e0592e1
commit
a1ff95e80a
@ -77,6 +77,10 @@ fn maybe_write_binary<T: Serialize>(path: &str, obj: &T) -> Result<(), Error> {
|
||||
bincode::serialize_into(file, obj).map_err(|err| Error::new(ErrorKind::Other, err))
|
||||
}
|
||||
|
||||
pub fn serialized_size_bytes<T: Serialize>(obj: &T) -> usize {
|
||||
bincode::serialized_size(obj).unwrap() as usize
|
||||
}
|
||||
|
||||
pub fn write_binary<T: Serialize>(path: String, obj: &T) {
|
||||
if let Err(err) = maybe_write_binary(&path, obj) {
|
||||
panic!("Can't write_binary({}): {}", path, err);
|
||||
|
@ -17,7 +17,8 @@ pub use crate::error::Error;
|
||||
pub use crate::io::{
|
||||
basename, deserialize_btreemap, deserialize_multimap, find_next_file, find_prev_file,
|
||||
list_all_objects, load_all_objects, maybe_read_binary, maybe_read_json, read_binary, read_json,
|
||||
serialize_btreemap, serialize_multimap, to_json, write_binary, write_json, FileWithProgress,
|
||||
serialize_btreemap, serialize_multimap, serialized_size_bytes, to_json, write_binary,
|
||||
write_json, FileWithProgress,
|
||||
};
|
||||
pub use crate::logs::Warn;
|
||||
pub use crate::random::{fork_rng, WeightedUsizeChoice};
|
||||
|
@ -8,7 +8,7 @@ use ezgui::{
|
||||
hotkey, Choice, Color, EventCtx, GfxCtx, HorizontalAlignment, Key, Line, ModalMenu, Text,
|
||||
VerticalAlignment,
|
||||
};
|
||||
use geom::Time;
|
||||
use geom::{Duration, Time};
|
||||
use sim::{Sim, SimFlags, SimOptions, TripMode};
|
||||
use std::collections::{BTreeMap, HashSet};
|
||||
|
||||
@ -279,7 +279,9 @@ pub fn prebake() {
|
||||
scenario.map_name, scenario.scenario_name
|
||||
));
|
||||
|
||||
let mut sim = Sim::new(&map, SimOptions::new("prebaked"), &mut timer);
|
||||
let mut opts = SimOptions::new("prebaked");
|
||||
opts.savestate_every = Some(Duration::hours(1));
|
||||
let mut sim = Sim::new(&map, opts, &mut timer);
|
||||
// Bit of an abuse of this, but just need to fix the rng seed.
|
||||
let mut rng = SimFlags::for_test("prebaked").make_rng();
|
||||
scenario.instantiate(&mut sim, &map, &mut rng, &mut timer);
|
||||
|
@ -386,7 +386,6 @@ fn osm_rank_to_color(cs: &ColorScheme, rank: usize) -> Color {
|
||||
}
|
||||
}
|
||||
|
||||
// TODO Show a little legend when it's first activated.
|
||||
// TODO ETA till goal...
|
||||
#[derive(Clone, Copy, PartialEq)]
|
||||
pub enum AgentColorScheme {
|
||||
|
@ -478,6 +478,12 @@ impl Analytics {
|
||||
}
|
||||
}
|
||||
|
||||
impl Default for Analytics {
|
||||
fn default() -> Analytics {
|
||||
Analytics::new()
|
||||
}
|
||||
}
|
||||
|
||||
pub struct TripPhase {
|
||||
pub start_time: Time,
|
||||
pub end_time: Option<Time>,
|
||||
|
@ -50,8 +50,10 @@ pub struct Sim {
|
||||
#[derivative(PartialEq = "ignore")]
|
||||
#[serde(skip_serializing, skip_deserializing)]
|
||||
trip_positions: Option<TripPositions>,
|
||||
// TODO Maybe the buffered events in child objects should also have this.
|
||||
// Don't serialize, to reduce prebaked savestate size. Analytics are saved once covering the
|
||||
// full day and can be trimmed to any time.
|
||||
#[derivative(PartialEq = "ignore")]
|
||||
#[serde(skip_serializing, skip_deserializing)]
|
||||
analytics: Analytics,
|
||||
}
|
||||
|
||||
@ -723,6 +725,42 @@ impl Sim {
|
||||
}
|
||||
|
||||
pub fn save(&self) -> String {
|
||||
if true {
|
||||
println!("sim savestate breakdown:");
|
||||
println!(
|
||||
"- driving: {} bytes",
|
||||
abstutil::prettyprint_usize(abstutil::serialized_size_bytes(&self.driving))
|
||||
);
|
||||
println!(
|
||||
"- parking: {} bytes",
|
||||
abstutil::prettyprint_usize(abstutil::serialized_size_bytes(&self.parking))
|
||||
);
|
||||
println!(
|
||||
"- walking: {} bytes",
|
||||
abstutil::prettyprint_usize(abstutil::serialized_size_bytes(&self.walking))
|
||||
);
|
||||
println!(
|
||||
"- intersections: {} bytes",
|
||||
abstutil::prettyprint_usize(abstutil::serialized_size_bytes(&self.intersections))
|
||||
);
|
||||
println!(
|
||||
"- transit: {} bytes",
|
||||
abstutil::prettyprint_usize(abstutil::serialized_size_bytes(&self.transit))
|
||||
);
|
||||
println!(
|
||||
"- trips: {} bytes",
|
||||
abstutil::prettyprint_usize(abstutil::serialized_size_bytes(&self.trips))
|
||||
);
|
||||
println!(
|
||||
"- spawner: {} bytes",
|
||||
abstutil::prettyprint_usize(abstutil::serialized_size_bytes(&self.spawner))
|
||||
);
|
||||
println!(
|
||||
"- scheduler: {} bytes",
|
||||
abstutil::prettyprint_usize(abstutil::serialized_size_bytes(&self.scheduler))
|
||||
);
|
||||
}
|
||||
|
||||
let path = self.save_path(self.time);
|
||||
abstutil::write_binary(path.clone(), self);
|
||||
path
|
||||
|
Loading…
Reference in New Issue
Block a user