give peds precedence over cars, and subsequently simplify the wacky crosswalk coloring

This commit is contained in:
Dustin Carlino 2018-12-03 17:16:18 -08:00
parent ac1e12b43a
commit 67ce42e2f6
2 changed files with 30 additions and 29 deletions

View File

@ -167,14 +167,10 @@ pub fn draw_signal_cycle(cycle: &Cycle, id: IntersectionID, g: &mut GfxCtx, ctx:
let priority_color = ctx
.cs
.get("turns protected by traffic signal right now", Color::GREEN);
let yield_color = if ctx.current_selection == Some(ID::Intersection(id)) {
ctx.cs.get("turns allowed with yielding by traffic signal right now, while intersection is selected", Color::grey(0.6).alpha(0.8))
} else {
ctx.cs.get(
"turns allowed with yielding by traffic signal right now",
Color::YELLOW.alpha(0.8),
)
};
let yield_color = ctx.cs.get(
"turns allowed with yielding by traffic signal right now",
Color::rgba(255, 105, 180, 0.8),
);
// TODO Ew... there's got to be a way to prevent drawing the intersection instead
let hide_crosswalk = if ctx.current_selection == Some(ID::Intersection(id)) {
ctx.cs.get("selected", Color::BLUE)
@ -183,16 +179,16 @@ pub fn draw_signal_cycle(cycle: &Cycle, id: IntersectionID, g: &mut GfxCtx, ctx:
};
// First over-draw the crosswalks.
// TODO Should this use the color_for system?
// TODO Should this use the color_for system? Really want to show/hide...
for crosswalk in &ctx.draw_map.get_i(id).crosswalks {
let color = if cycle.priority_turns.contains(&crosswalk.id1)
|| cycle.priority_turns.contains(&crosswalk.id2)
{
priority_color
ctx.cs.get("crosswalk", Color::WHITE)
} else if cycle.yield_turns.contains(&crosswalk.id1)
|| cycle.yield_turns.contains(&crosswalk.id2)
{
yield_color
panic!("Crosswalks shouldn't ever yield")
} else {
hide_crosswalk
};

View File

@ -220,13 +220,15 @@ fn four_way(map: &Map, i: IntersectionID) -> ControlTrafficSignal {
i,
vec![
vec![
(vec![north, south], Turns::StraightAndRight, PROTECTED),
(vec![north, south], Turns::Straight, PROTECTED),
(vec![north, south], Turns::Right, PROTECTED),
(vec![north, south], Turns::Left, YIELD),
(vec![east, west], Turns::Right, YIELD),
(vec![east, west], Turns::Crosswalk, YIELD),
],
vec![
(vec![east, west], Turns::StraightAndRight, PROTECTED),
(vec![east, west], Turns::Straight, PROTECTED),
(vec![east, west], Turns::Right, PROTECTED),
(vec![east, west], Turns::Left, YIELD),
(vec![north, south], Turns::Right, YIELD),
(vec![north, south], Turns::Crosswalk, YIELD),
@ -234,22 +236,24 @@ fn four_way(map: &Map, i: IntersectionID) -> ControlTrafficSignal {
],
);*/
// Four-phase with protected lefts, right turn on red (except for the protected lefts), peds
// yielding to cars
// Four-phase with protected lefts, right turn on red (except for the protected lefts), turning
// cars yield to peds
let cycles = make_cycles(
map,
i,
vec![
vec![
(vec![north, south], Turns::StraightAndRight, PROTECTED),
(vec![north, south], Turns::Straight, PROTECTED),
(vec![north, south], Turns::Right, YIELD),
(vec![east, west], Turns::Right, YIELD),
(vec![east, west], Turns::Crosswalk, YIELD),
(vec![east, west], Turns::Crosswalk, PROTECTED),
],
vec![(vec![north, south], Turns::Left, PROTECTED)],
vec![
(vec![east, west], Turns::StraightAndRight, PROTECTED),
(vec![east, west], Turns::Straight, PROTECTED),
(vec![east, west], Turns::Right, YIELD),
(vec![north, south], Turns::Right, YIELD),
(vec![north, south], Turns::Crosswalk, YIELD),
(vec![north, south], Turns::Crosswalk, PROTECTED),
],
vec![(vec![east, west], Turns::Left, PROTECTED)],
],
@ -274,22 +278,24 @@ fn three_way(map: &Map, i: IntersectionID) -> ControlTrafficSignal {
roads.remove(&south);
let east = roads.into_iter().next().unwrap();
// Two-phase with no protected lefts, right turn on red, peds yielding to cars
// Two-phase with no protected lefts, right turn on red, turning cars yield to peds
let cycles = make_cycles(
map,
i,
vec![
vec![
(vec![north, south], Turns::StraightAndRight, PROTECTED),
(vec![north, south], Turns::Straight, PROTECTED),
(vec![north, south], Turns::Right, YIELD),
(vec![north, south], Turns::Left, YIELD),
(vec![east], Turns::Right, YIELD),
(vec![east], Turns::Crosswalk, YIELD),
(vec![east], Turns::Crosswalk, PROTECTED),
],
vec![
(vec![east], Turns::StraightAndRight, PROTECTED),
(vec![east], Turns::Left, PROTECTED),
(vec![east], Turns::Straight, PROTECTED),
(vec![east], Turns::Right, YIELD),
(vec![east], Turns::Left, YIELD),
(vec![north, south], Turns::Right, YIELD),
(vec![north, south], Turns::Crosswalk, YIELD),
(vec![north, south], Turns::Crosswalk, PROTECTED),
],
],
);
@ -328,11 +334,10 @@ fn make_cycles(
TurnType::Crosswalk => if turns != Turns::Crosswalk {
continue;
},
TurnType::Straight => if turns != Turns::StraightAndRight {
TurnType::Straight => if turns != Turns::Straight {
continue;
},
TurnType::Right => if turns != Turns::StraightAndRight && turns != Turns::Right
{
TurnType::Right => if turns != Turns::Right {
continue;
},
TurnType::Left => if turns != Turns::Left {
@ -357,7 +362,7 @@ fn make_cycles(
#[derive(PartialEq)]
enum Turns {
StraightAndRight,
Straight,
Left,
Right,
// These always cross from one side of a road to the other.