Make traffic seitan close roads that agents are about to use, causing a

crash. And start to figure out the debugging story.
This commit is contained in:
Dustin Carlino 2020-10-05 08:49:16 -07:00
parent 5b84ac897c
commit 8e49aac42f
5 changed files with 48 additions and 6 deletions

View File

@ -273,7 +273,13 @@ impl State for DebugMode {
{
let mut batch = GeomBatch::new();
let agents = match id {
ID::Intersection(i) => app.primary.sim.get_accepted_agents(i),
ID::Intersection(i) => app
.primary
.sim
.get_accepted_agents(i)
.into_iter()
.map(|(a, _)| a)
.collect(),
ID::Car(c) => app.primary.sim.get_blocked_by(AgentID::Car(c)),
_ => unreachable!(),
};

View File

@ -981,7 +981,7 @@ impl DrivingSimState {
if intersections
.get_accepted_agents(i)
.iter()
.any(|a| matches!(a, AgentID::Car(_)))
.any(|(a, _)| matches!(a, AgentID::Car(_)))
{
return format!("someone's turning in {} still", i);
}

View File

@ -437,11 +437,11 @@ impl IntersectionSimState {
}
}
pub fn get_accepted_agents(&self, id: IntersectionID) -> HashSet<AgentID> {
pub fn get_accepted_agents(&self, id: IntersectionID) -> Vec<(AgentID, TurnID)> {
self.state[&id]
.accepted
.iter()
.map(|req| req.agent)
.map(|req| (req.agent, req.turn))
.collect()
}

View File

@ -236,7 +236,7 @@ impl Sim {
}
}
pub fn get_accepted_agents(&self, id: IntersectionID) -> HashSet<AgentID> {
pub fn get_accepted_agents(&self, id: IntersectionID) -> Vec<(AgentID, TurnID)> {
self.intersections.get_accepted_agents(id)
}
pub fn get_waiting_agents(&self, id: IntersectionID) -> Vec<(AgentID, TurnID, Time)> {

View File

@ -21,7 +21,16 @@ fn main() {
let mut timer = Timer::new("cause mass chaos");
let (mut map, mut sim, mut rng) = sim_flags.load(&mut timer);
run(&mut map, &mut sim, &mut rng, &mut timer);
if let Err(err) = std::panic::catch_unwind(std::panic::AssertUnwindSafe(|| {
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();
std::panic::resume_unwind(err)
}
}
fn run(map: &mut Map, sim: &mut Sim, rng: &mut XorShiftRng, timer: &mut Timer) {
@ -33,11 +42,38 @@ fn run(map: &mut Map, sim: &mut Sim, rng: &mut XorShiftRng, timer: &mut Timer) {
let mut edits = map.get_edits().clone();
edits.edits_name = "chaos".to_string();
nuke_random_parking(map, rng, &mut edits);
alter_turn_destinations(sim, map, rng, &mut edits);
map.must_apply_edits(edits, timer);
map.recalculate_pathfinding_after_edits(timer);
}
}
fn alter_turn_destinations(sim: &Sim, map: &Map, rng: &mut XorShiftRng, edits: &mut MapEdits) {
let num_edits = 3;
// Find active turns
let mut active_destinations = Vec::new();
for i in map.all_intersections() {
for (_, t) in sim.get_accepted_agents(i.id) {
if !map.get_l(t.dst).is_walkable() {
active_destinations.push(t.dst);
}
}
}
active_destinations.sort();
active_destinations.dedup();
active_destinations.shuffle(rng);
for l in active_destinations.into_iter().take(num_edits) {
// TODO Also need to change all parking lanes on the road; otherwise we might wind up
// making an edit that the UI blocks the player from doing.
let r = map.get_parent(l);
edits.commands.push(map.edit_road_cmd(r.id, |new| {
new.lanes_ltr[r.offset(l)].0 = LaneType::Construction;
}));
}
}
// TODO This doesn't cause any interesting crash yet. Find somebody in the act of
// parking/unparking/going to a spot, and nuke that instead.
fn nuke_random_parking(map: &Map, rng: &mut XorShiftRng, edits: &mut MapEdits) {