mirror of
https://github.com/a-b-street/abstreet.git
synced 2024-11-28 20:29:04 +03:00
prerender buildings and parcels
This commit is contained in:
parent
25bc02fb32
commit
f59879011d
@ -68,6 +68,7 @@
|
||||
- speed
|
||||
- change ezgui API to allow uploading geometry once
|
||||
- polyline -> arrow polygon. then collapse all lane markings into one Drawable.
|
||||
- prerender lane polygons for GREAT win
|
||||
|
||||
- what about color then? get fancy and plumb an override color uniform?
|
||||
- stop storing raw geometry when appropriate
|
||||
|
@ -1,7 +1,8 @@
|
||||
use crate::colors::ColorScheme;
|
||||
use crate::objects::{Ctx, ID};
|
||||
use crate::render::{RenderOptions, Renderable};
|
||||
use dimensioned::si;
|
||||
use ezgui::{Color, GfxCtx};
|
||||
use ezgui::{Color, Drawable, GfxCtx, Prerender};
|
||||
use geom::{Bounds, Line, Polygon, Pt2D};
|
||||
use map_model::{Building, BuildingID, LANE_THICKNESS};
|
||||
|
||||
@ -9,23 +10,39 @@ pub struct DrawBuilding {
|
||||
pub id: BuildingID,
|
||||
pub fill_polygon: Polygon,
|
||||
front_path: Polygon,
|
||||
|
||||
default_draw: Drawable,
|
||||
}
|
||||
|
||||
impl DrawBuilding {
|
||||
pub fn new(bldg: &Building) -> DrawBuilding {
|
||||
pub fn new(bldg: &Building, cs: &ColorScheme, prerender: &Prerender) -> DrawBuilding {
|
||||
// Trim the front path line away from the sidewalk's center line, so that it doesn't
|
||||
// overlap. For now, this cleanup is visual; it doesn't belong in the map_model layer.
|
||||
let mut front_path = bldg.front_path.line.clone();
|
||||
let len = front_path.length();
|
||||
let mut front_path_line = bldg.front_path.line.clone();
|
||||
let len = front_path_line.length();
|
||||
let trim_back = LANE_THICKNESS / 2.0 * si::M;
|
||||
if len > trim_back {
|
||||
front_path = Line::new(front_path.pt1(), front_path.dist_along(len - trim_back));
|
||||
front_path_line = Line::new(
|
||||
front_path_line.pt1(),
|
||||
front_path_line.dist_along(len - trim_back),
|
||||
);
|
||||
}
|
||||
let fill_polygon = Polygon::new(&bldg.points);
|
||||
let front_path = front_path_line.make_polygons(1.0);
|
||||
|
||||
let default_draw = prerender.upload(vec![
|
||||
(
|
||||
cs.get_def("building", Color::rgba_f(0.7, 0.7, 0.7, 0.8)),
|
||||
&fill_polygon,
|
||||
),
|
||||
(cs.get_def("building path", Color::grey(0.6)), &front_path),
|
||||
]);
|
||||
|
||||
DrawBuilding {
|
||||
id: bldg.id,
|
||||
fill_polygon: Polygon::new(&bldg.points),
|
||||
front_path: front_path.make_polygons(1.0),
|
||||
fill_polygon,
|
||||
front_path,
|
||||
default_draw,
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -38,19 +55,15 @@ impl Renderable for DrawBuilding {
|
||||
fn draw(&self, g: &mut GfxCtx, opts: RenderOptions, ctx: &Ctx) {
|
||||
// Buildings look better without boundaries, actually
|
||||
//g.draw_polygon(ctx.cs.get_def("building boundary", Color::rgb(0, 100, 0)), &self.boundary_polygon);
|
||||
g.draw_polygon_batch(vec![
|
||||
(
|
||||
opts.color.unwrap_or_else(|| {
|
||||
ctx.cs
|
||||
.get_def("building", Color::rgba_f(0.7, 0.7, 0.7, 0.8))
|
||||
}),
|
||||
&self.fill_polygon,
|
||||
),
|
||||
(
|
||||
ctx.cs.get_def("building path", Color::grey(0.6)),
|
||||
&self.front_path,
|
||||
),
|
||||
]);
|
||||
|
||||
if let Some(c) = opts.color {
|
||||
g.draw_polygon_batch(vec![
|
||||
(c, &self.fill_polygon),
|
||||
(ctx.cs.get("building path"), &self.front_path),
|
||||
]);
|
||||
} else {
|
||||
g.redraw(&self.default_draw);
|
||||
}
|
||||
}
|
||||
|
||||
fn get_bounds(&self) -> Bounds {
|
||||
|
@ -79,13 +79,13 @@ impl DrawMap {
|
||||
.iter()
|
||||
.map(|b| {
|
||||
timer.next();
|
||||
DrawBuilding::new(b)
|
||||
DrawBuilding::new(b, cs, prerender)
|
||||
})
|
||||
.collect();
|
||||
let parcels: Vec<DrawParcel> = map
|
||||
.all_parcels()
|
||||
.iter()
|
||||
.map(|p| DrawParcel::new(p))
|
||||
.map(|p| DrawParcel::new(p, cs, prerender))
|
||||
.collect();
|
||||
|
||||
let mut extra_shapes: Vec<DrawExtraShape> = Vec::new();
|
||||
|
@ -1,6 +1,7 @@
|
||||
use crate::colors::ColorScheme;
|
||||
use crate::objects::{Ctx, ID};
|
||||
use crate::render::{RenderOptions, Renderable, PARCEL_BOUNDARY_THICKNESS};
|
||||
use ezgui::{Color, GfxCtx};
|
||||
use ezgui::{Color, Drawable, GfxCtx, Prerender};
|
||||
use geom::{Bounds, PolyLine, Polygon, Pt2D};
|
||||
use map_model::{Parcel, ParcelID};
|
||||
|
||||
@ -22,21 +23,33 @@ const COLORS: [Color; 14] = [
|
||||
Color::rgba_f(0.8, 0.2, 0.5, 0.5),
|
||||
];
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct DrawParcel {
|
||||
pub id: ParcelID,
|
||||
// TODO bit wasteful to keep both
|
||||
boundary_polygon: Polygon,
|
||||
pub fill_polygon: Polygon,
|
||||
|
||||
default_draw: Drawable,
|
||||
}
|
||||
|
||||
impl DrawParcel {
|
||||
pub fn new(p: &Parcel) -> DrawParcel {
|
||||
pub fn new(p: &Parcel, cs: &ColorScheme, prerender: &Prerender) -> DrawParcel {
|
||||
let boundary_polygon =
|
||||
PolyLine::new(p.points.clone()).make_polygons(PARCEL_BOUNDARY_THICKNESS);
|
||||
let fill_polygon = Polygon::new(&p.points);
|
||||
let default_draw = prerender.upload(vec![
|
||||
(COLORS[p.block % COLORS.len()], &fill_polygon),
|
||||
(
|
||||
cs.get_def("parcel boundary", Color::grey(0.3)),
|
||||
&boundary_polygon,
|
||||
),
|
||||
]);
|
||||
|
||||
DrawParcel {
|
||||
id: p.id,
|
||||
boundary_polygon: PolyLine::new(p.points.clone())
|
||||
.make_polygons(PARCEL_BOUNDARY_THICKNESS),
|
||||
fill_polygon: Polygon::new(&p.points),
|
||||
boundary_polygon,
|
||||
fill_polygon,
|
||||
default_draw,
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -47,17 +60,14 @@ impl Renderable for DrawParcel {
|
||||
}
|
||||
|
||||
fn draw(&self, g: &mut GfxCtx, opts: RenderOptions, ctx: &Ctx) {
|
||||
let color = opts.color.unwrap_or_else(|| {
|
||||
let p = ctx.map.get_p(self.id);
|
||||
COLORS[p.block % COLORS.len()]
|
||||
});
|
||||
g.draw_polygon_batch(vec![
|
||||
(color, &self.fill_polygon),
|
||||
(
|
||||
ctx.cs.get_def("parcel boundary", Color::grey(0.3)),
|
||||
&self.boundary_polygon,
|
||||
),
|
||||
]);
|
||||
if let Some(color) = opts.color {
|
||||
g.draw_polygon_batch(vec![
|
||||
(color, &self.fill_polygon),
|
||||
(ctx.cs.get("parcel boundary"), &self.boundary_polygon),
|
||||
]);
|
||||
} else {
|
||||
g.redraw(&self.default_draw);
|
||||
}
|
||||
}
|
||||
|
||||
fn get_bounds(&self) -> Bounds {
|
||||
|
Loading…
Reference in New Issue
Block a user