mirror of
https://github.com/a-b-street/abstreet.git
synced 2024-11-28 12:12:00 +03:00
moving some debug info from the info panel to the console log
This commit is contained in:
parent
5440fca4fe
commit
201c0edaab
@ -5,7 +5,6 @@ use crate::ui::UI;
|
||||
use abstutil::prettyprint_usize;
|
||||
use ezgui::{hotkey, Color, EventCtx, GfxCtx, Key, Line, ModalMenu, Text};
|
||||
use geom::Time;
|
||||
use map_model::PathConstraints;
|
||||
use sim::CarID;
|
||||
use std::collections::BTreeMap;
|
||||
|
||||
@ -25,7 +24,7 @@ impl InfoPanel {
|
||||
}
|
||||
|
||||
InfoPanel {
|
||||
txt: info_for(id, ui, ctx),
|
||||
txt: info_for(id, ui),
|
||||
menu: ModalMenu::new("Info Panel", menu_entries, ctx),
|
||||
actions,
|
||||
}
|
||||
@ -64,16 +63,12 @@ impl State for InfoPanel {
|
||||
}
|
||||
}
|
||||
|
||||
fn info_for(id: ID, ui: &UI, ctx: &EventCtx) -> Text {
|
||||
fn info_for(id: ID, ui: &UI) -> Text {
|
||||
let (map, sim, draw_map) = (&ui.primary.map, &ui.primary.sim, &ui.primary.draw_map);
|
||||
let mut txt = Text::new();
|
||||
// TODO Technically we should recalculate all of this as the window resizes, then.
|
||||
txt.override_width = Some(0.7 * ctx.canvas.window_width);
|
||||
txt.override_height = Some(0.7 * ctx.canvas.window_height);
|
||||
|
||||
txt.extend(&CommonState::default_osd(id.clone(), ui));
|
||||
txt.highlight_last_line(Color::BLUE);
|
||||
let id_color = ui.cs.get("OSD ID color");
|
||||
let name_color = ui.cs.get("OSD name color");
|
||||
|
||||
match id {
|
||||
@ -82,20 +77,7 @@ fn info_for(id: ID, ui: &UI, ctx: &EventCtx) -> Text {
|
||||
let l = map.get_l(id);
|
||||
let r = map.get_r(l.parent);
|
||||
|
||||
txt.add_appended(vec![
|
||||
Line("Parent "),
|
||||
Line(r.id.to_string()).fg(id_color),
|
||||
Line(" ("),
|
||||
Line(r.orig_id.to_string()).fg(id_color),
|
||||
Line(" ) points to "),
|
||||
Line(r.dst_i.to_string()).fg(id_color),
|
||||
]);
|
||||
txt.add(Line(format!(
|
||||
"Lane is {} long, parent {} is {} long",
|
||||
l.length(),
|
||||
r.id,
|
||||
r.center_pts.length()
|
||||
)));
|
||||
txt.add(Line(format!("Lane is {} long", l.length())));
|
||||
|
||||
txt.add(Line(""));
|
||||
styled_kv(&mut txt, &r.osm_tags);
|
||||
@ -129,38 +111,13 @@ fn info_for(id: ID, ui: &UI, ctx: &EventCtx) -> Text {
|
||||
"{} total agents crossed",
|
||||
prettyprint_usize(sim.get_analytics().thruput_stats.count_per_road.get(r.id))
|
||||
)));
|
||||
|
||||
if l.lane_type.is_for_moving_vehicles() {
|
||||
for constraint in vec![
|
||||
PathConstraints::Car,
|
||||
PathConstraints::Bike,
|
||||
PathConstraints::Bus,
|
||||
] {
|
||||
if constraint.can_use(l, map) {
|
||||
txt.add(Line(format!(
|
||||
"Cost for {:?}: {}",
|
||||
constraint,
|
||||
l.get_max_cost(constraint, map)
|
||||
)));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
ID::Intersection(id) => {
|
||||
let i = map.get_i(id);
|
||||
txt.add(Line(i.orig_id.to_string()).fg(id_color));
|
||||
txt.add(Line("Connecting"));
|
||||
for r in &i.roads {
|
||||
let road = map.get_r(*r);
|
||||
txt.add_appended(vec![
|
||||
Line("- "),
|
||||
Line(road.get_name()).fg(name_color),
|
||||
Line(" ("),
|
||||
Line(road.id.to_string()).fg(id_color),
|
||||
Line(" = "),
|
||||
Line(road.orig_id.to_string()).fg(id_color),
|
||||
Line(")"),
|
||||
]);
|
||||
txt.add_appended(vec![Line("- "), Line(road.get_name()).fg(name_color)]);
|
||||
}
|
||||
|
||||
let accepted = ui.primary.sim.get_accepted_agents(id);
|
||||
|
@ -2,7 +2,7 @@ use crate::helpers::ID;
|
||||
use crate::render::DrawMap;
|
||||
use crate::ui::UI;
|
||||
use ezgui::{EventCtx, GfxCtx, Key, Line, Text};
|
||||
use map_model::Map;
|
||||
use map_model::{Map, PathConstraints};
|
||||
use sim::{AgentID, CarID, Sim};
|
||||
|
||||
pub struct ObjectDebugger {
|
||||
@ -56,21 +56,50 @@ impl ObjectDebugger {
|
||||
fn dump_debug(id: ID, map: &Map, sim: &Sim, draw_map: &DrawMap) {
|
||||
match id {
|
||||
ID::Road(id) => {
|
||||
map.get_r(id).dump_debug();
|
||||
println!("{}", abstutil::to_json(map.get_r(id)));
|
||||
}
|
||||
ID::Lane(id) => {
|
||||
map.get_l(id).dump_debug();
|
||||
let l = map.get_l(id);
|
||||
println!("{}", abstutil::to_json(l));
|
||||
|
||||
sim.debug_lane(id);
|
||||
|
||||
let r = map.get_parent(id);
|
||||
println!("Parent {} ({}) points to {}", r.id, r.orig_id, r.dst_i);
|
||||
|
||||
if l.lane_type.is_for_moving_vehicles() {
|
||||
for constraint in vec![
|
||||
PathConstraints::Car,
|
||||
PathConstraints::Bike,
|
||||
PathConstraints::Bus,
|
||||
] {
|
||||
if constraint.can_use(l, map) {
|
||||
println!(
|
||||
"Cost for {:?}: {}",
|
||||
constraint,
|
||||
l.get_max_cost(constraint, map)
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
ID::Intersection(id) => {
|
||||
map.get_i(id).dump_debug();
|
||||
let i = map.get_i(id);
|
||||
println!("{}", abstutil::to_json(i));
|
||||
|
||||
sim.debug_intersection(id, map);
|
||||
|
||||
println!("{} connecting:", i.orig_id);
|
||||
for r in &i.roads {
|
||||
let road = map.get_r(*r);
|
||||
println!("- {} = {}", road.id, road.orig_id);
|
||||
}
|
||||
}
|
||||
ID::Turn(id) => {
|
||||
map.get_t(id).dump_debug();
|
||||
println!("{}", abstutil::to_json(map.get_t(id)));
|
||||
}
|
||||
ID::Building(id) => {
|
||||
map.get_b(id).dump_debug();
|
||||
println!("{}", abstutil::to_json(map.get_b(id)));
|
||||
for (cars, descr) in vec![
|
||||
(
|
||||
sim.get_parked_cars_by_owner(id),
|
||||
@ -121,10 +150,10 @@ fn dump_debug(id: ID, map: &Map, sim: &Sim, draw_map: &DrawMap) {
|
||||
println!("associated road: {:?}", es.road);
|
||||
}
|
||||
ID::BusStop(id) => {
|
||||
map.get_bs(id).dump_debug();
|
||||
println!("{}", abstutil::to_json(map.get_bs(id)));
|
||||
}
|
||||
ID::Area(id) => {
|
||||
map.get_a(id).dump_debug();
|
||||
println!("{}", abstutil::to_json(map.get_a(id)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -28,9 +28,3 @@ pub struct Area {
|
||||
pub osm_tags: BTreeMap<String, String>,
|
||||
pub osm_id: i64,
|
||||
}
|
||||
|
||||
impl Area {
|
||||
pub fn dump_debug(&self) {
|
||||
println!("{}", abstutil::to_json(self));
|
||||
}
|
||||
}
|
||||
|
@ -46,10 +46,6 @@ pub struct Building {
|
||||
}
|
||||
|
||||
impl Building {
|
||||
pub fn dump_debug(&self) {
|
||||
println!("{}", abstutil::to_json(self));
|
||||
}
|
||||
|
||||
pub fn sidewalk(&self) -> LaneID {
|
||||
self.front_path.sidewalk.lane()
|
||||
}
|
||||
|
@ -34,12 +34,6 @@ pub struct BusStop {
|
||||
pub sidewalk_pos: Position,
|
||||
}
|
||||
|
||||
impl BusStop {
|
||||
pub fn dump_debug(&self) {
|
||||
println!("{}", abstutil::to_json(self));
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug)]
|
||||
pub struct BusRoute {
|
||||
pub id: BusRouteID,
|
||||
|
@ -109,10 +109,6 @@ impl Intersection {
|
||||
roads
|
||||
}
|
||||
|
||||
pub fn dump_debug(&self) {
|
||||
println!("{}", abstutil::to_json(self));
|
||||
}
|
||||
|
||||
pub fn some_outgoing_road(&self, map: &Map) -> DirectedRoadID {
|
||||
map.get_l(self.outgoing_lanes[0]).get_directed_parent(map)
|
||||
}
|
||||
|
@ -143,14 +143,6 @@ impl Lane {
|
||||
self.lane_center_pts.length()
|
||||
}
|
||||
|
||||
pub fn dump_debug(&self) {
|
||||
println!(
|
||||
"\nlet lane_center_l{}_pts = {}",
|
||||
self.id.0, self.lane_center_pts
|
||||
);
|
||||
println!("{}", abstutil::to_json(self));
|
||||
}
|
||||
|
||||
pub fn intersections(&self) -> Vec<IntersectionID> {
|
||||
// TODO I think we're assuming there are no loop lanes
|
||||
vec![self.src_i, self.dst_i]
|
||||
|
@ -307,10 +307,6 @@ impl Road {
|
||||
.collect()
|
||||
}
|
||||
|
||||
pub fn dump_debug(&self) {
|
||||
println!("{}", abstutil::to_json(self));
|
||||
}
|
||||
|
||||
pub fn any_on_other_side(&self, l: LaneID, lt: LaneType) -> Option<LaneID> {
|
||||
let search = if self.is_forwards(l) {
|
||||
&self.children_backwards
|
||||
|
@ -111,10 +111,6 @@ impl Turn {
|
||||
pub fn between_sidewalks(&self) -> bool {
|
||||
self.turn_type == TurnType::SharedSidewalkCorner || self.turn_type == TurnType::Crosswalk
|
||||
}
|
||||
|
||||
pub fn dump_debug(&self) {
|
||||
println!("{}", abstutil::to_json(self));
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq, PartialOrd, Ord, Serialize, Deserialize)]
|
||||
|
@ -833,6 +833,7 @@ impl DrivingSimState {
|
||||
pub fn debug_car(&self, id: CarID) {
|
||||
if let Some(ref car) = self.cars.get(&id) {
|
||||
println!("{}", abstutil::to_json(car));
|
||||
println!("State: {:?}", car.state);
|
||||
} else {
|
||||
println!("{} is parked somewhere", id);
|
||||
}
|
||||
@ -861,7 +862,6 @@ impl DrivingSimState {
|
||||
car.blocked_since.map(|t| now - t).unwrap_or(Duration::ZERO)
|
||||
),
|
||||
format!("Trip time so far: {}", now - car.started_at),
|
||||
format!("{:?}", car.state),
|
||||
])
|
||||
}
|
||||
|
||||
|
@ -777,10 +777,12 @@ impl Sim {
|
||||
|
||||
pub fn debug_ped(&self, id: PedestrianID) {
|
||||
self.walking.debug_ped(id);
|
||||
self.trips.debug_trip(AgentID::Pedestrian(id));
|
||||
}
|
||||
|
||||
pub fn debug_car(&self, id: CarID) {
|
||||
self.driving.debug_car(id);
|
||||
self.trips.debug_trip(AgentID::Car(id));
|
||||
}
|
||||
|
||||
pub fn debug_intersection(&self, id: IntersectionID, map: &Map) {
|
||||
@ -792,14 +794,11 @@ impl Sim {
|
||||
}
|
||||
|
||||
pub fn ped_tooltip(&self, p: PedestrianID, map: &Map) -> Vec<String> {
|
||||
let mut lines = self.walking.ped_tooltip(p, self.time, map);
|
||||
lines.extend(self.trips.tooltip_lines(AgentID::Pedestrian(p)));
|
||||
lines
|
||||
self.walking.ped_tooltip(p, self.time, map)
|
||||
}
|
||||
|
||||
pub fn car_tooltip(&self, car: CarID) -> Vec<String> {
|
||||
if let Some(mut lines) = self.driving.tooltip_lines(car, self.time) {
|
||||
lines.extend(self.trips.tooltip_lines(AgentID::Car(car)));
|
||||
if car.1 == VehicleType::Bus {
|
||||
let passengers = self.transit.get_passengers(car);
|
||||
lines.push(format!("{} passengers riding", passengers.len()));
|
||||
|
@ -478,14 +478,10 @@ impl TripManager {
|
||||
self.active_trip_mode.get(&id).cloned()
|
||||
}
|
||||
|
||||
pub fn tooltip_lines(&self, id: AgentID) -> Vec<String> {
|
||||
pub fn debug_trip(&self, id: AgentID) {
|
||||
// Only called for agents that _should_ have trips
|
||||
let trip = &self.trips[self.active_trip_mode[&id].0];
|
||||
vec![format!(
|
||||
"{} has goal {:?}",
|
||||
trip.id,
|
||||
trip.legs.back().unwrap()
|
||||
)]
|
||||
println!("{} has goal {:?}", trip.id, trip.legs.back().unwrap());
|
||||
}
|
||||
|
||||
// (total active trips, unfinished trips, active trips by the trip's current mode)
|
||||
|
Loading…
Reference in New Issue
Block a user