mirror of
https://github.com/a-b-street/abstreet.git
synced 2024-12-01 02:33:54 +03:00
always send along CarState in DrawCarInput, removing an annoying query method
This commit is contained in:
parent
b2e3f25393
commit
af7785d6a3
@ -15,6 +15,7 @@ pub struct DrawCar {
|
||||
turn_arrow: Option<Line>,
|
||||
// TODO maybe also draw lookahead buffer to know what the car is considering
|
||||
stopping_buffer: Option<Polygon>,
|
||||
state: CarState,
|
||||
}
|
||||
|
||||
impl DrawCar {
|
||||
@ -77,6 +78,7 @@ impl DrawCar {
|
||||
),
|
||||
],
|
||||
stopping_buffer,
|
||||
state: input.state,
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -89,7 +91,7 @@ impl Renderable for DrawCar {
|
||||
fn draw(&self, g: &mut GfxCtx, opts: RenderOptions, ctx: Ctx) {
|
||||
let color = opts.color.unwrap_or_else(|| {
|
||||
// TODO if it's a bus, color it differently -- but how? :\
|
||||
match ctx.sim.get_car_state(self.id) {
|
||||
match self.state {
|
||||
CarState::Debug => ctx
|
||||
.cs
|
||||
.get("debug car", Color::rgba(0, 0, 255, 0.8))
|
||||
|
@ -488,21 +488,6 @@ impl DrivingSimState {
|
||||
s
|
||||
}
|
||||
|
||||
pub fn get_car_state(&self, c: CarID) -> CarState {
|
||||
if let Some(driving) = self.cars.get(&c) {
|
||||
if driving.debug {
|
||||
CarState::Debug
|
||||
} else if driving.speed > kinematics::EPSILON_SPEED {
|
||||
CarState::Moving
|
||||
} else {
|
||||
CarState::Stuck
|
||||
}
|
||||
} else {
|
||||
// Assume the caller isn't asking about a nonexistent car
|
||||
CarState::Parked
|
||||
}
|
||||
}
|
||||
|
||||
pub fn get_active_and_waiting_count(&self) -> (usize, usize) {
|
||||
let waiting = self
|
||||
.cars
|
||||
@ -821,6 +806,13 @@ impl DrivingSimState {
|
||||
front: pos,
|
||||
angle,
|
||||
stopping_trace: self.trace_route(id, map, c.vehicle.stopping_distance(c.speed)),
|
||||
state: if c.debug {
|
||||
CarState::Debug
|
||||
} else if c.speed > kinematics::EPSILON_SPEED {
|
||||
CarState::Moving
|
||||
} else {
|
||||
CarState::Stuck
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
|
@ -251,14 +251,6 @@ fn time_parsing() {
|
||||
assert_eq!(Tick::parse("01:02:03.5"), Some(Tick(35 + 1200 + 36000)));
|
||||
}
|
||||
|
||||
#[derive(PartialEq, Eq)]
|
||||
pub enum CarState {
|
||||
Moving,
|
||||
Stuck,
|
||||
Parked,
|
||||
Debug,
|
||||
}
|
||||
|
||||
// TODO Don't just alias types; assert that time, dist, and speed are always positive
|
||||
pub type Time = si::Second<f64>;
|
||||
pub type Distance = si::Meter<f64>;
|
||||
@ -324,6 +316,15 @@ pub struct DrawCarInput {
|
||||
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
|
||||
|
@ -4,7 +4,7 @@ use map_model;
|
||||
use map_model::{BuildingID, Lane, LaneID, LaneType, Map};
|
||||
use std::collections::HashSet;
|
||||
use std::iter;
|
||||
use {CarID, Distance, DrawCarInput, ParkedCar, ParkingSpot};
|
||||
use {CarID, CarState, Distance, DrawCarInput, ParkedCar, ParkingSpot};
|
||||
|
||||
#[derive(Serialize, Deserialize, PartialEq, Eq)]
|
||||
pub struct ParkingSimState {
|
||||
@ -228,6 +228,7 @@ impl ParkingLane {
|
||||
front: front,
|
||||
angle: angle,
|
||||
stopping_trace: None,
|
||||
state: CarState::Parked,
|
||||
})
|
||||
})
|
||||
}).collect()
|
||||
|
@ -21,8 +21,8 @@ use trips::TripManager;
|
||||
use view::WorldView;
|
||||
use walking::WalkingSimState;
|
||||
use {
|
||||
AgentID, CarID, CarState, Distance, DrawCarInput, DrawPedestrianInput, Event, ParkedCar,
|
||||
PedestrianID, ScoreSummary, SimStats, Tick, TripID, TIMESTEP,
|
||||
AgentID, CarID, Distance, DrawCarInput, DrawPedestrianInput, Event, ParkedCar, PedestrianID,
|
||||
ScoreSummary, SimStats, Tick, TripID, TIMESTEP,
|
||||
};
|
||||
|
||||
#[derive(Serialize, Deserialize, Derivative)]
|
||||
@ -246,10 +246,6 @@ impl Sim {
|
||||
Ok(events)
|
||||
}
|
||||
|
||||
pub fn get_car_state(&self, c: CarID) -> CarState {
|
||||
self.driving_state.get_car_state(c)
|
||||
}
|
||||
|
||||
pub fn get_draw_car(&self, id: CarID, map: &Map) -> Option<DrawCarInput> {
|
||||
self.driving_state
|
||||
.get_draw_car(id, self.time, map)
|
||||
|
Loading…
Reference in New Issue
Block a user