mirror of
https://github.com/a-b-street/abstreet.git
synced 2024-11-24 01:15:12 +03:00
merge TripStart and TripEnd
This commit is contained in:
parent
f89fcb9b93
commit
ce180f7228
@ -222,9 +222,9 @@ ed7646c4c95feb4b82221d11d1485ad7 data/system/scenarios/23rd/weekday.bin
|
||||
1267040c7cf31f649570d6cf36c6ec78 data/system/scenarios/huge_seattle/weekday.bin
|
||||
176031b2e9e8fa045b0490a253dc5759 data/system/scenarios/caphill/weekday.bin
|
||||
6f641b99b5eb522f9aa028eace00cd19 data/system/scenarios/montlake/weekday.bin
|
||||
aca1bff071cecad4683254b95c5570d1 data/system/prebaked_results/23rd/weekday.bin
|
||||
19df25a1ca21b8b9b0379723d858543d data/system/prebaked_results/23rd/weekday.bin
|
||||
39dc5028982cc7ef40da44ec00ab1020 data/system/prebaked_results/signal_single/tutorial lvl1.bin
|
||||
c4f5661e5c62c0c0ccccc7c2b9f2d365 data/system/prebaked_results/signal_single/tutorial lvl2.bin
|
||||
b8137879ec00add4cd2a39e8c985420f data/system/prebaked_results/montlake/car vs bike contention.bin
|
||||
2662a2f6996e5f7452d4e8e047c95440 data/system/prebaked_results/montlake/weekday.bin
|
||||
449475f6f7b54bc5726f07e20a5ee342 data/system/prebaked_results/montlake/car vs bus contention.bin
|
||||
7b21dd09012381f79c2de6b79650c7cd data/system/prebaked_results/montlake/weekday.bin
|
||||
f275f3d5a926afc054f2b1a2b8d139b3 data/system/prebaked_results/montlake/car vs bus contention.bin
|
||||
|
@ -4,7 +4,7 @@ use crate::helpers::ID;
|
||||
use crate::info::{make_browser, make_table, make_tabs, person, InfoTab};
|
||||
use ezgui::{EventCtx, GeomBatch, Line, Text, TextExt, Widget};
|
||||
use map_model::BuildingID;
|
||||
use sim::PersonID;
|
||||
use sim::{PersonID, TripEndpoint};
|
||||
use std::collections::HashMap;
|
||||
|
||||
#[derive(Clone)]
|
||||
@ -85,7 +85,12 @@ pub fn info(
|
||||
}
|
||||
}
|
||||
|
||||
let trip_lines = app.primary.sim.count_trips_involving_bldg(id).describe();
|
||||
// TODO Rethink this
|
||||
let trip_lines = app
|
||||
.primary
|
||||
.sim
|
||||
.count_trips(TripEndpoint::Bldg(id))
|
||||
.describe();
|
||||
if !trip_lines.is_empty() {
|
||||
txt.add(Line(""));
|
||||
for line in trip_lines {
|
||||
|
@ -5,7 +5,7 @@ use abstutil::prettyprint_usize;
|
||||
use ezgui::{EventCtx, Line, Plot, PlotOptions, Series, Text, Widget};
|
||||
use geom::{Duration, Statistic, Time};
|
||||
use map_model::{IntersectionID, IntersectionType};
|
||||
use sim::Analytics;
|
||||
use sim::{Analytics, TripEndpoint};
|
||||
use std::collections::{BTreeSet, HashMap};
|
||||
|
||||
#[derive(Clone, PartialEq)]
|
||||
@ -70,7 +70,12 @@ pub fn info(
|
||||
InfoTab::Nil => {
|
||||
rows.extend(action_btns);
|
||||
|
||||
let trip_lines = app.primary.sim.count_trips_involving_border(id).describe();
|
||||
// TODO Rethink
|
||||
let trip_lines = app
|
||||
.primary
|
||||
.sim
|
||||
.count_trips(TripEndpoint::Border(id))
|
||||
.describe();
|
||||
if !trip_lines.is_empty() {
|
||||
let mut txt = Text::new();
|
||||
for line in trip_lines {
|
||||
|
@ -9,7 +9,7 @@ use ezgui::{
|
||||
};
|
||||
use geom::{Angle, Distance, Duration, Polygon, Pt2D, Time};
|
||||
use map_model::{Map, Path, PathStep};
|
||||
use sim::{PersonID, TripEnd, TripID, TripPhaseType, TripStart};
|
||||
use sim::{PersonID, TripEndpoint, TripID, TripPhaseType};
|
||||
use std::collections::HashMap;
|
||||
|
||||
#[derive(Clone, PartialEq)]
|
||||
@ -87,22 +87,9 @@ pub fn trip_details(
|
||||
("Trip start", start_time.ampm_tostring()),
|
||||
("Type", trip_mode.to_string()),
|
||||
// TODO If we're looking at a building, then "here"...
|
||||
// TODO Refactor... TripStart.name(map)?
|
||||
// TODO Buttons
|
||||
(
|
||||
"From",
|
||||
match trip_start {
|
||||
TripStart::Bldg(b) => map.get_b(b).just_address(map),
|
||||
TripStart::Border(i) => map.get_i(i).name(map),
|
||||
},
|
||||
),
|
||||
(
|
||||
"To",
|
||||
match trip_end {
|
||||
TripEnd::Bldg(b) => map.get_b(b).just_address(map),
|
||||
TripEnd::Border(i) => map.get_i(i).name(map),
|
||||
},
|
||||
),
|
||||
("From", endpoint(&trip_start, map).2),
|
||||
("To", endpoint(&trip_end, map).2),
|
||||
];
|
||||
return (
|
||||
Widget::col(make_table(ctx, kv)),
|
||||
@ -116,16 +103,7 @@ pub fn trip_details(
|
||||
}
|
||||
|
||||
let start_btn = {
|
||||
let (id, center, name) = match trip_start {
|
||||
TripStart::Bldg(b) => {
|
||||
let bldg = map.get_b(b);
|
||||
(ID::Building(b), bldg.label_center, bldg.just_address(map))
|
||||
}
|
||||
TripStart::Border(i) => {
|
||||
let i = map.get_i(i);
|
||||
(ID::Intersection(i.id), i.polygon.center(), i.name(map))
|
||||
}
|
||||
};
|
||||
let (id, center, name) = endpoint(&trip_start, map);
|
||||
markers.insert("jump to start".to_string(), id);
|
||||
unzoomed.add_svg(
|
||||
ctx.prerender,
|
||||
@ -155,16 +133,7 @@ pub fn trip_details(
|
||||
let end_time = phases.last().as_ref().and_then(|p| p.end_time);
|
||||
|
||||
let goal_btn = {
|
||||
let (id, center, name) = match trip_end {
|
||||
TripEnd::Bldg(b) => {
|
||||
let bldg = map.get_b(b);
|
||||
(ID::Building(b), bldg.label_center, bldg.just_address(map))
|
||||
}
|
||||
TripEnd::Border(i) => {
|
||||
let i = map.get_i(i);
|
||||
(ID::Intersection(i.id), i.polygon.center(), i.name(map))
|
||||
}
|
||||
};
|
||||
let (id, center, name) = endpoint(&trip_end, map);
|
||||
markers.insert("jump to goal".to_string(), id);
|
||||
unzoomed.add_svg(
|
||||
ctx.prerender,
|
||||
@ -371,3 +340,17 @@ fn make_elevation(ctx: &EventCtx, color: Color, walking: bool, path: &Path, map:
|
||||
)
|
||||
.bg(colors::PANEL_BG)
|
||||
}
|
||||
|
||||
// (ID, center, name)
|
||||
fn endpoint(endpt: &TripEndpoint, map: &Map) -> (ID, Pt2D, String) {
|
||||
match endpt {
|
||||
TripEndpoint::Bldg(b) => {
|
||||
let bldg = map.get_b(*b);
|
||||
(ID::Building(*b), bldg.label_center, bldg.just_address(map))
|
||||
}
|
||||
TripEndpoint::Border(i) => {
|
||||
let i = map.get_i(*i);
|
||||
(ID::Intersection(i.id), i.polygon.center(), i.name(map))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -13,6 +13,7 @@ use ezgui::{
|
||||
};
|
||||
use geom::Polygon;
|
||||
use map_model::IntersectionID;
|
||||
use sim::TripEndpoint;
|
||||
use std::collections::BTreeSet;
|
||||
|
||||
// TODO Maybe remember what things were spawned, offer to replay this later
|
||||
@ -65,7 +66,12 @@ impl GameplayState for Freeform {
|
||||
if let Some(ID::Intersection(i)) = app.primary.current_selection {
|
||||
if self.spawn_pts.contains(&i) {
|
||||
let mut txt = Text::new();
|
||||
for line in app.primary.sim.count_trips_involving_border(i).describe() {
|
||||
for line in app
|
||||
.primary
|
||||
.sim
|
||||
.count_trips(TripEndpoint::Border(i))
|
||||
.describe()
|
||||
{
|
||||
txt.add(Line(line));
|
||||
}
|
||||
if !txt.is_empty() {
|
||||
|
@ -23,7 +23,7 @@ pub(crate) use self::scheduler::{Command, Scheduler};
|
||||
pub use self::sim::{Sim, SimOptions};
|
||||
pub(crate) use self::transit::TransitSimState;
|
||||
pub use self::trips::{Person, PersonState, TripCount, TripResult};
|
||||
pub use self::trips::{TripEnd, TripMode, TripStart};
|
||||
pub use self::trips::{TripEndpoint, TripMode};
|
||||
pub(crate) use self::trips::{TripLeg, TripManager};
|
||||
pub use crate::render::{
|
||||
CarStatus, DontDrawAgents, DrawCarInput, DrawPedCrowdInput, DrawPedestrianInput, GetDrawAgents,
|
||||
|
@ -1,7 +1,7 @@
|
||||
use crate::{
|
||||
CarID, Command, CreateCar, CreatePedestrian, DrivingGoal, ParkingSimState, ParkingSpot,
|
||||
PedestrianID, PersonID, Scheduler, SidewalkPOI, SidewalkSpot, Sim, TripLeg, TripManager,
|
||||
TripStart, VehicleSpec, VehicleType, MAX_CAR_LENGTH,
|
||||
PedestrianID, PersonID, Scheduler, SidewalkPOI, SidewalkSpot, Sim, TripEndpoint, TripLeg,
|
||||
TripManager, VehicleSpec, VehicleType, MAX_CAR_LENGTH,
|
||||
};
|
||||
use abstutil::Timer;
|
||||
use geom::{Speed, Time, EPSILON_DIST};
|
||||
@ -285,7 +285,7 @@ impl TripSpawner {
|
||||
SidewalkSpot::building(b, map),
|
||||
));
|
||||
}
|
||||
let trip_start = TripStart::Border(map.get_l(start_pos.lane()).src_i);
|
||||
let trip_start = TripEndpoint::Border(map.get_l(start_pos.lane()).src_i);
|
||||
let trip = trips.new_trip(person, start_time, trip_start, legs);
|
||||
if let Some(path) = maybe_path {
|
||||
let router = goal.make_router(path, map, vehicle.vehicle_type);
|
||||
@ -335,7 +335,7 @@ impl TripSpawner {
|
||||
let trip = trips.new_trip(
|
||||
person,
|
||||
start_time,
|
||||
TripStart::Bldg(vehicle.owner.unwrap()),
|
||||
TripEndpoint::Bldg(vehicle.owner.unwrap()),
|
||||
legs,
|
||||
);
|
||||
|
||||
@ -370,7 +370,7 @@ impl TripSpawner {
|
||||
// the DrivingGoal, so we can expand the trip later.
|
||||
let legs = vec![TripLeg::Walk(ped_id.unwrap(), ped_speed, walk_to.clone())];
|
||||
let trip =
|
||||
trips.new_trip(person, start_time, TripStart::Bldg(start_bldg), legs);
|
||||
trips.new_trip(person, start_time, TripEndpoint::Bldg(start_bldg), legs);
|
||||
|
||||
scheduler.quick_push(
|
||||
start_time,
|
||||
@ -395,11 +395,11 @@ impl TripSpawner {
|
||||
person,
|
||||
start_time,
|
||||
match start.connection {
|
||||
SidewalkPOI::Building(b) => TripStart::Bldg(b),
|
||||
SidewalkPOI::Building(b) => TripEndpoint::Bldg(b),
|
||||
SidewalkPOI::SuddenlyAppear => {
|
||||
TripStart::Border(map.get_l(start.sidewalk_pos.lane()).src_i)
|
||||
TripEndpoint::Border(map.get_l(start.sidewalk_pos.lane()).src_i)
|
||||
}
|
||||
SidewalkPOI::Border(i) => TripStart::Border(i),
|
||||
SidewalkPOI::Border(i) => TripEndpoint::Border(i),
|
||||
_ => unreachable!(),
|
||||
},
|
||||
vec![TripLeg::Walk(ped_id.unwrap(), ped_speed, goal.clone())],
|
||||
@ -452,11 +452,11 @@ impl TripSpawner {
|
||||
person,
|
||||
start_time,
|
||||
match start.connection {
|
||||
SidewalkPOI::Building(b) => TripStart::Bldg(b),
|
||||
SidewalkPOI::Building(b) => TripEndpoint::Bldg(b),
|
||||
SidewalkPOI::SuddenlyAppear => {
|
||||
TripStart::Border(map.get_l(start.sidewalk_pos.lane()).src_i)
|
||||
TripEndpoint::Border(map.get_l(start.sidewalk_pos.lane()).src_i)
|
||||
}
|
||||
SidewalkPOI::Border(i) => TripStart::Border(i),
|
||||
SidewalkPOI::Border(i) => TripEndpoint::Border(i),
|
||||
_ => unreachable!(),
|
||||
},
|
||||
legs,
|
||||
@ -496,11 +496,11 @@ impl TripSpawner {
|
||||
person,
|
||||
start_time,
|
||||
match start.connection {
|
||||
SidewalkPOI::Building(b) => TripStart::Bldg(b),
|
||||
SidewalkPOI::Building(b) => TripEndpoint::Bldg(b),
|
||||
SidewalkPOI::SuddenlyAppear => {
|
||||
TripStart::Border(map.get_l(start.sidewalk_pos.lane()).src_i)
|
||||
TripEndpoint::Border(map.get_l(start.sidewalk_pos.lane()).src_i)
|
||||
}
|
||||
SidewalkPOI::Border(i) => TripStart::Border(i),
|
||||
SidewalkPOI::Border(i) => TripEndpoint::Border(i),
|
||||
_ => unreachable!(),
|
||||
},
|
||||
vec![
|
||||
|
@ -2,9 +2,9 @@ use crate::{
|
||||
AgentID, Analytics, CarID, Command, CreateCar, DrawCarInput, DrawPedCrowdInput,
|
||||
DrawPedestrianInput, DrivingGoal, DrivingSimState, Event, GetDrawAgents, IntersectionSimState,
|
||||
ParkedCar, ParkingSimState, ParkingSpot, PedestrianID, Person, PersonID, PersonState, Router,
|
||||
Scheduler, SidewalkPOI, SidewalkSpot, TransitSimState, TripCount, TripEnd, TripID, TripLeg,
|
||||
TripManager, TripMode, TripPhaseType, TripPositions, TripResult, TripSpawner, TripSpec,
|
||||
TripStart, UnzoomedAgent, VehicleSpec, VehicleType, WalkingSimState, BUS_LENGTH,
|
||||
Scheduler, SidewalkPOI, SidewalkSpot, TransitSimState, TripCount, TripEndpoint, TripID,
|
||||
TripLeg, TripManager, TripMode, TripPhaseType, TripPositions, TripResult, TripSpawner,
|
||||
TripSpec, UnzoomedAgent, VehicleSpec, VehicleType, WalkingSimState, BUS_LENGTH,
|
||||
};
|
||||
use abstutil::Timer;
|
||||
use derivative::Derivative;
|
||||
@ -851,11 +851,8 @@ impl Sim {
|
||||
self.trips.num_ppl()
|
||||
}
|
||||
|
||||
pub fn count_trips_involving_bldg(&self, b: BuildingID) -> TripCount {
|
||||
self.trips.count_trips_involving_bldg(b, self.time)
|
||||
}
|
||||
pub fn count_trips_involving_border(&self, i: IntersectionID) -> TripCount {
|
||||
self.trips.count_trips_involving_border(i, self.time)
|
||||
pub fn count_trips(&self, endpt: TripEndpoint) -> TripCount {
|
||||
self.trips.count_trips(endpt, self.time)
|
||||
}
|
||||
|
||||
pub fn debug_ped(&self, id: PedestrianID) {
|
||||
@ -957,7 +954,7 @@ impl Sim {
|
||||
}
|
||||
|
||||
// (start time, start position, end position, trip type)
|
||||
pub fn trip_info(&self, id: TripID) -> (Time, TripStart, TripEnd, TripMode) {
|
||||
pub fn trip_info(&self, id: TripID) -> (Time, TripEndpoint, TripEndpoint, TripMode) {
|
||||
self.trips.trip_info(id)
|
||||
}
|
||||
|
||||
|
@ -55,7 +55,7 @@ impl TripManager {
|
||||
&mut self,
|
||||
person: PersonID,
|
||||
spawned_at: Time,
|
||||
start: TripStart,
|
||||
start: TripEndpoint,
|
||||
legs: Vec<TripLeg>,
|
||||
) -> TripID {
|
||||
assert!(!legs.is_empty());
|
||||
@ -83,17 +83,17 @@ impl TripManager {
|
||||
}
|
||||
let end = match legs.last() {
|
||||
Some(TripLeg::Walk(_, _, ref spot)) => match spot.connection {
|
||||
SidewalkPOI::Building(b) => TripEnd::Bldg(b),
|
||||
SidewalkPOI::Border(i) => TripEnd::Border(i),
|
||||
SidewalkPOI::Building(b) => TripEndpoint::Bldg(b),
|
||||
SidewalkPOI::Border(i) => TripEndpoint::Border(i),
|
||||
SidewalkPOI::DeferredParkingSpot(_, ref goal) => match goal {
|
||||
DrivingGoal::ParkNear(b) => TripEnd::Bldg(*b),
|
||||
DrivingGoal::Border(i, _) => TripEnd::Border(*i),
|
||||
DrivingGoal::ParkNear(b) => TripEndpoint::Bldg(*b),
|
||||
DrivingGoal::Border(i, _) => TripEndpoint::Border(*i),
|
||||
},
|
||||
_ => unreachable!(),
|
||||
},
|
||||
Some(TripLeg::Drive(_, ref goal)) => match goal {
|
||||
DrivingGoal::ParkNear(b) => TripEnd::Bldg(*b),
|
||||
DrivingGoal::Border(i, _) => TripEnd::Border(*i),
|
||||
DrivingGoal::ParkNear(b) => TripEndpoint::Bldg(*b),
|
||||
DrivingGoal::Border(i, _) => TripEndpoint::Border(*i),
|
||||
},
|
||||
_ => unreachable!(),
|
||||
};
|
||||
@ -112,8 +112,8 @@ impl TripManager {
|
||||
let person = &mut self.people[trip.person.0];
|
||||
if person.trips.is_empty() {
|
||||
person.state = match trip.start {
|
||||
TripStart::Bldg(b) => PersonState::Inside(b),
|
||||
TripStart::Border(_) => PersonState::OffMap,
|
||||
TripEndpoint::Bldg(b) => PersonState::Inside(b),
|
||||
TripEndpoint::Border(_) => PersonState::OffMap,
|
||||
};
|
||||
}
|
||||
if let Some(t) = person.trips.last() {
|
||||
@ -591,19 +591,12 @@ impl TripManager {
|
||||
Some((t.id, t.spawned_at))
|
||||
}
|
||||
|
||||
pub fn trip_info(&self, id: TripID) -> (Time, TripStart, TripEnd, TripMode) {
|
||||
pub fn trip_info(&self, id: TripID) -> (Time, TripEndpoint, TripEndpoint, TripMode) {
|
||||
let t = &self.trips[id.0];
|
||||
(t.spawned_at, t.start.clone(), t.end.clone(), t.mode)
|
||||
}
|
||||
|
||||
// TODO Refactor after wrangling the TripStart/TripEnd mess
|
||||
pub fn count_trips_involving_bldg(&self, b: BuildingID, now: Time) -> TripCount {
|
||||
self.count_trips(TripStart::Bldg(b), TripEnd::Bldg(b), now)
|
||||
}
|
||||
pub fn count_trips_involving_border(&self, i: IntersectionID, now: Time) -> TripCount {
|
||||
self.count_trips(TripStart::Border(i), TripEnd::Border(i), now)
|
||||
}
|
||||
fn count_trips(&self, start: TripStart, end: TripEnd, now: Time) -> TripCount {
|
||||
pub fn count_trips(&self, endpt: TripEndpoint, now: Time) -> TripCount {
|
||||
let mut cnt = TripCount {
|
||||
from_aborted: Vec::new(),
|
||||
from_in_progress: Vec::new(),
|
||||
@ -615,7 +608,7 @@ impl TripManager {
|
||||
to_unstarted: Vec::new(),
|
||||
};
|
||||
for trip in &self.trips {
|
||||
if trip.start == start {
|
||||
if trip.start == endpt {
|
||||
if trip.aborted {
|
||||
cnt.from_aborted.push(trip.id);
|
||||
} else if trip.finished_at.is_some() {
|
||||
@ -627,7 +620,7 @@ impl TripManager {
|
||||
}
|
||||
}
|
||||
// One trip might could towards both!
|
||||
if trip.end == end {
|
||||
if trip.end == endpt {
|
||||
if trip.aborted {
|
||||
cnt.to_aborted.push(trip.id);
|
||||
} else if trip.finished_at.is_some() {
|
||||
@ -672,8 +665,8 @@ struct Trip {
|
||||
aborted: bool,
|
||||
legs: VecDeque<TripLeg>,
|
||||
mode: TripMode,
|
||||
start: TripStart,
|
||||
end: TripEnd,
|
||||
start: TripEndpoint,
|
||||
end: TripEndpoint,
|
||||
person: PersonID,
|
||||
}
|
||||
|
||||
@ -796,16 +789,8 @@ impl std::fmt::Display for TripMode {
|
||||
}
|
||||
}
|
||||
|
||||
// TODO Argh no, not more of these variants!
|
||||
|
||||
#[derive(Serialize, Deserialize, PartialEq, Debug, Clone)]
|
||||
pub enum TripStart {
|
||||
Bldg(BuildingID),
|
||||
Border(IntersectionID),
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, PartialEq, Debug, Clone)]
|
||||
pub enum TripEnd {
|
||||
pub enum TripEndpoint {
|
||||
Bldg(BuildingID),
|
||||
Border(IntersectionID),
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user