From 88232d3aec731d4947136120321d62a9799e4813 Mon Sep 17 00:00:00 2001 From: Dustin Carlino Date: Sun, 21 Jan 2024 16:44:56 +0000 Subject: [PATCH] Let the initial scenario be changed in the headless API, to make it easier to run without copying other unused files --- headless/src/main.rs | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/headless/src/main.rs b/headless/src/main.rs index f1ed1f556f..8878ed6598 100644 --- a/headless/src/main.rs +++ b/headless/src/main.rs @@ -1,5 +1,6 @@ //! This runs a simulation without any graphics and serves a very basic API to control things. See -//! https://a-b-street.github.io/docs/tech/dev/api.html for documentation. To run this: +//! https://a-b-street.github.io/docs/tech/dev/api.html for documentation and +//! https://github.com/mhabedank/abstreet-docker/ for an example of using with Docker. To run this: //! //! > cd headless; cargo run -- --port=1234 //! > curl http://localhost:1234/sim/get-time @@ -57,11 +58,16 @@ lazy_static::lazy_static! { about = "Simulate traffic with a JSON API, not a GUI" )] struct Args { + /// What IP to run the JSON API on. #[structopt(long, default_value = "127.0.0.1")] ip: IpAddr, /// What port to run the JSON API on. #[structopt(long)] port: u16, + /// If specified, start with this scenario loaded instead of the Montlake weekday default. Use + /// `/sim/load` to change this after startup or control more options. + #[structopt(long)] + scenario: Option, /// An arbitrary number to seed the random number generator. This is input to the deterministic /// simulation, so different values affect results. // TODO default_value can only handle strings, so copying SimFlags::RNG_SEED @@ -80,6 +86,9 @@ async fn main() { let mut load = LOAD.write().unwrap(); load.rng_seed = args.rng_seed; load.opts = args.opts; + if let Some(path) = args.scenario { + load.scenario = path; + } let (map, sim) = load.setup(&mut Timer::new("setup headless")); *MAP.write().unwrap() = map;