mirror of
https://github.com/a-b-street/abstreet.git
synced 2024-12-28 08:53:26 +03:00
remove sim's dependency on ezgui and hopefully speed up draw_unzoomed in the process
This commit is contained in:
parent
a0b69db71e
commit
e25af2e450
@ -90,7 +90,12 @@ impl UI {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
self.primary.sim.draw_unzoomed(g, &self.primary.map);
|
let (moving, waiting) = self.primary.sim.get_unzoomed_polygons(&self.primary.map);
|
||||||
|
g.draw_polygons(self.cs.get_def("moving blob of cars", Color::CYAN), &moving);
|
||||||
|
g.draw_polygons(
|
||||||
|
self.cs.get_def("waiting blob of cars", Color::RED),
|
||||||
|
&waiting,
|
||||||
|
);
|
||||||
} else {
|
} else {
|
||||||
let mut cache = self.primary.draw_map.agents.borrow_mut();
|
let mut cache = self.primary.draw_map.agents.borrow_mut();
|
||||||
let objects = self.get_renderables_back_to_front(
|
let objects = self.get_renderables_back_to_front(
|
||||||
|
@ -7,7 +7,6 @@ edition = "2018"
|
|||||||
[dependencies]
|
[dependencies]
|
||||||
abstutil = { path = "../abstutil" }
|
abstutil = { path = "../abstutil" }
|
||||||
derivative = "1.0.0"
|
derivative = "1.0.0"
|
||||||
ezgui = { path = "../ezgui" }
|
|
||||||
geom = { path = "../geom" }
|
geom = { path = "../geom" }
|
||||||
histogram = "0.6.9"
|
histogram = "0.6.9"
|
||||||
map_model = { path = "../map_model" }
|
map_model = { path = "../map_model" }
|
||||||
|
@ -6,8 +6,7 @@ use crate::{
|
|||||||
TripManager, WalkingSimState, FOLLOWING_DISTANCE,
|
TripManager, WalkingSimState, FOLLOWING_DISTANCE,
|
||||||
};
|
};
|
||||||
use abstutil::{deserialize_btreemap, serialize_btreemap};
|
use abstutil::{deserialize_btreemap, serialize_btreemap};
|
||||||
use ezgui::{Color, GfxCtx};
|
use geom::{Distance, Duration, PolyLine, Polygon};
|
||||||
use geom::{Distance, Duration, PolyLine};
|
|
||||||
use map_model::{BuildingID, DirectedRoadID, IntersectionID, LaneID, Map, Path, Traversable};
|
use map_model::{BuildingID, DirectedRoadID, IntersectionID, LaneID, Map, Path, Traversable};
|
||||||
use petgraph::graph::{Graph, NodeIndex};
|
use petgraph::graph::{Graph, NodeIndex};
|
||||||
use serde_derive::{Deserialize, Serialize};
|
use serde_derive::{Deserialize, Serialize};
|
||||||
@ -605,13 +604,13 @@ impl DrivingSimState {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn draw_unzoomed(&self, _time: Duration, g: &mut GfxCtx, map: &Map) {
|
pub fn get_unzoomed_polygons(&self, map: &Map) -> (Vec<Polygon>, Vec<Polygon>) {
|
||||||
const FREEFLOW: Color = Color::CYAN;
|
|
||||||
const WAITING: Color = Color::RED;
|
|
||||||
|
|
||||||
// These are the max over all lanes
|
// These are the max over all lanes
|
||||||
let mut moving: HashMap<DirectedRoadID, Distance> = HashMap::new();
|
let mut max_moving: HashMap<DirectedRoadID, Distance> = HashMap::new();
|
||||||
let mut waiting: HashMap<DirectedRoadID, Distance> = HashMap::new();
|
let mut max_waiting: HashMap<DirectedRoadID, Distance> = HashMap::new();
|
||||||
|
|
||||||
|
let mut moving = Vec::new();
|
||||||
|
let mut waiting = Vec::new();
|
||||||
|
|
||||||
for queue in self.queues.values() {
|
for queue in self.queues.values() {
|
||||||
if queue.cars.is_empty() {
|
if queue.cars.is_empty() {
|
||||||
@ -620,14 +619,18 @@ impl DrivingSimState {
|
|||||||
// Really coarse, strange behavior for turns. Overwrite blindly if there are concurrent turns
|
// Really coarse, strange behavior for turns. Overwrite blindly if there are concurrent turns
|
||||||
// happening. :(
|
// happening. :(
|
||||||
if let Traversable::Turn(t) = queue.id {
|
if let Traversable::Turn(t) = queue.id {
|
||||||
let color = match self.cars[&queue.cars[0]].state {
|
let polygon = map.get_i(t.parent).polygon.clone();
|
||||||
|
match self.cars[&queue.cars[0]].state {
|
||||||
CarState::Crossing(_, _)
|
CarState::Crossing(_, _)
|
||||||
| CarState::Unparking(_, _)
|
| CarState::Unparking(_, _)
|
||||||
| CarState::Parking(_, _, _)
|
| CarState::Parking(_, _, _)
|
||||||
| CarState::Idling(_, _) => FREEFLOW,
|
| CarState::Idling(_, _) => {
|
||||||
CarState::Queued | CarState::WaitingToAdvance => WAITING,
|
moving.push(polygon);
|
||||||
};
|
}
|
||||||
g.draw_polygon(color, &map.get_i(t.parent).polygon);
|
CarState::Queued | CarState::WaitingToAdvance => {
|
||||||
|
waiting.push(polygon);
|
||||||
|
}
|
||||||
|
}
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -665,16 +668,16 @@ impl DrivingSimState {
|
|||||||
let dr = map.get_l(queue.id.as_lane()).get_directed_parent(map);
|
let dr = map.get_l(queue.id.as_lane()).get_directed_parent(map);
|
||||||
|
|
||||||
if moving_len > Distance::ZERO {
|
if moving_len > Distance::ZERO {
|
||||||
let dist = moving.entry(dr).or_insert(Distance::ZERO);
|
let dist = max_moving.entry(dr).or_insert(Distance::ZERO);
|
||||||
*dist = moving_len.max(*dist);
|
*dist = moving_len.max(*dist);
|
||||||
}
|
}
|
||||||
if waiting_len > Distance::ZERO {
|
if waiting_len > Distance::ZERO {
|
||||||
let dist = waiting.entry(dr).or_insert(Distance::ZERO);
|
let dist = max_waiting.entry(dr).or_insert(Distance::ZERO);
|
||||||
*dist = waiting_len.max(*dist);
|
*dist = waiting_len.max(*dist);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (dr, len) in moving {
|
for (dr, len) in max_moving {
|
||||||
let (pl, width) = map
|
let (pl, width) = map
|
||||||
.get_r(dr.id)
|
.get_r(dr.id)
|
||||||
.get_center_for_side(dr.forwards)
|
.get_center_for_side(dr.forwards)
|
||||||
@ -682,14 +685,13 @@ impl DrivingSimState {
|
|||||||
.unwrap();
|
.unwrap();
|
||||||
// Some cars might be only partially on this road, so the length sum might be too big.
|
// Some cars might be only partially on this road, so the length sum might be too big.
|
||||||
let clamped_len = len.min(pl.length());
|
let clamped_len = len.min(pl.length());
|
||||||
g.draw_polygon(
|
moving.push(
|
||||||
FREEFLOW,
|
pl.exact_slice(Distance::ZERO, clamped_len)
|
||||||
&pl.exact_slice(Distance::ZERO, clamped_len)
|
|
||||||
.make_polygons(width),
|
.make_polygons(width),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (dr, len) in waiting {
|
for (dr, len) in max_waiting {
|
||||||
let (pl, width) = map
|
let (pl, width) = map
|
||||||
.get_r(dr.id)
|
.get_r(dr.id)
|
||||||
.get_center_for_side(dr.forwards)
|
.get_center_for_side(dr.forwards)
|
||||||
@ -697,12 +699,13 @@ impl DrivingSimState {
|
|||||||
.unwrap();
|
.unwrap();
|
||||||
// Some cars might be only partially on this road, so the length sum might be too big.
|
// Some cars might be only partially on this road, so the length sum might be too big.
|
||||||
let clamped_len = len.min(pl.length());
|
let clamped_len = len.min(pl.length());
|
||||||
g.draw_polygon(
|
waiting.push(
|
||||||
WAITING,
|
pl.exact_slice(pl.length() - clamped_len, pl.length())
|
||||||
&pl.exact_slice(pl.length() - clamped_len, pl.length())
|
|
||||||
.make_polygons(width),
|
.make_polygons(width),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
(moving, waiting)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_all_draw_cars(&self, time: Duration, map: &Map) -> Vec<DrawCarInput> {
|
pub fn get_all_draw_cars(&self, time: Duration, map: &Map) -> Vec<DrawCarInput> {
|
||||||
|
@ -7,8 +7,7 @@ use crate::{
|
|||||||
};
|
};
|
||||||
use abstutil::Timer;
|
use abstutil::Timer;
|
||||||
use derivative::Derivative;
|
use derivative::Derivative;
|
||||||
use ezgui::GfxCtx;
|
use geom::{Distance, Duration, PolyLine, Polygon, Pt2D};
|
||||||
use geom::{Distance, Duration, PolyLine, Pt2D};
|
|
||||||
use map_model::{BuildingID, BusRoute, IntersectionID, LaneID, Map, Path, Traversable};
|
use map_model::{BuildingID, BusRoute, IntersectionID, LaneID, Map, Path, Traversable};
|
||||||
use serde_derive::{Deserialize, Serialize};
|
use serde_derive::{Deserialize, Serialize};
|
||||||
use std::collections::{HashSet, VecDeque};
|
use std::collections::{HashSet, VecDeque};
|
||||||
@ -265,8 +264,9 @@ impl GetDrawAgents for Sim {
|
|||||||
|
|
||||||
// Drawing
|
// Drawing
|
||||||
impl Sim {
|
impl Sim {
|
||||||
pub fn draw_unzoomed(&self, g: &mut GfxCtx, map: &Map) {
|
// The results represent (moving, waiting) vehicles
|
||||||
self.driving.draw_unzoomed(self.time, g, map);
|
pub fn get_unzoomed_polygons(&self, map: &Map) -> (Vec<Polygon>, Vec<Polygon>) {
|
||||||
|
self.driving.get_unzoomed_polygons(map)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user