remove old unused get_unzoomed_agents, always return details. may be a little slower than the other, but it's worthwhile to prioritize optimizing the richer representation instead of maintaining awkward dupe code

This commit is contained in:
Dustin Carlino 2019-08-18 15:08:02 -07:00
parent dd28afcd29
commit be71aa42fc
4 changed files with 9 additions and 66 deletions

View File

@ -377,7 +377,7 @@ impl AgentCache {
let mut batch = GeomBatch::new();
let radius = Distance::meters(10.0) / g.canvas.cam_zoom;
for agent in primary.sim.get_unzoomed_agents_with_details(&primary.map) {
for agent in primary.sim.get_unzoomed_agents(&primary.map) {
batch.push(
acs.color_for(&agent, cs),
Circle::new(agent.pos, radius).to_polygon(),

View File

@ -3,10 +3,10 @@ use crate::mechanics::queue::Queue;
use crate::{
ActionAtEnd, AgentID, CarID, Command, CreateCar, DistanceInterval, DrawCarInput,
IntersectionSimState, ParkedCar, ParkingSimState, Scheduler, TimeInterval, TransitSimState,
TripManager, TripPositions, UnzoomedAgent, VehicleType, WalkingSimState, FOLLOWING_DISTANCE,
TripManager, TripPositions, UnzoomedAgent, WalkingSimState, FOLLOWING_DISTANCE,
};
use abstutil::{deserialize_btreemap, serialize_btreemap};
use geom::{Distance, Duration, PolyLine, Pt2D};
use geom::{Distance, Duration, PolyLine};
use map_model::{BuildingID, IntersectionID, LaneID, Map, Path, Traversable};
use petgraph::graph::{Graph, NodeIndex};
use serde_derive::{Deserialize, Serialize};
@ -653,41 +653,7 @@ impl DrivingSimState {
}
}
// cars, bikes, buses
pub fn get_unzoomed_agents(
&self,
now: Duration,
map: &Map,
) -> (Vec<Pt2D>, Vec<Pt2D>, Vec<Pt2D>) {
let mut cars = Vec::new();
let mut bikes = Vec::new();
let mut buses = Vec::new();
for queue in self.queues.values() {
if queue.cars.is_empty() {
continue;
}
for (car, dist) in queue.get_car_positions(now, &self.cars, &self.queues) {
let result = queue.id.dist_along(dist, map).0;
match car.1 {
VehicleType::Car => {
cars.push(result);
}
VehicleType::Bike => {
bikes.push(result);
}
VehicleType::Bus => {
buses.push(result);
}
}
}
}
(cars, bikes, buses)
}
pub fn get_unzoomed_agents_with_details(&self, now: Duration, map: &Map) -> Vec<UnzoomedAgent> {
pub fn get_unzoomed_agents(&self, now: Duration, map: &Map) -> Vec<UnzoomedAgent> {
let mut result = Vec::new();
for queue in self.queues.values() {

View File

@ -4,7 +4,7 @@ use crate::{
TimeInterval, TransitSimState, TripID, TripManager, TripPositions, UnzoomedAgent,
};
use abstutil::{deserialize_multimap, serialize_multimap, MultiMap};
use geom::{Distance, Duration, Line, PolyLine, Pt2D, Speed};
use geom::{Distance, Duration, Line, PolyLine, Speed};
use map_model::{BuildingID, Map, Path, PathStep, Traversable, LANE_THICKNESS};
use serde_derive::{Deserialize, Serialize};
use std::collections::BTreeMap;
@ -262,17 +262,7 @@ impl WalkingSimState {
Some(&p.path)
}
pub fn get_unzoomed_agents(&self, now: Duration, map: &Map) -> Vec<Pt2D> {
let mut peds = Vec::new();
for ped in self.peds.values() {
peds.push(ped.get_draw_ped(now, map).pos);
}
peds
}
pub fn get_unzoomed_agents_with_details(&self, now: Duration, map: &Map) -> Vec<UnzoomedAgent> {
pub fn get_unzoomed_agents(&self, now: Duration, map: &Map) -> Vec<UnzoomedAgent> {
let mut peds = Vec::new();
for ped in self.peds.values() {

View File

@ -310,22 +310,9 @@ impl GetDrawAgents for Sim {
// Drawing
impl Sim {
// The results represent (cars, bikes, buses, pedestrians)
pub fn get_unzoomed_agents(&self, map: &Map) -> (Vec<Pt2D>, Vec<Pt2D>, Vec<Pt2D>, Vec<Pt2D>) {
let (cars, bikes, buses) = self.driving.get_unzoomed_agents(self.time, map);
let peds = self.walking.get_unzoomed_agents(self.time, map);
(cars, bikes, buses, peds)
}
// TODO Ideally we'd always return UnzoomedAgent, but it's slow!
pub fn get_unzoomed_agents_with_details(&self, map: &Map) -> Vec<UnzoomedAgent> {
let mut result = self
.driving
.get_unzoomed_agents_with_details(self.time, map);
result.extend(
self.walking
.get_unzoomed_agents_with_details(self.time, map),
);
pub fn get_unzoomed_agents(&self, map: &Map) -> Vec<UnzoomedAgent> {
let mut result = self.driving.get_unzoomed_agents(self.time, map);
result.extend(self.walking.get_unzoomed_agents(self.time, map));
result
}
}