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