mirror of
https://github.com/a-b-street/abstreet.git
synced 2024-12-28 08:53:26 +03:00
dont look up full SimStats unless needed
This commit is contained in:
parent
2d7f64e69b
commit
58c4cb5e1b
@ -4,6 +4,7 @@
|
|||||||
|
|
||||||
- cache draw stuff
|
- cache draw stuff
|
||||||
- lazy SimStats
|
- lazy SimStats
|
||||||
|
- dont consider it when comparing or serializing
|
||||||
|
|
||||||
## Quick n easy
|
## Quick n easy
|
||||||
|
|
||||||
|
@ -93,7 +93,7 @@ impl ID {
|
|||||||
ID::Parcel(id) => map.maybe_get_p(id).map(|p| Pt2D::center(&p.points)),
|
ID::Parcel(id) => map.maybe_get_p(id).map(|p| Pt2D::center(&p.points)),
|
||||||
ID::BusStop(id) => map.maybe_get_bs(id).map(|bs| bs.sidewalk_pos.pt(map)),
|
ID::BusStop(id) => map.maybe_get_bs(id).map(|bs| bs.sidewalk_pos.pt(map)),
|
||||||
ID::Area(id) => map.maybe_get_a(id).map(|a| Pt2D::center(&a.points)),
|
ID::Area(id) => map.maybe_get_a(id).map(|a| Pt2D::center(&a.points)),
|
||||||
ID::Trip(id) => sim.get_stats().canonical_pt_per_trip.get(&id).cloned(),
|
ID::Trip(id) => sim.get_canonical_pt_per_trip(id, map),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -79,10 +79,10 @@ fn diff_trip(trip: TripID, ctx: &mut PluginCtx) -> DiffTripState {
|
|||||||
.map(|(s, _)| (&s.sim, &s.map))
|
.map(|(s, _)| (&s.sim, &s.map))
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
let pt1 = primary_sim.get_stats().canonical_pt_per_trip.get(&trip);
|
let pt1 = primary_sim.get_canonical_pt_per_trip(trip, primary_map);
|
||||||
let pt2 = secondary_sim.get_stats().canonical_pt_per_trip.get(&trip);
|
let pt2 = secondary_sim.get_canonical_pt_per_trip(trip, secondary_map);
|
||||||
let line = if pt1.is_some() && pt2.is_some() {
|
let line = if pt1.is_some() && pt2.is_some() {
|
||||||
Line::maybe_new(*pt1.unwrap(), *pt2.unwrap())
|
Line::maybe_new(pt1.unwrap(), pt2.unwrap())
|
||||||
} else {
|
} else {
|
||||||
None
|
None
|
||||||
};
|
};
|
||||||
|
@ -28,8 +28,12 @@ impl Plugin for FollowState {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if let Some(trip) = self.trip {
|
if let Some(trip) = self.trip {
|
||||||
if let Some(pt) = ctx.primary.sim.get_stats().canonical_pt_per_trip.get(&trip) {
|
if let Some(pt) = ctx
|
||||||
ctx.canvas.center_on_map_pt(*pt);
|
.primary
|
||||||
|
.sim
|
||||||
|
.get_canonical_pt_per_trip(trip, &ctx.primary.map)
|
||||||
|
{
|
||||||
|
ctx.canvas.center_on_map_pt(pt);
|
||||||
} else {
|
} else {
|
||||||
// TODO ideally they wouldnt vanish for so long according to
|
// TODO ideally they wouldnt vanish for so long according to
|
||||||
// get_canonical_point_for_trip
|
// get_canonical_point_for_trip
|
||||||
|
@ -12,7 +12,7 @@ use crate::{AgentID, CarID, Event, ParkedCar, PedestrianID, SimStats, Tick, Trip
|
|||||||
use abstutil;
|
use abstutil;
|
||||||
use abstutil::Error;
|
use abstutil::Error;
|
||||||
use derivative::Derivative;
|
use derivative::Derivative;
|
||||||
use geom::Distance;
|
use geom::{Distance, Pt2D};
|
||||||
use map_model::{BuildingID, IntersectionID, LaneID, LaneType, Map, Path, Trace, Turn};
|
use map_model::{BuildingID, IntersectionID, LaneID, LaneType, Map, Path, Trace, Turn};
|
||||||
use rand::{FromEntropy, SeedableRng};
|
use rand::{FromEntropy, SeedableRng};
|
||||||
use rand_xorshift::XorShiftRng;
|
use rand_xorshift::XorShiftRng;
|
||||||
@ -397,23 +397,33 @@ impl Sim {
|
|||||||
&self.stats
|
&self.stats
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn get_canonical_pt_per_trip(&self, trip: TripID, map: &Map) -> Option<Pt2D> {
|
||||||
|
self.trips_state
|
||||||
|
.trip_to_agent(trip)
|
||||||
|
.and_then(|id| self.canonical_pt_for_agent(id, map))
|
||||||
|
}
|
||||||
|
|
||||||
fn collect_stats(&mut self, map: &Map) {
|
fn collect_stats(&mut self, map: &Map) {
|
||||||
self.stats = SimStats::new(self.time);
|
self.stats = SimStats::new(self.time);
|
||||||
for trip in self.trips_state.get_active_trips().into_iter() {
|
for trip in self.trips_state.get_active_trips().into_iter() {
|
||||||
let pt = match self.trips_state.trip_to_agent(trip) {
|
if let Some(agent) = self.trips_state.trip_to_agent(trip) {
|
||||||
Some(AgentID::Car(id)) => self
|
if let Some(pt) = self.canonical_pt_for_agent(agent, map) {
|
||||||
.driving_state
|
self.stats.canonical_pt_per_trip.insert(trip, pt);
|
||||||
.get_draw_car(id, self.time, map)
|
}
|
||||||
.map(|c| c.body.last_pt()),
|
|
||||||
Some(AgentID::Pedestrian(id)) => self
|
|
||||||
.walking_state
|
|
||||||
.get_draw_ped(id, map, self.time)
|
|
||||||
.map(|p| p.pos),
|
|
||||||
None => None,
|
|
||||||
};
|
|
||||||
if let Some(pt) = pt {
|
|
||||||
self.stats.canonical_pt_per_trip.insert(trip, pt);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn canonical_pt_for_agent(&self, id: AgentID, map: &Map) -> Option<Pt2D> {
|
||||||
|
match id {
|
||||||
|
AgentID::Car(id) => self
|
||||||
|
.driving_state
|
||||||
|
.get_draw_car(id, self.time, map)
|
||||||
|
.map(|c| c.body.last_pt()),
|
||||||
|
AgentID::Pedestrian(id) => self
|
||||||
|
.walking_state
|
||||||
|
.get_draw_ped(id, map, self.time)
|
||||||
|
.map(|p| p.pos),
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user