From 6b5a0120386ebbe44ca005e8def983b4da903253 Mon Sep 17 00:00:00 2001 From: Dustin Carlino Date: Tue, 13 Nov 2018 11:34:17 -0800 Subject: [PATCH] organizing sim drawing things --- sim/src/lib.rs | 30 +++------------------- sim/src/render.rs | 64 +++++++++++++++++++++++++++++++++++++++++++++++ sim/src/sim.rs | 41 ++---------------------------- 3 files changed, 69 insertions(+), 66 deletions(-) create mode 100644 sim/src/render.rs diff --git a/sim/src/lib.rs b/sim/src/lib.rs index 461a82e465..81faf19c56 100644 --- a/sim/src/lib.rs +++ b/sim/src/lib.rs @@ -40,6 +40,7 @@ pub mod kinematics; mod make; mod parking; mod query; +mod render; mod router; mod sim; mod spawn; @@ -51,14 +52,14 @@ mod walking; use abstutil::Cloneable; use dimensioned::si; pub use events::Event; -use geom::{Angle, Pt2D}; pub use instrument::save_backtraces; pub use make::{ load, ABTest, ABTestResults, BorderSpawnOverTime, MapEdits, Neighborhood, NeighborhoodBuilder, OriginDestination, Scenario, SeedParkedCars, SimFlags, SpawnOverTime, }; -use map_model::{BuildingID, LaneID, Trace, TurnID}; +use map_model::{BuildingID, LaneID}; pub use query::{Benchmark, ScoreSummary, SimStats, Summary}; +pub use render::{CarState, DrawCarInput, DrawPedestrianInput}; pub use sim::Sim; use std::fmt; @@ -301,31 +302,6 @@ impl ParkedCar { } } -// Intermediate structures so that sim and editor crates don't have a cyclic dependency. -pub struct DrawPedestrianInput { - pub id: PedestrianID, - pub pos: Pt2D, - pub waiting_for_turn: Option, -} - -pub struct DrawCarInput { - pub id: CarID, - pub vehicle_length: Distance, - pub waiting_for_turn: Option, - pub front: Pt2D, - pub angle: Angle, - pub stopping_trace: Option, - pub state: CarState, -} - -#[derive(PartialEq, Eq)] -pub enum CarState { - Moving, - Stuck, - Parked, - Debug, -} - // We have to do this in the crate where these types are defined. Bit annoying, since it's really // kind of an ezgui concept. impl Cloneable for Neighborhood {} diff --git a/sim/src/render.rs b/sim/src/render.rs new file mode 100644 index 0000000000..e0358aa43b --- /dev/null +++ b/sim/src/render.rs @@ -0,0 +1,64 @@ +use geom::{Angle, Pt2D}; +use map_model::{LaneID, LaneType, Map, Trace, TurnID}; +use {CarID, Distance, PedestrianID, Sim}; + +// Intermediate structures so that sim and editor crates don't have a cyclic dependency. +pub struct DrawPedestrianInput { + pub id: PedestrianID, + pub pos: Pt2D, + pub waiting_for_turn: Option, +} + +pub struct DrawCarInput { + pub id: CarID, + pub vehicle_length: Distance, + pub waiting_for_turn: Option, + pub front: Pt2D, + pub angle: Angle, + pub stopping_trace: Option, + pub state: CarState, +} + +#[derive(PartialEq, Eq)] +pub enum CarState { + Moving, + Stuck, + Parked, + Debug, +} + +impl Sim { + pub fn get_draw_car(&self, id: CarID, map: &Map) -> Option { + self.driving_state + .get_draw_car(id, self.time, map) + .or_else(|| self.parking_state.get_draw_car(id)) + } + + pub fn get_draw_ped(&self, id: PedestrianID, map: &Map) -> Option { + self.walking_state.get_draw_ped(id, map) + } + + // TODO maybe just DrawAgent instead? should caller care? + pub fn get_draw_cars_on_lane(&self, l: LaneID, map: &Map) -> Vec { + match map.get_l(l).lane_type { + LaneType::Driving | LaneType::Bus => { + self.driving_state.get_draw_cars_on_lane(l, self.time, map) + } + LaneType::Parking => self.parking_state.get_draw_cars(l), + LaneType::Sidewalk => Vec::new(), + LaneType::Biking => Vec::new(), + } + } + + pub fn get_draw_cars_on_turn(&self, t: TurnID, map: &Map) -> Vec { + self.driving_state.get_draw_cars_on_turn(t, self.time, map) + } + + pub fn get_draw_peds_on_lane(&self, l: LaneID, map: &Map) -> Vec { + self.walking_state.get_draw_peds_on_lane(map.get_l(l), map) + } + + pub fn get_draw_peds_on_turn(&self, t: TurnID, map: &Map) -> Vec { + self.walking_state.get_draw_peds_on_turn(map.get_t(t)) + } +} diff --git a/sim/src/sim.rs b/sim/src/sim.rs index fa12dbd808..3267f0f822 100644 --- a/sim/src/sim.rs +++ b/sim/src/sim.rs @@ -6,7 +6,7 @@ use control::ControlMap; use driving::DrivingSimState; use instrument::capture_backtrace; use intersections::IntersectionSimState; -use map_model::{BuildingID, IntersectionID, LaneID, LaneType, Map, Path, Trace, Turn, TurnID}; +use map_model::{BuildingID, IntersectionID, LaneID, LaneType, Map, Path, Trace, Turn}; use parking::ParkingSimState; use rand::{FromEntropy, SeedableRng, XorShiftRng}; use spawn::Spawner; @@ -16,10 +16,7 @@ use transit::TransitSimState; use trips::TripManager; use view::WorldView; use walking::WalkingSimState; -use { - AgentID, CarID, Distance, DrawCarInput, DrawPedestrianInput, Event, ParkedCar, PedestrianID, - SimStats, Tick, TripID, TIMESTEP, -}; +use {AgentID, CarID, Distance, Event, ParkedCar, PedestrianID, SimStats, Tick, TripID, TIMESTEP}; #[derive(Serialize, Deserialize, Derivative)] #[derivative(PartialEq, Eq)] @@ -242,40 +239,6 @@ impl Sim { Ok(events) } - pub fn get_draw_car(&self, id: CarID, map: &Map) -> Option { - self.driving_state - .get_draw_car(id, self.time, map) - .or_else(|| self.parking_state.get_draw_car(id)) - } - - pub fn get_draw_ped(&self, id: PedestrianID, map: &Map) -> Option { - self.walking_state.get_draw_ped(id, map) - } - - // TODO maybe just DrawAgent instead? should caller care? - pub fn get_draw_cars_on_lane(&self, l: LaneID, map: &Map) -> Vec { - match map.get_l(l).lane_type { - LaneType::Driving | LaneType::Bus => { - self.driving_state.get_draw_cars_on_lane(l, self.time, map) - } - LaneType::Parking => self.parking_state.get_draw_cars(l), - LaneType::Sidewalk => Vec::new(), - LaneType::Biking => Vec::new(), - } - } - - pub fn get_draw_cars_on_turn(&self, t: TurnID, map: &Map) -> Vec { - self.driving_state.get_draw_cars_on_turn(t, self.time, map) - } - - pub fn get_draw_peds_on_lane(&self, l: LaneID, map: &Map) -> Vec { - self.walking_state.get_draw_peds_on_lane(map.get_l(l), map) - } - - pub fn get_draw_peds_on_turn(&self, t: TurnID, map: &Map) -> Vec { - self.walking_state.get_draw_peds_on_turn(map.get_t(t)) - } - pub fn is_empty(&self) -> bool { self.time == Tick::zero() && self.is_done() }