From 40206eccc3c87bb9a6c7be9bde8abaa6e6ad616e Mon Sep 17 00:00:00 2001 From: Dustin Carlino Date: Wed, 20 Feb 2019 11:24:21 -0800 Subject: [PATCH] removing most log usage from editor --- editor/src/macros.rs | 38 --------------------- editor/src/main.rs | 3 -- editor/src/plugins/debug/chokepoints.rs | 2 +- editor/src/plugins/debug/debug_polygon.rs | 3 +- editor/src/plugins/debug/geom_validation.rs | 12 +++---- editor/src/plugins/debug/hider.rs | 4 +-- editor/src/plugins/debug/spawn_agent.rs | 8 ++--- editor/src/plugins/edit/a_b_tests.rs | 2 +- editor/src/plugins/edit/color_picker.rs | 2 +- editor/src/plugins/edit/map_edits.rs | 2 +- editor/src/plugins/edit/road_editor.rs | 2 +- editor/src/plugins/sim/controls.rs | 6 ++-- editor/src/plugins/sim/diff_trip.rs | 2 +- editor/src/plugins/view/follow.rs | 2 +- editor/src/plugins/view/show_route.rs | 4 +-- editor/src/plugins/view/warp.rs | 14 ++++---- editor/src/render/intersection.rs | 8 ++--- editor/src/render/map.rs | 4 +-- editor/src/ui.rs | 16 +++++---- ezgui/Cargo.toml | 1 - ezgui/src/widgets/wizard.rs | 3 +- 21 files changed, 49 insertions(+), 89 deletions(-) delete mode 100644 editor/src/macros.rs diff --git a/editor/src/macros.rs b/editor/src/macros.rs deleted file mode 100644 index 2ba66e8fca..0000000000 --- a/editor/src/macros.rs +++ /dev/null @@ -1,38 +0,0 @@ -// Call the log crate, but pre-set the target. - -#[allow(unused_macros)] -macro_rules! debug { - ( $( $x:expr ),* ) => { - { - use log::log; - log!(target: "UI", log::Level::Debug, $( $x, )* ); - } - } -} - -macro_rules! info { - ( $( $x:expr ),* ) => { - { - use log::log; - log!(target: "UI", log::Level::Info, $( $x, )* ); - } - } -} - -macro_rules! warn { - ( $( $x:expr ),* ) => { - { - use log::log; - log!(target: "UI", log::Level::Warn, $( $x, )* ); - } - } -} - -macro_rules! error { - ( $( $x:expr ),* ) => { - { - use log::log; - log!(target: "UI", log::Level::Error, $( $x, )* ); - } - } -} diff --git a/editor/src/main.rs b/editor/src/main.rs index 657431ca81..0586e8c18b 100644 --- a/editor/src/main.rs +++ b/editor/src/main.rs @@ -1,6 +1,3 @@ -#[macro_use] -mod macros; - mod colors; mod objects; mod plugins; diff --git a/editor/src/plugins/debug/chokepoints.rs b/editor/src/plugins/debug/chokepoints.rs index 515c7b9790..c3d5d6e20b 100644 --- a/editor/src/plugins/debug/chokepoints.rs +++ b/editor/src/plugins/debug/chokepoints.rs @@ -48,7 +48,7 @@ fn find_chokepoints(sim: &Sim) -> ChokepointsFinder { let mut count_per_intersection: Counter = Counter::new(); let active = sim.active_agents(); - info!("Finding chokepoints from {} active agents", active.len()); + println!("Finding chokepoints from {} active agents", active.len()); for a in active.into_iter() { // Why would an active agent not have a path? Pedestrian riding a bus. if let Some(path) = sim.get_path(a) { diff --git a/editor/src/plugins/debug/debug_polygon.rs b/editor/src/plugins/debug/debug_polygon.rs index 2aaf992164..39f0231750 100644 --- a/editor/src/plugins/debug/debug_polygon.rs +++ b/editor/src/plugins/debug/debug_polygon.rs @@ -1,6 +1,7 @@ use crate::objects::{DrawCtx, ID}; use crate::plugins::{BlockingPlugin, PluginCtx}; use crate::render::calculate_corners; +use abstutil::Timer; use ezgui::{GfxCtx, Key, Text}; use geom::{Polygon, Pt2D, Triangle}; @@ -38,7 +39,7 @@ impl DebugPolygon { .contextual_action(Key::F2, "debug sidewalk corners") { return Some(DebugPolygon { - items: calculate_corners(i, &ctx.primary.map) + items: calculate_corners(i, &ctx.primary.map, &mut Timer::throwaway()) .into_iter() .map(Item::Polygon) .collect(), diff --git a/editor/src/plugins/debug/geom_validation.rs b/editor/src/plugins/debug/geom_validation.rs index 74342a9b77..7064186e7c 100644 --- a/editor/src/plugins/debug/geom_validation.rs +++ b/editor/src/plugins/debug/geom_validation.rs @@ -41,7 +41,7 @@ impl Validator { objects.push((ID::Parcel(p.id), make_polys(&p.fill_polygon))); } - info!( + println!( "{} objects total. About {} possible overlaps", objects.len(), objects.len().pow(2) @@ -94,14 +94,14 @@ impl BlockingPlugin for Validator { self.current_problem = self.gen.next(); if let Some((id1, id2)) = self.current_problem { - info!("{:?} and {:?} intersect", id1, id2); + println!("{:?} and {:?} intersect", id1, id2); ctx.canvas.center_on_map_pt( id1.canonical_point(&ctx.primary.map, &ctx.primary.sim, &ctx.primary.draw_map) .unwrap(), ); // TODO also modify selection state to highlight stuff? } else { - info!("No more problems!"); + println!("No more problems!"); return false; } } else if ctx.input.modal_action("quit") { @@ -161,7 +161,7 @@ fn list_problems(map: &Map) { continue; } - error!( + println!( "{} may be collapsible. OSM ways {} vs {}", i.id, r1.osm_way_id, r2.osm_way_id ); @@ -177,7 +177,7 @@ fn list_problems(map: &Map) { { continue; } - error!(" only {} has: {} = {}", r1.id, k, v); + println!(" only {} has: {} = {}", r1.id, k, v); } for (k, v) in tags2.difference(&common) { if k.starts_with("tiger:") @@ -187,7 +187,7 @@ fn list_problems(map: &Map) { { continue; } - error!(" only {} has: {} = {}", r2.id, k, v); + println!(" only {} has: {} = {}", r2.id, k, v); } } } diff --git a/editor/src/plugins/debug/hider.rs b/editor/src/plugins/debug/hider.rs index 5715884bbe..d053575121 100644 --- a/editor/src/plugins/debug/hider.rs +++ b/editor/src/plugins/debug/hider.rs @@ -29,7 +29,7 @@ impl NonblockingPlugin for Hider { ctx.input.set_mode("Object Hider", &ctx.canvas); if ctx.input.modal_action("unhide everything") { - info!("Unhiding {} things", self.items.len()); + println!("Unhiding {} things", self.items.len()); *ctx.recalculate_current_selection = true; ctx.primary.current_selection = None; return false; @@ -53,7 +53,7 @@ fn hide_something(ctx: &mut PluginCtx) -> Option { .input .contextual_action(Key::H, &format!("hide {:?}", id)) { - info!("Hiding {:?}", id); + println!("Hiding {:?}", id); *ctx.recalculate_current_selection = true; ctx.primary.current_selection = None; Some(id) diff --git a/editor/src/plugins/debug/spawn_agent.rs b/editor/src/plugins/debug/spawn_agent.rs index 4921f89e5e..b22bbe9d8f 100644 --- a/editor/src/plugins/debug/spawn_agent.rs +++ b/editor/src/plugins/debug/spawn_agent.rs @@ -147,7 +147,7 @@ impl BlockingPlugin for SpawnAgent { if self.maybe_goal.is_some() && ctx.input.contextual_action(Key::F3, "end the agent here") { match (self.from.clone(), self.maybe_goal.take().unwrap().0) { (Source::Walking(from), Goal::Building(to)) => { - info!( + println!( "Spawning {}", ctx.primary .sim @@ -155,7 +155,7 @@ impl BlockingPlugin for SpawnAgent { ); } (Source::Walking(from), Goal::Border(to)) => { - info!( + println!( "Spawning {}", ctx.primary .sim @@ -163,7 +163,7 @@ impl BlockingPlugin for SpawnAgent { ); } (Source::Driving(from), Goal::Building(to)) => { - info!( + println!( "Spawning {}", ctx.primary .sim @@ -171,7 +171,7 @@ impl BlockingPlugin for SpawnAgent { ); } (Source::Driving(from), Goal::Border(to)) => { - info!( + println!( "Spawning {}", ctx.primary .sim diff --git a/editor/src/plugins/edit/a_b_tests.rs b/editor/src/plugins/edit/a_b_tests.rs index f21ab79c60..a1595b1c86 100644 --- a/editor/src/plugins/edit/a_b_tests.rs +++ b/editor/src/plugins/edit/a_b_tests.rs @@ -98,7 +98,7 @@ fn launch_test( cs: &ColorScheme, prerender: &Prerender, ) -> ((PerMapUI, PluginsPerMap), (PerMapUI, PluginsPerMap)) { - info!("Launching A/B test {}...", test.test_name); + println!("Launching A/B test {}...", test.test_name); let load = format!( "../data/scenarios/{}/{}.json", test.map_name, test.scenario_name diff --git a/editor/src/plugins/edit/color_picker.rs b/editor/src/plugins/edit/color_picker.rs index 424eafe020..5fe79d35a3 100644 --- a/editor/src/plugins/edit/color_picker.rs +++ b/editor/src/plugins/edit/color_picker.rs @@ -53,7 +53,7 @@ impl BlockingPlugin for ColorPicker { ctx.cs.reset_modified(name, *orig); return false; } else if ctx.input.modal_action("finalize") { - info!("Setting color for {}", name); + println!("Setting color for {}", name); return false; } diff --git a/editor/src/plugins/edit/map_edits.rs b/editor/src/plugins/edit/map_edits.rs index e35c1dbcd6..2175da255f 100644 --- a/editor/src/plugins/edit/map_edits.rs +++ b/editor/src/plugins/edit/map_edits.rs @@ -97,7 +97,7 @@ fn manage_edits( let mut flags = current_flags.clone(); flags.sim_flags.edits_name = load_name; - info!("Reloading everything..."); + println!("Reloading everything..."); // TODO Properly retain enable_debug_plugins *new_primary = Some(PerMapUI::new(flags, cs, prerender, true)); Some(()) diff --git a/editor/src/plugins/edit/road_editor.rs b/editor/src/plugins/edit/road_editor.rs index 0c34fbe164..cc6c67d024 100644 --- a/editor/src/plugins/edit/road_editor.rs +++ b/editor/src/plugins/edit/road_editor.rs @@ -34,7 +34,7 @@ impl BlockingPlugin for RoadEditor { { let mut edits = ctx.primary.map.get_edits().clone(); edits.delete_lane(road, lane); - warn!("Have to reload the map from scratch to pick up this change!"); + println!("Have to reload the map from scratch to pick up this change!"); ctx.primary.map.store_new_edits(edits); } else if let Some(new_type) = next_valid_type(ctx.primary.map.get_edits(), road, lane) { diff --git a/editor/src/plugins/sim/controls.rs b/editor/src/plugins/sim/controls.rs index 8d6388418a..6dcc7f1c4c 100644 --- a/editor/src/plugins/sim/controls.rs +++ b/editor/src/plugins/sim/controls.rs @@ -69,7 +69,7 @@ impl AmbientPluginWithPrimaryPlugins for SimControls { } if ctx.secondary.is_some() && ctx.input.action_chosen("swap the primary/secondary sim") { - info!("Swapping primary/secondary sim"); + println!("Swapping primary/secondary sim"); // Check out this cool little trick. :D let (mut secondary, mut secondary_plugins) = ctx.secondary.take().unwrap(); mem::swap(ctx.primary, &mut secondary); @@ -110,7 +110,7 @@ impl AmbientPluginWithPrimaryPlugins for SimControls { .unwrap(); } } - None => error!("Couldn't load previous savestate"), + None => println!("Couldn't load previous savestate"), }; } if ctx.input.action_chosen("load next sim state") { @@ -132,7 +132,7 @@ impl AmbientPluginWithPrimaryPlugins for SimControls { .unwrap(); } } - None => error!("Couldn't load next savestate"), + None => println!("Couldn't load next savestate"), }; } diff --git a/editor/src/plugins/sim/diff_trip.rs b/editor/src/plugins/sim/diff_trip.rs index 6a3e06287c..3dac50589e 100644 --- a/editor/src/plugins/sim/diff_trip.rs +++ b/editor/src/plugins/sim/diff_trip.rs @@ -94,7 +94,7 @@ fn diff_trip(trip: TripID, ctx: &mut PluginCtx) -> DiffTripState { .and_then(|agent| secondary_sim.trace_route(agent, secondary_map, None)); if line.is_none() || primary_route.is_none() || secondary_route.is_none() { - warn!("{} isn't present in both sims", trip); + println!("{} isn't present in both sims", trip); } DiffTripState { time: primary_sim.time, diff --git a/editor/src/plugins/view/follow.rs b/editor/src/plugins/view/follow.rs index 446d0c025d..7b700b484d 100644 --- a/editor/src/plugins/view/follow.rs +++ b/editor/src/plugins/view/follow.rs @@ -37,7 +37,7 @@ impl AmbientPlugin for FollowState { } else { // TODO ideally they wouldnt vanish for so long according to // get_canonical_point_for_trip - warn!("{} is gone... temporarily or not?", trip); + println!("{} is gone... temporarily or not?", trip); } ctx.input.set_mode_with_prompt( "Agent Follower", diff --git a/editor/src/plugins/view/show_route.rs b/editor/src/plugins/view/show_route.rs index 5d8b1cbdd1..b7a82c09a5 100644 --- a/editor/src/plugins/view/show_route.rs +++ b/editor/src/plugins/view/show_route.rs @@ -85,11 +85,11 @@ fn show_route(trip: TripID, ctx: &mut PluginCtx) -> ShowRouteState { if let Some(trace) = ctx.primary.sim.trace_route(agent, &ctx.primary.map, None) { ShowRouteState::Active(time, trip, Some(trace)) } else { - warn!("{} has no trace right now", agent); + println!("{} has no trace right now", agent); ShowRouteState::Active(time, trip, None) } } else { - warn!( + println!( "{} has no agent associated right now; is the trip done?", trip ); diff --git a/editor/src/plugins/view/warp.rs b/editor/src/plugins/view/warp.rs index 7de0fe61ea..8ead3d8741 100644 --- a/editor/src/plugins/view/warp.rs +++ b/editor/src/plugins/view/warp.rs @@ -91,7 +91,7 @@ fn warp_point(line: String, map: &Map, sim: &Sim, draw_map: &DrawMap) -> Option< if let Some(r) = map.maybe_get_r(id) { ID::Lane(r.children_forwards[0].0) } else { - warn!("{} doesn't exist", id); + println!("{} doesn't exist", id); return None; } } @@ -110,7 +110,7 @@ fn warp_point(line: String, map: &Map, sim: &Sim, draw_map: &DrawMap) -> Option< if let Some(id) = map.lookup_turn_by_idx(idx) { ID::Turn(id) } else { - warn!("{} isn't a known TurnID", line); + println!("{} isn't a known TurnID", line); return None; } } @@ -123,7 +123,7 @@ fn warp_point(line: String, map: &Map, sim: &Sim, draw_map: &DrawMap) -> Option< { ID::Intersection(i.id) } else { - warn!("{} isn't known", stable_id); + println!("{} isn't known", stable_id); return None; } } @@ -132,12 +132,12 @@ fn warp_point(line: String, map: &Map, sim: &Sim, draw_map: &DrawMap) -> Option< if let Some(r) = map.all_roads().iter().find(|r| r.stable_id == stable_id) { ID::Lane(r.children_forwards[0].0) } else { - warn!("{} isn't known", stable_id); + println!("{} isn't known", stable_id); return None; } } _ => { - warn!("{} isn't a valid ID; Should be [libepct][0-9]+", line); + println!("{} isn't a valid ID; Should be [libepct][0-9]+", line); return None; } }, @@ -146,10 +146,10 @@ fn warp_point(line: String, map: &Map, sim: &Sim, draw_map: &DrawMap) -> Option< } }; if let Some(pt) = id.canonical_point(map, sim, draw_map) { - info!("Warping to {:?}", id); + println!("Warping to {:?}", id); Some((id, pt)) } else { - warn!("{:?} doesn't exist", id); + println!("{:?} doesn't exist", id); None } } diff --git a/editor/src/render/intersection.rs b/editor/src/render/intersection.rs index ffb4b3d127..830e4cf248 100644 --- a/editor/src/render/intersection.rs +++ b/editor/src/render/intersection.rs @@ -44,7 +44,7 @@ impl DrawIntersection { i.polygon.clone(), )]; default_geom.extend( - calculate_corners(i, map) + calculate_corners(i, map, timer) .into_iter() .map(|p| (cs.get("sidewalk"), p)), ); @@ -133,7 +133,7 @@ fn calculate_crosswalks( } // TODO Temporarily public for debugging. -pub fn calculate_corners(i: &Intersection, map: &Map) -> Vec { +pub fn calculate_corners(i: &Intersection, map: &Map, timer: &mut Timer) -> Vec { let mut corners = Vec::new(); for turn in &map.get_turns_in_intersection(i.id) { @@ -167,13 +167,13 @@ pub fn calculate_corners(i: &Intersection, map: &Map) -> Vec { pts_between.push(dst_line.pt1()); corners.push(Polygon::new(&pts_between)); } else { - error!( + timer.warn(format!( "Couldn't make geometry for {}. look for {} to {} in {:?}", turn.id, corner2, corner1, i.polygon.points() - ); + )); } } } diff --git a/editor/src/render/map.rs b/editor/src/render/map.rs index 54f333039c..dd5cc528f2 100644 --- a/editor/src/render/map.rs +++ b/editor/src/render/map.rs @@ -227,10 +227,10 @@ impl DrawMap { } timer.stop("create quadtree"); - info!( + timer.note(format!( "static DrawMap consumes {} MB on the GPU", abstutil::prettyprint_usize(prerender.get_total_bytes_uploaded() / 1024 / 1024) - ); + )); DrawMap { roads, diff --git a/editor/src/ui.rs b/editor/src/ui.rs index a7495d092b..04a57d0258 100644 --- a/editor/src/ui.rs +++ b/editor/src/ui.rs @@ -374,11 +374,13 @@ impl GUI for UI { } fn dump_before_abort(&self, canvas: &Canvas) { - error!("********************************************************************************"); - error!("UI broke! Primary sim:"); + println!( + "********************************************************************************" + ); + println!("UI broke! Primary sim:"); self.state.get_state().primary.sim.dump_before_abort(); if let Some((s, _)) = &self.state.get_state().secondary { - error!("Secondary sim:"); + println!("Secondary sim:"); s.sim.dump_before_abort(); } @@ -388,7 +390,7 @@ impl GUI for UI { fn before_quit(&self, canvas: &Canvas) { self.save_editor_state(canvas); self.state.get_state().cs.save(); - info!("Saved color_scheme"); + println!("Saved color_scheme"); } fn profiling_enabled(&self) -> bool { @@ -400,13 +402,13 @@ impl UI { pub fn new(state: S, canvas: &mut Canvas) -> UI { match abstutil::read_json::("../editor_state") { Ok(ref loaded) if state.get_state().primary.map.get_name() == &loaded.map_name => { - info!("Loaded previous editor_state"); + println!("Loaded previous editor_state"); canvas.cam_x = loaded.cam_x; canvas.cam_y = loaded.cam_y; canvas.cam_zoom = loaded.cam_zoom; } _ => { - warn!("Couldn't load editor_state or it's for a different map, so just focusing on an arbitrary building"); + println!("Couldn't load editor_state or it's for a different map, so just focusing on an arbitrary building"); let focus_pt = ID::Building(BuildingID(0)) .canonical_point( &state.get_state().primary.map, @@ -475,7 +477,7 @@ impl UI { }; // TODO maybe make state line up with the map, so loading from a new map doesn't break abstutil::write_json("../editor_state", &state).expect("Saving editor_state failed"); - info!("Saved editor_state"); + println!("Saved editor_state"); } // TODO This could probably belong to DrawMap again, but it's annoying to plumb things that diff --git a/ezgui/Cargo.toml b/ezgui/Cargo.toml index 744ea495b0..7d556d05dc 100644 --- a/ezgui/Cargo.toml +++ b/ezgui/Cargo.toml @@ -11,7 +11,6 @@ geom = { path = "../geom" } glium = "0.23.0" glium-glyph = "0.3.0" glutin = "0.19.0" -log = "0.4.5" palette = "0.4" serde = "1.0.87" serde_derive = "1.0.87" diff --git a/ezgui/src/widgets/wizard.rs b/ezgui/src/widgets/wizard.rs index 3f0fa0b159..f19c64d61a 100644 --- a/ezgui/src/widgets/wizard.rs +++ b/ezgui/src/widgets/wizard.rs @@ -1,7 +1,6 @@ use crate::widgets::{Menu, Position}; use crate::{Canvas, GfxCtx, InputResult, Key, LogScroller, TextBox, UserInput}; use abstutil::Cloneable; -use log::warn; use std::collections::VecDeque; pub struct Wizard { @@ -95,7 +94,7 @@ impl Wizard { if let Some(result) = parser(line.clone()) { Some(result) } else { - warn!(target: "UI", "Invalid input {}", line); + println!("Invalid input {}", line); None } }