mirror of
https://github.com/a-b-street/abstreet.git
synced 2024-12-29 01:13:53 +03:00
spawn as many trips from PSRC as possible
This commit is contained in:
parent
ef60359cc8
commit
bc69a6b4d4
@ -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),
|
||||
|
@ -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)
|
||||
|
@ -136,17 +136,20 @@ impl Road {
|
||||
|
||||
pub fn sidewalk_to_bike(&self, sidewalk: LaneID) -> Option<LaneID> {
|
||||
// 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)
|
||||
}
|
||||
|
@ -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<Position> {
|
||||
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)
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user