2019-08-19 00:41:56 +03:00
|
|
|
use crate::{CarID, PedestrianID, VehicleType};
|
2019-11-27 22:49:57 +03:00
|
|
|
use geom::{Angle, Distance, Duration, PolyLine, Pt2D, Time};
|
2019-11-21 20:57:01 +03:00
|
|
|
use map_model::{BuildingID, Map, Traversable, TurnID};
|
2018-11-13 22:34:17 +03:00
|
|
|
|
2019-09-07 23:09:09 +03:00
|
|
|
// Intermediate structures so that sim and game crates don't have a cyclic dependency.
|
2018-11-23 00:02:04 +03:00
|
|
|
#[derive(Clone)]
|
2018-11-13 22:34:17 +03:00
|
|
|
pub struct DrawPedestrianInput {
|
|
|
|
pub id: PedestrianID,
|
|
|
|
pub pos: Pt2D,
|
2019-05-06 22:12:31 +03:00
|
|
|
pub facing: Angle,
|
2018-11-13 22:34:17 +03:00
|
|
|
pub waiting_for_turn: Option<TurnID>,
|
2018-11-17 01:23:33 +03:00
|
|
|
pub preparing_bike: bool,
|
2018-12-03 22:12:05 +03:00
|
|
|
pub on: Traversable,
|
2019-09-07 22:01:45 +03:00
|
|
|
pub metadata: AgentMetadata,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Clone)]
|
|
|
|
pub struct AgentMetadata {
|
2019-08-19 23:34:25 +03:00
|
|
|
pub time_spent_blocked: Duration,
|
|
|
|
pub percent_dist_crossed: f64,
|
2019-08-20 00:06:04 +03:00
|
|
|
pub trip_time_so_far: Duration,
|
2018-11-13 22:34:17 +03:00
|
|
|
}
|
|
|
|
|
2019-08-17 08:18:19 +03:00
|
|
|
pub struct DrawPedCrowdInput {
|
|
|
|
pub low: Distance,
|
|
|
|
pub high: Distance,
|
|
|
|
pub members: Vec<PedestrianID>,
|
2019-11-21 20:57:01 +03:00
|
|
|
pub location: PedCrowdLocation,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Clone)]
|
|
|
|
pub enum PedCrowdLocation {
|
|
|
|
// bool is contraflow
|
|
|
|
Sidewalk(Traversable, bool),
|
|
|
|
FrontPath(BuildingID),
|
2019-08-17 08:18:19 +03:00
|
|
|
}
|
|
|
|
|
2018-11-23 00:02:04 +03:00
|
|
|
#[derive(Clone)]
|
2018-11-13 22:34:17 +03:00
|
|
|
pub struct DrawCarInput {
|
|
|
|
pub id: CarID,
|
|
|
|
pub waiting_for_turn: Option<TurnID>,
|
2019-02-27 03:39:17 +03:00
|
|
|
pub status: CarStatus,
|
2018-12-03 22:12:05 +03:00
|
|
|
pub on: Traversable,
|
2019-08-13 22:20:28 +03:00
|
|
|
pub label: Option<String>,
|
2019-09-07 22:01:45 +03:00
|
|
|
pub metadata: AgentMetadata,
|
2019-01-11 02:11:16 +03:00
|
|
|
|
2019-08-19 23:34:25 +03:00
|
|
|
// Starts at the BACK of the car.
|
2019-01-11 02:11:16 +03:00
|
|
|
pub body: PolyLine,
|
2018-11-13 22:34:17 +03:00
|
|
|
}
|
|
|
|
|
2019-02-07 06:33:51 +03:00
|
|
|
#[derive(Clone, Copy, PartialEq, Eq)]
|
2019-02-27 03:39:17 +03:00
|
|
|
pub enum CarStatus {
|
2018-11-13 22:34:17 +03:00
|
|
|
Moving,
|
2019-10-20 01:24:40 +03:00
|
|
|
Parked,
|
2018-11-13 22:34:17 +03:00
|
|
|
}
|
|
|
|
|
2019-08-07 01:24:34 +03:00
|
|
|
pub struct UnzoomedAgent {
|
2019-08-19 00:41:56 +03:00
|
|
|
// None means a pedestrian.
|
|
|
|
pub vehicle_type: Option<VehicleType>,
|
2019-08-07 01:24:34 +03:00
|
|
|
pub pos: Pt2D,
|
2019-09-07 22:01:45 +03:00
|
|
|
pub metadata: AgentMetadata,
|
2019-08-07 01:24:34 +03:00
|
|
|
}
|
|
|
|
|
2018-11-23 00:02:04 +03:00
|
|
|
// TODO Can we return borrows instead? Nice for time travel, not for main sim?
|
|
|
|
// actually good for main sim too; we're constantly calculating stuff while sim is paused
|
|
|
|
// otherwise? except we don't know what to calculate. maybe cache it?
|
|
|
|
pub trait GetDrawAgents {
|
2019-11-27 22:49:57 +03:00
|
|
|
fn time(&self) -> Time;
|
2019-05-09 04:24:57 +03:00
|
|
|
// Every time the time changes, this should increase. For smoothly animating stuff.
|
|
|
|
fn step_count(&self) -> usize;
|
2018-11-23 00:02:04 +03:00
|
|
|
fn get_draw_car(&self, id: CarID, map: &Map) -> Option<DrawCarInput>;
|
|
|
|
fn get_draw_ped(&self, id: PedestrianID, map: &Map) -> Option<DrawPedestrianInput>;
|
2018-11-27 02:45:54 +03:00
|
|
|
fn get_draw_cars(&self, on: Traversable, map: &Map) -> Vec<DrawCarInput>;
|
2019-08-17 08:18:19 +03:00
|
|
|
fn get_draw_peds(
|
|
|
|
&self,
|
|
|
|
on: Traversable,
|
|
|
|
map: &Map,
|
|
|
|
) -> (Vec<DrawPedestrianInput>, Vec<DrawPedCrowdInput>);
|
2018-12-03 22:12:05 +03:00
|
|
|
fn get_all_draw_cars(&self, map: &Map) -> Vec<DrawCarInput>;
|
|
|
|
fn get_all_draw_peds(&self, map: &Map) -> Vec<DrawPedestrianInput>;
|
2019-10-05 02:07:07 +03:00
|
|
|
fn get_unzoomed_agents(&self, map: &Map) -> Vec<UnzoomedAgent>;
|
|
|
|
}
|
|
|
|
|
|
|
|
pub struct DontDrawAgents;
|
|
|
|
|
|
|
|
impl GetDrawAgents for DontDrawAgents {
|
2019-11-27 22:49:57 +03:00
|
|
|
fn time(&self) -> Time {
|
|
|
|
Time::START_OF_DAY
|
2019-10-05 02:07:07 +03:00
|
|
|
}
|
|
|
|
fn step_count(&self) -> usize {
|
|
|
|
0
|
|
|
|
}
|
|
|
|
fn get_draw_car(&self, _: CarID, _: &Map) -> Option<DrawCarInput> {
|
|
|
|
None
|
|
|
|
}
|
|
|
|
fn get_draw_ped(&self, _: PedestrianID, _: &Map) -> Option<DrawPedestrianInput> {
|
|
|
|
None
|
|
|
|
}
|
|
|
|
fn get_draw_cars(&self, _: Traversable, _: &Map) -> Vec<DrawCarInput> {
|
|
|
|
Vec::new()
|
|
|
|
}
|
|
|
|
fn get_draw_peds(
|
|
|
|
&self,
|
|
|
|
_: Traversable,
|
|
|
|
_: &Map,
|
|
|
|
) -> (Vec<DrawPedestrianInput>, Vec<DrawPedCrowdInput>) {
|
|
|
|
(Vec::new(), Vec::new())
|
|
|
|
}
|
|
|
|
fn get_all_draw_cars(&self, _: &Map) -> Vec<DrawCarInput> {
|
|
|
|
Vec::new()
|
|
|
|
}
|
|
|
|
fn get_all_draw_peds(&self, _: &Map) -> Vec<DrawPedestrianInput> {
|
|
|
|
Vec::new()
|
|
|
|
}
|
|
|
|
fn get_unzoomed_agents(&self, _: &Map) -> Vec<UnzoomedAgent> {
|
|
|
|
Vec::new()
|
|
|
|
}
|
2018-11-23 00:02:04 +03:00
|
|
|
}
|