mirror of
https://github.com/a-b-street/abstreet.git
synced 2024-12-28 08:53:26 +03:00
refactor sim->editor metadata for unzoomed/zoomed agents
This commit is contained in:
parent
147a5781ca
commit
c5fd22ae81
@ -18,7 +18,9 @@ use map_model::{
|
||||
AreaID, BuildingID, BusStopID, DirectedRoadID, IntersectionID, IntersectionType, Lane, LaneID,
|
||||
Map, RoadID, Traversable, Turn, TurnID, TurnType, LANE_THICKNESS,
|
||||
};
|
||||
use sim::{CarStatus, DrawCarInput, DrawPedestrianInput, UnzoomedAgent, VehicleType};
|
||||
use sim::{
|
||||
AgentMetadata, CarStatus, DrawCarInput, DrawPedestrianInput, UnzoomedAgent, VehicleType,
|
||||
};
|
||||
use std::borrow::Borrow;
|
||||
use std::cell::RefCell;
|
||||
use std::collections::HashMap;
|
||||
@ -434,9 +436,7 @@ impl AgentColorScheme {
|
||||
Some(VehicleType::Bus) => cs.get_def("unzoomed bus", Color::BLUE.alpha(0.5)),
|
||||
None => cs.get_def("unzoomed pedestrian", Color::ORANGE.alpha(0.5)),
|
||||
},
|
||||
AgentColorScheme::Delay => delay_color(agent.time_spent_blocked),
|
||||
AgentColorScheme::DistanceCrossedSoFar => percent_color(agent.percent_dist_crossed),
|
||||
AgentColorScheme::TripTimeSoFar => delay_color(agent.trip_time_so_far),
|
||||
_ => self.by_metadata(&agent.metadata),
|
||||
}
|
||||
}
|
||||
|
||||
@ -454,9 +454,7 @@ impl AgentColorScheme {
|
||||
}
|
||||
}
|
||||
}
|
||||
AgentColorScheme::Delay => delay_color(input.time_spent_blocked),
|
||||
AgentColorScheme::DistanceCrossedSoFar => percent_color(input.percent_dist_crossed),
|
||||
AgentColorScheme::TripTimeSoFar => delay_color(input.trip_time_so_far),
|
||||
_ => self.by_metadata(&input.metadata),
|
||||
}
|
||||
}
|
||||
|
||||
@ -469,9 +467,7 @@ impl AgentColorScheme {
|
||||
CarStatus::Stuck => cs.get_def("stuck bike", Color::RED),
|
||||
CarStatus::Parked => panic!("Can't have a parked bike {}", input.id),
|
||||
},
|
||||
AgentColorScheme::Delay => delay_color(input.time_spent_blocked),
|
||||
AgentColorScheme::DistanceCrossedSoFar => percent_color(input.percent_dist_crossed),
|
||||
AgentColorScheme::TripTimeSoFar => delay_color(input.trip_time_so_far),
|
||||
_ => self.by_metadata(&input.metadata),
|
||||
}
|
||||
}
|
||||
|
||||
@ -484,9 +480,16 @@ impl AgentColorScheme {
|
||||
cs.get_def("pedestrian", Color::rgb_f(0.2, 0.7, 0.7))
|
||||
}
|
||||
}
|
||||
AgentColorScheme::Delay => delay_color(input.time_spent_blocked),
|
||||
AgentColorScheme::DistanceCrossedSoFar => percent_color(input.percent_dist_crossed),
|
||||
AgentColorScheme::TripTimeSoFar => delay_color(input.trip_time_so_far),
|
||||
_ => self.by_metadata(&input.metadata),
|
||||
}
|
||||
}
|
||||
|
||||
fn by_metadata(self, md: &AgentMetadata) -> Color {
|
||||
match self {
|
||||
AgentColorScheme::VehicleTypes => unreachable!(),
|
||||
AgentColorScheme::Delay => delay_color(md.time_spent_blocked),
|
||||
AgentColorScheme::DistanceCrossedSoFar => percent_color(md.percent_dist_crossed),
|
||||
AgentColorScheme::TripTimeSoFar => delay_color(md.trip_time_so_far),
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -23,7 +23,8 @@ pub(crate) use self::transit::TransitSimState;
|
||||
pub use self::trips::{FinishedTrips, TripEnd, TripMode, TripStart, TripStatus};
|
||||
pub(crate) use self::trips::{TripLeg, TripManager};
|
||||
pub use crate::render::{
|
||||
CarStatus, DrawCarInput, DrawPedCrowdInput, DrawPedestrianInput, GetDrawAgents, UnzoomedAgent,
|
||||
AgentMetadata, CarStatus, DrawCarInput, DrawPedCrowdInput, DrawPedestrianInput, GetDrawAgents,
|
||||
UnzoomedAgent,
|
||||
};
|
||||
use abstutil::Cloneable;
|
||||
use geom::{Distance, Duration, Pt2D, Speed};
|
||||
|
@ -1,6 +1,6 @@
|
||||
use crate::{
|
||||
CarStatus, DistanceInterval, DrawCarInput, ParkingSpot, Router, TimeInterval, TransitSimState,
|
||||
TripID, Vehicle, VehicleType,
|
||||
AgentMetadata, CarStatus, DistanceInterval, DrawCarInput, ParkingSpot, Router, TimeInterval,
|
||||
TransitSimState, TripID, Vehicle, VehicleType,
|
||||
};
|
||||
use geom::{Distance, Duration, PolyLine};
|
||||
use map_model::{Map, Traversable, LANE_THICKNESS};
|
||||
@ -123,7 +123,6 @@ impl Car {
|
||||
_ => raw_body,
|
||||
};
|
||||
|
||||
let path = self.router.get_path();
|
||||
DrawCarInput {
|
||||
id: self.vehicle.id,
|
||||
waiting_for_turn: match self.state {
|
||||
@ -156,11 +155,17 @@ impl Car {
|
||||
None
|
||||
},
|
||||
body,
|
||||
metadata: self.metadata(now),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn metadata(&self, now: Duration) -> AgentMetadata {
|
||||
AgentMetadata {
|
||||
time_spent_blocked: self
|
||||
.blocked_since
|
||||
.map(|t| now - t)
|
||||
.unwrap_or(Duration::ZERO),
|
||||
percent_dist_crossed: path.percent_dist_crossed(),
|
||||
percent_dist_crossed: self.router.get_path().percent_dist_crossed(),
|
||||
trip_time_so_far: now - self.started_at,
|
||||
}
|
||||
}
|
||||
|
@ -650,16 +650,10 @@ impl DrivingSimState {
|
||||
|
||||
for (c, dist) in queue.get_car_positions(now, &self.cars, &self.queues) {
|
||||
let car = &self.cars[&c];
|
||||
let path = car.router.get_path();
|
||||
result.push(UnzoomedAgent {
|
||||
vehicle_type: Some(car.vehicle.vehicle_type),
|
||||
pos: queue.id.dist_along(dist, map).0,
|
||||
time_spent_blocked: car
|
||||
.blocked_since
|
||||
.map(|t| now - t)
|
||||
.unwrap_or(Duration::ZERO),
|
||||
percent_dist_crossed: path.percent_dist_crossed(),
|
||||
trip_time_so_far: now - car.started_at,
|
||||
metadata: car.metadata(now),
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
use crate::{CarID, CarStatus, DrawCarInput, ParkedCar, ParkingSpot, Vehicle};
|
||||
use crate::{AgentMetadata, CarID, CarStatus, DrawCarInput, ParkedCar, ParkingSpot, Vehicle};
|
||||
use abstutil::{
|
||||
deserialize_btreemap, deserialize_multimap, serialize_btreemap, serialize_multimap, MultiMap,
|
||||
};
|
||||
@ -161,9 +161,11 @@ impl ParkingSimState {
|
||||
status: CarStatus::Parked,
|
||||
on: Traversable::Lane(lane),
|
||||
label: None,
|
||||
metadata: AgentMetadata {
|
||||
time_spent_blocked: Duration::ZERO,
|
||||
percent_dist_crossed: 0.0,
|
||||
trip_time_so_far: Duration::ZERO,
|
||||
},
|
||||
|
||||
body: map
|
||||
.get_l(lane)
|
||||
|
@ -1,7 +1,8 @@
|
||||
use crate::{
|
||||
AgentID, Command, CreatePedestrian, DistanceInterval, DrawPedCrowdInput, DrawPedestrianInput,
|
||||
IntersectionSimState, ParkingSimState, ParkingSpot, PedestrianID, Scheduler, SidewalkPOI,
|
||||
SidewalkSpot, TimeInterval, TransitSimState, TripID, TripManager, TripPositions, UnzoomedAgent,
|
||||
AgentID, AgentMetadata, Command, CreatePedestrian, DistanceInterval, DrawPedCrowdInput,
|
||||
DrawPedestrianInput, IntersectionSimState, ParkingSimState, ParkingSpot, PedestrianID,
|
||||
Scheduler, SidewalkPOI, SidewalkSpot, TimeInterval, TransitSimState, TripID, TripManager,
|
||||
TripPositions, UnzoomedAgent,
|
||||
};
|
||||
use abstutil::{deserialize_multimap, serialize_multimap, MultiMap};
|
||||
use geom::{Distance, Duration, Line, PolyLine, Speed};
|
||||
@ -274,9 +275,7 @@ impl WalkingSimState {
|
||||
peds.push(UnzoomedAgent {
|
||||
vehicle_type: None,
|
||||
pos: ped.get_draw_ped(now, map).pos,
|
||||
time_spent_blocked: ped.blocked_since.map(|t| now - t).unwrap_or(Duration::ZERO),
|
||||
percent_dist_crossed: ped.path.percent_dist_crossed(),
|
||||
trip_time_so_far: now - ped.started_at,
|
||||
metadata: ped.metadata(now),
|
||||
});
|
||||
}
|
||||
|
||||
@ -508,6 +507,12 @@ impl Pedestrian {
|
||||
_ => false,
|
||||
},
|
||||
on,
|
||||
metadata: self.metadata(now),
|
||||
}
|
||||
}
|
||||
|
||||
fn metadata(&self, now: Duration) -> AgentMetadata {
|
||||
AgentMetadata {
|
||||
time_spent_blocked: self
|
||||
.blocked_since
|
||||
.map(|t| now - t)
|
||||
|
@ -11,6 +11,11 @@ pub struct DrawPedestrianInput {
|
||||
pub waiting_for_turn: Option<TurnID>,
|
||||
pub preparing_bike: bool,
|
||||
pub on: Traversable,
|
||||
pub metadata: AgentMetadata,
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct AgentMetadata {
|
||||
pub time_spent_blocked: Duration,
|
||||
pub percent_dist_crossed: f64,
|
||||
pub trip_time_so_far: Duration,
|
||||
@ -31,9 +36,7 @@ pub struct DrawCarInput {
|
||||
pub status: CarStatus,
|
||||
pub on: Traversable,
|
||||
pub label: Option<String>,
|
||||
pub time_spent_blocked: Duration,
|
||||
pub percent_dist_crossed: f64,
|
||||
pub trip_time_so_far: Duration,
|
||||
pub metadata: AgentMetadata,
|
||||
|
||||
// Starts at the BACK of the car.
|
||||
pub body: PolyLine,
|
||||
@ -51,9 +54,7 @@ pub struct UnzoomedAgent {
|
||||
// None means a pedestrian.
|
||||
pub vehicle_type: Option<VehicleType>,
|
||||
pub pos: Pt2D,
|
||||
pub time_spent_blocked: Duration,
|
||||
pub percent_dist_crossed: f64,
|
||||
pub trip_time_so_far: Duration,
|
||||
pub metadata: AgentMetadata,
|
||||
}
|
||||
|
||||
// TODO Can we return borrows instead? Nice for time travel, not for main sim?
|
||||
|
Loading…
Reference in New Issue
Block a user