mirror of
https://github.com/a-b-street/abstreet.git
synced 2024-12-29 01:13:53 +03:00
recording parking phase
This commit is contained in:
parent
c842d6847e
commit
ea378c25f3
@ -103,10 +103,14 @@ impl DrivingSimState {
|
||||
} else {
|
||||
// Have to do this early
|
||||
if car.router.last_step() {
|
||||
match car
|
||||
.router
|
||||
.maybe_handle_end(params.start_dist, &car.vehicle, parking, map)
|
||||
{
|
||||
match car.router.maybe_handle_end(
|
||||
params.start_dist,
|
||||
&car.vehicle,
|
||||
parking,
|
||||
map,
|
||||
car.trip,
|
||||
&mut self.events,
|
||||
) {
|
||||
None | Some(ActionAtEnd::GotoLaneEnd) => {}
|
||||
x => {
|
||||
panic!("Car with one-step route {:?} had unexpected result from maybe_handle_end: {:?}", car.router, x);
|
||||
@ -261,8 +265,14 @@ impl DrivingSimState {
|
||||
// doing something weird like vanishing or re-parking immediately
|
||||
// (quite unlikely), the next loop will pick that up. Just trigger the
|
||||
// side effect of choosing an end_dist.
|
||||
car.router
|
||||
.maybe_handle_end(front, &car.vehicle, parking, map);
|
||||
car.router.maybe_handle_end(
|
||||
front,
|
||||
&car.vehicle,
|
||||
parking,
|
||||
map,
|
||||
car.trip,
|
||||
&mut self.events,
|
||||
);
|
||||
}
|
||||
car.state = car.crossing_state(front, now, map);
|
||||
scheduler.push(car.state.get_end_time(), Command::UpdateCar(car.vehicle.id));
|
||||
@ -347,7 +357,9 @@ impl DrivingSimState {
|
||||
// We do NOT need to update the follower. If they were Queued, they'll remain that
|
||||
// way, until laggy_head is None.
|
||||
|
||||
let last_step = car.router.advance(&car.vehicle, parking, map);
|
||||
let last_step =
|
||||
car.router
|
||||
.advance(&car.vehicle, parking, map, car.trip, &mut self.events);
|
||||
car.state = car.crossing_state(Distance::ZERO, now, map);
|
||||
car.blocked_since = None;
|
||||
scheduler.push(car.state.get_end_time(), Command::UpdateCar(car.vehicle.id));
|
||||
@ -419,10 +431,14 @@ impl DrivingSimState {
|
||||
| CarState::Idling(_, _)
|
||||
| CarState::WaitingToAdvance => unreachable!(),
|
||||
CarState::Queued => {
|
||||
match car
|
||||
.router
|
||||
.maybe_handle_end(our_dist, &car.vehicle, parking, map)
|
||||
{
|
||||
match car.router.maybe_handle_end(
|
||||
our_dist,
|
||||
&car.vehicle,
|
||||
parking,
|
||||
map,
|
||||
car.trip,
|
||||
&mut self.events,
|
||||
) {
|
||||
Some(ActionAtEnd::VanishAtBorder(i)) => {
|
||||
trips.car_or_bike_reached_border(now, car.vehicle.id, i);
|
||||
}
|
||||
|
@ -1,9 +1,9 @@
|
||||
use crate::mechanics::Queue;
|
||||
use crate::{ParkingSimState, ParkingSpot, SidewalkSpot, Vehicle};
|
||||
use crate::{Event, ParkingSimState, ParkingSpot, SidewalkSpot, TripID, Vehicle};
|
||||
use geom::Distance;
|
||||
use map_model::{
|
||||
BuildingID, IntersectionID, LaneID, Map, Path, PathConstraints, PathStep, Position,
|
||||
Traversable, TurnID,
|
||||
BuildingID, IntersectionID, LaneID, Map, Path, PathConstraints, PathRequest, PathStep,
|
||||
Position, Traversable, TurnID,
|
||||
};
|
||||
use serde_derive::{Deserialize, Serialize};
|
||||
use std::collections::{BTreeMap, HashMap, VecDeque};
|
||||
@ -125,11 +125,13 @@ impl Router {
|
||||
vehicle: &Vehicle,
|
||||
parking: &ParkingSimState,
|
||||
map: &Map,
|
||||
trip: TripID,
|
||||
events: &mut Vec<Event>,
|
||||
) -> Traversable {
|
||||
let prev = self.path.shift(map).as_traversable();
|
||||
if self.last_step() {
|
||||
// Do this to trigger the side-effect of looking for parking.
|
||||
self.maybe_handle_end(Distance::ZERO, vehicle, parking, map);
|
||||
self.maybe_handle_end(Distance::ZERO, vehicle, parking, map, trip, events);
|
||||
}
|
||||
|
||||
// Sanity check laws haven't been broken
|
||||
@ -154,6 +156,9 @@ impl Router {
|
||||
vehicle: &Vehicle,
|
||||
parking: &ParkingSimState,
|
||||
map: &Map,
|
||||
// TODO Not so nice to plumb all of this here
|
||||
trip: TripID,
|
||||
events: &mut Vec<Event>,
|
||||
) -> Option<ActionAtEnd> {
|
||||
match self.goal {
|
||||
Goal::EndAtBorder { end_dist, i } => {
|
||||
@ -187,6 +192,15 @@ impl Router {
|
||||
vehicle,
|
||||
map,
|
||||
) {
|
||||
events.push(Event::TripPhaseStarting(
|
||||
trip,
|
||||
Some(PathRequest {
|
||||
start: Position::new(current_lane, front),
|
||||
end: new_pos,
|
||||
constraints: PathConstraints::Car,
|
||||
}),
|
||||
format!("parking on the current lane"),
|
||||
));
|
||||
*spot = Some((new_spot, new_pos.dist_along()));
|
||||
} else {
|
||||
if let Some((new_path_steps, new_spot, new_pos)) =
|
||||
@ -196,6 +210,16 @@ impl Router {
|
||||
for step in new_path_steps {
|
||||
self.path.add(step, map);
|
||||
}
|
||||
// TODO This path might not be the same as the one found here...
|
||||
events.push(Event::TripPhaseStarting(
|
||||
trip,
|
||||
Some(PathRequest {
|
||||
start: Position::new(current_lane, front),
|
||||
end: new_pos,
|
||||
constraints: PathConstraints::Car,
|
||||
}),
|
||||
format!("parking somewhere else"),
|
||||
));
|
||||
} else {
|
||||
println!("WARNING: {} can't find parking on {} or anywhere reachable from it. Possibly we're just totally out of parking space!", vehicle.id, current_lane);
|
||||
*stuck_end_dist = Some(map.get_l(current_lane).length());
|
||||
|
Loading…
Reference in New Issue
Block a user