start drawing agents in the minimap. theyre a bit big.

This commit is contained in:
Dustin Carlino 2019-12-16 18:46:03 -08:00
parent eda40ecdec
commit 4046be3966
3 changed files with 40 additions and 13 deletions

View File

@ -127,6 +127,17 @@ impl Minimap {
);
g.redraw_clipped(&ui.primary.draw_map.draw_all_buildings, &inner_rect);
let mut cache = ui.primary.draw_map.agents.borrow_mut();
cache.draw_unzoomed_agents(
&ui.primary.sim,
&ui.primary.map,
ui.agent_cs,
&ui.cs,
g,
Some(&inner_rect),
zoom,
);
// The cursor
let (x1, y1) = {
let pt = g.canvas.screen_to_map(ScreenPt::new(0.0, 0.0));

View File

@ -11,7 +11,7 @@ use crate::render::Renderable;
use crate::ui::Flags;
use aabb_quadtree::QuadTree;
use abstutil::{Cloneable, Timer};
use ezgui::{Color, Drawable, EventCtx, GeomBatch, GfxCtx, Line, Text};
use ezgui::{Color, Drawable, EventCtx, GeomBatch, GfxCtx, Line, ScreenRectangle, Text};
use geom::{Bounds, Circle, Distance, Duration, FindClosest, Time};
use map_model::{
AreaID, BuildingID, BusStopID, DirectedRoadID, Intersection, IntersectionID, LaneID, Map, Road,
@ -296,10 +296,11 @@ impl DrawMap {
}
pub struct AgentCache {
// This time applies to agents_per_on. unzoomed has its own possibly separate Time!
time: Option<Time>,
agents_per_on: HashMap<Traversable, Vec<Box<dyn Renderable>>>,
// cam_zoom also matters
unzoomed: Option<(f64, Drawable)>,
unzoomed: Option<(Time, f64, Drawable)>,
}
impl AgentCache {
@ -334,6 +335,8 @@ impl AgentCache {
self.unzoomed = None;
}
// TODO GetDrawAgents indirection added for time traveling, but that's been removed. Maybe
// simplify this.
pub fn draw_unzoomed_agents(
&mut self,
source: &dyn GetDrawAgents,
@ -341,11 +344,17 @@ impl AgentCache {
acs: AgentColorScheme,
cs: &ColorScheme,
g: &mut GfxCtx,
clip: Option<&ScreenRectangle>,
cam_zoom: f64,
) {
let now = source.time();
if let Some((z, ref draw)) = self.unzoomed {
if g.canvas.cam_zoom == z && Some(now) == self.time {
g.redraw(draw);
if let Some((time, z, ref draw)) = self.unzoomed {
if cam_zoom == z && now == time {
if let Some(ref rect) = clip {
g.redraw_clipped(draw, rect);
} else {
g.redraw(draw);
}
return;
}
}
@ -356,18 +365,17 @@ impl AgentCache {
for agent in source.get_unzoomed_agents(map) {
batch.push(
acs.unzoomed_color(&agent, cs),
Circle::new(agent.pos, acs.unzoomed_radius(&agent) / g.canvas.cam_zoom)
.to_polygon(),
Circle::new(agent.pos, acs.unzoomed_radius(&agent) / cam_zoom).to_polygon(),
);
}
let draw = g.upload(batch);
g.redraw(&draw);
self.unzoomed = Some((g.canvas.cam_zoom, draw));
if Some(now) != self.time {
self.agents_per_on.clear();
self.time = Some(now);
if let Some(ref rect) = clip {
g.redraw_clipped(&draw, rect);
} else {
g.redraw(&draw);
}
self.unzoomed = Some((now, cam_zoom, draw));
}
}

View File

@ -145,7 +145,15 @@ impl UI {
}
let mut cache = self.primary.draw_map.agents.borrow_mut();
cache.draw_unzoomed_agents(source, &self.primary.map, self.agent_cs, &self.cs, g);
cache.draw_unzoomed_agents(
source,
&self.primary.map,
self.agent_cs,
&self.cs,
g,
None,
g.canvas.cam_zoom,
);
} else {
let mut cache = self.primary.draw_map.agents.borrow_mut();
let objects = self.get_renderables_back_to_front(