publishing an event to make the parking tests work

This commit is contained in:
Dustin Carlino 2019-02-28 10:40:55 -08:00
parent e6ff4481e7
commit 05ffb18fbc
5 changed files with 22 additions and 15 deletions

View File

@ -1,26 +1,19 @@
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 {
// TODO CarFinishedParking
// TODO and the pedestrian / trip associated with it?
CarReachedParkingSpot(CarID, ParkingSpot),
// TODO and the car / trip?
PedReachedParkingSpot(PedestrianID, ParkingSpot),
// TODO CarFinishedUnparking
BusArrivedAtStop(CarID, BusStopID),
BusDepartedFromStop(CarID, BusStopID),
PedReachedParkingSpot(PedestrianID, ParkingSpot),
PedReachedBuilding(PedestrianID, BuildingID),
PedReachedBusStop(PedestrianID, BusStopID),
PedEntersBus(PedestrianID, CarID),
PedLeavesBus(PedestrianID, CarID),
// TODO split up into cases or not?
AgentEntersTraversable(AgentID, Traversable),
AgentLeavesTraversable(AgentID, Traversable),
// TODO maybe AgentRequestsTurn?
IntersectionAcceptsRequest(AgentID, TurnID),
}

View File

@ -200,6 +200,10 @@ impl Sim {
// Running
impl Sim {
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.driving.step_if_needed(
@ -240,7 +244,7 @@ impl Sim {
}
}
Vec::new()
self.trips.collect_events()
}
pub fn dump_before_abort(&self) {

View File

@ -1,5 +1,5 @@
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,
};
use abstutil::{deserialize_btreemap, serialize_btreemap};
@ -17,6 +17,8 @@ pub struct TripManager {
deserialize_with = "deserialize_btreemap"
)]
active_trip_mode: BTreeMap<AgentID, TripID>,
events: Vec<Event>,
}
impl TripManager {
@ -24,10 +26,10 @@ impl TripManager {
TripManager {
trips: Vec::new(),
active_trip_mode: BTreeMap::new(),
events: Vec::new(),
}
}
// Transitions from spawner
pub fn agent_starting_trip_leg(&mut self, agent: AgentID, trip: TripID) {
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
@ -44,6 +46,7 @@ impl TripManager {
parking: &ParkingSimState,
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];
match trip.legs.pop_front() {
@ -388,6 +391,10 @@ impl TripManager {
// TODO Buses?
self.active_trip_mode.is_empty()
}
pub fn collect_events(&mut self) -> Vec<Event> {
self.events.drain(..).collect()
}
}
#[derive(Serialize, Deserialize, PartialEq, Debug)]

View File

@ -28,6 +28,7 @@ pub fn run(t: &mut TestRunner) {
),
&map,
);
sim.spawn_all_trips(&map, &mut Timer::throwaway());
h.setup_done(&sim);
sim.run_until_expectations_met(
@ -64,6 +65,7 @@ pub fn run(t: &mut TestRunner) {
),
&map,
);
sim.spawn_all_trips(&map, &mut Timer::throwaway());
h.setup_done(&sim);
sim.run_until_expectations_met(

View File

@ -56,6 +56,7 @@ pub fn run(t: &mut TestRunner) {
)
.0
.unwrap();
sim.spawn_all_trips(&map, &mut Timer::throwaway());
h.setup_done(&sim);
sim.run_until_expectations_met(