From 05ffb18fbccf590a4c6cef2922427d7a47d3ded5 Mon Sep 17 00:00:00 2001 From: Dustin Carlino Date: Thu, 28 Feb 2019 10:40:55 -0800 Subject: [PATCH] publishing an event to make the parking tests work --- sim/src/events.rs | 17 +++++------------ sim/src/sim.rs | 6 +++++- sim/src/trips.rs | 11 +++++++++-- tests/src/parking.rs | 2 ++ tests/src/transit.rs | 1 + 5 files changed, 22 insertions(+), 15 deletions(-) diff --git a/sim/src/events.rs b/sim/src/events.rs index 81ee54cfc8..05dfb0665c 100644 --- a/sim/src/events.rs +++ b/sim/src/events.rs @@ -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), } diff --git a/sim/src/sim.rs b/sim/src/sim.rs index 1d07b83c68..e29f896ae1 100644 --- a/sim/src/sim.rs +++ b/sim/src/sim.rs @@ -200,6 +200,10 @@ impl Sim { // Running impl Sim { pub fn step(&mut self, map: &Map) -> Vec { + 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) { diff --git a/sim/src/trips.rs b/sim/src/trips.rs index 684faf1e74..a9a2a159b3 100644 --- a/sim/src/trips.rs +++ b/sim/src/trips.rs @@ -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, + + events: Vec, } 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 { + self.events.drain(..).collect() + } } #[derive(Serialize, Deserialize, PartialEq, Debug)] diff --git a/tests/src/parking.rs b/tests/src/parking.rs index 9b089d4fc5..10e98bb626 100644 --- a/tests/src/parking.rs +++ b/tests/src/parking.rs @@ -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( diff --git a/tests/src/transit.rs b/tests/src/transit.rs index f72851f559..e34cff299f 100644 --- a/tests/src/transit.rs +++ b/tests/src/transit.rs @@ -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(