mirror of
https://github.com/a-b-street/abstreet.git
synced 2024-11-28 20:29:04 +03:00
load from map or savestate
This commit is contained in:
parent
f0a60e434d
commit
891b07bec4
@ -46,9 +46,9 @@ use structopt::StructOpt;
|
||||
#[derive(StructOpt, Debug)]
|
||||
#[structopt(name = "editor")]
|
||||
struct Flags {
|
||||
/// ABST input to load
|
||||
#[structopt(name = "abst_input")]
|
||||
abst_input: String,
|
||||
/// Map or savestate to load
|
||||
#[structopt(name = "load")]
|
||||
load: String,
|
||||
|
||||
/// Optional RNG seed
|
||||
#[structopt(long = "rng_seed")]
|
||||
@ -62,10 +62,6 @@ struct Flags {
|
||||
#[structopt(long = "kml")]
|
||||
kml: Option<String>,
|
||||
|
||||
/// Optional savestate to load
|
||||
#[structopt(long = "load_from")]
|
||||
load_from: Option<String>,
|
||||
|
||||
/// Scenario name for savestating
|
||||
#[structopt(long = "scenario_name", default_value = "editor")]
|
||||
scenario_name: String,
|
||||
@ -109,12 +105,11 @@ fn main() {
|
||||
gl,
|
||||
glyphs,
|
||||
ui::UI::new(
|
||||
&flags.abst_input,
|
||||
flags.load,
|
||||
flags.scenario_name,
|
||||
window_size,
|
||||
flags.rng_seed,
|
||||
flags.kml,
|
||||
flags.load_from,
|
||||
window_size,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
@ -20,9 +20,9 @@ pub struct SimController {
|
||||
}
|
||||
|
||||
impl SimController {
|
||||
pub fn new(map: &Map, scenario_name: String, rng_seed: Option<u8>) -> SimController {
|
||||
pub fn new(sim: Sim) -> SimController {
|
||||
SimController {
|
||||
sim: Sim::new(map, scenario_name, rng_seed),
|
||||
sim,
|
||||
desired_speed: 1.0,
|
||||
last_step: None,
|
||||
benchmark: None,
|
||||
|
@ -15,7 +15,7 @@ use graphics::types::Color;
|
||||
use gui;
|
||||
use kml;
|
||||
use map_model;
|
||||
use map_model::{Edits, IntersectionID};
|
||||
use map_model::IntersectionID;
|
||||
use piston::input::{Key, MouseCursorEvent};
|
||||
use piston::window::Size;
|
||||
use plugins::classification::OsmClassifier;
|
||||
@ -32,6 +32,7 @@ use plugins::traffic_signal_editor::TrafficSignalEditor;
|
||||
use plugins::turn_colors::TurnColors;
|
||||
use plugins::warp::WarpState;
|
||||
use render;
|
||||
use sim;
|
||||
use sim::{CarID, CarState, PedestrianID};
|
||||
use std::collections::HashMap;
|
||||
use std::process;
|
||||
@ -80,17 +81,13 @@ pub struct UI {
|
||||
|
||||
impl UI {
|
||||
pub fn new(
|
||||
abst_path: &str,
|
||||
load: String,
|
||||
scenario_name: String,
|
||||
window_size: Size,
|
||||
rng_seed: Option<u8>,
|
||||
kml: Option<String>,
|
||||
load_sim_from: Option<String>,
|
||||
window_size: Size,
|
||||
) -> UI {
|
||||
let edits: Edits = abstutil::read_json("road_edits.json").unwrap_or(Edits::new());
|
||||
|
||||
println!("Opening {}", abst_path);
|
||||
let map = map_model::Map::new(abst_path, &edits).expect("Couldn't load map");
|
||||
let (map, edits, control_map, sim) = sim::load(load, scenario_name, rng_seed);
|
||||
|
||||
let extra_shapes = if let Some(path) = kml {
|
||||
kml::load(&path, &map.get_gps_bounds()).expect("Couldn't load extra KML shapes")
|
||||
@ -98,16 +95,11 @@ impl UI {
|
||||
Vec::new()
|
||||
};
|
||||
|
||||
let control_map = ControlMap::new(&map);
|
||||
let (draw_map, center_pt) = render::DrawMap::new(&map, &control_map, extra_shapes);
|
||||
|
||||
let steepness_viz = SteepnessVisualizer::new(&map);
|
||||
let turn_colors = TurnColors::new(&control_map);
|
||||
let mut sim_ctrl = SimController::new(&map, scenario_name, rng_seed);
|
||||
if let Some(path) = load_sim_from {
|
||||
sim_ctrl.sim = abstutil::read_json(&path).expect("loading sim state failed");
|
||||
println!("Loaded {}", path);
|
||||
}
|
||||
let sim_ctrl = SimController::new(sim);
|
||||
|
||||
let mut ui = UI {
|
||||
map,
|
||||
|
@ -12,9 +12,9 @@ use structopt::StructOpt;
|
||||
#[derive(StructOpt, Debug)]
|
||||
#[structopt(name = "headless")]
|
||||
struct Flags {
|
||||
/// ABST input to load
|
||||
#[structopt(name = "abst_input")]
|
||||
abst_input: String,
|
||||
/// Map or savestate to load
|
||||
#[structopt(name = "load")]
|
||||
load: String,
|
||||
|
||||
/// Optional RNG seed
|
||||
#[structopt(long = "rng_seed")]
|
||||
@ -24,10 +24,6 @@ struct Flags {
|
||||
#[structopt(long = "save_at")]
|
||||
save_at: Option<String>,
|
||||
|
||||
/// Optional savestate to load
|
||||
#[structopt(long = "load_from")]
|
||||
load_from: Option<String>,
|
||||
|
||||
/// Big or large random scenario?
|
||||
#[structopt(long = "big_sim")]
|
||||
big_sim: bool,
|
||||
@ -40,17 +36,9 @@ struct Flags {
|
||||
fn main() {
|
||||
let flags = Flags::from_args();
|
||||
|
||||
println!("Opening {}", flags.abst_input);
|
||||
let map = map_model::Map::new(&flags.abst_input, &map_model::Edits::new())
|
||||
.expect("Couldn't load map");
|
||||
// TODO could load savestate
|
||||
let control_map = control::ControlMap::new(&map);
|
||||
let mut sim = sim::Sim::new(&map, flags.scenario_name, flags.rng_seed);
|
||||
let (map, _, control_map, mut sim) = sim::load(flags.load, flags.scenario_name, flags.rng_seed);
|
||||
|
||||
if let Some(path) = flags.load_from {
|
||||
sim = abstutil::read_json(&path).expect("loading sim state failed");
|
||||
println!("Loaded {}", path);
|
||||
} else {
|
||||
if sim.time == sim::Tick::zero() {
|
||||
// TODO need a notion of scenarios
|
||||
if flags.big_sim {
|
||||
sim.seed_parked_cars(0.95);
|
||||
|
@ -27,6 +27,7 @@ mod driving;
|
||||
mod intersections;
|
||||
// TODO pub only for tests...
|
||||
pub mod kinematics;
|
||||
mod load;
|
||||
mod parking;
|
||||
mod sim;
|
||||
mod spawn;
|
||||
@ -34,6 +35,7 @@ mod walking;
|
||||
|
||||
use dimensioned::si;
|
||||
use geom::{Angle, Pt2D};
|
||||
pub use load::load;
|
||||
use map_model::{LaneID, Map, TurnID};
|
||||
pub use sim::{Benchmark, Sim};
|
||||
use std::error;
|
||||
|
30
sim/src/load.rs
Normal file
30
sim/src/load.rs
Normal file
@ -0,0 +1,30 @@
|
||||
use abstutil;
|
||||
use control::ControlMap;
|
||||
use map_model::{Edits, Map};
|
||||
use Sim;
|
||||
|
||||
// Convenience method to setup everything.
|
||||
pub fn load(
|
||||
input: String,
|
||||
scenario_name: String,
|
||||
rng_seed: Option<u8>,
|
||||
) -> (Map, Edits, ControlMap, Sim) {
|
||||
let edits: Edits = abstutil::read_json("road_edits.json").unwrap_or(Edits::new());
|
||||
|
||||
if input.contains("data/save/") {
|
||||
println!("Resuming from {}", input);
|
||||
let sim: Sim = abstutil::read_json(&input).expect("loading sim state failed");
|
||||
// TODO assuming the relative path :(
|
||||
let map_path = format!("../data/{}.abst", sim.map_name);
|
||||
let map =
|
||||
Map::new(&map_path, &edits).expect(&format!("Couldn't load map from {}", map_path));
|
||||
let control_map = ControlMap::new(&map);
|
||||
(map, edits, control_map, sim)
|
||||
} else {
|
||||
println!("Loading map {}", input);
|
||||
let map = Map::new(&input, &edits).expect("Couldn't load map");
|
||||
let control_map = ControlMap::new(&map);
|
||||
let sim = Sim::new(&map, scenario_name, rng_seed);
|
||||
(map, edits, control_map, sim)
|
||||
}
|
||||
}
|
@ -27,7 +27,7 @@ pub struct Sim {
|
||||
#[derivative(PartialEq = "ignore")]
|
||||
rng: XorShiftRng,
|
||||
pub time: Tick,
|
||||
map_name: String,
|
||||
pub(crate) map_name: String,
|
||||
scenario_name: String,
|
||||
|
||||
spawner: Spawner,
|
||||
|
Loading…
Reference in New Issue
Block a user