Skip to content

Commit

Permalink
Mechanical refactor: bus {stop, route} -> transit. #372
Browse files Browse the repository at this point in the history
(Mostly renaming map_model code everywhere, not yet sim layer and above)
  • Loading branch information
dabreegster committed Dec 2, 2021
1 parent 0f07255 commit 413f7ec
Show file tree
Hide file tree
Showing 41 changed files with 368 additions and 355 deletions.
20 changes: 12 additions & 8 deletions game/src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,7 @@ impl App {
let mut roads: Vec<&dyn Renderable> = Vec::new();
let mut intersections: Vec<&dyn Renderable> = Vec::new();
let mut buildings: Vec<&dyn Renderable> = Vec::new();
let mut bus_stops: Vec<&dyn Renderable> = Vec::new();
let mut transit_stops: Vec<&dyn Renderable> = Vec::new();
let mut agents_on: Vec<Traversable> = Vec::new();

for id in draw_map.get_matching_objects(bounds) {
Expand All @@ -387,9 +387,9 @@ impl App {
let road = draw_map.get_r(id);
for lane in &road.lanes {
agents_on.push(Traversable::Lane(lane.id));
for bs in &map.get_l(lane.id).bus_stops {
if show_objs.show(&ID::BusStop(*bs)) {
bus_stops.push(draw_map.get_bs(*bs));
for ts in &map.get_l(lane.id).transit_stops {
if show_objs.show(&ID::TransitStop(*ts)) {
transit_stops.push(draw_map.get_ts(*ts));
}
}
lanes.push(lane);
Expand All @@ -409,7 +409,11 @@ impl App {
agents_on.push(Traversable::Lane(map.get_pl(id).driving_pos.lane()));
}

ID::Lane(_) | ID::BusStop(_) | ID::Car(_) | ID::Pedestrian(_) | ID::PedCrowd(_) => {
ID::Lane(_)
| ID::TransitStop(_)
| ID::Car(_)
| ID::Pedestrian(_)
| ID::PedCrowd(_) => {
panic!("{:?} shouldn't be in the quadtree", id)
}
}
Expand All @@ -423,7 +427,7 @@ impl App {
borrows.extend(roads);
borrows.extend(intersections);
borrows.extend(buildings);
borrows.extend(bus_stops);
borrows.extend(transit_stops);

// Expand all of the Traversables into agents, populating the cache if needed.
for on in &agents_on {
Expand Down Expand Up @@ -736,9 +740,9 @@ impl PerMap {
ID::PedCrowd(ref members) => self
.sim
.canonical_pt_for_agent(AgentID::Pedestrian(members[0]), &self.map),
ID::BusStop(id) => self
ID::TransitStop(id) => self
.map
.maybe_get_bs(id)
.maybe_get_ts(id)
.map(|bs| bs.sidewalk_pos.pt(&self.map)),
ID::Area(id) => self.map.maybe_get_a(id).map(|a| a.polygon.center()),
}
Expand Down
6 changes: 3 additions & 3 deletions game/src/common/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ impl CommonState {
if let Some(r) = app.primary.sim.bus_route_id(c) {
osd.append_all(vec![
Line(" serving "),
Line(&map.get_br(r).full_name).underlined(),
Line(&map.get_tr(r).long_name).underlined(),
]);
}
}
Expand All @@ -197,12 +197,12 @@ impl CommonState {
ID::PedCrowd(list) => {
osd.append(Line(format!("a crowd of {} pedestrians", list.len())));
}
ID::BusStop(bs) => {
ID::TransitStop(bs) => {
if app.opts.dev {
osd.append(Line(bs.to_string()).bold_body());
} else {
osd.append(Line("transit stop "));
osd.append(Line(&map.get_bs(bs).name).underlined());
osd.append(Line(&map.get_ts(bs).name).underlined());
}
osd.append(Line(" served by "));

Expand Down
8 changes: 4 additions & 4 deletions game/src/common/warp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use std::collections::BTreeMap;
use geom::Pt2D;
use map_gui::tools::{grey_out_map, PopupMsg};
use map_gui::ID;
use map_model::{AreaID, BuildingID, BusRouteID, IntersectionID, LaneID, ParkingLotID, RoadID};
use map_model::{AreaID, BuildingID, IntersectionID, LaneID, ParkingLotID, RoadID, TransitRouteID};
use sim::{PedestrianID, PersonID, TripID};
use widgetry::{
EventCtx, GfxCtx, Key, Line, Outcome, Panel, State, Text, TextBox, TextExt, Warper, Widget,
Expand Down Expand Up @@ -186,8 +186,8 @@ fn inner_warp_to_id(ctx: &mut EventCtx, app: &mut App, line: &str) -> Option<Tra
ID::Lane(r.lanes[0].id)
}
'R' => {
let r = BusRouteID(idx);
app.primary.map.maybe_get_br(r)?;
let r = TransitRouteID(idx);
app.primary.map.maybe_get_tr(r)?;
return Some(Transition::Multi(vec![
Transition::Pop,
Transition::ModifyState(Box::new(move |state, ctx, app| {
Expand All @@ -197,7 +197,7 @@ fn inner_warp_to_id(ctx: &mut EventCtx, app: &mut App, line: &str) -> Option<Tra
s.controls.common.as_mut().unwrap().launch_info_panel(
ctx,
app,
Tab::BusRoute(r),
Tab::TransitRoute(r),
&mut actions,
);
}
Expand Down
2 changes: 1 addition & 1 deletion game/src/debug/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -629,7 +629,7 @@ impl ContextualActions for Actions {
ID::ParkingLot(_) => {
actions.push((Key::H, "hide this".to_string()));
}
ID::BusStop(_) => {
ID::TransitStop(_) => {
actions.push((Key::H, "hide this".to_string()));
}
ID::Building(_) => {
Expand Down
6 changes: 3 additions & 3 deletions game/src/debug/objects.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,8 @@ impl ObjectDebugger {
sim.debug_ped(p);
}
}
ID::BusStop(id) => {
println!("{}", abstutil::to_json(map.get_bs(id)));
ID::TransitStop(id) => {
println!("{}", abstutil::to_json(map.get_ts(id)));
}
ID::Area(id) => {
println!("{}", abstutil::to_json(map.get_a(id)));
Expand All @@ -110,7 +110,7 @@ impl ObjectDebugger {
ID::Pedestrian(id) => sim.debug_agent_json(AgentID::Pedestrian(id)),
// Just show the first...
ID::PedCrowd(members) => sim.debug_agent_json(AgentID::Pedestrian(members[0])),
ID::BusStop(id) => abstutil::to_json(map.get_bs(id)),
ID::TransitStop(id) => abstutil::to_json(map.get_ts(id)),
ID::Area(id) => abstutil::to_json(map.get_a(id)),
ID::Road(_) => unreachable!(),
};
Expand Down
12 changes: 6 additions & 6 deletions game/src/edit/routes.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use geom::{Duration, Time};
use map_model::{BusRouteID, EditCmd};
use map_model::{EditCmd, TransitRouteID};
use widgetry::{
EventCtx, GfxCtx, HorizontalAlignment, Key, Line, Outcome, Panel, Spinner, State, TextExt,
VerticalAlignment, Widget,
Expand All @@ -11,21 +11,21 @@ use crate::edit::apply_map_edits;

pub struct RouteEditor {
panel: Panel,
route: BusRouteID,
route: TransitRouteID,
}

impl RouteEditor {
pub fn new_state(ctx: &mut EventCtx, app: &mut App, id: BusRouteID) -> Box<dyn State<App>> {
pub fn new_state(ctx: &mut EventCtx, app: &mut App, id: TransitRouteID) -> Box<dyn State<App>> {
app.primary.current_selection = None;

let route = app.primary.map.get_br(id);
let route = app.primary.map.get_tr(id);
Box::new(RouteEditor {
panel: Panel::new_builder(Widget::col(vec![
Widget::row(vec![
Line("Route editor").small_heading().into_widget(ctx),
ctx.style().btn_close_widget(ctx),
]),
Line(&route.full_name).into_widget(ctx),
Line(&route.long_name).into_widget(ctx),
// TODO This UI needs design, just something to start plumbing the edits
Widget::row(vec![
"Frequency".text_widget(ctx),
Expand Down Expand Up @@ -71,7 +71,7 @@ impl State<App> for RouteEditor {
let mut edits = app.primary.map.get_edits().clone();
edits.commands.push(EditCmd::ChangeRouteSchedule {
id: self.route,
old: app.primary.map.get_br(self.route).spawn_times.clone(),
old: app.primary.map.get_tr(self.route).spawn_times.clone(),
new: hourly_times,
});
apply_map_edits(ctx, app, edits);
Expand Down
38 changes: 20 additions & 18 deletions game/src/info/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ pub use trip::OpenTrip;
use geom::{Circle, Distance, Polygon, Time};
use map_gui::tools::open_browser;
use map_gui::ID;
use map_model::{AreaID, BuildingID, BusRouteID, BusStopID, IntersectionID, LaneID, ParkingLotID};
use map_model::{
AreaID, BuildingID, IntersectionID, LaneID, ParkingLotID, TransitRouteID, TransitStopID,
};
use sim::{
AgentID, AgentType, Analytics, CarID, ParkingSpot, PedestrianID, PersonID, PersonState, TripID,
VehicleType,
Expand All @@ -24,12 +26,12 @@ use crate::layer::PANEL_PLACEMENT;
use crate::sandbox::{dashboards, GameplayMode, SandboxMode, TimeWarpScreen};

mod building;
mod bus;
mod debug;
mod intersection;
mod lane;
mod parking_lot;
mod person;
mod transit;
mod trip;

pub struct InfoPanel {
Expand Down Expand Up @@ -57,9 +59,9 @@ pub enum Tab {
PersonBio(PersonID),
PersonSchedule(PersonID),

BusStatus(CarID),
BusStop(BusStopID),
BusRoute(BusRouteID),
TransitVehicleStatus(CarID),
TransitStop(TransitStopID),
TransitRoute(TransitRouteID),

ParkedCar(CarID),

Expand Down Expand Up @@ -151,7 +153,7 @@ impl Tab {
} else if c.vehicle_type == VehicleType::Bus || c.vehicle_type == VehicleType::Train
{
match app.session.info_panel_tab["bus"] {
"status" => Tab::BusStatus(c),
"status" => Tab::TransitVehicleStatus(c),
_ => unreachable!(),
}
} else {
Expand Down Expand Up @@ -180,7 +182,7 @@ impl Tab {
}
}
ID::PedCrowd(members) => Tab::Crowd(members),
ID::BusStop(bs) => Tab::BusStop(bs),
ID::TransitStop(bs) => Tab::TransitStop(bs),
ID::Area(a) => Tab::Area(a),
}
}
Expand All @@ -196,9 +198,9 @@ impl Tab {
_ => None,
}
}
Tab::BusStatus(c) => Some(ID::Car(*c)),
Tab::BusStop(bs) => Some(ID::BusStop(*bs)),
Tab::BusRoute(_) => None,
Tab::TransitVehicleStatus(c) => Some(ID::Car(*c)),
Tab::TransitStop(bs) => Some(ID::TransitStop(*bs)),
Tab::TransitRoute(_) => None,
// TODO If a parked car becomes in use while the panel is open, should update the
// panel better.
Tab::ParkedCar(c) => match app.primary.sim.lookup_parked_car(*c)?.spot {
Expand Down Expand Up @@ -262,9 +264,9 @@ impl Tab {
Tab::PersonTrips(_, _) => ("person", "trips"),
Tab::PersonBio(_) => ("person", "bio"),
Tab::PersonSchedule(_) => ("person", "schedule"),
Tab::BusStatus(_) => ("bus", "status"),
Tab::BusStop(_) => ("bus stop", "info"),
Tab::BusRoute(_) => ("bus route", "info"),
Tab::TransitVehicleStatus(_) => ("bus", "status"),
Tab::TransitStop(_) => ("bus stop", "info"),
Tab::TransitRoute(_) => ("bus route", "info"),
Tab::ParkedCar(_) => ("parked car", "info"),
Tab::BldgInfo(_) => ("bldg", "info"),
Tab::BldgPeople(_) => ("bldg", "people"),
Expand Down Expand Up @@ -332,9 +334,9 @@ impl InfoPanel {
person::schedule(ctx, app, &mut details, p, ctx_actions.is_paused()),
false,
),
Tab::BusStatus(c) => (bus::bus_status(ctx, app, &mut details, c), true),
Tab::BusStop(bs) => (bus::stop(ctx, app, &mut details, bs), true),
Tab::BusRoute(br) => (bus::route(ctx, app, &mut details, br), true),
Tab::TransitVehicleStatus(c) => (transit::bus_status(ctx, app, &mut details, c), true),
Tab::TransitStop(bs) => (transit::stop(ctx, app, &mut details, bs), true),
Tab::TransitRoute(br) => (transit::route(ctx, app, &mut details, br), true),
Tab::ParkedCar(c) => (
person::parked_car(ctx, app, &mut details, c, ctx_actions.is_paused()),
true,
Expand Down Expand Up @@ -571,7 +573,7 @@ impl InfoPanel {
} else if let Some(url) = action.strip_prefix("open ") {
open_browser(url);
(false, None)
} else if let Some(x) = action.strip_prefix("edit BusRoute #") {
} else if let Some(x) = action.strip_prefix("edit TransitRoute #") {
(
false,
Some(Transition::Multi(vec![
Expand All @@ -583,7 +585,7 @@ impl InfoPanel {
Transition::Push(RouteEditor::new_state(
ctx,
app,
BusRouteID(x.parse::<usize>().unwrap()),
TransitRouteID(x.parse::<usize>().unwrap()),
)),
])),
)
Expand Down
Loading

0 comments on commit 413f7ec

Please sign in to comment.