centralize a little more path building in abstutil

This commit is contained in:
Dustin Carlino 2019-12-02 20:49:55 -08:00
parent 720f9b8b30
commit 6170792328
6 changed files with 13 additions and 21 deletions

View File

@ -47,7 +47,6 @@ pub const AB_TESTS: &str = "ab_tests";
pub const AB_TEST_SAVES: &str = "ab_test_saves";
pub const EDITS: &str = "edits";
pub const NEIGHBORHOODS: &str = "neighborhoods";
pub const POLYGONS: &str = "polygons";
pub const SAVE: &str = "save";
pub const SCENARIOS: &str = "scenarios";
pub const SHORTCUTS: &str = "shortcuts";
@ -56,14 +55,6 @@ pub fn path1(map_name: &str, category: &str, dir: &str) -> String {
format!("../data/{}/{}/{}", category, map_name, dir)
}
pub fn path1_json(map_name: &str, category: &str, instance: &str) -> String {
format!("../data/{}/{}/{}.json", category, map_name, instance)
}
pub fn path1_bin(map_name: &str, category: &str, instance: &str) -> String {
format!("../data/{}/{}/{}.bin", category, map_name, instance)
}
pub fn path2_dir(map_name: &str, category: &str, dir: &str) -> String {
format!("../data/{}/{}/{}/", category, map_name, dir)
}
@ -103,3 +94,11 @@ pub fn path_prebaked_results(map_name: &str) -> String {
pub fn path_shortcut(name: &str) -> String {
format!("../data/shortcuts/{}.json", name)
}
pub fn path_scenario(map_name: &str, scenario_name: &str) -> String {
format!("../data/scenarios/{}/{}.bin", map_name, scenario_name)
}
pub fn path_edits(map_name: &str, edits_name: &str) -> String {
format!("../data/edits/{}/{}.json", map_name, edits_name)
}

View File

@ -123,7 +123,7 @@ fn launch_test(test: &ABTest, ui: &mut UI, ctx: &mut EventCtx) -> ABTestMode {
&format!("Launching A/B test {}", test.test_name),
|ctx, mut timer| {
let scenario: Scenario = abstutil::read_binary(
&abstutil::path1_bin(&test.map_name, abstutil::SCENARIOS, &test.scenario_name),
&abstutil::path_scenario(&test.map_name, &test.scenario_name),
&mut timer,
);

View File

@ -213,11 +213,7 @@ pub fn prebake() {
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",
),
load: abstutil::path_scenario(map_name, "weekday_typical_traffic_from_psrc"),
use_map_fixes: true,
rng_seed: Some(42),
opts: SimOptions::new("prebaked"),

View File

@ -69,7 +69,7 @@ fn load_scenario(wiz: &mut Wizard, ctx: &mut EventCtx, ui: &mut UI) -> Option<Tr
abstutil::list_all_objects(abstutil::SCENARIOS, &map_name)
})?;
let scenario = abstutil::read_binary(
&abstutil::path1_bin(&map_name, abstutil::SCENARIOS, &s),
&abstutil::path_scenario(&map_name, &s),
&mut Timer::throwaway(),
);
Some(Transition::Replace(Box::new(

View File

@ -75,7 +75,7 @@ impl GameplayMode {
s
} else {
abstutil::read_binary(
&abstutil::path1_bin(&ui.primary.map.get_name(), abstutil::SCENARIOS, &name),
&abstutil::path_scenario(&ui.primary.map.get_name(), &name),
timer,
)
})

View File

@ -73,10 +73,7 @@ impl MapEdits {
if edits_name == "no_edits" {
return MapEdits::new(map_name.to_string());
}
abstutil::read_json(
&abstutil::path1_json(map_name, abstutil::EDITS, edits_name),
timer,
)
abstutil::read_json(&abstutil::path_edits(map_name, edits_name), timer)
}
// TODO Version these