diff --git a/geom/src/polyline3.rs b/geom/src/polyline3.rs index 54298d08..d72cb2ae 100644 --- a/geom/src/polyline3.rs +++ b/geom/src/polyline3.rs @@ -76,6 +76,10 @@ impl PolyLine3 { }) } + pub fn middle(&self) -> Vec3 { + self.point_along(self.length() * 0.5) + } + /// Simplifies the polyline by keeping points /// where the dot product of the previous and next segment is greater than mindot /// mindot should be a bit more than -1 diff --git a/native_app/src/gui/windows/debug.rs b/native_app/src/gui/windows/debug.rs index 2dbce210..14cef736 100644 --- a/native_app/src/gui/windows/debug.rs +++ b/native_app/src/gui/windows/debug.rs @@ -13,7 +13,7 @@ use egui::Widget; use engine::{PerfCountersStatic, Tesselator}; use geom::{Camera, Color, LinearColor, Spline3, Vec2}; use simulation::map::{ - IntersectionID, Map, MapSubscriber, RoadSegmentKind, TraverseKind, UpdateType, + IntersectionID, Map, MapSubscriber, NetworkObjectID, RoadSegmentKind, TraverseKind, UpdateType, }; use simulation::transportation::train::TrainReservations; use simulation::world_command::WorldCommand; @@ -38,6 +38,7 @@ impl Default for DebugObjs { (true, "Debug pathfinder", debug_pathfinder), (false, "Debug train reservations", debug_trainreservations), (false, "Debug connectivity", debug_connectivity), + (false, "Debug electricity", debug_electricity), (false, "Debug spatialmap", debug_spatialmap), (false, "Debug transport grid", debug_transport_grid), (false, "Debug splines", debug_spline), @@ -295,6 +296,41 @@ pub fn debug_road_points(tess: &mut Tesselator, sim: &Simulation, _: &UiWo Some(()) } +fn random_color(i: u64) -> Color { + let r = common::rand::randu(i as u32); + Color::hsv(r * 360.0, 0.8, 0.6, 0.5) +} + +pub fn debug_electricity(tess: &mut Tesselator, sim: &Simulation, _: &UiWorld) -> Option<()> { + let map = sim.map(); + + let getpos = |object: NetworkObjectID| match object { + NetworkObjectID::Building(b) => Some(map.get(b)?.obb.center().z(5.0)), + NetworkObjectID::Intersection(i) => Some(map.get(i)?.pos.up(5.0)), + NetworkObjectID::Road(r) => { + let road = map.get(r)?; + Some(road.points.middle().up(5.0)) + } + }; + + for network in map.electricity.networks() { + tess.set_color(random_color(common::hash_u64(network.id))); + + for object in &network.objects { + tess.draw_circle(getpos(*object)?, 10.0); + } + } + + for (k, v) in map.electricity.graph.iter() { + tess.set_color(random_color(common::hash_u64(map.electricity.net_id(*k)?))); + for v in v { + tess.draw_stroke(getpos(*k)?, getpos(*v)?, 3.0); + } + } + + Some(()) +} + pub fn debug_connectivity( tess: &mut Tesselator, sim: &Simulation, @@ -323,8 +359,7 @@ pub fn debug_connectivity( } for (i, comp) in state.connectivity.1.iter().enumerate() { - let r = common::rand::randu(i as u32); - tess.set_color(Color::hsv(r * 360.0, 0.8, 0.6, 0.5)); + tess.set_color(random_color(i as u64)); for int in comp.iter().flat_map(|x| map.intersections().get(*x)) { tess.draw_circle(int.pos, 8.0); diff --git a/simulation/src/map/mod.rs b/simulation/src/map/mod.rs index ab7b01de..2919f299 100644 --- a/simulation/src/map/mod.rs +++ b/simulation/src/map/mod.rs @@ -44,6 +44,7 @@ mod turn_policy; // Use self or else it would be ambiguous with "pathfinding" crate pub use self::pathfinding::*; pub use change_detection::*; +pub use electricity::*; pub use light_policy::*; pub use map::*; pub use spatial_map::*;