prebake results per map, and store in binary

This commit is contained in:
Dustin Carlino 2019-11-05 10:15:44 -08:00
parent c54842faff
commit 3b1a659f15
5 changed files with 35 additions and 19 deletions

2
.gitignore vendored
View File

@ -10,7 +10,7 @@ data/input/*
data/maps/*
data/neighborhoods/*
data/raw_maps/*
data/prebaked_results.json
data/prebaked_results/*
data/save/*
data/scenarios/*
data/screenshots/*/*.png

View File

@ -96,6 +96,10 @@ pub fn path_pending_screenshots(map_name: &str) -> String {
format!("../data/screenshots/pending_{}", map_name)
}
pub fn path_prebaked_results(map_name: &str) -> String {
format!("../data/prebaked_results/{}.bin", map_name)
}
pub fn path_shortcut(name: &str) -> String {
format!("../data/shortcuts/{}.json", name)
}

View File

@ -132,20 +132,26 @@ impl State for ChallengeSplash {
pub fn prebake() {
let mut timer = Timer::new("prebake all challenge results");
timer.start("run normal sim");
let (map, mut sim, _) = SimFlags {
load: abstutil::path1_bin(
"montlake",
abstutil::SCENARIOS,
"weekday_typical_traffic_from_psrc",
),
use_map_fixes: true,
rng_seed: Some(42),
opts: SimOptions::new("prebaked"),
}
.load(&mut timer);
sim.timed_step(&map, Duration::END_OF_DAY, &mut timer);
timer.stop("run normal sim");
for map_name in vec!["montlake", "23rd"] {
timer.start(&format!("run normal sim for {}", map_name));
let (map, mut sim, _) = SimFlags {
load: abstutil::path1_bin(
map_name,
abstutil::SCENARIOS,
"weekday_typical_traffic_from_psrc",
),
use_map_fixes: true,
rng_seed: Some(42),
opts: SimOptions::new("prebaked"),
}
.load(&mut timer);
sim.timed_step(&map, Duration::END_OF_DAY, &mut timer);
timer.stop(&format!("run normal sim for {}", map_name));
abstutil::write_json("../data/prebaked_results.json", sim.get_analytics()).unwrap();
abstutil::write_binary(
&abstutil::path_prebaked_results(map_name),
sim.get_analytics(),
)
.unwrap();
}
}

View File

@ -47,8 +47,14 @@ enum State {
impl GameplayState {
pub fn initialize(mode: GameplayMode, ui: &mut UI, ctx: &mut EventCtx) -> GameplayState {
let prebaked: Analytics =
abstutil::read_json("../data/prebaked_results.json", &mut Timer::throwaway()).unwrap();
let prebaked: Analytics = abstutil::read_binary(
&abstutil::path_prebaked_results(ui.primary.map.get_name()),
&mut Timer::throwaway(),
)
.unwrap_or_else(|_| {
println!("WARNING! No prebaked sim analytics. Only freeform mode will work.");
Analytics::new()
});
let (state, maybe_scenario) = match mode.clone() {
GameplayMode::Freeform => (

View File

@ -6,7 +6,7 @@ function common_release {
cp docs/INSTRUCTIONS.md $OUT
mkdir $OUT/data
cp data/color_scheme.json data/prebaked_results.json $OUT/data
cp -Rv data/color_scheme.json data/prebaked_results $OUT/data
mkdir $OUT/data/maps
for map in 23rd ballard caphill downtown montlake; do