mirror of
https://github.com/a-b-street/abstreet.git
synced 2024-12-25 23:43:25 +03:00
publishing an event to make the parking tests work
This commit is contained in:
parent
e6ff4481e7
commit
05ffb18fbc
@ -1,26 +1,19 @@
|
|||||||
use crate::{AgentID, CarID, ParkingSpot, PedestrianID};
|
use crate::{AgentID, CarID, ParkingSpot, PedestrianID};
|
||||||
use map_model::{BuildingID, BusStopID, Traversable, TurnID};
|
use map_model::{BuildingID, BusStopID, Traversable};
|
||||||
|
use serde_derive::{Deserialize, Serialize};
|
||||||
|
|
||||||
#[derive(Debug, PartialEq, Eq)]
|
#[derive(Debug, PartialEq, Eq, Serialize, Deserialize)]
|
||||||
pub enum Event {
|
pub enum Event {
|
||||||
// TODO CarFinishedParking
|
|
||||||
// TODO and the pedestrian / trip associated with it?
|
|
||||||
CarReachedParkingSpot(CarID, ParkingSpot),
|
CarReachedParkingSpot(CarID, ParkingSpot),
|
||||||
// TODO and the car / trip?
|
|
||||||
PedReachedParkingSpot(PedestrianID, ParkingSpot),
|
|
||||||
// TODO CarFinishedUnparking
|
|
||||||
BusArrivedAtStop(CarID, BusStopID),
|
BusArrivedAtStop(CarID, BusStopID),
|
||||||
BusDepartedFromStop(CarID, BusStopID),
|
BusDepartedFromStop(CarID, BusStopID),
|
||||||
|
|
||||||
|
PedReachedParkingSpot(PedestrianID, ParkingSpot),
|
||||||
PedReachedBuilding(PedestrianID, BuildingID),
|
PedReachedBuilding(PedestrianID, BuildingID),
|
||||||
PedReachedBusStop(PedestrianID, BusStopID),
|
PedReachedBusStop(PedestrianID, BusStopID),
|
||||||
PedEntersBus(PedestrianID, CarID),
|
PedEntersBus(PedestrianID, CarID),
|
||||||
PedLeavesBus(PedestrianID, CarID),
|
PedLeavesBus(PedestrianID, CarID),
|
||||||
|
|
||||||
// TODO split up into cases or not?
|
|
||||||
AgentEntersTraversable(AgentID, Traversable),
|
AgentEntersTraversable(AgentID, Traversable),
|
||||||
AgentLeavesTraversable(AgentID, Traversable),
|
|
||||||
|
|
||||||
// TODO maybe AgentRequestsTurn?
|
|
||||||
IntersectionAcceptsRequest(AgentID, TurnID),
|
|
||||||
}
|
}
|
||||||
|
@ -200,6 +200,10 @@ impl Sim {
|
|||||||
// Running
|
// Running
|
||||||
impl Sim {
|
impl Sim {
|
||||||
pub fn step(&mut self, map: &Map) -> Vec<Event> {
|
pub fn step(&mut self, map: &Map) -> Vec<Event> {
|
||||||
|
if !self.spawner.is_done() {
|
||||||
|
panic!("Forgot to call spawn_all_trips");
|
||||||
|
}
|
||||||
|
|
||||||
self.time += TIMESTEP;
|
self.time += TIMESTEP;
|
||||||
|
|
||||||
self.driving.step_if_needed(
|
self.driving.step_if_needed(
|
||||||
@ -240,7 +244,7 @@ impl Sim {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Vec::new()
|
self.trips.collect_events()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn dump_before_abort(&self) {
|
pub fn dump_before_abort(&self) {
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
use crate::{
|
use crate::{
|
||||||
AgentID, CarID, Command, CreateCar, CreatePedestrian, DrivingGoal, ParkingSimState,
|
AgentID, CarID, Command, CreateCar, CreatePedestrian, DrivingGoal, Event, ParkingSimState,
|
||||||
ParkingSpot, PedestrianID, Router, Scheduler, SidewalkPOI, SidewalkSpot, TripID, Vehicle,
|
ParkingSpot, PedestrianID, Router, Scheduler, SidewalkPOI, SidewalkSpot, TripID, Vehicle,
|
||||||
};
|
};
|
||||||
use abstutil::{deserialize_btreemap, serialize_btreemap};
|
use abstutil::{deserialize_btreemap, serialize_btreemap};
|
||||||
@ -17,6 +17,8 @@ pub struct TripManager {
|
|||||||
deserialize_with = "deserialize_btreemap"
|
deserialize_with = "deserialize_btreemap"
|
||||||
)]
|
)]
|
||||||
active_trip_mode: BTreeMap<AgentID, TripID>,
|
active_trip_mode: BTreeMap<AgentID, TripID>,
|
||||||
|
|
||||||
|
events: Vec<Event>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl TripManager {
|
impl TripManager {
|
||||||
@ -24,10 +26,10 @@ impl TripManager {
|
|||||||
TripManager {
|
TripManager {
|
||||||
trips: Vec::new(),
|
trips: Vec::new(),
|
||||||
active_trip_mode: BTreeMap::new(),
|
active_trip_mode: BTreeMap::new(),
|
||||||
|
events: Vec::new(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Transitions from spawner
|
|
||||||
pub fn agent_starting_trip_leg(&mut self, agent: AgentID, trip: TripID) {
|
pub fn agent_starting_trip_leg(&mut self, agent: AgentID, trip: TripID) {
|
||||||
assert!(!self.active_trip_mode.contains_key(&agent));
|
assert!(!self.active_trip_mode.contains_key(&agent));
|
||||||
// TODO ensure a trip only has one active agent (aka, not walking and driving at the same
|
// TODO ensure a trip only has one active agent (aka, not walking and driving at the same
|
||||||
@ -44,6 +46,7 @@ impl TripManager {
|
|||||||
parking: &ParkingSimState,
|
parking: &ParkingSimState,
|
||||||
scheduler: &mut Scheduler,
|
scheduler: &mut Scheduler,
|
||||||
) {
|
) {
|
||||||
|
self.events.push(Event::CarReachedParkingSpot(car, spot));
|
||||||
let trip = &mut self.trips[self.active_trip_mode.remove(&AgentID::Car(car)).unwrap().0];
|
let trip = &mut self.trips[self.active_trip_mode.remove(&AgentID::Car(car)).unwrap().0];
|
||||||
|
|
||||||
match trip.legs.pop_front() {
|
match trip.legs.pop_front() {
|
||||||
@ -388,6 +391,10 @@ impl TripManager {
|
|||||||
// TODO Buses?
|
// TODO Buses?
|
||||||
self.active_trip_mode.is_empty()
|
self.active_trip_mode.is_empty()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn collect_events(&mut self) -> Vec<Event> {
|
||||||
|
self.events.drain(..).collect()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize, PartialEq, Debug)]
|
#[derive(Serialize, Deserialize, PartialEq, Debug)]
|
||||||
|
@ -28,6 +28,7 @@ pub fn run(t: &mut TestRunner) {
|
|||||||
),
|
),
|
||||||
&map,
|
&map,
|
||||||
);
|
);
|
||||||
|
sim.spawn_all_trips(&map, &mut Timer::throwaway());
|
||||||
h.setup_done(&sim);
|
h.setup_done(&sim);
|
||||||
|
|
||||||
sim.run_until_expectations_met(
|
sim.run_until_expectations_met(
|
||||||
@ -64,6 +65,7 @@ pub fn run(t: &mut TestRunner) {
|
|||||||
),
|
),
|
||||||
&map,
|
&map,
|
||||||
);
|
);
|
||||||
|
sim.spawn_all_trips(&map, &mut Timer::throwaway());
|
||||||
h.setup_done(&sim);
|
h.setup_done(&sim);
|
||||||
|
|
||||||
sim.run_until_expectations_met(
|
sim.run_until_expectations_met(
|
||||||
|
@ -56,6 +56,7 @@ pub fn run(t: &mut TestRunner) {
|
|||||||
)
|
)
|
||||||
.0
|
.0
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
sim.spawn_all_trips(&map, &mut Timer::throwaway());
|
||||||
h.setup_done(&sim);
|
h.setup_done(&sim);
|
||||||
|
|
||||||
sim.run_until_expectations_met(
|
sim.run_until_expectations_met(
|
||||||
|
Loading…
Reference in New Issue
Block a user