mirror of
https://github.com/a-b-street/abstreet.git
synced 2024-12-25 15:33:44 +03:00
Simplify the traffic seitan tool's logging and make it easier to find
the last savestate and edits of a crash.
This commit is contained in:
parent
4760d6b2cf
commit
e9f9d3884b
@ -80,16 +80,7 @@ impl SimFlags {
|
|||||||
map.recalculate_pathfinding_after_edits(timer);
|
map.recalculate_pathfinding_after_edits(timer);
|
||||||
}
|
}
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
// Little brittle. Sometimes legitimate edits wind up being saved without a
|
panic!("Couldn't load edits \"{}\": {}", sim.edits_name, err);
|
||||||
// proper name.
|
|
||||||
if sim.edits_name.starts_with("Untitled Proposal") {
|
|
||||||
warn!(
|
|
||||||
"Sim savestate refers to edits \"{}\", but not using them: {}",
|
|
||||||
sim.edits_name, err
|
|
||||||
);
|
|
||||||
} else {
|
|
||||||
panic!("Couldn't load edits \"{}\": {}", sim.edits_name, err);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
sim.restore_paths(&map, timer);
|
sim.restore_paths(&map, timer);
|
||||||
|
@ -44,7 +44,7 @@ pub struct Sim {
|
|||||||
scheduler: Scheduler,
|
scheduler: Scheduler,
|
||||||
time: Time,
|
time: Time,
|
||||||
|
|
||||||
// TODO Reconsider these
|
// These're needed to load from a savestate.
|
||||||
pub(crate) map_name: String,
|
pub(crate) map_name: String,
|
||||||
pub(crate) edits_name: String,
|
pub(crate) edits_name: String,
|
||||||
// Some tests deliberately set different scenario names for comparisons.
|
// Some tests deliberately set different scenario names for comparisons.
|
||||||
@ -886,6 +886,8 @@ impl Sim {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn handle_live_edits(&mut self, map: &Map) {
|
pub fn handle_live_edits(&mut self, map: &Map) {
|
||||||
|
self.edits_name = map.get_edits().edits_name.clone();
|
||||||
|
|
||||||
let affected = self.find_trips_affected_by_live_edits(map);
|
let affected = self.find_trips_affected_by_live_edits(map);
|
||||||
|
|
||||||
// V1: Just cancel every trip crossing an affected area.
|
// V1: Just cancel every trip crossing an affected area.
|
||||||
|
@ -19,15 +19,21 @@ fn main() {
|
|||||||
let sim_flags = SimFlags::from_args(&mut args);
|
let sim_flags = SimFlags::from_args(&mut args);
|
||||||
args.done();
|
args.done();
|
||||||
|
|
||||||
let mut timer = Timer::new("cause mass chaos");
|
let mut timer = Timer::throwaway();
|
||||||
let (mut map, mut sim, mut rng) = sim_flags.load(&mut timer);
|
let (mut map, mut sim, mut rng) = sim_flags.load(&mut timer);
|
||||||
|
|
||||||
|
// Set the edits name up-front, so that the savestates get named reasonably too.
|
||||||
|
{
|
||||||
|
let mut edits = map.get_edits().clone();
|
||||||
|
edits.edits_name = "traffic_seitan".to_string();
|
||||||
|
map.must_apply_edits(edits, &mut timer);
|
||||||
|
map.recalculate_pathfinding_after_edits(&mut timer);
|
||||||
|
sim.handle_live_edits(&map);
|
||||||
|
}
|
||||||
|
|
||||||
if let Err(err) = std::panic::catch_unwind(std::panic::AssertUnwindSafe(|| {
|
if let Err(err) = std::panic::catch_unwind(std::panic::AssertUnwindSafe(|| {
|
||||||
run(&mut map, &mut sim, &mut rng, &mut timer);
|
run(&mut map, &mut sim, &mut rng, &mut timer);
|
||||||
})) {
|
})) {
|
||||||
let mut edits = map.get_edits().clone();
|
|
||||||
edits.edits_name = "traffic_seitan_crash".to_string();
|
|
||||||
map.must_apply_edits(edits, &mut timer);
|
|
||||||
map.save_edits();
|
map.save_edits();
|
||||||
|
|
||||||
println!("Crashed at {}", sim.time());
|
println!("Crashed at {}", sim.time());
|
||||||
@ -40,11 +46,11 @@ fn run(map: &mut Map, sim: &mut Sim, rng: &mut XorShiftRng, timer: &mut Timer) {
|
|||||||
let edit_frequency = Duration::minutes(5);
|
let edit_frequency = Duration::minutes(5);
|
||||||
|
|
||||||
while !sim.is_done() {
|
while !sim.is_done() {
|
||||||
|
println!("");
|
||||||
sim.timed_step(map, edit_frequency, &mut None, timer);
|
sim.timed_step(map, edit_frequency, &mut None, timer);
|
||||||
sim.save();
|
sim.save();
|
||||||
|
|
||||||
let mut edits = map.get_edits().clone();
|
let mut edits = map.get_edits().clone();
|
||||||
edits.edits_name = "chaos".to_string();
|
|
||||||
nuke_random_parking(map, rng, &mut edits);
|
nuke_random_parking(map, rng, &mut edits);
|
||||||
alter_turn_destinations(sim, map, rng, &mut edits);
|
alter_turn_destinations(sim, map, rng, &mut edits);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user