mirror of
https://github.com/a-b-street/abstreet.git
synced 2024-11-28 03:35:51 +03:00
call Timer.done automatically using Drop trait. use throwaway less
This commit is contained in:
parent
f6a6bb888e
commit
f249c6b2d9
@ -118,33 +118,8 @@ impl Timer {
|
||||
self.warnings.push(line);
|
||||
}
|
||||
|
||||
pub fn done(mut self) {
|
||||
let stop_name = self.outermost_name.clone();
|
||||
self.stop(&stop_name);
|
||||
assert!(self.stack.is_empty());
|
||||
println!();
|
||||
for line in self.results {
|
||||
println!("{}", line);
|
||||
}
|
||||
println!();
|
||||
|
||||
if !self.notes.is_empty() {
|
||||
println!("{} notes:", self.notes.len());
|
||||
for line in self.notes {
|
||||
println!("{}", line);
|
||||
}
|
||||
println!();
|
||||
}
|
||||
notes::dump_notes();
|
||||
|
||||
if !self.warnings.is_empty() {
|
||||
println!("{} warnings:", self.warnings.len());
|
||||
for line in self.warnings {
|
||||
println!("{}", line);
|
||||
}
|
||||
println!();
|
||||
}
|
||||
}
|
||||
// Used to end the scope of a timer early.
|
||||
pub fn done(self) {}
|
||||
|
||||
pub fn start(&mut self, name: &str) {
|
||||
println!("{}...", name);
|
||||
@ -258,6 +233,36 @@ impl Timer {
|
||||
}
|
||||
}
|
||||
|
||||
impl std::ops::Drop for Timer {
|
||||
fn drop(&mut self) {
|
||||
let stop_name = self.outermost_name.clone();
|
||||
self.stop(&stop_name);
|
||||
assert!(self.stack.is_empty());
|
||||
println!();
|
||||
for line in &self.results {
|
||||
println!("{}", line);
|
||||
}
|
||||
println!();
|
||||
|
||||
if !self.notes.is_empty() {
|
||||
println!("{} notes:", self.notes.len());
|
||||
for line in &self.notes {
|
||||
println!("{}", line);
|
||||
}
|
||||
println!();
|
||||
}
|
||||
notes::dump_notes();
|
||||
|
||||
if !self.warnings.is_empty() {
|
||||
println!("{} warnings:", self.warnings.len());
|
||||
for line in &self.warnings {
|
||||
println!("{}", line);
|
||||
}
|
||||
println!();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// For repeated things
|
||||
// TODO Why does the PartialEq derivation in sim require this?
|
||||
#[derive(Default)]
|
||||
|
@ -9,5 +9,4 @@ fn main() {
|
||||
timer.start("saving map");
|
||||
abstutil::write_binary(&flags.output, &map).expect("serializing map failed");
|
||||
timer.stop("saving map");
|
||||
timer.done();
|
||||
}
|
||||
|
@ -111,7 +111,8 @@ impl viewer::ObjectID for ID {
|
||||
}
|
||||
|
||||
fn load_initial_map(filename: &str, canvas: &mut Canvas, prerender: &Prerender) -> World<ID> {
|
||||
let data: raw_data::InitialMap = read_binary(filename, &mut Timer::throwaway()).unwrap();
|
||||
let data: raw_data::InitialMap =
|
||||
read_binary(filename, &mut Timer::new("load InitialMap")).unwrap();
|
||||
|
||||
let mut w = World::new(&data.bounds);
|
||||
|
||||
|
@ -39,7 +39,11 @@ impl DebugPolygon {
|
||||
.contextual_action(Key::F2, "debug sidewalk corners")
|
||||
{
|
||||
return Some(DebugPolygon {
|
||||
items: calculate_corners(i, &ctx.primary.map, &mut Timer::throwaway())
|
||||
items: calculate_corners(
|
||||
i,
|
||||
&ctx.primary.map,
|
||||
&mut Timer::new("calculate corners"),
|
||||
)
|
||||
.into_iter()
|
||||
.map(Item::Polygon)
|
||||
.collect(),
|
||||
|
@ -194,7 +194,7 @@ impl BlockingPlugin for SpawnAgent {
|
||||
}
|
||||
}
|
||||
};
|
||||
sim.spawn_all_trips(map, &mut Timer::throwaway());
|
||||
sim.spawn_all_trips(map, &mut Timer::new("spawn trip"));
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -47,14 +47,12 @@ impl BlockingPlugin for ScenarioManager {
|
||||
} else if ctx.input.modal_action("edit") {
|
||||
*self = ScenarioManager::EditScenario(scenario.clone(), Wizard::new());
|
||||
} else if ctx.input.modal_action("instantiate") {
|
||||
let mut timer = Timer::new("instantiate scenario");
|
||||
scenario.instantiate(
|
||||
&mut ctx.primary.sim,
|
||||
&ctx.primary.map,
|
||||
&mut ctx.primary.current_flags.sim_flags.make_rng(),
|
||||
&mut timer,
|
||||
&mut Timer::new("instantiate scenario"),
|
||||
);
|
||||
timer.done();
|
||||
return false;
|
||||
} else if scroller.event(&mut ctx.input) {
|
||||
return false;
|
||||
|
@ -60,7 +60,7 @@ impl BlockingPlugin for StopSignEditor {
|
||||
} else if input.modal_action("quit") {
|
||||
return false;
|
||||
} else if input.modal_action("reset to default") {
|
||||
let sign = ControlStopSign::new(map, self.i, &mut Timer::throwaway());
|
||||
let sign = ControlStopSign::new(map, self.i, &mut Timer::new("reset ControlStopSign"));
|
||||
map.edit_stop_sign(sign);
|
||||
}
|
||||
true
|
||||
|
@ -144,7 +144,7 @@ impl AmbientPluginWithPrimaryPlugins for SimControls {
|
||||
&mut ctx.primary.sim,
|
||||
&ctx.primary.map,
|
||||
&mut ctx.primary.current_flags.sim_flags.make_rng(),
|
||||
&mut Timer::throwaway(),
|
||||
&mut Timer::new("seed sim"),
|
||||
);
|
||||
*ctx.recalculate_current_selection = true;
|
||||
}
|
||||
|
@ -291,7 +291,7 @@ impl DrawMap {
|
||||
true,
|
||||
cs,
|
||||
prerender,
|
||||
&mut Timer::throwaway(),
|
||||
&mut Timer::new("recalculate DrawLane"),
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -484,7 +484,6 @@ impl PerMapUI {
|
||||
current_flags: flags.clone(),
|
||||
};
|
||||
let plugins = PluginsPerMap::new(&state, &mut timer, enable_debug_controls);
|
||||
timer.done();
|
||||
(state, plugins)
|
||||
}
|
||||
}
|
||||
|
@ -160,6 +160,6 @@ fn setup_scenario(primary: &mut PerMapUI) {
|
||||
&mut primary.sim,
|
||||
map,
|
||||
&mut primary.current_flags.sim_flags.make_rng(),
|
||||
&mut Timer::throwaway(),
|
||||
&mut Timer::new("setup tutorial"),
|
||||
);
|
||||
}
|
||||
|
@ -31,11 +31,11 @@ impl UI {
|
||||
Map::new(
|
||||
&flags.load_map,
|
||||
MapEdits::new("map name"),
|
||||
&mut Timer::throwaway(),
|
||||
&mut Timer::new("load map"),
|
||||
)
|
||||
.unwrap()
|
||||
} else {
|
||||
abstutil::read_binary(&flags.load_map, &mut Timer::throwaway()).unwrap()
|
||||
abstutil::read_binary(&flags.load_map, &mut Timer::new("load map")).unwrap()
|
||||
};
|
||||
|
||||
UI {
|
||||
|
@ -4,16 +4,18 @@ use structopt::StructOpt;
|
||||
fn main() {
|
||||
let flags = kml::Flags::from_args();
|
||||
|
||||
let mut timer = abstutil::Timer::new("extracting shapes from KML");
|
||||
|
||||
// TODO don't hardcode
|
||||
let mut bounds = GPSBounds::new();
|
||||
bounds.update(LonLat::new(-122.4416, 47.5793));
|
||||
bounds.update(LonLat::new(-122.2421, 47.7155));
|
||||
|
||||
let shapes = kml::load(&flags.input, &bounds, &mut timer).unwrap();
|
||||
let shapes = kml::load(
|
||||
&flags.input,
|
||||
&bounds,
|
||||
&mut abstutil::Timer::new("extracting shapes from KML"),
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
println!("Writing to {}", flags.output);
|
||||
abstutil::write_binary(&flags.output, &shapes).unwrap();
|
||||
timer.done();
|
||||
}
|
||||
|
@ -43,5 +43,4 @@ fn main() {
|
||||
timer.start("save map");
|
||||
map.save();
|
||||
timer.stop("save map");
|
||||
timer.done();
|
||||
}
|
||||
|
@ -385,7 +385,7 @@ impl Model {
|
||||
|
||||
// TODO Directly use raw_data and get rid of Model? Might be more maintainable long-term.
|
||||
pub fn import(path: &str) -> (Model, QuadTree<ID>) {
|
||||
let data: raw_data::Map = read_binary(path, &mut Timer::throwaway()).unwrap();
|
||||
let data: raw_data::Map = read_binary(path, &mut Timer::new("load map")).unwrap();
|
||||
let gps_bounds = data.get_gps_bounds();
|
||||
|
||||
let mut m = Model::new();
|
||||
|
Loading…
Reference in New Issue
Block a user