From a1ff95e80a77d665325f7dcf018e1c5b04b31ea8 Mon Sep 17 00:00:00 2001 From: Dustin Carlino Date: Tue, 17 Dec 2019 16:36:29 -0800 Subject: [PATCH] exploring the feasibility of recording prebaked savestates (to use for quick previews in edit mode). reduced size of savestates significantly by ommitting analytics... --- abstutil/src/io.rs | 4 ++++ abstutil/src/lib.rs | 3 ++- game/src/challenges.rs | 6 ++++-- game/src/render/map.rs | 1 - sim/src/analytics.rs | 6 ++++++ sim/src/sim.rs | 40 +++++++++++++++++++++++++++++++++++++++- 6 files changed, 55 insertions(+), 5 deletions(-) diff --git a/abstutil/src/io.rs b/abstutil/src/io.rs index 7dc628a399..c9a76252ee 100644 --- a/abstutil/src/io.rs +++ b/abstutil/src/io.rs @@ -77,6 +77,10 @@ fn maybe_write_binary(path: &str, obj: &T) -> Result<(), Error> { bincode::serialize_into(file, obj).map_err(|err| Error::new(ErrorKind::Other, err)) } +pub fn serialized_size_bytes(obj: &T) -> usize { + bincode::serialized_size(obj).unwrap() as usize +} + pub fn write_binary(path: String, obj: &T) { if let Err(err) = maybe_write_binary(&path, obj) { panic!("Can't write_binary({}): {}", path, err); diff --git a/abstutil/src/lib.rs b/abstutil/src/lib.rs index 44a9ad39b9..b7e5684814 100644 --- a/abstutil/src/lib.rs +++ b/abstutil/src/lib.rs @@ -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}; diff --git a/game/src/challenges.rs b/game/src/challenges.rs index 1e8410e57f..5fb679fc6b 100644 --- a/game/src/challenges.rs +++ b/game/src/challenges.rs @@ -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); diff --git a/game/src/render/map.rs b/game/src/render/map.rs index fc1f4dcfed..b8e49cc16c 100644 --- a/game/src/render/map.rs +++ b/game/src/render/map.rs @@ -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 { diff --git a/sim/src/analytics.rs b/sim/src/analytics.rs index bb46758453..30442c3ba0 100644 --- a/sim/src/analytics.rs +++ b/sim/src/analytics.rs @@ -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