From bc69a6b4d40358e042205c845305377dbf514d47 Mon Sep 17 00:00:00 2001 From: Dustin Carlino Date: Sat, 25 May 2019 18:32:03 -0700 Subject: [PATCH] spawn as many trips from PSRC as possible --- editor/src/mission/mod.rs | 21 ++++++++++++++------- editor/src/sandbox/spawner.rs | 24 ++++++++++++++---------- map_model/src/road.rs | 3 +++ sim/src/make/spawner.rs | 18 +++++++++++------- 4 files changed, 42 insertions(+), 24 deletions(-) diff --git a/editor/src/mission/mod.rs b/editor/src/mission/mod.rs index 316d59aa97..068b492a28 100644 --- a/editor/src/mission/mod.rs +++ b/editor/src/mission/mod.rs @@ -261,15 +261,22 @@ fn instantiate_trips(ctx: &mut EventCtx, ui: &mut UI) { trip.depart_at, match trip.mode { // TODO Use a parked car, but first have to figure out what cars to seed. - Mode::Drive => TripSpec::CarAppearing { - start_pos: TripSpec::spawn_car_at( + Mode::Drive => { + if let Some(start_pos) = TripSpec::spawn_car_at( Position::bldg_via_driving(trip.from, map).unwrap(), map, - ), - goal: DrivingGoal::ParkNear(trip.to), - ped_speed: Scenario::rand_ped_speed(&mut rng), - vehicle_spec: Scenario::rand_car(&mut rng), - }, + ) { + TripSpec::CarAppearing { + start_pos, + goal: DrivingGoal::ParkNear(trip.to), + ped_speed: Scenario::rand_ped_speed(&mut rng), + vehicle_spec: Scenario::rand_car(&mut rng), + } + } else { + timer.warn(format!("Can't make car appear at {}", trip.from)); + continue; + } + } Mode::Bike => TripSpec::UsingBike { start: SidewalkSpot::building(trip.from, map), goal: DrivingGoal::ParkNear(trip.to), diff --git a/editor/src/sandbox/spawner.rs b/editor/src/sandbox/spawner.rs index 8f7e572da1..a10aeb5fd1 100644 --- a/editor/src/sandbox/spawner.rs +++ b/editor/src/sandbox/spawner.rs @@ -220,16 +220,20 @@ impl AgentSpawner { } } (Source::Driving(from), Goal::Building(to)) => { - sim.schedule_trip( - sim.time(), - TripSpec::CarAppearing { - start_pos: TripSpec::spawn_car_at(from, map), - vehicle_spec: Scenario::rand_car(&mut rng), - goal: DrivingGoal::ParkNear(to), - ped_speed: Scenario::rand_ped_speed(&mut rng), - }, - map, - ); + if let Some(start_pos) = TripSpec::spawn_car_at(from, map) { + sim.schedule_trip( + sim.time(), + TripSpec::CarAppearing { + start_pos, + vehicle_spec: Scenario::rand_car(&mut rng), + goal: DrivingGoal::ParkNear(to), + ped_speed: Scenario::rand_ped_speed(&mut rng), + }, + map, + ); + } else { + println!("Can't make a car appear at {:?}", from); + } } (Source::Driving(from), Goal::Border(to)) => { if let Some(goal) = DrivingGoal::end_at_border(to, vec![LaneType::Driving], map) diff --git a/map_model/src/road.rs b/map_model/src/road.rs index 0dc681736a..7a1f82ab6a 100644 --- a/map_model/src/road.rs +++ b/map_model/src/road.rs @@ -136,17 +136,20 @@ impl Road { pub fn sidewalk_to_bike(&self, sidewalk: LaneID) -> Option { // TODO Crossing bus lanes means higher layers of sim should know to block these off + // Oneways mean we might need to consider the other side of the road. let (fwds, idx) = self.dir_and_offset(sidewalk); if fwds { self.children_forwards[0..idx] .iter() .rev() + .chain(self.children_backwards.iter()) .find(|(_, lt)| *lt == LaneType::Driving || *lt == LaneType::Biking) .map(|(id, _)| *id) } else { self.children_backwards[0..idx] .iter() .rev() + .chain(self.children_forwards.iter()) .find(|(_, lt)| *lt == LaneType::Driving || *lt == LaneType::Biking) .map(|(id, _)| *id) } diff --git a/sim/src/make/spawner.rs b/sim/src/make/spawner.rs index ef320cfaa7..bc1145a1e2 100644 --- a/sim/src/make/spawner.rs +++ b/sim/src/make/spawner.rs @@ -335,17 +335,21 @@ impl TripSpawner { } impl TripSpec { - // Fixes problems that schedule_trip would hit. - pub fn spawn_car_at(pos: Position, map: &Map) -> Position { + // If possible, fixes problems that schedule_trip would hit. + pub fn spawn_car_at(pos: Position, map: &Map) -> Option { let len = map.get_l(pos.lane()).length(); if pos.dist_along() == len { - assert!(pos.dist_along() > EPSILON_DIST); - Position::new(pos.lane(), pos.dist_along() - EPSILON_DIST) + if pos.dist_along() <= EPSILON_DIST { + return None; + } + Some(Position::new(pos.lane(), pos.dist_along() - EPSILON_DIST)) } else if pos.dist_along() < MAX_CAR_LENGTH { - assert!(len > MAX_CAR_LENGTH); - Position::new(pos.lane(), MAX_CAR_LENGTH) + if len <= MAX_CAR_LENGTH { + return None; + } + Some(Position::new(pos.lane(), MAX_CAR_LENGTH)) } else { - pos + Some(pos) } }