From 44128b3615c51d15a735d9bb09c5a6c8b452d60a Mon Sep 17 00:00:00 2001 From: Dustin Carlino Date: Fri, 22 Nov 2019 12:11:04 -0800 Subject: [PATCH] hanle turn groups a bit more correctly in ControlTrafficSignal... but not yet natively --- data/screenshots/montlake/MANIFEST | 40 +++++++++++++------------- game/src/edit/traffic_signals.rs | 24 +++++++--------- map_model/src/traffic_signals.rs | 46 ++++++++++++++++++++++-------- 3 files changed, 65 insertions(+), 45 deletions(-) diff --git a/data/screenshots/montlake/MANIFEST b/data/screenshots/montlake/MANIFEST index 290e6b05b5..3cac0634dd 100644 --- a/data/screenshots/montlake/MANIFEST +++ b/data/screenshots/montlake/MANIFEST @@ -1,21 +1,21 @@ -32fe6088d0626aea9e2fdfddef6f4da5 ../data/screenshots/pending_montlake/01x01_i19.png -966f567fb9aa9855f4a5b92001cf7cff ../data/screenshots/pending_montlake/02x01_i24.png -8c1227160b6a8244bbdb7c8b504d69aa ../data/screenshots/pending_montlake/03x01_i0.png -abad174a1a96560ae30c2db15ab6c2cb ../data/screenshots/pending_montlake/01x02_i5.png +5aaf318b0c20b3c9da62f6a70d1cbeb2 ../data/screenshots/pending_montlake/01x01_i19.png +76cca3da48a852446b5fd971a11ed1fd ../data/screenshots/pending_montlake/02x01_i24.png +d512261a5c2b6cea1e0c8dfc1a8e0577 ../data/screenshots/pending_montlake/03x01_i0.png +c2265ffe2687702f9e4947a3e913f8e1 ../data/screenshots/pending_montlake/01x02_i5.png 5e0e26848557b3386a8aa1839ad58560 ../data/screenshots/pending_montlake/02x02_i9.png -b8e121a435731b3c105c9bd7052775dc ../data/screenshots/pending_montlake/03x02_i8.png -a128166f4fc8c404c1043032ce426b40 ../data/screenshots/pending_montlake/01x03_i20.png -9162c2429dace890c01b9f1106af7bfe ../data/screenshots/pending_montlake/02x03_i71.png -6b7de9c100ca476a4aa2fe12830dd44a ../data/screenshots/pending_montlake/03x03_i77.png -e62c06cbcc8b82714009fcc3360d5377 ../data/screenshots/pending_montlake/01x04_i4.png -5c633da7efc5540631743241e00a1220 ../data/screenshots/pending_montlake/02x04_i1.png -4a7d05e039eea28b7009d1e78203a3da ../data/screenshots/pending_montlake/03x04_i58.png -a9eb423970fc9ec9029ce839b6d45913 ../data/screenshots/pending_montlake/01x05_i31.png -bdc20ec3835d5ea97dfe876c7e91b409 ../data/screenshots/pending_montlake/02x05_i25.png -765d355df2add3c3264c2c7a11c0c12d ../data/screenshots/pending_montlake/03x05_i65.png -c74934011cc0a3edee1b0715a6c917b1 ../data/screenshots/pending_montlake/01x06_i40.png -c4a802fcc9efb8a26652f3db55a89e62 ../data/screenshots/pending_montlake/02x06_i124.png -0109c9ae20b1a1974d5bd4f8607634b2 ../data/screenshots/pending_montlake/03x06_i2.png -abc2e0ef3a1e2bdcb9be7cd0e8d47c6c ../data/screenshots/pending_montlake/01x07_i26.png -2af4fcf2c1dc5d9c2ca4d32a6a6fa561 ../data/screenshots/pending_montlake/02x07_i85.png -a9a97911411e5408655fb6301c859578 ../data/screenshots/pending_montlake/03x07_i27.png +fd4827621dce3d35e45d002accfb26b8 ../data/screenshots/pending_montlake/03x02_i8.png +e78e9e7c26ae6b1277c4d43edf08ee80 ../data/screenshots/pending_montlake/01x03_i20.png +b50558deb831aa64343363424d4f0db0 ../data/screenshots/pending_montlake/02x03_i71.png +e9a8d6818825bcf3093da6dae2e98a9b ../data/screenshots/pending_montlake/03x03_i77.png +21d07447172f8f34b14344d89396df81 ../data/screenshots/pending_montlake/01x04_i4.png +2a8bdc2cb10094b8b751ea9b32b55067 ../data/screenshots/pending_montlake/02x04_i1.png +65d18cca57480aa1d7586da1e89819c9 ../data/screenshots/pending_montlake/03x04_i58.png +998f630092fae5bf71d63b4ff325fc80 ../data/screenshots/pending_montlake/01x05_i31.png +6e8640054dce9e3a1f7c8687a7cda26c ../data/screenshots/pending_montlake/02x05_i25.png +dbc37b1b2bb8ff585ac06b85d866071b ../data/screenshots/pending_montlake/03x05_i65.png +278e29d55df2b6d1bcc3b8b1beed3331 ../data/screenshots/pending_montlake/01x06_i40.png +a1fd4f7e50c305ba879207d9b1a3eeec ../data/screenshots/pending_montlake/02x06_i124.png +8138848ffc4ac8422f04480e3664bc83 ../data/screenshots/pending_montlake/03x06_i2.png +06c616e6536e6fbae1f7fff6dae84731 ../data/screenshots/pending_montlake/01x07_i26.png +2b8847ad4dbb6a5a2180b96373c4e389 ../data/screenshots/pending_montlake/02x07_i85.png +8e22d53affc74cb8fd1de963c3685b6d ../data/screenshots/pending_montlake/03x07_i27.png diff --git a/game/src/edit/traffic_signals.rs b/game/src/edit/traffic_signals.rs index 0650166b60..7d1b9cc8b4 100644 --- a/game/src/edit/traffic_signals.rs +++ b/game/src/edit/traffic_signals.rs @@ -90,24 +90,22 @@ impl State for TrafficSignalEditor { // Just one key to toggle between the 3 states let next_priority = match phase.get_priority_group(id, &signal_copy) { TurnPriority::Banned => { - if id.crosswalk.is_some() { - if phase.could_be_protected_group(id, &signal_copy, &ui.primary.map) { - Some(TurnPriority::Protected) - } else { - None - } + if phase.could_be_protected_group(id, &signal_copy, &ui.primary.map) { + Some(TurnPriority::Protected) + } else if id.crosswalk.is_some() { + None } else { Some(TurnPriority::Yield) } } - TurnPriority::Yield => { - if phase.could_be_protected_group(id, &signal_copy, &ui.primary.map) { - Some(TurnPriority::Protected) - } else { + TurnPriority::Yield => Some(TurnPriority::Banned), + TurnPriority::Protected => { + if id.crosswalk.is_some() { Some(TurnPriority::Banned) + } else { + Some(TurnPriority::Yield) } } - TurnPriority::Protected => Some(TurnPriority::Banned), }; if let Some(pri) = next_priority { if ctx.input.contextual_action( @@ -183,7 +181,7 @@ impl State for TrafficSignalEditor { let mut phase = Phase::new(); for t in ui.primary.map.get_turns_in_intersection(self.diagram.i) { if t.turn_type == TurnType::SharedSidewalkCorner { - phase.edit_turn(t, TurnPriority::Protected); + phase.protected_turns.insert(t.id); } } signal.phases.insert(current_phase + 1, phase); @@ -193,7 +191,7 @@ impl State for TrafficSignalEditor { let mut phase = Phase::new(); for t in ui.primary.map.get_turns_in_intersection(self.diagram.i) { if t.between_sidewalks() { - phase.edit_turn(t, TurnPriority::Protected); + phase.protected_turns.insert(t.id); } } signal.phases.insert(current_phase + 1, phase); diff --git a/map_model/src/traffic_signals.rs b/map_model/src/traffic_signals.rs index 3abe8c031d..5f88eee407 100644 --- a/map_model/src/traffic_signals.rs +++ b/map_model/src/traffic_signals.rs @@ -520,7 +520,7 @@ impl Phase { } } - pub fn could_be_protected_turn(&self, t1: TurnID, map: &Map) -> bool { + fn could_be_protected_turn(&self, t1: TurnID, map: &Map) -> bool { let turn1 = map.get_t(t1); for t2 in &self.protected_turns { if t1 == *t2 || turn1.conflicts_with(map.get_t(*t2)) { @@ -540,7 +540,7 @@ impl Phase { } } - pub fn edit_turn(&mut self, t: &Turn, pri: TurnPriority) { + fn edit_turn(&mut self, t: &Turn, pri: TurnPriority) { let mut ids = vec![t.id]; if t.turn_type == TurnType::Crosswalk { ids.extend(t.other_crosswalk_ids.clone()); @@ -564,13 +564,14 @@ impl Phase { let mut protected = Vec::new(); let mut permitted = Vec::new(); for group in parent.turn_groups.values() { - // TODO All or nothing based on the first member. Temporary measure before switching - // ControlTrafficSignal to natively understand TurnGroup. - let t = group.members[0]; - if self.protected_turns.contains(&t) { - protected.push(group); - } else if self.yield_turns.contains(&t) { - permitted.push(group); + match self.get_priority_group(group.id, parent) { + TurnPriority::Protected => { + protected.push(group); + } + TurnPriority::Yield => { + permitted.push(group); + } + TurnPriority::Banned => {} } } (protected, permitted) @@ -581,7 +582,22 @@ impl Phase { g: TurnGroupID, parent: &ControlTrafficSignal, ) -> TurnPriority { - self.get_priority(parent.turn_groups[&g].members[0]) + // Any, not all. + if parent.turn_groups[&g] + .members + .iter() + .any(|t| self.get_priority(*t) == TurnPriority::Protected) + { + return TurnPriority::Protected; + } + if parent.turn_groups[&g] + .members + .iter() + .any(|t| self.get_priority(*t) == TurnPriority::Yield) + { + return TurnPriority::Yield; + } + TurnPriority::Banned } pub fn could_be_protected_group( @@ -590,7 +606,11 @@ impl Phase { parent: &ControlTrafficSignal, map: &Map, ) -> bool { - self.could_be_protected_turn(parent.turn_groups[&g].members[0], map) + // All, not any? + parent.turn_groups[&g] + .members + .iter() + .all(|t| self.could_be_protected_turn(*t, map)) } pub fn edit_group( @@ -600,7 +620,9 @@ impl Phase { parent: &ControlTrafficSignal, map: &Map, ) { - self.edit_turn(map.get_t(parent.turn_groups[&g].members[0]), pri); + for t in &parent.turn_groups[&g].members { + self.edit_turn(map.get_t(*t), pri); + } } }