mirror of
https://github.com/a-b-street/abstreet.git
synced 2024-12-18 03:41:52 +03:00
Don't touch SimFlags in headless at all
This commit is contained in:
parent
da1921ae74
commit
e1b079900a
@ -35,13 +35,12 @@ lazy_static::lazy_static! {
|
||||
static ref MAP: RwLock<Map> = RwLock::new(Map::blank());
|
||||
static ref SIM: RwLock<Sim> = RwLock::new(Sim::new(&Map::blank(), SimOptions::new("tmp"), &mut Timer::throwaway()));
|
||||
static ref LOAD: RwLock<LoadSim> = RwLock::new({
|
||||
let flags = SimFlags::for_test("tmp");
|
||||
LoadSim {
|
||||
scenario: abstutil::path_scenario("montlake", "weekday"),
|
||||
modifiers: Vec::new(),
|
||||
edits: None,
|
||||
rng_seed: flags.rng_seed,
|
||||
opts: flags.opts,
|
||||
rng_seed: SimFlags::RNG_SEED,
|
||||
opts: SimOptions::default(),
|
||||
}
|
||||
});
|
||||
}
|
||||
@ -50,15 +49,17 @@ lazy_static::lazy_static! {
|
||||
async fn main() {
|
||||
let mut args = CmdArgs::new();
|
||||
let mut timer = Timer::new("setup headless");
|
||||
// TODO Misleading, because we ignore the free argument (load)
|
||||
let sim_flags = SimFlags::from_args(&mut args);
|
||||
let rng_seed = args
|
||||
.optional_parse("--rng_seed", |s| s.parse())
|
||||
.unwrap_or(SimFlags::RNG_SEED);
|
||||
let opts = SimOptions::from_args(&mut args, rng_seed);
|
||||
let port = args.required("--port").parse::<u16>().unwrap();
|
||||
args.done();
|
||||
|
||||
{
|
||||
let mut load = LOAD.write().unwrap();
|
||||
load.rng_seed = sim_flags.rng_seed;
|
||||
load.opts = sim_flags.opts;
|
||||
load.rng_seed = rng_seed;
|
||||
load.opts = opts;
|
||||
|
||||
let (map, sim) = load.setup(&mut timer);
|
||||
*MAP.write().unwrap() = map;
|
||||
|
@ -1,11 +1,9 @@
|
||||
use crate::{AlertHandler, Scenario, ScenarioModifier, Sim, SimOptions};
|
||||
use crate::{Scenario, ScenarioModifier, Sim, SimOptions};
|
||||
use abstutil::CmdArgs;
|
||||
use map_model::{Map, MapEdits};
|
||||
use rand::SeedableRng;
|
||||
use rand_xorshift::XorShiftRng;
|
||||
|
||||
const RNG_SEED: u8 = 42;
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct SimFlags {
|
||||
pub load: String,
|
||||
@ -15,44 +13,19 @@ pub struct SimFlags {
|
||||
}
|
||||
|
||||
impl SimFlags {
|
||||
pub const RNG_SEED: u8 = 42;
|
||||
|
||||
pub fn from_args(args: &mut CmdArgs) -> SimFlags {
|
||||
let rng_seed = args
|
||||
.optional_parse("--rng_seed", |s| s.parse())
|
||||
.unwrap_or(RNG_SEED);
|
||||
|
||||
.unwrap_or(SimFlags::RNG_SEED);
|
||||
SimFlags {
|
||||
load: args
|
||||
.optional_free()
|
||||
.unwrap_or_else(|| abstutil::path_map("montlake")),
|
||||
modifiers: Vec::new(),
|
||||
rng_seed,
|
||||
opts: SimOptions {
|
||||
run_name: args
|
||||
.optional("--run_name")
|
||||
.unwrap_or_else(|| "unnamed".to_string()),
|
||||
use_freeform_policy_everywhere: args.enabled("--freeform_policy"),
|
||||
dont_block_the_box: !args.enabled("--disable_block_the_box"),
|
||||
recalc_lanechanging: !args.enabled("--disable_recalc_lc"),
|
||||
break_turn_conflict_cycles: !args.enabled("--disable_break_turn_conflict_cycles"),
|
||||
handle_uber_turns: !args.enabled("--disable_handle_uber_turns"),
|
||||
enable_pandemic_model: if args.enabled("--pandemic") {
|
||||
Some(XorShiftRng::from_seed([rng_seed; 16]))
|
||||
} else {
|
||||
None
|
||||
},
|
||||
alerts: args
|
||||
.optional("--alerts")
|
||||
.map(|x| match x.as_ref() {
|
||||
"print" => AlertHandler::Print,
|
||||
"block" => AlertHandler::Block,
|
||||
"silence" => AlertHandler::Silence,
|
||||
_ => panic!("Bad --alerts={}. Must be print|block|silence", x),
|
||||
})
|
||||
.unwrap_or(AlertHandler::Print),
|
||||
pathfinding_upfront: args.enabled("--pathfinding_upfront"),
|
||||
live_map_edits: args.enabled("--live_map_edits"),
|
||||
infinite_parking: args.enabled("--infinite_parking"),
|
||||
},
|
||||
opts: SimOptions::from_args(args, rng_seed),
|
||||
}
|
||||
}
|
||||
|
||||
@ -65,7 +38,7 @@ impl SimFlags {
|
||||
SimFlags {
|
||||
load: abstutil::path_map(map),
|
||||
modifiers: Vec::new(),
|
||||
rng_seed: RNG_SEED,
|
||||
rng_seed: SimFlags::RNG_SEED,
|
||||
opts: SimOptions::new(run_name),
|
||||
}
|
||||
}
|
||||
|
@ -10,13 +10,14 @@ use crate::{
|
||||
VehicleSpec, VehicleType, WalkingSimState, BUS_LENGTH, LIGHT_RAIL_LENGTH, MIN_CAR_LENGTH,
|
||||
SPAWN_DIST,
|
||||
};
|
||||
use abstutil::{prettyprint_usize, serialized_size_bytes, Parallelism, Timer};
|
||||
use abstutil::{prettyprint_usize, serialized_size_bytes, CmdArgs, Parallelism, Timer};
|
||||
use geom::{Distance, Duration, Speed, Time};
|
||||
use instant::Instant;
|
||||
use map_model::{
|
||||
BuildingID, BusRoute, LaneID, Map, ParkingLotID, Path, PathConstraints, PathRequest, Position,
|
||||
Traversable,
|
||||
};
|
||||
use rand::SeedableRng;
|
||||
use rand_xorshift::XorShiftRng;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use std::collections::{BTreeSet, HashSet};
|
||||
@ -85,6 +86,38 @@ impl std::default::Default for SimOptions {
|
||||
}
|
||||
}
|
||||
|
||||
impl SimOptions {
|
||||
pub fn from_args(args: &mut CmdArgs, rng_seed: u8) -> SimOptions {
|
||||
SimOptions {
|
||||
run_name: args
|
||||
.optional("--run_name")
|
||||
.unwrap_or_else(|| "unnamed".to_string()),
|
||||
use_freeform_policy_everywhere: args.enabled("--freeform_policy"),
|
||||
dont_block_the_box: !args.enabled("--disable_block_the_box"),
|
||||
recalc_lanechanging: !args.enabled("--disable_recalc_lc"),
|
||||
break_turn_conflict_cycles: !args.enabled("--disable_break_turn_conflict_cycles"),
|
||||
handle_uber_turns: !args.enabled("--disable_handle_uber_turns"),
|
||||
enable_pandemic_model: if args.enabled("--pandemic") {
|
||||
Some(XorShiftRng::from_seed([rng_seed; 16]))
|
||||
} else {
|
||||
None
|
||||
},
|
||||
alerts: args
|
||||
.optional("--alerts")
|
||||
.map(|x| match x.as_ref() {
|
||||
"print" => AlertHandler::Print,
|
||||
"block" => AlertHandler::Block,
|
||||
"silence" => AlertHandler::Silence,
|
||||
_ => panic!("Bad --alerts={}. Must be print|block|silence", x),
|
||||
})
|
||||
.unwrap_or(AlertHandler::Print),
|
||||
pathfinding_upfront: args.enabled("--pathfinding_upfront"),
|
||||
live_map_edits: args.enabled("--live_map_edits"),
|
||||
infinite_parking: args.enabled("--infinite_parking"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
pub enum AlertHandler {
|
||||
// Just print the alert to STDOUT
|
||||
|
Loading…
Reference in New Issue
Block a user