mirror of
https://github.com/a-b-street/abstreet.git
synced 2024-12-25 23:43:25 +03:00
load named map edits, not a single one
This commit is contained in:
parent
f30dae570c
commit
72d0294efb
@ -61,12 +61,22 @@ struct Flags {
|
||||
/// Scenario name for savestating
|
||||
#[structopt(long = "scenario_name", default_value = "editor")]
|
||||
scenario_name: String,
|
||||
|
||||
/// Name of map edits
|
||||
#[structopt(long = "edits_name", default_value = "no_edits")]
|
||||
edits_name: String,
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let flags = Flags::from_args();
|
||||
ezgui::run(
|
||||
ui::UIWrapper::new(flags.load, flags.scenario_name, flags.rng_seed, flags.kml),
|
||||
ui::UIWrapper::new(
|
||||
flags.load,
|
||||
flags.scenario_name,
|
||||
flags.edits_name,
|
||||
flags.rng_seed,
|
||||
flags.kml,
|
||||
),
|
||||
"A/B Street",
|
||||
1024,
|
||||
768,
|
||||
|
@ -68,6 +68,7 @@ impl UIWrapper {
|
||||
pub fn new(
|
||||
load: String,
|
||||
scenario_name: String,
|
||||
edits_name: String,
|
||||
rng_seed: Option<u8>,
|
||||
kml: Option<String>,
|
||||
) -> UIWrapper {
|
||||
@ -78,6 +79,7 @@ impl UIWrapper {
|
||||
let (map, control_map, sim) = sim::load(
|
||||
load,
|
||||
scenario_name,
|
||||
edits_name,
|
||||
rng_seed,
|
||||
Some(sim::Tick::from_seconds(30)),
|
||||
);
|
||||
@ -384,10 +386,11 @@ impl UI {
|
||||
// TODO maybe make state line up with the map, so loading from a new map doesn't break
|
||||
abstutil::write_json("editor_state", &state).expect("Saving editor_state failed");
|
||||
abstutil::write_json("color_scheme", &self.cs).expect("Saving color_scheme failed");
|
||||
// TODO do this from a plugin!
|
||||
abstutil::write_json(
|
||||
"map_edits.json",
|
||||
&format!("../data/edits/{}/ui.json", self.map.get_name()),
|
||||
&MapEdits {
|
||||
edits_name: "nameless".to_string(),
|
||||
edits_name: "ui".to_string(),
|
||||
map_name: self.map.get_name().to_string(),
|
||||
road_edits: self.road_editor.get_edits().clone(),
|
||||
stop_signs: self.control_map.get_stop_signs_savestate(),
|
||||
|
@ -36,6 +36,10 @@ struct Flags {
|
||||
/// Scenario name for savestating
|
||||
#[structopt(long = "scenario_name", default_value = "headless")]
|
||||
scenario_name: String,
|
||||
|
||||
/// Name of map edits
|
||||
#[structopt(long = "edits_name", default_value = "no_edits")]
|
||||
edits_name: String,
|
||||
}
|
||||
|
||||
fn main() {
|
||||
@ -47,6 +51,7 @@ fn main() {
|
||||
let (map, control_map, mut sim) = sim::load(
|
||||
flags.load.clone(),
|
||||
flags.scenario_name,
|
||||
flags.edits_name,
|
||||
flags.rng_seed,
|
||||
Some(sim::Tick::from_seconds(30)),
|
||||
);
|
||||
|
@ -15,7 +15,7 @@ pub struct MapEdits {
|
||||
impl MapEdits {
|
||||
pub fn new() -> MapEdits {
|
||||
MapEdits {
|
||||
edits_name: "unnamed".to_string(),
|
||||
edits_name: "no_edits".to_string(),
|
||||
map_name: "TODO".to_string(), // TODO er
|
||||
road_edits: RoadEdits::new(),
|
||||
stop_signs: BTreeMap::new(),
|
||||
|
@ -11,18 +11,20 @@ use {CarID, Event, MapEdits, PedestrianID, RouteID, Scenario, Sim, Tick};
|
||||
pub fn load(
|
||||
input: String,
|
||||
scenario_name: String,
|
||||
edits_name: String,
|
||||
rng_seed: Option<u8>,
|
||||
savestate_every: Option<Tick>,
|
||||
) -> (Map, ControlMap, Sim) {
|
||||
// TODO read a specific one
|
||||
let edits: MapEdits = abstutil::read_json("map_edits.json").unwrap_or(MapEdits::new());
|
||||
|
||||
if input.contains("data/save/") {
|
||||
info!("Resuming from {}", input);
|
||||
flame::start("read sim savestate");
|
||||
let sim: Sim = abstutil::read_json(&input).expect("loading sim state failed");
|
||||
flame::end("read sim savestate");
|
||||
// TODO assuming the relative path :(
|
||||
let edits: MapEdits = abstutil::read_json(&format!(
|
||||
"../data/edits/{}/{}.json",
|
||||
sim.map_name, edits_name
|
||||
)).unwrap_or(MapEdits::new());
|
||||
let map_path = format!("../data/maps/{}.abst", sim.map_name);
|
||||
let map = Map::new(&map_path, edits.road_edits.clone())
|
||||
.expect(&format!("Couldn't load map from {}", map_path));
|
||||
@ -31,6 +33,10 @@ pub fn load(
|
||||
} else if input.contains("data/scenarios/") {
|
||||
info!("Seeding the simulation from scenario {}", input);
|
||||
let scenario: Scenario = abstutil::read_json(&input).expect("loading scenario failed");
|
||||
let edits: MapEdits = abstutil::read_json(&format!(
|
||||
"../data/edits/{}/{}.json",
|
||||
scenario.map_name, edits_name
|
||||
)).unwrap_or(MapEdits::new());
|
||||
let map_path = format!("../data/maps/{}.abst", scenario.map_name);
|
||||
let map = Map::new(&map_path, edits.road_edits.clone())
|
||||
.expect(&format!("Couldn't load map from {}", map_path));
|
||||
@ -44,7 +50,15 @@ pub fn load(
|
||||
scenario.instantiate(&mut sim, &map);
|
||||
(map, control_map, sim)
|
||||
} else {
|
||||
// TODO relative dir is brittle; match more cautiously
|
||||
let map_name = input
|
||||
.trim_left_matches("../data/maps/")
|
||||
.trim_right_matches(".abst")
|
||||
.to_string();
|
||||
info!("Loading map {}", input);
|
||||
let edits: MapEdits =
|
||||
abstutil::read_json(&format!("../data/edits/{}/{}.json", map_name, edits_name))
|
||||
.unwrap_or(MapEdits::new());
|
||||
let map = Map::new(&input, edits.road_edits.clone()).expect("Couldn't load map");
|
||||
let control_map = ControlMap::new(&map, &edits.stop_signs, &edits.traffic_signals);
|
||||
flame::start("create sim");
|
||||
|
@ -8,6 +8,7 @@ fn aorta_model_completes() {
|
||||
let (map, control_map, mut sim) = sim::load(
|
||||
"../data/maps/small.abst".to_string(),
|
||||
"aorta_model_completes".to_string(),
|
||||
"no_edits".to_string(),
|
||||
Some(42),
|
||||
Some(sim::Tick::from_seconds(30)),
|
||||
);
|
||||
|
@ -8,6 +8,7 @@ fn serialization() {
|
||||
let (map, _, mut sim) = sim::load(
|
||||
"../data/maps/small.abst".to_string(),
|
||||
"serialization".to_string(),
|
||||
"no_edits".to_string(),
|
||||
Some(42),
|
||||
None,
|
||||
);
|
||||
@ -25,6 +26,7 @@ fn from_scratch() {
|
||||
let (map, control_map, mut sim1) = sim::load(
|
||||
"../data/maps/small.abst".to_string(),
|
||||
"from_scratch_1".to_string(),
|
||||
"no_edits".to_string(),
|
||||
Some(42),
|
||||
None,
|
||||
);
|
||||
@ -52,6 +54,7 @@ fn with_savestating() {
|
||||
let (map, control_map, mut sim1) = sim::load(
|
||||
"../data/maps/small.abst".to_string(),
|
||||
"with_savestating_1".to_string(),
|
||||
"no_edits".to_string(),
|
||||
Some(42),
|
||||
None,
|
||||
);
|
||||
|
@ -8,6 +8,7 @@ fn bus_reaches_stops() {
|
||||
let (map, control_map, mut sim) = sim::load(
|
||||
"../data/maps/small.abst".to_string(),
|
||||
"bus_reaches_stops".to_string(),
|
||||
"no_edits".to_string(),
|
||||
Some(42),
|
||||
Some(sim::Tick::from_seconds(30)),
|
||||
);
|
||||
@ -36,6 +37,7 @@ fn ped_uses_bus() {
|
||||
let (map, control_map, mut sim) = sim::load(
|
||||
"../data/maps/small.abst".to_string(),
|
||||
"bus_reaches_stops".to_string(),
|
||||
"no_edits".to_string(),
|
||||
Some(42),
|
||||
Some(sim::Tick::from_seconds(30)),
|
||||
);
|
||||
|
Loading…
Reference in New Issue
Block a user