prerender crosswalks

This commit is contained in:
Dustin Carlino 2019-02-02 15:22:30 -08:00
parent 3f4711b13d
commit 461efe4ef8
3 changed files with 24 additions and 16 deletions

View File

@ -91,5 +91,4 @@
## Performance
- crosswalks still not batched
- it's a pity we have to redo DrawCar work for all those parked cars every tick

View File

@ -50,7 +50,7 @@ impl DrawIntersection {
DrawIntersection {
id: i.id,
polygon: i.polygon.clone(),
crosswalks: calculate_crosswalks(i.id, map),
crosswalks: calculate_crosswalks(i.id, map, prerender, cs),
intersection_type: i.intersection_type,
zorder: i.get_zorder(map),
draw_default: prerender.upload(default_geom),
@ -86,7 +86,7 @@ impl Renderable for DrawIntersection {
}
} else {
for crosswalk in &self.crosswalks {
crosswalk.draw(g, ctx.cs.get_def("crosswalk", Color::WHITE));
crosswalk.draw(g);
}
}
}
@ -105,12 +105,17 @@ impl Renderable for DrawIntersection {
}
}
fn calculate_crosswalks(i: IntersectionID, map: &Map) -> Vec<DrawCrosswalk> {
fn calculate_crosswalks(
i: IntersectionID,
map: &Map,
prerender: &Prerender,
cs: &ColorScheme,
) -> Vec<DrawCrosswalk> {
let mut crosswalks = Vec::new();
for turn in &map.get_turns_in_intersection(i) {
// Avoid double-rendering
if turn.turn_type == TurnType::Crosswalk && map.get_l(turn.id.src).dst_i == i {
crosswalks.push(DrawCrosswalk::new(turn));
crosswalks.push(DrawCrosswalk::new(turn, prerender, cs));
}
}
crosswalks
@ -174,7 +179,7 @@ pub fn draw_signal_cycle(cycle: &Cycle, g: &mut GfxCtx, ctx: &Ctx) {
for crosswalk in &ctx.draw_map.get_i(cycle.parent).crosswalks {
if cycle.get_priority(crosswalk.id1) == TurnPriority::Priority {
crosswalk.draw(g, ctx.cs.get("crosswalk"));
crosswalk.draw(g);
}
}
for t in &cycle.priority_turns {

View File

@ -1,10 +1,11 @@
use crate::colors::ColorScheme;
use crate::objects::{Ctx, ID};
use crate::render::{
RenderOptions, Renderable, BIG_ARROW_THICKNESS, CROSSWALK_LINE_THICKNESS,
TURN_ICON_ARROW_LENGTH, TURN_ICON_ARROW_THICKNESS,
};
use ezgui::{Color, GfxCtx};
use geom::{Bounds, Circle, Distance, Line, Polygon, Pt2D};
use ezgui::{Color, Drawable, GfxCtx, Prerender};
use geom::{Bounds, Circle, Distance, Line, Pt2D};
use map_model::{Map, Turn, TurnID, LANE_THICKNESS};
#[derive(Debug)]
@ -105,15 +106,14 @@ impl Renderable for DrawTurn {
}
}
#[derive(Debug)]
pub struct DrawCrosswalk {
// This is arbitrarily one of the two IDs
pub id1: TurnID,
draw: Vec<Polygon>,
draw_default: Drawable,
}
impl DrawCrosswalk {
pub fn new(turn: &Turn) -> DrawCrosswalk {
pub fn new(turn: &Turn, prerender: &Prerender, cs: &ColorScheme) -> DrawCrosswalk {
// Start at least LANE_THICKNESS out to not hit sidewalk corners. Also account for
// the thickness of the crosswalk line itself. Center the lines inside these two
// boundaries.
@ -136,19 +136,23 @@ impl DrawCrosswalk {
let pt1 = line.dist_along(dist_along);
// Reuse perp_line. Project away an arbitrary amount
let pt2 = pt1.project_away(Distance::meters(1.0), turn.angle());
draw.push(
draw.push((
cs.get_def("crosswalk", Color::WHITE),
perp_line(Line::new(pt1, pt2), LANE_THICKNESS)
.make_polygons(CROSSWALK_LINE_THICKNESS),
);
));
dist_along += tile_every;
}
}
DrawCrosswalk { id1: turn.id, draw }
DrawCrosswalk {
id1: turn.id,
draw_default: prerender.upload(draw),
}
}
pub fn draw(&self, g: &mut GfxCtx, color: Color) {
g.draw_polygon_batch(self.draw.iter().map(|poly| (color, poly)).collect());
pub fn draw(&self, g: &mut GfxCtx) {
g.redraw(&self.draw_default);
}
}