mirror of
https://github.com/a-b-street/abstreet.git
synced 2024-11-24 17:37:22 +03:00
simple perf boosts: avoiding some unnecessary GPU uploads every frame
This commit is contained in:
parent
44128b3615
commit
e7bda09978
@ -10,6 +10,7 @@ profiler = ["cpuprofiler"]
|
||||
|
||||
[dependencies]
|
||||
abstutil = { path = "../abstutil" }
|
||||
# backtrace = "0.3.40"
|
||||
cpuprofiler = { version = "0.0.3", optional = true }
|
||||
geom = { path = "../geom" }
|
||||
glium = "0.25.1"
|
||||
|
@ -417,6 +417,9 @@ impl<'a> Prerender<'a> {
|
||||
}
|
||||
|
||||
fn actually_upload(&self, permanent: bool, list: Vec<(Color, &Polygon)>) -> Drawable {
|
||||
//let bt = format!("{:?}", backtrace::Backtrace::new());
|
||||
//println!("{}", bt);
|
||||
|
||||
self.num_uploads.set(self.num_uploads.get() + 1);
|
||||
|
||||
let mut vertices: Vec<Vertex> = Vec::new();
|
||||
|
@ -1,8 +1,8 @@
|
||||
use crate::layout::{stack_vertically, ContainerOrientation, Widget};
|
||||
use crate::widgets::text_box::TextBox;
|
||||
use crate::{
|
||||
hotkey, Canvas, Color, EventCtx, EventLoopMode, GfxCtx, InputResult, Key, Line, ModalMenu,
|
||||
MultiKey, ScreenDims, ScreenPt, ScreenRectangle, Text, Warper,
|
||||
hotkey, Canvas, Color, EventCtx, EventLoopMode, GeomBatch, GfxCtx, InputResult, Key, Line,
|
||||
ModalMenu, MultiKey, ScreenDims, ScreenPt, ScreenRectangle, Text, Warper,
|
||||
};
|
||||
use geom::{Distance, Duration, Polygon, Pt2D};
|
||||
|
||||
@ -98,12 +98,13 @@ impl Slider {
|
||||
}
|
||||
|
||||
pub fn draw(&self, g: &mut GfxCtx) {
|
||||
g.fork_screenspace();
|
||||
// TODO Cache the batch
|
||||
let mut batch = GeomBatch::new();
|
||||
|
||||
// A nice background for the entire thing
|
||||
g.draw_polygon(
|
||||
batch.push(
|
||||
Color::grey(0.3),
|
||||
&Polygon::rectangle_topleft(
|
||||
Polygon::rectangle_topleft(
|
||||
Pt2D::new(self.top_left.x, self.top_left.y),
|
||||
Distance::meters(self.dims.total_width),
|
||||
Distance::meters(self.dims.bar_height + 2.0 * self.dims.vert_padding),
|
||||
@ -117,9 +118,9 @@ impl Slider {
|
||||
});
|
||||
|
||||
// The bar
|
||||
g.draw_polygon(
|
||||
batch.push(
|
||||
Color::WHITE,
|
||||
&Polygon::rectangle_topleft(
|
||||
Polygon::rectangle_topleft(
|
||||
Pt2D::new(
|
||||
self.top_left.x + self.dims.horiz_padding,
|
||||
self.top_left.y + self.dims.vert_padding,
|
||||
@ -131,9 +132,9 @@ impl Slider {
|
||||
|
||||
// Show the progress
|
||||
if self.current_percent != 0.0 {
|
||||
g.draw_polygon(
|
||||
batch.push(
|
||||
Color::GREEN,
|
||||
&Polygon::rectangle_topleft(
|
||||
Polygon::rectangle_topleft(
|
||||
Pt2D::new(
|
||||
self.top_left.x + self.dims.horiz_padding,
|
||||
self.top_left.y + self.dims.vert_padding,
|
||||
@ -145,14 +146,18 @@ impl Slider {
|
||||
}
|
||||
|
||||
// The actual slider
|
||||
g.draw_polygon(
|
||||
batch.push(
|
||||
if self.mouse_on_slider {
|
||||
Color::YELLOW
|
||||
} else {
|
||||
Color::grey(0.7)
|
||||
},
|
||||
&self.slider_geom(),
|
||||
self.slider_geom(),
|
||||
);
|
||||
|
||||
g.fork_screenspace();
|
||||
batch.draw(g);
|
||||
g.unfork();
|
||||
}
|
||||
|
||||
fn slider_geom(&self) -> Polygon {
|
||||
|
@ -182,11 +182,7 @@ fn info_for(id: ID, ui: &UI, ctx: &EventCtx) -> Text {
|
||||
)
|
||||
)));
|
||||
}
|
||||
// TODO No way to trigger the info panel for this yet.
|
||||
ID::Turn(id) => {
|
||||
let t = map.get_t(id);
|
||||
txt.add(Line(format!("{:?}", t.turn_type)));
|
||||
}
|
||||
ID::Turn(_) => unreachable!(),
|
||||
ID::Building(id) => {
|
||||
let b = map.get_b(id);
|
||||
txt.add(Line(format!(
|
||||
|
@ -43,7 +43,6 @@ enum Goal {
|
||||
|
||||
impl AgentSpawner {
|
||||
pub fn new(ctx: &mut EventCtx, ui: &mut UI) -> Option<Box<dyn State>> {
|
||||
let menu = ModalMenu::new("Agent Spawner", vec![(hotkey(Key::Escape), "quit")], ctx);
|
||||
let map = &ui.primary.map;
|
||||
match ui.primary.current_selection {
|
||||
Some(ID::Building(id)) => {
|
||||
@ -66,7 +65,11 @@ impl AgentSpawner {
|
||||
.contextual_action(Key::F3, "spawn a pedestrian starting here just walking")
|
||||
{
|
||||
return Some(Box::new(AgentSpawner {
|
||||
menu,
|
||||
menu: ModalMenu::new(
|
||||
"Agent Spawner",
|
||||
vec![(hotkey(Key::Escape), "quit")],
|
||||
ctx,
|
||||
),
|
||||
from: Source::WalkFromBldg(id),
|
||||
maybe_goal: None,
|
||||
}));
|
||||
@ -80,7 +83,11 @@ impl AgentSpawner {
|
||||
)
|
||||
{
|
||||
return Some(Box::new(AgentSpawner {
|
||||
menu,
|
||||
menu: ModalMenu::new(
|
||||
"Agent Spawner",
|
||||
vec![(hotkey(Key::Escape), "quit")],
|
||||
ctx,
|
||||
),
|
||||
from: Source::WalkFromBldgThenMaybeUseCar(id),
|
||||
maybe_goal: None,
|
||||
}));
|
||||
@ -91,7 +98,11 @@ impl AgentSpawner {
|
||||
.contextual_action(Key::F4, "spawn a car starting here")
|
||||
{
|
||||
return Some(Box::new(AgentSpawner {
|
||||
menu,
|
||||
menu: ModalMenu::new(
|
||||
"Agent Spawner",
|
||||
vec![(hotkey(Key::Escape), "quit")],
|
||||
ctx,
|
||||
),
|
||||
from: Source::Drive(pos),
|
||||
maybe_goal: None,
|
||||
}));
|
||||
@ -103,7 +114,11 @@ impl AgentSpawner {
|
||||
.contextual_action(Key::F7, "spawn a bike starting here")
|
||||
{
|
||||
return Some(Box::new(AgentSpawner {
|
||||
menu,
|
||||
menu: ModalMenu::new(
|
||||
"Agent Spawner",
|
||||
vec![(hotkey(Key::Escape), "quit")],
|
||||
ctx,
|
||||
),
|
||||
from: Source::BikeFromBldg(id, pos),
|
||||
maybe_goal: None,
|
||||
}));
|
||||
@ -117,7 +132,11 @@ impl AgentSpawner {
|
||||
.contextual_action(Key::F3, "spawn a car starting here")
|
||||
{
|
||||
return Some(Box::new(AgentSpawner {
|
||||
menu,
|
||||
menu: ModalMenu::new(
|
||||
"Agent Spawner",
|
||||
vec![(hotkey(Key::Escape), "quit")],
|
||||
ctx,
|
||||
),
|
||||
from: Source::Drive(Position::new(id, map.get_l(id).length() / 2.0)),
|
||||
maybe_goal: None,
|
||||
}));
|
||||
@ -127,7 +146,11 @@ impl AgentSpawner {
|
||||
.contextual_action(Key::F3, "spawn a pedestrian starting here")
|
||||
{
|
||||
return Some(Box::new(AgentSpawner {
|
||||
menu,
|
||||
menu: ModalMenu::new(
|
||||
"Agent Spawner",
|
||||
vec![(hotkey(Key::Escape), "quit")],
|
||||
ctx,
|
||||
),
|
||||
from: Source::WalkFromSidewalk(Position::new(
|
||||
id,
|
||||
map.get_l(id).length() / 2.0,
|
||||
|
Loading…
Reference in New Issue
Block a user