From 998c27ddff366eccf34425eb9215fb01b42a7a8b Mon Sep 17 00:00:00 2001 From: Dustin Carlino Date: Sun, 20 Jan 2019 14:27:25 -0800 Subject: [PATCH] starting a plugin to interactively spawn specific agents --- docs/TODO_quality.md | 3 +- docs/TODO_ux.md | 10 +++ editor/src/plugins/debug/mod.rs | 1 + editor/src/plugins/debug/spawn_agent.rs | 88 +++++++++++++++++++++++++ editor/src/state.rs | 3 + editor/src/ui.rs | 1 + 6 files changed, 105 insertions(+), 1 deletion(-) create mode 100644 editor/src/plugins/debug/spawn_agent.rs diff --git a/docs/TODO_quality.md b/docs/TODO_quality.md index 82e631416d..77c876073f 100644 --- a/docs/TODO_quality.md +++ b/docs/TODO_quality.md @@ -24,12 +24,13 @@ - zorder for bridges/tunnels - apply to cars/peds too; figure out statics/dynamics plumbing - - first need to interactively spawn a car/ped somewhere to test this easily - degenerate-2's should only have one crosswalk - then make them thinner - ped paths through sidewalk corners are totally broken + - calculate the better paths first, then make the corner geometry from that? +- car turns often clip sidewalk corners now - figure out what to do about yellow center lines - intersections on one-ways look weird diff --git a/docs/TODO_ux.md b/docs/TODO_ux.md index c4c3ecaefd..e3d9edd033 100644 --- a/docs/TODO_ux.md +++ b/docs/TODO_ux.md @@ -2,6 +2,16 @@ ## Quick n easy +- interactively spawn a car/ped somewhere to test this easily + - start to end of driving lanes + - pathfinding or trace or something is wrong for walking; the last line sometimes has the wrong distance + - actually spawn stuff + - stop disabling mouseover at low zoom when in this mode + - then back to zorder for cars/peds + +- try showing traffic signals by little boxes at the end of lanes + - red circle means right turn on red OK, red right arrow means nope, green means normal turns ok, green arrow means protected left, crosswalk hand or stick figure + - color roads as solid black when zoomed out, and make intersections similar (except for stop sign / signal) - audit all panics - tune text color, size, padding diff --git a/editor/src/plugins/debug/mod.rs b/editor/src/plugins/debug/mod.rs index f322d2bb06..dfe6cd4ed1 100644 --- a/editor/src/plugins/debug/mod.rs +++ b/editor/src/plugins/debug/mod.rs @@ -6,3 +6,4 @@ pub mod floodfill; pub mod geom_validation; pub mod hider; pub mod layers; +pub mod spawn_agent; diff --git a/editor/src/plugins/debug/spawn_agent.rs b/editor/src/plugins/debug/spawn_agent.rs new file mode 100644 index 0000000000..22f793c145 --- /dev/null +++ b/editor/src/plugins/debug/spawn_agent.rs @@ -0,0 +1,88 @@ +use crate::objects::{Ctx, ID}; +use crate::plugins::{Plugin, PluginCtx}; +use dimensioned::si; +use ezgui::{Color, GfxCtx, Key}; +use map_model::{BuildingID, PathRequest, Pathfinder, Trace, LANE_THICKNESS}; +use std::f64; + +pub struct SpawnAgent { + from_bldg: BuildingID, + + maybe_goal: Option<(BuildingID, Option)>, +} + +impl SpawnAgent { + pub fn new(ctx: &mut PluginCtx) -> Option { + if let Some(ID::Building(id)) = ctx.primary.current_selection { + if ctx + .input + .contextual_action(Key::F3, "spawn an agent starting here") + { + return Some(SpawnAgent { + from_bldg: id, + maybe_goal: None, + }); + } + } + None + } +} + +impl Plugin for SpawnAgent { + fn blocking_event(&mut self, ctx: &mut PluginCtx) -> bool { + ctx.input.set_mode("Agent Spawner", &ctx.canvas); + if ctx.input.modal_action("quit") { + return false; + } + + // TODO disabling mouseover at low zoom is actually annoying now + if let Some(ID::Building(id)) = ctx.primary.current_selection { + if self + .maybe_goal + .as_ref() + .map(|(b, _)| *b != id) + .unwrap_or(true) + { + self.maybe_goal = Some((id, None)); + + let map = &ctx.primary.map; + let start = map.get_b(self.from_bldg).front_path.sidewalk; + if let Some(path) = Pathfinder::shortest_distance( + map, + PathRequest { + start, + end: map.get_b(id).front_path.sidewalk, + can_use_bike_lanes: false, + can_use_bus_lanes: false, + }, + ) { + self.maybe_goal = + Some((id, path.trace(map, start.dist_along(), f64::MAX * si::M))); + } + } + } else { + self.maybe_goal = None; + } + + if self.maybe_goal.is_some() && ctx.input.contextual_action(Key::F3, "end the agent here") { + // TODO spawn em + return false; + } + + true + } + + fn draw(&self, g: &mut GfxCtx, ctx: &Ctx) { + if let Some((_, Some(ref trace))) = self.maybe_goal { + g.draw_polygon(ctx.cs.get("route"), &trace.make_polygons(LANE_THICKNESS)); + } + } + + fn color_for(&self, obj: ID, ctx: &Ctx) -> Option { + if ID::Building(self.from_bldg) == obj { + Some(ctx.cs.get("selected")) + } else { + None + } + } +} diff --git a/editor/src/state.rs b/editor/src/state.rs index 50983ae008..2cb6eba2ac 100644 --- a/editor/src/state.rs +++ b/editor/src/state.rs @@ -231,6 +231,9 @@ impl UIState for DefaultUIState { } else if let Some(p) = debug::debug_polygon::DebugPolygon::new(&mut ctx) { self.exclusive_blocking_plugin = Some(Box::new(p)); return; + } else if let Some(p) = debug::spawn_agent::SpawnAgent::new(&mut ctx) { + self.exclusive_blocking_plugin = Some(Box::new(p)); + return; } } } diff --git a/editor/src/ui.rs b/editor/src/ui.rs index a96e287062..f1069c69af 100644 --- a/editor/src/ui.rs +++ b/editor/src/ui.rs @@ -178,6 +178,7 @@ impl GUI for UI { (Key::Comma, "prev item"), ], ), + ModalMenu::new("Agent Spawner", vec![(Key::Enter, "quit")]), ] }