mirror of
https://github.com/a-b-street/abstreet.git
synced 2024-11-25 11:44:25 +03:00
view all routes tool in debug mode
This commit is contained in:
parent
66b21c81ec
commit
b996b3773e
@ -24,14 +24,11 @@ impl AgentTools {
|
||||
RouteViewer::Active(_, trip, _) => {
|
||||
txt.add_line(format!("Showing {}'s route", trip));
|
||||
}
|
||||
RouteViewer::DebugAllRoutes(_, _) => {
|
||||
txt.add_line("Showing all routes".to_string());
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn event(&mut self, ctx: &mut EventCtx, ui: &mut UI, menu: &mut ModalMenu) {
|
||||
pub fn event(&mut self, ctx: &mut EventCtx, ui: &UI, menu: &mut ModalMenu) {
|
||||
if self.following.is_none() {
|
||||
if let Some(agent) = ui.primary.current_selection.and_then(|id| id.agent_id()) {
|
||||
if let Some(trip) = ui.primary.sim.agent_to_trip(agent) {
|
||||
|
@ -9,19 +9,16 @@ pub enum RouteViewer {
|
||||
Inactive,
|
||||
Hovering(Duration, AgentID, PolyLine),
|
||||
Active(Duration, TripID, Option<PolyLine>),
|
||||
DebugAllRoutes(Duration, Vec<PolyLine>),
|
||||
}
|
||||
|
||||
impl RouteViewer {
|
||||
pub fn event(&mut self, ctx: &mut EventCtx, ui: &mut UI, menu: &mut ModalMenu) {
|
||||
pub fn event(&mut self, ctx: &mut EventCtx, ui: &UI, menu: &mut ModalMenu) {
|
||||
match self {
|
||||
RouteViewer::Inactive => {
|
||||
if let Some(agent) = ui.primary.current_selection.and_then(|id| id.agent_id()) {
|
||||
if let Some(trace) = ui.primary.sim.trace_route(agent, &ui.primary.map, None) {
|
||||
*self = RouteViewer::Hovering(ui.primary.sim.time(), agent, trace);
|
||||
}
|
||||
} else if menu.action("show/hide route for all agents") {
|
||||
*self = debug_all_routes(ui);
|
||||
}
|
||||
}
|
||||
RouteViewer::Hovering(time, agent, _) => {
|
||||
@ -62,13 +59,6 @@ impl RouteViewer {
|
||||
*self = show_route(*trip, ui);
|
||||
}
|
||||
}
|
||||
RouteViewer::DebugAllRoutes(time, _) => {
|
||||
if menu.action("show/hide route for all agents") {
|
||||
*self = RouteViewer::Inactive;
|
||||
} else if *time != ui.primary.sim.time() {
|
||||
*self = debug_all_routes(ui);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -86,11 +76,6 @@ impl RouteViewer {
|
||||
&trace.make_polygons(LANE_THICKNESS),
|
||||
);
|
||||
}
|
||||
RouteViewer::DebugAllRoutes(_, ref traces) => {
|
||||
for t in traces {
|
||||
g.draw_polygon(ui.cs.get("route"), &t.make_polygons(LANE_THICKNESS));
|
||||
}
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
@ -114,23 +99,3 @@ fn show_route(trip: TripID, ui: &UI) -> RouteViewer {
|
||||
RouteViewer::Active(time, trip, None)
|
||||
}
|
||||
}
|
||||
|
||||
fn debug_all_routes(ui: &mut UI) -> RouteViewer {
|
||||
let mut traces: Vec<PolyLine> = Vec::new();
|
||||
let trips: Vec<TripID> = ui
|
||||
.primary
|
||||
.sim
|
||||
.get_trip_positions(&ui.primary.map)
|
||||
.canonical_pt_per_trip
|
||||
.keys()
|
||||
.cloned()
|
||||
.collect();
|
||||
for trip in trips {
|
||||
if let Some(agent) = ui.primary.sim.trip_to_agent(trip) {
|
||||
if let Some(trace) = ui.primary.sim.trace_route(agent, &ui.primary.map, None) {
|
||||
traces.push(trace);
|
||||
}
|
||||
}
|
||||
}
|
||||
RouteViewer::DebugAllRoutes(ui.primary.sim.time(), traces)
|
||||
}
|
||||
|
@ -5,6 +5,7 @@ mod connected_roads;
|
||||
mod neighborhood_summary;
|
||||
mod objects;
|
||||
mod polygons;
|
||||
mod routes;
|
||||
|
||||
use crate::common::CommonState;
|
||||
use crate::edit::EditMode;
|
||||
@ -35,6 +36,7 @@ pub struct DebugMode {
|
||||
layers: ShowLayers,
|
||||
search_results: Option<(String, HashSet<ID>)>,
|
||||
neighborhood_summary: neighborhood_summary::NeighborhoodSummary,
|
||||
all_routes: routes::AllRoutesViewer,
|
||||
}
|
||||
|
||||
impl DebugMode {
|
||||
@ -60,6 +62,7 @@ impl DebugMode {
|
||||
(hotkey(Key::M), "clear OSM search results"),
|
||||
(hotkey(Key::S), "configure colors"),
|
||||
(hotkey(Key::N), "show/hide neighborhood summaries"),
|
||||
(hotkey(Key::R), "show/hide route for all agents"),
|
||||
(lctrl(Key::S), "sandbox mode"),
|
||||
(lctrl(Key::E), "edit mode"),
|
||||
],
|
||||
@ -83,6 +86,7 @@ impl DebugMode {
|
||||
ctx.prerender,
|
||||
&mut Timer::new("set up DebugMode"),
|
||||
),
|
||||
all_routes: routes::AllRoutesViewer::Inactive,
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -123,6 +127,12 @@ impl State for DebugMode {
|
||||
if self.neighborhood_summary.active {
|
||||
txt.add_line("Showing neighborhood summaries".to_string());
|
||||
}
|
||||
match self.all_routes {
|
||||
routes::AllRoutesViewer::Active(_, ref traces) => {
|
||||
txt.add_line(format!("Showing {} routes", traces.len()));
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
self.menu.handle_event(ctx, Some(txt));
|
||||
|
||||
ctx.canvas.handle_event(ctx.input);
|
||||
@ -148,6 +158,7 @@ impl State for DebugMode {
|
||||
self.chokepoints = Some(chokepoints::ChokepointsFinder::new(&ui.primary.sim));
|
||||
}
|
||||
}
|
||||
self.all_routes.event(ui, &mut self.menu);
|
||||
if !self.show_original_roads.is_empty() {
|
||||
if self.menu.action("clear original roads shown") {
|
||||
self.show_original_roads.clear();
|
||||
@ -322,6 +333,7 @@ impl State for DebugMode {
|
||||
|
||||
self.objects.draw(g, ui);
|
||||
self.neighborhood_summary.draw(g);
|
||||
self.all_routes.draw(g, ui);
|
||||
|
||||
if !g.is_screencap() {
|
||||
self.menu.draw(g);
|
||||
|
57
editor/src/debug/routes.rs
Normal file
57
editor/src/debug/routes.rs
Normal file
@ -0,0 +1,57 @@
|
||||
use crate::ui::UI;
|
||||
use ezgui::{GfxCtx, ModalMenu};
|
||||
use geom::{Duration, PolyLine};
|
||||
use map_model::LANE_THICKNESS;
|
||||
use sim::TripID;
|
||||
|
||||
pub enum AllRoutesViewer {
|
||||
Inactive,
|
||||
Active(Duration, Vec<PolyLine>),
|
||||
}
|
||||
|
||||
impl AllRoutesViewer {
|
||||
pub fn event(&mut self, ui: &mut UI, menu: &mut ModalMenu) {
|
||||
match self {
|
||||
AllRoutesViewer::Inactive => {
|
||||
if menu.action("show/hide route for all agents") {
|
||||
*self = debug_all_routes(ui);
|
||||
}
|
||||
}
|
||||
AllRoutesViewer::Active(time, _) => {
|
||||
if menu.action("show/hide route for all agents") {
|
||||
*self = AllRoutesViewer::Inactive;
|
||||
} else if *time != ui.primary.sim.time() {
|
||||
*self = debug_all_routes(ui);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn draw(&self, g: &mut GfxCtx, ui: &UI) {
|
||||
if let AllRoutesViewer::Active(_, ref traces) = self {
|
||||
for t in traces {
|
||||
g.draw_polygon(ui.cs.get("route"), &t.make_polygons(LANE_THICKNESS));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn debug_all_routes(ui: &mut UI) -> AllRoutesViewer {
|
||||
let mut traces: Vec<PolyLine> = Vec::new();
|
||||
let trips: Vec<TripID> = ui
|
||||
.primary
|
||||
.sim
|
||||
.get_trip_positions(&ui.primary.map)
|
||||
.canonical_pt_per_trip
|
||||
.keys()
|
||||
.cloned()
|
||||
.collect();
|
||||
for trip in trips {
|
||||
if let Some(agent) = ui.primary.sim.trip_to_agent(trip) {
|
||||
if let Some(trace) = ui.primary.sim.trace_route(agent, &ui.primary.map, None) {
|
||||
traces.push(trace);
|
||||
}
|
||||
}
|
||||
}
|
||||
AllRoutesViewer::Active(ui.primary.sim.time(), traces)
|
||||
}
|
@ -48,8 +48,6 @@ impl SandboxMode {
|
||||
// TODO Strange to always have this. Really it's a case of stacked modal?
|
||||
(hotkey(Key::F), "stop following agent"),
|
||||
(hotkey(Key::R), "stop showing agent's route"),
|
||||
// TODO This should probably be a debug thing instead
|
||||
(hotkey(Key::L), "show/hide route for all agents"),
|
||||
(hotkey(Key::A), "show/hide active traffic"),
|
||||
(hotkey(Key::T), "start time traveling"),
|
||||
(hotkey(Key::Q), "scoreboard"),
|
||||
|
Loading…
Reference in New Issue
Block a user