organizing sim drawing things

This commit is contained in:
Dustin Carlino 2018-11-13 11:34:17 -08:00
parent 11c2bbd11e
commit 6b5a012038
3 changed files with 69 additions and 66 deletions

View File

@ -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<TurnID>,
}
pub struct DrawCarInput {
pub id: CarID,
pub vehicle_length: Distance,
pub waiting_for_turn: Option<TurnID>,
pub front: Pt2D,
pub angle: Angle,
pub stopping_trace: Option<Trace>,
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 {}

64
sim/src/render.rs Normal file
View File

@ -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<TurnID>,
}
pub struct DrawCarInput {
pub id: CarID,
pub vehicle_length: Distance,
pub waiting_for_turn: Option<TurnID>,
pub front: Pt2D,
pub angle: Angle,
pub stopping_trace: Option<Trace>,
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<DrawCarInput> {
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<DrawPedestrianInput> {
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<DrawCarInput> {
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<DrawCarInput> {
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<DrawPedestrianInput> {
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<DrawPedestrianInput> {
self.walking_state.get_draw_peds_on_turn(map.get_t(t))
}
}

View File

@ -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<DrawCarInput> {
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<DrawPedestrianInput> {
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<DrawCarInput> {
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<DrawCarInput> {
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<DrawPedestrianInput> {
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<DrawPedestrianInput> {
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()
}