only have one Prerender object constructed, simplifying the plumbing of the Cell counters

This commit is contained in:
Dustin Carlino 2019-02-11 12:05:08 -08:00
parent 1d3e4284a7
commit 72e823c2c6
3 changed files with 19 additions and 39 deletions

View File

@ -105,16 +105,10 @@ impl<T, G: GUI<T>> State<T, G> {
&mut self,
display: &glium::Display,
program: &glium::Program,
prerender: &Prerender,
screenshot: bool,
uploads_so_far: usize,
bytes_uploaded_so_far: usize,
) -> Option<String> {
let mut target = display.draw();
let prerender = Prerender {
display,
num_uploads: Cell::new(uploads_so_far),
total_bytes_uploaded: Cell::new(bytes_uploaded_so_far),
};
let mut g = GfxCtx::new(&self.canvas, &prerender, &mut target, program);
let mut naming_hint: Option<String> = None;
@ -211,27 +205,17 @@ pub fn run<T, G: GUI<T>, F: FnOnce(&mut Canvas, &Prerender) -> G>(
gui,
};
let num_uploads = prerender.num_uploads.get();
let total_bytes_uploaded = prerender.total_bytes_uploaded.get();
loop_forever(
state,
events_loop,
display,
program,
num_uploads,
total_bytes_uploaded,
);
loop_forever(state, events_loop, program, prerender);
}
fn loop_forever<T, G: GUI<T>>(
mut state: State<T, G>,
mut events_loop: glutin::EventsLoop,
display: glium::Display,
program: glium::Program,
mut uploads_so_far: usize,
mut bytes_uploaded_so_far: usize,
prerender: Prerender,
) {
let mut wait_for_events = false;
loop {
let start_frame = Instant::now();
@ -254,19 +238,19 @@ fn loop_forever<T, G: GUI<T>>(
let any_new_events = !new_events.is_empty();
for event in new_events {
let prerender = Prerender {
display: &display,
num_uploads: Cell::new(uploads_so_far),
total_bytes_uploaded: Cell::new(bytes_uploaded_so_far),
};
let (new_state, mode) = state.event(event, &prerender);
state = new_state;
wait_for_events = mode == EventLoopMode::InputOnly;
uploads_so_far = prerender.num_uploads.get();
bytes_uploaded_so_far = prerender.total_bytes_uploaded.get();
if let EventLoopMode::ScreenCaptureEverything { zoom, max_x, max_y } = mode {
state =
widgets::screenshot_everything(state, &display, &program, zoom, max_x, max_y);
state = widgets::screenshot_everything(
state,
&prerender.display,
&program,
&prerender,
zoom,
max_x,
max_y,
);
}
}
@ -274,14 +258,8 @@ fn loop_forever<T, G: GUI<T>>(
// those events before drawing or somehow know that the release event was ignored and we
// don't need to redraw.
if any_new_events {
state.draw(
&display,
&program,
false,
uploads_so_far,
bytes_uploaded_so_far,
);
uploads_so_far = 0;
state.draw(&prerender.display, &program, &prerender, false);
prerender.num_uploads.set(0);
}
// Primitive event loop.

View File

@ -1,4 +1,5 @@
use crate::runner::{State, GUI};
use crate::Prerender;
use abstutil::Timer;
use std::io::Write;
use std::{fs, process, thread, time};
@ -7,6 +8,7 @@ pub(crate) fn screenshot_everything<T, G: GUI<T>>(
mut state: State<T, G>,
display: &glium::Display,
program: &glium::Program,
prerender: &Prerender,
zoom: f64,
max_x: f64,
max_y: f64,
@ -29,7 +31,7 @@ pub(crate) fn screenshot_everything<T, G: GUI<T>>(
state.canvas.cam_x = (tile_x as f64) * state.canvas.window_width;
state.canvas.cam_y = (tile_y as f64) * state.canvas.window_height;
let naming_hint = state.draw(display, program, true, 0, 0);
let naming_hint = state.draw(display, program, prerender, true);
// TODO Is vsync or something else causing the above redraw to not actually show up in
// time for scrot to see it? This is slow (30s total for Montlake), but stable.
thread::sleep(time::Duration::from_millis(100));

View File

@ -110,5 +110,5 @@ fn classify(num_residential_units: Option<usize>, tags: &BTreeMap<String, String
return BuildingType::Business;
}
return BuildingType::Unknown;
BuildingType::Unknown
}