mirror of
https://github.com/a-b-street/abstreet.git
synced 2024-12-24 15:02:59 +03:00
stop generating RNGs from entropy. use the prebaked seed by default. allow explicitly changing the rng, but no use for that yet
This commit is contained in:
parent
1f9e9f5479
commit
0eaf33ff46
@ -42,9 +42,6 @@ One-time setup:
|
||||
experience, so they're hidden for now.
|
||||
- `cargo run -- --tutorial=12` starts somewhere in the tutorial
|
||||
- Adding `--edits='name of edits'` starts with edits applied to the map.
|
||||
- If you're testing anything related to prebaked results (used for comparisons
|
||||
against a baseline in challenge mode), make sure to set `--rng_seed=42`. The
|
||||
`--dev` flag does by default.
|
||||
- All code is automatically formatted using
|
||||
https://github.com/rust-lang/rustfmt; please run `cargo +nightly fmt` before
|
||||
sending a PR. (You have to install the nightly toolchain just for fmt)
|
||||
|
@ -111,9 +111,6 @@ fn launch_test(test: &ABTest, app: &mut App, ctx: &mut EventCtx) -> ABTestMode {
|
||||
|
||||
{
|
||||
timer.start("load primary");
|
||||
if app.primary.current_flags.sim_flags.rng_seed.is_none() {
|
||||
app.primary.current_flags.sim_flags.rng_seed = Some(42);
|
||||
}
|
||||
app.primary.current_flags.sim_flags.opts.run_name =
|
||||
format!("{} with {}", test.test_name, test.edits1_name);
|
||||
app.primary.current_flags.sim_flags.opts.savestate_every = None;
|
||||
|
@ -36,16 +36,7 @@ fn main() {
|
||||
num_agents: args.optional_parse("--num_agents", |s| s.parse()),
|
||||
};
|
||||
let mut opts = options::Options::default();
|
||||
if args.enabled("--dev") {
|
||||
opts.dev = true;
|
||||
flags.sim_flags.rng_seed = Some(42);
|
||||
}
|
||||
|
||||
// No random in wasm
|
||||
#[cfg(target_arch = "wasm32")]
|
||||
{
|
||||
flags.sim_flags.rng_seed = Some(42);
|
||||
}
|
||||
opts.dev = args.enabled("--dev");
|
||||
|
||||
if let Some(x) = args.optional("--color_scheme") {
|
||||
let mut ok = false;
|
||||
|
@ -790,10 +790,7 @@ impl TutorialState {
|
||||
// TODO Should some of this always happen?
|
||||
app.primary.clear_sim();
|
||||
if let Some(ref cb) = self.stage().spawn {
|
||||
let old = app.primary.current_flags.sim_flags.rng_seed;
|
||||
app.primary.current_flags.sim_flags.rng_seed = Some(42);
|
||||
(cb)(app);
|
||||
app.primary.current_flags.sim_flags.rng_seed = old;
|
||||
app.primary
|
||||
.sim
|
||||
.normal_step(&app.primary.map, Duration::seconds(0.1));
|
||||
|
@ -15,7 +15,7 @@ fn main() {
|
||||
args.done();
|
||||
|
||||
let mut sim_flags = SimFlags::synthetic_test("montlake", "pandemic");
|
||||
sim_flags.opts.enable_pandemic_model = Some(XorShiftRng::from_seed([42; 16]));
|
||||
sim_flags.opts.enable_pandemic_model = Some(XorShiftRng::from_seed([sim_flags.rng_seed; 16]));
|
||||
let mut timer = Timer::new("setup headless");
|
||||
let (map, mut sim, mut rng) = sim_flags.load(&mut timer);
|
||||
|
||||
|
@ -1,3 +1,3 @@
|
||||
cd game
|
||||
set RUST_BACKTRACE=1
|
||||
game.exe --rng_seed=42 1> ..\\output.txt 2>&1
|
||||
game.exe 1> ..\\output.txt 2>&1
|
||||
|
@ -1,4 +1,4 @@
|
||||
#!/bin/bash
|
||||
|
||||
cd game
|
||||
RUST_BACKTRACE=1 ./game --rng_seed=42
|
||||
RUST_BACKTRACE=1 ./game
|
||||
|
@ -5,17 +5,21 @@ 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,
|
||||
pub use_map_fixes: bool,
|
||||
pub rng_seed: Option<u8>,
|
||||
pub rng_seed: u8,
|
||||
pub opts: SimOptions,
|
||||
}
|
||||
|
||||
impl SimFlags {
|
||||
pub fn from_args(args: &mut CmdArgs) -> SimFlags {
|
||||
let rng_seed = args.optional_parse("--rng_seed", |s| s.parse());
|
||||
let rng_seed = args
|
||||
.optional_parse("--rng_seed", |s| s.parse())
|
||||
.unwrap_or(RNG_SEED);
|
||||
|
||||
SimFlags {
|
||||
load: args
|
||||
@ -33,11 +37,7 @@ impl SimFlags {
|
||||
recalc_lanechanging: !args.enabled("--dont_recalc_lc"),
|
||||
break_turn_conflict_cycles: args.enabled("--break_turn_conflict_cycles"),
|
||||
enable_pandemic_model: if args.enabled("--pandemic") {
|
||||
if let Some(seed) = rng_seed {
|
||||
Some(XorShiftRng::from_seed([seed; 16]))
|
||||
} else {
|
||||
Some(XorShiftRng::from_entropy())
|
||||
}
|
||||
Some(XorShiftRng::from_seed([rng_seed; 16]))
|
||||
} else {
|
||||
None
|
||||
},
|
||||
@ -63,17 +63,13 @@ impl SimFlags {
|
||||
SimFlags {
|
||||
load: abstutil::path_map(map),
|
||||
use_map_fixes: true,
|
||||
rng_seed: Some(42),
|
||||
rng_seed: RNG_SEED,
|
||||
opts: SimOptions::new(run_name),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn make_rng(&self) -> XorShiftRng {
|
||||
if let Some(seed) = self.rng_seed {
|
||||
XorShiftRng::from_seed([seed; 16])
|
||||
} else {
|
||||
XorShiftRng::from_entropy()
|
||||
}
|
||||
XorShiftRng::from_seed([self.rng_seed; 16])
|
||||
}
|
||||
|
||||
// Convenience method to setup everything.
|
||||
|
Loading…
Reference in New Issue
Block a user