mirror of
https://github.com/a-b-street/abstreet.git
synced 2024-12-01 02:33:54 +03:00
guarantee protected turns actually get first dibs in the scheduler
This commit is contained in:
parent
1145bbc8e6
commit
3ee73d40f0
@ -71,7 +71,8 @@ pub struct Turn {
|
||||
// TODO Some turns might not actually have geometry. Currently encoded by two equal points.
|
||||
// Represent more directly?
|
||||
pub geom: PolyLine,
|
||||
// Empty except for TurnType::Crosswalk.
|
||||
// Empty except for TurnType::Crosswalk. Usually just one other ID, except for the case of 4
|
||||
// duplicates at a degenerate intersection.
|
||||
pub other_crosswalk_ids: BTreeSet<TurnID>,
|
||||
|
||||
// Just for convenient debugging lookup.
|
||||
|
@ -159,12 +159,19 @@ impl IntersectionSimState {
|
||||
unreachable!()
|
||||
};
|
||||
|
||||
protected.extend(yielding);
|
||||
for req in protected {
|
||||
// Use update because multiple agents could finish a turn at the same time, before the
|
||||
// waiting one has a chance to try again.
|
||||
scheduler.update(now, Command::update_agent(req.agent));
|
||||
}
|
||||
// Make sure the protected group gets first dibs. The scheduler arbitrarily (but
|
||||
// deterministically) orders commands with the same time.
|
||||
for req in yielding {
|
||||
scheduler.update(
|
||||
now + Duration::seconds(0.1),
|
||||
Command::update_agent(req.agent),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// This is only triggered for traffic signals.
|
||||
|
@ -70,6 +70,7 @@ impl Ord for Item {
|
||||
if ord != Ordering::Equal {
|
||||
return ord;
|
||||
}
|
||||
// This is important! The tie-breaker if time is the same is ARBITRARY!
|
||||
self.cmd_type.cmp(&other.cmd_type)
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user