removing most log usage from editor

This commit is contained in:
Dustin Carlino 2019-02-20 11:24:21 -08:00
parent e4ef1ec79d
commit 40206eccc3
21 changed files with 49 additions and 89 deletions

View File

@ -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, )* );
}
}
}

View File

@ -1,6 +1,3 @@
#[macro_use]
mod macros;
mod colors;
mod objects;
mod plugins;

View File

@ -48,7 +48,7 @@ fn find_chokepoints(sim: &Sim) -> ChokepointsFinder {
let mut count_per_intersection: Counter<IntersectionID, usize> = 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) {

View File

@ -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(),

View File

@ -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);
}
}
}

View File

@ -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<ID> {
.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)

View File

@ -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

View File

@ -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

View File

@ -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;
}

View File

@ -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(())

View File

@ -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)
{

View File

@ -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"),
};
}

View File

@ -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,

View File

@ -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",

View File

@ -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
);

View File

@ -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
}
}

View File

@ -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<Polygon> {
pub fn calculate_corners(i: &Intersection, map: &Map, timer: &mut Timer) -> Vec<Polygon> {
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<Polygon> {
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()
);
));
}
}
}

View File

@ -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,

View File

@ -374,11 +374,13 @@ impl<S: UIState> GUI<RenderingHints> for UI<S> {
}
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<S: UIState> GUI<RenderingHints> for UI<S> {
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<S: UIState> UI<S> {
pub fn new(state: S, canvas: &mut Canvas) -> UI<S> {
match abstutil::read_json::<EditorState>("../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<S: UIState> UI<S> {
};
// 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

View File

@ -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"

View File

@ -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
}
}