mirror of
https://github.com/a-b-street/abstreet.git
synced 2024-12-01 10:44:56 +03:00
rephrase time_since_last_turn as time_spent_blocked, so things like pedestrians walking on long roads don't show up as spurious gridlockedness
This commit is contained in:
parent
4c7c9156d0
commit
a3cd03a5bc
@ -89,7 +89,7 @@ impl CommonState {
|
||||
.get_unzoomed_agents_with_delay(&ui.primary.map)
|
||||
{
|
||||
batch.push(
|
||||
delay_color(agent.time_since_last_turn),
|
||||
delay_color(agent.time_spent_blocked),
|
||||
Circle::new(agent.pos, radius).to_polygon(),
|
||||
);
|
||||
}
|
||||
|
@ -13,7 +13,7 @@ pub struct Car {
|
||||
pub state: CarState,
|
||||
pub router: Router,
|
||||
pub trip: TripID,
|
||||
pub last_completed_turn: Duration,
|
||||
pub blocked_since: Option<Duration>,
|
||||
|
||||
// In reverse order -- most recently left is first. The sum length of these must be >=
|
||||
// vehicle.length.
|
||||
|
@ -85,7 +85,7 @@ impl DrivingSimState {
|
||||
// Temporary
|
||||
state: CarState::Queued,
|
||||
last_steps: VecDeque::new(),
|
||||
last_completed_turn: now,
|
||||
blocked_since: None,
|
||||
trip: params.trip,
|
||||
};
|
||||
if params.maybe_parked_car.is_some() {
|
||||
@ -226,6 +226,7 @@ impl DrivingSimState {
|
||||
match car.state {
|
||||
CarState::Crossing(_, _) => {
|
||||
car.state = CarState::Queued;
|
||||
car.blocked_since = Some(now);
|
||||
if car.router.last_step() {
|
||||
// Immediately run update_car_with_distances.
|
||||
return true;
|
||||
@ -274,6 +275,7 @@ impl DrivingSimState {
|
||||
now,
|
||||
map,
|
||||
);
|
||||
follower.blocked_since = None;
|
||||
scheduler.update(
|
||||
follower.state.get_end_time(),
|
||||
Command::UpdateCar(follower.vehicle.id),
|
||||
@ -330,6 +332,7 @@ impl DrivingSimState {
|
||||
|
||||
let last_step = car.router.advance(&car.vehicle, parking, map);
|
||||
car.state = car.crossing_state(Distance::ZERO, now, map);
|
||||
car.blocked_since = None;
|
||||
scheduler.push(car.state.get_end_time(), Command::UpdateCar(car.vehicle.id));
|
||||
|
||||
car.last_steps.push_front(last_step);
|
||||
@ -387,7 +390,8 @@ impl DrivingSimState {
|
||||
.unwrap();
|
||||
let our_dist = dists[idx].1;
|
||||
|
||||
// Just two cases here.
|
||||
// Just two cases here. In all cases, we leave the Queued state.
|
||||
car.blocked_since = None;
|
||||
match car.state {
|
||||
CarState::Crossing(_, _)
|
||||
| CarState::Unparking(_, _)
|
||||
@ -521,6 +525,7 @@ impl DrivingSimState {
|
||||
// no-op. But if they were blocked, then this will prevent them from
|
||||
// jumping forwards.
|
||||
follower.state = follower.crossing_state(follower_dist, now, map);
|
||||
follower.blocked_since = None;
|
||||
scheduler.update(
|
||||
follower.state.get_end_time(),
|
||||
Command::UpdateCar(follower_id),
|
||||
@ -610,7 +615,6 @@ impl DrivingSimState {
|
||||
match on {
|
||||
Traversable::Turn(t) => {
|
||||
intersections.turn_finished(now, AgentID::Car(car.vehicle.id), *t, scheduler);
|
||||
car.last_completed_turn = now;
|
||||
}
|
||||
Traversable::Lane(l) => {
|
||||
old_queue.free_reserved_space(car);
|
||||
@ -694,7 +698,10 @@ impl DrivingSimState {
|
||||
for (car, dist) in queue.get_car_positions(now, &self.cars, &self.queues) {
|
||||
result.push(UnzoomedAgent {
|
||||
pos: queue.id.dist_along(dist, map).0,
|
||||
time_since_last_turn: now - self.cars[&car].last_completed_turn,
|
||||
time_spent_blocked: self.cars[&car]
|
||||
.blocked_since
|
||||
.map(|t| now - t)
|
||||
.unwrap_or(Duration::ZERO),
|
||||
});
|
||||
}
|
||||
}
|
||||
@ -773,7 +780,10 @@ impl DrivingSimState {
|
||||
format!("{} on {}", id, car.router.head()),
|
||||
format!("Owned by {:?}", car.vehicle.owner),
|
||||
format!("{} lanes left", car.router.get_path().num_lanes()),
|
||||
format!("Last turned {} ago", now - car.last_completed_turn),
|
||||
format!(
|
||||
"Blocked for {}",
|
||||
car.blocked_since.map(|t| now - t).unwrap_or(Duration::ZERO)
|
||||
),
|
||||
format!("{:?}", car.state),
|
||||
])
|
||||
}
|
||||
|
@ -53,7 +53,7 @@ impl WalkingSimState {
|
||||
TimeInterval::new(Duration::ZERO, Duration::seconds(1.0)),
|
||||
),
|
||||
speed: params.speed,
|
||||
last_completed_turn: now,
|
||||
blocked_since: None,
|
||||
path: params.path,
|
||||
goal: params.goal,
|
||||
trip: params.trip,
|
||||
@ -140,6 +140,7 @@ impl WalkingSimState {
|
||||
self.peds.remove(&id);
|
||||
} else {
|
||||
ped.state = PedState::WaitingForBus;
|
||||
ped.blocked_since = Some(now);
|
||||
}
|
||||
}
|
||||
SidewalkPOI::Border(i) => {
|
||||
@ -163,7 +164,6 @@ impl WalkingSimState {
|
||||
} else {
|
||||
if let PathStep::Turn(t) = ped.path.current_step() {
|
||||
intersections.turn_finished(now, AgentID::Pedestrian(ped.id), t, scheduler);
|
||||
ped.last_completed_turn = now;
|
||||
}
|
||||
|
||||
let dist = dist_int.end;
|
||||
@ -178,6 +178,7 @@ impl WalkingSimState {
|
||||
} else {
|
||||
// Must've failed because we can't turn yet. Don't schedule a retry here.
|
||||
ped.state = PedState::WaitingToTurn(dist);
|
||||
ped.blocked_since = Some(now);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -190,6 +191,7 @@ impl WalkingSimState {
|
||||
scheduler,
|
||||
) {
|
||||
scheduler.push(ped.state.get_end_time(), Command::UpdatePed(ped.id));
|
||||
ped.blocked_since = None;
|
||||
}
|
||||
}
|
||||
PedState::LeavingBuilding(b, _) => {
|
||||
@ -241,7 +243,10 @@ impl WalkingSimState {
|
||||
vec![
|
||||
format!("{} on {:?}", p.id, p.path.current_step()),
|
||||
format!("{} lanes left in path", p.path.num_lanes()),
|
||||
format!("Last turned {} ago", now - p.last_completed_turn),
|
||||
format!(
|
||||
"Blocked for {}",
|
||||
p.blocked_since.map(|t| now - t).unwrap_or(Duration::ZERO)
|
||||
),
|
||||
format!("{:?}", p.state),
|
||||
]
|
||||
}
|
||||
@ -281,7 +286,7 @@ impl WalkingSimState {
|
||||
for ped in self.peds.values() {
|
||||
peds.push(UnzoomedAgent {
|
||||
pos: ped.get_draw_ped(now, map).pos,
|
||||
time_since_last_turn: now - ped.last_completed_turn,
|
||||
time_spent_blocked: ped.blocked_since.map(|t| now - t).unwrap_or(Duration::ZERO),
|
||||
});
|
||||
}
|
||||
|
||||
@ -302,9 +307,7 @@ struct Pedestrian {
|
||||
id: PedestrianID,
|
||||
state: PedState,
|
||||
speed: Speed,
|
||||
// Pedestrians waiting for buses will also have their times creep up, but that's nice, since it
|
||||
// captures that same sense of delay.
|
||||
last_completed_turn: Duration,
|
||||
blocked_since: Option<Duration>,
|
||||
|
||||
path: Path,
|
||||
goal: SidewalkSpot,
|
||||
|
@ -35,8 +35,7 @@ pub enum CarStatus {
|
||||
|
||||
pub struct UnzoomedAgent {
|
||||
pub pos: Pt2D,
|
||||
// TODO Track actual delay, based on more fine-grained states. Easiest to be an Option
|
||||
pub time_since_last_turn: Duration,
|
||||
pub time_spent_blocked: Duration,
|
||||
}
|
||||
|
||||
// TODO Can we return borrows instead? Nice for time travel, not for main sim?
|
||||
|
Loading…
Reference in New Issue
Block a user