mirror of
https://github.com/a-b-street/abstreet.git
synced 2024-11-28 03:35:51 +03:00
expunge the concept of traffic signals being in overtime. not realistic to how people drive, the current rules allow progress without impacting safety. also disable gridlock detection -- noisy results, easier to visually spot, and slow.
This commit is contained in:
parent
d72aefdc7c
commit
5a3862dda0
@ -115,8 +115,6 @@
|
||||
- validation (just do it in spawn and return an error?)
|
||||
- getting the path
|
||||
- converting goal into router and such
|
||||
- is overtime necessary?
|
||||
- all the scoring/query stuff is so terrible
|
||||
|
||||
- perf
|
||||
- speed up Scheduler
|
||||
|
@ -2,7 +2,6 @@ use crate::helpers::ID;
|
||||
use crate::render::{draw_signal_diagram, DrawCtx, DrawTurn};
|
||||
use crate::ui::UI;
|
||||
use ezgui::{Color, EventCtx, GfxCtx, Key};
|
||||
use geom::Duration;
|
||||
use map_model::{IntersectionID, LaneID, Map, TurnType};
|
||||
|
||||
pub struct TurnCyclerState {
|
||||
@ -89,12 +88,8 @@ impl TurnCyclerState {
|
||||
State::ShowIntersection(i) => {
|
||||
if self.shift_key_held {
|
||||
if let Some(signal) = ui.primary.map.maybe_get_traffic_signal(i) {
|
||||
let (cycle, mut time_left) =
|
||||
let (cycle, time_left) =
|
||||
signal.current_cycle_and_remaining_time(ui.primary.sim.time());
|
||||
if ui.primary.sim.is_in_overtime(i, &ui.primary.map) {
|
||||
// TODO Hacky way of indicating overtime. Should make a 3-case enum.
|
||||
time_left = Duration::seconds(-1.0);
|
||||
}
|
||||
let ctx = DrawCtx {
|
||||
cs: &ui.cs,
|
||||
map: &ui.primary.map,
|
||||
|
@ -140,20 +140,18 @@ impl Renderable for DrawIntersection {
|
||||
&& opts.suppress_traffic_signal_details != Some(self.id)
|
||||
{
|
||||
let signal = ctx.map.get_traffic_signal(self.id);
|
||||
if !ctx.sim.is_in_overtime(self.id, ctx.map) {
|
||||
let mut maybe_redraw = self.draw_traffic_signal.borrow_mut();
|
||||
let recalc = maybe_redraw
|
||||
.as_ref()
|
||||
.map(|(_, t)| *t != ctx.sim.time())
|
||||
.unwrap_or(true);
|
||||
if recalc {
|
||||
let (cycle, t) = signal.current_cycle_and_remaining_time(ctx.sim.time());
|
||||
let mut batch = GeomBatch::new();
|
||||
draw_signal_cycle(cycle, Some(t), &mut batch, ctx);
|
||||
*maybe_redraw = Some((g.prerender.upload(batch), ctx.sim.time()));
|
||||
}
|
||||
g.redraw(&maybe_redraw.as_ref().unwrap().0);
|
||||
let mut maybe_redraw = self.draw_traffic_signal.borrow_mut();
|
||||
let recalc = maybe_redraw
|
||||
.as_ref()
|
||||
.map(|(_, t)| *t != ctx.sim.time())
|
||||
.unwrap_or(true);
|
||||
if recalc {
|
||||
let (cycle, t) = signal.current_cycle_and_remaining_time(ctx.sim.time());
|
||||
let mut batch = GeomBatch::new();
|
||||
draw_signal_cycle(cycle, Some(t), &mut batch, ctx);
|
||||
*maybe_redraw = Some((g.prerender.upload(batch), ctx.sim.time()));
|
||||
}
|
||||
g.redraw(&maybe_redraw.as_ref().unwrap().0);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -397,22 +395,12 @@ pub fn draw_signal_diagram(
|
||||
let mut labels = Vec::new();
|
||||
for (idx, cycle) in cycles.iter().enumerate() {
|
||||
if idx == current_cycle && time_left.is_some() {
|
||||
// TODO Hacky way of indicating overtime
|
||||
if time_left.unwrap() < Duration::ZERO {
|
||||
let mut txt = Text::from_line(format!("Cycle {}: ", idx + 1));
|
||||
txt.append(
|
||||
"OVERTIME".to_string(),
|
||||
Some(ctx.cs.get_def("signal overtime", Color::RED)),
|
||||
);
|
||||
labels.push(txt);
|
||||
} else {
|
||||
labels.push(Text::from_line(format!(
|
||||
"Cycle {}: {:.01}s / {}",
|
||||
idx + 1,
|
||||
(cycle.duration - time_left.unwrap()).inner_seconds(),
|
||||
cycle.duration
|
||||
)));
|
||||
}
|
||||
labels.push(Text::from_line(format!(
|
||||
"Cycle {}: {:.01}s / {}",
|
||||
idx + 1,
|
||||
(cycle.duration - time_left.unwrap()).inner_seconds(),
|
||||
cycle.duration
|
||||
)));
|
||||
} else {
|
||||
labels.push(Text::from_line(format!(
|
||||
"Cycle {}: {}",
|
||||
|
@ -11,7 +11,7 @@ fi
|
||||
rm -rfv $OUT
|
||||
mkdir $OUT
|
||||
|
||||
cp color_scheme docs/INSTRUCTIONS.md release/play_abstreet.sh $OUT
|
||||
cp color_scheme.json docs/INSTRUCTIONS.md release/play_abstreet.sh $OUT
|
||||
|
||||
mkdir -p $OUT/data/maps
|
||||
for map in 23rd ballard caphill downtown montlake; do
|
||||
@ -19,7 +19,7 @@ for map in 23rd ballard caphill downtown montlake; do
|
||||
done
|
||||
|
||||
mkdir -p $OUT/data/shapes
|
||||
cp -v data/shapes/popdat $OUT/data/shapes
|
||||
cp -v data/shapes/popdat.bin $OUT/data/shapes
|
||||
|
||||
mkdir $OUT/editor
|
||||
cargo build --release --bin editor
|
||||
|
@ -7,7 +7,7 @@ OUT=abstreet_windows
|
||||
rm -rfv $OUT
|
||||
mkdir $OUT
|
||||
|
||||
cp color_scheme docs/INSTRUCTIONS.md release/play_abstreet.bat $OUT
|
||||
cp color_scheme.json docs/INSTRUCTIONS.md release/play_abstreet.bat $OUT
|
||||
|
||||
mkdir -p $OUT/data/maps
|
||||
for map in 23rd ballard caphill downtown montlake; do
|
||||
@ -15,7 +15,7 @@ for map in 23rd ballard caphill downtown montlake; do
|
||||
done
|
||||
|
||||
mkdir -p $OUT/data/shapes
|
||||
cp -v data/shapes/popdat $OUT/data/shapes
|
||||
cp -v data/shapes/popdat.bin $OUT/data/shapes
|
||||
|
||||
mkdir $OUT/editor
|
||||
cross build --release --target x86_64-pc-windows-gnu --bin editor
|
||||
|
@ -738,8 +738,8 @@ impl DrivingSimState {
|
||||
car.vehicle.owner
|
||||
}
|
||||
|
||||
// This ignores capacity, pedestrians, and traffic signal overtime. So it should yield false
|
||||
// positives (thinks there's gridlock, when there isn't) but never false negatives.
|
||||
// This ignores capacity and pedestrians. So it should yield false positives (thinks there's
|
||||
// gridlock, when there isn't) but never false negatives.
|
||||
pub fn detect_gridlock(&self, map: &Map) -> bool {
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
|
||||
enum Node {
|
||||
|
@ -67,8 +67,8 @@ impl IntersectionSimState {
|
||||
assert!(state.accepted.remove(&Request { agent, turn }));
|
||||
|
||||
// TODO Could be smarter here. For both policies, only wake up agents that would then be
|
||||
// accepted. For now, wake up everyone -- for traffic signals, maybe we were in overtime,
|
||||
// or maybe a Yield and Priority finished and could let another one in.
|
||||
// accepted. For now, wake up everyone -- for traffic signals, maybe a Yield and Priority
|
||||
// finished and could let another one in.
|
||||
|
||||
for req in state.waiting.keys() {
|
||||
// TODO Use update because multiple agents could finish a turn at the same time, before
|
||||
@ -155,18 +155,6 @@ impl IntersectionSimState {
|
||||
.map(|req| req.agent)
|
||||
.collect()
|
||||
}
|
||||
|
||||
pub fn is_in_overtime(&self, time: Duration, id: IntersectionID, map: &Map) -> bool {
|
||||
if let Some(ref signal) = map.maybe_get_traffic_signal(id) {
|
||||
let (cycle, _) = signal.current_cycle_and_remaining_time(time);
|
||||
self.state[&id]
|
||||
.accepted
|
||||
.iter()
|
||||
.any(|req| cycle.get_priority(req.turn) == TurnPriority::Banned)
|
||||
} else {
|
||||
false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl State {
|
||||
@ -237,17 +225,6 @@ impl State {
|
||||
) -> bool {
|
||||
let (cycle, _remaining_cycle_time) = signal.current_cycle_and_remaining_time(time);
|
||||
|
||||
// For now, just maintain safety when agents over-run.
|
||||
for req in &self.accepted {
|
||||
if cycle.get_priority(req.turn) == TurnPriority::Banned {
|
||||
/*println!(
|
||||
"{:?} is still doing {} after the cycle is over",
|
||||
req.agent, req.turn
|
||||
);*/
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// Can't go at all this cycle.
|
||||
if cycle.get_priority(new_req.turn) == TurnPriority::Banned {
|
||||
return false;
|
||||
@ -272,8 +249,7 @@ impl State {
|
||||
// higher-priority vehicle wants to begin.
|
||||
|
||||
// TODO Don't accept the agent if they won't finish the turn in time. If the turn and
|
||||
// target lane were clear, we could calculate the time, but it gets hard. For now, allow
|
||||
// overtime. This is trivial for peds.
|
||||
// target lane were clear, we could calculate the time.
|
||||
|
||||
true
|
||||
}
|
||||
|
@ -56,7 +56,10 @@ pub struct Sim {
|
||||
impl Sim {
|
||||
pub fn new(map: &Map, run_name: String, savestate_every: Option<Duration>) -> Sim {
|
||||
let mut scheduler = Scheduler::new();
|
||||
scheduler.push(CHECK_FOR_GRIDLOCK_FREQUENCY, Command::CheckForGridlock);
|
||||
// TODO Gridlock detection doesn't add value right now.
|
||||
if false {
|
||||
scheduler.push(CHECK_FOR_GRIDLOCK_FREQUENCY, Command::CheckForGridlock);
|
||||
}
|
||||
if let Some(d) = savestate_every {
|
||||
scheduler.push(d, Command::Savestate(d));
|
||||
}
|
||||
@ -780,8 +783,4 @@ impl Sim {
|
||||
pub fn get_accepted_agents(&self, id: IntersectionID) -> HashSet<AgentID> {
|
||||
self.intersections.get_accepted_agents(id)
|
||||
}
|
||||
|
||||
pub fn is_in_overtime(&self, id: IntersectionID, map: &Map) -> bool {
|
||||
self.intersections.is_in_overtime(self.time, id, map)
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user