From d6699b2247ff6e5ffb4c277600a91206d49c2bea Mon Sep 17 00:00:00 2001 From: Elesbaan70 <95266227+Elesbaan70@users.noreply.github.com> Date: Thu, 5 May 2022 10:26:22 -0500 Subject: [PATCH 01/21] Hook API definition --- .../Impl/JunctionRestrictionsManager.cs | 12 ++------ .../Hook/IJunctionRestrictionsHook.cs | 28 +++++++++++++++++++ .../Manager/IJunctionRestrictionsManager.cs | 14 ++++++++++ TLM/TMPE.API/TMPE.API.csproj | 2 ++ .../Traffic/Enums/JunctionRestrictionFlags.cs | 10 +++++++ 5 files changed, 57 insertions(+), 9 deletions(-) create mode 100644 TLM/TMPE.API/Hook/IJunctionRestrictionsHook.cs create mode 100644 TLM/TMPE.API/Traffic/Enums/JunctionRestrictionFlags.cs diff --git a/TLM/TLM/Manager/Impl/JunctionRestrictionsManager.cs b/TLM/TLM/Manager/Impl/JunctionRestrictionsManager.cs index cd2ca801a..03e6b07e9 100644 --- a/TLM/TLM/Manager/Impl/JunctionRestrictionsManager.cs +++ b/TLM/TLM/Manager/Impl/JunctionRestrictionsManager.cs @@ -17,6 +17,7 @@ namespace TrafficManager.Manager.Impl { using TrafficManager.Util; using TrafficManager.Util.Extensions; using TrafficManager.Lifecycle; + using TrafficManager.API.Traffic.Enums; public class JunctionRestrictionsManager : AbstractGeometryObservingManager, @@ -38,6 +39,8 @@ private JunctionRestrictionsManager() { invalidSegmentRestrictions = new SegmentJunctionRestrictions[NetManager.MAX_SEGMENT_COUNT]; } + public event Action FlagsChanged; + private void AddInvalidSegmentJunctionRestrictions(ushort segmentId, bool startNode, ref JunctionRestrictions restrictions) { @@ -1318,15 +1321,6 @@ public bool LoadData(List data) { return ret; } - private enum JunctionRestrictionFlags { - AllowUTurn = 1 << 0, - AllowNearTurnOnRed = 1 << 1, - AllowFarTurnOnRed = 1 << 2, - AllowForwardLaneChange = 1 << 3, - AllowEnterWhenBlocked = 1 << 4, - AllowPedestrianCrossing = 1 << 5, - } - private struct SegmentJunctionRestrictions { public JunctionRestrictions startNodeRestrictions; public JunctionRestrictions endNodeRestrictions; diff --git a/TLM/TMPE.API/Hook/IJunctionRestrictionsHook.cs b/TLM/TMPE.API/Hook/IJunctionRestrictionsHook.cs new file mode 100644 index 000000000..ff8689508 --- /dev/null +++ b/TLM/TMPE.API/Hook/IJunctionRestrictionsHook.cs @@ -0,0 +1,28 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using TrafficManager.API.Traffic.Enums; + +namespace TrafficManager.API.Hook { + public interface IJunctionRestrictionsHook { + + event FlagsHookHandler GetDefaults; + + event FlagsHookHandler GetConfigurable; + + public class FlagsHookArgs { + + public JunctionRestrictionFlags Mask { get; private set; } + + public JunctionRestrictionFlags Result { get; set; } + + public FlagsHookArgs(JunctionRestrictionFlags mask, JunctionRestrictionFlags result) { + Mask = mask; + Result = result; + } + } + + public delegate void FlagsHookHandler(FlagsHookArgs args); + } +} diff --git a/TLM/TMPE.API/Manager/IJunctionRestrictionsManager.cs b/TLM/TMPE.API/Manager/IJunctionRestrictionsManager.cs index 5b4865d18..c05562c29 100644 --- a/TLM/TMPE.API/Manager/IJunctionRestrictionsManager.cs +++ b/TLM/TMPE.API/Manager/IJunctionRestrictionsManager.cs @@ -1,5 +1,7 @@ namespace TrafficManager.API.Manager { using CSUtil.Commons; + using System; + using TrafficManager.API.Traffic.Enums; public interface IJunctionRestrictionsManager { #region IsConfigurable @@ -574,5 +576,17 @@ bool GetDefaultPedestrianCrossingAllowed(ushort segmentId, /// Updates the default values for all junction restrictions and segments. /// void UpdateAllDefaults(); + + event Action FlagsChanged; + + public class FlagsChangedEventArgs { + + public JunctionRestrictionFlags Flags { get; private set; } + + public FlagsChangedEventArgs(JunctionRestrictionFlags flags) { + Flags = flags; + } + } + } } \ No newline at end of file diff --git a/TLM/TMPE.API/TMPE.API.csproj b/TLM/TMPE.API/TMPE.API.csproj index 6744b6214..6f4639898 100644 --- a/TLM/TMPE.API/TMPE.API.csproj +++ b/TLM/TMPE.API/TMPE.API.csproj @@ -76,6 +76,7 @@ Properties\SharedAssemblyInfo.cs + @@ -144,6 +145,7 @@ + diff --git a/TLM/TMPE.API/Traffic/Enums/JunctionRestrictionFlags.cs b/TLM/TMPE.API/Traffic/Enums/JunctionRestrictionFlags.cs new file mode 100644 index 000000000..5e3b7bd38 --- /dev/null +++ b/TLM/TMPE.API/Traffic/Enums/JunctionRestrictionFlags.cs @@ -0,0 +1,10 @@ +namespace TrafficManager.API.Traffic.Enums { + public enum JunctionRestrictionFlags { + AllowUTurn = 1 << 0, + AllowNearTurnOnRed = 1 << 1, + AllowFarTurnOnRed = 1 << 2, + AllowForwardLaneChange = 1 << 3, + AllowEnterWhenBlocked = 1 << 4, + AllowPedestrianCrossing = 1 << 5, + } +} From 918ea2d93006d73aa59a3cbb36f80060095699e9 Mon Sep 17 00:00:00 2001 From: Elesbaan70 <95266227+Elesbaan70@users.noreply.github.com> Date: Fri, 6 May 2022 00:22:46 -0500 Subject: [PATCH 02/21] Fill in missing pieces --- .../Hook/IJunctionRestrictionsHook.cs | 43 ++++++++++++++++--- 1 file changed, 37 insertions(+), 6 deletions(-) diff --git a/TLM/TMPE.API/Hook/IJunctionRestrictionsHook.cs b/TLM/TMPE.API/Hook/IJunctionRestrictionsHook.cs index ff8689508..211fa02da 100644 --- a/TLM/TMPE.API/Hook/IJunctionRestrictionsHook.cs +++ b/TLM/TMPE.API/Hook/IJunctionRestrictionsHook.cs @@ -7,22 +7,53 @@ namespace TrafficManager.API.Hook { public interface IJunctionRestrictionsHook { - event FlagsHookHandler GetDefaults; - - event FlagsHookHandler GetConfigurable; + /// + /// An event that allows a handler to modify the results of a GetDefaultTrafficRule method. + /// + event Action GetDefaults; + + /// + /// An event that allows a handler to modify the results of an IsTrafficRuleConfigurable method. + /// + event Action GetConfigurable; + + /// + /// Invalidates the specified flags so that they will be recalculated. + /// Recalculation is not guaranteed to happen immediately, but is guaranteed to happen + /// before their next use. + /// + /// + public void InvalidateFlags(JunctionRestrictionFlags flags); public class FlagsHookArgs { + /// + /// Identifies the segment for which flag data is being returned. + /// + public ushort SegmentId { get; private set; } + + /// + /// Identifies the node on the segment for which flag data is being returned. + /// + public bool StartNode { get; private set; } + + /// + /// Identifies which flags are being returned. Unnecessary computation may be avoided + /// by examining this mask to see which flags are being requested. + /// public JunctionRestrictionFlags Mask { get; private set; } + /// + /// The flag return values. Changes to this property alter the outcome of the underlying operation. + /// public JunctionRestrictionFlags Result { get; set; } - public FlagsHookArgs(JunctionRestrictionFlags mask, JunctionRestrictionFlags result) { + internal FlagsHookArgs(ushort segmentId, bool startNode, JunctionRestrictionFlags mask, JunctionRestrictionFlags result) { + SegmentId = segmentId; + StartNode = startNode; Mask = mask; Result = result; } } - - public delegate void FlagsHookHandler(FlagsHookArgs args); } } From 7eaf0e406d1fc322c4e15fbf7d87f065f7417602 Mon Sep 17 00:00:00 2001 From: Elesbaan70 <95266227+Elesbaan70@users.noreply.github.com> Date: Thu, 26 May 2022 07:46:15 -0500 Subject: [PATCH 03/21] No FlagsChanged event until all the redundant mess has been eliminated --- TLM/TLM/Manager/Impl/JunctionRestrictionsManager.cs | 2 -- TLM/TMPE.API/Manager/IJunctionRestrictionsManager.cs | 11 ----------- 2 files changed, 13 deletions(-) diff --git a/TLM/TLM/Manager/Impl/JunctionRestrictionsManager.cs b/TLM/TLM/Manager/Impl/JunctionRestrictionsManager.cs index 03e6b07e9..be85b81a8 100644 --- a/TLM/TLM/Manager/Impl/JunctionRestrictionsManager.cs +++ b/TLM/TLM/Manager/Impl/JunctionRestrictionsManager.cs @@ -39,8 +39,6 @@ private JunctionRestrictionsManager() { invalidSegmentRestrictions = new SegmentJunctionRestrictions[NetManager.MAX_SEGMENT_COUNT]; } - public event Action FlagsChanged; - private void AddInvalidSegmentJunctionRestrictions(ushort segmentId, bool startNode, ref JunctionRestrictions restrictions) { diff --git a/TLM/TMPE.API/Manager/IJunctionRestrictionsManager.cs b/TLM/TMPE.API/Manager/IJunctionRestrictionsManager.cs index c05562c29..4bc785c20 100644 --- a/TLM/TMPE.API/Manager/IJunctionRestrictionsManager.cs +++ b/TLM/TMPE.API/Manager/IJunctionRestrictionsManager.cs @@ -577,16 +577,5 @@ bool GetDefaultPedestrianCrossingAllowed(ushort segmentId, /// void UpdateAllDefaults(); - event Action FlagsChanged; - - public class FlagsChangedEventArgs { - - public JunctionRestrictionFlags Flags { get; private set; } - - public FlagsChangedEventArgs(JunctionRestrictionFlags flags) { - Flags = flags; - } - } - } } \ No newline at end of file From 5461b9ddf4f6f134384900f54fd1cc672baa4a59 Mon Sep 17 00:00:00 2001 From: Elesbaan70 <95266227+Elesbaan70@users.noreply.github.com> Date: Fri, 27 May 2022 10:33:12 -0500 Subject: [PATCH 04/21] rename "invalid" restrictions to "orphaned" --- .../Impl/JunctionRestrictionsManager.cs | 26 +++++++++---------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/TLM/TLM/Manager/Impl/JunctionRestrictionsManager.cs b/TLM/TLM/Manager/Impl/JunctionRestrictionsManager.cs index be85b81a8..86d7e8ae3 100644 --- a/TLM/TLM/Manager/Impl/JunctionRestrictionsManager.cs +++ b/TLM/TLM/Manager/Impl/JunctionRestrictionsManager.cs @@ -27,7 +27,7 @@ public class JunctionRestrictionsManager public static JunctionRestrictionsManager Instance { get; } = new JunctionRestrictionsManager(); - private readonly SegmentJunctionRestrictions[] invalidSegmentRestrictions; + private readonly SegmentJunctionRestrictions[] orphanedRestrictions; /// /// Holds junction restrictions for each segment end @@ -36,16 +36,16 @@ public class JunctionRestrictionsManager private JunctionRestrictionsManager() { segmentRestrictions = new SegmentJunctionRestrictions[NetManager.MAX_SEGMENT_COUNT]; - invalidSegmentRestrictions = new SegmentJunctionRestrictions[NetManager.MAX_SEGMENT_COUNT]; + orphanedRestrictions = new SegmentJunctionRestrictions[NetManager.MAX_SEGMENT_COUNT]; } - private void AddInvalidSegmentJunctionRestrictions(ushort segmentId, + private void AddOrphanedSegmentJunctionRestrictions(ushort segmentId, bool startNode, - ref JunctionRestrictions restrictions) { + JunctionRestrictions restrictions) { if (startNode) { - invalidSegmentRestrictions[segmentId].startNodeRestrictions = restrictions; + orphanedRestrictions[segmentId].startNodeRestrictions = restrictions; } else { - invalidSegmentRestrictions[segmentId].endNodeRestrictions = restrictions; + orphanedRestrictions[segmentId].endNodeRestrictions = restrictions; } } @@ -57,11 +57,11 @@ protected override void HandleSegmentEndReplacement(SegmentEndReplacement replac JunctionRestrictions restrictions; if (oldSegmentEndId.StartNode) { - restrictions = invalidSegmentRestrictions[oldSegmentEndId.SegmentId].startNodeRestrictions; - invalidSegmentRestrictions[oldSegmentEndId.SegmentId].startNodeRestrictions.Reset(); + restrictions = orphanedRestrictions[oldSegmentEndId.SegmentId].startNodeRestrictions; + orphanedRestrictions[oldSegmentEndId.SegmentId].startNodeRestrictions.Reset(); } else { - restrictions = invalidSegmentRestrictions[oldSegmentEndId.SegmentId].endNodeRestrictions; - invalidSegmentRestrictions[oldSegmentEndId.SegmentId].endNodeRestrictions.Reset(); + restrictions = orphanedRestrictions[oldSegmentEndId.SegmentId].endNodeRestrictions; + orphanedRestrictions[oldSegmentEndId.SegmentId].endNodeRestrictions.Reset(); } UpdateDefaults( @@ -173,7 +173,7 @@ private void HandleInvalidSegment(ref ExtSegment seg, bool startNode) { : segmentRestrictions[seg.segmentId].endNodeRestrictions; if (!restrictions.IsDefault()) { - AddInvalidSegmentJunctionRestrictions(seg.segmentId, startNode, ref restrictions); + AddOrphanedSegmentJunctionRestrictions(seg.segmentId, startNode, restrictions); } segmentRestrictions[seg.segmentId].Reset(startNode, true); @@ -1035,8 +1035,8 @@ public override void OnLevelUnloading() { segmentRestrictions[i].Reset(startNode: null, resetDefaults: true); } - for (int i = 0; i < invalidSegmentRestrictions.Length; ++i) { - invalidSegmentRestrictions[i].Reset(startNode: null, resetDefaults: true); + for (int i = 0; i < orphanedRestrictions.Length; ++i) { + orphanedRestrictions[i].Reset(startNode: null, resetDefaults: true); } } From 1f91a918d0f1d337d44f8140ce7b140374c0b14f Mon Sep 17 00:00:00 2001 From: Elesbaan70 <95266227+Elesbaan70@users.noreply.github.com> Date: Fri, 27 May 2022 13:22:18 -0500 Subject: [PATCH 05/21] Rename antipatterned SegmentEndId class --- .../Geometry/Impl/{SegmentEndId.cs => SegmentEndIdApi.cs} | 7 ++++--- TLM/TLM/Manager/Impl/ExtNodeManager.cs | 4 ++-- TLM/TLM/TLM.csproj | 2 +- TLM/TLM/Traffic/Impl/SegmentEnd.cs | 2 +- TLM/TLM/TrafficLight/Impl/CustomSegmentLights.cs | 2 +- TLM/TLM/TrafficLight/Impl/TimedTrafficLights.cs | 2 +- 6 files changed, 10 insertions(+), 9 deletions(-) rename TLM/TLM/Geometry/Impl/{SegmentEndId.cs => SegmentEndIdApi.cs} (87%) diff --git a/TLM/TLM/Geometry/Impl/SegmentEndId.cs b/TLM/TLM/Geometry/Impl/SegmentEndIdApi.cs similarity index 87% rename from TLM/TLM/Geometry/Impl/SegmentEndId.cs rename to TLM/TLM/Geometry/Impl/SegmentEndIdApi.cs index e30fa811b..f191729db 100644 --- a/TLM/TLM/Geometry/Impl/SegmentEndId.cs +++ b/TLM/TLM/Geometry/Impl/SegmentEndIdApi.cs @@ -1,14 +1,15 @@ namespace TrafficManager.Geometry.Impl { + using System; using TrafficManager.API.Traffic; using TrafficManager.Util.Extensions; - public class SegmentEndId : ISegmentEndId { - public SegmentEndId(ushort segmentId, ushort nodeId) { + public class SegmentEndIdApi : ISegmentEndId { + public SegmentEndIdApi(ushort segmentId, ushort nodeId) { SegmentId = segmentId; StartNode = segmentId.ToSegment().IsStartNode(nodeId); } - public SegmentEndId(ushort segmentId, bool startNode) { + public SegmentEndIdApi(ushort segmentId, bool startNode) { SegmentId = segmentId; StartNode = startNode; } diff --git a/TLM/TLM/Manager/Impl/ExtNodeManager.cs b/TLM/TLM/Manager/Impl/ExtNodeManager.cs index 4a935c1db..11e645140 100644 --- a/TLM/TLM/Manager/Impl/ExtNodeManager.cs +++ b/TLM/TLM/Manager/Impl/ExtNodeManager.cs @@ -90,7 +90,7 @@ public void AddSegment(ushort nodeId, ushort segmentId) { { var replacement = new SegmentEndReplacement { oldSegmentEndId = ExtNodes[nodeId].removedSegmentEndId, - newSegmentEndId = new SegmentEndId(segmentId, nodeId), + newSegmentEndId = new SegmentEndIdApi(segmentId, nodeId), }; ExtNodes[nodeId].removedSegmentEndId = null; @@ -100,7 +100,7 @@ public void AddSegment(ushort nodeId, ushort segmentId) { public void RemoveSegment(ushort nodeId, ushort segmentId) { if (ExtNodes[nodeId].segmentIds.Remove(segmentId)) { - ExtNodes[nodeId].removedSegmentEndId = new SegmentEndId(segmentId, nodeId); + ExtNodes[nodeId].removedSegmentEndId = new SegmentEndIdApi(segmentId, nodeId); } } diff --git a/TLM/TLM/TLM.csproj b/TLM/TLM/TLM.csproj index 9512a3df0..788cd6d5a 100644 --- a/TLM/TLM/TLM.csproj +++ b/TLM/TLM/TLM.csproj @@ -135,7 +135,7 @@ - + diff --git a/TLM/TLM/Traffic/Impl/SegmentEnd.cs b/TLM/TLM/Traffic/Impl/SegmentEnd.cs index 83c9c7522..8e396eb71 100644 --- a/TLM/TLM/Traffic/Impl/SegmentEnd.cs +++ b/TLM/TLM/Traffic/Impl/SegmentEnd.cs @@ -20,7 +20,7 @@ namespace TrafficManager.Traffic.Impl { /// (having custom traffic lights or priority signs). /// [Obsolete("should be removed when implementing issue #240")] - public class SegmentEnd : SegmentEndId, ISegmentEnd { + public class SegmentEnd : SegmentEndIdApi, ISegmentEnd { public SegmentEnd(ushort segmentId, bool startNode) : base(segmentId, startNode) { Update(); diff --git a/TLM/TLM/TrafficLight/Impl/CustomSegmentLights.cs b/TLM/TLM/TrafficLight/Impl/CustomSegmentLights.cs index 33fa2fb21..88f5ae68f 100644 --- a/TLM/TLM/TrafficLight/Impl/CustomSegmentLights.cs +++ b/TLM/TLM/TrafficLight/Impl/CustomSegmentLights.cs @@ -19,7 +19,7 @@ namespace TrafficManager.TrafficLight.Impl { /// Represents the set of custom traffic lights located at a node /// public class CustomSegmentLights - : SegmentEndId + : SegmentEndIdApi { // private static readonly ExtVehicleType[] SINGLE_LANE_VEHICLETYPES // = new ExtVehicleType[] { ExtVehicleType.Tram, ExtVehicleType.Service, diff --git a/TLM/TLM/TrafficLight/Impl/TimedTrafficLights.cs b/TLM/TLM/TrafficLight/Impl/TimedTrafficLights.cs index 5b676d874..d5ebd62b9 100644 --- a/TLM/TLM/TrafficLight/Impl/TimedTrafficLights.cs +++ b/TLM/TLM/TrafficLight/Impl/TimedTrafficLights.cs @@ -1297,7 +1297,7 @@ private void UpdateSegmentEnds(ref NetNode node) { } var startNode = segmentId.ToSegment().IsStartNode(NodeId); - ISegmentEndId endId = new SegmentEndId(segmentId, startNode); + ISegmentEndId endId = new SegmentEndIdApi(segmentId, startNode); if (segmentEndIds.Contains(endId)) { Log._DebugIf( From 5fad9ae4d3a5e475bd08272014bec58d2736cf64 Mon Sep 17 00:00:00 2001 From: Elesbaan70 <95266227+Elesbaan70@users.noreply.github.com> Date: Fri, 27 May 2022 15:09:00 -0500 Subject: [PATCH 06/21] SegmentEndId --- TLM/TLM/Geometry/Impl/SegmentEndIdApi.cs | 1 + .../Impl/JunctionRestrictionsManager.cs | 238 +++++++++--------- TLM/TLM/Network/Data/SegmentEndId.cs | 31 +++ TLM/TLM/TLM.csproj | 2 + TLM/TLM/Util/Extensions/NetNodeExtensions.cs | 2 + .../Util/Extensions/SegmentEndIdExtensions.cs | 53 ++++ 6 files changed, 210 insertions(+), 117 deletions(-) create mode 100644 TLM/TLM/Network/Data/SegmentEndId.cs create mode 100644 TLM/TLM/Util/Extensions/SegmentEndIdExtensions.cs diff --git a/TLM/TLM/Geometry/Impl/SegmentEndIdApi.cs b/TLM/TLM/Geometry/Impl/SegmentEndIdApi.cs index f191729db..e04b3ce93 100644 --- a/TLM/TLM/Geometry/Impl/SegmentEndIdApi.cs +++ b/TLM/TLM/Geometry/Impl/SegmentEndIdApi.cs @@ -3,6 +3,7 @@ namespace TrafficManager.Geometry.Impl { using TrafficManager.API.Traffic; using TrafficManager.Util.Extensions; + [Obsolete("New code should use TrafficManager.Network.Data.SegmentId unless it needs to implement ISegmentEndId. ISegmentEndId should be deprecated in the future, and should be avoided in new APIs.")] public class SegmentEndIdApi : ISegmentEndId { public SegmentEndIdApi(ushort segmentId, ushort nodeId) { SegmentId = segmentId; diff --git a/TLM/TLM/Manager/Impl/JunctionRestrictionsManager.cs b/TLM/TLM/Manager/Impl/JunctionRestrictionsManager.cs index 86d7e8ae3..e00c8d263 100644 --- a/TLM/TLM/Manager/Impl/JunctionRestrictionsManager.cs +++ b/TLM/TLM/Manager/Impl/JunctionRestrictionsManager.cs @@ -9,6 +9,7 @@ namespace TrafficManager.Manager.Impl { using TrafficManager.API.Traffic.Data; using TrafficManager.API.Traffic; using TrafficManager.Geometry; + using TrafficManager.Network.Data; using TrafficManager.State.ConfigData; using TrafficManager.State; using TrafficManager.Traffic; @@ -39,6 +40,12 @@ private JunctionRestrictionsManager() { orphanedRestrictions = new SegmentJunctionRestrictions[NetManager.MAX_SEGMENT_COUNT]; } + private ref JunctionRestrictions GetJunctionRestrictions(SegmentEndId segmentEndId) { + return ref (segmentEndId.StartNode + ? ref segmentRestrictions[segmentEndId].startNodeRestrictions + : ref segmentRestrictions[segmentEndId].endNodeRestrictions); + } + private void AddOrphanedSegmentJunctionRestrictions(ushort segmentId, bool startNode, JunctionRestrictions restrictions) { @@ -58,10 +65,10 @@ protected override void HandleSegmentEndReplacement(SegmentEndReplacement replac JunctionRestrictions restrictions; if (oldSegmentEndId.StartNode) { restrictions = orphanedRestrictions[oldSegmentEndId.SegmentId].startNodeRestrictions; - orphanedRestrictions[oldSegmentEndId.SegmentId].startNodeRestrictions.Reset(); + orphanedRestrictions[oldSegmentEndId.SegmentId].startNodeRestrictions.Reset(oldSegmentEndId.FromApi()); } else { restrictions = orphanedRestrictions[oldSegmentEndId.SegmentId].endNodeRestrictions; - orphanedRestrictions[oldSegmentEndId.SegmentId].endNodeRestrictions.Reset(); + orphanedRestrictions[oldSegmentEndId.SegmentId].endNodeRestrictions.Reset(oldSegmentEndId.FromApi()); } UpdateDefaults( @@ -74,13 +81,13 @@ ref segEndMan.ExtSegmentEnds[segEndMan.GetIndex(newSegmentEndId.SegmentId, newSe $"Segment replacement detected: {oldSegmentEndId.SegmentId} -> {newSegmentEndId.SegmentId} " + $"@ {newSegmentEndId.StartNode}"); - SetSegmentJunctionRestrictions(newSegmentEndId.SegmentId, newSegmentEndId.StartNode, restrictions); + SetSegmentJunctionRestrictions(newSegmentEndId.FromApi(), restrictions); } public override void OnLevelLoading() { base.OnLevelLoading(); - for (uint i = 0; i < NetManager.MAX_SEGMENT_COUNT; ++i) { - ExtSegment seg = Constants.ManagerFactory.ExtSegmentManager.ExtSegments[i]; + for (ushort segmentId = 0; segmentId < NetManager.MAX_SEGMENT_COUNT; ++segmentId) { + ExtSegment seg = Constants.ManagerFactory.ExtSegmentManager.ExtSegments[segmentId]; if (seg.valid) { HandleValidSegment(ref seg); } @@ -91,12 +98,12 @@ protected override void InternalPrintDebugInfo() { base.InternalPrintDebugInfo(); Log._Debug("Junction restrictions:"); - for (int i = 0; i < segmentRestrictions.Length; ++i) { - if (segmentRestrictions[i].IsDefault()) { + for (ushort segmentId = 0; segmentId < segmentRestrictions.Length; ++segmentId) { + if (segmentRestrictions[segmentId].IsDefault(segmentId)) { continue; } - Log._Debug($"Segment {i}: {segmentRestrictions[i]}"); + Log._Debug($"Segment {segmentId}: {segmentRestrictions[segmentId]}"); } } @@ -111,20 +118,15 @@ private bool MayHaveJunctionRestrictions(ushort nodeId) { } public bool HasJunctionRestrictions(ushort nodeId) { - ref NetNode netNode = ref nodeId.ToNode(); - if (!netNode.IsValid()) { + if (!nodeId.ToNode().IsValid()) { return false; } for (int i = 0; i < 8; ++i) { - ushort segmentId = netNode.GetSegment(i); - if (segmentId != 0) { - bool startNode = segmentId.ToSegment().m_startNode == nodeId; - bool isDefault = startNode - ? segmentRestrictions[segmentId].startNodeRestrictions.IsDefault() - : segmentRestrictions[segmentId].endNodeRestrictions.IsDefault(); - - if (!isDefault) { + var segmentEndId = nodeId.GetSegmentEnd(i); + if (segmentEndId != default) { + + if (!GetJunctionRestrictions(segmentEndId).IsDefault(segmentEndId)) { return true; } } @@ -136,15 +138,10 @@ public bool HasJunctionRestrictions(ushort nodeId) { private void RemoveJunctionRestrictions(ushort nodeId) { Log._Debug($"JunctionRestrictionsManager.RemoveJunctionRestrictions({nodeId}) called."); - ref NetNode node = ref nodeId.ToNode(); for (int i = 0; i < 8; ++i) { - ushort segmentId = node.GetSegment(i); - if (segmentId != 0) { - if (segmentId.ToSegment().m_startNode == nodeId) { - segmentRestrictions[segmentId].startNodeRestrictions.Reset(false); - } else { - segmentRestrictions[segmentId].endNodeRestrictions.Reset(false); - } + var segmentEndId = nodeId.GetSegmentEnd(i); + if (segmentEndId != default) { + GetJunctionRestrictions(segmentEndId).Reset(segmentEndId, false); } } } @@ -168,15 +165,18 @@ protected override void HandleInvalidSegment(ref ExtSegment seg) { } private void HandleInvalidSegment(ref ExtSegment seg, bool startNode) { + + var segmentEndId = seg.segmentId.AtNode(startNode); + JunctionRestrictions restrictions = startNode ? segmentRestrictions[seg.segmentId].startNodeRestrictions : segmentRestrictions[seg.segmentId].endNodeRestrictions; - if (!restrictions.IsDefault()) { + if (!restrictions.IsDefault(segmentEndId)) { AddOrphanedSegmentJunctionRestrictions(seg.segmentId, startNode, restrictions); } - segmentRestrictions[seg.segmentId].Reset(startNode, true); + segmentRestrictions[seg.segmentId].Reset(segmentEndId); } protected override void HandleValidSegment(ref ExtSegment seg) { @@ -219,61 +219,64 @@ ref segEndMan.ExtSegmentEnds[segEndMan.GetIndex(segmentId, false)], private void UpdateDefaults(ref ExtSegmentEnd segEnd, ref JunctionRestrictions restrictions, ref NetNode node) { + + var segmentEndId = segEnd.GetSegmentEndId(); + if (!IsUturnAllowedConfigurable(segEnd.segmentId, segEnd.startNode, ref node)) { - restrictions.ClearValue(JunctionRestrictionFlags.AllowUTurn); + restrictions.ClearValue(segmentEndId, JunctionRestrictionFlags.AllowUTurn); } if (!IsNearTurnOnRedAllowedConfigurable(segEnd.segmentId, segEnd.startNode, ref node)) { - restrictions.ClearValue(JunctionRestrictionFlags.AllowNearTurnOnRed); + restrictions.ClearValue(segmentEndId, JunctionRestrictionFlags.AllowNearTurnOnRed); } if (!IsFarTurnOnRedAllowedConfigurable(segEnd.segmentId, segEnd.startNode, ref node)) { - restrictions.ClearValue(JunctionRestrictionFlags.AllowFarTurnOnRed); + restrictions.ClearValue(segmentEndId, JunctionRestrictionFlags.AllowFarTurnOnRed); } if (!IsLaneChangingAllowedWhenGoingStraightConfigurable( segEnd.segmentId, segEnd.startNode, ref node)) { - restrictions.ClearValue(JunctionRestrictionFlags.AllowForwardLaneChange); + restrictions.ClearValue(segmentEndId, JunctionRestrictionFlags.AllowForwardLaneChange); } if (!IsEnteringBlockedJunctionAllowedConfigurable( segEnd.segmentId, segEnd.startNode, ref node)) { - restrictions.ClearValue(JunctionRestrictionFlags.AllowEnterWhenBlocked); + restrictions.ClearValue(segmentEndId, JunctionRestrictionFlags.AllowEnterWhenBlocked); } if (!IsPedestrianCrossingAllowedConfigurable( segEnd.segmentId, segEnd.startNode, ref node)) { - restrictions.ClearValue(JunctionRestrictionFlags.AllowPedestrianCrossing); + restrictions.ClearValue(segmentEndId, JunctionRestrictionFlags.AllowPedestrianCrossing); } - restrictions.SetDefault(JunctionRestrictionFlags.AllowUTurn, GetDefaultUturnAllowed( + restrictions.SetDefault(segmentEndId, JunctionRestrictionFlags.AllowUTurn, GetDefaultUturnAllowed( segEnd.segmentId, segEnd.startNode, ref node)); - restrictions.SetDefault(JunctionRestrictionFlags.AllowNearTurnOnRed, GetDefaultNearTurnOnRedAllowed( + restrictions.SetDefault(segmentEndId, JunctionRestrictionFlags.AllowNearTurnOnRed, GetDefaultNearTurnOnRedAllowed( segEnd.segmentId, segEnd.startNode, ref node)); - restrictions.SetDefault(JunctionRestrictionFlags.AllowFarTurnOnRed, GetDefaultFarTurnOnRedAllowed( + restrictions.SetDefault(segmentEndId, JunctionRestrictionFlags.AllowFarTurnOnRed, GetDefaultFarTurnOnRedAllowed( segEnd.segmentId, segEnd.startNode, ref node)); - restrictions.SetDefault(JunctionRestrictionFlags.AllowForwardLaneChange, + restrictions.SetDefault(segmentEndId, JunctionRestrictionFlags.AllowForwardLaneChange, GetDefaultLaneChangingAllowedWhenGoingStraight( segEnd.segmentId, segEnd.startNode, ref node)); - restrictions.SetDefault(JunctionRestrictionFlags.AllowEnterWhenBlocked, GetDefaultEnteringBlockedJunctionAllowed( + restrictions.SetDefault(segmentEndId, JunctionRestrictionFlags.AllowEnterWhenBlocked, GetDefaultEnteringBlockedJunctionAllowed( segEnd.segmentId, segEnd.startNode, ref node)); - restrictions.SetDefault(JunctionRestrictionFlags.AllowPedestrianCrossing, GetDefaultPedestrianCrossingAllowed( + restrictions.SetDefault(segmentEndId, JunctionRestrictionFlags.AllowPedestrianCrossing, GetDefaultPedestrianCrossingAllowed( segEnd.segmentId, segEnd.startNode, ref node)); @@ -287,12 +290,12 @@ private void UpdateDefaults(ref ExtSegmentEnd segEnd, "defaultEnterWhenBlockedAllowed={6}, defaultPedestrianCrossingAllowed={7}", segEnd.segmentId, segEnd.startNode, - restrictions.GetDefault(JunctionRestrictionFlags.AllowUTurn), - restrictions.GetDefault(JunctionRestrictionFlags.AllowNearTurnOnRed), - restrictions.GetDefault(JunctionRestrictionFlags.AllowFarTurnOnRed), - restrictions.GetDefault(JunctionRestrictionFlags.AllowForwardLaneChange), - restrictions.GetDefault(JunctionRestrictionFlags.AllowEnterWhenBlocked), - restrictions.GetDefault(JunctionRestrictionFlags.AllowPedestrianCrossing)); + restrictions.GetDefault(segmentEndId, JunctionRestrictionFlags.AllowUTurn), + restrictions.GetDefault(segmentEndId, JunctionRestrictionFlags.AllowNearTurnOnRed), + restrictions.GetDefault(segmentEndId, JunctionRestrictionFlags.AllowFarTurnOnRed), + restrictions.GetDefault(segmentEndId, JunctionRestrictionFlags.AllowForwardLaneChange), + restrictions.GetDefault(segmentEndId, JunctionRestrictionFlags.AllowEnterWhenBlocked), + restrictions.GetDefault(segmentEndId, JunctionRestrictionFlags.AllowPedestrianCrossing)); } #endif Notifier.Instance.OnNodeModified(segEnd.nodeId, this); @@ -367,7 +370,7 @@ public bool GetDefaultUturnAllowed(ushort segmentId, bool startNode, ref NetNode } public bool IsUturnAllowed(ushort segmentId, bool startNode) { - return segmentRestrictions[segmentId].GetValueOrDefault(JunctionRestrictionFlags.AllowUTurn, startNode); + return segmentRestrictions[segmentId].GetValueOrDefault(segmentId.AtNode(startNode), JunctionRestrictionFlags.AllowUTurn); } public bool IsNearTurnOnRedAllowedConfigurable(ushort segmentId, @@ -450,11 +453,11 @@ public bool IsTurnOnRedAllowed(bool near, ushort segmentId, bool startNode) { } public bool IsNearTurnOnRedAllowed(ushort segmentId, bool startNode) { - return segmentRestrictions[segmentId].GetValueOrDefault(JunctionRestrictionFlags.AllowNearTurnOnRed, startNode); + return segmentRestrictions[segmentId].GetValueOrDefault(segmentId.AtNode(startNode), JunctionRestrictionFlags.AllowNearTurnOnRed); } public bool IsFarTurnOnRedAllowed(ushort segmentId, bool startNode) { - return segmentRestrictions[segmentId].GetValueOrDefault(JunctionRestrictionFlags.AllowFarTurnOnRed, startNode); + return segmentRestrictions[segmentId].GetValueOrDefault(segmentId.AtNode(startNode), JunctionRestrictionFlags.AllowFarTurnOnRed); } public bool IsLaneChangingAllowedWhenGoingStraightConfigurable( @@ -528,7 +531,7 @@ public bool GetDefaultLaneChangingAllowedWhenGoingStraight(ushort segmentId, boo } public bool IsLaneChangingAllowedWhenGoingStraight(ushort segmentId, bool startNode) { - return segmentRestrictions[segmentId].GetValueOrDefault(JunctionRestrictionFlags.AllowForwardLaneChange, startNode); + return segmentRestrictions[segmentId].GetValueOrDefault(segmentId.AtNode(startNode), JunctionRestrictionFlags.AllowForwardLaneChange); } public bool IsEnteringBlockedJunctionAllowedConfigurable( @@ -629,7 +632,7 @@ public bool GetDefaultEnteringBlockedJunctionAllowed( } public bool IsEnteringBlockedJunctionAllowed(ushort segmentId, bool startNode) { - return segmentRestrictions[segmentId].GetValueOrDefault(JunctionRestrictionFlags.AllowEnterWhenBlocked, startNode); + return segmentRestrictions[segmentId].GetValueOrDefault(segmentId.AtNode(startNode), JunctionRestrictionFlags.AllowEnterWhenBlocked); } public bool IsPedestrianCrossingAllowedConfigurable(ushort segmentId, bool startNode, ref NetNode node) { @@ -717,19 +720,19 @@ public bool GetDefaultPedestrianCrossingAllowed(ushort segmentId, bool startNode } public bool IsPedestrianCrossingAllowed(ushort segmentId, bool startNode) { - return segmentRestrictions[segmentId].GetValueOrDefault(JunctionRestrictionFlags.AllowPedestrianCrossing, startNode); + return segmentRestrictions[segmentId].GetValueOrDefault(segmentId.AtNode(startNode), JunctionRestrictionFlags.AllowPedestrianCrossing); } public TernaryBool GetUturnAllowed(ushort segmentId, bool startNode) { - return segmentRestrictions[segmentId].GetTernaryBool(JunctionRestrictionFlags.AllowUTurn, startNode); + return segmentRestrictions[segmentId].GetTernaryBool(segmentId.AtNode(startNode), JunctionRestrictionFlags.AllowUTurn); } public TernaryBool GetNearTurnOnRedAllowed(ushort segmentId, bool startNode) { - return segmentRestrictions[segmentId].GetTernaryBool(JunctionRestrictionFlags.AllowNearTurnOnRed, startNode); + return segmentRestrictions[segmentId].GetTernaryBool(segmentId.AtNode(startNode), JunctionRestrictionFlags.AllowNearTurnOnRed); } public TernaryBool GetFarTurnOnRedAllowed(ushort segmentId, bool startNode) { - return segmentRestrictions[segmentId].GetTernaryBool(JunctionRestrictionFlags.AllowFarTurnOnRed, startNode); + return segmentRestrictions[segmentId].GetTernaryBool(segmentId.AtNode(startNode), JunctionRestrictionFlags.AllowFarTurnOnRed); } public TernaryBool GetTurnOnRedAllowed(bool near, ushort segmentId, bool startNode) { @@ -739,15 +742,15 @@ public TernaryBool GetTurnOnRedAllowed(bool near, ushort segmentId, bool startNo } public TernaryBool GetLaneChangingAllowedWhenGoingStraight(ushort segmentId, bool startNode) { - return segmentRestrictions[segmentId].GetTernaryBool(JunctionRestrictionFlags.AllowForwardLaneChange, startNode); + return segmentRestrictions[segmentId].GetTernaryBool(segmentId.AtNode(startNode), JunctionRestrictionFlags.AllowForwardLaneChange); } public TernaryBool GetEnteringBlockedJunctionAllowed(ushort segmentId, bool startNode) { - return segmentRestrictions[segmentId].GetTernaryBool(JunctionRestrictionFlags.AllowEnterWhenBlocked, startNode); + return segmentRestrictions[segmentId].GetTernaryBool(segmentId.AtNode(startNode), JunctionRestrictionFlags.AllowEnterWhenBlocked); } public TernaryBool GetPedestrianCrossingAllowed(ushort segmentId, bool startNode) { - return segmentRestrictions[segmentId].GetTernaryBool(JunctionRestrictionFlags.AllowPedestrianCrossing, startNode); + return segmentRestrictions[segmentId].GetTernaryBool(segmentId.AtNode(startNode), JunctionRestrictionFlags.AllowPedestrianCrossing); } public bool ToggleUturnAllowed(ushort segmentId, bool startNode) { @@ -835,38 +838,38 @@ public bool ClearSegmentEnd(ushort segmentId, bool startNode) { return ret; } - private void SetSegmentJunctionRestrictions(ushort segmentId, bool startNode, JunctionRestrictions restrictions) { - if (restrictions.HasValue(JunctionRestrictionFlags.AllowUTurn)) { - SetUturnAllowed(segmentId, startNode, restrictions.GetValueOrDefault(JunctionRestrictionFlags.AllowUTurn)); + private void SetSegmentJunctionRestrictions(SegmentEndId segmentEndId, JunctionRestrictions restrictions) { + if (restrictions.HasValue(segmentEndId, JunctionRestrictionFlags.AllowUTurn)) { + SetUturnAllowed(segmentEndId.SegmentId, segmentEndId.StartNode, restrictions.GetValueOrDefault(segmentEndId, JunctionRestrictionFlags.AllowUTurn)); } - if (restrictions.HasValue(JunctionRestrictionFlags.AllowNearTurnOnRed)) { - SetNearTurnOnRedAllowed(segmentId, startNode, restrictions.GetValueOrDefault(JunctionRestrictionFlags.AllowNearTurnOnRed)); + if (restrictions.HasValue(segmentEndId, JunctionRestrictionFlags.AllowNearTurnOnRed)) { + SetNearTurnOnRedAllowed(segmentEndId.SegmentId, segmentEndId.StartNode, restrictions.GetValueOrDefault(segmentEndId, JunctionRestrictionFlags.AllowNearTurnOnRed)); } - if (restrictions.HasValue(JunctionRestrictionFlags.AllowFarTurnOnRed)) { - SetFarTurnOnRedAllowed(segmentId, startNode, restrictions.GetValueOrDefault(JunctionRestrictionFlags.AllowFarTurnOnRed)); + if (restrictions.HasValue(segmentEndId, JunctionRestrictionFlags.AllowFarTurnOnRed)) { + SetFarTurnOnRedAllowed(segmentEndId.SegmentId, segmentEndId.StartNode, restrictions.GetValueOrDefault(segmentEndId, JunctionRestrictionFlags.AllowFarTurnOnRed)); } - if (restrictions.HasValue(JunctionRestrictionFlags.AllowForwardLaneChange)) { + if (restrictions.HasValue(segmentEndId, JunctionRestrictionFlags.AllowForwardLaneChange)) { SetLaneChangingAllowedWhenGoingStraight( - segmentId, - startNode, - restrictions.GetValueOrDefault(JunctionRestrictionFlags.AllowForwardLaneChange)); + segmentEndId.SegmentId, + segmentEndId.StartNode, + restrictions.GetValueOrDefault(segmentEndId, JunctionRestrictionFlags.AllowForwardLaneChange)); } - if (restrictions.HasValue(JunctionRestrictionFlags.AllowEnterWhenBlocked)) { + if (restrictions.HasValue(segmentEndId, JunctionRestrictionFlags.AllowEnterWhenBlocked)) { SetEnteringBlockedJunctionAllowed( - segmentId, - startNode, - restrictions.GetValueOrDefault(JunctionRestrictionFlags.AllowEnterWhenBlocked)); + segmentEndId.SegmentId, + segmentEndId.StartNode, + restrictions.GetValueOrDefault(segmentEndId, JunctionRestrictionFlags.AllowEnterWhenBlocked)); } - if (restrictions.HasValue(JunctionRestrictionFlags.AllowPedestrianCrossing)) { + if (restrictions.HasValue(segmentEndId, JunctionRestrictionFlags.AllowPedestrianCrossing)) { SetPedestrianCrossingAllowed( - segmentId, - startNode, - restrictions.GetValueOrDefault(JunctionRestrictionFlags.AllowPedestrianCrossing)); + segmentEndId.SegmentId, + segmentEndId.StartNode, + restrictions.GetValueOrDefault(segmentEndId, JunctionRestrictionFlags.AllowPedestrianCrossing)); } } @@ -894,7 +897,7 @@ public bool SetUturnAllowed(ushort segmentId, bool startNode, TernaryBool value) return false; } - segmentRestrictions[segmentId].SetValue(JunctionRestrictionFlags.AllowUTurn, startNode, value); + segmentRestrictions[segmentId].SetValue(segmentId.AtNode(startNode), JunctionRestrictionFlags.AllowUTurn, value); OnSegmentChange( segmentId, startNode, @@ -931,9 +934,9 @@ public bool SetTurnOnRedAllowed(bool near, ushort segmentId, bool startNode, Ter } if (near) { - segmentRestrictions[segmentId].SetValue(JunctionRestrictionFlags.AllowNearTurnOnRed, startNode, value); + segmentRestrictions[segmentId].SetValue(segmentId.AtNode(startNode), JunctionRestrictionFlags.AllowNearTurnOnRed, value); } else { - segmentRestrictions[segmentId].SetValue(JunctionRestrictionFlags.AllowFarTurnOnRed, startNode, value); + segmentRestrictions[segmentId].SetValue(segmentId.AtNode(startNode), JunctionRestrictionFlags.AllowFarTurnOnRed, value); } OnSegmentChange(segmentId, startNode, ref Constants.ManagerFactory.ExtSegmentManager.ExtSegments[segmentId], true); return true; @@ -955,7 +958,7 @@ public bool SetLaneChangingAllowedWhenGoingStraight( return false; } - segmentRestrictions[segmentId].SetValue(JunctionRestrictionFlags.AllowForwardLaneChange, startNode, value); + segmentRestrictions[segmentId].SetValue(segmentId.AtNode(startNode), JunctionRestrictionFlags.AllowForwardLaneChange, value); OnSegmentChange( segmentId, startNode, @@ -977,7 +980,7 @@ public bool SetEnteringBlockedJunctionAllowed(ushort segmentId, bool startNode, return false; } - segmentRestrictions[segmentId].SetValue(JunctionRestrictionFlags.AllowEnterWhenBlocked, startNode, value); + segmentRestrictions[segmentId].SetValue(segmentId.AtNode(startNode), JunctionRestrictionFlags.AllowEnterWhenBlocked, value); // recalculation not needed here because this is a simulation-time feature OnSegmentChange( @@ -1001,7 +1004,7 @@ public bool SetPedestrianCrossingAllowed(ushort segmentId, bool startNode, Terna return false; } - segmentRestrictions[segmentId].SetValue(JunctionRestrictionFlags.AllowPedestrianCrossing, startNode, value); + segmentRestrictions[segmentId].SetValue(segmentId.AtNode(startNode), JunctionRestrictionFlags.AllowPedestrianCrossing, value); OnSegmentChange( segmentId, startNode, @@ -1031,12 +1034,12 @@ private void OnSegmentChange(ushort segmentId, public override void OnLevelUnloading() { base.OnLevelUnloading(); - for (int i = 0; i < segmentRestrictions.Length; ++i) { - segmentRestrictions[i].Reset(startNode: null, resetDefaults: true); + for (ushort segmentId = 0; segmentId < segmentRestrictions.Length; ++segmentId) { + segmentRestrictions[segmentId].Reset((ushort)segmentId); } - for (int i = 0; i < orphanedRestrictions.Length; ++i) { - orphanedRestrictions[i].Reset(startNode: null, resetDefaults: true); + for (ushort segmentId = 0; segmentId < orphanedRestrictions.Length; ++segmentId) { + orphanedRestrictions[segmentId].Reset(segmentId); } } @@ -1228,7 +1231,7 @@ public bool LoadData(List data) { ExtSegmentManager extSegmentManager = ExtSegmentManager.Instance; - for (uint segmentId = 0; segmentId < NetManager.MAX_SEGMENT_COUNT; segmentId++) { + for (ushort segmentId = 0; segmentId < NetManager.MAX_SEGMENT_COUNT; segmentId++) { try { ref NetSegment netSegment = ref ((ushort)segmentId).ToSegment(); @@ -1244,7 +1247,7 @@ public bool LoadData(List data) { if (startNodeId.ToNode().IsValid()) { JunctionRestrictions endFlags = segmentRestrictions[segmentId].startNodeRestrictions; - if (!endFlags.IsDefault()) { + if (!endFlags.IsDefault(segmentId.AtStartNode())) { startNodeFlags = new Configuration.SegmentNodeFlags(); startNodeFlags.uturnAllowed = @@ -1272,7 +1275,7 @@ public bool LoadData(List data) { if (endNodeId.ToNode().IsValid()) { JunctionRestrictions restrictions = segmentRestrictions[segmentId].endNodeRestrictions; - if (!restrictions.IsDefault()) { + if (!restrictions.IsDefault(segmentId.AtEndNode())) { endNodeFlags = new Configuration.SegmentNodeFlags(); endNodeFlags.uturnAllowed = @@ -1323,33 +1326,35 @@ private struct SegmentJunctionRestrictions { public JunctionRestrictions startNodeRestrictions; public JunctionRestrictions endNodeRestrictions; - public bool GetValueOrDefault(JunctionRestrictionFlags flags, bool startNode) { - return (startNode ? startNodeRestrictions : endNodeRestrictions).GetValueOrDefault(flags); + public bool GetValueOrDefault(SegmentEndId segmentEndId, JunctionRestrictionFlags flags) { + return (segmentEndId.StartNode ? startNodeRestrictions : endNodeRestrictions).GetValueOrDefault(segmentEndId, flags); } - public TernaryBool GetTernaryBool(JunctionRestrictionFlags flags, bool startNode) { - return (startNode ? startNodeRestrictions : endNodeRestrictions).GetTernaryBool(flags); + public TernaryBool GetTernaryBool(SegmentEndId segmentEndId, JunctionRestrictionFlags flags) { + return (segmentEndId.StartNode ? startNodeRestrictions : endNodeRestrictions).GetTernaryBool(segmentEndId, flags); } - public void SetValue(JunctionRestrictionFlags flags, bool startNode, TernaryBool value) { - if (startNode) - startNodeRestrictions.SetValue(flags, value); + public void SetValue(SegmentEndId segmentEndId, JunctionRestrictionFlags flags, TernaryBool value) { + if (segmentEndId.StartNode) + startNodeRestrictions.SetValue(segmentEndId, flags, value); else - endNodeRestrictions.SetValue(flags, value); + endNodeRestrictions.SetValue(segmentEndId, flags, value); } - public bool IsDefault() { - return startNodeRestrictions.IsDefault() && endNodeRestrictions.IsDefault(); + public bool IsDefault(ushort segmentId) { + return startNodeRestrictions.IsDefault(segmentId.AtStartNode()) && endNodeRestrictions.IsDefault(segmentId.AtEndNode()); } - public void Reset(bool? startNode = null, bool resetDefaults = true) { - if (startNode == null || (bool)startNode) { - startNodeRestrictions.Reset(resetDefaults); - } + public void Reset(SegmentEndId segmentEndId) { + if (segmentEndId.StartNode) + startNodeRestrictions.Reset(segmentEndId); + else + endNodeRestrictions.Reset(segmentEndId); + } - if (startNode == null || !(bool)startNode) { - endNodeRestrictions.Reset(resetDefaults); - } + public void Reset(ushort segmentId) { + Reset(segmentId.AtStartNode()); + Reset(segmentId.AtEndNode()); } public override string ToString() { @@ -1368,28 +1373,27 @@ private struct JunctionRestrictions { private JunctionRestrictionFlags defaults; - - public void ClearValue(JunctionRestrictionFlags flags) { + public void ClearValue(SegmentEndId segmentEndId, JunctionRestrictionFlags flags) { values &= ~flags; mask &= ~flags; } - public void SetDefault(JunctionRestrictionFlags flags, bool value) { + public void SetDefault(SegmentEndId segmentEndId, JunctionRestrictionFlags flags, bool value) { if (value) defaults |= flags; else defaults &= ~flags; } - public bool GetDefault(JunctionRestrictionFlags flags) { + public bool GetDefault(SegmentEndId segmentEndId, JunctionRestrictionFlags flags) { return (defaults & flags) == flags; } - public bool HasValue(JunctionRestrictionFlags flags) { + public bool HasValue(SegmentEndId segmentEndId, JunctionRestrictionFlags flags) { return (mask & flags) == flags; } - public TernaryBool GetTernaryBool(JunctionRestrictionFlags flags) { + public TernaryBool GetTernaryBool(SegmentEndId segmentEndId, JunctionRestrictionFlags flags) { return (mask & flags) == flags ? (values & flags) == flags ? TernaryBool.True @@ -1397,11 +1401,11 @@ public TernaryBool GetTernaryBool(JunctionRestrictionFlags flags) { : TernaryBool.Undefined; } - public bool GetValueOrDefault(JunctionRestrictionFlags flags) { + public bool GetValueOrDefault(SegmentEndId segmentEndId, JunctionRestrictionFlags flags) { return ((values & flags & mask) | (defaults & flags & ~mask)) == flags; } - public void SetValue(JunctionRestrictionFlags flags, TernaryBool value) { + public void SetValue(SegmentEndId segmentEndId, JunctionRestrictionFlags flags, TernaryBool value) { switch (value) { case TernaryBool.True: values |= flags; @@ -1423,11 +1427,11 @@ public void SetValue(JunctionRestrictionFlags flags, TernaryBool value) { } } - public bool IsDefault() { + public bool IsDefault(SegmentEndId segmentEndId) { return ((values & mask) | (defaults & ~mask)) == defaults; } - public void Reset(bool resetDefaults = true) { + public void Reset(SegmentEndId segmentEndId, bool resetDefaults = true) { values = mask = default; if (resetDefaults) { diff --git a/TLM/TLM/Network/Data/SegmentEndId.cs b/TLM/TLM/Network/Data/SegmentEndId.cs new file mode 100644 index 000000000..9b749e85d --- /dev/null +++ b/TLM/TLM/Network/Data/SegmentEndId.cs @@ -0,0 +1,31 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace TrafficManager.Network.Data { + + /// + /// To help facilitate future migration of this struct into the API, please put + /// implementation-specific methods in . + /// + public struct SegmentEndId { + + public ushort SegmentId; + + public bool StartNode; + + public SegmentEndId(ushort segmentId, bool startNode) { + SegmentId = segmentId; + StartNode = startNode; + } + + public static bool operator ==(SegmentEndId x, SegmentEndId y) => x.Equals(y); + + public static bool operator !=(SegmentEndId x, SegmentEndId y) => !x.Equals(y); + + public static implicit operator ushort(SegmentEndId segmentEndId) => segmentEndId.SegmentId; + + public override string ToString() => $"[SegmentId={SegmentId}, StartNode={StartNode}]"; + } +} diff --git a/TLM/TLM/TLM.csproj b/TLM/TLM/TLM.csproj index 788cd6d5a..2391869ff 100644 --- a/TLM/TLM/TLM.csproj +++ b/TLM/TLM/TLM.csproj @@ -148,6 +148,7 @@ + @@ -190,6 +191,7 @@ + diff --git a/TLM/TLM/Util/Extensions/NetNodeExtensions.cs b/TLM/TLM/Util/Extensions/NetNodeExtensions.cs index 967cbb95d..0070316aa 100644 --- a/TLM/TLM/Util/Extensions/NetNodeExtensions.cs +++ b/TLM/TLM/Util/Extensions/NetNodeExtensions.cs @@ -1,5 +1,7 @@ namespace TrafficManager.Util.Extensions { using ColossalFramework; + using TrafficManager.Network.Data; + public static class NetNodeExtensions { private static NetNode[] _nodeBuffer = Singleton.instance.m_nodes.m_buffer; diff --git a/TLM/TLM/Util/Extensions/SegmentEndIdExtensions.cs b/TLM/TLM/Util/Extensions/SegmentEndIdExtensions.cs new file mode 100644 index 000000000..b670f2cc9 --- /dev/null +++ b/TLM/TLM/Util/Extensions/SegmentEndIdExtensions.cs @@ -0,0 +1,53 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using TrafficManager.API.Traffic; +using TrafficManager.API.Traffic.Data; +using TrafficManager.Geometry.Impl; +using TrafficManager.Network.Data; + +namespace TrafficManager.Util.Extensions { + /// + /// This class exists so that if we want to move to the API, + /// we've already prepared for that by not including a lot of implementation-specific methods. + /// + internal static class SegmentEndIdExtensions { + + public static ref NetSegment GetSegment(this SegmentEndId segmentEndId) => ref segmentEndId.SegmentId.ToSegment(); + + public static ushort GetNodeId(this SegmentEndId segmentEndId) => + segmentEndId.StartNode ? segmentEndId.GetSegment().m_startNode : segmentEndId.GetSegment().m_endNode; + + public static ref NetNode GetNode(this SegmentEndId segmentEndId) => ref segmentEndId.GetNodeId().ToNode(); + + public static ISegmentEndId ToApi(this SegmentEndId segmentEndId) => + new SegmentEndIdApi(segmentEndId.SegmentId, segmentEndId.StartNode); + + public static SegmentEndId FromApi(this ISegmentEndId segmentEndId) => + new SegmentEndId(segmentEndId.SegmentId, segmentEndId.StartNode); + + public static SegmentEndId AtStartNode(this ushort segmentId) => new SegmentEndId(segmentId, true); + + public static SegmentEndId AtEndNode(this ushort segmentId) => new SegmentEndId(segmentId, false); + + public static SegmentEndId AtNode(this ushort segmentId, bool startNode) => new SegmentEndId(segmentId, startNode); + + public static SegmentEndId AtNode(this ushort segmentId, ushort nodeId) { + if (segmentId == 0) + return default; + ref var segment = ref segmentId.ToSegment(); + if (nodeId == segment.m_startNode) + return segmentId.AtStartNode(); + else if (nodeId == segment.m_endNode) + return segmentId.AtEndNode(); + throw new ArgumentException($"Segment {segmentId} is not on node {nodeId}", nameof(nodeId)); + } + + public static SegmentEndId GetSegmentEnd(this ushort nodeId, int segmentIndex) => + nodeId.ToNode().GetSegment(segmentIndex).AtNode(nodeId); + + public static SegmentEndId GetSegmentEndId(this ExtSegmentEnd extSegmentEnd) => + extSegmentEnd.segmentId.AtNode(extSegmentEnd.startNode); + } +} From 47fd73d5893b3a3b436d48e9e324fe497b6594a2 Mon Sep 17 00:00:00 2001 From: Elesbaan70 <95266227+Elesbaan70@users.noreply.github.com> Date: Fri, 27 May 2022 16:42:19 -0500 Subject: [PATCH 07/21] Implement to-be-deprecated APIs privately, eliminate TernaryBool --- .../Impl/JunctionRestrictionsManager.cs | 417 +++++++++++++----- TLM/TLM/Util/Record/SegmentEndRecord.cs | 37 +- 2 files changed, 316 insertions(+), 138 deletions(-) diff --git a/TLM/TLM/Manager/Impl/JunctionRestrictionsManager.cs b/TLM/TLM/Manager/Impl/JunctionRestrictionsManager.cs index e00c8d263..cd43d3a12 100644 --- a/TLM/TLM/Manager/Impl/JunctionRestrictionsManager.cs +++ b/TLM/TLM/Manager/Impl/JunctionRestrictionsManager.cs @@ -723,34 +723,34 @@ public bool IsPedestrianCrossingAllowed(ushort segmentId, bool startNode) { return segmentRestrictions[segmentId].GetValueOrDefault(segmentId.AtNode(startNode), JunctionRestrictionFlags.AllowPedestrianCrossing); } - public TernaryBool GetUturnAllowed(ushort segmentId, bool startNode) { - return segmentRestrictions[segmentId].GetTernaryBool(segmentId.AtNode(startNode), JunctionRestrictionFlags.AllowUTurn); + public bool? GetUturnAllowed(ushort segmentId, bool startNode) { + return segmentRestrictions[segmentId].GetValue(segmentId.AtNode(startNode), JunctionRestrictionFlags.AllowUTurn); } - public TernaryBool GetNearTurnOnRedAllowed(ushort segmentId, bool startNode) { - return segmentRestrictions[segmentId].GetTernaryBool(segmentId.AtNode(startNode), JunctionRestrictionFlags.AllowNearTurnOnRed); + public bool? GetNearTurnOnRedAllowed(ushort segmentId, bool startNode) { + return segmentRestrictions[segmentId].GetValue(segmentId.AtNode(startNode), JunctionRestrictionFlags.AllowNearTurnOnRed); } - public TernaryBool GetFarTurnOnRedAllowed(ushort segmentId, bool startNode) { - return segmentRestrictions[segmentId].GetTernaryBool(segmentId.AtNode(startNode), JunctionRestrictionFlags.AllowFarTurnOnRed); + public bool? GetFarTurnOnRedAllowed(ushort segmentId, bool startNode) { + return segmentRestrictions[segmentId].GetValue(segmentId.AtNode(startNode), JunctionRestrictionFlags.AllowFarTurnOnRed); } - public TernaryBool GetTurnOnRedAllowed(bool near, ushort segmentId, bool startNode) { + public bool? GetTurnOnRedAllowed(bool near, ushort segmentId, bool startNode) { return near ? GetNearTurnOnRedAllowed(segmentId, startNode) : GetFarTurnOnRedAllowed(segmentId, startNode); } - public TernaryBool GetLaneChangingAllowedWhenGoingStraight(ushort segmentId, bool startNode) { - return segmentRestrictions[segmentId].GetTernaryBool(segmentId.AtNode(startNode), JunctionRestrictionFlags.AllowForwardLaneChange); + public bool? GetLaneChangingAllowedWhenGoingStraight(ushort segmentId, bool startNode) { + return segmentRestrictions[segmentId].GetValue(segmentId.AtNode(startNode), JunctionRestrictionFlags.AllowForwardLaneChange); } - public TernaryBool GetEnteringBlockedJunctionAllowed(ushort segmentId, bool startNode) { - return segmentRestrictions[segmentId].GetTernaryBool(segmentId.AtNode(startNode), JunctionRestrictionFlags.AllowEnterWhenBlocked); + public bool? GetEnteringBlockedJunctionAllowed(ushort segmentId, bool startNode) { + return segmentRestrictions[segmentId].GetValue(segmentId.AtNode(startNode), JunctionRestrictionFlags.AllowEnterWhenBlocked); } - public TernaryBool GetPedestrianCrossingAllowed(ushort segmentId, bool startNode) { - return segmentRestrictions[segmentId].GetTernaryBool(segmentId.AtNode(startNode), JunctionRestrictionFlags.AllowPedestrianCrossing); + public bool? GetPedestrianCrossingAllowed(ushort segmentId, bool startNode) { + return segmentRestrictions[segmentId].GetValue(segmentId.AtNode(startNode), JunctionRestrictionFlags.AllowPedestrianCrossing); } public bool ToggleUturnAllowed(ushort segmentId, bool startNode) { @@ -790,51 +790,14 @@ public bool TogglePedestrianCrossingAllowed(ushort segmentId, bool startNode) { !IsPedestrianCrossingAllowed(segmentId, startNode)); } - public bool SetUturnAllowed(ushort segmentId, bool startNode, bool value) { - return SetUturnAllowed(segmentId, startNode, ToTernaryBool(value)); - } - - public bool SetNearTurnOnRedAllowed(ushort segmentId, bool startNode, bool value) { - return SetNearTurnOnRedAllowed(segmentId, startNode, ToTernaryBool(value)); - } - - public bool SetFarTurnOnRedAllowed(ushort segmentId, bool startNode, bool value) { - return SetFarTurnOnRedAllowed(segmentId, startNode, ToTernaryBool(value)); - } - - public bool SetTurnOnRedAllowed(bool near, ushort segmentId, bool startNode, bool value) { - return SetTurnOnRedAllowed(near, segmentId, startNode, ToTernaryBool(value)); - } - - public bool SetLaneChangingAllowedWhenGoingStraight(ushort segmentId, bool startNode, bool value) { - return SetLaneChangingAllowedWhenGoingStraight( - segmentId, - startNode, - ToTernaryBool(value)); - } - - public bool SetEnteringBlockedJunctionAllowed(ushort segmentId, bool startNode, bool value) { - return SetEnteringBlockedJunctionAllowed( - segmentId, - startNode, - ToTernaryBool(value)); - } - - public bool SetPedestrianCrossingAllowed(ushort segmentId, bool startNode, bool value) { - return SetPedestrianCrossingAllowed( - segmentId, - startNode, - ToTernaryBool(value)); - } - public bool ClearSegmentEnd(ushort segmentId, bool startNode) { bool ret = true; - ret |= SetPedestrianCrossingAllowed(segmentId, startNode, TernaryBool.Undefined); - ret |= SetEnteringBlockedJunctionAllowed(segmentId, startNode, TernaryBool.Undefined); - ret |= SetLaneChangingAllowedWhenGoingStraight(segmentId, startNode, TernaryBool.Undefined); - ret |= SetFarTurnOnRedAllowed(segmentId, startNode, TernaryBool.Undefined); - ret |= SetNearTurnOnRedAllowed(segmentId, startNode, TernaryBool.Undefined); - ret |= SetUturnAllowed(segmentId, startNode, TernaryBool.Undefined); + ret |= SetPedestrianCrossingAllowed(segmentId, startNode, null); + ret |= SetEnteringBlockedJunctionAllowed(segmentId, startNode, null); + ret |= SetLaneChangingAllowedWhenGoingStraight(segmentId, startNode, null); + ret |= SetFarTurnOnRedAllowed(segmentId, startNode, null); + ret |= SetNearTurnOnRedAllowed(segmentId, startNode, null); + ret |= SetUturnAllowed(segmentId, startNode, null); return ret; } @@ -876,9 +839,7 @@ private void SetSegmentJunctionRestrictions(SegmentEndId segmentEndId, JunctionR private static ref NetNode GetNode(ushort segmentId, bool startNode) => ref segmentId.ToSegment().GetNodeId(startNode).ToNode(); - #region SetAllowed: TernaryBool - - public bool SetUturnAllowed(ushort segmentId, bool startNode, TernaryBool value) { + public bool SetUturnAllowed(ushort segmentId, bool startNode, bool? value) { ref NetSegment netSegment = ref segmentId.ToSegment(); if (!netSegment.IsValid()) { @@ -891,7 +852,7 @@ public bool SetUturnAllowed(ushort segmentId, bool startNode, TernaryBool value) return false; } - if (value == TernaryBool.False && Constants.ManagerFactory.LaneConnectionManager.HasUturnConnections( + if (value == false && Constants.ManagerFactory.LaneConnectionManager.HasUturnConnections( segmentId, startNode)) { return false; @@ -906,15 +867,15 @@ public bool SetUturnAllowed(ushort segmentId, bool startNode, TernaryBool value) return true; } - public bool SetNearTurnOnRedAllowed(ushort segmentId, bool startNode, TernaryBool value) { + public bool SetNearTurnOnRedAllowed(ushort segmentId, bool startNode, bool? value) { return SetTurnOnRedAllowed(true, segmentId, startNode, value); } - public bool SetFarTurnOnRedAllowed(ushort segmentId, bool startNode, TernaryBool value) { + public bool SetFarTurnOnRedAllowed(ushort segmentId, bool startNode, bool? value) { return SetTurnOnRedAllowed(false, segmentId, startNode, value); } - public bool SetTurnOnRedAllowed(bool near, ushort segmentId, bool startNode, TernaryBool value) { + public bool SetTurnOnRedAllowed(bool near, ushort segmentId, bool startNode, bool? value) { ref NetSegment netSegment = ref segmentId.ToSegment(); if (!netSegment.IsValid()) { @@ -927,7 +888,7 @@ public bool SetTurnOnRedAllowed(bool near, ushort segmentId, bool startNode, Ter return false; } - if (value == TernaryBool.False && Constants.ManagerFactory.LaneConnectionManager.HasUturnConnections( + if (value == false && Constants.ManagerFactory.LaneConnectionManager.HasUturnConnections( segmentId, startNode)) { return false; @@ -945,7 +906,7 @@ public bool SetTurnOnRedAllowed(bool near, ushort segmentId, bool startNode, Ter public bool SetLaneChangingAllowedWhenGoingStraight( ushort segmentId, bool startNode, - TernaryBool value) { + bool? value) { ref NetSegment netSegment = ref segmentId.ToSegment(); if (!netSegment.IsValid()) { @@ -967,7 +928,7 @@ public bool SetLaneChangingAllowedWhenGoingStraight( return true; } - public bool SetEnteringBlockedJunctionAllowed(ushort segmentId, bool startNode, TernaryBool value) { + public bool SetEnteringBlockedJunctionAllowed(ushort segmentId, bool startNode, bool? value) { ref NetSegment netSegment = ref segmentId.ToSegment(); if (!netSegment.IsValid()) { @@ -991,7 +952,7 @@ public bool SetEnteringBlockedJunctionAllowed(ushort segmentId, bool startNode, return true; } - public bool SetPedestrianCrossingAllowed(ushort segmentId, bool startNode, TernaryBool value) { + public bool SetPedestrianCrossingAllowed(ushort segmentId, bool startNode, bool? value) { ref NetSegment netSegment = ref segmentId.ToSegment(); if (!netSegment.IsValid()) { @@ -1013,8 +974,6 @@ public bool SetPedestrianCrossingAllowed(ushort segmentId, bool startNode, Terna return true; } -#endregion - private void OnSegmentChange(ushort segmentId, bool startNode, ref ExtSegment seg, @@ -1251,17 +1210,12 @@ public bool LoadData(List data) { startNodeFlags = new Configuration.SegmentNodeFlags(); startNodeFlags.uturnAllowed = - TernaryBoolUtil.ToOptBool(GetUturnAllowed((ushort)segmentId, true)); - startNodeFlags.turnOnRedAllowed = TernaryBoolUtil.ToOptBool( - GetNearTurnOnRedAllowed((ushort)segmentId, true)); - startNodeFlags.farTurnOnRedAllowed = TernaryBoolUtil.ToOptBool( - GetFarTurnOnRedAllowed((ushort)segmentId, true)); - startNodeFlags.straightLaneChangingAllowed = TernaryBoolUtil.ToOptBool( - GetLaneChangingAllowedWhenGoingStraight((ushort)segmentId, true)); - startNodeFlags.enterWhenBlockedAllowed = TernaryBoolUtil.ToOptBool( - GetEnteringBlockedJunctionAllowed((ushort)segmentId, true)); - startNodeFlags.pedestrianCrossingAllowed = TernaryBoolUtil.ToOptBool( - GetPedestrianCrossingAllowed((ushort)segmentId, true)); + GetUturnAllowed(segmentId, true); + startNodeFlags.turnOnRedAllowed = GetNearTurnOnRedAllowed(segmentId, true); + startNodeFlags.farTurnOnRedAllowed = GetFarTurnOnRedAllowed(segmentId, true); + startNodeFlags.straightLaneChangingAllowed = GetLaneChangingAllowedWhenGoingStraight(segmentId, true); + startNodeFlags.enterWhenBlockedAllowed = GetEnteringBlockedJunctionAllowed(segmentId, true); + startNodeFlags.pedestrianCrossingAllowed = GetPedestrianCrossingAllowed(segmentId, true); #if DEBUGSAVE Log._Debug($"JunctionRestrictionsManager.SaveData: Saving start node "+ @@ -1279,18 +1233,12 @@ public bool LoadData(List data) { endNodeFlags = new Configuration.SegmentNodeFlags(); endNodeFlags.uturnAllowed = - TernaryBoolUtil.ToOptBool( - GetUturnAllowed((ushort)segmentId, false)); - endNodeFlags.turnOnRedAllowed = TernaryBoolUtil.ToOptBool( - GetNearTurnOnRedAllowed((ushort)segmentId, false)); - endNodeFlags.farTurnOnRedAllowed = TernaryBoolUtil.ToOptBool( - GetFarTurnOnRedAllowed((ushort)segmentId, false)); - endNodeFlags.straightLaneChangingAllowed = TernaryBoolUtil.ToOptBool( - GetLaneChangingAllowedWhenGoingStraight((ushort)segmentId, false)); - endNodeFlags.enterWhenBlockedAllowed = TernaryBoolUtil.ToOptBool( - GetEnteringBlockedJunctionAllowed((ushort)segmentId, false)); - endNodeFlags.pedestrianCrossingAllowed = TernaryBoolUtil.ToOptBool( - GetPedestrianCrossingAllowed((ushort)segmentId, false)); + GetUturnAllowed(segmentId, false); + endNodeFlags.turnOnRedAllowed = GetNearTurnOnRedAllowed(segmentId, false); + endNodeFlags.farTurnOnRedAllowed = GetFarTurnOnRedAllowed(segmentId, false); + endNodeFlags.straightLaneChangingAllowed = GetLaneChangingAllowedWhenGoingStraight(segmentId, false); + endNodeFlags.enterWhenBlockedAllowed = GetEnteringBlockedJunctionAllowed(segmentId, false); + endNodeFlags.pedestrianCrossingAllowed = GetPedestrianCrossingAllowed(segmentId, false); #if DEBUGSAVE Log._Debug($"JunctionRestrictionsManager.SaveData: Saving end node junction "+ @@ -1322,6 +1270,244 @@ public bool LoadData(List data) { return ret; } + public bool IsConfigurable(ushort segmentId, bool startNode, JunctionRestrictionFlags flags) { + + ref var node = ref segmentId.ToSegment().GetNodeId(startNode).ToNode(); + + if (flags.IsFlagSet(JunctionRestrictionFlags.AllowUTurn) && !IsUturnAllowedConfigurable(segmentId, startNode, ref node)) + return false; + + if (flags.IsFlagSet(JunctionRestrictionFlags.AllowNearTurnOnRed) && !IsNearTurnOnRedAllowedConfigurable(segmentId, startNode, ref node)) + return false; + + if (flags.IsFlagSet(JunctionRestrictionFlags.AllowFarTurnOnRed) && !IsFarTurnOnRedAllowedConfigurable(segmentId, startNode, ref node)) + return false; + + if (flags.IsFlagSet(JunctionRestrictionFlags.AllowForwardLaneChange) && !IsLaneChangingAllowedWhenGoingStraightConfigurable(segmentId, startNode, ref node)) + return false; + + if (flags.IsFlagSet(JunctionRestrictionFlags.AllowEnterWhenBlocked) && !IsEnteringBlockedJunctionAllowedConfigurable(segmentId, startNode, ref node)) + return false; + + if (flags.IsFlagSet(JunctionRestrictionFlags.AllowPedestrianCrossing) && !IsPedestrianCrossingAllowedConfigurable(segmentId, startNode, ref node)) + return false; + + return true; + } + + bool IJunctionRestrictionsManager.IsUturnAllowedConfigurable(ushort segmentId, bool startNode, ref NetNode node) + => IsConfigurable(segmentId, startNode, JunctionRestrictionFlags.AllowUTurn); + + bool IJunctionRestrictionsManager.IsNearTurnOnRedAllowedConfigurable(ushort segmentId, bool startNode, ref NetNode node) + => IsConfigurable(segmentId, startNode, JunctionRestrictionFlags.AllowNearTurnOnRed); + + bool IJunctionRestrictionsManager.IsFarTurnOnRedAllowedConfigurable(ushort segmentId, bool startNode, ref NetNode node) + => IsConfigurable(segmentId, startNode, JunctionRestrictionFlags.AllowFarTurnOnRed); + + bool IJunctionRestrictionsManager.IsTurnOnRedAllowedConfigurable(bool near, ushort segmentId, bool startNode, ref NetNode node) + => IsConfigurable(segmentId, startNode, near ? JunctionRestrictionFlags.AllowNearTurnOnRed : JunctionRestrictionFlags.AllowFarTurnOnRed); + + bool IJunctionRestrictionsManager.IsLaneChangingAllowedWhenGoingStraightConfigurable(ushort segmentId, bool startNode, ref NetNode node) + => IsConfigurable(segmentId, startNode, JunctionRestrictionFlags.AllowForwardLaneChange); + + bool IJunctionRestrictionsManager.IsEnteringBlockedJunctionAllowedConfigurable(ushort segmentId, bool startNode, ref NetNode node) + => IsConfigurable(segmentId, startNode, JunctionRestrictionFlags.AllowEnterWhenBlocked); + + bool IJunctionRestrictionsManager.IsPedestrianCrossingAllowedConfigurable(ushort segmentId, bool startNode, ref NetNode node) + => IsConfigurable(segmentId, startNode, JunctionRestrictionFlags.AllowPedestrianCrossing); + + public bool GetDefaultValue(ushort segmentId, bool startNode, JunctionRestrictionFlags flags) { + + if (flags == default) + return false; + + ref var node = ref segmentId.ToSegment().GetNodeId(startNode).ToNode(); + + if (flags.IsFlagSet(JunctionRestrictionFlags.AllowUTurn) && !GetDefaultUturnAllowed(segmentId, startNode, ref node)) + return false; + + if (flags.IsFlagSet(JunctionRestrictionFlags.AllowNearTurnOnRed) && !GetDefaultNearTurnOnRedAllowed(segmentId, startNode, ref node)) + return false; + + if (flags.IsFlagSet(JunctionRestrictionFlags.AllowFarTurnOnRed) && !GetDefaultFarTurnOnRedAllowed(segmentId, startNode, ref node)) + return false; + + if (flags.IsFlagSet(JunctionRestrictionFlags.AllowForwardLaneChange) && !GetDefaultLaneChangingAllowedWhenGoingStraight(segmentId, startNode, ref node)) + return false; + + if (flags.IsFlagSet(JunctionRestrictionFlags.AllowEnterWhenBlocked) && !GetDefaultEnteringBlockedJunctionAllowed(segmentId, startNode, ref node)) + return false; + + if (flags.IsFlagSet(JunctionRestrictionFlags.AllowPedestrianCrossing) && !GetDefaultPedestrianCrossingAllowed(segmentId, startNode, ref node)) + return false; + + return true; + } + + bool IJunctionRestrictionsManager.GetDefaultUturnAllowed(ushort segmentId, bool startNode, ref NetNode node) + => GetDefaultValue(segmentId, startNode, JunctionRestrictionFlags.AllowUTurn); + + bool IJunctionRestrictionsManager.GetDefaultNearTurnOnRedAllowed(ushort segmentId, bool startNode, ref NetNode node) + => GetDefaultValue(segmentId, startNode, JunctionRestrictionFlags.AllowNearTurnOnRed); + + bool IJunctionRestrictionsManager.GetDefaultFarTurnOnRedAllowed(ushort segmentId, bool startNode, ref NetNode node) + => GetDefaultValue(segmentId, startNode, JunctionRestrictionFlags.AllowFarTurnOnRed); + + bool IJunctionRestrictionsManager.GetDefaultTurnOnRedAllowed(bool near, ushort segmentId, bool startNode, ref NetNode node) + => GetDefaultValue(segmentId, startNode, near ? JunctionRestrictionFlags.AllowNearTurnOnRed : JunctionRestrictionFlags.AllowFarTurnOnRed); + + bool IJunctionRestrictionsManager.GetDefaultLaneChangingAllowedWhenGoingStraight(ushort segmentId, bool startNode, ref NetNode node) + => GetDefaultValue(segmentId, startNode, JunctionRestrictionFlags.AllowForwardLaneChange); + + bool IJunctionRestrictionsManager.GetDefaultEnteringBlockedJunctionAllowed(ushort segmentId, bool startNode, ref NetNode node) + => GetDefaultValue(segmentId, startNode, JunctionRestrictionFlags.AllowEnterWhenBlocked); + + bool IJunctionRestrictionsManager.GetDefaultPedestrianCrossingAllowed(ushort segmentId, bool startNode, ref NetNode node) + => GetDefaultValue(segmentId, startNode, JunctionRestrictionFlags.AllowPedestrianCrossing); + + public bool ToggleValue(ushort segmentId, bool startNode, JunctionRestrictionFlags flags) { + + if (flags == default || ((int)flags & ((int)flags - 1)) != 0) + return false; + + if (flags.IsFlagSet(JunctionRestrictionFlags.AllowUTurn)) + return ToggleUturnAllowed(segmentId, startNode); + + if (flags.IsFlagSet(JunctionRestrictionFlags.AllowNearTurnOnRed)) + return ToggleNearTurnOnRedAllowed(segmentId, startNode); + + if (flags.IsFlagSet(JunctionRestrictionFlags.AllowFarTurnOnRed)) + return ToggleFarTurnOnRedAllowed(segmentId, startNode); + + if (flags.IsFlagSet(JunctionRestrictionFlags.AllowForwardLaneChange)) + return ToggleLaneChangingAllowedWhenGoingStraight(segmentId, startNode); + + if (flags.IsFlagSet(JunctionRestrictionFlags.AllowEnterWhenBlocked)) + return ToggleEnteringBlockedJunctionAllowed(segmentId, startNode); + + if (flags.IsFlagSet(JunctionRestrictionFlags.AllowPedestrianCrossing)) + return TogglePedestrianCrossingAllowed(segmentId, startNode); + + return false; + } + + bool IJunctionRestrictionsManager.ToggleUturnAllowed(ushort segmentId, bool startNode) + => ToggleValue(segmentId, startNode, JunctionRestrictionFlags.AllowUTurn); + + bool IJunctionRestrictionsManager.ToggleNearTurnOnRedAllowed(ushort segmentId, bool startNode) + => ToggleValue(segmentId, startNode, JunctionRestrictionFlags.AllowNearTurnOnRed); + + bool IJunctionRestrictionsManager.ToggleFarTurnOnRedAllowed(ushort segmentId, bool startNode) + => ToggleValue(segmentId, startNode, JunctionRestrictionFlags.AllowFarTurnOnRed); + + bool IJunctionRestrictionsManager.ToggleTurnOnRedAllowed(bool near, ushort segmentId, bool startNode) + => ToggleValue(segmentId, startNode, near ? JunctionRestrictionFlags.AllowNearTurnOnRed : JunctionRestrictionFlags.AllowFarTurnOnRed); + + bool IJunctionRestrictionsManager.ToggleLaneChangingAllowedWhenGoingStraight(ushort segmentId, bool startNode) + => ToggleValue(segmentId, startNode, JunctionRestrictionFlags.AllowForwardLaneChange); + + bool IJunctionRestrictionsManager.ToggleEnteringBlockedJunctionAllowed(ushort segmentId, bool startNode) + => ToggleValue(segmentId, startNode, JunctionRestrictionFlags.AllowEnterWhenBlocked); + + bool IJunctionRestrictionsManager.TogglePedestrianCrossingAllowed(ushort segmentId, bool startNode) + => ToggleValue(segmentId, startNode, JunctionRestrictionFlags.AllowPedestrianCrossing); + + public bool SetValue(ushort segmentId, bool startNode, JunctionRestrictionFlags flags, bool? value) { + + if (flags == default) + return false; + + if (flags.IsFlagSet(JunctionRestrictionFlags.AllowUTurn) && !SetUturnAllowed(segmentId, startNode, value)) + return false; + + if (flags.IsFlagSet(JunctionRestrictionFlags.AllowNearTurnOnRed) && !SetNearTurnOnRedAllowed(segmentId, startNode, value)) + return false; + + if (flags.IsFlagSet(JunctionRestrictionFlags.AllowFarTurnOnRed) && !SetFarTurnOnRedAllowed(segmentId, startNode, value)) + return false; + + if (flags.IsFlagSet(JunctionRestrictionFlags.AllowForwardLaneChange) && !SetLaneChangingAllowedWhenGoingStraight(segmentId, startNode, value)) + return false; + + if (flags.IsFlagSet(JunctionRestrictionFlags.AllowEnterWhenBlocked) && !SetEnteringBlockedJunctionAllowed(segmentId, startNode, value)) + return false; + + if (flags.IsFlagSet(JunctionRestrictionFlags.AllowPedestrianCrossing) && !SetPedestrianCrossingAllowed(segmentId, startNode, value)) + return false; + + return true; + } + + bool IJunctionRestrictionsManager.SetUturnAllowed(ushort segmentId, bool startNode, bool value) + => SetValue(segmentId, startNode, JunctionRestrictionFlags.AllowUTurn, value); + + bool IJunctionRestrictionsManager.SetNearTurnOnRedAllowed(ushort segmentId, bool startNode, bool value) + => SetValue(segmentId, startNode, JunctionRestrictionFlags.AllowNearTurnOnRed, value); + + bool IJunctionRestrictionsManager.SetFarTurnOnRedAllowed(ushort segmentId, bool startNode, bool value) + => SetValue(segmentId, startNode, JunctionRestrictionFlags.AllowFarTurnOnRed, value); + + bool IJunctionRestrictionsManager.SetTurnOnRedAllowed(bool near, ushort segmentId, bool startNode, bool value) + => SetValue(segmentId, startNode, near ? JunctionRestrictionFlags.AllowNearTurnOnRed : JunctionRestrictionFlags.AllowFarTurnOnRed, value); + + bool IJunctionRestrictionsManager.SetLaneChangingAllowedWhenGoingStraight(ushort segmentId, bool startNode, bool value) + => SetValue(segmentId, startNode, JunctionRestrictionFlags.AllowForwardLaneChange, value); + + bool IJunctionRestrictionsManager.SetEnteringBlockedJunctionAllowed(ushort segmentId, bool startNode, bool value) + => SetValue(segmentId, startNode, JunctionRestrictionFlags.AllowEnterWhenBlocked, value); + + bool IJunctionRestrictionsManager.SetPedestrianCrossingAllowed(ushort segmentId, bool startNode, bool value) + => SetValue(segmentId, startNode, JunctionRestrictionFlags.AllowPedestrianCrossing, value); + + bool IJunctionRestrictionsManager.SetUturnAllowed(ushort segmentId, bool startNode, TernaryBool value) + => SetValue(segmentId, startNode, JunctionRestrictionFlags.AllowUTurn, ToOptBool(value)); + + bool IJunctionRestrictionsManager.SetNearTurnOnRedAllowed(ushort segmentId, bool startNode, TernaryBool value) + => SetValue(segmentId, startNode, JunctionRestrictionFlags.AllowNearTurnOnRed, ToOptBool(value)); + + bool IJunctionRestrictionsManager.SetFarTurnOnRedAllowed(ushort segmentId, bool startNode, TernaryBool value) + => SetValue(segmentId, startNode, JunctionRestrictionFlags.AllowFarTurnOnRed, ToOptBool(value)); + + bool IJunctionRestrictionsManager.SetTurnOnRedAllowed(bool near, ushort segmentId, bool startNode, TernaryBool value) + => SetValue(segmentId, startNode, near ? JunctionRestrictionFlags.AllowNearTurnOnRed : JunctionRestrictionFlags.AllowFarTurnOnRed, ToOptBool(value)); + + bool IJunctionRestrictionsManager.SetLaneChangingAllowedWhenGoingStraight(ushort segmentId, bool startNode, TernaryBool value) + => SetValue(segmentId, startNode, JunctionRestrictionFlags.AllowForwardLaneChange, ToOptBool(value)); + + bool IJunctionRestrictionsManager.SetEnteringBlockedJunctionAllowed(ushort segmentId, bool startNode, TernaryBool value) + => SetValue(segmentId, startNode, JunctionRestrictionFlags.AllowEnterWhenBlocked, ToOptBool(value)); + + bool IJunctionRestrictionsManager.SetPedestrianCrossingAllowed(ushort segmentId, bool startNode, TernaryBool value) + => SetValue(segmentId, startNode, JunctionRestrictionFlags.AllowPedestrianCrossing, ToOptBool(value)); + + bool IJunctionRestrictionsManager.ClearSegmentEnd(ushort segmentId, bool startNode) { + throw new NotImplementedException(); + } + + public bool? GetValue(ushort segmentId, bool startNode, JunctionRestrictionFlags flags) + => segmentRestrictions[segmentId].GetValue(segmentId.AtNode(startNode), flags); + + TernaryBool IJunctionRestrictionsManager.GetUturnAllowed(ushort segmentId, bool startNode) + => ToTernaryBool(GetValue(segmentId, startNode, JunctionRestrictionFlags.AllowUTurn)); + + TernaryBool IJunctionRestrictionsManager.GetNearTurnOnRedAllowed(ushort segmentId, bool startNode) + => ToTernaryBool(GetValue(segmentId, startNode, JunctionRestrictionFlags.AllowNearTurnOnRed)); + + TernaryBool IJunctionRestrictionsManager.GetFarTurnOnRedAllowed(ushort segmentId, bool startNode) + => ToTernaryBool(GetValue(segmentId, startNode, JunctionRestrictionFlags.AllowFarTurnOnRed)); + + TernaryBool IJunctionRestrictionsManager.GetTurnOnRedAllowed(bool near, ushort segmentId, bool startNode) + => ToTernaryBool(GetValue(segmentId, startNode, near ? JunctionRestrictionFlags.AllowNearTurnOnRed : JunctionRestrictionFlags.AllowFarTurnOnRed)); + + TernaryBool IJunctionRestrictionsManager.GetLaneChangingAllowedWhenGoingStraight(ushort segmentId, bool startNode) + => ToTernaryBool(GetValue(segmentId, startNode, JunctionRestrictionFlags.AllowForwardLaneChange)); + + TernaryBool IJunctionRestrictionsManager.GetEnteringBlockedJunctionAllowed(ushort segmentId, bool startNode) + => ToTernaryBool(GetValue(segmentId, startNode, JunctionRestrictionFlags.AllowEnterWhenBlocked)); + + TernaryBool IJunctionRestrictionsManager.GetPedestrianCrossingAllowed(ushort segmentId, bool startNode) + => ToTernaryBool(GetValue(segmentId, startNode, JunctionRestrictionFlags.AllowPedestrianCrossing)); + private struct SegmentJunctionRestrictions { public JunctionRestrictions startNodeRestrictions; public JunctionRestrictions endNodeRestrictions; @@ -1330,11 +1516,11 @@ public bool GetValueOrDefault(SegmentEndId segmentEndId, JunctionRestrictionFlag return (segmentEndId.StartNode ? startNodeRestrictions : endNodeRestrictions).GetValueOrDefault(segmentEndId, flags); } - public TernaryBool GetTernaryBool(SegmentEndId segmentEndId, JunctionRestrictionFlags flags) { - return (segmentEndId.StartNode ? startNodeRestrictions : endNodeRestrictions).GetTernaryBool(segmentEndId, flags); + public bool? GetValue(SegmentEndId segmentEndId, JunctionRestrictionFlags flags) { + return (segmentEndId.StartNode ? startNodeRestrictions : endNodeRestrictions).GetValue(segmentEndId, flags); } - public void SetValue(SegmentEndId segmentEndId, JunctionRestrictionFlags flags, TernaryBool value) { + public void SetValue(SegmentEndId segmentEndId, JunctionRestrictionFlags flags, bool? value) { if (segmentEndId.StartNode) startNodeRestrictions.SetValue(segmentEndId, flags, value); else @@ -1393,37 +1579,28 @@ public bool HasValue(SegmentEndId segmentEndId, JunctionRestrictionFlags flags) return (mask & flags) == flags; } - public TernaryBool GetTernaryBool(SegmentEndId segmentEndId, JunctionRestrictionFlags flags) { - return (mask & flags) == flags - ? (values & flags) == flags - ? TernaryBool.True - : TernaryBool.False - : TernaryBool.Undefined; + public bool? GetValue(SegmentEndId segmentEndId, JunctionRestrictionFlags flags) { + + return (mask & flags) != flags ? null + : (values & flags) == flags ? true + : (values & flags) == 0 ? false + : null; } public bool GetValueOrDefault(SegmentEndId segmentEndId, JunctionRestrictionFlags flags) { return ((values & flags & mask) | (defaults & flags & ~mask)) == flags; } - public void SetValue(SegmentEndId segmentEndId, JunctionRestrictionFlags flags, TernaryBool value) { - switch (value) { - case TernaryBool.True: - values |= flags; - mask |= flags; - break; - - case TernaryBool.False: - values &= ~flags; - mask |= flags; - break; - - case TernaryBool.Undefined: - values &= ~flags; - mask &= ~flags; - break; - - default: - throw new ArgumentOutOfRangeException(nameof(value)); + public void SetValue(SegmentEndId segmentEndId, JunctionRestrictionFlags flags, bool? value) { + if (value == true) { + values |= flags; + mask |= flags; + } else if (value == false) { + values &= ~flags; + mask |= flags; + } else { + values &= ~flags; + mask &= ~flags; } } diff --git a/TLM/TLM/Util/Record/SegmentEndRecord.cs b/TLM/TLM/Util/Record/SegmentEndRecord.cs index 596d6b234..c8b06f520 100644 --- a/TLM/TLM/Util/Record/SegmentEndRecord.cs +++ b/TLM/TLM/Util/Record/SegmentEndRecord.cs @@ -6,6 +6,7 @@ namespace TrafficManager.Util.Record { using TrafficManager.API.Traffic.Enums; using TrafficManager.Manager.Impl; using TrafficManager.State; + using static CSUtil.Commons.TernaryBoolUtil; [Serializable] class SegmentEndRecord : IRecordable { @@ -39,12 +40,12 @@ public SegmentEndRecord(ushort segmentId, bool startNode) { private static JunctionRestrictionsManager JRMan => JunctionRestrictionsManager.Instance; public void Record() { - uturnAllowed_ = JRMan.GetUturnAllowed(SegmentId, StartNode); - nearTurnOnRedAllowed_ = JRMan.GetNearTurnOnRedAllowed(SegmentId, StartNode); - farTurnOnRedAllowed_ = JRMan.GetFarTurnOnRedAllowed(SegmentId, StartNode); - laneChangingAllowedWhenGoingStraight_ = JRMan.GetLaneChangingAllowedWhenGoingStraight(SegmentId, StartNode); - enteringBlockedJunctionAllowed_ = JRMan.GetEnteringBlockedJunctionAllowed(SegmentId, StartNode); - pedestrianCrossingAllowed_ = JRMan.GetPedestrianCrossingAllowed(SegmentId, StartNode); + uturnAllowed_ = ToTernaryBool(JRMan.GetUturnAllowed(SegmentId, StartNode)); + nearTurnOnRedAllowed_ = ToTernaryBool(JRMan.GetNearTurnOnRedAllowed(SegmentId, StartNode)); + farTurnOnRedAllowed_ = ToTernaryBool(JRMan.GetFarTurnOnRedAllowed(SegmentId, StartNode)); + laneChangingAllowedWhenGoingStraight_ = ToTernaryBool(JRMan.GetLaneChangingAllowedWhenGoingStraight(SegmentId, StartNode)); + enteringBlockedJunctionAllowed_ = ToTernaryBool(JRMan.GetEnteringBlockedJunctionAllowed(SegmentId, StartNode)); + pedestrianCrossingAllowed_ = ToTernaryBool(JRMan.GetPedestrianCrossingAllowed(SegmentId, StartNode)); prioirtySign_ = priorityMan.GetPrioritySign(SegmentId, StartNode); @@ -64,12 +65,12 @@ public void Restore() { } // all necessary checks are performed internally. - JRMan.SetUturnAllowed(SegmentId, StartNode, uturnAllowed_); - JRMan.SetNearTurnOnRedAllowed(SegmentId, StartNode, nearTurnOnRedAllowed_); - JRMan.SetFarTurnOnRedAllowed(SegmentId, StartNode, farTurnOnRedAllowed_); - JRMan.SetLaneChangingAllowedWhenGoingStraight(SegmentId, StartNode, laneChangingAllowedWhenGoingStraight_); - JRMan.SetEnteringBlockedJunctionAllowed(SegmentId, StartNode, enteringBlockedJunctionAllowed_); - JRMan.SetPedestrianCrossingAllowed(SegmentId, StartNode, pedestrianCrossingAllowed_); + JRMan.SetUturnAllowed(SegmentId, StartNode, ToOptBool(uturnAllowed_)); + JRMan.SetNearTurnOnRedAllowed(SegmentId, StartNode, ToOptBool(nearTurnOnRedAllowed_)); + JRMan.SetFarTurnOnRedAllowed(SegmentId, StartNode, ToOptBool(farTurnOnRedAllowed_)); + JRMan.SetLaneChangingAllowedWhenGoingStraight(SegmentId, StartNode, ToOptBool(laneChangingAllowedWhenGoingStraight_)); + JRMan.SetEnteringBlockedJunctionAllowed(SegmentId, StartNode, ToOptBool(enteringBlockedJunctionAllowed_)); + JRMan.SetPedestrianCrossingAllowed(SegmentId, StartNode, ToOptBool(pedestrianCrossingAllowed_)); } public void Transfer(Dictionary map) { @@ -83,12 +84,12 @@ public void Transfer(Dictionary map) { } // all necessary checks are performed internally. - JRMan.SetUturnAllowed(segmentId, StartNode, uturnAllowed_); - JRMan.SetNearTurnOnRedAllowed(segmentId, StartNode, nearTurnOnRedAllowed_); - JRMan.SetFarTurnOnRedAllowed(segmentId, StartNode, farTurnOnRedAllowed_); - JRMan.SetLaneChangingAllowedWhenGoingStraight(segmentId, StartNode, laneChangingAllowedWhenGoingStraight_); - JRMan.SetEnteringBlockedJunctionAllowed(segmentId, StartNode, enteringBlockedJunctionAllowed_); - JRMan.SetPedestrianCrossingAllowed(segmentId, StartNode, pedestrianCrossingAllowed_); + JRMan.SetUturnAllowed(segmentId, StartNode, ToOptBool(uturnAllowed_)); + JRMan.SetNearTurnOnRedAllowed(segmentId, StartNode, ToOptBool(nearTurnOnRedAllowed_)); + JRMan.SetFarTurnOnRedAllowed(segmentId, StartNode, ToOptBool(farTurnOnRedAllowed_)); + JRMan.SetLaneChangingAllowedWhenGoingStraight(segmentId, StartNode, ToOptBool(laneChangingAllowedWhenGoingStraight_)); + JRMan.SetEnteringBlockedJunctionAllowed(segmentId, StartNode, ToOptBool(enteringBlockedJunctionAllowed_)); + JRMan.SetPedestrianCrossingAllowed(segmentId, StartNode, ToOptBool(pedestrianCrossingAllowed_)); } public void Transfer(uint mappedId) { From 438bab0967a648f8b1fa75a2793a575e3a0ed8e5 Mon Sep 17 00:00:00 2001 From: Elesbaan70 <95266227+Elesbaan70@users.noreply.github.com> Date: Fri, 27 May 2022 17:14:07 -0500 Subject: [PATCH 08/21] Remove a lot of redundant code --- TLM/TLM/Custom/PathFinding/CustomPathFind.cs | 19 +- .../Impl/JunctionRestrictionsManager.cs | 181 ++++-------------- TLM/TLM/Manager/Impl/RoutingManager.cs | 9 +- .../Manager/Impl/VehicleBehaviorManager.cs | 5 +- .../UI/SubTools/ManualTrafficLightsTool.cs | 5 +- .../UI/SubTools/TTL/TimedTrafficLightsTool.cs | 5 +- TLM/TLM/Util/Record/SegmentEndRecord.cs | 12 +- 7 files changed, 73 insertions(+), 163 deletions(-) diff --git a/TLM/TLM/Custom/PathFinding/CustomPathFind.cs b/TLM/TLM/Custom/PathFinding/CustomPathFind.cs index d3c807f44..9ce297581 100644 --- a/TLM/TLM/Custom/PathFinding/CustomPathFind.cs +++ b/TLM/TLM/Custom/PathFinding/CustomPathFind.cs @@ -1084,10 +1084,11 @@ ref nextSegmentId.ToSegment(), #if JUNCTIONRESTRICTIONS // next segment does not have pedestrian lanes but cims need to // cross it to reach the next segment - if (!junctionManager.IsPedestrianCrossingAllowed( + if (!junctionManager.GetValueOrDefault( leftSegmentId, leftSegment.m_startNode == - nextNodeId)) { + nextNodeId, + JunctionRestrictionFlags.AllowPedestrianCrossing)) { break; } #endif @@ -1122,10 +1123,11 @@ ref nextSegmentId.ToSegment(), #if JUNCTIONRESTRICTIONS // next segment does not have pedestrian lanes but cims need to // cross it to reach the next segment - if (!junctionManager.IsPedestrianCrossingAllowed( + if (!junctionManager.GetValueOrDefault( rightSegmentId, rightSegment.m_startNode == - nextNodeId)) { + nextNodeId, + JunctionRestrictionFlags.AllowPedestrianCrossing)) { break; } #endif @@ -3167,9 +3169,10 @@ private void ProcessItemPedBicycle( if (Options.junctionRestrictionsEnabled && item.Position.m_segment == nextSegmentId) { // check if pedestrians are not allowed to cross here - if (!junctionManager.IsPedestrianCrossingAllowed( + if (!junctionManager.GetValueOrDefault( nextSegmentId, - nextIsStartNode)) { + nextIsStartNode, + JunctionRestrictionFlags.AllowPedestrianCrossing)) { if (isLogEnabled) { DebugLog( unitId, @@ -3587,7 +3590,7 @@ private bool ProcessItemRouted( prevIsCarLane && // u-turns for road vehicles only (!isHeavyVehicle_ || isStockUturnPoint) && // only small vehicles may perform u-turns OR everyone at stock u-turn points !prevIsOutgoingOneWay && // do not u-turn on one-ways - junctionManager.IsUturnAllowed(prevSegmentId, nextIsStartNode); + junctionManager.GetValueOrDefault(prevSegmentId, nextIsStartNode, JunctionRestrictionFlags.AllowUTurn); if (isLogEnabled) { DebugLog( @@ -3600,7 +3603,7 @@ private bool ProcessItemRouted( $"\tisStockUturnPoint={isStockUturnPoint}\n" + $"\tprevIsOutgoingOneWay={prevIsOutgoingOneWay}\n" + $"\tjManager.IsUturnAllowed(prevSegmentId, " + - $"nextIsStartNode)={junctionManager.IsUturnAllowed(prevSegmentId, nextIsStartNode)}\n" + + $"nextIsStartNode)={junctionManager.GetValueOrDefault(prevSegmentId, nextIsStartNode, JunctionRestrictionFlags.AllowUTurn)}\n" + $"\tm_queueItem.vehicleId={queueItem_.vehicleId}\n" + $"\tm_queueItem.spawned={queueItem_.spawned}\n" + $"\tprevSegmentId={prevSegmentId}\n" + diff --git a/TLM/TLM/Manager/Impl/JunctionRestrictionsManager.cs b/TLM/TLM/Manager/Impl/JunctionRestrictionsManager.cs index cd43d3a12..2492ca036 100644 --- a/TLM/TLM/Manager/Impl/JunctionRestrictionsManager.cs +++ b/TLM/TLM/Manager/Impl/JunctionRestrictionsManager.cs @@ -369,10 +369,6 @@ public bool GetDefaultUturnAllowed(ushort segmentId, bool startNode, ref NetNode return ret; } - public bool IsUturnAllowed(ushort segmentId, bool startNode) { - return segmentRestrictions[segmentId].GetValueOrDefault(segmentId.AtNode(startNode), JunctionRestrictionFlags.AllowUTurn); - } - public bool IsNearTurnOnRedAllowedConfigurable(ushort segmentId, bool startNode, ref NetNode node) { @@ -446,20 +442,6 @@ public bool GetDefaultTurnOnRedAllowed(bool near, ushort segmentId, bool startNo return ret; } - public bool IsTurnOnRedAllowed(bool near, ushort segmentId, bool startNode) { - return near - ? IsNearTurnOnRedAllowed(segmentId, startNode) - : IsFarTurnOnRedAllowed(segmentId, startNode); - } - - public bool IsNearTurnOnRedAllowed(ushort segmentId, bool startNode) { - return segmentRestrictions[segmentId].GetValueOrDefault(segmentId.AtNode(startNode), JunctionRestrictionFlags.AllowNearTurnOnRed); - } - - public bool IsFarTurnOnRedAllowed(ushort segmentId, bool startNode) { - return segmentRestrictions[segmentId].GetValueOrDefault(segmentId.AtNode(startNode), JunctionRestrictionFlags.AllowFarTurnOnRed); - } - public bool IsLaneChangingAllowedWhenGoingStraightConfigurable( ushort segmentId, bool startNode, @@ -530,10 +512,6 @@ public bool GetDefaultLaneChangingAllowedWhenGoingStraight(ushort segmentId, boo return ret; } - public bool IsLaneChangingAllowedWhenGoingStraight(ushort segmentId, bool startNode) { - return segmentRestrictions[segmentId].GetValueOrDefault(segmentId.AtNode(startNode), JunctionRestrictionFlags.AllowForwardLaneChange); - } - public bool IsEnteringBlockedJunctionAllowedConfigurable( ushort segmentId, bool startNode, @@ -631,10 +609,6 @@ public bool GetDefaultEnteringBlockedJunctionAllowed( return ret; } - public bool IsEnteringBlockedJunctionAllowed(ushort segmentId, bool startNode) { - return segmentRestrictions[segmentId].GetValueOrDefault(segmentId.AtNode(startNode), JunctionRestrictionFlags.AllowEnterWhenBlocked); - } - public bool IsPedestrianCrossingAllowedConfigurable(ushort segmentId, bool startNode, ref NetNode node) { bool ret = (node.m_flags & (NetNode.Flags.Junction | NetNode.Flags.Bend)) != NetNode.Flags.None && node.Info?.m_class?.m_service != ItemClass.Service.Beautification; @@ -719,77 +693,6 @@ public bool GetDefaultPedestrianCrossingAllowed(ushort segmentId, bool startNode return ret; } - public bool IsPedestrianCrossingAllowed(ushort segmentId, bool startNode) { - return segmentRestrictions[segmentId].GetValueOrDefault(segmentId.AtNode(startNode), JunctionRestrictionFlags.AllowPedestrianCrossing); - } - - public bool? GetUturnAllowed(ushort segmentId, bool startNode) { - return segmentRestrictions[segmentId].GetValue(segmentId.AtNode(startNode), JunctionRestrictionFlags.AllowUTurn); - } - - public bool? GetNearTurnOnRedAllowed(ushort segmentId, bool startNode) { - return segmentRestrictions[segmentId].GetValue(segmentId.AtNode(startNode), JunctionRestrictionFlags.AllowNearTurnOnRed); - } - - public bool? GetFarTurnOnRedAllowed(ushort segmentId, bool startNode) { - return segmentRestrictions[segmentId].GetValue(segmentId.AtNode(startNode), JunctionRestrictionFlags.AllowFarTurnOnRed); - } - - public bool? GetTurnOnRedAllowed(bool near, ushort segmentId, bool startNode) { - return near - ? GetNearTurnOnRedAllowed(segmentId, startNode) - : GetFarTurnOnRedAllowed(segmentId, startNode); - } - - public bool? GetLaneChangingAllowedWhenGoingStraight(ushort segmentId, bool startNode) { - return segmentRestrictions[segmentId].GetValue(segmentId.AtNode(startNode), JunctionRestrictionFlags.AllowForwardLaneChange); - } - - public bool? GetEnteringBlockedJunctionAllowed(ushort segmentId, bool startNode) { - return segmentRestrictions[segmentId].GetValue(segmentId.AtNode(startNode), JunctionRestrictionFlags.AllowEnterWhenBlocked); - } - - public bool? GetPedestrianCrossingAllowed(ushort segmentId, bool startNode) { - return segmentRestrictions[segmentId].GetValue(segmentId.AtNode(startNode), JunctionRestrictionFlags.AllowPedestrianCrossing); - } - - public bool ToggleUturnAllowed(ushort segmentId, bool startNode) { - return SetUturnAllowed(segmentId, startNode, !IsUturnAllowed(segmentId, startNode)); - } - - public bool ToggleNearTurnOnRedAllowed(ushort segmentId, bool startNode) { - return ToggleTurnOnRedAllowed(true, segmentId, startNode); - } - - public bool ToggleFarTurnOnRedAllowed(ushort segmentId, bool startNode) { - return ToggleTurnOnRedAllowed(false, segmentId, startNode); - } - - public bool ToggleTurnOnRedAllowed(bool near, ushort segmentId, bool startNode) { - return SetTurnOnRedAllowed(near, segmentId, startNode, !IsTurnOnRedAllowed(near, segmentId, startNode)); - } - - public bool ToggleLaneChangingAllowedWhenGoingStraight(ushort segmentId, bool startNode) { - return SetLaneChangingAllowedWhenGoingStraight( - segmentId, - startNode, - !IsLaneChangingAllowedWhenGoingStraight(segmentId, startNode)); - } - - public bool ToggleEnteringBlockedJunctionAllowed(ushort segmentId, bool startNode) { - return SetEnteringBlockedJunctionAllowed( - segmentId, - startNode, - !IsEnteringBlockedJunctionAllowed(segmentId, startNode)); - } - - public bool TogglePedestrianCrossingAllowed(ushort segmentId, bool startNode) { - return SetPedestrianCrossingAllowed( - segmentId, - startNode, - !IsPedestrianCrossingAllowed(segmentId, startNode)); - } - public bool ClearSegmentEnd(ushort segmentId, bool startNode) { bool ret = true; ret |= SetPedestrianCrossingAllowed(segmentId, startNode, null); @@ -845,7 +748,7 @@ public bool SetUturnAllowed(ushort segmentId, bool startNode, bool? value) { if (!netSegment.IsValid()) { return false; } - if(GetUturnAllowed(segmentId, startNode) == value) { + if(GetValue(segmentId, startNode, JunctionRestrictionFlags.AllowUTurn) == value) { return true; } if(!IsUturnAllowedConfigurable(segmentId, startNode, ref GetNode(segmentId, startNode))) { @@ -881,7 +784,7 @@ public bool SetTurnOnRedAllowed(bool near, ushort segmentId, bool startNode, boo if (!netSegment.IsValid()) { return false; } - if (GetTurnOnRedAllowed(near, segmentId, startNode) == value) { + if (GetValue(segmentId, startNode, near ? JunctionRestrictionFlags.AllowNearTurnOnRed : JunctionRestrictionFlags.AllowFarTurnOnRed) == value) { return true; } if (!IsTurnOnRedAllowedConfigurable(near, segmentId, startNode, ref GetNode(segmentId, startNode))) { @@ -912,7 +815,7 @@ public bool SetLaneChangingAllowedWhenGoingStraight( if (!netSegment.IsValid()) { return false; } - if (GetLaneChangingAllowedWhenGoingStraight(segmentId, startNode) == value) { + if (GetValue(segmentId, startNode, JunctionRestrictionFlags.AllowForwardLaneChange) == value) { return true; } if (!IsLaneChangingAllowedWhenGoingStraightConfigurable(segmentId, startNode, ref GetNode(segmentId, startNode))) { @@ -934,7 +837,7 @@ public bool SetEnteringBlockedJunctionAllowed(ushort segmentId, bool startNode, if (!netSegment.IsValid()) { return false; } - if (GetEnteringBlockedJunctionAllowed(segmentId, startNode) == value) { + if (GetValue(segmentId, startNode, JunctionRestrictionFlags.AllowEnterWhenBlocked) == value) { return true; } if (!IsEnteringBlockedJunctionAllowedConfigurable(segmentId, startNode, ref GetNode(segmentId, startNode))) { @@ -958,7 +861,7 @@ public bool SetPedestrianCrossingAllowed(ushort segmentId, bool startNode, bool? if (!netSegment.IsValid()) { return false; } - if(GetPedestrianCrossingAllowed(segmentId, startNode) == value) { + if(GetValue(segmentId, startNode, JunctionRestrictionFlags.AllowPedestrianCrossing) == value) { return true; } if(!IsPedestrianCrossingAllowedConfigurable(segmentId, startNode, ref GetNode(segmentId, startNode))) { @@ -1209,13 +1112,12 @@ public bool LoadData(List data) { if (!endFlags.IsDefault(segmentId.AtStartNode())) { startNodeFlags = new Configuration.SegmentNodeFlags(); - startNodeFlags.uturnAllowed = - GetUturnAllowed(segmentId, true); - startNodeFlags.turnOnRedAllowed = GetNearTurnOnRedAllowed(segmentId, true); - startNodeFlags.farTurnOnRedAllowed = GetFarTurnOnRedAllowed(segmentId, true); - startNodeFlags.straightLaneChangingAllowed = GetLaneChangingAllowedWhenGoingStraight(segmentId, true); - startNodeFlags.enterWhenBlockedAllowed = GetEnteringBlockedJunctionAllowed(segmentId, true); - startNodeFlags.pedestrianCrossingAllowed = GetPedestrianCrossingAllowed(segmentId, true); + startNodeFlags.uturnAllowed = GetValue(segmentId, true, JunctionRestrictionFlags.AllowUTurn); + startNodeFlags.turnOnRedAllowed = GetValue(segmentId, true, JunctionRestrictionFlags.AllowNearTurnOnRed); + startNodeFlags.farTurnOnRedAllowed = GetValue(segmentId, true, JunctionRestrictionFlags.AllowFarTurnOnRed); + startNodeFlags.straightLaneChangingAllowed = GetValue(segmentId, true, JunctionRestrictionFlags.AllowForwardLaneChange); + startNodeFlags.enterWhenBlockedAllowed = GetValue(segmentId, true, JunctionRestrictionFlags.AllowEnterWhenBlocked); + startNodeFlags.pedestrianCrossingAllowed = GetValue(segmentId, true, JunctionRestrictionFlags.AllowPedestrianCrossing); #if DEBUGSAVE Log._Debug($"JunctionRestrictionsManager.SaveData: Saving start node "+ @@ -1232,13 +1134,12 @@ public bool LoadData(List data) { if (!restrictions.IsDefault(segmentId.AtEndNode())) { endNodeFlags = new Configuration.SegmentNodeFlags(); - endNodeFlags.uturnAllowed = - GetUturnAllowed(segmentId, false); - endNodeFlags.turnOnRedAllowed = GetNearTurnOnRedAllowed(segmentId, false); - endNodeFlags.farTurnOnRedAllowed = GetFarTurnOnRedAllowed(segmentId, false); - endNodeFlags.straightLaneChangingAllowed = GetLaneChangingAllowedWhenGoingStraight(segmentId, false); - endNodeFlags.enterWhenBlockedAllowed = GetEnteringBlockedJunctionAllowed(segmentId, false); - endNodeFlags.pedestrianCrossingAllowed = GetPedestrianCrossingAllowed(segmentId, false); + endNodeFlags.uturnAllowed = GetValue(segmentId, false, JunctionRestrictionFlags.AllowUTurn); + endNodeFlags.turnOnRedAllowed = GetValue(segmentId, false, JunctionRestrictionFlags.AllowNearTurnOnRed); + endNodeFlags.farTurnOnRedAllowed = GetValue(segmentId, false, JunctionRestrictionFlags.AllowFarTurnOnRed); + endNodeFlags.straightLaneChangingAllowed = GetValue(segmentId, false, JunctionRestrictionFlags.AllowForwardLaneChange); + endNodeFlags.enterWhenBlockedAllowed = GetValue(segmentId, false, JunctionRestrictionFlags.AllowEnterWhenBlocked); + endNodeFlags.pedestrianCrossingAllowed = GetValue(segmentId, false, JunctionRestrictionFlags.AllowPedestrianCrossing); #if DEBUGSAVE Log._Debug($"JunctionRestrictionsManager.SaveData: Saving end node junction "+ @@ -1370,25 +1271,7 @@ public bool ToggleValue(ushort segmentId, bool startNode, JunctionRestrictionFla if (flags == default || ((int)flags & ((int)flags - 1)) != 0) return false; - if (flags.IsFlagSet(JunctionRestrictionFlags.AllowUTurn)) - return ToggleUturnAllowed(segmentId, startNode); - - if (flags.IsFlagSet(JunctionRestrictionFlags.AllowNearTurnOnRed)) - return ToggleNearTurnOnRedAllowed(segmentId, startNode); - - if (flags.IsFlagSet(JunctionRestrictionFlags.AllowFarTurnOnRed)) - return ToggleFarTurnOnRedAllowed(segmentId, startNode); - - if (flags.IsFlagSet(JunctionRestrictionFlags.AllowForwardLaneChange)) - return ToggleLaneChangingAllowedWhenGoingStraight(segmentId, startNode); - - if (flags.IsFlagSet(JunctionRestrictionFlags.AllowEnterWhenBlocked)) - return ToggleEnteringBlockedJunctionAllowed(segmentId, startNode); - - if (flags.IsFlagSet(JunctionRestrictionFlags.AllowPedestrianCrossing)) - return TogglePedestrianCrossingAllowed(segmentId, startNode); - - return false; + return SetValue(segmentId, startNode, flags, !GetValueOrDefault(segmentId, startNode, flags)); } bool IJunctionRestrictionsManager.ToggleUturnAllowed(ushort segmentId, bool startNode) @@ -1480,13 +1363,12 @@ bool IJunctionRestrictionsManager.SetEnteringBlockedJunctionAllowed(ushort segme bool IJunctionRestrictionsManager.SetPedestrianCrossingAllowed(ushort segmentId, bool startNode, TernaryBool value) => SetValue(segmentId, startNode, JunctionRestrictionFlags.AllowPedestrianCrossing, ToOptBool(value)); - bool IJunctionRestrictionsManager.ClearSegmentEnd(ushort segmentId, bool startNode) { - throw new NotImplementedException(); - } - public bool? GetValue(ushort segmentId, bool startNode, JunctionRestrictionFlags flags) => segmentRestrictions[segmentId].GetValue(segmentId.AtNode(startNode), flags); + public bool GetValueOrDefault(ushort segmentId, bool startNode, JunctionRestrictionFlags flags) + => segmentRestrictions[segmentId].GetValueOrDefault(segmentId.AtNode(startNode), flags); + TernaryBool IJunctionRestrictionsManager.GetUturnAllowed(ushort segmentId, bool startNode) => ToTernaryBool(GetValue(segmentId, startNode, JunctionRestrictionFlags.AllowUTurn)); @@ -1508,6 +1390,27 @@ TernaryBool IJunctionRestrictionsManager.GetEnteringBlockedJunctionAllowed(ushor TernaryBool IJunctionRestrictionsManager.GetPedestrianCrossingAllowed(ushort segmentId, bool startNode) => ToTernaryBool(GetValue(segmentId, startNode, JunctionRestrictionFlags.AllowPedestrianCrossing)); + bool IJunctionRestrictionsManager.IsUturnAllowed(ushort segmentId, bool startNode) + => GetValueOrDefault(segmentId, startNode, JunctionRestrictionFlags.AllowUTurn); + + bool IJunctionRestrictionsManager.IsNearTurnOnRedAllowed(ushort segmentId, bool startNode) + => GetValueOrDefault(segmentId, startNode, JunctionRestrictionFlags.AllowNearTurnOnRed); + + bool IJunctionRestrictionsManager.IsFarTurnOnRedAllowed(ushort segmentId, bool startNode) + => GetValueOrDefault(segmentId, startNode, JunctionRestrictionFlags.AllowFarTurnOnRed); + + bool IJunctionRestrictionsManager.IsTurnOnRedAllowed(bool near, ushort segmentId, bool startNode) + => GetValueOrDefault(segmentId, startNode, near ? JunctionRestrictionFlags.AllowNearTurnOnRed : JunctionRestrictionFlags.AllowFarTurnOnRed); + + bool IJunctionRestrictionsManager.IsLaneChangingAllowedWhenGoingStraight(ushort segmentId, bool startNode) + => GetValueOrDefault(segmentId, startNode, JunctionRestrictionFlags.AllowForwardLaneChange); + + bool IJunctionRestrictionsManager.IsEnteringBlockedJunctionAllowed(ushort segmentId, bool startNode) + => GetValueOrDefault(segmentId, startNode, JunctionRestrictionFlags.AllowEnterWhenBlocked); + + bool IJunctionRestrictionsManager.IsPedestrianCrossingAllowed(ushort segmentId, bool startNode) + => GetValueOrDefault(segmentId, startNode, JunctionRestrictionFlags.AllowPedestrianCrossing); + private struct SegmentJunctionRestrictions { public JunctionRestrictions startNodeRestrictions; public JunctionRestrictions endNodeRestrictions; diff --git a/TLM/TLM/Manager/Impl/RoutingManager.cs b/TLM/TLM/Manager/Impl/RoutingManager.cs index 1df9449a5..d596260f4 100644 --- a/TLM/TLM/Manager/Impl/RoutingManager.cs +++ b/TLM/TLM/Manager/Impl/RoutingManager.cs @@ -988,9 +988,10 @@ private void RecalculateLaneEndRoutingData( hasRightArrow); } - bool hasUTurnRule = JunctionRestrictionsManager.Instance.IsUturnAllowed( + bool hasUTurnRule = JunctionRestrictionsManager.Instance.GetValueOrDefault( nextSegmentId, - isNodeStartNodeOfNextSegment); + isNodeStartNodeOfNextSegment, + JunctionRestrictionFlags.AllowUTurn); bool hasFarTurnArrow = (Shortcuts.LHT && hasRightArrow) || (Shortcuts.RHT && hasLeftArrow); bool canTurn = !nodeIsRealJunction || nodeIsEndOrOneWayOut || hasFarTurnArrow || hasUTurnRule; @@ -1159,8 +1160,8 @@ private void RecalculateLaneEndRoutingData( bool laneChangesAllowed = Options.junctionRestrictionsEnabled - && JunctionRestrictionsManager.Instance.IsLaneChangingAllowedWhenGoingStraight( - nextSegmentId, isNodeStartNodeOfNextSegment); + && JunctionRestrictionsManager.Instance.GetValueOrDefault( + nextSegmentId, isNodeStartNodeOfNextSegment, JunctionRestrictionFlags.AllowForwardLaneChange); int nextCompatibleLaneCount = numNextCompatibleTransitionDatas; if (nextCompatibleLaneCount > 0) { diff --git a/TLM/TLM/Manager/Impl/VehicleBehaviorManager.cs b/TLM/TLM/Manager/Impl/VehicleBehaviorManager.cs index 997b1ced5..7aba24eb8 100644 --- a/TLM/TLM/Manager/Impl/VehicleBehaviorManager.cs +++ b/TLM/TLM/Manager/Impl/VehicleBehaviorManager.cs @@ -1699,9 +1699,10 @@ protected bool MustCheckSpace(ushort segmentId, } else { if (Options.junctionRestrictionsEnabled) { checkSpace = - !JunctionRestrictionsManager.Instance.IsEnteringBlockedJunctionAllowed( + !JunctionRestrictionsManager.Instance.GetValueOrDefault( segmentId, - startNode); + startNode, + JunctionRestrictionFlags.AllowEnterWhenBlocked); } else { checkSpace = (node.m_flags & (NetNode.Flags.Junction diff --git a/TLM/TLM/UI/SubTools/ManualTrafficLightsTool.cs b/TLM/TLM/UI/SubTools/ManualTrafficLightsTool.cs index 5402a61eb..6ec00ea3f 100644 --- a/TLM/TLM/UI/SubTools/ManualTrafficLightsTool.cs +++ b/TLM/TLM/UI/SubTools/ManualTrafficLightsTool.cs @@ -116,9 +116,10 @@ public override void OnToolGUI(Event e) { } bool showPedLight = segmentLights.PedestrianLightState != null && - junctionRestrictionsManager.IsPedestrianCrossingAllowed( + junctionRestrictionsManager.GetValueOrDefault( segmentLights.SegmentId, - segmentLights.StartNode); + segmentLights.StartNode, + JunctionRestrictionFlags.AllowPedestrianCrossing); bool visible = GeometryUtil.WorldToScreenPoint(position, out Vector3 screenPos); if (!visible) { diff --git a/TLM/TLM/UI/SubTools/TTL/TimedTrafficLightsTool.cs b/TLM/TLM/UI/SubTools/TTL/TimedTrafficLightsTool.cs index 8b8d8e0e7..1443cf634 100644 --- a/TLM/TLM/UI/SubTools/TTL/TimedTrafficLightsTool.cs +++ b/TLM/TLM/UI/SubTools/TTL/TimedTrafficLightsTool.cs @@ -1495,9 +1495,10 @@ private void ShowGUI() { } bool showPedLight = liveSegmentLights.PedestrianLightState != null && - junctionRestrictionsManager.IsPedestrianCrossingAllowed( + junctionRestrictionsManager.GetValueOrDefault( liveSegmentLights.SegmentId, - liveSegmentLights.StartNode); + liveSegmentLights.StartNode, + JunctionRestrictionFlags.AllowPedestrianCrossing); bool timedActive = timedNode.IsStarted(); if (!timedActive) { diff --git a/TLM/TLM/Util/Record/SegmentEndRecord.cs b/TLM/TLM/Util/Record/SegmentEndRecord.cs index c8b06f520..42269045e 100644 --- a/TLM/TLM/Util/Record/SegmentEndRecord.cs +++ b/TLM/TLM/Util/Record/SegmentEndRecord.cs @@ -40,12 +40,12 @@ public SegmentEndRecord(ushort segmentId, bool startNode) { private static JunctionRestrictionsManager JRMan => JunctionRestrictionsManager.Instance; public void Record() { - uturnAllowed_ = ToTernaryBool(JRMan.GetUturnAllowed(SegmentId, StartNode)); - nearTurnOnRedAllowed_ = ToTernaryBool(JRMan.GetNearTurnOnRedAllowed(SegmentId, StartNode)); - farTurnOnRedAllowed_ = ToTernaryBool(JRMan.GetFarTurnOnRedAllowed(SegmentId, StartNode)); - laneChangingAllowedWhenGoingStraight_ = ToTernaryBool(JRMan.GetLaneChangingAllowedWhenGoingStraight(SegmentId, StartNode)); - enteringBlockedJunctionAllowed_ = ToTernaryBool(JRMan.GetEnteringBlockedJunctionAllowed(SegmentId, StartNode)); - pedestrianCrossingAllowed_ = ToTernaryBool(JRMan.GetPedestrianCrossingAllowed(SegmentId, StartNode)); + uturnAllowed_ = ToTernaryBool(JRMan.GetValueOrDefault(SegmentId, StartNode, JunctionRestrictionFlags.AllowUTurn)); + nearTurnOnRedAllowed_ = ToTernaryBool(JRMan.GetValueOrDefault(SegmentId, StartNode, JunctionRestrictionFlags.AllowNearTurnOnRed)); + farTurnOnRedAllowed_ = ToTernaryBool(JRMan.GetValueOrDefault(SegmentId, StartNode, JunctionRestrictionFlags.AllowFarTurnOnRed)); + laneChangingAllowedWhenGoingStraight_ = ToTernaryBool(JRMan.GetValueOrDefault(SegmentId, StartNode, JunctionRestrictionFlags.AllowForwardLaneChange)); + enteringBlockedJunctionAllowed_ = ToTernaryBool(JRMan.GetValueOrDefault(SegmentId, StartNode, JunctionRestrictionFlags.AllowEnterWhenBlocked)); + pedestrianCrossingAllowed_ = ToTernaryBool(JRMan.GetValueOrDefault(SegmentId, StartNode, JunctionRestrictionFlags.AllowPedestrianCrossing)); prioirtySign_ = priorityMan.GetPrioritySign(SegmentId, StartNode); From a9cfa050ddc58816290d8a672602d17c4ac3c029 Mon Sep 17 00:00:00 2001 From: Elesbaan70 <95266227+Elesbaan70@users.noreply.github.com> Date: Fri, 27 May 2022 17:25:50 -0500 Subject: [PATCH 09/21] FlagsAttribute missing from JunctionRestrictionFlags --- TLM/TMPE.API/Traffic/Enums/JunctionRestrictionFlags.cs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/TLM/TMPE.API/Traffic/Enums/JunctionRestrictionFlags.cs b/TLM/TMPE.API/Traffic/Enums/JunctionRestrictionFlags.cs index 5e3b7bd38..b36728013 100644 --- a/TLM/TMPE.API/Traffic/Enums/JunctionRestrictionFlags.cs +++ b/TLM/TMPE.API/Traffic/Enums/JunctionRestrictionFlags.cs @@ -1,4 +1,8 @@ +using System; + namespace TrafficManager.API.Traffic.Enums { + + [Flags] public enum JunctionRestrictionFlags { AllowUTurn = 1 << 0, AllowNearTurnOnRed = 1 << 1, From 3c139af5ac039a0bb8e2dc7e63ab9c69b8d9edd9 Mon Sep 17 00:00:00 2001 From: Elesbaan70 <95266227+Elesbaan70@users.noreply.github.com> Date: Fri, 27 May 2022 18:08:13 -0500 Subject: [PATCH 10/21] Lazy update of default values --- .../Impl/JunctionRestrictionsManager.cs | 101 ++++++++++-------- .../Traffic/Enums/JunctionRestrictionFlags.cs | 2 + 2 files changed, 60 insertions(+), 43 deletions(-) diff --git a/TLM/TLM/Manager/Impl/JunctionRestrictionsManager.cs b/TLM/TLM/Manager/Impl/JunctionRestrictionsManager.cs index 2492ca036..a67fac2a8 100644 --- a/TLM/TLM/Manager/Impl/JunctionRestrictionsManager.cs +++ b/TLM/TLM/Manager/Impl/JunctionRestrictionsManager.cs @@ -180,7 +180,7 @@ private void HandleInvalidSegment(ref ExtSegment seg, bool startNode) { } protected override void HandleValidSegment(ref ExtSegment seg) { - UpdateDefaults(ref seg); + segmentRestrictions[seg.segmentId].Invalidate(seg.segmentId); } /// @@ -290,12 +290,12 @@ private void UpdateDefaults(ref ExtSegmentEnd segEnd, "defaultEnterWhenBlockedAllowed={6}, defaultPedestrianCrossingAllowed={7}", segEnd.segmentId, segEnd.startNode, - restrictions.GetDefault(segmentEndId, JunctionRestrictionFlags.AllowUTurn), - restrictions.GetDefault(segmentEndId, JunctionRestrictionFlags.AllowNearTurnOnRed), - restrictions.GetDefault(segmentEndId, JunctionRestrictionFlags.AllowFarTurnOnRed), - restrictions.GetDefault(segmentEndId, JunctionRestrictionFlags.AllowForwardLaneChange), - restrictions.GetDefault(segmentEndId, JunctionRestrictionFlags.AllowEnterWhenBlocked), - restrictions.GetDefault(segmentEndId, JunctionRestrictionFlags.AllowPedestrianCrossing)); + restrictions.GetDefaultValue(segmentEndId, JunctionRestrictionFlags.AllowUTurn), + restrictions.GetDefaultValue(segmentEndId, JunctionRestrictionFlags.AllowNearTurnOnRed), + restrictions.GetDefaultValue(segmentEndId, JunctionRestrictionFlags.AllowFarTurnOnRed), + restrictions.GetDefaultValue(segmentEndId, JunctionRestrictionFlags.AllowForwardLaneChange), + restrictions.GetDefaultValue(segmentEndId, JunctionRestrictionFlags.AllowEnterWhenBlocked), + restrictions.GetDefaultValue(segmentEndId, JunctionRestrictionFlags.AllowPedestrianCrossing)); } #endif Notifier.Instance.OnNodeModified(segEnd.nodeId, this); @@ -330,7 +330,7 @@ public bool IsUturnAllowedConfigurable(ushort segmentId, bool startNode, ref Net return ret; } - public bool GetDefaultUturnAllowed(ushort segmentId, bool startNode, ref NetNode node) { + private bool GetDefaultUturnAllowed(ushort segmentId, bool startNode, ref NetNode node) { #if DEBUG bool logLogic = DebugSwitch.JunctionRestrictions.Get(); #else @@ -403,19 +403,19 @@ public bool IsTurnOnRedAllowedConfigurable(bool near, return ret; } - public bool GetDefaultNearTurnOnRedAllowed(ushort segmentId, + private bool GetDefaultNearTurnOnRedAllowed(ushort segmentId, bool startNode, ref NetNode node) { return GetDefaultTurnOnRedAllowed(true, segmentId, startNode, ref node); } - public bool GetDefaultFarTurnOnRedAllowed(ushort segmentId, + private bool GetDefaultFarTurnOnRedAllowed(ushort segmentId, bool startNode, ref NetNode node) { return GetDefaultTurnOnRedAllowed(false, segmentId, startNode, ref node); } - public bool GetDefaultTurnOnRedAllowed(bool near, ushort segmentId, bool startNode, ref NetNode node) { + private bool GetDefaultTurnOnRedAllowed(bool near, ushort segmentId, bool startNode, ref NetNode node) { #if DEBUG bool logLogic = DebugSwitch.JunctionRestrictions.Get(); #else @@ -480,7 +480,7 @@ public bool IsLaneChangingAllowedWhenGoingStraightConfigurable( return ret; } - public bool GetDefaultLaneChangingAllowedWhenGoingStraight(ushort segmentId, bool startNode, ref NetNode node) { + private bool GetDefaultLaneChangingAllowedWhenGoingStraight(ushort segmentId, bool startNode, ref NetNode node) { #if DEBUG bool logLogic = DebugSwitch.JunctionRestrictions.Get(); #else @@ -547,7 +547,7 @@ public bool IsEnteringBlockedJunctionAllowedConfigurable( return ret; } - public bool GetDefaultEnteringBlockedJunctionAllowed( + private bool GetDefaultEnteringBlockedJunctionAllowed( ushort segmentId, bool startNode, ref NetNode node) { @@ -623,7 +623,7 @@ public bool IsPedestrianCrossingAllowedConfigurable(ushort segmentId, bool start return ret; } - public bool GetDefaultPedestrianCrossingAllowed(ushort segmentId, bool startNode, ref NetNode node) { + private bool GetDefaultPedestrianCrossingAllowed(ushort segmentId, bool startNode, ref NetNode node) { #if DEBUG bool logLogic = DebugSwitch.JunctionRestrictions.Get(); #else @@ -1217,33 +1217,8 @@ bool IJunctionRestrictionsManager.IsEnteringBlockedJunctionAllowedConfigurable(u bool IJunctionRestrictionsManager.IsPedestrianCrossingAllowedConfigurable(ushort segmentId, bool startNode, ref NetNode node) => IsConfigurable(segmentId, startNode, JunctionRestrictionFlags.AllowPedestrianCrossing); - public bool GetDefaultValue(ushort segmentId, bool startNode, JunctionRestrictionFlags flags) { - - if (flags == default) - return false; - - ref var node = ref segmentId.ToSegment().GetNodeId(startNode).ToNode(); - - if (flags.IsFlagSet(JunctionRestrictionFlags.AllowUTurn) && !GetDefaultUturnAllowed(segmentId, startNode, ref node)) - return false; - - if (flags.IsFlagSet(JunctionRestrictionFlags.AllowNearTurnOnRed) && !GetDefaultNearTurnOnRedAllowed(segmentId, startNode, ref node)) - return false; - - if (flags.IsFlagSet(JunctionRestrictionFlags.AllowFarTurnOnRed) && !GetDefaultFarTurnOnRedAllowed(segmentId, startNode, ref node)) - return false; - - if (flags.IsFlagSet(JunctionRestrictionFlags.AllowForwardLaneChange) && !GetDefaultLaneChangingAllowedWhenGoingStraight(segmentId, startNode, ref node)) - return false; - - if (flags.IsFlagSet(JunctionRestrictionFlags.AllowEnterWhenBlocked) && !GetDefaultEnteringBlockedJunctionAllowed(segmentId, startNode, ref node)) - return false; - - if (flags.IsFlagSet(JunctionRestrictionFlags.AllowPedestrianCrossing) && !GetDefaultPedestrianCrossingAllowed(segmentId, startNode, ref node)) - return false; - - return true; - } + public bool GetDefaultValue(ushort segmentId, bool startNode, JunctionRestrictionFlags flags) + => segmentRestrictions[segmentId].GetDefaultValue(segmentId.AtNode(startNode), flags); bool IJunctionRestrictionsManager.GetDefaultUturnAllowed(ushort segmentId, bool startNode, ref NetNode node) => GetDefaultValue(segmentId, startNode, JunctionRestrictionFlags.AllowUTurn); @@ -1423,6 +1398,10 @@ public bool GetValueOrDefault(SegmentEndId segmentEndId, JunctionRestrictionFlag return (segmentEndId.StartNode ? startNodeRestrictions : endNodeRestrictions).GetValue(segmentEndId, flags); } + public bool GetDefaultValue(SegmentEndId segmentEndId, JunctionRestrictionFlags flags) { + return (segmentEndId.StartNode ? startNodeRestrictions : endNodeRestrictions).GetDefaultValue(segmentEndId, flags); + } + public void SetValue(SegmentEndId segmentEndId, JunctionRestrictionFlags flags, bool? value) { if (segmentEndId.StartNode) startNodeRestrictions.SetValue(segmentEndId, flags, value); @@ -1446,6 +1425,11 @@ public void Reset(ushort segmentId) { Reset(segmentId.AtEndNode()); } + public void Invalidate(ushort segmentId) { + startNodeRestrictions.Invalidate(segmentId.AtStartNode()); + endNodeRestrictions.Invalidate(segmentId.AtEndNode()); + } + public override string ToString() { return "[SegmentJunctionRestrictions\n" + $"\tstartNodeRestrictions = {startNodeRestrictions}\n" + @@ -1462,6 +1446,8 @@ private struct JunctionRestrictions { private JunctionRestrictionFlags defaults; + private JunctionRestrictionFlags valid; + public void ClearValue(SegmentEndId segmentEndId, JunctionRestrictionFlags flags) { values &= ~flags; mask &= ~flags; @@ -1474,7 +1460,8 @@ public void SetDefault(SegmentEndId segmentEndId, JunctionRestrictionFlags flags defaults &= ~flags; } - public bool GetDefault(SegmentEndId segmentEndId, JunctionRestrictionFlags flags) { + public bool GetDefaultValue(SegmentEndId segmentEndId, JunctionRestrictionFlags flags) { + Recalculate(segmentEndId); return (defaults & flags) == flags; } @@ -1491,6 +1478,7 @@ public bool HasValue(SegmentEndId segmentEndId, JunctionRestrictionFlags flags) } public bool GetValueOrDefault(SegmentEndId segmentEndId, JunctionRestrictionFlags flags) { + Recalculate(segmentEndId); return ((values & flags & mask) | (defaults & flags & ~mask)) == flags; } @@ -1508,17 +1496,44 @@ public void SetValue(SegmentEndId segmentEndId, JunctionRestrictionFlags flags, } public bool IsDefault(SegmentEndId segmentEndId) { + Recalculate(segmentEndId); return ((values & mask) | (defaults & ~mask)) == defaults; } + private delegate bool CalculateDefault(ushort segmentId, bool startNode, ref NetNode node); + + private void Recalculate(SegmentEndId segmentEndId, JunctionRestrictionFlags flags, CalculateDefault calculateDefault) { + if ((valid & flags) != flags) { + SetDefault(segmentEndId, flags, calculateDefault(segmentEndId.SegmentId, segmentEndId.StartNode, ref segmentEndId.GetNode())); + valid |= flags; + } + } + + private void Recalculate(SegmentEndId segmentEndId) { + + if ((valid & JunctionRestrictionFlags.All) != JunctionRestrictionFlags.All) { + + Recalculate(segmentEndId, JunctionRestrictionFlags.AllowUTurn, Instance.GetDefaultUturnAllowed); + Recalculate(segmentEndId, JunctionRestrictionFlags.AllowNearTurnOnRed, Instance.GetDefaultNearTurnOnRedAllowed); + Recalculate(segmentEndId, JunctionRestrictionFlags.AllowFarTurnOnRed, Instance.GetDefaultFarTurnOnRedAllowed); + Recalculate(segmentEndId, JunctionRestrictionFlags.AllowForwardLaneChange, Instance.GetDefaultLaneChangingAllowedWhenGoingStraight); + Recalculate(segmentEndId, JunctionRestrictionFlags.AllowEnterWhenBlocked, Instance.GetDefaultEnteringBlockedJunctionAllowed); + Recalculate(segmentEndId, JunctionRestrictionFlags.AllowPedestrianCrossing, Instance.GetDefaultPedestrianCrossingAllowed); + } + } + public void Reset(SegmentEndId segmentEndId, bool resetDefaults = true) { values = mask = default; if (resetDefaults) { - defaults = default; + valid = default; } } + public void Invalidate(SegmentEndId segmentEndId) { + valid = default; + } + public override string ToString() { return string.Format( $"[JunctionRestrictions\n\tvalues = {values}\n\tmask = {mask}\n" + diff --git a/TLM/TMPE.API/Traffic/Enums/JunctionRestrictionFlags.cs b/TLM/TMPE.API/Traffic/Enums/JunctionRestrictionFlags.cs index b36728013..3a4059e5b 100644 --- a/TLM/TMPE.API/Traffic/Enums/JunctionRestrictionFlags.cs +++ b/TLM/TMPE.API/Traffic/Enums/JunctionRestrictionFlags.cs @@ -10,5 +10,7 @@ public enum JunctionRestrictionFlags { AllowForwardLaneChange = 1 << 3, AllowEnterWhenBlocked = 1 << 4, AllowPedestrianCrossing = 1 << 5, + + All = (1 << 6) - 1, } } From fca9d2505cab155df2b8d7bbd8775c397c86aee7 Mon Sep 17 00:00:00 2001 From: Elesbaan70 <95266227+Elesbaan70@users.noreply.github.com> Date: Fri, 27 May 2022 19:20:55 -0500 Subject: [PATCH 11/21] Cache configurable calculations --- .../Impl/JunctionRestrictionsManager.cs | 235 +++++------------- 1 file changed, 63 insertions(+), 172 deletions(-) diff --git a/TLM/TLM/Manager/Impl/JunctionRestrictionsManager.cs b/TLM/TLM/Manager/Impl/JunctionRestrictionsManager.cs index a67fac2a8..290562596 100644 --- a/TLM/TLM/Manager/Impl/JunctionRestrictionsManager.cs +++ b/TLM/TLM/Manager/Impl/JunctionRestrictionsManager.cs @@ -71,10 +71,7 @@ protected override void HandleSegmentEndReplacement(SegmentEndReplacement replac orphanedRestrictions[oldSegmentEndId.SegmentId].endNodeRestrictions.Reset(oldSegmentEndId.FromApi()); } - UpdateDefaults( - ref segEndMan.ExtSegmentEnds[segEndMan.GetIndex(newSegmentEndId.SegmentId, newSegmentEndId.StartNode)], - ref restrictions, - ref segEnd.nodeId.ToNode()); + GetJunctionRestrictions(newSegmentEndId.FromApi()).Invalidate(newSegmentEndId.FromApi()); Log._Debug( $"JunctionRestrictionsManager.HandleSegmentEndReplacement({replacement}): " + @@ -188,120 +185,17 @@ protected override void HandleValidSegment(ref ExtSegment seg) { /// TODO [issue #1116]: publish segment changes? if so it should be done only when policy changes not when deserializing. /// public void UpdateAllDefaults() { - ExtSegmentManager extSegmentManager = ExtSegmentManager.Instance; + for (ushort segmentId = 0; segmentId < NetManager.MAX_SEGMENT_COUNT; ++segmentId) { - ref NetSegment netSegment = ref segmentId.ToSegment(); - if (!netSegment.IsValid()) { + if (!segmentId.ToSegment().IsValid()) { continue; } - - UpdateDefaults(ref extSegmentManager.ExtSegments[segmentId]); - } - } - - private void UpdateDefaults(ref ExtSegment seg) { - ushort segmentId = seg.segmentId; - ref NetSegment netSegment = ref segmentId.ToSegment(); - IExtSegmentEndManager segEndMan = Constants.ManagerFactory.ExtSegmentEndManager; - - UpdateDefaults( - ref segEndMan.ExtSegmentEnds[segEndMan.GetIndex(segmentId, true)], - ref segmentRestrictions[segmentId].startNodeRestrictions, - ref netSegment.m_startNode.ToNode()); - - UpdateDefaults( - ref segEndMan.ExtSegmentEnds[segEndMan.GetIndex(segmentId, false)], - ref segmentRestrictions[segmentId].endNodeRestrictions, - ref netSegment.m_endNode.ToNode()); - } - - private void UpdateDefaults(ref ExtSegmentEnd segEnd, - ref JunctionRestrictions restrictions, - ref NetNode node) { - - var segmentEndId = segEnd.GetSegmentEndId(); - - if (!IsUturnAllowedConfigurable(segEnd.segmentId, segEnd.startNode, ref node)) { - restrictions.ClearValue(segmentEndId, JunctionRestrictionFlags.AllowUTurn); - } - - if (!IsNearTurnOnRedAllowedConfigurable(segEnd.segmentId, segEnd.startNode, ref node)) { - restrictions.ClearValue(segmentEndId, JunctionRestrictionFlags.AllowNearTurnOnRed); + segmentRestrictions[segmentId].Invalidate(segmentId); } - - if (!IsFarTurnOnRedAllowedConfigurable(segEnd.segmentId, segEnd.startNode, ref node)) { - restrictions.ClearValue(segmentEndId, JunctionRestrictionFlags.AllowFarTurnOnRed); - } - - if (!IsLaneChangingAllowedWhenGoingStraightConfigurable( - segEnd.segmentId, - segEnd.startNode, - ref node)) { - restrictions.ClearValue(segmentEndId, JunctionRestrictionFlags.AllowForwardLaneChange); - } - - if (!IsEnteringBlockedJunctionAllowedConfigurable( - segEnd.segmentId, - segEnd.startNode, - ref node)) { - restrictions.ClearValue(segmentEndId, JunctionRestrictionFlags.AllowEnterWhenBlocked); - } - - if (!IsPedestrianCrossingAllowedConfigurable( - segEnd.segmentId, - segEnd.startNode, - ref node)) { - restrictions.ClearValue(segmentEndId, JunctionRestrictionFlags.AllowPedestrianCrossing); - } - - restrictions.SetDefault(segmentEndId, JunctionRestrictionFlags.AllowUTurn, GetDefaultUturnAllowed( - segEnd.segmentId, - segEnd.startNode, - ref node)); - restrictions.SetDefault(segmentEndId, JunctionRestrictionFlags.AllowNearTurnOnRed, GetDefaultNearTurnOnRedAllowed( - segEnd.segmentId, - segEnd.startNode, - ref node)); - restrictions.SetDefault(segmentEndId, JunctionRestrictionFlags.AllowFarTurnOnRed, GetDefaultFarTurnOnRedAllowed( - segEnd.segmentId, - segEnd.startNode, - ref node)); - restrictions.SetDefault(segmentEndId, JunctionRestrictionFlags.AllowForwardLaneChange, - GetDefaultLaneChangingAllowedWhenGoingStraight( - segEnd.segmentId, - segEnd.startNode, - ref node)); - restrictions.SetDefault(segmentEndId, JunctionRestrictionFlags.AllowEnterWhenBlocked, GetDefaultEnteringBlockedJunctionAllowed( - segEnd.segmentId, - segEnd.startNode, - ref node)); - restrictions.SetDefault(segmentEndId, JunctionRestrictionFlags.AllowPedestrianCrossing, GetDefaultPedestrianCrossingAllowed( - segEnd.segmentId, - segEnd.startNode, - ref node)); - -#if DEBUG - if (DebugSwitch.JunctionRestrictions.Get()) { - Log._DebugFormat( - "JunctionRestrictionsManager.UpdateDefaults({0}, {1}): Set defaults: " + - "defaultUturnAllowed={2}, defaultNearTurnOnRedAllowed={3}, " + - "defaultFarTurnOnRedAllowed={4}, defaultStraightLaneChangingAllowed={5}, " + - "defaultEnterWhenBlockedAllowed={6}, defaultPedestrianCrossingAllowed={7}", - segEnd.segmentId, - segEnd.startNode, - restrictions.GetDefaultValue(segmentEndId, JunctionRestrictionFlags.AllowUTurn), - restrictions.GetDefaultValue(segmentEndId, JunctionRestrictionFlags.AllowNearTurnOnRed), - restrictions.GetDefaultValue(segmentEndId, JunctionRestrictionFlags.AllowFarTurnOnRed), - restrictions.GetDefaultValue(segmentEndId, JunctionRestrictionFlags.AllowForwardLaneChange), - restrictions.GetDefaultValue(segmentEndId, JunctionRestrictionFlags.AllowEnterWhenBlocked), - restrictions.GetDefaultValue(segmentEndId, JunctionRestrictionFlags.AllowPedestrianCrossing)); - } -#endif - Notifier.Instance.OnNodeModified(segEnd.nodeId, this); } - public bool IsUturnAllowedConfigurable(ushort segmentId, bool startNode, ref NetNode node) { + private bool IsUturnAllowedConfigurable(ushort segmentId, bool startNode, ref NetNode node) { ref NetSegment netSegment = ref segmentId.ToSegment(); if (!netSegment.IsValid()) { @@ -330,17 +224,14 @@ public bool IsUturnAllowedConfigurable(ushort segmentId, bool startNode, ref Net return ret; } - private bool GetDefaultUturnAllowed(ushort segmentId, bool startNode, ref NetNode node) { + private bool GetDefaultUturnAllowed(ushort segmentId, bool startNode, ref NetNode node, bool isConfigurable) { #if DEBUG bool logLogic = DebugSwitch.JunctionRestrictions.Get(); #else const bool logLogic = false; #endif - if (!Constants.ManagerFactory.JunctionRestrictionsManager.IsUturnAllowedConfigurable( - segmentId, - startNode, - ref node)) { + if (!isConfigurable) { bool res = (node.m_flags & (NetNode.Flags.End | NetNode.Flags.OneWayOut)) != NetNode.Flags.None; if (logLogic) { @@ -369,19 +260,19 @@ private bool GetDefaultUturnAllowed(ushort segmentId, bool startNode, ref NetNod return ret; } - public bool IsNearTurnOnRedAllowedConfigurable(ushort segmentId, + private bool IsNearTurnOnRedAllowedConfigurable(ushort segmentId, bool startNode, ref NetNode node) { return IsTurnOnRedAllowedConfigurable(true, segmentId, startNode, ref node); } - public bool IsFarTurnOnRedAllowedConfigurable(ushort segmentId, + private bool IsFarTurnOnRedAllowedConfigurable(ushort segmentId, bool startNode, ref NetNode node) { return IsTurnOnRedAllowedConfigurable(false, segmentId, startNode, ref node); } - public bool IsTurnOnRedAllowedConfigurable(bool near, + private bool IsTurnOnRedAllowedConfigurable(bool near, ushort segmentId, bool startNode, ref NetNode node) { @@ -405,24 +296,26 @@ public bool IsTurnOnRedAllowedConfigurable(bool near, private bool GetDefaultNearTurnOnRedAllowed(ushort segmentId, bool startNode, - ref NetNode node) { - return GetDefaultTurnOnRedAllowed(true, segmentId, startNode, ref node); + ref NetNode node, + bool isConfigurable) { + return GetDefaultTurnOnRedAllowed(true, segmentId, startNode, ref node, isConfigurable); } private bool GetDefaultFarTurnOnRedAllowed(ushort segmentId, bool startNode, - ref NetNode node) { - return GetDefaultTurnOnRedAllowed(false, segmentId, startNode, ref node); + ref NetNode node, + bool isConfigurable) { + return GetDefaultTurnOnRedAllowed(false, segmentId, startNode, ref node, isConfigurable); } - private bool GetDefaultTurnOnRedAllowed(bool near, ushort segmentId, bool startNode, ref NetNode node) { + private bool GetDefaultTurnOnRedAllowed(bool near, ushort segmentId, bool startNode, ref NetNode node, bool isConfigurable) { #if DEBUG bool logLogic = DebugSwitch.JunctionRestrictions.Get(); #else const bool logLogic = false; #endif - if (!IsTurnOnRedAllowedConfigurable(near, segmentId, startNode, ref node)) { + if (!isConfigurable) { if (logLogic) { Log._Debug( $"JunctionRestrictionsManager.IsTurnOnRedAllowedConfigurable({near}, " + @@ -442,7 +335,7 @@ private bool GetDefaultTurnOnRedAllowed(bool near, ushort segmentId, bool startN return ret; } - public bool IsLaneChangingAllowedWhenGoingStraightConfigurable( + private bool IsLaneChangingAllowedWhenGoingStraightConfigurable( ushort segmentId, bool startNode, ref NetNode node) { @@ -480,18 +373,14 @@ public bool IsLaneChangingAllowedWhenGoingStraightConfigurable( return ret; } - private bool GetDefaultLaneChangingAllowedWhenGoingStraight(ushort segmentId, bool startNode, ref NetNode node) { + private bool GetDefaultLaneChangingAllowedWhenGoingStraight(ushort segmentId, bool startNode, ref NetNode node, bool isConfigurable) { #if DEBUG bool logLogic = DebugSwitch.JunctionRestrictions.Get(); #else const bool logLogic = false; #endif - if (!Constants.ManagerFactory.JunctionRestrictionsManager - .IsLaneChangingAllowedWhenGoingStraightConfigurable( - segmentId, - startNode, - ref node)) { + if (!isConfigurable) { if (logLogic) { Log._Debug( "JunctionRestrictionsManager.GetDefaultLaneChangingAllowedWhenGoingStraight" + @@ -512,7 +401,7 @@ private bool GetDefaultLaneChangingAllowedWhenGoingStraight(ushort segmentId, bo return ret; } - public bool IsEnteringBlockedJunctionAllowedConfigurable( + private bool IsEnteringBlockedJunctionAllowedConfigurable( ushort segmentId, bool startNode, ref NetNode node) { @@ -550,7 +439,8 @@ public bool IsEnteringBlockedJunctionAllowedConfigurable( private bool GetDefaultEnteringBlockedJunctionAllowed( ushort segmentId, bool startNode, - ref NetNode node) { + ref NetNode node, + bool isConfigurable) { #if DEBUG bool logLogic = DebugSwitch.JunctionRestrictions.Get(); #else @@ -562,7 +452,7 @@ private bool GetDefaultEnteringBlockedJunctionAllowed( return false; } - if (!IsEnteringBlockedJunctionAllowedConfigurable(segmentId, startNode, ref node)) { + if (!isConfigurable) { bool res = (node.m_flags & (NetNode.Flags.Junction | NetNode.Flags.OneWayOut | NetNode.Flags.OneWayIn)) != NetNode.Flags.Junction || @@ -609,7 +499,7 @@ private bool GetDefaultEnteringBlockedJunctionAllowed( return ret; } - public bool IsPedestrianCrossingAllowedConfigurable(ushort segmentId, bool startNode, ref NetNode node) { + private bool IsPedestrianCrossingAllowedConfigurable(ushort segmentId, bool startNode, ref NetNode node) { bool ret = (node.m_flags & (NetNode.Flags.Junction | NetNode.Flags.Bend)) != NetNode.Flags.None && node.Info?.m_class?.m_service != ItemClass.Service.Beautification; #if DEBUG @@ -623,14 +513,14 @@ public bool IsPedestrianCrossingAllowedConfigurable(ushort segmentId, bool start return ret; } - private bool GetDefaultPedestrianCrossingAllowed(ushort segmentId, bool startNode, ref NetNode node) { + private bool GetDefaultPedestrianCrossingAllowed(ushort segmentId, bool startNode, ref NetNode node, bool isConfigurable) { #if DEBUG bool logLogic = DebugSwitch.JunctionRestrictions.Get(); #else const bool logLogic = false; #endif - if (!IsPedestrianCrossingAllowedConfigurable(segmentId, startNode, ref node)) { + if (!isConfigurable) { if (logLogic) { Log._Debug( "JunctionRestrictionsManager.GetDefaultPedestrianCrossingAllowed" + @@ -1171,30 +1061,8 @@ public bool LoadData(List data) { return ret; } - public bool IsConfigurable(ushort segmentId, bool startNode, JunctionRestrictionFlags flags) { - - ref var node = ref segmentId.ToSegment().GetNodeId(startNode).ToNode(); - - if (flags.IsFlagSet(JunctionRestrictionFlags.AllowUTurn) && !IsUturnAllowedConfigurable(segmentId, startNode, ref node)) - return false; - - if (flags.IsFlagSet(JunctionRestrictionFlags.AllowNearTurnOnRed) && !IsNearTurnOnRedAllowedConfigurable(segmentId, startNode, ref node)) - return false; - - if (flags.IsFlagSet(JunctionRestrictionFlags.AllowFarTurnOnRed) && !IsFarTurnOnRedAllowedConfigurable(segmentId, startNode, ref node)) - return false; - - if (flags.IsFlagSet(JunctionRestrictionFlags.AllowForwardLaneChange) && !IsLaneChangingAllowedWhenGoingStraightConfigurable(segmentId, startNode, ref node)) - return false; - - if (flags.IsFlagSet(JunctionRestrictionFlags.AllowEnterWhenBlocked) && !IsEnteringBlockedJunctionAllowedConfigurable(segmentId, startNode, ref node)) - return false; - - if (flags.IsFlagSet(JunctionRestrictionFlags.AllowPedestrianCrossing) && !IsPedestrianCrossingAllowedConfigurable(segmentId, startNode, ref node)) - return false; - - return true; - } + public bool IsConfigurable(ushort segmentId, bool startNode, JunctionRestrictionFlags flags) + => segmentRestrictions[segmentId].IsConfigurable(segmentId.AtNode(startNode), flags); bool IJunctionRestrictionsManager.IsUturnAllowedConfigurable(ushort segmentId, bool startNode, ref NetNode node) => IsConfigurable(segmentId, startNode, JunctionRestrictionFlags.AllowUTurn); @@ -1402,6 +1270,10 @@ public bool GetDefaultValue(SegmentEndId segmentEndId, JunctionRestrictionFlags return (segmentEndId.StartNode ? startNodeRestrictions : endNodeRestrictions).GetDefaultValue(segmentEndId, flags); } + public bool IsConfigurable(SegmentEndId segmentEndId, JunctionRestrictionFlags flags) { + return (segmentEndId.StartNode ? startNodeRestrictions : endNodeRestrictions).IsConfigurable(segmentEndId, flags); + } + public void SetValue(SegmentEndId segmentEndId, JunctionRestrictionFlags flags, bool? value) { if (segmentEndId.StartNode) startNodeRestrictions.SetValue(segmentEndId, flags, value); @@ -1428,6 +1300,7 @@ public void Reset(ushort segmentId) { public void Invalidate(ushort segmentId) { startNodeRestrictions.Invalidate(segmentId.AtStartNode()); endNodeRestrictions.Invalidate(segmentId.AtEndNode()); + Notifier.Instance.OnNodeModified(segmentId, Instance); } public override string ToString() { @@ -1446,6 +1319,8 @@ private struct JunctionRestrictions { private JunctionRestrictionFlags defaults; + private JunctionRestrictionFlags configurables; + private JunctionRestrictionFlags valid; public void ClearValue(SegmentEndId segmentEndId, JunctionRestrictionFlags flags) { @@ -1453,18 +1328,30 @@ public void ClearValue(SegmentEndId segmentEndId, JunctionRestrictionFlags flags mask &= ~flags; } - public void SetDefault(SegmentEndId segmentEndId, JunctionRestrictionFlags flags, bool value) { + private void SetDefault(SegmentEndId segmentEndId, JunctionRestrictionFlags flags, bool value) { if (value) defaults |= flags; else defaults &= ~flags; } + private void SetConfigurable(SegmentEndId segmentEndId, JunctionRestrictionFlags flags, bool value) { + if (value) + configurables |= flags; + else + configurables &= ~flags; + } + public bool GetDefaultValue(SegmentEndId segmentEndId, JunctionRestrictionFlags flags) { Recalculate(segmentEndId); return (defaults & flags) == flags; } + public bool IsConfigurable(SegmentEndId segmentEndId, JunctionRestrictionFlags flags) { + Recalculate(segmentEndId); + return (configurables & flags) == flags; + } + public bool HasValue(SegmentEndId segmentEndId, JunctionRestrictionFlags flags) { return (mask & flags) == flags; } @@ -1500,11 +1387,14 @@ public bool IsDefault(SegmentEndId segmentEndId) { return ((values & mask) | (defaults & ~mask)) == defaults; } - private delegate bool CalculateDefault(ushort segmentId, bool startNode, ref NetNode node); + private delegate bool CalculateConfigurable(ushort segmentId, bool startNode, ref NetNode node); + private delegate bool CalculateDefault(ushort segmentId, bool startNode, ref NetNode node, bool isConfigurable); - private void Recalculate(SegmentEndId segmentEndId, JunctionRestrictionFlags flags, CalculateDefault calculateDefault) { + private void Recalculate(SegmentEndId segmentEndId, JunctionRestrictionFlags flags, CalculateConfigurable calculateConfigurable, CalculateDefault calculateDefault) { if ((valid & flags) != flags) { - SetDefault(segmentEndId, flags, calculateDefault(segmentEndId.SegmentId, segmentEndId.StartNode, ref segmentEndId.GetNode())); + bool isConfigurable = calculateConfigurable(segmentEndId.SegmentId, segmentEndId.StartNode, ref segmentEndId.GetNode()); + SetConfigurable(segmentEndId, flags, isConfigurable); + SetDefault(segmentEndId, flags, calculateDefault(segmentEndId.SegmentId, segmentEndId.StartNode, ref segmentEndId.GetNode(), isConfigurable)); valid |= flags; } } @@ -1513,12 +1403,12 @@ private void Recalculate(SegmentEndId segmentEndId) { if ((valid & JunctionRestrictionFlags.All) != JunctionRestrictionFlags.All) { - Recalculate(segmentEndId, JunctionRestrictionFlags.AllowUTurn, Instance.GetDefaultUturnAllowed); - Recalculate(segmentEndId, JunctionRestrictionFlags.AllowNearTurnOnRed, Instance.GetDefaultNearTurnOnRedAllowed); - Recalculate(segmentEndId, JunctionRestrictionFlags.AllowFarTurnOnRed, Instance.GetDefaultFarTurnOnRedAllowed); - Recalculate(segmentEndId, JunctionRestrictionFlags.AllowForwardLaneChange, Instance.GetDefaultLaneChangingAllowedWhenGoingStraight); - Recalculate(segmentEndId, JunctionRestrictionFlags.AllowEnterWhenBlocked, Instance.GetDefaultEnteringBlockedJunctionAllowed); - Recalculate(segmentEndId, JunctionRestrictionFlags.AllowPedestrianCrossing, Instance.GetDefaultPedestrianCrossingAllowed); + Recalculate(segmentEndId, JunctionRestrictionFlags.AllowUTurn, Instance.IsUturnAllowedConfigurable, Instance.GetDefaultUturnAllowed); + Recalculate(segmentEndId, JunctionRestrictionFlags.AllowNearTurnOnRed, Instance.IsNearTurnOnRedAllowedConfigurable, Instance.GetDefaultNearTurnOnRedAllowed); + Recalculate(segmentEndId, JunctionRestrictionFlags.AllowFarTurnOnRed, Instance.IsFarTurnOnRedAllowedConfigurable, Instance.GetDefaultFarTurnOnRedAllowed); + Recalculate(segmentEndId, JunctionRestrictionFlags.AllowForwardLaneChange, Instance.IsLaneChangingAllowedWhenGoingStraightConfigurable, Instance.GetDefaultLaneChangingAllowedWhenGoingStraight); + Recalculate(segmentEndId, JunctionRestrictionFlags.AllowEnterWhenBlocked, Instance.IsEnteringBlockedJunctionAllowedConfigurable, Instance.GetDefaultEnteringBlockedJunctionAllowed); + Recalculate(segmentEndId, JunctionRestrictionFlags.AllowPedestrianCrossing, Instance.IsPedestrianCrossingAllowedConfigurable, Instance.GetDefaultPedestrianCrossingAllowed); } } @@ -1532,6 +1422,7 @@ public void Reset(SegmentEndId segmentEndId, bool resetDefaults = true) { public void Invalidate(SegmentEndId segmentEndId) { valid = default; + Notifier.Instance.OnNodeModified(segmentEndId.GetNodeId(), Instance); } public override string ToString() { From a230ca77d14f59c977df2bdb6c9624c216cb2cce Mon Sep 17 00:00:00 2001 From: Elesbaan70 <95266227+Elesbaan70@users.noreply.github.com> Date: Fri, 27 May 2022 19:48:13 -0500 Subject: [PATCH 12/21] Updates to IJunctionRestrictionsManager --- .../Manager/IJunctionRestrictionsManager.cs | 160 +++++++++++++++++- 1 file changed, 159 insertions(+), 1 deletion(-) diff --git a/TLM/TMPE.API/Manager/IJunctionRestrictionsManager.cs b/TLM/TMPE.API/Manager/IJunctionRestrictionsManager.cs index 4bc785c20..6336e5db2 100644 --- a/TLM/TMPE.API/Manager/IJunctionRestrictionsManager.cs +++ b/TLM/TMPE.API/Manager/IJunctionRestrictionsManager.cs @@ -4,18 +4,81 @@ namespace TrafficManager.API.Manager { using TrafficManager.API.Traffic.Enums; public interface IJunctionRestrictionsManager { + + /// + /// Indicates whether the specified flag is configurable. + /// If more than one flag is specified, indicates whether all are configurable. + /// + /// + /// + /// + /// + bool IsConfigurable(ushort segmentId, bool startNode, JunctionRestrictionFlags flags); + + /// + /// Returns the set value (not the default) for the specified flag, or null if no value has been set. + /// If more than one flag is specified, null is returned if they do not all have the same value. + /// + /// + /// + /// + /// + bool? GetValue(ushort segmentId, bool startNode, JunctionRestrictionFlags flags); + + /// + /// Returns the set value of the specified flag, or the default value if no value is set. + /// If more than one flag is specified, returns the logical AND of all results. + /// + /// + /// + /// + /// + bool GetValueOrDefault(ushort segmentId, bool startNode, JunctionRestrictionFlags flags); + + /// + /// Returns the default value for the specified flag. + /// If more than one flag is specified, returns the logical AND of all the results. + /// + /// + /// + /// + /// + bool GetDefaultValue(ushort segmentId, bool startNode, JunctionRestrictionFlags flags); + + /// + /// Sets the value of the specified flag(s). If null, clears the set value so that the default will be used. + /// + /// + /// + /// + /// + /// true if the operation was successful, false if not configurable + bool SetValue(ushort segmentId, bool startNode, JunctionRestrictionFlags flags, bool? value); + + /// + /// Toggles the value of the specified flag. This method fails if more than one flag is specified. + /// + /// + /// + /// + /// true if the operation was successful, false if not configurable or if more than one flag was specified + bool ToggleValue(ushort segmentId, bool startNode, JunctionRestrictionFlags flags); + #region IsConfigurable /// + /// This API is dprecated. Please use .
/// Determines if u-turn behavior may be controlled at the given segment end. ///
/// segment id /// at start node? /// node data /// true if u-turns may be customized, false otherwise + [Obsolete("Please use IsConfigurable(ushort, bool, JunctionRestrictionFlags)")] bool IsUturnAllowedConfigurable(ushort segmentId, bool startNode, ref NetNode node); /// + /// This API is dprecated. Please use .
/// Determines if turn-on-red behavior is enabled for near turns and may be controlled at /// the given segment end. ///
@@ -24,9 +87,11 @@ public interface IJunctionRestrictionsManager { /// node data /// true if turn-on-red may be customized for near turns, /// false otherwise + [Obsolete("Please use IsConfigurable(ushort, bool, JunctionRestrictionFlags)")] bool IsNearTurnOnRedAllowedConfigurable(ushort segmentId, bool startNode, ref NetNode node); /// + /// This API is dprecated. Please use .
/// Determines if turn-on-red behavior is enabled for far turns and may be controlled at /// the given segment end. ///
@@ -35,9 +100,11 @@ public interface IJunctionRestrictionsManager { /// node data /// true if turn-on-red may be customized for far turns, /// false otherwise + [Obsolete("Please use IsConfigurable(ushort, bool, JunctionRestrictionFlags)")] bool IsFarTurnOnRedAllowedConfigurable(ushort segmentId, bool startNode, ref NetNode node); /// + /// This API is dprecated. Please use .
/// Determines if turn-on-red behavior is enabled for the given turn type and that it may /// be controlled at the given segment end. ///
@@ -46,24 +113,28 @@ public interface IJunctionRestrictionsManager { /// at start node? /// node data /// true if turn-on-red may be customized, false otherwise + [Obsolete("Please use IsConfigurable(ushort, bool, JunctionRestrictionFlags)")] bool IsTurnOnRedAllowedConfigurable(bool near, ushort segmentId, bool startNode, ref NetNode node); /// + /// This API is dprecated. Please use .
/// Determines if lane changing behavior may be controlled at the given segment end. ///
/// segment id /// at start node? /// node data /// true if lane changing may be customized, false otherwise + [Obsolete("Please use IsConfigurable(ushort, bool, JunctionRestrictionFlags)")] bool IsLaneChangingAllowedWhenGoingStraightConfigurable( ushort segmentId, bool startNode, ref NetNode node); /// + /// This API is dprecated. Please use .
/// Determines if entering blocked junctions may be controlled at the given segment end. ///
/// segment id @@ -71,11 +142,13 @@ bool IsLaneChangingAllowedWhenGoingStraightConfigurable( /// node data /// true if entering blocked junctions may be customized, /// false otherwise + [Obsolete("Please use IsConfigurable(ushort, bool, JunctionRestrictionFlags)")] bool IsEnteringBlockedJunctionAllowedConfigurable(ushort segmentId, bool startNode, ref NetNode node); /// + /// This API is dprecated. Please use .
/// Determines if pedestrian crossings may be controlled at the given segment end. ///
/// segment id @@ -83,6 +156,7 @@ bool IsEnteringBlockedJunctionAllowedConfigurable(ushort segmentId, /// node data /// true if pedestrian crossings may be customized, false /// otherwise + [Obsolete("Please use IsConfigurable(ushort, bool, JunctionRestrictionFlags)")] bool IsPedestrianCrossingAllowedConfigurable(ushort segmentId, bool startNode, ref NetNode node); @@ -91,6 +165,7 @@ bool IsPedestrianCrossingAllowedConfigurable(ushort segmentId, #region GetDefault /// + /// This API is dprecated. Please use .
/// Determines the default setting for u-turns at the given segment end. ///
/// segment id @@ -98,9 +173,11 @@ bool IsPedestrianCrossingAllowedConfigurable(ushort segmentId, /// node data /// true if u-turns are allowed by default, false /// otherwise + [Obsolete("Please use GetDefaultValue(ushort, bool, JunctionRestrictionFlags)")] bool GetDefaultUturnAllowed(ushort segmentId, bool startNode, ref NetNode node); /// + /// This API is dprecated. Please use .
/// Determines the default setting for near turn-on-red at the given segment end. ///
/// segment id @@ -108,9 +185,11 @@ bool IsPedestrianCrossingAllowedConfigurable(ushort segmentId, /// node data /// true if turn-on-red is allowed for near turns by default, /// false otherwise + [Obsolete("Please use GetDefaultValue(ushort, bool, JunctionRestrictionFlags)")] bool GetDefaultNearTurnOnRedAllowed(ushort segmentId, bool startNode, ref NetNode node); /// + /// This API is dprecated. Please use .
/// Determines the default setting for far turn-on-red at the given segment end. ///
/// segment id @@ -118,9 +197,11 @@ bool IsPedestrianCrossingAllowedConfigurable(ushort segmentId, /// node data /// true if turn-on-red is allowed for far turns by default, /// false otherwise + [Obsolete("Please use GetDefaultValue(ushort, bool, JunctionRestrictionFlags)")] bool GetDefaultFarTurnOnRedAllowed(ushort segmentId, bool startNode, ref NetNode node); /// + /// This API is dprecated. Please use .
/// Determines the default turn-on-red setting for the given turn type at the given segment end. ///
/// for near turns? @@ -129,12 +210,14 @@ bool IsPedestrianCrossingAllowedConfigurable(ushort segmentId, /// node data /// true if turn-on-red is allowed by default, false /// otherwise + [Obsolete("Please use GetDefaultValue(ushort, bool, JunctionRestrictionFlags)")] bool GetDefaultTurnOnRedAllowed(bool near, ushort segmentId, bool startNode, ref NetNode node); /// + /// This API is dprecated. Please use .
/// Determines the default setting for straight lane changes at the given segment end. ///
/// segment id @@ -142,12 +225,14 @@ bool GetDefaultTurnOnRedAllowed(bool near, /// node data /// true if straight lane changes are allowed by default, /// false otherwise + [Obsolete("Please use GetDefaultValue(ushort, bool, JunctionRestrictionFlags)")] bool GetDefaultLaneChangingAllowedWhenGoingStraight( ushort segmentId, bool startNode, ref NetNode node); /// + /// This API is dprecated. Please use .
/// Determines the default setting for entering a blocked junction at the given segment end. ///
/// segment id @@ -155,11 +240,13 @@ bool GetDefaultLaneChangingAllowedWhenGoingStraight( /// node data /// true if entering a blocked junction is allowed by default, /// false otherwise + [Obsolete("Please use GetDefaultValue(ushort, bool, JunctionRestrictionFlags)")] bool GetDefaultEnteringBlockedJunctionAllowed(ushort segmentId, bool startNode, ref NetNode node); /// + /// This API is dprecated. Please use .
/// Determines the default setting for pedestrian crossings at the given segment end. ///
/// segment id @@ -168,6 +255,7 @@ bool GetDefaultEnteringBlockedJunctionAllowed(ushort segmentId, /// true if crossing the road is allowed by default, /// false otherwise /// returns the default value if flag is not set. + [Obsolete("Please use GetDefaultValue(ushort, bool, JunctionRestrictionFlags)")] bool GetDefaultPedestrianCrossingAllowed(ushort segmentId, bool startNode, ref NetNode node); @@ -176,33 +264,40 @@ bool GetDefaultPedestrianCrossingAllowed(ushort segmentId, #region IsAllowed /// + /// This API is dprecated. Please use .
/// Determines whether u-turns are allowed at the given segment end. ///
/// segment id /// at start node? /// true if u-turns are allowed, false otherwise /// returns the default value if flag is not set. + [Obsolete("Please use GetValueOrDefault(ushort, bool, JunctionRestrictionFlags)")] bool IsUturnAllowed(ushort segmentId, bool startNode); /// + /// This API is dprecated. Please use .
/// Determines whether turn-on-red is allowed for near turns at the given segment end. ///
/// segment id /// at start node? /// true if turn-on-red is allowed for near turns, false otherwise /// returns the default value if flag is not set. + [Obsolete("Please use GetValueOrDefault(ushort, bool, JunctionRestrictionFlags)")] bool IsNearTurnOnRedAllowed(ushort segmentId, bool startNode); /// + /// This API is dprecated. Please use .
/// Determines whether turn-on-red is allowed for far turns at the given segment end. ///
/// segment id /// at start node? /// true if turn-on-red is allowed for far turns, false otherwise /// returns the default behaviour if flag is not set. + [Obsolete("Please use GetValueOrDefault(ushort, bool, JunctionRestrictionFlags)")] bool IsFarTurnOnRedAllowed(ushort segmentId, bool startNode); /// + /// This API is dprecated. Please use .
/// Determines whether turn-on-red is allowed for the given turn type at the given segment end. ///
/// for near turns? @@ -210,66 +305,80 @@ bool GetDefaultPedestrianCrossingAllowed(ushort segmentId, /// at start node? /// true if turn-on-red is allowed, false otherwise /// returns the default behaviour if flag is not set. + [Obsolete("Please use GetValueOrDefault(ushort, bool, JunctionRestrictionFlags)")] bool IsTurnOnRedAllowed(bool near, ushort segmentId, bool startNode); /// + /// This API is dprecated. Please use .
/// Determines whether lane changing when going straight is allowed at the given segment end. ///
/// segment id /// at start node? /// true if lane changing when going straight is allowed, false otherwise /// returns the default behaviour if flag is not set. + [Obsolete("Please use GetValueOrDefault(ushort, bool, JunctionRestrictionFlags)")] bool IsLaneChangingAllowedWhenGoingStraight(ushort segmentId, bool startNode); /// + /// This API is dprecated. Please use .
/// Determines whether entering a blocked junction is allowed at the given segment end. ///
/// segment id /// at start node? /// true if entering a blocked junction is allowed, false otherwise /// returns the default behaviour if flag is not set. + [Obsolete("Please use GetValueOrDefault(ushort, bool, JunctionRestrictionFlags)")] bool IsEnteringBlockedJunctionAllowed(ushort segmentId, bool startNode); /// + /// This API is dprecated. Please use .
/// Determines whether crossing the road is allowed at the given segment end. ///
/// segment id /// at start node? /// true if crossing the road is allowed, false otherwise. /// returns the default value if flag is not set. + [Obsolete("Please use GetValueOrDefault(ushort, bool, JunctionRestrictionFlags)")] bool IsPedestrianCrossingAllowed(ushort segmentId, bool startNode); #endregion #region Get /// + /// This API is dprecated. Please use .
/// Retrieves the u-turn setting for the given segment end. ///
/// segment id /// at start node? /// ternary u-turn flag. /// returns TernaryBool.Undefined if the flag is not set. + [Obsolete("Please use GetValue(ushort, bool, JunctionRestrictionFlags)")] TernaryBool GetUturnAllowed(ushort segmentId, bool startNode); /// + /// This API is dprecated. Please use .
/// Retrieves the turn-on-red setting for near turns and the given segment end. ///
/// segment id /// at start node? /// ternary turn-on-red flag for near turns. /// returns TernaryBool.Undefined if the flag is not set. + [Obsolete("Please use GetValue(ushort, bool, JunctionRestrictionFlags)")] TernaryBool GetNearTurnOnRedAllowed(ushort segmentId, bool startNode); /// + /// This API is dprecated. Please use .
/// Retrieves the turn-on-red setting for far turns and the given segment end. ///
/// segment id /// at start node? /// ternary turn-on-red flag for far turns. /// returns TernaryBool.Undefined if the flag is not set. + [Obsolete("Please use GetValue(ushort, bool, JunctionRestrictionFlags)")] TernaryBool GetFarTurnOnRedAllowed(ushort segmentId, bool startNode); /// + /// This API is dprecated. Please use .
/// Retrieves the turn-on-red setting for the given turn type and segment end. ///
/// for near turns? @@ -277,39 +386,47 @@ bool GetDefaultPedestrianCrossingAllowed(ushort segmentId, /// at start node? /// ternary turn-on-red flag. /// returns TernaryBool.Undefined if the flag is not set. + [Obsolete("Please use GetValue(ushort, bool, JunctionRestrictionFlags)")] TernaryBool GetTurnOnRedAllowed(bool near, ushort segmentId, bool startNode); /// + /// This API is dprecated. Please use .
/// Retrieves the lane changing setting for the given segment end. ///
/// segment id /// at start node? /// ternary lane changing flag. /// returns TernaryBool.Undefined if the flag is not set. + [Obsolete("Please use GetValue(ushort, bool, JunctionRestrictionFlags)")] TernaryBool GetLaneChangingAllowedWhenGoingStraight(ushort segmentId, bool startNode); /// + /// This API is dprecated. Please use .
/// Retrieves the "enter blocked junction" setting for the given segment end. ///
/// segment id /// at start node? /// ternary "enter blocked junction" flag. /// returns TernaryBool.Undefined if the flag is not set. + [Obsolete("Please use GetValue(ushort, bool, JunctionRestrictionFlags)")] TernaryBool GetEnteringBlockedJunctionAllowed(ushort segmentId, bool startNode); /// + /// This API is dprecated. Please use .
/// Retrieves the pedestrian crossing setting for the given segment end. ///
/// segment id /// at start node? /// ternary pedestrian crossing flag. /// returns TernaryBool.Undefined if the flag is not set. + [Obsolete("Please use GetValue(ushort, bool, JunctionRestrictionFlags)")] TernaryBool GetPedestrianCrossingAllowed(ushort segmentId, bool startNode); #endregion - + #region Toggle /// + /// This API is dprecated. Please use .
/// Switches the u-turn flag for the given segment end. ///
/// segment id @@ -318,9 +435,11 @@ bool GetDefaultPedestrianCrossingAllowed(ushort segmentId, /// Silently returns true if the given equals to the flag. /// On failure (including when traffic rule is not configurable) returns false /// + [Obsolete("Please use ToggleValue(ushort, bool, JunctionRestrictionFlags)")] bool ToggleUturnAllowed(ushort segmentId, bool startNode); /// + /// This API is dprecated. Please use .
/// Switches the turn-on-red flag for near turns and given segment end. ///
/// segment id @@ -329,9 +448,11 @@ bool GetDefaultPedestrianCrossingAllowed(ushort segmentId, /// Silently returns true if the given equals to the flag. /// On failure (including when traffic rule is not configurable) returns false /// + [Obsolete("Please use ToggleValue(ushort, bool, JunctionRestrictionFlags)")] bool ToggleNearTurnOnRedAllowed(ushort segmentId, bool startNode); /// + /// This API is dprecated. Please use .
/// Switches the turn-on-red flag for far turns and given segment end. ///
/// segment id @@ -340,9 +461,11 @@ bool GetDefaultPedestrianCrossingAllowed(ushort segmentId, /// Silently returns true if the given equals to the flag. /// On failure (including when traffic rule is not configurable) returns false /// + [Obsolete("Please use ToggleValue(ushort, bool, JunctionRestrictionFlags)")] bool ToggleFarTurnOnRedAllowed(ushort segmentId, bool startNode); /// + /// This API is dprecated. Please use .
/// Switches the turn-on-red flag for the given turn type and segment end. ///
/// for near turns? @@ -352,9 +475,11 @@ bool GetDefaultPedestrianCrossingAllowed(ushort segmentId, /// Silently returns true if the given equals to the flag. /// On failure (including when traffic rule is not configurable) returns false /// + [Obsolete("Please use ToggleValue(ushort, bool, JunctionRestrictionFlags)")] bool ToggleTurnOnRedAllowed(bool near, ushort segmentId, bool startNode); /// + /// This API is dprecated. Please use .
/// Switches the lane changing flag for the given segment end. ///
/// segment id @@ -363,9 +488,11 @@ bool GetDefaultPedestrianCrossingAllowed(ushort segmentId, /// Silently returns true if the given equals to the flag. /// On failure (including when traffic rule is not configurable) returns false /// + [Obsolete("Please use ToggleValue(ushort, bool, JunctionRestrictionFlags)")] bool ToggleLaneChangingAllowedWhenGoingStraight(ushort segmentId, bool startNode); /// + /// This API is dprecated. Please use .
/// Switches the "enter blocked junction" flag for the given segment end. ///
/// segment id @@ -374,9 +501,11 @@ bool GetDefaultPedestrianCrossingAllowed(ushort segmentId, /// Silently returns true if the given equals to the flag. /// On failure (including when traffic rule is not configurable) returns false /// + [Obsolete("Please use ToggleValue(ushort, bool, JunctionRestrictionFlags)")] bool ToggleEnteringBlockedJunctionAllowed(ushort segmentId, bool startNode); /// + /// This API is dprecated. Please use .
/// Switches the pedestrian crossing flag for the given segment end. ///
/// segment id @@ -385,12 +514,14 @@ bool GetDefaultPedestrianCrossingAllowed(ushort segmentId, /// Silently returns true if the given equals to the flag. /// On failure (including when traffic rule is not configurable) returns false /// + [Obsolete("Please use ToggleValue(ushort, bool, JunctionRestrictionFlags)")] bool TogglePedestrianCrossingAllowed(ushort segmentId, bool startNode); #endregion #region Set : bool /// + /// This API is dprecated. Please use .
/// Sets the u-turn flag for the given segment end to the given value. ///
/// segment id @@ -400,9 +531,11 @@ bool GetDefaultPedestrianCrossingAllowed(ushort segmentId, /// Silently returns true if the given equals to the flag. /// On failure (including when traffic rule is not configurable) returns false /// + [Obsolete("Please use SetValue(ushort, bool, JunctionRestrictionFlags, bool?)")] bool SetUturnAllowed(ushort segmentId, bool startNode, bool value); /// + /// This API is dprecated. Please use .
/// Sets the turn-on-red flag for near turns at the given segment end to the given value. ///
/// segment id @@ -412,9 +545,11 @@ bool GetDefaultPedestrianCrossingAllowed(ushort segmentId, /// Silently returns true if the given equals to the flag. /// On failure (including when traffic rule is not configurable) returns false /// + [Obsolete("Please use SetValue(ushort, bool, JunctionRestrictionFlags, bool?)")] bool SetNearTurnOnRedAllowed(ushort segmentId, bool startNode, bool value); /// + /// This API is dprecated. Please use .
/// Sets the turn-on-red flag for far turns at the given segment end to the given value. ///
/// segment id @@ -424,9 +559,11 @@ bool GetDefaultPedestrianCrossingAllowed(ushort segmentId, /// Silently returns true if the given equals to the flag. /// On failure (including when traffic rule is not configurable) returns false /// + [Obsolete("Please use SetValue(ushort, bool, JunctionRestrictionFlags, bool?)")] bool SetFarTurnOnRedAllowed(ushort segmentId, bool startNode, bool value); /// + /// This API is dprecated. Please use .
/// Sets the turn-on-red flag for the given turn type and segment end to the given value. ///
/// for near turns? @@ -437,9 +574,11 @@ bool GetDefaultPedestrianCrossingAllowed(ushort segmentId, /// Silently returns true if the given equals to the flag. /// On failure (including when traffic rule is not configurable) returns false /// + [Obsolete("Please use SetValue(ushort, bool, JunctionRestrictionFlags, bool?)")] bool SetTurnOnRedAllowed(bool near, ushort segmentId, bool startNode, bool value); /// + /// This API is dprecated. Please use .
/// Sets the lane changing flag for the given segment end to the given value. ///
/// segment id @@ -449,9 +588,11 @@ bool GetDefaultPedestrianCrossingAllowed(ushort segmentId, /// Silently returns true if the given equals to the flag. /// On failure (including when traffic rule is not configurable) returns false /// + [Obsolete("Please use SetValue(ushort, bool, JunctionRestrictionFlags, bool?)")] bool SetLaneChangingAllowedWhenGoingStraight(ushort segmentId, bool startNode, bool value); /// + /// This API is dprecated. Please use .
/// Sets the "enter blocked junction" flag for the given segment end to the given value. ///
/// segment id @@ -461,9 +602,11 @@ bool GetDefaultPedestrianCrossingAllowed(ushort segmentId, /// Silently returns true if the given equals to the flag. /// On failure (including when traffic rule is not configurable) returns false /// + [Obsolete("Please use SetValue(ushort, bool, JunctionRestrictionFlags, bool?)")] bool SetEnteringBlockedJunctionAllowed(ushort segmentId, bool startNode, bool value); /// + /// This API is dprecated. Please use .
/// Sets the pedestrian crossing flag for the given segment end to the given value. ///
/// segment id @@ -473,12 +616,14 @@ bool GetDefaultPedestrianCrossingAllowed(ushort segmentId, /// Silently returns true if the given equals to the flag. /// On failure (including when traffic rule is not configurable) returns false /// + [Obsolete("Please use SetValue(ushort, bool, JunctionRestrictionFlags, bool?)")] bool SetPedestrianCrossingAllowed(ushort segmentId, bool startNode, bool value); #endregion #region Set : TernaryBool /// + /// This API is dprecated. Please use .
/// Sets the u-turn flag for the given segment end to the given value. ///
/// segment id @@ -488,9 +633,11 @@ bool GetDefaultPedestrianCrossingAllowed(ushort segmentId, /// Silently returns true if the given equals to the flag. /// On failure (including when traffic rule is not configurable) returns false /// + [Obsolete("Please use SetValue(ushort, bool, JunctionRestrictionFlags, bool?)")] bool SetUturnAllowed(ushort segmentId, bool startNode, TernaryBool value); /// + /// This API is dprecated. Please use .
/// Sets the turn-on-red flag for near turns at the given segment end to the given value. ///
/// segment id @@ -500,9 +647,11 @@ bool GetDefaultPedestrianCrossingAllowed(ushort segmentId, /// Silently returns true if the given equals to the flag. /// On failure (including when traffic rule is not configurable) returns false /// + [Obsolete("Please use SetValue(ushort, bool, JunctionRestrictionFlags, bool?)")] bool SetNearTurnOnRedAllowed(ushort segmentId, bool startNode, TernaryBool value); /// + /// This API is dprecated. Please use .
/// Sets the turn-on-red flag for far turns at the given segment end to the given value. ///
/// segment id @@ -512,9 +661,11 @@ bool GetDefaultPedestrianCrossingAllowed(ushort segmentId, /// Silently returns true if the given equals to the flag. /// On failure (including when traffic rule is not configurable) returns false /// + [Obsolete("Please use SetValue(ushort, bool, JunctionRestrictionFlags, bool?)")] bool SetFarTurnOnRedAllowed(ushort segmentId, bool startNode, TernaryBool value); /// + /// This API is dprecated. Please use .
/// Sets the turn-on-red flag for the given turn type and segment end to the given value. ///
/// for near turns? @@ -525,9 +676,11 @@ bool GetDefaultPedestrianCrossingAllowed(ushort segmentId, /// Silently returns true if the given equals to the flag. /// On failure (including when traffic rule is not configurable) returns false /// + [Obsolete("Please use SetValue(ushort, bool, JunctionRestrictionFlags, bool?)")] bool SetTurnOnRedAllowed(bool near, ushort segmentId, bool startNode, TernaryBool value); /// + /// This API is dprecated. Please use .
/// Sets the lane changing flag for the given segment end to the given value. ///
/// segment id @@ -537,9 +690,11 @@ bool GetDefaultPedestrianCrossingAllowed(ushort segmentId, /// Silently returns true if the given equals to the flag. /// On failure (including when traffic rule is not configurable) returns false /// + [Obsolete("Please use SetValue(ushort, bool, JunctionRestrictionFlags, bool?)")] bool SetLaneChangingAllowedWhenGoingStraight(ushort segmentId, bool startNode, TernaryBool value); /// + /// This API is dprecated. Please use .
/// Sets the "enter blocked junction" flag for the given segment end to the given value. ///
/// segment id @@ -549,9 +704,11 @@ bool GetDefaultPedestrianCrossingAllowed(ushort segmentId, /// Silently returns true if the given equals to the flag. /// On failure (including when traffic rule is not configurable) returns false /// + [Obsolete("Please use SetValue(ushort, bool, JunctionRestrictionFlags, bool?)")] bool SetEnteringBlockedJunctionAllowed(ushort segmentId, bool startNode, TernaryBool value); /// + /// This API is dprecated. Please use .
/// Sets the pedestrian crossing flag for the given segment end to the given value. ///
/// segment id @@ -561,6 +718,7 @@ bool GetDefaultPedestrianCrossingAllowed(ushort segmentId, /// Silently returns true if the given equals to the flag. /// On failure (including when traffic rule is not configurable) returns false /// + [Obsolete("Please use SetValue(ushort, bool, JunctionRestrictionFlags, bool?)")] bool SetPedestrianCrossingAllowed(ushort segmentId, bool startNode, TernaryBool value); #endregion From ed2dd2a2b31e076ba4af3f16ca0b6fc1ff96fa50 Mon Sep 17 00:00:00 2001 From: Elesbaan70 <95266227+Elesbaan70@users.noreply.github.com> Date: Fri, 27 May 2022 22:09:58 -0500 Subject: [PATCH 13/21] Clean up all the redudant setters --- .../Impl/JunctionRestrictionsManager.cs | 451 ++++-------------- .../LaneConnectionSubManager.cs | 3 +- TLM/TLM/Util/PriorityRoad.cs | 8 +- TLM/TLM/Util/Record/SegmentEndRecord.cs | 24 +- TLM/TLM/Util/RoundaboutMassEdit.cs | 14 +- 5 files changed, 128 insertions(+), 372 deletions(-) diff --git a/TLM/TLM/Manager/Impl/JunctionRestrictionsManager.cs b/TLM/TLM/Manager/Impl/JunctionRestrictionsManager.cs index 290562596..38d6df71b 100644 --- a/TLM/TLM/Manager/Impl/JunctionRestrictionsManager.cs +++ b/TLM/TLM/Manager/Impl/JunctionRestrictionsManager.cs @@ -19,6 +19,7 @@ namespace TrafficManager.Manager.Impl { using TrafficManager.Util.Extensions; using TrafficManager.Lifecycle; using TrafficManager.API.Traffic.Enums; + using TrafficManager.Manager.Impl.LaneConnection; public class JunctionRestrictionsManager : AbstractGeometryObservingManager, @@ -584,188 +585,20 @@ private bool GetDefaultPedestrianCrossingAllowed(ushort segmentId, bool startNod } public bool ClearSegmentEnd(ushort segmentId, bool startNode) { - bool ret = true; - ret |= SetPedestrianCrossingAllowed(segmentId, startNode, null); - ret |= SetEnteringBlockedJunctionAllowed(segmentId, startNode, null); - ret |= SetLaneChangingAllowedWhenGoingStraight(segmentId, startNode, null); - ret |= SetFarTurnOnRedAllowed(segmentId, startNode, null); - ret |= SetNearTurnOnRedAllowed(segmentId, startNode, null); - ret |= SetUturnAllowed(segmentId, startNode, null); - return ret; - } - - private void SetSegmentJunctionRestrictions(SegmentEndId segmentEndId, JunctionRestrictions restrictions) { - if (restrictions.HasValue(segmentEndId, JunctionRestrictionFlags.AllowUTurn)) { - SetUturnAllowed(segmentEndId.SegmentId, segmentEndId.StartNode, restrictions.GetValueOrDefault(segmentEndId, JunctionRestrictionFlags.AllowUTurn)); - } - - if (restrictions.HasValue(segmentEndId, JunctionRestrictionFlags.AllowNearTurnOnRed)) { - SetNearTurnOnRedAllowed(segmentEndId.SegmentId, segmentEndId.StartNode, restrictions.GetValueOrDefault(segmentEndId, JunctionRestrictionFlags.AllowNearTurnOnRed)); - } - - if (restrictions.HasValue(segmentEndId, JunctionRestrictionFlags.AllowFarTurnOnRed)) { - SetFarTurnOnRedAllowed(segmentEndId.SegmentId, segmentEndId.StartNode, restrictions.GetValueOrDefault(segmentEndId, JunctionRestrictionFlags.AllowFarTurnOnRed)); - } - - if (restrictions.HasValue(segmentEndId, JunctionRestrictionFlags.AllowForwardLaneChange)) { - SetLaneChangingAllowedWhenGoingStraight( - segmentEndId.SegmentId, - segmentEndId.StartNode, - restrictions.GetValueOrDefault(segmentEndId, JunctionRestrictionFlags.AllowForwardLaneChange)); - } - - if (restrictions.HasValue(segmentEndId, JunctionRestrictionFlags.AllowEnterWhenBlocked)) { - SetEnteringBlockedJunctionAllowed( - segmentEndId.SegmentId, - segmentEndId.StartNode, - restrictions.GetValueOrDefault(segmentEndId, JunctionRestrictionFlags.AllowEnterWhenBlocked)); - } - - if (restrictions.HasValue(segmentEndId, JunctionRestrictionFlags.AllowPedestrianCrossing)) { - SetPedestrianCrossingAllowed( - segmentEndId.SegmentId, - segmentEndId.StartNode, - restrictions.GetValueOrDefault(segmentEndId, JunctionRestrictionFlags.AllowPedestrianCrossing)); - } - } - - private static ref NetNode GetNode(ushort segmentId, bool startNode) => - ref segmentId.ToSegment().GetNodeId(startNode).ToNode(); - public bool SetUturnAllowed(ushort segmentId, bool startNode, bool? value) { - ref NetSegment netSegment = ref segmentId.ToSegment(); - - if (!netSegment.IsValid()) { - return false; - } - if(GetValue(segmentId, startNode, JunctionRestrictionFlags.AllowUTurn) == value) { - return true; - } - if(!IsUturnAllowedConfigurable(segmentId, startNode, ref GetNode(segmentId, startNode))) { - return false; - } - - if (value == false && Constants.ManagerFactory.LaneConnectionManager.HasUturnConnections( - segmentId, - startNode)) { + if (!segmentId.ToSegment().IsValid()) return false; - } - - segmentRestrictions[segmentId].SetValue(segmentId.AtNode(startNode), JunctionRestrictionFlags.AllowUTurn, value); - OnSegmentChange( - segmentId, - startNode, - ref Constants.ManagerFactory.ExtSegmentManager.ExtSegments[segmentId], - true); - return true; - } - public bool SetNearTurnOnRedAllowed(ushort segmentId, bool startNode, bool? value) { - return SetTurnOnRedAllowed(true, segmentId, startNode, value); + var segmentEndId = segmentId.AtNode(startNode); + return GetJunctionRestrictions(segmentEndId).ClearValue(segmentEndId, JunctionRestrictionFlags.All); } - public bool SetFarTurnOnRedAllowed(ushort segmentId, bool startNode, bool? value) { - return SetTurnOnRedAllowed(false, segmentId, startNode, value); - } - - public bool SetTurnOnRedAllowed(bool near, ushort segmentId, bool startNode, bool? value) { - ref NetSegment netSegment = ref segmentId.ToSegment(); - - if (!netSegment.IsValid()) { - return false; - } - if (GetValue(segmentId, startNode, near ? JunctionRestrictionFlags.AllowNearTurnOnRed : JunctionRestrictionFlags.AllowFarTurnOnRed) == value) { - return true; - } - if (!IsTurnOnRedAllowedConfigurable(near, segmentId, startNode, ref GetNode(segmentId, startNode))) { - return false; - } - - if (value == false && Constants.ManagerFactory.LaneConnectionManager.HasUturnConnections( - segmentId, - startNode)) { - return false; - } - - if (near) { - segmentRestrictions[segmentId].SetValue(segmentId.AtNode(startNode), JunctionRestrictionFlags.AllowNearTurnOnRed, value); - } else { - segmentRestrictions[segmentId].SetValue(segmentId.AtNode(startNode), JunctionRestrictionFlags.AllowFarTurnOnRed, value); - } - OnSegmentChange(segmentId, startNode, ref Constants.ManagerFactory.ExtSegmentManager.ExtSegments[segmentId], true); - return true; - } - - public bool SetLaneChangingAllowedWhenGoingStraight( - ushort segmentId, - bool startNode, - bool? value) { - ref NetSegment netSegment = ref segmentId.ToSegment(); - - if (!netSegment.IsValid()) { - return false; - } - if (GetValue(segmentId, startNode, JunctionRestrictionFlags.AllowForwardLaneChange) == value) { - return true; - } - if (!IsLaneChangingAllowedWhenGoingStraightConfigurable(segmentId, startNode, ref GetNode(segmentId, startNode))) { - return false; - } - - segmentRestrictions[segmentId].SetValue(segmentId.AtNode(startNode), JunctionRestrictionFlags.AllowForwardLaneChange, value); - OnSegmentChange( - segmentId, - startNode, - ref Constants.ManagerFactory.ExtSegmentManager.ExtSegments[segmentId], - true); - return true; - } - - public bool SetEnteringBlockedJunctionAllowed(ushort segmentId, bool startNode, bool? value) { - ref NetSegment netSegment = ref segmentId.ToSegment(); - - if (!netSegment.IsValid()) { - return false; - } - if (GetValue(segmentId, startNode, JunctionRestrictionFlags.AllowEnterWhenBlocked) == value) { - return true; - } - if (!IsEnteringBlockedJunctionAllowedConfigurable(segmentId, startNode, ref GetNode(segmentId, startNode))) { - return false; - } - - segmentRestrictions[segmentId].SetValue(segmentId.AtNode(startNode), JunctionRestrictionFlags.AllowEnterWhenBlocked, value); - - // recalculation not needed here because this is a simulation-time feature - OnSegmentChange( - segmentId, - startNode, - ref Constants.ManagerFactory.ExtSegmentManager.ExtSegments[segmentId], - false); - return true; + private void SetSegmentJunctionRestrictions(SegmentEndId segmentEndId, JunctionRestrictions restrictions) { + GetJunctionRestrictions(segmentEndId).Copy(segmentEndId, restrictions); } - public bool SetPedestrianCrossingAllowed(ushort segmentId, bool startNode, bool? value) { - ref NetSegment netSegment = ref segmentId.ToSegment(); - - if (!netSegment.IsValid()) { - return false; - } - if(GetValue(segmentId, startNode, JunctionRestrictionFlags.AllowPedestrianCrossing) == value) { - return true; - } - if(!IsPedestrianCrossingAllowedConfigurable(segmentId, startNode, ref GetNode(segmentId, startNode))) { - return false; - } - - segmentRestrictions[segmentId].SetValue(segmentId.AtNode(startNode), JunctionRestrictionFlags.AllowPedestrianCrossing, value); - OnSegmentChange( - segmentId, - startNode, - ref Constants.ManagerFactory.ExtSegmentManager.ExtSegments[segmentId], - true); - return true; - } + private static ref NetNode GetNode(ushort segmentId, bool startNode) => + ref segmentId.ToSegment().GetNodeId(startNode).ToNode(); private void OnSegmentChange(ushort segmentId, bool startNode, @@ -818,71 +651,12 @@ public bool LoadData(List data) { Configuration.SegmentNodeFlags flags = segNodeConf.startNodeFlags; ref NetNode startNode = ref startNodeId.ToNode(); - if (flags.uturnAllowed != null && - IsUturnAllowedConfigurable( - segNodeConf.segmentId, - true, - ref startNode)) { - SetUturnAllowed( - segNodeConf.segmentId, - true, - (bool)flags.uturnAllowed); - } - - if (flags.turnOnRedAllowed != null && - IsNearTurnOnRedAllowedConfigurable( - segNodeConf.segmentId, - true, - ref startNode)) { - SetNearTurnOnRedAllowed( - segNodeConf.segmentId, - true, - (bool)flags.turnOnRedAllowed); - } - - if (flags.farTurnOnRedAllowed != null && - IsFarTurnOnRedAllowedConfigurable( - segNodeConf.segmentId, - true, - ref startNode)) { - SetFarTurnOnRedAllowed( - segNodeConf.segmentId, - true, - (bool)flags.farTurnOnRedAllowed); - } - - if (flags.straightLaneChangingAllowed != null && - IsLaneChangingAllowedWhenGoingStraightConfigurable( - segNodeConf.segmentId, - true, - ref startNode)) { - SetLaneChangingAllowedWhenGoingStraight( - segNodeConf.segmentId, - true, - (bool)flags.straightLaneChangingAllowed); - } - - if (flags.enterWhenBlockedAllowed != null && - IsEnteringBlockedJunctionAllowedConfigurable( - segNodeConf.segmentId, - true, - ref startNode)) { - SetEnteringBlockedJunctionAllowed( - segNodeConf.segmentId, - true, - (bool)flags.enterWhenBlockedAllowed); - } - - if (flags.pedestrianCrossingAllowed != null && - IsPedestrianCrossingAllowedConfigurable( - segNodeConf.segmentId, - true, - ref startNode)) { - SetPedestrianCrossingAllowed( - segNodeConf.segmentId, - true, - (bool)flags.pedestrianCrossingAllowed); - } + SetValue(segNodeConf.segmentId, true, JunctionRestrictionFlags.AllowUTurn, flags.uturnAllowed); + SetValue(segNodeConf.segmentId, true, JunctionRestrictionFlags.AllowNearTurnOnRed, flags.turnOnRedAllowed); + SetValue(segNodeConf.segmentId, true, JunctionRestrictionFlags.AllowFarTurnOnRed, flags.farTurnOnRedAllowed); + SetValue(segNodeConf.segmentId, true, JunctionRestrictionFlags.AllowForwardLaneChange, flags.straightLaneChangingAllowed); + SetValue(segNodeConf.segmentId, true, JunctionRestrictionFlags.AllowEnterWhenBlocked, flags.enterWhenBlockedAllowed); + SetValue(segNodeConf.segmentId, true, JunctionRestrictionFlags.AllowPedestrianCrossing, flags.pedestrianCrossingAllowed); } else { Log.Warning( "JunctionRestrictionsManager.LoadData(): Could not get segment " + @@ -893,74 +667,15 @@ public bool LoadData(List data) { if (segNodeConf.endNodeFlags != null) { ushort endNodeId = netSegment.m_endNode; if (endNodeId != 0) { - Configuration.SegmentNodeFlags flags1 = segNodeConf.endNodeFlags; + Configuration.SegmentNodeFlags flags = segNodeConf.endNodeFlags; ref NetNode node = ref endNodeId.ToNode(); - if (flags1.uturnAllowed != null && - IsUturnAllowedConfigurable( - segNodeConf.segmentId, - false, - ref node)) { - SetUturnAllowed( - segNodeConf.segmentId, - false, - (bool)flags1.uturnAllowed); - } - - if (flags1.straightLaneChangingAllowed != null && - IsLaneChangingAllowedWhenGoingStraightConfigurable( - segNodeConf.segmentId, - false, - ref node)) { - SetLaneChangingAllowedWhenGoingStraight( - segNodeConf.segmentId, - false, - (bool)flags1.straightLaneChangingAllowed); - } - - if (flags1.enterWhenBlockedAllowed != null && - IsEnteringBlockedJunctionAllowedConfigurable( - segNodeConf.segmentId, - false, - ref node)) { - SetEnteringBlockedJunctionAllowed( - segNodeConf.segmentId, - false, - (bool)flags1.enterWhenBlockedAllowed); - } - - if (flags1.pedestrianCrossingAllowed != null && - IsPedestrianCrossingAllowedConfigurable( - segNodeConf.segmentId, - false, - ref node)) { - SetPedestrianCrossingAllowed( - segNodeConf.segmentId, - false, - (bool)flags1.pedestrianCrossingAllowed); - } - - if (flags1.turnOnRedAllowed != null && - IsNearTurnOnRedAllowedConfigurable( - segNodeConf.segmentId, - false, - ref node)) { - SetNearTurnOnRedAllowed( - segNodeConf.segmentId, - false, - (bool)flags1.turnOnRedAllowed); - } - - if (flags1.farTurnOnRedAllowed != null && - IsFarTurnOnRedAllowedConfigurable( - segNodeConf.segmentId, - false, - ref node)) { - SetFarTurnOnRedAllowed( - segNodeConf.segmentId, - false, - (bool)flags1.farTurnOnRedAllowed); - } + SetValue(segNodeConf.segmentId, false, JunctionRestrictionFlags.AllowUTurn, flags.uturnAllowed); + SetValue(segNodeConf.segmentId, false, JunctionRestrictionFlags.AllowNearTurnOnRed, flags.turnOnRedAllowed); + SetValue(segNodeConf.segmentId, false, JunctionRestrictionFlags.AllowFarTurnOnRed, flags.farTurnOnRedAllowed); + SetValue(segNodeConf.segmentId, false, JunctionRestrictionFlags.AllowForwardLaneChange, flags.straightLaneChangingAllowed); + SetValue(segNodeConf.segmentId, false, JunctionRestrictionFlags.AllowEnterWhenBlocked, flags.enterWhenBlockedAllowed); + SetValue(segNodeConf.segmentId, false, JunctionRestrictionFlags.AllowPedestrianCrossing, flags.pedestrianCrossingAllowed); } else { Log.Warning( "JunctionRestrictionsManager.LoadData(): Could not get segment " + @@ -1138,31 +853,8 @@ bool IJunctionRestrictionsManager.ToggleEnteringBlockedJunctionAllowed(ushort se bool IJunctionRestrictionsManager.TogglePedestrianCrossingAllowed(ushort segmentId, bool startNode) => ToggleValue(segmentId, startNode, JunctionRestrictionFlags.AllowPedestrianCrossing); - public bool SetValue(ushort segmentId, bool startNode, JunctionRestrictionFlags flags, bool? value) { - - if (flags == default) - return false; - - if (flags.IsFlagSet(JunctionRestrictionFlags.AllowUTurn) && !SetUturnAllowed(segmentId, startNode, value)) - return false; - - if (flags.IsFlagSet(JunctionRestrictionFlags.AllowNearTurnOnRed) && !SetNearTurnOnRedAllowed(segmentId, startNode, value)) - return false; - - if (flags.IsFlagSet(JunctionRestrictionFlags.AllowFarTurnOnRed) && !SetFarTurnOnRedAllowed(segmentId, startNode, value)) - return false; - - if (flags.IsFlagSet(JunctionRestrictionFlags.AllowForwardLaneChange) && !SetLaneChangingAllowedWhenGoingStraight(segmentId, startNode, value)) - return false; - - if (flags.IsFlagSet(JunctionRestrictionFlags.AllowEnterWhenBlocked) && !SetEnteringBlockedJunctionAllowed(segmentId, startNode, value)) - return false; - - if (flags.IsFlagSet(JunctionRestrictionFlags.AllowPedestrianCrossing) && !SetPedestrianCrossingAllowed(segmentId, startNode, value)) - return false; - - return true; - } + public bool SetValue(ushort segmentId, bool startNode, JunctionRestrictionFlags flags, bool? value) + => segmentId.ToSegment().IsValid() && flags != default && segmentRestrictions[segmentId].SetValue(segmentId.AtNode(startNode), flags, value); bool IJunctionRestrictionsManager.SetUturnAllowed(ushort segmentId, bool startNode, bool value) => SetValue(segmentId, startNode, JunctionRestrictionFlags.AllowUTurn, value); @@ -1274,11 +966,11 @@ public bool IsConfigurable(SegmentEndId segmentEndId, JunctionRestrictionFlags f return (segmentEndId.StartNode ? startNodeRestrictions : endNodeRestrictions).IsConfigurable(segmentEndId, flags); } - public void SetValue(SegmentEndId segmentEndId, JunctionRestrictionFlags flags, bool? value) { + public bool SetValue(SegmentEndId segmentEndId, JunctionRestrictionFlags flags, bool? value) { if (segmentEndId.StartNode) - startNodeRestrictions.SetValue(segmentEndId, flags, value); + return startNodeRestrictions.SetValue(segmentEndId, flags, value); else - endNodeRestrictions.SetValue(segmentEndId, flags, value); + return endNodeRestrictions.SetValue(segmentEndId, flags, value); } public bool IsDefault(ushort segmentId) { @@ -1323,10 +1015,7 @@ private struct JunctionRestrictions { private JunctionRestrictionFlags valid; - public void ClearValue(SegmentEndId segmentEndId, JunctionRestrictionFlags flags) { - values &= ~flags; - mask &= ~flags; - } + public bool ClearValue(SegmentEndId segmentEndId, JunctionRestrictionFlags flags) => SetValue(segmentEndId, flags, null); private void SetDefault(SegmentEndId segmentEndId, JunctionRestrictionFlags flags, bool value) { if (value) @@ -1369,17 +1058,66 @@ public bool GetValueOrDefault(SegmentEndId segmentEndId, JunctionRestrictionFlag return ((values & flags & mask) | (defaults & flags & ~mask)) == flags; } - public void SetValue(SegmentEndId segmentEndId, JunctionRestrictionFlags flags, bool? value) { - if (value == true) { - values |= flags; - mask |= flags; - } else if (value == false) { - values &= ~flags; - mask |= flags; - } else { - values &= ~flags; - mask &= ~flags; - } + public JunctionRestrictionFlags GetFlagsWithDefaults(SegmentEndId segmentEndId) { + return (values & mask) | (defaults & ~mask); + } + + private const JunctionRestrictionFlags routingRecalculationFlags = JunctionRestrictionFlags.All & ~JunctionRestrictionFlags.AllowEnterWhenBlocked; + + private bool ValidateSet(SegmentEndId segmentEndId, JunctionRestrictionFlags flags, JunctionRestrictionFlags newValues, JunctionRestrictionFlags newMask) { + + const JunctionRestrictionFlags uTurnCheckFlags + = JunctionRestrictionFlags.AllowNearTurnOnRed + | JunctionRestrictionFlags.AllowFarTurnOnRed + | JunctionRestrictionFlags.AllowUTurn; + + if ((newMask & flags & uTurnCheckFlags) != 0 + && (newValues & newMask & flags & uTurnCheckFlags) == 0 + && LaneConnectionManager.Instance.HasUturnConnections(segmentEndId.SegmentId, segmentEndId.StartNode)) + return false; + + return true; + } + + public bool SetValue(SegmentEndId segmentEndId, JunctionRestrictionFlags flags, bool? value) { + + Recalculate(segmentEndId); + + var newValues = value == true ? (values | flags) : (values & ~flags); + var newMask = value.HasValue ? (mask | flags) : (mask & ~flags); + + return Set(segmentEndId, flags, newValues, newMask); + } + + private bool Set(SegmentEndId segmentEndId, JunctionRestrictionFlags flags, JunctionRestrictionFlags newValues, JunctionRestrictionFlags newMask) { + + Recalculate(segmentEndId); + + var changingValues = newValues ^ values; + var changingMask = newMask ^ mask; + + if (changingValues == 0 && changingMask == 0) + return true; + + if ((configurables & changingValues) != changingValues || (configurables & changingMask) != changingMask) + return false; + + if (!ValidateSet(segmentEndId, flags, newValues, newMask)) + return false; + + values = newValues & flags; + mask = newMask & flags; + + Instance.OnSegmentChange(segmentEndId.SegmentId, + segmentEndId.StartNode, + ref ExtSegmentManager.Instance.ExtSegments[segmentEndId.SegmentId], + (flags & routingRecalculationFlags) != 0); + return true; + } + + public void Copy(SegmentEndId segmentEndId, JunctionRestrictions other) { + Recalculate(segmentEndId); + Set(segmentEndId, other.mask & configurables, other.values, other.mask); } public bool IsDefault(SegmentEndId segmentEndId) { @@ -1401,7 +1139,9 @@ private void Recalculate(SegmentEndId segmentEndId, JunctionRestrictionFlags fla private void Recalculate(SegmentEndId segmentEndId) { - if ((valid & JunctionRestrictionFlags.All) != JunctionRestrictionFlags.All) { + var recalculateFlags = JunctionRestrictionFlags.All & ~valid; + + if (recalculateFlags != default) { Recalculate(segmentEndId, JunctionRestrictionFlags.AllowUTurn, Instance.IsUturnAllowedConfigurable, Instance.GetDefaultUturnAllowed); Recalculate(segmentEndId, JunctionRestrictionFlags.AllowNearTurnOnRed, Instance.IsNearTurnOnRedAllowedConfigurable, Instance.GetDefaultNearTurnOnRedAllowed); @@ -1409,6 +1149,17 @@ private void Recalculate(SegmentEndId segmentEndId) { Recalculate(segmentEndId, JunctionRestrictionFlags.AllowForwardLaneChange, Instance.IsLaneChangingAllowedWhenGoingStraightConfigurable, Instance.GetDefaultLaneChangingAllowedWhenGoingStraight); Recalculate(segmentEndId, JunctionRestrictionFlags.AllowEnterWhenBlocked, Instance.IsEnteringBlockedJunctionAllowedConfigurable, Instance.GetDefaultEnteringBlockedJunctionAllowed); Recalculate(segmentEndId, JunctionRestrictionFlags.AllowPedestrianCrossing, Instance.IsPedestrianCrossingAllowedConfigurable, Instance.GetDefaultPedestrianCrossingAllowed); + + var clearFlags = mask & ~configurables; + if (clearFlags != default) { + values &= configurables; + mask &= configurables; + } + + Instance.OnSegmentChange(segmentEndId.SegmentId, + segmentEndId.StartNode, + ref ExtSegmentManager.Instance.ExtSegments[segmentEndId.SegmentId], + ((recalculateFlags | clearFlags) & routingRecalculationFlags) != 0); } } diff --git a/TLM/TLM/Manager/Impl/LaneConnection/LaneConnectionSubManager.cs b/TLM/TLM/Manager/Impl/LaneConnection/LaneConnectionSubManager.cs index fb68c7144..ee8e38100 100644 --- a/TLM/TLM/Manager/Impl/LaneConnection/LaneConnectionSubManager.cs +++ b/TLM/TLM/Manager/Impl/LaneConnection/LaneConnectionSubManager.cs @@ -362,9 +362,10 @@ internal bool AddLaneConnection(uint sourceLaneId, uint targetLaneId, bool sourc RecalculateLaneArrows(sourceLaneId, nodeId, sourceStartNode); if (sourceSegmentId == targetSegmentId) { - JunctionRestrictionsManager.Instance.SetUturnAllowed( + JunctionRestrictionsManager.Instance.SetValue( sourceSegmentId, sourceStartNode, + JunctionRestrictionFlags.AllowUTurn, true); } diff --git a/TLM/TLM/Util/PriorityRoad.cs b/TLM/TLM/Util/PriorityRoad.cs index 39645907b..df438fec6 100644 --- a/TLM/TLM/Util/PriorityRoad.cs +++ b/TLM/TLM/Util/PriorityRoad.cs @@ -412,9 +412,9 @@ private static ArrowDirection GetDirection(ushort segmentId, ushort otherSegment private static void FixMajorSegmentRules(ushort segmentId, ushort nodeId) { Log._Debug($"FixMajorSegmentRules({segmentId}, {nodeId}) was called"); bool startNode = segmentId.ToSegment().IsStartNode(nodeId); - JunctionRestrictionsManager.Instance.SetEnteringBlockedJunctionAllowed(segmentId, startNode, true); + JunctionRestrictionsManager.Instance.SetValue(segmentId, startNode, JunctionRestrictionFlags.AllowEnterWhenBlocked, true); if (!Options.PriorityRoad_CrossMainR) { - JunctionRestrictionsManager.Instance.SetPedestrianCrossingAllowed(segmentId, startNode, false); + JunctionRestrictionsManager.Instance.SetValue(segmentId, startNode, JunctionRestrictionFlags.AllowPedestrianCrossing, false); } TrafficPriorityManager.Instance.SetPrioritySign(segmentId, startNode, PriorityType.Main); } @@ -423,10 +423,10 @@ private static void FixMinorSegmentRules(ushort segmentId, ushort nodeId, List map) { @@ -84,12 +84,12 @@ public void Transfer(Dictionary map) { } // all necessary checks are performed internally. - JRMan.SetUturnAllowed(segmentId, StartNode, ToOptBool(uturnAllowed_)); - JRMan.SetNearTurnOnRedAllowed(segmentId, StartNode, ToOptBool(nearTurnOnRedAllowed_)); - JRMan.SetFarTurnOnRedAllowed(segmentId, StartNode, ToOptBool(farTurnOnRedAllowed_)); - JRMan.SetLaneChangingAllowedWhenGoingStraight(segmentId, StartNode, ToOptBool(laneChangingAllowedWhenGoingStraight_)); - JRMan.SetEnteringBlockedJunctionAllowed(segmentId, StartNode, ToOptBool(enteringBlockedJunctionAllowed_)); - JRMan.SetPedestrianCrossingAllowed(segmentId, StartNode, ToOptBool(pedestrianCrossingAllowed_)); + JRMan.SetValue(segmentId, StartNode, JunctionRestrictionFlags.AllowUTurn, ToOptBool(uturnAllowed_)); + JRMan.SetValue(segmentId, StartNode, JunctionRestrictionFlags.AllowNearTurnOnRed, ToOptBool(nearTurnOnRedAllowed_)); + JRMan.SetValue(segmentId, StartNode, JunctionRestrictionFlags.AllowFarTurnOnRed, ToOptBool(farTurnOnRedAllowed_)); + JRMan.SetValue(segmentId, StartNode, JunctionRestrictionFlags.AllowForwardLaneChange, ToOptBool(laneChangingAllowedWhenGoingStraight_)); + JRMan.SetValue(segmentId, StartNode, JunctionRestrictionFlags.AllowEnterWhenBlocked, ToOptBool(enteringBlockedJunctionAllowed_)); + JRMan.SetValue(segmentId, StartNode, JunctionRestrictionFlags.AllowPedestrianCrossing, ToOptBool(pedestrianCrossingAllowed_)); } public void Transfer(uint mappedId) { diff --git a/TLM/TLM/Util/RoundaboutMassEdit.cs b/TLM/TLM/Util/RoundaboutMassEdit.cs index 31906355a..6f15d14fb 100644 --- a/TLM/TLM/Util/RoundaboutMassEdit.cs +++ b/TLM/TLM/Util/RoundaboutMassEdit.cs @@ -122,14 +122,16 @@ private static void FixRulesRoundabout(ushort segmentId, bool startNode) { } if (Options.RoundAboutQuickFix_NoCrossMainR) { - JunctionRestrictionsManager.Instance.SetPedestrianCrossingAllowed( + JunctionRestrictionsManager.Instance.SetValue( segmentId, startNode, + JunctionRestrictionFlags.AllowPedestrianCrossing, false); } - JunctionRestrictionsManager.Instance.SetEnteringBlockedJunctionAllowed( + JunctionRestrictionsManager.Instance.SetValue( segmentId, startNode, + JunctionRestrictionFlags.AllowEnterWhenBlocked, true); } @@ -138,9 +140,10 @@ internal static void FixRulesMinor(ushort segmentId, ushort nodeId) { bool isHighway = ExtNodeManager.JunctionHasOnlyHighwayRoads(nodeId); if (Options.RoundAboutQuickFix_NoCrossYieldR) { - JunctionRestrictionsManager.Instance.SetPedestrianCrossingAllowed( + JunctionRestrictionsManager.Instance.SetValue( segmentId, startNode, + JunctionRestrictionFlags.AllowPedestrianCrossing, false); } if (Options.RoundAboutQuickFix_PrioritySigns) { @@ -152,13 +155,14 @@ internal static void FixRulesMinor(ushort segmentId, ushort nodeId) { if (isHighway) { //ignore highway rules: //TODO remove as part of issue #569 - JunctionRestrictionsManager.Instance.SetLaneChangingAllowedWhenGoingStraight(segmentId, startNode, true); + JunctionRestrictionsManager.Instance.SetValue(segmentId, startNode, JunctionRestrictionFlags.AllowForwardLaneChange, true); } // endif if (Options.RoundAboutQuickFix_KeepClearYieldR) { - JunctionRestrictionsManager.Instance.SetEnteringBlockedJunctionAllowed( + JunctionRestrictionsManager.Instance.SetValue( segmentId, startNode, + JunctionRestrictionFlags.AllowEnterWhenBlocked, false); } } From ef6aa5b56737227dc33e94e83b579d33dd79926a Mon Sep 17 00:00:00 2001 From: Elesbaan70 <95266227+Elesbaan70@users.noreply.github.com> Date: Fri, 27 May 2022 22:18:46 -0500 Subject: [PATCH 14/21] separate and condense deprecated methods --- .../Impl/JunctionRestrictionsManager.cs | 195 +++++------------- 1 file changed, 49 insertions(+), 146 deletions(-) diff --git a/TLM/TLM/Manager/Impl/JunctionRestrictionsManager.cs b/TLM/TLM/Manager/Impl/JunctionRestrictionsManager.cs index 38d6df71b..8ea3f7de4 100644 --- a/TLM/TLM/Manager/Impl/JunctionRestrictionsManager.cs +++ b/TLM/TLM/Manager/Impl/JunctionRestrictionsManager.cs @@ -779,51 +779,9 @@ public bool LoadData(List data) { public bool IsConfigurable(ushort segmentId, bool startNode, JunctionRestrictionFlags flags) => segmentRestrictions[segmentId].IsConfigurable(segmentId.AtNode(startNode), flags); - bool IJunctionRestrictionsManager.IsUturnAllowedConfigurable(ushort segmentId, bool startNode, ref NetNode node) - => IsConfigurable(segmentId, startNode, JunctionRestrictionFlags.AllowUTurn); - - bool IJunctionRestrictionsManager.IsNearTurnOnRedAllowedConfigurable(ushort segmentId, bool startNode, ref NetNode node) - => IsConfigurable(segmentId, startNode, JunctionRestrictionFlags.AllowNearTurnOnRed); - - bool IJunctionRestrictionsManager.IsFarTurnOnRedAllowedConfigurable(ushort segmentId, bool startNode, ref NetNode node) - => IsConfigurable(segmentId, startNode, JunctionRestrictionFlags.AllowFarTurnOnRed); - - bool IJunctionRestrictionsManager.IsTurnOnRedAllowedConfigurable(bool near, ushort segmentId, bool startNode, ref NetNode node) - => IsConfigurable(segmentId, startNode, near ? JunctionRestrictionFlags.AllowNearTurnOnRed : JunctionRestrictionFlags.AllowFarTurnOnRed); - - bool IJunctionRestrictionsManager.IsLaneChangingAllowedWhenGoingStraightConfigurable(ushort segmentId, bool startNode, ref NetNode node) - => IsConfigurable(segmentId, startNode, JunctionRestrictionFlags.AllowForwardLaneChange); - - bool IJunctionRestrictionsManager.IsEnteringBlockedJunctionAllowedConfigurable(ushort segmentId, bool startNode, ref NetNode node) - => IsConfigurable(segmentId, startNode, JunctionRestrictionFlags.AllowEnterWhenBlocked); - - bool IJunctionRestrictionsManager.IsPedestrianCrossingAllowedConfigurable(ushort segmentId, bool startNode, ref NetNode node) - => IsConfigurable(segmentId, startNode, JunctionRestrictionFlags.AllowPedestrianCrossing); - public bool GetDefaultValue(ushort segmentId, bool startNode, JunctionRestrictionFlags flags) => segmentRestrictions[segmentId].GetDefaultValue(segmentId.AtNode(startNode), flags); - bool IJunctionRestrictionsManager.GetDefaultUturnAllowed(ushort segmentId, bool startNode, ref NetNode node) - => GetDefaultValue(segmentId, startNode, JunctionRestrictionFlags.AllowUTurn); - - bool IJunctionRestrictionsManager.GetDefaultNearTurnOnRedAllowed(ushort segmentId, bool startNode, ref NetNode node) - => GetDefaultValue(segmentId, startNode, JunctionRestrictionFlags.AllowNearTurnOnRed); - - bool IJunctionRestrictionsManager.GetDefaultFarTurnOnRedAllowed(ushort segmentId, bool startNode, ref NetNode node) - => GetDefaultValue(segmentId, startNode, JunctionRestrictionFlags.AllowFarTurnOnRed); - - bool IJunctionRestrictionsManager.GetDefaultTurnOnRedAllowed(bool near, ushort segmentId, bool startNode, ref NetNode node) - => GetDefaultValue(segmentId, startNode, near ? JunctionRestrictionFlags.AllowNearTurnOnRed : JunctionRestrictionFlags.AllowFarTurnOnRed); - - bool IJunctionRestrictionsManager.GetDefaultLaneChangingAllowedWhenGoingStraight(ushort segmentId, bool startNode, ref NetNode node) - => GetDefaultValue(segmentId, startNode, JunctionRestrictionFlags.AllowForwardLaneChange); - - bool IJunctionRestrictionsManager.GetDefaultEnteringBlockedJunctionAllowed(ushort segmentId, bool startNode, ref NetNode node) - => GetDefaultValue(segmentId, startNode, JunctionRestrictionFlags.AllowEnterWhenBlocked); - - bool IJunctionRestrictionsManager.GetDefaultPedestrianCrossingAllowed(ushort segmentId, bool startNode, ref NetNode node) - => GetDefaultValue(segmentId, startNode, JunctionRestrictionFlags.AllowPedestrianCrossing); - public bool ToggleValue(ushort segmentId, bool startNode, JunctionRestrictionFlags flags) { if (flags == default || ((int)flags & ((int)flags - 1)) != 0) @@ -832,119 +790,64 @@ public bool ToggleValue(ushort segmentId, bool startNode, JunctionRestrictionFla return SetValue(segmentId, startNode, flags, !GetValueOrDefault(segmentId, startNode, flags)); } - bool IJunctionRestrictionsManager.ToggleUturnAllowed(ushort segmentId, bool startNode) - => ToggleValue(segmentId, startNode, JunctionRestrictionFlags.AllowUTurn); - - bool IJunctionRestrictionsManager.ToggleNearTurnOnRedAllowed(ushort segmentId, bool startNode) - => ToggleValue(segmentId, startNode, JunctionRestrictionFlags.AllowNearTurnOnRed); - - bool IJunctionRestrictionsManager.ToggleFarTurnOnRedAllowed(ushort segmentId, bool startNode) - => ToggleValue(segmentId, startNode, JunctionRestrictionFlags.AllowFarTurnOnRed); - - bool IJunctionRestrictionsManager.ToggleTurnOnRedAllowed(bool near, ushort segmentId, bool startNode) - => ToggleValue(segmentId, startNode, near ? JunctionRestrictionFlags.AllowNearTurnOnRed : JunctionRestrictionFlags.AllowFarTurnOnRed); - - bool IJunctionRestrictionsManager.ToggleLaneChangingAllowedWhenGoingStraight(ushort segmentId, bool startNode) - => ToggleValue(segmentId, startNode, JunctionRestrictionFlags.AllowForwardLaneChange); - - bool IJunctionRestrictionsManager.ToggleEnteringBlockedJunctionAllowed(ushort segmentId, bool startNode) - => ToggleValue(segmentId, startNode, JunctionRestrictionFlags.AllowEnterWhenBlocked); - - bool IJunctionRestrictionsManager.TogglePedestrianCrossingAllowed(ushort segmentId, bool startNode) - => ToggleValue(segmentId, startNode, JunctionRestrictionFlags.AllowPedestrianCrossing); - public bool SetValue(ushort segmentId, bool startNode, JunctionRestrictionFlags flags, bool? value) => segmentId.ToSegment().IsValid() && flags != default && segmentRestrictions[segmentId].SetValue(segmentId.AtNode(startNode), flags, value); - bool IJunctionRestrictionsManager.SetUturnAllowed(ushort segmentId, bool startNode, bool value) - => SetValue(segmentId, startNode, JunctionRestrictionFlags.AllowUTurn, value); - - bool IJunctionRestrictionsManager.SetNearTurnOnRedAllowed(ushort segmentId, bool startNode, bool value) - => SetValue(segmentId, startNode, JunctionRestrictionFlags.AllowNearTurnOnRed, value); - - bool IJunctionRestrictionsManager.SetFarTurnOnRedAllowed(ushort segmentId, bool startNode, bool value) - => SetValue(segmentId, startNode, JunctionRestrictionFlags.AllowFarTurnOnRed, value); - - bool IJunctionRestrictionsManager.SetTurnOnRedAllowed(bool near, ushort segmentId, bool startNode, bool value) - => SetValue(segmentId, startNode, near ? JunctionRestrictionFlags.AllowNearTurnOnRed : JunctionRestrictionFlags.AllowFarTurnOnRed, value); - - bool IJunctionRestrictionsManager.SetLaneChangingAllowedWhenGoingStraight(ushort segmentId, bool startNode, bool value) - => SetValue(segmentId, startNode, JunctionRestrictionFlags.AllowForwardLaneChange, value); - - bool IJunctionRestrictionsManager.SetEnteringBlockedJunctionAllowed(ushort segmentId, bool startNode, bool value) - => SetValue(segmentId, startNode, JunctionRestrictionFlags.AllowEnterWhenBlocked, value); - - bool IJunctionRestrictionsManager.SetPedestrianCrossingAllowed(ushort segmentId, bool startNode, bool value) - => SetValue(segmentId, startNode, JunctionRestrictionFlags.AllowPedestrianCrossing, value); - - bool IJunctionRestrictionsManager.SetUturnAllowed(ushort segmentId, bool startNode, TernaryBool value) - => SetValue(segmentId, startNode, JunctionRestrictionFlags.AllowUTurn, ToOptBool(value)); - - bool IJunctionRestrictionsManager.SetNearTurnOnRedAllowed(ushort segmentId, bool startNode, TernaryBool value) - => SetValue(segmentId, startNode, JunctionRestrictionFlags.AllowNearTurnOnRed, ToOptBool(value)); - - bool IJunctionRestrictionsManager.SetFarTurnOnRedAllowed(ushort segmentId, bool startNode, TernaryBool value) - => SetValue(segmentId, startNode, JunctionRestrictionFlags.AllowFarTurnOnRed, ToOptBool(value)); - - bool IJunctionRestrictionsManager.SetTurnOnRedAllowed(bool near, ushort segmentId, bool startNode, TernaryBool value) - => SetValue(segmentId, startNode, near ? JunctionRestrictionFlags.AllowNearTurnOnRed : JunctionRestrictionFlags.AllowFarTurnOnRed, ToOptBool(value)); - - bool IJunctionRestrictionsManager.SetLaneChangingAllowedWhenGoingStraight(ushort segmentId, bool startNode, TernaryBool value) - => SetValue(segmentId, startNode, JunctionRestrictionFlags.AllowForwardLaneChange, ToOptBool(value)); - - bool IJunctionRestrictionsManager.SetEnteringBlockedJunctionAllowed(ushort segmentId, bool startNode, TernaryBool value) - => SetValue(segmentId, startNode, JunctionRestrictionFlags.AllowEnterWhenBlocked, ToOptBool(value)); - - bool IJunctionRestrictionsManager.SetPedestrianCrossingAllowed(ushort segmentId, bool startNode, TernaryBool value) - => SetValue(segmentId, startNode, JunctionRestrictionFlags.AllowPedestrianCrossing, ToOptBool(value)); - public bool? GetValue(ushort segmentId, bool startNode, JunctionRestrictionFlags flags) => segmentRestrictions[segmentId].GetValue(segmentId.AtNode(startNode), flags); public bool GetValueOrDefault(ushort segmentId, bool startNode, JunctionRestrictionFlags flags) => segmentRestrictions[segmentId].GetValueOrDefault(segmentId.AtNode(startNode), flags); - TernaryBool IJunctionRestrictionsManager.GetUturnAllowed(ushort segmentId, bool startNode) - => ToTernaryBool(GetValue(segmentId, startNode, JunctionRestrictionFlags.AllowUTurn)); - - TernaryBool IJunctionRestrictionsManager.GetNearTurnOnRedAllowed(ushort segmentId, bool startNode) - => ToTernaryBool(GetValue(segmentId, startNode, JunctionRestrictionFlags.AllowNearTurnOnRed)); - - TernaryBool IJunctionRestrictionsManager.GetFarTurnOnRedAllowed(ushort segmentId, bool startNode) - => ToTernaryBool(GetValue(segmentId, startNode, JunctionRestrictionFlags.AllowFarTurnOnRed)); - - TernaryBool IJunctionRestrictionsManager.GetTurnOnRedAllowed(bool near, ushort segmentId, bool startNode) - => ToTernaryBool(GetValue(segmentId, startNode, near ? JunctionRestrictionFlags.AllowNearTurnOnRed : JunctionRestrictionFlags.AllowFarTurnOnRed)); - - TernaryBool IJunctionRestrictionsManager.GetLaneChangingAllowedWhenGoingStraight(ushort segmentId, bool startNode) - => ToTernaryBool(GetValue(segmentId, startNode, JunctionRestrictionFlags.AllowForwardLaneChange)); - - TernaryBool IJunctionRestrictionsManager.GetEnteringBlockedJunctionAllowed(ushort segmentId, bool startNode) - => ToTernaryBool(GetValue(segmentId, startNode, JunctionRestrictionFlags.AllowEnterWhenBlocked)); - - TernaryBool IJunctionRestrictionsManager.GetPedestrianCrossingAllowed(ushort segmentId, bool startNode) - => ToTernaryBool(GetValue(segmentId, startNode, JunctionRestrictionFlags.AllowPedestrianCrossing)); - - bool IJunctionRestrictionsManager.IsUturnAllowed(ushort segmentId, bool startNode) - => GetValueOrDefault(segmentId, startNode, JunctionRestrictionFlags.AllowUTurn); - - bool IJunctionRestrictionsManager.IsNearTurnOnRedAllowed(ushort segmentId, bool startNode) - => GetValueOrDefault(segmentId, startNode, JunctionRestrictionFlags.AllowNearTurnOnRed); - - bool IJunctionRestrictionsManager.IsFarTurnOnRedAllowed(ushort segmentId, bool startNode) - => GetValueOrDefault(segmentId, startNode, JunctionRestrictionFlags.AllowFarTurnOnRed); - - bool IJunctionRestrictionsManager.IsTurnOnRedAllowed(bool near, ushort segmentId, bool startNode) - => GetValueOrDefault(segmentId, startNode, near ? JunctionRestrictionFlags.AllowNearTurnOnRed : JunctionRestrictionFlags.AllowFarTurnOnRed); - - bool IJunctionRestrictionsManager.IsLaneChangingAllowedWhenGoingStraight(ushort segmentId, bool startNode) - => GetValueOrDefault(segmentId, startNode, JunctionRestrictionFlags.AllowForwardLaneChange); - - bool IJunctionRestrictionsManager.IsEnteringBlockedJunctionAllowed(ushort segmentId, bool startNode) - => GetValueOrDefault(segmentId, startNode, JunctionRestrictionFlags.AllowEnterWhenBlocked); - - bool IJunctionRestrictionsManager.IsPedestrianCrossingAllowed(ushort segmentId, bool startNode) - => GetValueOrDefault(segmentId, startNode, JunctionRestrictionFlags.AllowPedestrianCrossing); + bool IJunctionRestrictionsManager.IsUturnAllowedConfigurable(ushort segmentId, bool startNode, ref NetNode node) => IsConfigurable(segmentId, startNode, JunctionRestrictionFlags.AllowUTurn); + bool IJunctionRestrictionsManager.IsNearTurnOnRedAllowedConfigurable(ushort segmentId, bool startNode, ref NetNode node) => IsConfigurable(segmentId, startNode, JunctionRestrictionFlags.AllowNearTurnOnRed); + bool IJunctionRestrictionsManager.IsFarTurnOnRedAllowedConfigurable(ushort segmentId, bool startNode, ref NetNode node) => IsConfigurable(segmentId, startNode, JunctionRestrictionFlags.AllowFarTurnOnRed); + bool IJunctionRestrictionsManager.IsTurnOnRedAllowedConfigurable(bool near, ushort segmentId, bool startNode, ref NetNode node) => IsConfigurable(segmentId, startNode, near ? JunctionRestrictionFlags.AllowNearTurnOnRed : JunctionRestrictionFlags.AllowFarTurnOnRed); + bool IJunctionRestrictionsManager.IsLaneChangingAllowedWhenGoingStraightConfigurable(ushort segmentId, bool startNode, ref NetNode node) => IsConfigurable(segmentId, startNode, JunctionRestrictionFlags.AllowForwardLaneChange); + bool IJunctionRestrictionsManager.IsEnteringBlockedJunctionAllowedConfigurable(ushort segmentId, bool startNode, ref NetNode node) => IsConfigurable(segmentId, startNode, JunctionRestrictionFlags.AllowEnterWhenBlocked); + bool IJunctionRestrictionsManager.IsPedestrianCrossingAllowedConfigurable(ushort segmentId, bool startNode, ref NetNode node) => IsConfigurable(segmentId, startNode, JunctionRestrictionFlags.AllowPedestrianCrossing); + bool IJunctionRestrictionsManager.GetDefaultUturnAllowed(ushort segmentId, bool startNode, ref NetNode node) => GetDefaultValue(segmentId, startNode, JunctionRestrictionFlags.AllowUTurn); + bool IJunctionRestrictionsManager.GetDefaultNearTurnOnRedAllowed(ushort segmentId, bool startNode, ref NetNode node) => GetDefaultValue(segmentId, startNode, JunctionRestrictionFlags.AllowNearTurnOnRed); + bool IJunctionRestrictionsManager.GetDefaultFarTurnOnRedAllowed(ushort segmentId, bool startNode, ref NetNode node) => GetDefaultValue(segmentId, startNode, JunctionRestrictionFlags.AllowFarTurnOnRed); + bool IJunctionRestrictionsManager.GetDefaultTurnOnRedAllowed(bool near, ushort segmentId, bool startNode, ref NetNode node) => GetDefaultValue(segmentId, startNode, near ? JunctionRestrictionFlags.AllowNearTurnOnRed : JunctionRestrictionFlags.AllowFarTurnOnRed); + bool IJunctionRestrictionsManager.GetDefaultLaneChangingAllowedWhenGoingStraight(ushort segmentId, bool startNode, ref NetNode node) => GetDefaultValue(segmentId, startNode, JunctionRestrictionFlags.AllowForwardLaneChange); + bool IJunctionRestrictionsManager.GetDefaultEnteringBlockedJunctionAllowed(ushort segmentId, bool startNode, ref NetNode node) => GetDefaultValue(segmentId, startNode, JunctionRestrictionFlags.AllowEnterWhenBlocked); + bool IJunctionRestrictionsManager.GetDefaultPedestrianCrossingAllowed(ushort segmentId, bool startNode, ref NetNode node) => GetDefaultValue(segmentId, startNode, JunctionRestrictionFlags.AllowPedestrianCrossing); + bool IJunctionRestrictionsManager.ToggleUturnAllowed(ushort segmentId, bool startNode) => ToggleValue(segmentId, startNode, JunctionRestrictionFlags.AllowUTurn); + bool IJunctionRestrictionsManager.ToggleNearTurnOnRedAllowed(ushort segmentId, bool startNode) => ToggleValue(segmentId, startNode, JunctionRestrictionFlags.AllowNearTurnOnRed); + bool IJunctionRestrictionsManager.ToggleFarTurnOnRedAllowed(ushort segmentId, bool startNode) => ToggleValue(segmentId, startNode, JunctionRestrictionFlags.AllowFarTurnOnRed); + bool IJunctionRestrictionsManager.ToggleTurnOnRedAllowed(bool near, ushort segmentId, bool startNode) => ToggleValue(segmentId, startNode, near ? JunctionRestrictionFlags.AllowNearTurnOnRed : JunctionRestrictionFlags.AllowFarTurnOnRed); + bool IJunctionRestrictionsManager.ToggleLaneChangingAllowedWhenGoingStraight(ushort segmentId, bool startNode) => ToggleValue(segmentId, startNode, JunctionRestrictionFlags.AllowForwardLaneChange); + bool IJunctionRestrictionsManager.ToggleEnteringBlockedJunctionAllowed(ushort segmentId, bool startNode) => ToggleValue(segmentId, startNode, JunctionRestrictionFlags.AllowEnterWhenBlocked); + bool IJunctionRestrictionsManager.TogglePedestrianCrossingAllowed(ushort segmentId, bool startNode) => ToggleValue(segmentId, startNode, JunctionRestrictionFlags.AllowPedestrianCrossing); + bool IJunctionRestrictionsManager.SetUturnAllowed(ushort segmentId, bool startNode, bool value) => SetValue(segmentId, startNode, JunctionRestrictionFlags.AllowUTurn, value); + bool IJunctionRestrictionsManager.SetNearTurnOnRedAllowed(ushort segmentId, bool startNode, bool value) => SetValue(segmentId, startNode, JunctionRestrictionFlags.AllowNearTurnOnRed, value); + bool IJunctionRestrictionsManager.SetFarTurnOnRedAllowed(ushort segmentId, bool startNode, bool value) => SetValue(segmentId, startNode, JunctionRestrictionFlags.AllowFarTurnOnRed, value); + bool IJunctionRestrictionsManager.SetTurnOnRedAllowed(bool near, ushort segmentId, bool startNode, bool value) => SetValue(segmentId, startNode, near ? JunctionRestrictionFlags.AllowNearTurnOnRed : JunctionRestrictionFlags.AllowFarTurnOnRed, value); + bool IJunctionRestrictionsManager.SetLaneChangingAllowedWhenGoingStraight(ushort segmentId, bool startNode, bool value) => SetValue(segmentId, startNode, JunctionRestrictionFlags.AllowForwardLaneChange, value); + bool IJunctionRestrictionsManager.SetEnteringBlockedJunctionAllowed(ushort segmentId, bool startNode, bool value) => SetValue(segmentId, startNode, JunctionRestrictionFlags.AllowEnterWhenBlocked, value); + bool IJunctionRestrictionsManager.SetPedestrianCrossingAllowed(ushort segmentId, bool startNode, bool value) => SetValue(segmentId, startNode, JunctionRestrictionFlags.AllowPedestrianCrossing, value); + bool IJunctionRestrictionsManager.SetUturnAllowed(ushort segmentId, bool startNode, TernaryBool value) => SetValue(segmentId, startNode, JunctionRestrictionFlags.AllowUTurn, ToOptBool(value)); + bool IJunctionRestrictionsManager.SetNearTurnOnRedAllowed(ushort segmentId, bool startNode, TernaryBool value) => SetValue(segmentId, startNode, JunctionRestrictionFlags.AllowNearTurnOnRed, ToOptBool(value)); + bool IJunctionRestrictionsManager.SetFarTurnOnRedAllowed(ushort segmentId, bool startNode, TernaryBool value) => SetValue(segmentId, startNode, JunctionRestrictionFlags.AllowFarTurnOnRed, ToOptBool(value)); + bool IJunctionRestrictionsManager.SetTurnOnRedAllowed(bool near, ushort segmentId, bool startNode, TernaryBool value) => SetValue(segmentId, startNode, near ? JunctionRestrictionFlags.AllowNearTurnOnRed : JunctionRestrictionFlags.AllowFarTurnOnRed, ToOptBool(value)); + bool IJunctionRestrictionsManager.SetLaneChangingAllowedWhenGoingStraight(ushort segmentId, bool startNode, TernaryBool value) => SetValue(segmentId, startNode, JunctionRestrictionFlags.AllowForwardLaneChange, ToOptBool(value)); + bool IJunctionRestrictionsManager.SetEnteringBlockedJunctionAllowed(ushort segmentId, bool startNode, TernaryBool value) => SetValue(segmentId, startNode, JunctionRestrictionFlags.AllowEnterWhenBlocked, ToOptBool(value)); + bool IJunctionRestrictionsManager.SetPedestrianCrossingAllowed(ushort segmentId, bool startNode, TernaryBool value) => SetValue(segmentId, startNode, JunctionRestrictionFlags.AllowPedestrianCrossing, ToOptBool(value)); + TernaryBool IJunctionRestrictionsManager.GetUturnAllowed(ushort segmentId, bool startNode) => ToTernaryBool(GetValue(segmentId, startNode, JunctionRestrictionFlags.AllowUTurn)); + TernaryBool IJunctionRestrictionsManager.GetNearTurnOnRedAllowed(ushort segmentId, bool startNode) => ToTernaryBool(GetValue(segmentId, startNode, JunctionRestrictionFlags.AllowNearTurnOnRed)); + TernaryBool IJunctionRestrictionsManager.GetFarTurnOnRedAllowed(ushort segmentId, bool startNode) => ToTernaryBool(GetValue(segmentId, startNode, JunctionRestrictionFlags.AllowFarTurnOnRed)); + TernaryBool IJunctionRestrictionsManager.GetTurnOnRedAllowed(bool near, ushort segmentId, bool startNode) => ToTernaryBool(GetValue(segmentId, startNode, near ? JunctionRestrictionFlags.AllowNearTurnOnRed : JunctionRestrictionFlags.AllowFarTurnOnRed)); + TernaryBool IJunctionRestrictionsManager.GetLaneChangingAllowedWhenGoingStraight(ushort segmentId, bool startNode) => ToTernaryBool(GetValue(segmentId, startNode, JunctionRestrictionFlags.AllowForwardLaneChange)); + TernaryBool IJunctionRestrictionsManager.GetEnteringBlockedJunctionAllowed(ushort segmentId, bool startNode) => ToTernaryBool(GetValue(segmentId, startNode, JunctionRestrictionFlags.AllowEnterWhenBlocked)); + TernaryBool IJunctionRestrictionsManager.GetPedestrianCrossingAllowed(ushort segmentId, bool startNode) => ToTernaryBool(GetValue(segmentId, startNode, JunctionRestrictionFlags.AllowPedestrianCrossing)); + bool IJunctionRestrictionsManager.IsUturnAllowed(ushort segmentId, bool startNode) => GetValueOrDefault(segmentId, startNode, JunctionRestrictionFlags.AllowUTurn); + bool IJunctionRestrictionsManager.IsNearTurnOnRedAllowed(ushort segmentId, bool startNode) => GetValueOrDefault(segmentId, startNode, JunctionRestrictionFlags.AllowNearTurnOnRed); + bool IJunctionRestrictionsManager.IsFarTurnOnRedAllowed(ushort segmentId, bool startNode) => GetValueOrDefault(segmentId, startNode, JunctionRestrictionFlags.AllowFarTurnOnRed); + bool IJunctionRestrictionsManager.IsTurnOnRedAllowed(bool near, ushort segmentId, bool startNode) => GetValueOrDefault(segmentId, startNode, near ? JunctionRestrictionFlags.AllowNearTurnOnRed : JunctionRestrictionFlags.AllowFarTurnOnRed); + bool IJunctionRestrictionsManager.IsLaneChangingAllowedWhenGoingStraight(ushort segmentId, bool startNode) => GetValueOrDefault(segmentId, startNode, JunctionRestrictionFlags.AllowForwardLaneChange); + bool IJunctionRestrictionsManager.IsEnteringBlockedJunctionAllowed(ushort segmentId, bool startNode) => GetValueOrDefault(segmentId, startNode, JunctionRestrictionFlags.AllowEnterWhenBlocked); + bool IJunctionRestrictionsManager.IsPedestrianCrossingAllowed(ushort segmentId, bool startNode) => GetValueOrDefault(segmentId, startNode, JunctionRestrictionFlags.AllowPedestrianCrossing); private struct SegmentJunctionRestrictions { public JunctionRestrictions startNodeRestrictions; From b00d0e718e6a1c4072baf2a2f38eb8718005fe57 Mon Sep 17 00:00:00 2001 From: Elesbaan70 <95266227+Elesbaan70@users.noreply.github.com> Date: Sat, 28 May 2022 07:17:10 -0500 Subject: [PATCH 15/21] clean up some notifications --- .../Impl/JunctionRestrictionsManager.cs | 31 ++++++++----------- 1 file changed, 13 insertions(+), 18 deletions(-) diff --git a/TLM/TLM/Manager/Impl/JunctionRestrictionsManager.cs b/TLM/TLM/Manager/Impl/JunctionRestrictionsManager.cs index 8ea3f7de4..51475c408 100644 --- a/TLM/TLM/Manager/Impl/JunctionRestrictionsManager.cs +++ b/TLM/TLM/Manager/Impl/JunctionRestrictionsManager.cs @@ -600,20 +600,21 @@ private void SetSegmentJunctionRestrictions(SegmentEndId segmentEndId, JunctionR private static ref NetNode GetNode(ushort segmentId, bool startNode) => ref segmentId.ToSegment().GetNodeId(startNode).ToNode(); - private void OnSegmentChange(ushort segmentId, - bool startNode, - ref ExtSegment seg, + private void OnSegmentChange(SegmentEndId segmentEndId, bool requireRecalc) { + + ref var seg = ref ExtSegmentManager.Instance.ExtSegments[segmentEndId.SegmentId]; + HandleValidSegment(ref seg); if (requireRecalc) { - RoutingManager.Instance.RequestRecalculation(segmentId); + RoutingManager.Instance.RequestRecalculation(segmentEndId.SegmentId); if (TMPELifecycle.Instance.MayPublishSegmentChanges()) { - ExtSegmentManager.Instance.PublishSegmentChanges(segmentId); + ExtSegmentManager.Instance.PublishSegmentChanges(segmentEndId.SegmentId); } } - Notifier.Instance.OnNodeModified(segmentId.ToSegment().GetNodeId(startNode), this); + Notifier.Instance.OnNodeModified(segmentEndId.GetNodeId(), this); } public override void OnLevelUnloading() { @@ -893,8 +894,8 @@ public void Reset(ushort segmentId) { } public void Invalidate(ushort segmentId) { - startNodeRestrictions.Invalidate(segmentId.AtStartNode()); - endNodeRestrictions.Invalidate(segmentId.AtEndNode()); + startNodeRestrictions.Invalidate(segmentId.AtStartNode(), false); + endNodeRestrictions.Invalidate(segmentId.AtEndNode(), false); Notifier.Instance.OnNodeModified(segmentId, Instance); } @@ -1011,10 +1012,6 @@ private bool Set(SegmentEndId segmentEndId, JunctionRestrictionFlags flags, Junc values = newValues & flags; mask = newMask & flags; - Instance.OnSegmentChange(segmentEndId.SegmentId, - segmentEndId.StartNode, - ref ExtSegmentManager.Instance.ExtSegments[segmentEndId.SegmentId], - (flags & routingRecalculationFlags) != 0); return true; } @@ -1059,10 +1056,7 @@ private void Recalculate(SegmentEndId segmentEndId) { mask &= configurables; } - Instance.OnSegmentChange(segmentEndId.SegmentId, - segmentEndId.StartNode, - ref ExtSegmentManager.Instance.ExtSegments[segmentEndId.SegmentId], - ((recalculateFlags | clearFlags) & routingRecalculationFlags) != 0); + Instance.OnSegmentChange(segmentEndId, ((recalculateFlags | clearFlags) & routingRecalculationFlags) != 0); } } @@ -1074,9 +1068,10 @@ public void Reset(SegmentEndId segmentEndId, bool resetDefaults = true) { } } - public void Invalidate(SegmentEndId segmentEndId) { + public void Invalidate(SegmentEndId segmentEndId, bool notify = true) { valid = default; - Notifier.Instance.OnNodeModified(segmentEndId.GetNodeId(), Instance); + if (notify) + Notifier.Instance.OnNodeModified(segmentEndId.GetNodeId(), Instance); } public override string ToString() { From 2fac55b4941dd63c3c417a33b70321c9c1c91d2a Mon Sep 17 00:00:00 2001 From: Elesbaan70 <95266227+Elesbaan70@users.noreply.github.com> Date: Sat, 28 May 2022 09:02:45 -0500 Subject: [PATCH 16/21] Make as many deprecated methods as possible public/obsolete, to help with compatibility --- .../Impl/JunctionRestrictionsManager.cs | 70 +++++++++---------- 1 file changed, 35 insertions(+), 35 deletions(-) diff --git a/TLM/TLM/Manager/Impl/JunctionRestrictionsManager.cs b/TLM/TLM/Manager/Impl/JunctionRestrictionsManager.cs index 51475c408..435162df1 100644 --- a/TLM/TLM/Manager/Impl/JunctionRestrictionsManager.cs +++ b/TLM/TLM/Manager/Impl/JunctionRestrictionsManager.cs @@ -814,41 +814,41 @@ public bool GetValueOrDefault(ushort segmentId, bool startNode, JunctionRestrict bool IJunctionRestrictionsManager.GetDefaultLaneChangingAllowedWhenGoingStraight(ushort segmentId, bool startNode, ref NetNode node) => GetDefaultValue(segmentId, startNode, JunctionRestrictionFlags.AllowForwardLaneChange); bool IJunctionRestrictionsManager.GetDefaultEnteringBlockedJunctionAllowed(ushort segmentId, bool startNode, ref NetNode node) => GetDefaultValue(segmentId, startNode, JunctionRestrictionFlags.AllowEnterWhenBlocked); bool IJunctionRestrictionsManager.GetDefaultPedestrianCrossingAllowed(ushort segmentId, bool startNode, ref NetNode node) => GetDefaultValue(segmentId, startNode, JunctionRestrictionFlags.AllowPedestrianCrossing); - bool IJunctionRestrictionsManager.ToggleUturnAllowed(ushort segmentId, bool startNode) => ToggleValue(segmentId, startNode, JunctionRestrictionFlags.AllowUTurn); - bool IJunctionRestrictionsManager.ToggleNearTurnOnRedAllowed(ushort segmentId, bool startNode) => ToggleValue(segmentId, startNode, JunctionRestrictionFlags.AllowNearTurnOnRed); - bool IJunctionRestrictionsManager.ToggleFarTurnOnRedAllowed(ushort segmentId, bool startNode) => ToggleValue(segmentId, startNode, JunctionRestrictionFlags.AllowFarTurnOnRed); - bool IJunctionRestrictionsManager.ToggleTurnOnRedAllowed(bool near, ushort segmentId, bool startNode) => ToggleValue(segmentId, startNode, near ? JunctionRestrictionFlags.AllowNearTurnOnRed : JunctionRestrictionFlags.AllowFarTurnOnRed); - bool IJunctionRestrictionsManager.ToggleLaneChangingAllowedWhenGoingStraight(ushort segmentId, bool startNode) => ToggleValue(segmentId, startNode, JunctionRestrictionFlags.AllowForwardLaneChange); - bool IJunctionRestrictionsManager.ToggleEnteringBlockedJunctionAllowed(ushort segmentId, bool startNode) => ToggleValue(segmentId, startNode, JunctionRestrictionFlags.AllowEnterWhenBlocked); - bool IJunctionRestrictionsManager.TogglePedestrianCrossingAllowed(ushort segmentId, bool startNode) => ToggleValue(segmentId, startNode, JunctionRestrictionFlags.AllowPedestrianCrossing); - bool IJunctionRestrictionsManager.SetUturnAllowed(ushort segmentId, bool startNode, bool value) => SetValue(segmentId, startNode, JunctionRestrictionFlags.AllowUTurn, value); - bool IJunctionRestrictionsManager.SetNearTurnOnRedAllowed(ushort segmentId, bool startNode, bool value) => SetValue(segmentId, startNode, JunctionRestrictionFlags.AllowNearTurnOnRed, value); - bool IJunctionRestrictionsManager.SetFarTurnOnRedAllowed(ushort segmentId, bool startNode, bool value) => SetValue(segmentId, startNode, JunctionRestrictionFlags.AllowFarTurnOnRed, value); - bool IJunctionRestrictionsManager.SetTurnOnRedAllowed(bool near, ushort segmentId, bool startNode, bool value) => SetValue(segmentId, startNode, near ? JunctionRestrictionFlags.AllowNearTurnOnRed : JunctionRestrictionFlags.AllowFarTurnOnRed, value); - bool IJunctionRestrictionsManager.SetLaneChangingAllowedWhenGoingStraight(ushort segmentId, bool startNode, bool value) => SetValue(segmentId, startNode, JunctionRestrictionFlags.AllowForwardLaneChange, value); - bool IJunctionRestrictionsManager.SetEnteringBlockedJunctionAllowed(ushort segmentId, bool startNode, bool value) => SetValue(segmentId, startNode, JunctionRestrictionFlags.AllowEnterWhenBlocked, value); - bool IJunctionRestrictionsManager.SetPedestrianCrossingAllowed(ushort segmentId, bool startNode, bool value) => SetValue(segmentId, startNode, JunctionRestrictionFlags.AllowPedestrianCrossing, value); - bool IJunctionRestrictionsManager.SetUturnAllowed(ushort segmentId, bool startNode, TernaryBool value) => SetValue(segmentId, startNode, JunctionRestrictionFlags.AllowUTurn, ToOptBool(value)); - bool IJunctionRestrictionsManager.SetNearTurnOnRedAllowed(ushort segmentId, bool startNode, TernaryBool value) => SetValue(segmentId, startNode, JunctionRestrictionFlags.AllowNearTurnOnRed, ToOptBool(value)); - bool IJunctionRestrictionsManager.SetFarTurnOnRedAllowed(ushort segmentId, bool startNode, TernaryBool value) => SetValue(segmentId, startNode, JunctionRestrictionFlags.AllowFarTurnOnRed, ToOptBool(value)); - bool IJunctionRestrictionsManager.SetTurnOnRedAllowed(bool near, ushort segmentId, bool startNode, TernaryBool value) => SetValue(segmentId, startNode, near ? JunctionRestrictionFlags.AllowNearTurnOnRed : JunctionRestrictionFlags.AllowFarTurnOnRed, ToOptBool(value)); - bool IJunctionRestrictionsManager.SetLaneChangingAllowedWhenGoingStraight(ushort segmentId, bool startNode, TernaryBool value) => SetValue(segmentId, startNode, JunctionRestrictionFlags.AllowForwardLaneChange, ToOptBool(value)); - bool IJunctionRestrictionsManager.SetEnteringBlockedJunctionAllowed(ushort segmentId, bool startNode, TernaryBool value) => SetValue(segmentId, startNode, JunctionRestrictionFlags.AllowEnterWhenBlocked, ToOptBool(value)); - bool IJunctionRestrictionsManager.SetPedestrianCrossingAllowed(ushort segmentId, bool startNode, TernaryBool value) => SetValue(segmentId, startNode, JunctionRestrictionFlags.AllowPedestrianCrossing, ToOptBool(value)); - TernaryBool IJunctionRestrictionsManager.GetUturnAllowed(ushort segmentId, bool startNode) => ToTernaryBool(GetValue(segmentId, startNode, JunctionRestrictionFlags.AllowUTurn)); - TernaryBool IJunctionRestrictionsManager.GetNearTurnOnRedAllowed(ushort segmentId, bool startNode) => ToTernaryBool(GetValue(segmentId, startNode, JunctionRestrictionFlags.AllowNearTurnOnRed)); - TernaryBool IJunctionRestrictionsManager.GetFarTurnOnRedAllowed(ushort segmentId, bool startNode) => ToTernaryBool(GetValue(segmentId, startNode, JunctionRestrictionFlags.AllowFarTurnOnRed)); - TernaryBool IJunctionRestrictionsManager.GetTurnOnRedAllowed(bool near, ushort segmentId, bool startNode) => ToTernaryBool(GetValue(segmentId, startNode, near ? JunctionRestrictionFlags.AllowNearTurnOnRed : JunctionRestrictionFlags.AllowFarTurnOnRed)); - TernaryBool IJunctionRestrictionsManager.GetLaneChangingAllowedWhenGoingStraight(ushort segmentId, bool startNode) => ToTernaryBool(GetValue(segmentId, startNode, JunctionRestrictionFlags.AllowForwardLaneChange)); - TernaryBool IJunctionRestrictionsManager.GetEnteringBlockedJunctionAllowed(ushort segmentId, bool startNode) => ToTernaryBool(GetValue(segmentId, startNode, JunctionRestrictionFlags.AllowEnterWhenBlocked)); - TernaryBool IJunctionRestrictionsManager.GetPedestrianCrossingAllowed(ushort segmentId, bool startNode) => ToTernaryBool(GetValue(segmentId, startNode, JunctionRestrictionFlags.AllowPedestrianCrossing)); - bool IJunctionRestrictionsManager.IsUturnAllowed(ushort segmentId, bool startNode) => GetValueOrDefault(segmentId, startNode, JunctionRestrictionFlags.AllowUTurn); - bool IJunctionRestrictionsManager.IsNearTurnOnRedAllowed(ushort segmentId, bool startNode) => GetValueOrDefault(segmentId, startNode, JunctionRestrictionFlags.AllowNearTurnOnRed); - bool IJunctionRestrictionsManager.IsFarTurnOnRedAllowed(ushort segmentId, bool startNode) => GetValueOrDefault(segmentId, startNode, JunctionRestrictionFlags.AllowFarTurnOnRed); - bool IJunctionRestrictionsManager.IsTurnOnRedAllowed(bool near, ushort segmentId, bool startNode) => GetValueOrDefault(segmentId, startNode, near ? JunctionRestrictionFlags.AllowNearTurnOnRed : JunctionRestrictionFlags.AllowFarTurnOnRed); - bool IJunctionRestrictionsManager.IsLaneChangingAllowedWhenGoingStraight(ushort segmentId, bool startNode) => GetValueOrDefault(segmentId, startNode, JunctionRestrictionFlags.AllowForwardLaneChange); - bool IJunctionRestrictionsManager.IsEnteringBlockedJunctionAllowed(ushort segmentId, bool startNode) => GetValueOrDefault(segmentId, startNode, JunctionRestrictionFlags.AllowEnterWhenBlocked); - bool IJunctionRestrictionsManager.IsPedestrianCrossingAllowed(ushort segmentId, bool startNode) => GetValueOrDefault(segmentId, startNode, JunctionRestrictionFlags.AllowPedestrianCrossing); + [Obsolete("If you must call this method, please go through IJunctionRestrictionsManager.", true)] public bool ToggleUturnAllowed(ushort segmentId, bool startNode) => ToggleValue(segmentId, startNode, JunctionRestrictionFlags.AllowUTurn); + [Obsolete("If you must call this method, please go through IJunctionRestrictionsManager.", true)] public bool ToggleNearTurnOnRedAllowed(ushort segmentId, bool startNode) => ToggleValue(segmentId, startNode, JunctionRestrictionFlags.AllowNearTurnOnRed); + [Obsolete("If you must call this method, please go through IJunctionRestrictionsManager.", true)] public bool ToggleFarTurnOnRedAllowed(ushort segmentId, bool startNode) => ToggleValue(segmentId, startNode, JunctionRestrictionFlags.AllowFarTurnOnRed); + [Obsolete("If you must call this method, please go through IJunctionRestrictionsManager.", true)] public bool ToggleTurnOnRedAllowed(bool near, ushort segmentId, bool startNode) => ToggleValue(segmentId, startNode, near ? JunctionRestrictionFlags.AllowNearTurnOnRed : JunctionRestrictionFlags.AllowFarTurnOnRed); + [Obsolete("If you must call this method, please go through IJunctionRestrictionsManager.", true)] public bool ToggleLaneChangingAllowedWhenGoingStraight(ushort segmentId, bool startNode) => ToggleValue(segmentId, startNode, JunctionRestrictionFlags.AllowForwardLaneChange); + [Obsolete("If you must call this method, please go through IJunctionRestrictionsManager.", true)] public bool ToggleEnteringBlockedJunctionAllowed(ushort segmentId, bool startNode) => ToggleValue(segmentId, startNode, JunctionRestrictionFlags.AllowEnterWhenBlocked); + [Obsolete("If you must call this method, please go through IJunctionRestrictionsManager.", true)] public bool TogglePedestrianCrossingAllowed(ushort segmentId, bool startNode) => ToggleValue(segmentId, startNode, JunctionRestrictionFlags.AllowPedestrianCrossing); + [Obsolete("If you must call this method, please go through IJunctionRestrictionsManager.", true)] public bool SetUturnAllowed(ushort segmentId, bool startNode, bool value) => SetValue(segmentId, startNode, JunctionRestrictionFlags.AllowUTurn, value); + [Obsolete("If you must call this method, please go through IJunctionRestrictionsManager.", true)] public bool SetNearTurnOnRedAllowed(ushort segmentId, bool startNode, bool value) => SetValue(segmentId, startNode, JunctionRestrictionFlags.AllowNearTurnOnRed, value); + [Obsolete("If you must call this method, please go through IJunctionRestrictionsManager.", true)] public bool SetFarTurnOnRedAllowed(ushort segmentId, bool startNode, bool value) => SetValue(segmentId, startNode, JunctionRestrictionFlags.AllowFarTurnOnRed, value); + [Obsolete("If you must call this method, please go through IJunctionRestrictionsManager.", true)] public bool SetTurnOnRedAllowed(bool near, ushort segmentId, bool startNode, bool value) => SetValue(segmentId, startNode, near ? JunctionRestrictionFlags.AllowNearTurnOnRed : JunctionRestrictionFlags.AllowFarTurnOnRed, value); + [Obsolete("If you must call this method, please go through IJunctionRestrictionsManager.", true)] public bool SetLaneChangingAllowedWhenGoingStraight(ushort segmentId, bool startNode, bool value) => SetValue(segmentId, startNode, JunctionRestrictionFlags.AllowForwardLaneChange, value); + [Obsolete("If you must call this method, please go through IJunctionRestrictionsManager.", true)] public bool SetEnteringBlockedJunctionAllowed(ushort segmentId, bool startNode, bool value) => SetValue(segmentId, startNode, JunctionRestrictionFlags.AllowEnterWhenBlocked, value); + [Obsolete("If you must call this method, please go through IJunctionRestrictionsManager.", true)] public bool SetPedestrianCrossingAllowed(ushort segmentId, bool startNode, bool value) => SetValue(segmentId, startNode, JunctionRestrictionFlags.AllowPedestrianCrossing, value); + [Obsolete("If you must call this method, please go through IJunctionRestrictionsManager.", true)] public bool SetUturnAllowed(ushort segmentId, bool startNode, TernaryBool value) => SetValue(segmentId, startNode, JunctionRestrictionFlags.AllowUTurn, ToOptBool(value)); + [Obsolete("If you must call this method, please go through IJunctionRestrictionsManager.", true)] public bool SetNearTurnOnRedAllowed(ushort segmentId, bool startNode, TernaryBool value) => SetValue(segmentId, startNode, JunctionRestrictionFlags.AllowNearTurnOnRed, ToOptBool(value)); + [Obsolete("If you must call this method, please go through IJunctionRestrictionsManager.", true)] public bool SetFarTurnOnRedAllowed(ushort segmentId, bool startNode, TernaryBool value) => SetValue(segmentId, startNode, JunctionRestrictionFlags.AllowFarTurnOnRed, ToOptBool(value)); + [Obsolete("If you must call this method, please go through IJunctionRestrictionsManager.", true)] public bool SetTurnOnRedAllowed(bool near, ushort segmentId, bool startNode, TernaryBool value) => SetValue(segmentId, startNode, near ? JunctionRestrictionFlags.AllowNearTurnOnRed : JunctionRestrictionFlags.AllowFarTurnOnRed, ToOptBool(value)); + [Obsolete("If you must call this method, please go through IJunctionRestrictionsManager.", true)] public bool SetLaneChangingAllowedWhenGoingStraight(ushort segmentId, bool startNode, TernaryBool value) => SetValue(segmentId, startNode, JunctionRestrictionFlags.AllowForwardLaneChange, ToOptBool(value)); + [Obsolete("If you must call this method, please go through IJunctionRestrictionsManager.", true)] public bool SetEnteringBlockedJunctionAllowed(ushort segmentId, bool startNode, TernaryBool value) => SetValue(segmentId, startNode, JunctionRestrictionFlags.AllowEnterWhenBlocked, ToOptBool(value)); + [Obsolete("If you must call this method, please go through IJunctionRestrictionsManager.", true)] public bool SetPedestrianCrossingAllowed(ushort segmentId, bool startNode, TernaryBool value) => SetValue(segmentId, startNode, JunctionRestrictionFlags.AllowPedestrianCrossing, ToOptBool(value)); + [Obsolete("If you must call this method, please go through IJunctionRestrictionsManager.", true)] public TernaryBool GetUturnAllowed(ushort segmentId, bool startNode) => ToTernaryBool(GetValue(segmentId, startNode, JunctionRestrictionFlags.AllowUTurn)); + [Obsolete("If you must call this method, please go through IJunctionRestrictionsManager.", true)] public TernaryBool GetNearTurnOnRedAllowed(ushort segmentId, bool startNode) => ToTernaryBool(GetValue(segmentId, startNode, JunctionRestrictionFlags.AllowNearTurnOnRed)); + [Obsolete("If you must call this method, please go through IJunctionRestrictionsManager.", true)] public TernaryBool GetFarTurnOnRedAllowed(ushort segmentId, bool startNode) => ToTernaryBool(GetValue(segmentId, startNode, JunctionRestrictionFlags.AllowFarTurnOnRed)); + [Obsolete("If you must call this method, please go through IJunctionRestrictionsManager.", true)] public TernaryBool GetTurnOnRedAllowed(bool near, ushort segmentId, bool startNode) => ToTernaryBool(GetValue(segmentId, startNode, near ? JunctionRestrictionFlags.AllowNearTurnOnRed : JunctionRestrictionFlags.AllowFarTurnOnRed)); + [Obsolete("If you must call this method, please go through IJunctionRestrictionsManager.", true)] public TernaryBool GetLaneChangingAllowedWhenGoingStraight(ushort segmentId, bool startNode) => ToTernaryBool(GetValue(segmentId, startNode, JunctionRestrictionFlags.AllowForwardLaneChange)); + [Obsolete("If you must call this method, please go through IJunctionRestrictionsManager.", true)] public TernaryBool GetEnteringBlockedJunctionAllowed(ushort segmentId, bool startNode) => ToTernaryBool(GetValue(segmentId, startNode, JunctionRestrictionFlags.AllowEnterWhenBlocked)); + [Obsolete("If you must call this method, please go through IJunctionRestrictionsManager.", true)] public TernaryBool GetPedestrianCrossingAllowed(ushort segmentId, bool startNode) => ToTernaryBool(GetValue(segmentId, startNode, JunctionRestrictionFlags.AllowPedestrianCrossing)); + [Obsolete("If you must call this method, please go through IJunctionRestrictionsManager.", true)] public bool IsUturnAllowed(ushort segmentId, bool startNode) => GetValueOrDefault(segmentId, startNode, JunctionRestrictionFlags.AllowUTurn); + [Obsolete("If you must call this method, please go through IJunctionRestrictionsManager.", true)] public bool IsNearTurnOnRedAllowed(ushort segmentId, bool startNode) => GetValueOrDefault(segmentId, startNode, JunctionRestrictionFlags.AllowNearTurnOnRed); + [Obsolete("If you must call this method, please go through IJunctionRestrictionsManager.", true)] public bool IsFarTurnOnRedAllowed(ushort segmentId, bool startNode) => GetValueOrDefault(segmentId, startNode, JunctionRestrictionFlags.AllowFarTurnOnRed); + [Obsolete("If you must call this method, please go through IJunctionRestrictionsManager.", true)] public bool IsTurnOnRedAllowed(bool near, ushort segmentId, bool startNode) => GetValueOrDefault(segmentId, startNode, near ? JunctionRestrictionFlags.AllowNearTurnOnRed : JunctionRestrictionFlags.AllowFarTurnOnRed); + [Obsolete("If you must call this method, please go through IJunctionRestrictionsManager.", true)] public bool IsLaneChangingAllowedWhenGoingStraight(ushort segmentId, bool startNode) => GetValueOrDefault(segmentId, startNode, JunctionRestrictionFlags.AllowForwardLaneChange); + [Obsolete("If you must call this method, please go through IJunctionRestrictionsManager.", true)] public bool IsEnteringBlockedJunctionAllowed(ushort segmentId, bool startNode) => GetValueOrDefault(segmentId, startNode, JunctionRestrictionFlags.AllowEnterWhenBlocked); + [Obsolete("If you must call this method, please go through IJunctionRestrictionsManager.", true)] public bool IsPedestrianCrossingAllowed(ushort segmentId, bool startNode) => GetValueOrDefault(segmentId, startNode, JunctionRestrictionFlags.AllowPedestrianCrossing); private struct SegmentJunctionRestrictions { public JunctionRestrictions startNodeRestrictions; From 46eb439cf8aeaa0c0b6229adf606f1575d4bd26c Mon Sep 17 00:00:00 2001 From: Elesbaan70 <95266227+Elesbaan70@users.noreply.github.com> Date: Sat, 28 May 2022 10:46:26 -0500 Subject: [PATCH 17/21] several things broken --- .../Manager/Impl/JunctionRestrictionsManager.cs | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/TLM/TLM/Manager/Impl/JunctionRestrictionsManager.cs b/TLM/TLM/Manager/Impl/JunctionRestrictionsManager.cs index 435162df1..02811fab0 100644 --- a/TLM/TLM/Manager/Impl/JunctionRestrictionsManager.cs +++ b/TLM/TLM/Manager/Impl/JunctionRestrictionsManager.cs @@ -894,9 +894,8 @@ public void Reset(ushort segmentId) { } public void Invalidate(ushort segmentId) { - startNodeRestrictions.Invalidate(segmentId.AtStartNode(), false); - endNodeRestrictions.Invalidate(segmentId.AtEndNode(), false); - Notifier.Instance.OnNodeModified(segmentId, Instance); + startNodeRestrictions.Invalidate(segmentId.AtStartNode()); + endNodeRestrictions.Invalidate(segmentId.AtEndNode()); } public override string ToString() { @@ -1054,9 +1053,9 @@ private void Recalculate(SegmentEndId segmentEndId) { if (clearFlags != default) { values &= configurables; mask &= configurables; - } - Instance.OnSegmentChange(segmentEndId, ((recalculateFlags | clearFlags) & routingRecalculationFlags) != 0); + Instance.OnSegmentChange(segmentEndId, (clearFlags & routingRecalculationFlags) != 0); + } } } @@ -1068,10 +1067,9 @@ public void Reset(SegmentEndId segmentEndId, bool resetDefaults = true) { } } - public void Invalidate(SegmentEndId segmentEndId, bool notify = true) { + public void Invalidate(SegmentEndId segmentEndId) { valid = default; - if (notify) - Notifier.Instance.OnNodeModified(segmentEndId.GetNodeId(), Instance); + Notifier.Instance.OnNodeModified(segmentEndId.GetNodeId(), Instance); } public override string ToString() { @@ -1082,4 +1080,4 @@ public override string ToString() { } } } -} \ No newline at end of file +} From 211182babe75ccccd4d1ea06e13e6a925a6b27db Mon Sep 17 00:00:00 2001 From: Elesbaan70 <95266227+Elesbaan70@users.noreply.github.com> Date: Sat, 28 May 2022 15:52:45 -0500 Subject: [PATCH 18/21] IJunctionRestrictionsHook implementation --- TLM/TLM/Constants.cs | 3 + TLM/TLM/Hook/Impl/HookFactory.cs | 14 ++ .../Impl/JunctionRestrictionsManager.cs | 198 ++++++++++++++---- TLM/TLM/TLM.csproj | 1 + TLM/TMPE.API/Hook/IHookFactory.cs | 10 + .../Hook/IJunctionRestrictionsHook.cs | 24 ++- TLM/TMPE.API/Implementations.cs | 3 + TLM/TMPE.API/TMPE.API.csproj | 1 + 8 files changed, 205 insertions(+), 49 deletions(-) create mode 100644 TLM/TLM/Hook/Impl/HookFactory.cs create mode 100644 TLM/TMPE.API/Hook/IHookFactory.cs diff --git a/TLM/TLM/Constants.cs b/TLM/TLM/Constants.cs index 899f15c04..26b757e31 100644 --- a/TLM/TLM/Constants.cs +++ b/TLM/TLM/Constants.cs @@ -1,4 +1,5 @@ namespace TrafficManager { + using TrafficManager.API.Hook; using TrafficManager.API.Manager; using TrafficManager.API.Notifier; using TrafficManager.U; @@ -35,6 +36,8 @@ public static float ByteToFloat(byte b) { public static IManagerFactory ManagerFactory => Manager.Impl.ManagerFactory.Instance; + public static IHookFactory HookFactory => Hook.Impl.HookFactory.Instance; + public static INotifier Notifier => TrafficManager.Notifier.Instance; } } diff --git a/TLM/TLM/Hook/Impl/HookFactory.cs b/TLM/TLM/Hook/Impl/HookFactory.cs new file mode 100644 index 000000000..ae6930eff --- /dev/null +++ b/TLM/TLM/Hook/Impl/HookFactory.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using TrafficManager.API.Hook; + +namespace TrafficManager.Hook.Impl { + public class HookFactory : IHookFactory { + + public static IHookFactory Instance = new HookFactory(); + + public IJunctionRestrictionsHook JunctionRestrictionsHook => Manager.Impl.JunctionRestrictionsManager.Instance; + } +} diff --git a/TLM/TLM/Manager/Impl/JunctionRestrictionsManager.cs b/TLM/TLM/Manager/Impl/JunctionRestrictionsManager.cs index 02811fab0..5e50fdcf0 100644 --- a/TLM/TLM/Manager/Impl/JunctionRestrictionsManager.cs +++ b/TLM/TLM/Manager/Impl/JunctionRestrictionsManager.cs @@ -5,6 +5,7 @@ namespace TrafficManager.Manager.Impl { using System.Collections.Generic; using System; using TrafficManager.API.Geometry; + using TrafficManager.API.Hook; using TrafficManager.API.Manager; using TrafficManager.API.Traffic.Data; using TrafficManager.API.Traffic; @@ -20,11 +21,13 @@ namespace TrafficManager.Manager.Impl { using TrafficManager.Lifecycle; using TrafficManager.API.Traffic.Enums; using TrafficManager.Manager.Impl.LaneConnection; + using static TrafficManager.API.Hook.IJunctionRestrictionsHook; public class JunctionRestrictionsManager : AbstractGeometryObservingManager, ICustomDataManager>, - IJunctionRestrictionsManager + IJunctionRestrictionsManager, + IJunctionRestrictionsHook { public static JunctionRestrictionsManager Instance { get; } = new JunctionRestrictionsManager(); @@ -36,11 +39,31 @@ public class JunctionRestrictionsManager /// private readonly SegmentJunctionRestrictions[] segmentRestrictions; + public event Action GetDefaultsHook; + public event Action GetConfigurableHook; + private JunctionRestrictionsManager() { segmentRestrictions = new SegmentJunctionRestrictions[NetManager.MAX_SEGMENT_COUNT]; orphanedRestrictions = new SegmentJunctionRestrictions[NetManager.MAX_SEGMENT_COUNT]; } + public void InvalidateFlags(ushort segmentId, bool startNode, JunctionRestrictionFlags flags) { + + if (segmentId.ToSegment().IsValid()) { + SegmentEndId segmentEndId = segmentId.AtNode(startNode); + GetJunctionRestrictions(segmentEndId).Invalidate(segmentEndId); + } + } + + public void InvalidateFlags(ushort nodeId, JunctionRestrictionFlags flags) { + + if (nodeId.ToNode().IsValid()) { + foreach (var segmentId in ExtNodeManager.Instance.GetNodeSegmentIds(nodeId, ClockDirection.Clockwise)) { + InvalidateFlags(segmentId, segmentId.ToSegment().IsStartNode(nodeId), flags); + } + } + } + private ref JunctionRestrictions GetJunctionRestrictions(SegmentEndId segmentEndId) { return ref (segmentEndId.StartNode ? ref segmentRestrictions[segmentEndId].startNodeRestrictions @@ -196,7 +219,8 @@ public void UpdateAllDefaults() { } } - private bool IsUturnAllowedConfigurable(ushort segmentId, bool startNode, ref NetNode node) { + [Obsolete("If you must call this method, please go through IJunctionRestrictionsManager.", true)] + public bool IsUturnAllowedConfigurable(ushort segmentId, bool startNode, ref NetNode node) { ref NetSegment netSegment = ref segmentId.ToSegment(); if (!netSegment.IsValid()) { @@ -225,13 +249,35 @@ private bool IsUturnAllowedConfigurable(ushort segmentId, bool startNode, ref Ne return ret; } - private bool GetDefaultUturnAllowed(ushort segmentId, bool startNode, ref NetNode node, bool isConfigurable) { + /// + /// This is necessary because we can't change the signature of methods known to be patched. + /// It will go away once the Node Controller mods are updated. + /// + private static class CalculationContext { + + [ThreadStatic] + private static bool? _isConfigurable; + + public static bool? IsConfigurable { + get => _isConfigurable; + set { + if (value.HasValue && _isConfigurable.HasValue) + throw new InvalidOperationException("JunctionRestrictionsManager.CalculationContext used recursively"); + + _isConfigurable = value; + } + } + } + + [Obsolete("If you must call this method, please go through IJunctionRestrictionsManager.", true)] + public bool GetDefaultUturnAllowed(ushort segmentId, bool startNode, ref NetNode node) { #if DEBUG bool logLogic = DebugSwitch.JunctionRestrictions.Get(); #else const bool logLogic = false; #endif + var isConfigurable = CalculationContext.IsConfigurable ?? IsUturnAllowedConfigurable(segmentId, startNode, ref node); if (!isConfigurable) { bool res = (node.m_flags & (NetNode.Flags.End | NetNode.Flags.OneWayOut)) != NetNode.Flags.None; @@ -261,19 +307,22 @@ private bool GetDefaultUturnAllowed(ushort segmentId, bool startNode, ref NetNod return ret; } - private bool IsNearTurnOnRedAllowedConfigurable(ushort segmentId, + [Obsolete("If you must call this method, please go through IJunctionRestrictionsManager.", true)] + public bool IsNearTurnOnRedAllowedConfigurable(ushort segmentId, bool startNode, ref NetNode node) { return IsTurnOnRedAllowedConfigurable(true, segmentId, startNode, ref node); } - private bool IsFarTurnOnRedAllowedConfigurable(ushort segmentId, + [Obsolete("If you must call this method, please go through IJunctionRestrictionsManager.", true)] + public bool IsFarTurnOnRedAllowedConfigurable(ushort segmentId, bool startNode, ref NetNode node) { return IsTurnOnRedAllowedConfigurable(false, segmentId, startNode, ref node); } - private bool IsTurnOnRedAllowedConfigurable(bool near, + [Obsolete("If you must call this method, please go through IJunctionRestrictionsManager.", true)] + public bool IsTurnOnRedAllowedConfigurable(bool near, ushort segmentId, bool startNode, ref NetNode node) { @@ -295,27 +344,29 @@ private bool IsTurnOnRedAllowedConfigurable(bool near, return ret; } - private bool GetDefaultNearTurnOnRedAllowed(ushort segmentId, + [Obsolete("If you must call this method, please go through IJunctionRestrictionsManager.", true)] + public bool GetDefaultNearTurnOnRedAllowed(ushort segmentId, bool startNode, - ref NetNode node, - bool isConfigurable) { - return GetDefaultTurnOnRedAllowed(true, segmentId, startNode, ref node, isConfigurable); + ref NetNode node) { + return GetDefaultTurnOnRedAllowed(true, segmentId, startNode, ref node); } - private bool GetDefaultFarTurnOnRedAllowed(ushort segmentId, + [Obsolete("If you must call this method, please go through IJunctionRestrictionsManager.", true)] + public bool GetDefaultFarTurnOnRedAllowed(ushort segmentId, bool startNode, - ref NetNode node, - bool isConfigurable) { - return GetDefaultTurnOnRedAllowed(false, segmentId, startNode, ref node, isConfigurable); + ref NetNode node) { + return GetDefaultTurnOnRedAllowed(false, segmentId, startNode, ref node); } - private bool GetDefaultTurnOnRedAllowed(bool near, ushort segmentId, bool startNode, ref NetNode node, bool isConfigurable) { + [Obsolete("If you must call this method, please go through IJunctionRestrictionsManager.", true)] + public bool GetDefaultTurnOnRedAllowed(bool near, ushort segmentId, bool startNode, ref NetNode node) { #if DEBUG bool logLogic = DebugSwitch.JunctionRestrictions.Get(); #else const bool logLogic = false; #endif + var isConfigurable = CalculationContext.IsConfigurable ?? IsTurnOnRedAllowedConfigurable(near, segmentId, startNode, ref node); if (!isConfigurable) { if (logLogic) { Log._Debug( @@ -336,7 +387,8 @@ private bool GetDefaultTurnOnRedAllowed(bool near, ushort segmentId, bool startN return ret; } - private bool IsLaneChangingAllowedWhenGoingStraightConfigurable( + [Obsolete("If you must call this method, please go through IJunctionRestrictionsManager.", true)] + public bool IsLaneChangingAllowedWhenGoingStraightConfigurable( ushort segmentId, bool startNode, ref NetNode node) { @@ -374,13 +426,15 @@ private bool IsLaneChangingAllowedWhenGoingStraightConfigurable( return ret; } - private bool GetDefaultLaneChangingAllowedWhenGoingStraight(ushort segmentId, bool startNode, ref NetNode node, bool isConfigurable) { + [Obsolete("If you must call this method, please go through IJunctionRestrictionsManager.", true)] + public bool GetDefaultLaneChangingAllowedWhenGoingStraight(ushort segmentId, bool startNode, ref NetNode node) { #if DEBUG bool logLogic = DebugSwitch.JunctionRestrictions.Get(); #else const bool logLogic = false; #endif + var isConfigurable = CalculationContext.IsConfigurable ?? IsLaneChangingAllowedWhenGoingStraightConfigurable(segmentId, startNode, ref node); if (!isConfigurable) { if (logLogic) { Log._Debug( @@ -402,7 +456,8 @@ private bool GetDefaultLaneChangingAllowedWhenGoingStraight(ushort segmentId, bo return ret; } - private bool IsEnteringBlockedJunctionAllowedConfigurable( + [Obsolete("If you must call this method, please go through IJunctionRestrictionsManager.", true)] + public bool IsEnteringBlockedJunctionAllowedConfigurable( ushort segmentId, bool startNode, ref NetNode node) { @@ -437,11 +492,11 @@ private bool IsEnteringBlockedJunctionAllowedConfigurable( return ret; } - private bool GetDefaultEnteringBlockedJunctionAllowed( + [Obsolete("If you must call this method, please go through IJunctionRestrictionsManager.", true)] + public bool GetDefaultEnteringBlockedJunctionAllowed( ushort segmentId, bool startNode, - ref NetNode node, - bool isConfigurable) { + ref NetNode node) { #if DEBUG bool logLogic = DebugSwitch.JunctionRestrictions.Get(); #else @@ -453,6 +508,7 @@ private bool GetDefaultEnteringBlockedJunctionAllowed( return false; } + var isConfigurable = CalculationContext.IsConfigurable ?? IsEnteringBlockedJunctionAllowedConfigurable(segmentId, startNode, ref node); if (!isConfigurable) { bool res = (node.m_flags & (NetNode.Flags.Junction | NetNode.Flags.OneWayOut | @@ -500,7 +556,8 @@ private bool GetDefaultEnteringBlockedJunctionAllowed( return ret; } - private bool IsPedestrianCrossingAllowedConfigurable(ushort segmentId, bool startNode, ref NetNode node) { + [Obsolete("If you must call this method, please go through IJunctionRestrictionsManager.", true)] + public bool IsPedestrianCrossingAllowedConfigurable(ushort segmentId, bool startNode, ref NetNode node) { bool ret = (node.m_flags & (NetNode.Flags.Junction | NetNode.Flags.Bend)) != NetNode.Flags.None && node.Info?.m_class?.m_service != ItemClass.Service.Beautification; #if DEBUG @@ -514,13 +571,15 @@ private bool IsPedestrianCrossingAllowedConfigurable(ushort segmentId, bool star return ret; } - private bool GetDefaultPedestrianCrossingAllowed(ushort segmentId, bool startNode, ref NetNode node, bool isConfigurable) { + [Obsolete("If you must call this method, please go through IJunctionRestrictionsManager.", true)] + public bool GetDefaultPedestrianCrossingAllowed(ushort segmentId, bool startNode, ref NetNode node) { #if DEBUG bool logLogic = DebugSwitch.JunctionRestrictions.Get(); #else const bool logLogic = false; #endif + var isConfigurable = CalculationContext.IsConfigurable ?? IsPedestrianCrossingAllowedConfigurable(segmentId, startNode, ref node); if (!isConfigurable) { if (logLogic) { Log._Debug( @@ -1024,30 +1083,85 @@ public bool IsDefault(SegmentEndId segmentEndId) { return ((values & mask) | (defaults & ~mask)) == defaults; } - private delegate bool CalculateConfigurable(ushort segmentId, bool startNode, ref NetNode node); - private delegate bool CalculateDefault(ushort segmentId, bool startNode, ref NetNode node, bool isConfigurable); + private delegate bool Calculator(ushort segmentId, bool startNode, ref NetNode node); - private void Recalculate(SegmentEndId segmentEndId, JunctionRestrictionFlags flags, CalculateConfigurable calculateConfigurable, CalculateDefault calculateDefault) { - if ((valid & flags) != flags) { - bool isConfigurable = calculateConfigurable(segmentEndId.SegmentId, segmentEndId.StartNode, ref segmentEndId.GetNode()); - SetConfigurable(segmentEndId, flags, isConfigurable); - SetDefault(segmentEndId, flags, calculateDefault(segmentEndId.SegmentId, segmentEndId.StartNode, ref segmentEndId.GetNode(), isConfigurable)); - valid |= flags; - } + /// + /// This is needed because the methods are annoted to produce a compiler error if referenced directly. + /// + /// + /// + private static Calculator DelegateTo(string methodName) { + return (Calculator)Delegate.CreateDelegate(typeof(Calculator), Instance, methodName); } + private static Dictionary configurableCalculators = new Dictionary() { + { JunctionRestrictionFlags.AllowUTurn, DelegateTo(nameof(IsUturnAllowedConfigurable)) }, + { JunctionRestrictionFlags.AllowNearTurnOnRed, DelegateTo(nameof(IsNearTurnOnRedAllowedConfigurable)) }, + { JunctionRestrictionFlags.AllowFarTurnOnRed, DelegateTo(nameof(IsFarTurnOnRedAllowedConfigurable)) }, + { JunctionRestrictionFlags.AllowForwardLaneChange, DelegateTo(nameof(IsLaneChangingAllowedWhenGoingStraightConfigurable)) }, + { JunctionRestrictionFlags.AllowEnterWhenBlocked, DelegateTo(nameof(IsEnteringBlockedJunctionAllowedConfigurable)) }, + { JunctionRestrictionFlags.AllowPedestrianCrossing, DelegateTo(nameof(IsPedestrianCrossingAllowedConfigurable)) }, + }; + + private static Dictionary defaultCalculators = new Dictionary() { + { JunctionRestrictionFlags.AllowUTurn, DelegateTo(nameof(GetDefaultUturnAllowed)) }, + { JunctionRestrictionFlags.AllowNearTurnOnRed, DelegateTo(nameof(GetDefaultNearTurnOnRedAllowed)) }, + { JunctionRestrictionFlags.AllowFarTurnOnRed, DelegateTo(nameof(GetDefaultFarTurnOnRedAllowed)) }, + { JunctionRestrictionFlags.AllowForwardLaneChange, DelegateTo(nameof(GetDefaultLaneChangingAllowedWhenGoingStraight)) }, + { JunctionRestrictionFlags.AllowEnterWhenBlocked, DelegateTo(nameof(GetDefaultEnteringBlockedJunctionAllowed)) }, + { JunctionRestrictionFlags.AllowPedestrianCrossing, DelegateTo(nameof(GetDefaultPedestrianCrossingAllowed)) }, + }; + private void Recalculate(SegmentEndId segmentEndId) { var recalculateFlags = JunctionRestrictionFlags.All & ~valid; - if (recalculateFlags != default) { + ref var node = ref segmentEndId.GetNodeId().ToNode(); - Recalculate(segmentEndId, JunctionRestrictionFlags.AllowUTurn, Instance.IsUturnAllowedConfigurable, Instance.GetDefaultUturnAllowed); - Recalculate(segmentEndId, JunctionRestrictionFlags.AllowNearTurnOnRed, Instance.IsNearTurnOnRedAllowedConfigurable, Instance.GetDefaultNearTurnOnRedAllowed); - Recalculate(segmentEndId, JunctionRestrictionFlags.AllowFarTurnOnRed, Instance.IsFarTurnOnRedAllowedConfigurable, Instance.GetDefaultFarTurnOnRedAllowed); - Recalculate(segmentEndId, JunctionRestrictionFlags.AllowForwardLaneChange, Instance.IsLaneChangingAllowedWhenGoingStraightConfigurable, Instance.GetDefaultLaneChangingAllowedWhenGoingStraight); - Recalculate(segmentEndId, JunctionRestrictionFlags.AllowEnterWhenBlocked, Instance.IsEnteringBlockedJunctionAllowedConfigurable, Instance.GetDefaultEnteringBlockedJunctionAllowed); - Recalculate(segmentEndId, JunctionRestrictionFlags.AllowPedestrianCrossing, Instance.IsPedestrianCrossingAllowedConfigurable, Instance.GetDefaultPedestrianCrossingAllowed); + JunctionRestrictionFlags newConfigurables = default; + + foreach (var c in configurableCalculators) { + if ((recalculateFlags & c.Key) != 0) { + var result = c.Value(segmentEndId.SegmentId, segmentEndId.StartNode, ref node); + if (result) + newConfigurables |= c.Key; + else + newConfigurables &= ~c.Key; + } + } + + if (Instance.GetConfigurableHook != null) { + var args = new FlagsHookArgs(segmentEndId.SegmentId, segmentEndId.StartNode, mask, newConfigurables); + Instance.GetConfigurableHook(args); + newConfigurables = args.Result; + } + + JunctionRestrictionFlags newDefaults = default; + + foreach (var c in defaultCalculators) { + if ((recalculateFlags & c.Key) != 0) { + try { + CalculationContext.IsConfigurable = (newConfigurables & c.Key) != 0; + var result = c.Value(segmentEndId.SegmentId, segmentEndId.StartNode, ref node); + if (result) + newDefaults |= c.Key; + else + newDefaults &= ~c.Key; + } + finally { + CalculationContext.IsConfigurable = null; + } + } + } + + if (Instance.GetDefaultsHook != null) { + var args = new FlagsHookArgs(segmentEndId.SegmentId, segmentEndId.StartNode, mask, newDefaults); + Instance.GetDefaultsHook(args); + newDefaults = args.Result; + } + + configurables = (configurables & ~recalculateFlags) | (newConfigurables & recalculateFlags); + defaults = (defaults & ~recalculateFlags) | (newDefaults & recalculateFlags); var clearFlags = mask & ~configurables; if (clearFlags != default) { @@ -1068,8 +1182,10 @@ public void Reset(SegmentEndId segmentEndId, bool resetDefaults = true) { } public void Invalidate(SegmentEndId segmentEndId) { - valid = default; - Notifier.Instance.OnNodeModified(segmentEndId.GetNodeId(), Instance); + if (valid != default) { + valid = default; + Notifier.Instance.OnNodeModified(segmentEndId.GetNodeId(), Instance); + } } public override string ToString() { diff --git a/TLM/TLM/TLM.csproj b/TLM/TLM/TLM.csproj index 2391869ff..afc3dc049 100644 --- a/TLM/TLM/TLM.csproj +++ b/TLM/TLM/TLM.csproj @@ -136,6 +136,7 @@ + diff --git a/TLM/TMPE.API/Hook/IHookFactory.cs b/TLM/TMPE.API/Hook/IHookFactory.cs new file mode 100644 index 000000000..0cbd2f8a6 --- /dev/null +++ b/TLM/TMPE.API/Hook/IHookFactory.cs @@ -0,0 +1,10 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace TrafficManager.API.Hook { + public interface IHookFactory { + IJunctionRestrictionsHook JunctionRestrictionsHook { get; } + } +} diff --git a/TLM/TMPE.API/Hook/IJunctionRestrictionsHook.cs b/TLM/TMPE.API/Hook/IJunctionRestrictionsHook.cs index 211fa02da..359685468 100644 --- a/TLM/TMPE.API/Hook/IJunctionRestrictionsHook.cs +++ b/TLM/TMPE.API/Hook/IJunctionRestrictionsHook.cs @@ -10,20 +10,27 @@ public interface IJunctionRestrictionsHook { /// /// An event that allows a handler to modify the results of a GetDefaultTrafficRule method. /// - event Action GetDefaults; + event Action GetDefaultsHook; /// /// An event that allows a handler to modify the results of an IsTrafficRuleConfigurable method. /// - event Action GetConfigurable; + event Action GetConfigurableHook; /// - /// Invalidates the specified flags so that they will be recalculated. - /// Recalculation is not guaranteed to happen immediately, but is guaranteed to happen - /// before their next use. + /// Schedules the specified flags for recalculation. /// - /// - public void InvalidateFlags(JunctionRestrictionFlags flags); + /// + /// + /// Specifies which flags to invalidate. + public void InvalidateFlags(ushort segmentId, bool startNode, JunctionRestrictionFlags flags); + + /// + /// Schedles the specified flags for recalculation for all segment ends on the specified node. + /// + /// + /// Specifies which flags to invalidate. + public void InvalidateFlags(ushort nodeId, JunctionRestrictionFlags flags); public class FlagsHookArgs { @@ -45,10 +52,11 @@ public class FlagsHookArgs { /// /// The flag return values. Changes to this property alter the outcome of the underlying operation. + /// Any flags that not set in the property are ignored. /// public JunctionRestrictionFlags Result { get; set; } - internal FlagsHookArgs(ushort segmentId, bool startNode, JunctionRestrictionFlags mask, JunctionRestrictionFlags result) { + public FlagsHookArgs(ushort segmentId, bool startNode, JunctionRestrictionFlags mask, JunctionRestrictionFlags result) { SegmentId = segmentId; StartNode = startNode; Mask = mask; diff --git a/TLM/TMPE.API/Implementations.cs b/TLM/TMPE.API/Implementations.cs index 88ecd0bfc..ebeb91037 100644 --- a/TLM/TMPE.API/Implementations.cs +++ b/TLM/TMPE.API/Implementations.cs @@ -3,13 +3,16 @@ namespace TrafficManager.API { using TrafficManager.API.Manager; using TrafficManager.API.Notifier; using System.Linq; + using TrafficManager.API.Hook; public static class Implementations { private static Type constantsType_; private static IManagerFactory managerFactory_; + private static IHookFactory hookFactory_; private static INotifier notifier_; public static IManagerFactory ManagerFactory => managerFactory_ ??= GetImplementation(); + public static IHookFactory HookFactory => hookFactory_ ??= GetImplementation(); public static INotifier Notifier => notifier_ ??= GetImplementation(); private static T GetImplementation() diff --git a/TLM/TMPE.API/TMPE.API.csproj b/TLM/TMPE.API/TMPE.API.csproj index 3463015b1..1a5b2bbb0 100644 --- a/TLM/TMPE.API/TMPE.API.csproj +++ b/TLM/TMPE.API/TMPE.API.csproj @@ -76,6 +76,7 @@ Properties\SharedAssemblyInfo.cs + From f0a6ba175188dab7980930093ab5af4fec54ef9d Mon Sep 17 00:00:00 2001 From: Elesbaan70 <95266227+Elesbaan70@users.noreply.github.com> Date: Sun, 29 May 2022 01:28:35 -0500 Subject: [PATCH 19/21] If I don't rename this, every future developer will curse me --- TLM/TLM/Custom/PathFinding/CustomPathFind.cs | 10 +- .../Impl/JunctionRestrictionsManager.cs | 252 +++++++++--------- .../LaneConnectionSubManager.cs | 2 +- TLM/TLM/Manager/Impl/RoutingManager.cs | 4 +- .../Manager/Impl/VehicleBehaviorManager.cs | 2 +- .../UI/SubTools/ManualTrafficLightsTool.cs | 2 +- .../UI/SubTools/TTL/TimedTrafficLightsTool.cs | 2 +- TLM/TLM/Util/PriorityRoad.cs | 8 +- TLM/TLM/Util/Record/SegmentEndRecord.cs | 36 +-- TLM/TLM/Util/RoundaboutMassEdit.cs | 10 +- .../Hook/IJunctionRestrictionsHook.cs | 10 +- .../Manager/IJunctionRestrictionsManager.cs | 110 ++++---- TLM/TMPE.API/TMPE.API.csproj | 2 +- ...nFlags.cs => JunctionRestrictionsFlags.cs} | 2 +- 14 files changed, 226 insertions(+), 226 deletions(-) rename TLM/TMPE.API/Traffic/Enums/{JunctionRestrictionFlags.cs => JunctionRestrictionsFlags.cs} (88%) diff --git a/TLM/TLM/Custom/PathFinding/CustomPathFind.cs b/TLM/TLM/Custom/PathFinding/CustomPathFind.cs index 9ce297581..a78bcaa96 100644 --- a/TLM/TLM/Custom/PathFinding/CustomPathFind.cs +++ b/TLM/TLM/Custom/PathFinding/CustomPathFind.cs @@ -1088,7 +1088,7 @@ ref nextSegmentId.ToSegment(), leftSegmentId, leftSegment.m_startNode == nextNodeId, - JunctionRestrictionFlags.AllowPedestrianCrossing)) { + JunctionRestrictionsFlags.AllowPedestrianCrossing)) { break; } #endif @@ -1127,7 +1127,7 @@ ref nextSegmentId.ToSegment(), rightSegmentId, rightSegment.m_startNode == nextNodeId, - JunctionRestrictionFlags.AllowPedestrianCrossing)) { + JunctionRestrictionsFlags.AllowPedestrianCrossing)) { break; } #endif @@ -3172,7 +3172,7 @@ private void ProcessItemPedBicycle( if (!junctionManager.GetValueOrDefault( nextSegmentId, nextIsStartNode, - JunctionRestrictionFlags.AllowPedestrianCrossing)) { + JunctionRestrictionsFlags.AllowPedestrianCrossing)) { if (isLogEnabled) { DebugLog( unitId, @@ -3590,7 +3590,7 @@ private bool ProcessItemRouted( prevIsCarLane && // u-turns for road vehicles only (!isHeavyVehicle_ || isStockUturnPoint) && // only small vehicles may perform u-turns OR everyone at stock u-turn points !prevIsOutgoingOneWay && // do not u-turn on one-ways - junctionManager.GetValueOrDefault(prevSegmentId, nextIsStartNode, JunctionRestrictionFlags.AllowUTurn); + junctionManager.GetValueOrDefault(prevSegmentId, nextIsStartNode, JunctionRestrictionsFlags.AllowUTurn); if (isLogEnabled) { DebugLog( @@ -3603,7 +3603,7 @@ private bool ProcessItemRouted( $"\tisStockUturnPoint={isStockUturnPoint}\n" + $"\tprevIsOutgoingOneWay={prevIsOutgoingOneWay}\n" + $"\tjManager.IsUturnAllowed(prevSegmentId, " + - $"nextIsStartNode)={junctionManager.GetValueOrDefault(prevSegmentId, nextIsStartNode, JunctionRestrictionFlags.AllowUTurn)}\n" + + $"nextIsStartNode)={junctionManager.GetValueOrDefault(prevSegmentId, nextIsStartNode, JunctionRestrictionsFlags.AllowUTurn)}\n" + $"\tm_queueItem.vehicleId={queueItem_.vehicleId}\n" + $"\tm_queueItem.spawned={queueItem_.spawned}\n" + $"\tprevSegmentId={prevSegmentId}\n" + diff --git a/TLM/TLM/Manager/Impl/JunctionRestrictionsManager.cs b/TLM/TLM/Manager/Impl/JunctionRestrictionsManager.cs index 5e50fdcf0..458d945ee 100644 --- a/TLM/TLM/Manager/Impl/JunctionRestrictionsManager.cs +++ b/TLM/TLM/Manager/Impl/JunctionRestrictionsManager.cs @@ -47,7 +47,7 @@ private JunctionRestrictionsManager() { orphanedRestrictions = new SegmentJunctionRestrictions[NetManager.MAX_SEGMENT_COUNT]; } - public void InvalidateFlags(ushort segmentId, bool startNode, JunctionRestrictionFlags flags) { + public void InvalidateFlags(ushort segmentId, bool startNode, JunctionRestrictionsFlags flags) { if (segmentId.ToSegment().IsValid()) { SegmentEndId segmentEndId = segmentId.AtNode(startNode); @@ -55,7 +55,7 @@ public void InvalidateFlags(ushort segmentId, bool startNode, JunctionRestrictio } } - public void InvalidateFlags(ushort nodeId, JunctionRestrictionFlags flags) { + public void InvalidateFlags(ushort nodeId, JunctionRestrictionsFlags flags) { if (nodeId.ToNode().IsValid()) { foreach (var segmentId in ExtNodeManager.Instance.GetNodeSegmentIds(nodeId, ClockDirection.Clockwise)) { @@ -649,7 +649,7 @@ public bool ClearSegmentEnd(ushort segmentId, bool startNode) { return false; var segmentEndId = segmentId.AtNode(startNode); - return GetJunctionRestrictions(segmentEndId).ClearValue(segmentEndId, JunctionRestrictionFlags.All); + return GetJunctionRestrictions(segmentEndId).ClearValue(segmentEndId, JunctionRestrictionsFlags.All); } private void SetSegmentJunctionRestrictions(SegmentEndId segmentEndId, JunctionRestrictions restrictions) { @@ -711,12 +711,12 @@ public bool LoadData(List data) { Configuration.SegmentNodeFlags flags = segNodeConf.startNodeFlags; ref NetNode startNode = ref startNodeId.ToNode(); - SetValue(segNodeConf.segmentId, true, JunctionRestrictionFlags.AllowUTurn, flags.uturnAllowed); - SetValue(segNodeConf.segmentId, true, JunctionRestrictionFlags.AllowNearTurnOnRed, flags.turnOnRedAllowed); - SetValue(segNodeConf.segmentId, true, JunctionRestrictionFlags.AllowFarTurnOnRed, flags.farTurnOnRedAllowed); - SetValue(segNodeConf.segmentId, true, JunctionRestrictionFlags.AllowForwardLaneChange, flags.straightLaneChangingAllowed); - SetValue(segNodeConf.segmentId, true, JunctionRestrictionFlags.AllowEnterWhenBlocked, flags.enterWhenBlockedAllowed); - SetValue(segNodeConf.segmentId, true, JunctionRestrictionFlags.AllowPedestrianCrossing, flags.pedestrianCrossingAllowed); + SetValue(segNodeConf.segmentId, true, JunctionRestrictionsFlags.AllowUTurn, flags.uturnAllowed); + SetValue(segNodeConf.segmentId, true, JunctionRestrictionsFlags.AllowNearTurnOnRed, flags.turnOnRedAllowed); + SetValue(segNodeConf.segmentId, true, JunctionRestrictionsFlags.AllowFarTurnOnRed, flags.farTurnOnRedAllowed); + SetValue(segNodeConf.segmentId, true, JunctionRestrictionsFlags.AllowForwardLaneChange, flags.straightLaneChangingAllowed); + SetValue(segNodeConf.segmentId, true, JunctionRestrictionsFlags.AllowEnterWhenBlocked, flags.enterWhenBlockedAllowed); + SetValue(segNodeConf.segmentId, true, JunctionRestrictionsFlags.AllowPedestrianCrossing, flags.pedestrianCrossingAllowed); } else { Log.Warning( "JunctionRestrictionsManager.LoadData(): Could not get segment " + @@ -730,12 +730,12 @@ public bool LoadData(List data) { Configuration.SegmentNodeFlags flags = segNodeConf.endNodeFlags; ref NetNode node = ref endNodeId.ToNode(); - SetValue(segNodeConf.segmentId, false, JunctionRestrictionFlags.AllowUTurn, flags.uturnAllowed); - SetValue(segNodeConf.segmentId, false, JunctionRestrictionFlags.AllowNearTurnOnRed, flags.turnOnRedAllowed); - SetValue(segNodeConf.segmentId, false, JunctionRestrictionFlags.AllowFarTurnOnRed, flags.farTurnOnRedAllowed); - SetValue(segNodeConf.segmentId, false, JunctionRestrictionFlags.AllowForwardLaneChange, flags.straightLaneChangingAllowed); - SetValue(segNodeConf.segmentId, false, JunctionRestrictionFlags.AllowEnterWhenBlocked, flags.enterWhenBlockedAllowed); - SetValue(segNodeConf.segmentId, false, JunctionRestrictionFlags.AllowPedestrianCrossing, flags.pedestrianCrossingAllowed); + SetValue(segNodeConf.segmentId, false, JunctionRestrictionsFlags.AllowUTurn, flags.uturnAllowed); + SetValue(segNodeConf.segmentId, false, JunctionRestrictionsFlags.AllowNearTurnOnRed, flags.turnOnRedAllowed); + SetValue(segNodeConf.segmentId, false, JunctionRestrictionsFlags.AllowFarTurnOnRed, flags.farTurnOnRedAllowed); + SetValue(segNodeConf.segmentId, false, JunctionRestrictionsFlags.AllowForwardLaneChange, flags.straightLaneChangingAllowed); + SetValue(segNodeConf.segmentId, false, JunctionRestrictionsFlags.AllowEnterWhenBlocked, flags.enterWhenBlockedAllowed); + SetValue(segNodeConf.segmentId, false, JunctionRestrictionsFlags.AllowPedestrianCrossing, flags.pedestrianCrossingAllowed); } else { Log.Warning( "JunctionRestrictionsManager.LoadData(): Could not get segment " + @@ -777,12 +777,12 @@ public bool LoadData(List data) { if (!endFlags.IsDefault(segmentId.AtStartNode())) { startNodeFlags = new Configuration.SegmentNodeFlags(); - startNodeFlags.uturnAllowed = GetValue(segmentId, true, JunctionRestrictionFlags.AllowUTurn); - startNodeFlags.turnOnRedAllowed = GetValue(segmentId, true, JunctionRestrictionFlags.AllowNearTurnOnRed); - startNodeFlags.farTurnOnRedAllowed = GetValue(segmentId, true, JunctionRestrictionFlags.AllowFarTurnOnRed); - startNodeFlags.straightLaneChangingAllowed = GetValue(segmentId, true, JunctionRestrictionFlags.AllowForwardLaneChange); - startNodeFlags.enterWhenBlockedAllowed = GetValue(segmentId, true, JunctionRestrictionFlags.AllowEnterWhenBlocked); - startNodeFlags.pedestrianCrossingAllowed = GetValue(segmentId, true, JunctionRestrictionFlags.AllowPedestrianCrossing); + startNodeFlags.uturnAllowed = GetValue(segmentId, true, JunctionRestrictionsFlags.AllowUTurn); + startNodeFlags.turnOnRedAllowed = GetValue(segmentId, true, JunctionRestrictionsFlags.AllowNearTurnOnRed); + startNodeFlags.farTurnOnRedAllowed = GetValue(segmentId, true, JunctionRestrictionsFlags.AllowFarTurnOnRed); + startNodeFlags.straightLaneChangingAllowed = GetValue(segmentId, true, JunctionRestrictionsFlags.AllowForwardLaneChange); + startNodeFlags.enterWhenBlockedAllowed = GetValue(segmentId, true, JunctionRestrictionsFlags.AllowEnterWhenBlocked); + startNodeFlags.pedestrianCrossingAllowed = GetValue(segmentId, true, JunctionRestrictionsFlags.AllowPedestrianCrossing); #if DEBUGSAVE Log._Debug($"JunctionRestrictionsManager.SaveData: Saving start node "+ @@ -799,12 +799,12 @@ public bool LoadData(List data) { if (!restrictions.IsDefault(segmentId.AtEndNode())) { endNodeFlags = new Configuration.SegmentNodeFlags(); - endNodeFlags.uturnAllowed = GetValue(segmentId, false, JunctionRestrictionFlags.AllowUTurn); - endNodeFlags.turnOnRedAllowed = GetValue(segmentId, false, JunctionRestrictionFlags.AllowNearTurnOnRed); - endNodeFlags.farTurnOnRedAllowed = GetValue(segmentId, false, JunctionRestrictionFlags.AllowFarTurnOnRed); - endNodeFlags.straightLaneChangingAllowed = GetValue(segmentId, false, JunctionRestrictionFlags.AllowForwardLaneChange); - endNodeFlags.enterWhenBlockedAllowed = GetValue(segmentId, false, JunctionRestrictionFlags.AllowEnterWhenBlocked); - endNodeFlags.pedestrianCrossingAllowed = GetValue(segmentId, false, JunctionRestrictionFlags.AllowPedestrianCrossing); + endNodeFlags.uturnAllowed = GetValue(segmentId, false, JunctionRestrictionsFlags.AllowUTurn); + endNodeFlags.turnOnRedAllowed = GetValue(segmentId, false, JunctionRestrictionsFlags.AllowNearTurnOnRed); + endNodeFlags.farTurnOnRedAllowed = GetValue(segmentId, false, JunctionRestrictionsFlags.AllowFarTurnOnRed); + endNodeFlags.straightLaneChangingAllowed = GetValue(segmentId, false, JunctionRestrictionsFlags.AllowForwardLaneChange); + endNodeFlags.enterWhenBlockedAllowed = GetValue(segmentId, false, JunctionRestrictionsFlags.AllowEnterWhenBlocked); + endNodeFlags.pedestrianCrossingAllowed = GetValue(segmentId, false, JunctionRestrictionsFlags.AllowPedestrianCrossing); #if DEBUGSAVE Log._Debug($"JunctionRestrictionsManager.SaveData: Saving end node junction "+ @@ -836,13 +836,13 @@ public bool LoadData(List data) { return ret; } - public bool IsConfigurable(ushort segmentId, bool startNode, JunctionRestrictionFlags flags) + public bool IsConfigurable(ushort segmentId, bool startNode, JunctionRestrictionsFlags flags) => segmentRestrictions[segmentId].IsConfigurable(segmentId.AtNode(startNode), flags); - public bool GetDefaultValue(ushort segmentId, bool startNode, JunctionRestrictionFlags flags) + public bool GetDefaultValue(ushort segmentId, bool startNode, JunctionRestrictionsFlags flags) => segmentRestrictions[segmentId].GetDefaultValue(segmentId.AtNode(startNode), flags); - public bool ToggleValue(ushort segmentId, bool startNode, JunctionRestrictionFlags flags) { + public bool ToggleValue(ushort segmentId, bool startNode, JunctionRestrictionsFlags flags) { if (flags == default || ((int)flags & ((int)flags - 1)) != 0) return false; @@ -850,86 +850,86 @@ public bool ToggleValue(ushort segmentId, bool startNode, JunctionRestrictionFla return SetValue(segmentId, startNode, flags, !GetValueOrDefault(segmentId, startNode, flags)); } - public bool SetValue(ushort segmentId, bool startNode, JunctionRestrictionFlags flags, bool? value) + public bool SetValue(ushort segmentId, bool startNode, JunctionRestrictionsFlags flags, bool? value) => segmentId.ToSegment().IsValid() && flags != default && segmentRestrictions[segmentId].SetValue(segmentId.AtNode(startNode), flags, value); - public bool? GetValue(ushort segmentId, bool startNode, JunctionRestrictionFlags flags) + public bool? GetValue(ushort segmentId, bool startNode, JunctionRestrictionsFlags flags) => segmentRestrictions[segmentId].GetValue(segmentId.AtNode(startNode), flags); - public bool GetValueOrDefault(ushort segmentId, bool startNode, JunctionRestrictionFlags flags) + public bool GetValueOrDefault(ushort segmentId, bool startNode, JunctionRestrictionsFlags flags) => segmentRestrictions[segmentId].GetValueOrDefault(segmentId.AtNode(startNode), flags); - bool IJunctionRestrictionsManager.IsUturnAllowedConfigurable(ushort segmentId, bool startNode, ref NetNode node) => IsConfigurable(segmentId, startNode, JunctionRestrictionFlags.AllowUTurn); - bool IJunctionRestrictionsManager.IsNearTurnOnRedAllowedConfigurable(ushort segmentId, bool startNode, ref NetNode node) => IsConfigurable(segmentId, startNode, JunctionRestrictionFlags.AllowNearTurnOnRed); - bool IJunctionRestrictionsManager.IsFarTurnOnRedAllowedConfigurable(ushort segmentId, bool startNode, ref NetNode node) => IsConfigurable(segmentId, startNode, JunctionRestrictionFlags.AllowFarTurnOnRed); - bool IJunctionRestrictionsManager.IsTurnOnRedAllowedConfigurable(bool near, ushort segmentId, bool startNode, ref NetNode node) => IsConfigurable(segmentId, startNode, near ? JunctionRestrictionFlags.AllowNearTurnOnRed : JunctionRestrictionFlags.AllowFarTurnOnRed); - bool IJunctionRestrictionsManager.IsLaneChangingAllowedWhenGoingStraightConfigurable(ushort segmentId, bool startNode, ref NetNode node) => IsConfigurable(segmentId, startNode, JunctionRestrictionFlags.AllowForwardLaneChange); - bool IJunctionRestrictionsManager.IsEnteringBlockedJunctionAllowedConfigurable(ushort segmentId, bool startNode, ref NetNode node) => IsConfigurable(segmentId, startNode, JunctionRestrictionFlags.AllowEnterWhenBlocked); - bool IJunctionRestrictionsManager.IsPedestrianCrossingAllowedConfigurable(ushort segmentId, bool startNode, ref NetNode node) => IsConfigurable(segmentId, startNode, JunctionRestrictionFlags.AllowPedestrianCrossing); - bool IJunctionRestrictionsManager.GetDefaultUturnAllowed(ushort segmentId, bool startNode, ref NetNode node) => GetDefaultValue(segmentId, startNode, JunctionRestrictionFlags.AllowUTurn); - bool IJunctionRestrictionsManager.GetDefaultNearTurnOnRedAllowed(ushort segmentId, bool startNode, ref NetNode node) => GetDefaultValue(segmentId, startNode, JunctionRestrictionFlags.AllowNearTurnOnRed); - bool IJunctionRestrictionsManager.GetDefaultFarTurnOnRedAllowed(ushort segmentId, bool startNode, ref NetNode node) => GetDefaultValue(segmentId, startNode, JunctionRestrictionFlags.AllowFarTurnOnRed); - bool IJunctionRestrictionsManager.GetDefaultTurnOnRedAllowed(bool near, ushort segmentId, bool startNode, ref NetNode node) => GetDefaultValue(segmentId, startNode, near ? JunctionRestrictionFlags.AllowNearTurnOnRed : JunctionRestrictionFlags.AllowFarTurnOnRed); - bool IJunctionRestrictionsManager.GetDefaultLaneChangingAllowedWhenGoingStraight(ushort segmentId, bool startNode, ref NetNode node) => GetDefaultValue(segmentId, startNode, JunctionRestrictionFlags.AllowForwardLaneChange); - bool IJunctionRestrictionsManager.GetDefaultEnteringBlockedJunctionAllowed(ushort segmentId, bool startNode, ref NetNode node) => GetDefaultValue(segmentId, startNode, JunctionRestrictionFlags.AllowEnterWhenBlocked); - bool IJunctionRestrictionsManager.GetDefaultPedestrianCrossingAllowed(ushort segmentId, bool startNode, ref NetNode node) => GetDefaultValue(segmentId, startNode, JunctionRestrictionFlags.AllowPedestrianCrossing); - [Obsolete("If you must call this method, please go through IJunctionRestrictionsManager.", true)] public bool ToggleUturnAllowed(ushort segmentId, bool startNode) => ToggleValue(segmentId, startNode, JunctionRestrictionFlags.AllowUTurn); - [Obsolete("If you must call this method, please go through IJunctionRestrictionsManager.", true)] public bool ToggleNearTurnOnRedAllowed(ushort segmentId, bool startNode) => ToggleValue(segmentId, startNode, JunctionRestrictionFlags.AllowNearTurnOnRed); - [Obsolete("If you must call this method, please go through IJunctionRestrictionsManager.", true)] public bool ToggleFarTurnOnRedAllowed(ushort segmentId, bool startNode) => ToggleValue(segmentId, startNode, JunctionRestrictionFlags.AllowFarTurnOnRed); - [Obsolete("If you must call this method, please go through IJunctionRestrictionsManager.", true)] public bool ToggleTurnOnRedAllowed(bool near, ushort segmentId, bool startNode) => ToggleValue(segmentId, startNode, near ? JunctionRestrictionFlags.AllowNearTurnOnRed : JunctionRestrictionFlags.AllowFarTurnOnRed); - [Obsolete("If you must call this method, please go through IJunctionRestrictionsManager.", true)] public bool ToggleLaneChangingAllowedWhenGoingStraight(ushort segmentId, bool startNode) => ToggleValue(segmentId, startNode, JunctionRestrictionFlags.AllowForwardLaneChange); - [Obsolete("If you must call this method, please go through IJunctionRestrictionsManager.", true)] public bool ToggleEnteringBlockedJunctionAllowed(ushort segmentId, bool startNode) => ToggleValue(segmentId, startNode, JunctionRestrictionFlags.AllowEnterWhenBlocked); - [Obsolete("If you must call this method, please go through IJunctionRestrictionsManager.", true)] public bool TogglePedestrianCrossingAllowed(ushort segmentId, bool startNode) => ToggleValue(segmentId, startNode, JunctionRestrictionFlags.AllowPedestrianCrossing); - [Obsolete("If you must call this method, please go through IJunctionRestrictionsManager.", true)] public bool SetUturnAllowed(ushort segmentId, bool startNode, bool value) => SetValue(segmentId, startNode, JunctionRestrictionFlags.AllowUTurn, value); - [Obsolete("If you must call this method, please go through IJunctionRestrictionsManager.", true)] public bool SetNearTurnOnRedAllowed(ushort segmentId, bool startNode, bool value) => SetValue(segmentId, startNode, JunctionRestrictionFlags.AllowNearTurnOnRed, value); - [Obsolete("If you must call this method, please go through IJunctionRestrictionsManager.", true)] public bool SetFarTurnOnRedAllowed(ushort segmentId, bool startNode, bool value) => SetValue(segmentId, startNode, JunctionRestrictionFlags.AllowFarTurnOnRed, value); - [Obsolete("If you must call this method, please go through IJunctionRestrictionsManager.", true)] public bool SetTurnOnRedAllowed(bool near, ushort segmentId, bool startNode, bool value) => SetValue(segmentId, startNode, near ? JunctionRestrictionFlags.AllowNearTurnOnRed : JunctionRestrictionFlags.AllowFarTurnOnRed, value); - [Obsolete("If you must call this method, please go through IJunctionRestrictionsManager.", true)] public bool SetLaneChangingAllowedWhenGoingStraight(ushort segmentId, bool startNode, bool value) => SetValue(segmentId, startNode, JunctionRestrictionFlags.AllowForwardLaneChange, value); - [Obsolete("If you must call this method, please go through IJunctionRestrictionsManager.", true)] public bool SetEnteringBlockedJunctionAllowed(ushort segmentId, bool startNode, bool value) => SetValue(segmentId, startNode, JunctionRestrictionFlags.AllowEnterWhenBlocked, value); - [Obsolete("If you must call this method, please go through IJunctionRestrictionsManager.", true)] public bool SetPedestrianCrossingAllowed(ushort segmentId, bool startNode, bool value) => SetValue(segmentId, startNode, JunctionRestrictionFlags.AllowPedestrianCrossing, value); - [Obsolete("If you must call this method, please go through IJunctionRestrictionsManager.", true)] public bool SetUturnAllowed(ushort segmentId, bool startNode, TernaryBool value) => SetValue(segmentId, startNode, JunctionRestrictionFlags.AllowUTurn, ToOptBool(value)); - [Obsolete("If you must call this method, please go through IJunctionRestrictionsManager.", true)] public bool SetNearTurnOnRedAllowed(ushort segmentId, bool startNode, TernaryBool value) => SetValue(segmentId, startNode, JunctionRestrictionFlags.AllowNearTurnOnRed, ToOptBool(value)); - [Obsolete("If you must call this method, please go through IJunctionRestrictionsManager.", true)] public bool SetFarTurnOnRedAllowed(ushort segmentId, bool startNode, TernaryBool value) => SetValue(segmentId, startNode, JunctionRestrictionFlags.AllowFarTurnOnRed, ToOptBool(value)); - [Obsolete("If you must call this method, please go through IJunctionRestrictionsManager.", true)] public bool SetTurnOnRedAllowed(bool near, ushort segmentId, bool startNode, TernaryBool value) => SetValue(segmentId, startNode, near ? JunctionRestrictionFlags.AllowNearTurnOnRed : JunctionRestrictionFlags.AllowFarTurnOnRed, ToOptBool(value)); - [Obsolete("If you must call this method, please go through IJunctionRestrictionsManager.", true)] public bool SetLaneChangingAllowedWhenGoingStraight(ushort segmentId, bool startNode, TernaryBool value) => SetValue(segmentId, startNode, JunctionRestrictionFlags.AllowForwardLaneChange, ToOptBool(value)); - [Obsolete("If you must call this method, please go through IJunctionRestrictionsManager.", true)] public bool SetEnteringBlockedJunctionAllowed(ushort segmentId, bool startNode, TernaryBool value) => SetValue(segmentId, startNode, JunctionRestrictionFlags.AllowEnterWhenBlocked, ToOptBool(value)); - [Obsolete("If you must call this method, please go through IJunctionRestrictionsManager.", true)] public bool SetPedestrianCrossingAllowed(ushort segmentId, bool startNode, TernaryBool value) => SetValue(segmentId, startNode, JunctionRestrictionFlags.AllowPedestrianCrossing, ToOptBool(value)); - [Obsolete("If you must call this method, please go through IJunctionRestrictionsManager.", true)] public TernaryBool GetUturnAllowed(ushort segmentId, bool startNode) => ToTernaryBool(GetValue(segmentId, startNode, JunctionRestrictionFlags.AllowUTurn)); - [Obsolete("If you must call this method, please go through IJunctionRestrictionsManager.", true)] public TernaryBool GetNearTurnOnRedAllowed(ushort segmentId, bool startNode) => ToTernaryBool(GetValue(segmentId, startNode, JunctionRestrictionFlags.AllowNearTurnOnRed)); - [Obsolete("If you must call this method, please go through IJunctionRestrictionsManager.", true)] public TernaryBool GetFarTurnOnRedAllowed(ushort segmentId, bool startNode) => ToTernaryBool(GetValue(segmentId, startNode, JunctionRestrictionFlags.AllowFarTurnOnRed)); - [Obsolete("If you must call this method, please go through IJunctionRestrictionsManager.", true)] public TernaryBool GetTurnOnRedAllowed(bool near, ushort segmentId, bool startNode) => ToTernaryBool(GetValue(segmentId, startNode, near ? JunctionRestrictionFlags.AllowNearTurnOnRed : JunctionRestrictionFlags.AllowFarTurnOnRed)); - [Obsolete("If you must call this method, please go through IJunctionRestrictionsManager.", true)] public TernaryBool GetLaneChangingAllowedWhenGoingStraight(ushort segmentId, bool startNode) => ToTernaryBool(GetValue(segmentId, startNode, JunctionRestrictionFlags.AllowForwardLaneChange)); - [Obsolete("If you must call this method, please go through IJunctionRestrictionsManager.", true)] public TernaryBool GetEnteringBlockedJunctionAllowed(ushort segmentId, bool startNode) => ToTernaryBool(GetValue(segmentId, startNode, JunctionRestrictionFlags.AllowEnterWhenBlocked)); - [Obsolete("If you must call this method, please go through IJunctionRestrictionsManager.", true)] public TernaryBool GetPedestrianCrossingAllowed(ushort segmentId, bool startNode) => ToTernaryBool(GetValue(segmentId, startNode, JunctionRestrictionFlags.AllowPedestrianCrossing)); - [Obsolete("If you must call this method, please go through IJunctionRestrictionsManager.", true)] public bool IsUturnAllowed(ushort segmentId, bool startNode) => GetValueOrDefault(segmentId, startNode, JunctionRestrictionFlags.AllowUTurn); - [Obsolete("If you must call this method, please go through IJunctionRestrictionsManager.", true)] public bool IsNearTurnOnRedAllowed(ushort segmentId, bool startNode) => GetValueOrDefault(segmentId, startNode, JunctionRestrictionFlags.AllowNearTurnOnRed); - [Obsolete("If you must call this method, please go through IJunctionRestrictionsManager.", true)] public bool IsFarTurnOnRedAllowed(ushort segmentId, bool startNode) => GetValueOrDefault(segmentId, startNode, JunctionRestrictionFlags.AllowFarTurnOnRed); - [Obsolete("If you must call this method, please go through IJunctionRestrictionsManager.", true)] public bool IsTurnOnRedAllowed(bool near, ushort segmentId, bool startNode) => GetValueOrDefault(segmentId, startNode, near ? JunctionRestrictionFlags.AllowNearTurnOnRed : JunctionRestrictionFlags.AllowFarTurnOnRed); - [Obsolete("If you must call this method, please go through IJunctionRestrictionsManager.", true)] public bool IsLaneChangingAllowedWhenGoingStraight(ushort segmentId, bool startNode) => GetValueOrDefault(segmentId, startNode, JunctionRestrictionFlags.AllowForwardLaneChange); - [Obsolete("If you must call this method, please go through IJunctionRestrictionsManager.", true)] public bool IsEnteringBlockedJunctionAllowed(ushort segmentId, bool startNode) => GetValueOrDefault(segmentId, startNode, JunctionRestrictionFlags.AllowEnterWhenBlocked); - [Obsolete("If you must call this method, please go through IJunctionRestrictionsManager.", true)] public bool IsPedestrianCrossingAllowed(ushort segmentId, bool startNode) => GetValueOrDefault(segmentId, startNode, JunctionRestrictionFlags.AllowPedestrianCrossing); + bool IJunctionRestrictionsManager.IsUturnAllowedConfigurable(ushort segmentId, bool startNode, ref NetNode node) => IsConfigurable(segmentId, startNode, JunctionRestrictionsFlags.AllowUTurn); + bool IJunctionRestrictionsManager.IsNearTurnOnRedAllowedConfigurable(ushort segmentId, bool startNode, ref NetNode node) => IsConfigurable(segmentId, startNode, JunctionRestrictionsFlags.AllowNearTurnOnRed); + bool IJunctionRestrictionsManager.IsFarTurnOnRedAllowedConfigurable(ushort segmentId, bool startNode, ref NetNode node) => IsConfigurable(segmentId, startNode, JunctionRestrictionsFlags.AllowFarTurnOnRed); + bool IJunctionRestrictionsManager.IsTurnOnRedAllowedConfigurable(bool near, ushort segmentId, bool startNode, ref NetNode node) => IsConfigurable(segmentId, startNode, near ? JunctionRestrictionsFlags.AllowNearTurnOnRed : JunctionRestrictionsFlags.AllowFarTurnOnRed); + bool IJunctionRestrictionsManager.IsLaneChangingAllowedWhenGoingStraightConfigurable(ushort segmentId, bool startNode, ref NetNode node) => IsConfigurable(segmentId, startNode, JunctionRestrictionsFlags.AllowForwardLaneChange); + bool IJunctionRestrictionsManager.IsEnteringBlockedJunctionAllowedConfigurable(ushort segmentId, bool startNode, ref NetNode node) => IsConfigurable(segmentId, startNode, JunctionRestrictionsFlags.AllowEnterWhenBlocked); + bool IJunctionRestrictionsManager.IsPedestrianCrossingAllowedConfigurable(ushort segmentId, bool startNode, ref NetNode node) => IsConfigurable(segmentId, startNode, JunctionRestrictionsFlags.AllowPedestrianCrossing); + bool IJunctionRestrictionsManager.GetDefaultUturnAllowed(ushort segmentId, bool startNode, ref NetNode node) => GetDefaultValue(segmentId, startNode, JunctionRestrictionsFlags.AllowUTurn); + bool IJunctionRestrictionsManager.GetDefaultNearTurnOnRedAllowed(ushort segmentId, bool startNode, ref NetNode node) => GetDefaultValue(segmentId, startNode, JunctionRestrictionsFlags.AllowNearTurnOnRed); + bool IJunctionRestrictionsManager.GetDefaultFarTurnOnRedAllowed(ushort segmentId, bool startNode, ref NetNode node) => GetDefaultValue(segmentId, startNode, JunctionRestrictionsFlags.AllowFarTurnOnRed); + bool IJunctionRestrictionsManager.GetDefaultTurnOnRedAllowed(bool near, ushort segmentId, bool startNode, ref NetNode node) => GetDefaultValue(segmentId, startNode, near ? JunctionRestrictionsFlags.AllowNearTurnOnRed : JunctionRestrictionsFlags.AllowFarTurnOnRed); + bool IJunctionRestrictionsManager.GetDefaultLaneChangingAllowedWhenGoingStraight(ushort segmentId, bool startNode, ref NetNode node) => GetDefaultValue(segmentId, startNode, JunctionRestrictionsFlags.AllowForwardLaneChange); + bool IJunctionRestrictionsManager.GetDefaultEnteringBlockedJunctionAllowed(ushort segmentId, bool startNode, ref NetNode node) => GetDefaultValue(segmentId, startNode, JunctionRestrictionsFlags.AllowEnterWhenBlocked); + bool IJunctionRestrictionsManager.GetDefaultPedestrianCrossingAllowed(ushort segmentId, bool startNode, ref NetNode node) => GetDefaultValue(segmentId, startNode, JunctionRestrictionsFlags.AllowPedestrianCrossing); + [Obsolete("If you must call this method, please go through IJunctionRestrictionsManager.", true)] public bool ToggleUturnAllowed(ushort segmentId, bool startNode) => ToggleValue(segmentId, startNode, JunctionRestrictionsFlags.AllowUTurn); + [Obsolete("If you must call this method, please go through IJunctionRestrictionsManager.", true)] public bool ToggleNearTurnOnRedAllowed(ushort segmentId, bool startNode) => ToggleValue(segmentId, startNode, JunctionRestrictionsFlags.AllowNearTurnOnRed); + [Obsolete("If you must call this method, please go through IJunctionRestrictionsManager.", true)] public bool ToggleFarTurnOnRedAllowed(ushort segmentId, bool startNode) => ToggleValue(segmentId, startNode, JunctionRestrictionsFlags.AllowFarTurnOnRed); + [Obsolete("If you must call this method, please go through IJunctionRestrictionsManager.", true)] public bool ToggleTurnOnRedAllowed(bool near, ushort segmentId, bool startNode) => ToggleValue(segmentId, startNode, near ? JunctionRestrictionsFlags.AllowNearTurnOnRed : JunctionRestrictionsFlags.AllowFarTurnOnRed); + [Obsolete("If you must call this method, please go through IJunctionRestrictionsManager.", true)] public bool ToggleLaneChangingAllowedWhenGoingStraight(ushort segmentId, bool startNode) => ToggleValue(segmentId, startNode, JunctionRestrictionsFlags.AllowForwardLaneChange); + [Obsolete("If you must call this method, please go through IJunctionRestrictionsManager.", true)] public bool ToggleEnteringBlockedJunctionAllowed(ushort segmentId, bool startNode) => ToggleValue(segmentId, startNode, JunctionRestrictionsFlags.AllowEnterWhenBlocked); + [Obsolete("If you must call this method, please go through IJunctionRestrictionsManager.", true)] public bool TogglePedestrianCrossingAllowed(ushort segmentId, bool startNode) => ToggleValue(segmentId, startNode, JunctionRestrictionsFlags.AllowPedestrianCrossing); + [Obsolete("If you must call this method, please go through IJunctionRestrictionsManager.", true)] public bool SetUturnAllowed(ushort segmentId, bool startNode, bool value) => SetValue(segmentId, startNode, JunctionRestrictionsFlags.AllowUTurn, value); + [Obsolete("If you must call this method, please go through IJunctionRestrictionsManager.", true)] public bool SetNearTurnOnRedAllowed(ushort segmentId, bool startNode, bool value) => SetValue(segmentId, startNode, JunctionRestrictionsFlags.AllowNearTurnOnRed, value); + [Obsolete("If you must call this method, please go through IJunctionRestrictionsManager.", true)] public bool SetFarTurnOnRedAllowed(ushort segmentId, bool startNode, bool value) => SetValue(segmentId, startNode, JunctionRestrictionsFlags.AllowFarTurnOnRed, value); + [Obsolete("If you must call this method, please go through IJunctionRestrictionsManager.", true)] public bool SetTurnOnRedAllowed(bool near, ushort segmentId, bool startNode, bool value) => SetValue(segmentId, startNode, near ? JunctionRestrictionsFlags.AllowNearTurnOnRed : JunctionRestrictionsFlags.AllowFarTurnOnRed, value); + [Obsolete("If you must call this method, please go through IJunctionRestrictionsManager.", true)] public bool SetLaneChangingAllowedWhenGoingStraight(ushort segmentId, bool startNode, bool value) => SetValue(segmentId, startNode, JunctionRestrictionsFlags.AllowForwardLaneChange, value); + [Obsolete("If you must call this method, please go through IJunctionRestrictionsManager.", true)] public bool SetEnteringBlockedJunctionAllowed(ushort segmentId, bool startNode, bool value) => SetValue(segmentId, startNode, JunctionRestrictionsFlags.AllowEnterWhenBlocked, value); + [Obsolete("If you must call this method, please go through IJunctionRestrictionsManager.", true)] public bool SetPedestrianCrossingAllowed(ushort segmentId, bool startNode, bool value) => SetValue(segmentId, startNode, JunctionRestrictionsFlags.AllowPedestrianCrossing, value); + [Obsolete("If you must call this method, please go through IJunctionRestrictionsManager.", true)] public bool SetUturnAllowed(ushort segmentId, bool startNode, TernaryBool value) => SetValue(segmentId, startNode, JunctionRestrictionsFlags.AllowUTurn, ToOptBool(value)); + [Obsolete("If you must call this method, please go through IJunctionRestrictionsManager.", true)] public bool SetNearTurnOnRedAllowed(ushort segmentId, bool startNode, TernaryBool value) => SetValue(segmentId, startNode, JunctionRestrictionsFlags.AllowNearTurnOnRed, ToOptBool(value)); + [Obsolete("If you must call this method, please go through IJunctionRestrictionsManager.", true)] public bool SetFarTurnOnRedAllowed(ushort segmentId, bool startNode, TernaryBool value) => SetValue(segmentId, startNode, JunctionRestrictionsFlags.AllowFarTurnOnRed, ToOptBool(value)); + [Obsolete("If you must call this method, please go through IJunctionRestrictionsManager.", true)] public bool SetTurnOnRedAllowed(bool near, ushort segmentId, bool startNode, TernaryBool value) => SetValue(segmentId, startNode, near ? JunctionRestrictionsFlags.AllowNearTurnOnRed : JunctionRestrictionsFlags.AllowFarTurnOnRed, ToOptBool(value)); + [Obsolete("If you must call this method, please go through IJunctionRestrictionsManager.", true)] public bool SetLaneChangingAllowedWhenGoingStraight(ushort segmentId, bool startNode, TernaryBool value) => SetValue(segmentId, startNode, JunctionRestrictionsFlags.AllowForwardLaneChange, ToOptBool(value)); + [Obsolete("If you must call this method, please go through IJunctionRestrictionsManager.", true)] public bool SetEnteringBlockedJunctionAllowed(ushort segmentId, bool startNode, TernaryBool value) => SetValue(segmentId, startNode, JunctionRestrictionsFlags.AllowEnterWhenBlocked, ToOptBool(value)); + [Obsolete("If you must call this method, please go through IJunctionRestrictionsManager.", true)] public bool SetPedestrianCrossingAllowed(ushort segmentId, bool startNode, TernaryBool value) => SetValue(segmentId, startNode, JunctionRestrictionsFlags.AllowPedestrianCrossing, ToOptBool(value)); + [Obsolete("If you must call this method, please go through IJunctionRestrictionsManager.", true)] public TernaryBool GetUturnAllowed(ushort segmentId, bool startNode) => ToTernaryBool(GetValue(segmentId, startNode, JunctionRestrictionsFlags.AllowUTurn)); + [Obsolete("If you must call this method, please go through IJunctionRestrictionsManager.", true)] public TernaryBool GetNearTurnOnRedAllowed(ushort segmentId, bool startNode) => ToTernaryBool(GetValue(segmentId, startNode, JunctionRestrictionsFlags.AllowNearTurnOnRed)); + [Obsolete("If you must call this method, please go through IJunctionRestrictionsManager.", true)] public TernaryBool GetFarTurnOnRedAllowed(ushort segmentId, bool startNode) => ToTernaryBool(GetValue(segmentId, startNode, JunctionRestrictionsFlags.AllowFarTurnOnRed)); + [Obsolete("If you must call this method, please go through IJunctionRestrictionsManager.", true)] public TernaryBool GetTurnOnRedAllowed(bool near, ushort segmentId, bool startNode) => ToTernaryBool(GetValue(segmentId, startNode, near ? JunctionRestrictionsFlags.AllowNearTurnOnRed : JunctionRestrictionsFlags.AllowFarTurnOnRed)); + [Obsolete("If you must call this method, please go through IJunctionRestrictionsManager.", true)] public TernaryBool GetLaneChangingAllowedWhenGoingStraight(ushort segmentId, bool startNode) => ToTernaryBool(GetValue(segmentId, startNode, JunctionRestrictionsFlags.AllowForwardLaneChange)); + [Obsolete("If you must call this method, please go through IJunctionRestrictionsManager.", true)] public TernaryBool GetEnteringBlockedJunctionAllowed(ushort segmentId, bool startNode) => ToTernaryBool(GetValue(segmentId, startNode, JunctionRestrictionsFlags.AllowEnterWhenBlocked)); + [Obsolete("If you must call this method, please go through IJunctionRestrictionsManager.", true)] public TernaryBool GetPedestrianCrossingAllowed(ushort segmentId, bool startNode) => ToTernaryBool(GetValue(segmentId, startNode, JunctionRestrictionsFlags.AllowPedestrianCrossing)); + [Obsolete("If you must call this method, please go through IJunctionRestrictionsManager.", true)] public bool IsUturnAllowed(ushort segmentId, bool startNode) => GetValueOrDefault(segmentId, startNode, JunctionRestrictionsFlags.AllowUTurn); + [Obsolete("If you must call this method, please go through IJunctionRestrictionsManager.", true)] public bool IsNearTurnOnRedAllowed(ushort segmentId, bool startNode) => GetValueOrDefault(segmentId, startNode, JunctionRestrictionsFlags.AllowNearTurnOnRed); + [Obsolete("If you must call this method, please go through IJunctionRestrictionsManager.", true)] public bool IsFarTurnOnRedAllowed(ushort segmentId, bool startNode) => GetValueOrDefault(segmentId, startNode, JunctionRestrictionsFlags.AllowFarTurnOnRed); + [Obsolete("If you must call this method, please go through IJunctionRestrictionsManager.", true)] public bool IsTurnOnRedAllowed(bool near, ushort segmentId, bool startNode) => GetValueOrDefault(segmentId, startNode, near ? JunctionRestrictionsFlags.AllowNearTurnOnRed : JunctionRestrictionsFlags.AllowFarTurnOnRed); + [Obsolete("If you must call this method, please go through IJunctionRestrictionsManager.", true)] public bool IsLaneChangingAllowedWhenGoingStraight(ushort segmentId, bool startNode) => GetValueOrDefault(segmentId, startNode, JunctionRestrictionsFlags.AllowForwardLaneChange); + [Obsolete("If you must call this method, please go through IJunctionRestrictionsManager.", true)] public bool IsEnteringBlockedJunctionAllowed(ushort segmentId, bool startNode) => GetValueOrDefault(segmentId, startNode, JunctionRestrictionsFlags.AllowEnterWhenBlocked); + [Obsolete("If you must call this method, please go through IJunctionRestrictionsManager.", true)] public bool IsPedestrianCrossingAllowed(ushort segmentId, bool startNode) => GetValueOrDefault(segmentId, startNode, JunctionRestrictionsFlags.AllowPedestrianCrossing); private struct SegmentJunctionRestrictions { public JunctionRestrictions startNodeRestrictions; public JunctionRestrictions endNodeRestrictions; - public bool GetValueOrDefault(SegmentEndId segmentEndId, JunctionRestrictionFlags flags) { + public bool GetValueOrDefault(SegmentEndId segmentEndId, JunctionRestrictionsFlags flags) { return (segmentEndId.StartNode ? startNodeRestrictions : endNodeRestrictions).GetValueOrDefault(segmentEndId, flags); } - public bool? GetValue(SegmentEndId segmentEndId, JunctionRestrictionFlags flags) { + public bool? GetValue(SegmentEndId segmentEndId, JunctionRestrictionsFlags flags) { return (segmentEndId.StartNode ? startNodeRestrictions : endNodeRestrictions).GetValue(segmentEndId, flags); } - public bool GetDefaultValue(SegmentEndId segmentEndId, JunctionRestrictionFlags flags) { + public bool GetDefaultValue(SegmentEndId segmentEndId, JunctionRestrictionsFlags flags) { return (segmentEndId.StartNode ? startNodeRestrictions : endNodeRestrictions).GetDefaultValue(segmentEndId, flags); } - public bool IsConfigurable(SegmentEndId segmentEndId, JunctionRestrictionFlags flags) { + public bool IsConfigurable(SegmentEndId segmentEndId, JunctionRestrictionsFlags flags) { return (segmentEndId.StartNode ? startNodeRestrictions : endNodeRestrictions).IsConfigurable(segmentEndId, flags); } - public bool SetValue(SegmentEndId segmentEndId, JunctionRestrictionFlags flags, bool? value) { + public bool SetValue(SegmentEndId segmentEndId, JunctionRestrictionsFlags flags, bool? value) { if (segmentEndId.StartNode) return startNodeRestrictions.SetValue(segmentEndId, flags, value); else @@ -967,47 +967,47 @@ public override string ToString() { private struct JunctionRestrictions { - private JunctionRestrictionFlags values; + private JunctionRestrictionsFlags values; - private JunctionRestrictionFlags mask; + private JunctionRestrictionsFlags mask; - private JunctionRestrictionFlags defaults; + private JunctionRestrictionsFlags defaults; - private JunctionRestrictionFlags configurables; + private JunctionRestrictionsFlags configurables; - private JunctionRestrictionFlags valid; + private JunctionRestrictionsFlags valid; - public bool ClearValue(SegmentEndId segmentEndId, JunctionRestrictionFlags flags) => SetValue(segmentEndId, flags, null); + public bool ClearValue(SegmentEndId segmentEndId, JunctionRestrictionsFlags flags) => SetValue(segmentEndId, flags, null); - private void SetDefault(SegmentEndId segmentEndId, JunctionRestrictionFlags flags, bool value) { + private void SetDefault(SegmentEndId segmentEndId, JunctionRestrictionsFlags flags, bool value) { if (value) defaults |= flags; else defaults &= ~flags; } - private void SetConfigurable(SegmentEndId segmentEndId, JunctionRestrictionFlags flags, bool value) { + private void SetConfigurable(SegmentEndId segmentEndId, JunctionRestrictionsFlags flags, bool value) { if (value) configurables |= flags; else configurables &= ~flags; } - public bool GetDefaultValue(SegmentEndId segmentEndId, JunctionRestrictionFlags flags) { + public bool GetDefaultValue(SegmentEndId segmentEndId, JunctionRestrictionsFlags flags) { Recalculate(segmentEndId); return (defaults & flags) == flags; } - public bool IsConfigurable(SegmentEndId segmentEndId, JunctionRestrictionFlags flags) { + public bool IsConfigurable(SegmentEndId segmentEndId, JunctionRestrictionsFlags flags) { Recalculate(segmentEndId); return (configurables & flags) == flags; } - public bool HasValue(SegmentEndId segmentEndId, JunctionRestrictionFlags flags) { + public bool HasValue(SegmentEndId segmentEndId, JunctionRestrictionsFlags flags) { return (mask & flags) == flags; } - public bool? GetValue(SegmentEndId segmentEndId, JunctionRestrictionFlags flags) { + public bool? GetValue(SegmentEndId segmentEndId, JunctionRestrictionsFlags flags) { return (mask & flags) != flags ? null : (values & flags) == flags ? true @@ -1015,23 +1015,23 @@ public bool HasValue(SegmentEndId segmentEndId, JunctionRestrictionFlags flags) : null; } - public bool GetValueOrDefault(SegmentEndId segmentEndId, JunctionRestrictionFlags flags) { + public bool GetValueOrDefault(SegmentEndId segmentEndId, JunctionRestrictionsFlags flags) { Recalculate(segmentEndId); return ((values & flags & mask) | (defaults & flags & ~mask)) == flags; } - public JunctionRestrictionFlags GetFlagsWithDefaults(SegmentEndId segmentEndId) { + public JunctionRestrictionsFlags GetFlagsWithDefaults(SegmentEndId segmentEndId) { return (values & mask) | (defaults & ~mask); } - private const JunctionRestrictionFlags routingRecalculationFlags = JunctionRestrictionFlags.All & ~JunctionRestrictionFlags.AllowEnterWhenBlocked; + private const JunctionRestrictionsFlags routingRecalculationFlags = JunctionRestrictionsFlags.All & ~JunctionRestrictionsFlags.AllowEnterWhenBlocked; - private bool ValidateSet(SegmentEndId segmentEndId, JunctionRestrictionFlags flags, JunctionRestrictionFlags newValues, JunctionRestrictionFlags newMask) { + private bool ValidateSet(SegmentEndId segmentEndId, JunctionRestrictionsFlags flags, JunctionRestrictionsFlags newValues, JunctionRestrictionsFlags newMask) { - const JunctionRestrictionFlags uTurnCheckFlags - = JunctionRestrictionFlags.AllowNearTurnOnRed - | JunctionRestrictionFlags.AllowFarTurnOnRed - | JunctionRestrictionFlags.AllowUTurn; + const JunctionRestrictionsFlags uTurnCheckFlags + = JunctionRestrictionsFlags.AllowNearTurnOnRed + | JunctionRestrictionsFlags.AllowFarTurnOnRed + | JunctionRestrictionsFlags.AllowUTurn; if ((newMask & flags & uTurnCheckFlags) != 0 && (newValues & newMask & flags & uTurnCheckFlags) == 0 @@ -1041,7 +1041,7 @@ const JunctionRestrictionFlags uTurnCheckFlags return true; } - public bool SetValue(SegmentEndId segmentEndId, JunctionRestrictionFlags flags, bool? value) { + public bool SetValue(SegmentEndId segmentEndId, JunctionRestrictionsFlags flags, bool? value) { Recalculate(segmentEndId); @@ -1051,7 +1051,7 @@ public bool SetValue(SegmentEndId segmentEndId, JunctionRestrictionFlags flags, return Set(segmentEndId, flags, newValues, newMask); } - private bool Set(SegmentEndId segmentEndId, JunctionRestrictionFlags flags, JunctionRestrictionFlags newValues, JunctionRestrictionFlags newMask) { + private bool Set(SegmentEndId segmentEndId, JunctionRestrictionsFlags flags, JunctionRestrictionsFlags newValues, JunctionRestrictionsFlags newMask) { Recalculate(segmentEndId); @@ -1094,31 +1094,31 @@ private static Calculator DelegateTo(string methodName) { return (Calculator)Delegate.CreateDelegate(typeof(Calculator), Instance, methodName); } - private static Dictionary configurableCalculators = new Dictionary() { - { JunctionRestrictionFlags.AllowUTurn, DelegateTo(nameof(IsUturnAllowedConfigurable)) }, - { JunctionRestrictionFlags.AllowNearTurnOnRed, DelegateTo(nameof(IsNearTurnOnRedAllowedConfigurable)) }, - { JunctionRestrictionFlags.AllowFarTurnOnRed, DelegateTo(nameof(IsFarTurnOnRedAllowedConfigurable)) }, - { JunctionRestrictionFlags.AllowForwardLaneChange, DelegateTo(nameof(IsLaneChangingAllowedWhenGoingStraightConfigurable)) }, - { JunctionRestrictionFlags.AllowEnterWhenBlocked, DelegateTo(nameof(IsEnteringBlockedJunctionAllowedConfigurable)) }, - { JunctionRestrictionFlags.AllowPedestrianCrossing, DelegateTo(nameof(IsPedestrianCrossingAllowedConfigurable)) }, + private static Dictionary configurableCalculators = new Dictionary() { + { JunctionRestrictionsFlags.AllowUTurn, DelegateTo(nameof(IsUturnAllowedConfigurable)) }, + { JunctionRestrictionsFlags.AllowNearTurnOnRed, DelegateTo(nameof(IsNearTurnOnRedAllowedConfigurable)) }, + { JunctionRestrictionsFlags.AllowFarTurnOnRed, DelegateTo(nameof(IsFarTurnOnRedAllowedConfigurable)) }, + { JunctionRestrictionsFlags.AllowForwardLaneChange, DelegateTo(nameof(IsLaneChangingAllowedWhenGoingStraightConfigurable)) }, + { JunctionRestrictionsFlags.AllowEnterWhenBlocked, DelegateTo(nameof(IsEnteringBlockedJunctionAllowedConfigurable)) }, + { JunctionRestrictionsFlags.AllowPedestrianCrossing, DelegateTo(nameof(IsPedestrianCrossingAllowedConfigurable)) }, }; - private static Dictionary defaultCalculators = new Dictionary() { - { JunctionRestrictionFlags.AllowUTurn, DelegateTo(nameof(GetDefaultUturnAllowed)) }, - { JunctionRestrictionFlags.AllowNearTurnOnRed, DelegateTo(nameof(GetDefaultNearTurnOnRedAllowed)) }, - { JunctionRestrictionFlags.AllowFarTurnOnRed, DelegateTo(nameof(GetDefaultFarTurnOnRedAllowed)) }, - { JunctionRestrictionFlags.AllowForwardLaneChange, DelegateTo(nameof(GetDefaultLaneChangingAllowedWhenGoingStraight)) }, - { JunctionRestrictionFlags.AllowEnterWhenBlocked, DelegateTo(nameof(GetDefaultEnteringBlockedJunctionAllowed)) }, - { JunctionRestrictionFlags.AllowPedestrianCrossing, DelegateTo(nameof(GetDefaultPedestrianCrossingAllowed)) }, + private static Dictionary defaultCalculators = new Dictionary() { + { JunctionRestrictionsFlags.AllowUTurn, DelegateTo(nameof(GetDefaultUturnAllowed)) }, + { JunctionRestrictionsFlags.AllowNearTurnOnRed, DelegateTo(nameof(GetDefaultNearTurnOnRedAllowed)) }, + { JunctionRestrictionsFlags.AllowFarTurnOnRed, DelegateTo(nameof(GetDefaultFarTurnOnRedAllowed)) }, + { JunctionRestrictionsFlags.AllowForwardLaneChange, DelegateTo(nameof(GetDefaultLaneChangingAllowedWhenGoingStraight)) }, + { JunctionRestrictionsFlags.AllowEnterWhenBlocked, DelegateTo(nameof(GetDefaultEnteringBlockedJunctionAllowed)) }, + { JunctionRestrictionsFlags.AllowPedestrianCrossing, DelegateTo(nameof(GetDefaultPedestrianCrossingAllowed)) }, }; private void Recalculate(SegmentEndId segmentEndId) { - var recalculateFlags = JunctionRestrictionFlags.All & ~valid; + var recalculateFlags = JunctionRestrictionsFlags.All & ~valid; if (recalculateFlags != default) { ref var node = ref segmentEndId.GetNodeId().ToNode(); - JunctionRestrictionFlags newConfigurables = default; + JunctionRestrictionsFlags newConfigurables = default; foreach (var c in configurableCalculators) { if ((recalculateFlags & c.Key) != 0) { @@ -1136,7 +1136,7 @@ private void Recalculate(SegmentEndId segmentEndId) { newConfigurables = args.Result; } - JunctionRestrictionFlags newDefaults = default; + JunctionRestrictionsFlags newDefaults = default; foreach (var c in defaultCalculators) { if ((recalculateFlags & c.Key) != 0) { diff --git a/TLM/TLM/Manager/Impl/LaneConnection/LaneConnectionSubManager.cs b/TLM/TLM/Manager/Impl/LaneConnection/LaneConnectionSubManager.cs index ee8e38100..f82d71a25 100644 --- a/TLM/TLM/Manager/Impl/LaneConnection/LaneConnectionSubManager.cs +++ b/TLM/TLM/Manager/Impl/LaneConnection/LaneConnectionSubManager.cs @@ -365,7 +365,7 @@ internal bool AddLaneConnection(uint sourceLaneId, uint targetLaneId, bool sourc JunctionRestrictionsManager.Instance.SetValue( sourceSegmentId, sourceStartNode, - JunctionRestrictionFlags.AllowUTurn, + JunctionRestrictionsFlags.AllowUTurn, true); } diff --git a/TLM/TLM/Manager/Impl/RoutingManager.cs b/TLM/TLM/Manager/Impl/RoutingManager.cs index d596260f4..937cf881d 100644 --- a/TLM/TLM/Manager/Impl/RoutingManager.cs +++ b/TLM/TLM/Manager/Impl/RoutingManager.cs @@ -991,7 +991,7 @@ private void RecalculateLaneEndRoutingData( bool hasUTurnRule = JunctionRestrictionsManager.Instance.GetValueOrDefault( nextSegmentId, isNodeStartNodeOfNextSegment, - JunctionRestrictionFlags.AllowUTurn); + JunctionRestrictionsFlags.AllowUTurn); bool hasFarTurnArrow = (Shortcuts.LHT && hasRightArrow) || (Shortcuts.RHT && hasLeftArrow); bool canTurn = !nodeIsRealJunction || nodeIsEndOrOneWayOut || hasFarTurnArrow || hasUTurnRule; @@ -1161,7 +1161,7 @@ private void RecalculateLaneEndRoutingData( bool laneChangesAllowed = Options.junctionRestrictionsEnabled && JunctionRestrictionsManager.Instance.GetValueOrDefault( - nextSegmentId, isNodeStartNodeOfNextSegment, JunctionRestrictionFlags.AllowForwardLaneChange); + nextSegmentId, isNodeStartNodeOfNextSegment, JunctionRestrictionsFlags.AllowForwardLaneChange); int nextCompatibleLaneCount = numNextCompatibleTransitionDatas; if (nextCompatibleLaneCount > 0) { diff --git a/TLM/TLM/Manager/Impl/VehicleBehaviorManager.cs b/TLM/TLM/Manager/Impl/VehicleBehaviorManager.cs index 7aba24eb8..2e24ee149 100644 --- a/TLM/TLM/Manager/Impl/VehicleBehaviorManager.cs +++ b/TLM/TLM/Manager/Impl/VehicleBehaviorManager.cs @@ -1702,7 +1702,7 @@ protected bool MustCheckSpace(ushort segmentId, !JunctionRestrictionsManager.Instance.GetValueOrDefault( segmentId, startNode, - JunctionRestrictionFlags.AllowEnterWhenBlocked); + JunctionRestrictionsFlags.AllowEnterWhenBlocked); } else { checkSpace = (node.m_flags & (NetNode.Flags.Junction diff --git a/TLM/TLM/UI/SubTools/ManualTrafficLightsTool.cs b/TLM/TLM/UI/SubTools/ManualTrafficLightsTool.cs index 6ec00ea3f..bed90a967 100644 --- a/TLM/TLM/UI/SubTools/ManualTrafficLightsTool.cs +++ b/TLM/TLM/UI/SubTools/ManualTrafficLightsTool.cs @@ -119,7 +119,7 @@ public override void OnToolGUI(Event e) { junctionRestrictionsManager.GetValueOrDefault( segmentLights.SegmentId, segmentLights.StartNode, - JunctionRestrictionFlags.AllowPedestrianCrossing); + JunctionRestrictionsFlags.AllowPedestrianCrossing); bool visible = GeometryUtil.WorldToScreenPoint(position, out Vector3 screenPos); if (!visible) { diff --git a/TLM/TLM/UI/SubTools/TTL/TimedTrafficLightsTool.cs b/TLM/TLM/UI/SubTools/TTL/TimedTrafficLightsTool.cs index 1443cf634..f28388691 100644 --- a/TLM/TLM/UI/SubTools/TTL/TimedTrafficLightsTool.cs +++ b/TLM/TLM/UI/SubTools/TTL/TimedTrafficLightsTool.cs @@ -1498,7 +1498,7 @@ private void ShowGUI() { junctionRestrictionsManager.GetValueOrDefault( liveSegmentLights.SegmentId, liveSegmentLights.StartNode, - JunctionRestrictionFlags.AllowPedestrianCrossing); + JunctionRestrictionsFlags.AllowPedestrianCrossing); bool timedActive = timedNode.IsStarted(); if (!timedActive) { diff --git a/TLM/TLM/Util/PriorityRoad.cs b/TLM/TLM/Util/PriorityRoad.cs index df438fec6..4de604241 100644 --- a/TLM/TLM/Util/PriorityRoad.cs +++ b/TLM/TLM/Util/PriorityRoad.cs @@ -412,9 +412,9 @@ private static ArrowDirection GetDirection(ushort segmentId, ushort otherSegment private static void FixMajorSegmentRules(ushort segmentId, ushort nodeId) { Log._Debug($"FixMajorSegmentRules({segmentId}, {nodeId}) was called"); bool startNode = segmentId.ToSegment().IsStartNode(nodeId); - JunctionRestrictionsManager.Instance.SetValue(segmentId, startNode, JunctionRestrictionFlags.AllowEnterWhenBlocked, true); + JunctionRestrictionsManager.Instance.SetValue(segmentId, startNode, JunctionRestrictionsFlags.AllowEnterWhenBlocked, true); if (!Options.PriorityRoad_CrossMainR) { - JunctionRestrictionsManager.Instance.SetValue(segmentId, startNode, JunctionRestrictionFlags.AllowPedestrianCrossing, false); + JunctionRestrictionsManager.Instance.SetValue(segmentId, startNode, JunctionRestrictionsFlags.AllowPedestrianCrossing, false); } TrafficPriorityManager.Instance.SetPrioritySign(segmentId, startNode, PriorityType.Main); } @@ -423,10 +423,10 @@ private static void FixMinorSegmentRules(ushort segmentId, ushort nodeId, List JunctionRestrictionsManager.Instance; public void Record() { - uturnAllowed_ = ToTernaryBool(JRMan.GetValueOrDefault(SegmentId, StartNode, JunctionRestrictionFlags.AllowUTurn)); - nearTurnOnRedAllowed_ = ToTernaryBool(JRMan.GetValueOrDefault(SegmentId, StartNode, JunctionRestrictionFlags.AllowNearTurnOnRed)); - farTurnOnRedAllowed_ = ToTernaryBool(JRMan.GetValueOrDefault(SegmentId, StartNode, JunctionRestrictionFlags.AllowFarTurnOnRed)); - laneChangingAllowedWhenGoingStraight_ = ToTernaryBool(JRMan.GetValueOrDefault(SegmentId, StartNode, JunctionRestrictionFlags.AllowForwardLaneChange)); - enteringBlockedJunctionAllowed_ = ToTernaryBool(JRMan.GetValueOrDefault(SegmentId, StartNode, JunctionRestrictionFlags.AllowEnterWhenBlocked)); - pedestrianCrossingAllowed_ = ToTernaryBool(JRMan.GetValueOrDefault(SegmentId, StartNode, JunctionRestrictionFlags.AllowPedestrianCrossing)); + uturnAllowed_ = ToTernaryBool(JRMan.GetValueOrDefault(SegmentId, StartNode, JunctionRestrictionsFlags.AllowUTurn)); + nearTurnOnRedAllowed_ = ToTernaryBool(JRMan.GetValueOrDefault(SegmentId, StartNode, JunctionRestrictionsFlags.AllowNearTurnOnRed)); + farTurnOnRedAllowed_ = ToTernaryBool(JRMan.GetValueOrDefault(SegmentId, StartNode, JunctionRestrictionsFlags.AllowFarTurnOnRed)); + laneChangingAllowedWhenGoingStraight_ = ToTernaryBool(JRMan.GetValueOrDefault(SegmentId, StartNode, JunctionRestrictionsFlags.AllowForwardLaneChange)); + enteringBlockedJunctionAllowed_ = ToTernaryBool(JRMan.GetValueOrDefault(SegmentId, StartNode, JunctionRestrictionsFlags.AllowEnterWhenBlocked)); + pedestrianCrossingAllowed_ = ToTernaryBool(JRMan.GetValueOrDefault(SegmentId, StartNode, JunctionRestrictionsFlags.AllowPedestrianCrossing)); prioirtySign_ = priorityMan.GetPrioritySign(SegmentId, StartNode); @@ -65,12 +65,12 @@ public void Restore() { } // all necessary checks are performed internally. - JRMan.SetValue(SegmentId, StartNode, JunctionRestrictionFlags.AllowUTurn, ToOptBool(uturnAllowed_)); - JRMan.SetValue(SegmentId, StartNode, JunctionRestrictionFlags.AllowNearTurnOnRed, ToOptBool(nearTurnOnRedAllowed_)); - JRMan.SetValue(SegmentId, StartNode, JunctionRestrictionFlags.AllowFarTurnOnRed, ToOptBool(farTurnOnRedAllowed_)); - JRMan.SetValue(SegmentId, StartNode, JunctionRestrictionFlags.AllowForwardLaneChange, ToOptBool(laneChangingAllowedWhenGoingStraight_)); - JRMan.SetValue(SegmentId, StartNode, JunctionRestrictionFlags.AllowEnterWhenBlocked, ToOptBool(enteringBlockedJunctionAllowed_)); - JRMan.SetValue(SegmentId, StartNode, JunctionRestrictionFlags.AllowPedestrianCrossing, ToOptBool(pedestrianCrossingAllowed_)); + JRMan.SetValue(SegmentId, StartNode, JunctionRestrictionsFlags.AllowUTurn, ToOptBool(uturnAllowed_)); + JRMan.SetValue(SegmentId, StartNode, JunctionRestrictionsFlags.AllowNearTurnOnRed, ToOptBool(nearTurnOnRedAllowed_)); + JRMan.SetValue(SegmentId, StartNode, JunctionRestrictionsFlags.AllowFarTurnOnRed, ToOptBool(farTurnOnRedAllowed_)); + JRMan.SetValue(SegmentId, StartNode, JunctionRestrictionsFlags.AllowForwardLaneChange, ToOptBool(laneChangingAllowedWhenGoingStraight_)); + JRMan.SetValue(SegmentId, StartNode, JunctionRestrictionsFlags.AllowEnterWhenBlocked, ToOptBool(enteringBlockedJunctionAllowed_)); + JRMan.SetValue(SegmentId, StartNode, JunctionRestrictionsFlags.AllowPedestrianCrossing, ToOptBool(pedestrianCrossingAllowed_)); } public void Transfer(Dictionary map) { @@ -84,12 +84,12 @@ public void Transfer(Dictionary map) { } // all necessary checks are performed internally. - JRMan.SetValue(segmentId, StartNode, JunctionRestrictionFlags.AllowUTurn, ToOptBool(uturnAllowed_)); - JRMan.SetValue(segmentId, StartNode, JunctionRestrictionFlags.AllowNearTurnOnRed, ToOptBool(nearTurnOnRedAllowed_)); - JRMan.SetValue(segmentId, StartNode, JunctionRestrictionFlags.AllowFarTurnOnRed, ToOptBool(farTurnOnRedAllowed_)); - JRMan.SetValue(segmentId, StartNode, JunctionRestrictionFlags.AllowForwardLaneChange, ToOptBool(laneChangingAllowedWhenGoingStraight_)); - JRMan.SetValue(segmentId, StartNode, JunctionRestrictionFlags.AllowEnterWhenBlocked, ToOptBool(enteringBlockedJunctionAllowed_)); - JRMan.SetValue(segmentId, StartNode, JunctionRestrictionFlags.AllowPedestrianCrossing, ToOptBool(pedestrianCrossingAllowed_)); + JRMan.SetValue(segmentId, StartNode, JunctionRestrictionsFlags.AllowUTurn, ToOptBool(uturnAllowed_)); + JRMan.SetValue(segmentId, StartNode, JunctionRestrictionsFlags.AllowNearTurnOnRed, ToOptBool(nearTurnOnRedAllowed_)); + JRMan.SetValue(segmentId, StartNode, JunctionRestrictionsFlags.AllowFarTurnOnRed, ToOptBool(farTurnOnRedAllowed_)); + JRMan.SetValue(segmentId, StartNode, JunctionRestrictionsFlags.AllowForwardLaneChange, ToOptBool(laneChangingAllowedWhenGoingStraight_)); + JRMan.SetValue(segmentId, StartNode, JunctionRestrictionsFlags.AllowEnterWhenBlocked, ToOptBool(enteringBlockedJunctionAllowed_)); + JRMan.SetValue(segmentId, StartNode, JunctionRestrictionsFlags.AllowPedestrianCrossing, ToOptBool(pedestrianCrossingAllowed_)); } public void Transfer(uint mappedId) { diff --git a/TLM/TLM/Util/RoundaboutMassEdit.cs b/TLM/TLM/Util/RoundaboutMassEdit.cs index 6f15d14fb..48350da95 100644 --- a/TLM/TLM/Util/RoundaboutMassEdit.cs +++ b/TLM/TLM/Util/RoundaboutMassEdit.cs @@ -125,13 +125,13 @@ private static void FixRulesRoundabout(ushort segmentId, bool startNode) { JunctionRestrictionsManager.Instance.SetValue( segmentId, startNode, - JunctionRestrictionFlags.AllowPedestrianCrossing, + JunctionRestrictionsFlags.AllowPedestrianCrossing, false); } JunctionRestrictionsManager.Instance.SetValue( segmentId, startNode, - JunctionRestrictionFlags.AllowEnterWhenBlocked, + JunctionRestrictionsFlags.AllowEnterWhenBlocked, true); } @@ -143,7 +143,7 @@ internal static void FixRulesMinor(ushort segmentId, ushort nodeId) { JunctionRestrictionsManager.Instance.SetValue( segmentId, startNode, - JunctionRestrictionFlags.AllowPedestrianCrossing, + JunctionRestrictionsFlags.AllowPedestrianCrossing, false); } if (Options.RoundAboutQuickFix_PrioritySigns) { @@ -155,14 +155,14 @@ internal static void FixRulesMinor(ushort segmentId, ushort nodeId) { if (isHighway) { //ignore highway rules: //TODO remove as part of issue #569 - JunctionRestrictionsManager.Instance.SetValue(segmentId, startNode, JunctionRestrictionFlags.AllowForwardLaneChange, true); + JunctionRestrictionsManager.Instance.SetValue(segmentId, startNode, JunctionRestrictionsFlags.AllowForwardLaneChange, true); } // endif if (Options.RoundAboutQuickFix_KeepClearYieldR) { JunctionRestrictionsManager.Instance.SetValue( segmentId, startNode, - JunctionRestrictionFlags.AllowEnterWhenBlocked, + JunctionRestrictionsFlags.AllowEnterWhenBlocked, false); } } diff --git a/TLM/TMPE.API/Hook/IJunctionRestrictionsHook.cs b/TLM/TMPE.API/Hook/IJunctionRestrictionsHook.cs index 359685468..49010e72f 100644 --- a/TLM/TMPE.API/Hook/IJunctionRestrictionsHook.cs +++ b/TLM/TMPE.API/Hook/IJunctionRestrictionsHook.cs @@ -23,14 +23,14 @@ public interface IJunctionRestrictionsHook { /// /// /// Specifies which flags to invalidate. - public void InvalidateFlags(ushort segmentId, bool startNode, JunctionRestrictionFlags flags); + public void InvalidateFlags(ushort segmentId, bool startNode, JunctionRestrictionsFlags flags); /// /// Schedles the specified flags for recalculation for all segment ends on the specified node. /// /// /// Specifies which flags to invalidate. - public void InvalidateFlags(ushort nodeId, JunctionRestrictionFlags flags); + public void InvalidateFlags(ushort nodeId, JunctionRestrictionsFlags flags); public class FlagsHookArgs { @@ -48,15 +48,15 @@ public class FlagsHookArgs { /// Identifies which flags are being returned. Unnecessary computation may be avoided /// by examining this mask to see which flags are being requested. /// - public JunctionRestrictionFlags Mask { get; private set; } + public JunctionRestrictionsFlags Mask { get; private set; } /// /// The flag return values. Changes to this property alter the outcome of the underlying operation. /// Any flags that not set in the property are ignored. /// - public JunctionRestrictionFlags Result { get; set; } + public JunctionRestrictionsFlags Result { get; set; } - public FlagsHookArgs(ushort segmentId, bool startNode, JunctionRestrictionFlags mask, JunctionRestrictionFlags result) { + public FlagsHookArgs(ushort segmentId, bool startNode, JunctionRestrictionsFlags mask, JunctionRestrictionsFlags result) { SegmentId = segmentId; StartNode = startNode; Mask = mask; diff --git a/TLM/TMPE.API/Manager/IJunctionRestrictionsManager.cs b/TLM/TMPE.API/Manager/IJunctionRestrictionsManager.cs index 6336e5db2..55f8c2b3d 100644 --- a/TLM/TMPE.API/Manager/IJunctionRestrictionsManager.cs +++ b/TLM/TMPE.API/Manager/IJunctionRestrictionsManager.cs @@ -13,7 +13,7 @@ public interface IJunctionRestrictionsManager { /// /// /// - bool IsConfigurable(ushort segmentId, bool startNode, JunctionRestrictionFlags flags); + bool IsConfigurable(ushort segmentId, bool startNode, JunctionRestrictionsFlags flags); /// /// Returns the set value (not the default) for the specified flag, or null if no value has been set. @@ -23,7 +23,7 @@ public interface IJunctionRestrictionsManager { /// /// /// - bool? GetValue(ushort segmentId, bool startNode, JunctionRestrictionFlags flags); + bool? GetValue(ushort segmentId, bool startNode, JunctionRestrictionsFlags flags); /// /// Returns the set value of the specified flag, or the default value if no value is set. @@ -33,7 +33,7 @@ public interface IJunctionRestrictionsManager { /// /// /// - bool GetValueOrDefault(ushort segmentId, bool startNode, JunctionRestrictionFlags flags); + bool GetValueOrDefault(ushort segmentId, bool startNode, JunctionRestrictionsFlags flags); /// /// Returns the default value for the specified flag. @@ -43,7 +43,7 @@ public interface IJunctionRestrictionsManager { /// /// /// - bool GetDefaultValue(ushort segmentId, bool startNode, JunctionRestrictionFlags flags); + bool GetDefaultValue(ushort segmentId, bool startNode, JunctionRestrictionsFlags flags); /// /// Sets the value of the specified flag(s). If null, clears the set value so that the default will be used. @@ -53,7 +53,7 @@ public interface IJunctionRestrictionsManager { /// /// /// true if the operation was successful, false if not configurable - bool SetValue(ushort segmentId, bool startNode, JunctionRestrictionFlags flags, bool? value); + bool SetValue(ushort segmentId, bool startNode, JunctionRestrictionsFlags flags, bool? value); /// /// Toggles the value of the specified flag. This method fails if more than one flag is specified. @@ -62,12 +62,12 @@ public interface IJunctionRestrictionsManager { /// /// /// true if the operation was successful, false if not configurable or if more than one flag was specified - bool ToggleValue(ushort segmentId, bool startNode, JunctionRestrictionFlags flags); + bool ToggleValue(ushort segmentId, bool startNode, JunctionRestrictionsFlags flags); #region IsConfigurable /// - /// This API is dprecated. Please use .
+ /// This API is dprecated. Please use .
/// Determines if u-turn behavior may be controlled at the given segment end. ///
/// segment id @@ -78,7 +78,7 @@ public interface IJunctionRestrictionsManager { bool IsUturnAllowedConfigurable(ushort segmentId, bool startNode, ref NetNode node); /// - /// This API is dprecated. Please use .
+ /// This API is dprecated. Please use .
/// Determines if turn-on-red behavior is enabled for near turns and may be controlled at /// the given segment end. ///
@@ -91,7 +91,7 @@ public interface IJunctionRestrictionsManager { bool IsNearTurnOnRedAllowedConfigurable(ushort segmentId, bool startNode, ref NetNode node); /// - /// This API is dprecated. Please use .
+ /// This API is dprecated. Please use .
/// Determines if turn-on-red behavior is enabled for far turns and may be controlled at /// the given segment end. ///
@@ -104,7 +104,7 @@ public interface IJunctionRestrictionsManager { bool IsFarTurnOnRedAllowedConfigurable(ushort segmentId, bool startNode, ref NetNode node); /// - /// This API is dprecated. Please use .
+ /// This API is dprecated. Please use .
/// Determines if turn-on-red behavior is enabled for the given turn type and that it may /// be controlled at the given segment end. ///
@@ -120,7 +120,7 @@ bool IsTurnOnRedAllowedConfigurable(bool near, ref NetNode node); /// - /// This API is dprecated. Please use .
+ /// This API is dprecated. Please use .
/// Determines if lane changing behavior may be controlled at the given segment end. ///
/// segment id @@ -134,7 +134,7 @@ bool IsLaneChangingAllowedWhenGoingStraightConfigurable( ref NetNode node); /// - /// This API is dprecated. Please use .
+ /// This API is dprecated. Please use .
/// Determines if entering blocked junctions may be controlled at the given segment end. ///
/// segment id @@ -148,7 +148,7 @@ bool IsEnteringBlockedJunctionAllowedConfigurable(ushort segmentId, ref NetNode node); /// - /// This API is dprecated. Please use .
+ /// This API is dprecated. Please use .
/// Determines if pedestrian crossings may be controlled at the given segment end. ///
/// segment id @@ -165,7 +165,7 @@ bool IsPedestrianCrossingAllowedConfigurable(ushort segmentId, #region GetDefault /// - /// This API is dprecated. Please use .
+ /// This API is dprecated. Please use .
/// Determines the default setting for u-turns at the given segment end. ///
/// segment id @@ -177,7 +177,7 @@ bool IsPedestrianCrossingAllowedConfigurable(ushort segmentId, bool GetDefaultUturnAllowed(ushort segmentId, bool startNode, ref NetNode node); /// - /// This API is dprecated. Please use .
+ /// This API is dprecated. Please use .
/// Determines the default setting for near turn-on-red at the given segment end. ///
/// segment id @@ -189,7 +189,7 @@ bool IsPedestrianCrossingAllowedConfigurable(ushort segmentId, bool GetDefaultNearTurnOnRedAllowed(ushort segmentId, bool startNode, ref NetNode node); /// - /// This API is dprecated. Please use .
+ /// This API is dprecated. Please use .
/// Determines the default setting for far turn-on-red at the given segment end. ///
/// segment id @@ -201,7 +201,7 @@ bool IsPedestrianCrossingAllowedConfigurable(ushort segmentId, bool GetDefaultFarTurnOnRedAllowed(ushort segmentId, bool startNode, ref NetNode node); /// - /// This API is dprecated. Please use .
+ /// This API is dprecated. Please use .
/// Determines the default turn-on-red setting for the given turn type at the given segment end. ///
/// for near turns? @@ -217,7 +217,7 @@ bool GetDefaultTurnOnRedAllowed(bool near, ref NetNode node); /// - /// This API is dprecated. Please use .
+ /// This API is dprecated. Please use .
/// Determines the default setting for straight lane changes at the given segment end. ///
/// segment id @@ -232,7 +232,7 @@ bool GetDefaultLaneChangingAllowedWhenGoingStraight( ref NetNode node); /// - /// This API is dprecated. Please use .
+ /// This API is dprecated. Please use .
/// Determines the default setting for entering a blocked junction at the given segment end. ///
/// segment id @@ -246,7 +246,7 @@ bool GetDefaultEnteringBlockedJunctionAllowed(ushort segmentId, ref NetNode node); /// - /// This API is dprecated. Please use .
+ /// This API is dprecated. Please use .
/// Determines the default setting for pedestrian crossings at the given segment end. ///
/// segment id @@ -264,7 +264,7 @@ bool GetDefaultPedestrianCrossingAllowed(ushort segmentId, #region IsAllowed /// - /// This API is dprecated. Please use .
+ /// This API is dprecated. Please use .
/// Determines whether u-turns are allowed at the given segment end. ///
/// segment id @@ -275,7 +275,7 @@ bool GetDefaultPedestrianCrossingAllowed(ushort segmentId, bool IsUturnAllowed(ushort segmentId, bool startNode); /// - /// This API is dprecated. Please use .
+ /// This API is dprecated. Please use .
/// Determines whether turn-on-red is allowed for near turns at the given segment end. ///
/// segment id @@ -286,7 +286,7 @@ bool GetDefaultPedestrianCrossingAllowed(ushort segmentId, bool IsNearTurnOnRedAllowed(ushort segmentId, bool startNode); /// - /// This API is dprecated. Please use .
+ /// This API is dprecated. Please use .
/// Determines whether turn-on-red is allowed for far turns at the given segment end. ///
/// segment id @@ -297,7 +297,7 @@ bool GetDefaultPedestrianCrossingAllowed(ushort segmentId, bool IsFarTurnOnRedAllowed(ushort segmentId, bool startNode); /// - /// This API is dprecated. Please use .
+ /// This API is dprecated. Please use .
/// Determines whether turn-on-red is allowed for the given turn type at the given segment end. ///
/// for near turns? @@ -309,7 +309,7 @@ bool GetDefaultPedestrianCrossingAllowed(ushort segmentId, bool IsTurnOnRedAllowed(bool near, ushort segmentId, bool startNode); /// - /// This API is dprecated. Please use .
+ /// This API is dprecated. Please use .
/// Determines whether lane changing when going straight is allowed at the given segment end. ///
/// segment id @@ -320,7 +320,7 @@ bool GetDefaultPedestrianCrossingAllowed(ushort segmentId, bool IsLaneChangingAllowedWhenGoingStraight(ushort segmentId, bool startNode); /// - /// This API is dprecated. Please use .
+ /// This API is dprecated. Please use .
/// Determines whether entering a blocked junction is allowed at the given segment end. ///
/// segment id @@ -331,7 +331,7 @@ bool GetDefaultPedestrianCrossingAllowed(ushort segmentId, bool IsEnteringBlockedJunctionAllowed(ushort segmentId, bool startNode); /// - /// This API is dprecated. Please use .
+ /// This API is dprecated. Please use .
/// Determines whether crossing the road is allowed at the given segment end. ///
/// segment id @@ -345,7 +345,7 @@ bool GetDefaultPedestrianCrossingAllowed(ushort segmentId, #region Get /// - /// This API is dprecated. Please use .
+ /// This API is dprecated. Please use .
/// Retrieves the u-turn setting for the given segment end. ///
/// segment id @@ -356,7 +356,7 @@ bool GetDefaultPedestrianCrossingAllowed(ushort segmentId, TernaryBool GetUturnAllowed(ushort segmentId, bool startNode); /// - /// This API is dprecated. Please use .
+ /// This API is dprecated. Please use .
/// Retrieves the turn-on-red setting for near turns and the given segment end. ///
/// segment id @@ -367,7 +367,7 @@ bool GetDefaultPedestrianCrossingAllowed(ushort segmentId, TernaryBool GetNearTurnOnRedAllowed(ushort segmentId, bool startNode); /// - /// This API is dprecated. Please use .
+ /// This API is dprecated. Please use .
/// Retrieves the turn-on-red setting for far turns and the given segment end. ///
/// segment id @@ -378,7 +378,7 @@ bool GetDefaultPedestrianCrossingAllowed(ushort segmentId, TernaryBool GetFarTurnOnRedAllowed(ushort segmentId, bool startNode); /// - /// This API is dprecated. Please use .
+ /// This API is dprecated. Please use .
/// Retrieves the turn-on-red setting for the given turn type and segment end. ///
/// for near turns? @@ -390,7 +390,7 @@ bool GetDefaultPedestrianCrossingAllowed(ushort segmentId, TernaryBool GetTurnOnRedAllowed(bool near, ushort segmentId, bool startNode); /// - /// This API is dprecated. Please use .
+ /// This API is dprecated. Please use .
/// Retrieves the lane changing setting for the given segment end. ///
/// segment id @@ -401,7 +401,7 @@ bool GetDefaultPedestrianCrossingAllowed(ushort segmentId, TernaryBool GetLaneChangingAllowedWhenGoingStraight(ushort segmentId, bool startNode); /// - /// This API is dprecated. Please use .
+ /// This API is dprecated. Please use .
/// Retrieves the "enter blocked junction" setting for the given segment end. ///
/// segment id @@ -412,7 +412,7 @@ bool GetDefaultPedestrianCrossingAllowed(ushort segmentId, TernaryBool GetEnteringBlockedJunctionAllowed(ushort segmentId, bool startNode); /// - /// This API is dprecated. Please use .
+ /// This API is dprecated. Please use .
/// Retrieves the pedestrian crossing setting for the given segment end. ///
/// segment id @@ -426,7 +426,7 @@ bool GetDefaultPedestrianCrossingAllowed(ushort segmentId, #region Toggle /// - /// This API is dprecated. Please use .
+ /// This API is dprecated. Please use .
/// Switches the u-turn flag for the given segment end. ///
/// segment id @@ -439,7 +439,7 @@ bool GetDefaultPedestrianCrossingAllowed(ushort segmentId, bool ToggleUturnAllowed(ushort segmentId, bool startNode); /// - /// This API is dprecated. Please use .
+ /// This API is dprecated. Please use .
/// Switches the turn-on-red flag for near turns and given segment end. ///
/// segment id @@ -452,7 +452,7 @@ bool GetDefaultPedestrianCrossingAllowed(ushort segmentId, bool ToggleNearTurnOnRedAllowed(ushort segmentId, bool startNode); /// - /// This API is dprecated. Please use .
+ /// This API is dprecated. Please use .
/// Switches the turn-on-red flag for far turns and given segment end. ///
/// segment id @@ -465,7 +465,7 @@ bool GetDefaultPedestrianCrossingAllowed(ushort segmentId, bool ToggleFarTurnOnRedAllowed(ushort segmentId, bool startNode); /// - /// This API is dprecated. Please use .
+ /// This API is dprecated. Please use .
/// Switches the turn-on-red flag for the given turn type and segment end. ///
/// for near turns? @@ -479,7 +479,7 @@ bool GetDefaultPedestrianCrossingAllowed(ushort segmentId, bool ToggleTurnOnRedAllowed(bool near, ushort segmentId, bool startNode); /// - /// This API is dprecated. Please use .
+ /// This API is dprecated. Please use .
/// Switches the lane changing flag for the given segment end. ///
/// segment id @@ -492,7 +492,7 @@ bool GetDefaultPedestrianCrossingAllowed(ushort segmentId, bool ToggleLaneChangingAllowedWhenGoingStraight(ushort segmentId, bool startNode); /// - /// This API is dprecated. Please use .
+ /// This API is dprecated. Please use .
/// Switches the "enter blocked junction" flag for the given segment end. ///
/// segment id @@ -505,7 +505,7 @@ bool GetDefaultPedestrianCrossingAllowed(ushort segmentId, bool ToggleEnteringBlockedJunctionAllowed(ushort segmentId, bool startNode); /// - /// This API is dprecated. Please use .
+ /// This API is dprecated. Please use .
/// Switches the pedestrian crossing flag for the given segment end. ///
/// segment id @@ -521,7 +521,7 @@ bool GetDefaultPedestrianCrossingAllowed(ushort segmentId, #region Set : bool /// - /// This API is dprecated. Please use .
+ /// This API is dprecated. Please use .
/// Sets the u-turn flag for the given segment end to the given value. ///
/// segment id @@ -535,7 +535,7 @@ bool GetDefaultPedestrianCrossingAllowed(ushort segmentId, bool SetUturnAllowed(ushort segmentId, bool startNode, bool value); /// - /// This API is dprecated. Please use .
+ /// This API is dprecated. Please use .
/// Sets the turn-on-red flag for near turns at the given segment end to the given value. ///
/// segment id @@ -549,7 +549,7 @@ bool GetDefaultPedestrianCrossingAllowed(ushort segmentId, bool SetNearTurnOnRedAllowed(ushort segmentId, bool startNode, bool value); /// - /// This API is dprecated. Please use .
+ /// This API is dprecated. Please use .
/// Sets the turn-on-red flag for far turns at the given segment end to the given value. ///
/// segment id @@ -563,7 +563,7 @@ bool GetDefaultPedestrianCrossingAllowed(ushort segmentId, bool SetFarTurnOnRedAllowed(ushort segmentId, bool startNode, bool value); /// - /// This API is dprecated. Please use .
+ /// This API is dprecated. Please use .
/// Sets the turn-on-red flag for the given turn type and segment end to the given value. ///
/// for near turns? @@ -578,7 +578,7 @@ bool GetDefaultPedestrianCrossingAllowed(ushort segmentId, bool SetTurnOnRedAllowed(bool near, ushort segmentId, bool startNode, bool value); /// - /// This API is dprecated. Please use .
+ /// This API is dprecated. Please use .
/// Sets the lane changing flag for the given segment end to the given value. ///
/// segment id @@ -592,7 +592,7 @@ bool GetDefaultPedestrianCrossingAllowed(ushort segmentId, bool SetLaneChangingAllowedWhenGoingStraight(ushort segmentId, bool startNode, bool value); /// - /// This API is dprecated. Please use .
+ /// This API is dprecated. Please use .
/// Sets the "enter blocked junction" flag for the given segment end to the given value. ///
/// segment id @@ -606,7 +606,7 @@ bool GetDefaultPedestrianCrossingAllowed(ushort segmentId, bool SetEnteringBlockedJunctionAllowed(ushort segmentId, bool startNode, bool value); /// - /// This API is dprecated. Please use .
+ /// This API is dprecated. Please use .
/// Sets the pedestrian crossing flag for the given segment end to the given value. ///
/// segment id @@ -623,7 +623,7 @@ bool GetDefaultPedestrianCrossingAllowed(ushort segmentId, #region Set : TernaryBool /// - /// This API is dprecated. Please use .
+ /// This API is dprecated. Please use .
/// Sets the u-turn flag for the given segment end to the given value. ///
/// segment id @@ -637,7 +637,7 @@ bool GetDefaultPedestrianCrossingAllowed(ushort segmentId, bool SetUturnAllowed(ushort segmentId, bool startNode, TernaryBool value); /// - /// This API is dprecated. Please use .
+ /// This API is dprecated. Please use .
/// Sets the turn-on-red flag for near turns at the given segment end to the given value. ///
/// segment id @@ -651,7 +651,7 @@ bool GetDefaultPedestrianCrossingAllowed(ushort segmentId, bool SetNearTurnOnRedAllowed(ushort segmentId, bool startNode, TernaryBool value); /// - /// This API is dprecated. Please use .
+ /// This API is dprecated. Please use .
/// Sets the turn-on-red flag for far turns at the given segment end to the given value. ///
/// segment id @@ -665,7 +665,7 @@ bool GetDefaultPedestrianCrossingAllowed(ushort segmentId, bool SetFarTurnOnRedAllowed(ushort segmentId, bool startNode, TernaryBool value); /// - /// This API is dprecated. Please use .
+ /// This API is dprecated. Please use .
/// Sets the turn-on-red flag for the given turn type and segment end to the given value. ///
/// for near turns? @@ -680,7 +680,7 @@ bool GetDefaultPedestrianCrossingAllowed(ushort segmentId, bool SetTurnOnRedAllowed(bool near, ushort segmentId, bool startNode, TernaryBool value); /// - /// This API is dprecated. Please use .
+ /// This API is dprecated. Please use .
/// Sets the lane changing flag for the given segment end to the given value. ///
/// segment id @@ -694,7 +694,7 @@ bool GetDefaultPedestrianCrossingAllowed(ushort segmentId, bool SetLaneChangingAllowedWhenGoingStraight(ushort segmentId, bool startNode, TernaryBool value); /// - /// This API is dprecated. Please use .
+ /// This API is dprecated. Please use .
/// Sets the "enter blocked junction" flag for the given segment end to the given value. ///
/// segment id @@ -708,7 +708,7 @@ bool GetDefaultPedestrianCrossingAllowed(ushort segmentId, bool SetEnteringBlockedJunctionAllowed(ushort segmentId, bool startNode, TernaryBool value); /// - /// This API is dprecated. Please use .
+ /// This API is dprecated. Please use .
/// Sets the pedestrian crossing flag for the given segment end to the given value. ///
/// segment id diff --git a/TLM/TMPE.API/TMPE.API.csproj b/TLM/TMPE.API/TMPE.API.csproj index 1a5b2bbb0..46c046e04 100644 --- a/TLM/TMPE.API/TMPE.API.csproj +++ b/TLM/TMPE.API/TMPE.API.csproj @@ -147,7 +147,7 @@ - + diff --git a/TLM/TMPE.API/Traffic/Enums/JunctionRestrictionFlags.cs b/TLM/TMPE.API/Traffic/Enums/JunctionRestrictionsFlags.cs similarity index 88% rename from TLM/TMPE.API/Traffic/Enums/JunctionRestrictionFlags.cs rename to TLM/TMPE.API/Traffic/Enums/JunctionRestrictionsFlags.cs index 3a4059e5b..4407edd55 100644 --- a/TLM/TMPE.API/Traffic/Enums/JunctionRestrictionFlags.cs +++ b/TLM/TMPE.API/Traffic/Enums/JunctionRestrictionsFlags.cs @@ -3,7 +3,7 @@ namespace TrafficManager.API.Traffic.Enums { [Flags] - public enum JunctionRestrictionFlags { + public enum JunctionRestrictionsFlags { AllowUTurn = 1 << 0, AllowNearTurnOnRed = 1 << 1, AllowFarTurnOnRed = 1 << 2, From 42801160df641a13dbba3b43cdf9bd94d65d70e0 Mon Sep 17 00:00:00 2001 From: Elesbaan70 <95266227+Elesbaan70@users.noreply.github.com> Date: Sun, 29 May 2022 03:43:56 -0500 Subject: [PATCH 20/21] A couple of nasty bugs --- TLM/TLM/Manager/Impl/JunctionRestrictionsManager.cs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/TLM/TLM/Manager/Impl/JunctionRestrictionsManager.cs b/TLM/TLM/Manager/Impl/JunctionRestrictionsManager.cs index 458d945ee..11e5f298e 100644 --- a/TLM/TLM/Manager/Impl/JunctionRestrictionsManager.cs +++ b/TLM/TLM/Manager/Impl/JunctionRestrictionsManager.cs @@ -1131,7 +1131,7 @@ private void Recalculate(SegmentEndId segmentEndId) { } if (Instance.GetConfigurableHook != null) { - var args = new FlagsHookArgs(segmentEndId.SegmentId, segmentEndId.StartNode, mask, newConfigurables); + var args = new FlagsHookArgs(segmentEndId.SegmentId, segmentEndId.StartNode, recalculateFlags, newConfigurables); Instance.GetConfigurableHook(args); newConfigurables = args.Result; } @@ -1155,13 +1155,14 @@ private void Recalculate(SegmentEndId segmentEndId) { } if (Instance.GetDefaultsHook != null) { - var args = new FlagsHookArgs(segmentEndId.SegmentId, segmentEndId.StartNode, mask, newDefaults); + var args = new FlagsHookArgs(segmentEndId.SegmentId, segmentEndId.StartNode, recalculateFlags, newDefaults); Instance.GetDefaultsHook(args); newDefaults = args.Result; } configurables = (configurables & ~recalculateFlags) | (newConfigurables & recalculateFlags); defaults = (defaults & ~recalculateFlags) | (newDefaults & recalculateFlags); + valid |= recalculateFlags; var clearFlags = mask & ~configurables; if (clearFlags != default) { From 636d1e277cc74959f9618265c9756e3e6357f931 Mon Sep 17 00:00:00 2001 From: Elesbaan70 <95266227+Elesbaan70@users.noreply.github.com> Date: Fri, 17 Jun 2022 23:55:20 -0500 Subject: [PATCH 21/21] Reconcile dulicate enum --- TLM/TLM/Custom/PathFinding/CustomPathFind.cs | 10 +- .../Impl/JunctionRestrictionsManager.cs | 252 +++++++++--------- .../LaneConnectionSubManager.cs | 2 +- TLM/TLM/Manager/Impl/RoutingManager.cs | 6 +- .../Manager/Impl/VehicleBehaviorManager.cs | 2 +- .../UI/SubTools/ManualTrafficLightsTool.cs | 2 +- .../UI/SubTools/TTL/TimedTrafficLightsTool.cs | 2 +- TLM/TLM/Util/PriorityRoad.cs | 8 +- TLM/TLM/Util/Record/SegmentEndRecord.cs | 36 +-- TLM/TLM/Util/RoundaboutMassEdit.cs | 10 +- .../Hook/IJunctionRestrictionsHook.cs | 10 +- .../Manager/IJunctionRestrictionsManager.cs | 110 ++++---- TLM/TMPE.API/TMPE.API.csproj | 1 - .../Traffic/Enums/JunctionRestrictionFlags.cs | 8 +- .../Enums/JunctionRestrictionsFlags.cs | 16 -- 15 files changed, 232 insertions(+), 243 deletions(-) delete mode 100644 TLM/TMPE.API/Traffic/Enums/JunctionRestrictionsFlags.cs diff --git a/TLM/TLM/Custom/PathFinding/CustomPathFind.cs b/TLM/TLM/Custom/PathFinding/CustomPathFind.cs index a78bcaa96..9ce297581 100644 --- a/TLM/TLM/Custom/PathFinding/CustomPathFind.cs +++ b/TLM/TLM/Custom/PathFinding/CustomPathFind.cs @@ -1088,7 +1088,7 @@ ref nextSegmentId.ToSegment(), leftSegmentId, leftSegment.m_startNode == nextNodeId, - JunctionRestrictionsFlags.AllowPedestrianCrossing)) { + JunctionRestrictionFlags.AllowPedestrianCrossing)) { break; } #endif @@ -1127,7 +1127,7 @@ ref nextSegmentId.ToSegment(), rightSegmentId, rightSegment.m_startNode == nextNodeId, - JunctionRestrictionsFlags.AllowPedestrianCrossing)) { + JunctionRestrictionFlags.AllowPedestrianCrossing)) { break; } #endif @@ -3172,7 +3172,7 @@ private void ProcessItemPedBicycle( if (!junctionManager.GetValueOrDefault( nextSegmentId, nextIsStartNode, - JunctionRestrictionsFlags.AllowPedestrianCrossing)) { + JunctionRestrictionFlags.AllowPedestrianCrossing)) { if (isLogEnabled) { DebugLog( unitId, @@ -3590,7 +3590,7 @@ private bool ProcessItemRouted( prevIsCarLane && // u-turns for road vehicles only (!isHeavyVehicle_ || isStockUturnPoint) && // only small vehicles may perform u-turns OR everyone at stock u-turn points !prevIsOutgoingOneWay && // do not u-turn on one-ways - junctionManager.GetValueOrDefault(prevSegmentId, nextIsStartNode, JunctionRestrictionsFlags.AllowUTurn); + junctionManager.GetValueOrDefault(prevSegmentId, nextIsStartNode, JunctionRestrictionFlags.AllowUTurn); if (isLogEnabled) { DebugLog( @@ -3603,7 +3603,7 @@ private bool ProcessItemRouted( $"\tisStockUturnPoint={isStockUturnPoint}\n" + $"\tprevIsOutgoingOneWay={prevIsOutgoingOneWay}\n" + $"\tjManager.IsUturnAllowed(prevSegmentId, " + - $"nextIsStartNode)={junctionManager.GetValueOrDefault(prevSegmentId, nextIsStartNode, JunctionRestrictionsFlags.AllowUTurn)}\n" + + $"nextIsStartNode)={junctionManager.GetValueOrDefault(prevSegmentId, nextIsStartNode, JunctionRestrictionFlags.AllowUTurn)}\n" + $"\tm_queueItem.vehicleId={queueItem_.vehicleId}\n" + $"\tm_queueItem.spawned={queueItem_.spawned}\n" + $"\tprevSegmentId={prevSegmentId}\n" + diff --git a/TLM/TLM/Manager/Impl/JunctionRestrictionsManager.cs b/TLM/TLM/Manager/Impl/JunctionRestrictionsManager.cs index 11e5f298e..4a8822564 100644 --- a/TLM/TLM/Manager/Impl/JunctionRestrictionsManager.cs +++ b/TLM/TLM/Manager/Impl/JunctionRestrictionsManager.cs @@ -47,7 +47,7 @@ private JunctionRestrictionsManager() { orphanedRestrictions = new SegmentJunctionRestrictions[NetManager.MAX_SEGMENT_COUNT]; } - public void InvalidateFlags(ushort segmentId, bool startNode, JunctionRestrictionsFlags flags) { + public void InvalidateFlags(ushort segmentId, bool startNode, JunctionRestrictionFlags flags) { if (segmentId.ToSegment().IsValid()) { SegmentEndId segmentEndId = segmentId.AtNode(startNode); @@ -55,7 +55,7 @@ public void InvalidateFlags(ushort segmentId, bool startNode, JunctionRestrictio } } - public void InvalidateFlags(ushort nodeId, JunctionRestrictionsFlags flags) { + public void InvalidateFlags(ushort nodeId, JunctionRestrictionFlags flags) { if (nodeId.ToNode().IsValid()) { foreach (var segmentId in ExtNodeManager.Instance.GetNodeSegmentIds(nodeId, ClockDirection.Clockwise)) { @@ -649,7 +649,7 @@ public bool ClearSegmentEnd(ushort segmentId, bool startNode) { return false; var segmentEndId = segmentId.AtNode(startNode); - return GetJunctionRestrictions(segmentEndId).ClearValue(segmentEndId, JunctionRestrictionsFlags.All); + return GetJunctionRestrictions(segmentEndId).ClearValue(segmentEndId, JunctionRestrictionFlags.All); } private void SetSegmentJunctionRestrictions(SegmentEndId segmentEndId, JunctionRestrictions restrictions) { @@ -711,12 +711,12 @@ public bool LoadData(List data) { Configuration.SegmentNodeFlags flags = segNodeConf.startNodeFlags; ref NetNode startNode = ref startNodeId.ToNode(); - SetValue(segNodeConf.segmentId, true, JunctionRestrictionsFlags.AllowUTurn, flags.uturnAllowed); - SetValue(segNodeConf.segmentId, true, JunctionRestrictionsFlags.AllowNearTurnOnRed, flags.turnOnRedAllowed); - SetValue(segNodeConf.segmentId, true, JunctionRestrictionsFlags.AllowFarTurnOnRed, flags.farTurnOnRedAllowed); - SetValue(segNodeConf.segmentId, true, JunctionRestrictionsFlags.AllowForwardLaneChange, flags.straightLaneChangingAllowed); - SetValue(segNodeConf.segmentId, true, JunctionRestrictionsFlags.AllowEnterWhenBlocked, flags.enterWhenBlockedAllowed); - SetValue(segNodeConf.segmentId, true, JunctionRestrictionsFlags.AllowPedestrianCrossing, flags.pedestrianCrossingAllowed); + SetValue(segNodeConf.segmentId, true, JunctionRestrictionFlags.AllowUTurn, flags.uturnAllowed); + SetValue(segNodeConf.segmentId, true, JunctionRestrictionFlags.AllowNearTurnOnRed, flags.turnOnRedAllowed); + SetValue(segNodeConf.segmentId, true, JunctionRestrictionFlags.AllowFarTurnOnRed, flags.farTurnOnRedAllowed); + SetValue(segNodeConf.segmentId, true, JunctionRestrictionFlags.AllowForwardLaneChange, flags.straightLaneChangingAllowed); + SetValue(segNodeConf.segmentId, true, JunctionRestrictionFlags.AllowEnterWhenBlocked, flags.enterWhenBlockedAllowed); + SetValue(segNodeConf.segmentId, true, JunctionRestrictionFlags.AllowPedestrianCrossing, flags.pedestrianCrossingAllowed); } else { Log.Warning( "JunctionRestrictionsManager.LoadData(): Could not get segment " + @@ -730,12 +730,12 @@ public bool LoadData(List data) { Configuration.SegmentNodeFlags flags = segNodeConf.endNodeFlags; ref NetNode node = ref endNodeId.ToNode(); - SetValue(segNodeConf.segmentId, false, JunctionRestrictionsFlags.AllowUTurn, flags.uturnAllowed); - SetValue(segNodeConf.segmentId, false, JunctionRestrictionsFlags.AllowNearTurnOnRed, flags.turnOnRedAllowed); - SetValue(segNodeConf.segmentId, false, JunctionRestrictionsFlags.AllowFarTurnOnRed, flags.farTurnOnRedAllowed); - SetValue(segNodeConf.segmentId, false, JunctionRestrictionsFlags.AllowForwardLaneChange, flags.straightLaneChangingAllowed); - SetValue(segNodeConf.segmentId, false, JunctionRestrictionsFlags.AllowEnterWhenBlocked, flags.enterWhenBlockedAllowed); - SetValue(segNodeConf.segmentId, false, JunctionRestrictionsFlags.AllowPedestrianCrossing, flags.pedestrianCrossingAllowed); + SetValue(segNodeConf.segmentId, false, JunctionRestrictionFlags.AllowUTurn, flags.uturnAllowed); + SetValue(segNodeConf.segmentId, false, JunctionRestrictionFlags.AllowNearTurnOnRed, flags.turnOnRedAllowed); + SetValue(segNodeConf.segmentId, false, JunctionRestrictionFlags.AllowFarTurnOnRed, flags.farTurnOnRedAllowed); + SetValue(segNodeConf.segmentId, false, JunctionRestrictionFlags.AllowForwardLaneChange, flags.straightLaneChangingAllowed); + SetValue(segNodeConf.segmentId, false, JunctionRestrictionFlags.AllowEnterWhenBlocked, flags.enterWhenBlockedAllowed); + SetValue(segNodeConf.segmentId, false, JunctionRestrictionFlags.AllowPedestrianCrossing, flags.pedestrianCrossingAllowed); } else { Log.Warning( "JunctionRestrictionsManager.LoadData(): Could not get segment " + @@ -777,12 +777,12 @@ public bool LoadData(List data) { if (!endFlags.IsDefault(segmentId.AtStartNode())) { startNodeFlags = new Configuration.SegmentNodeFlags(); - startNodeFlags.uturnAllowed = GetValue(segmentId, true, JunctionRestrictionsFlags.AllowUTurn); - startNodeFlags.turnOnRedAllowed = GetValue(segmentId, true, JunctionRestrictionsFlags.AllowNearTurnOnRed); - startNodeFlags.farTurnOnRedAllowed = GetValue(segmentId, true, JunctionRestrictionsFlags.AllowFarTurnOnRed); - startNodeFlags.straightLaneChangingAllowed = GetValue(segmentId, true, JunctionRestrictionsFlags.AllowForwardLaneChange); - startNodeFlags.enterWhenBlockedAllowed = GetValue(segmentId, true, JunctionRestrictionsFlags.AllowEnterWhenBlocked); - startNodeFlags.pedestrianCrossingAllowed = GetValue(segmentId, true, JunctionRestrictionsFlags.AllowPedestrianCrossing); + startNodeFlags.uturnAllowed = GetValue(segmentId, true, JunctionRestrictionFlags.AllowUTurn); + startNodeFlags.turnOnRedAllowed = GetValue(segmentId, true, JunctionRestrictionFlags.AllowNearTurnOnRed); + startNodeFlags.farTurnOnRedAllowed = GetValue(segmentId, true, JunctionRestrictionFlags.AllowFarTurnOnRed); + startNodeFlags.straightLaneChangingAllowed = GetValue(segmentId, true, JunctionRestrictionFlags.AllowForwardLaneChange); + startNodeFlags.enterWhenBlockedAllowed = GetValue(segmentId, true, JunctionRestrictionFlags.AllowEnterWhenBlocked); + startNodeFlags.pedestrianCrossingAllowed = GetValue(segmentId, true, JunctionRestrictionFlags.AllowPedestrianCrossing); #if DEBUGSAVE Log._Debug($"JunctionRestrictionsManager.SaveData: Saving start node "+ @@ -799,12 +799,12 @@ public bool LoadData(List data) { if (!restrictions.IsDefault(segmentId.AtEndNode())) { endNodeFlags = new Configuration.SegmentNodeFlags(); - endNodeFlags.uturnAllowed = GetValue(segmentId, false, JunctionRestrictionsFlags.AllowUTurn); - endNodeFlags.turnOnRedAllowed = GetValue(segmentId, false, JunctionRestrictionsFlags.AllowNearTurnOnRed); - endNodeFlags.farTurnOnRedAllowed = GetValue(segmentId, false, JunctionRestrictionsFlags.AllowFarTurnOnRed); - endNodeFlags.straightLaneChangingAllowed = GetValue(segmentId, false, JunctionRestrictionsFlags.AllowForwardLaneChange); - endNodeFlags.enterWhenBlockedAllowed = GetValue(segmentId, false, JunctionRestrictionsFlags.AllowEnterWhenBlocked); - endNodeFlags.pedestrianCrossingAllowed = GetValue(segmentId, false, JunctionRestrictionsFlags.AllowPedestrianCrossing); + endNodeFlags.uturnAllowed = GetValue(segmentId, false, JunctionRestrictionFlags.AllowUTurn); + endNodeFlags.turnOnRedAllowed = GetValue(segmentId, false, JunctionRestrictionFlags.AllowNearTurnOnRed); + endNodeFlags.farTurnOnRedAllowed = GetValue(segmentId, false, JunctionRestrictionFlags.AllowFarTurnOnRed); + endNodeFlags.straightLaneChangingAllowed = GetValue(segmentId, false, JunctionRestrictionFlags.AllowForwardLaneChange); + endNodeFlags.enterWhenBlockedAllowed = GetValue(segmentId, false, JunctionRestrictionFlags.AllowEnterWhenBlocked); + endNodeFlags.pedestrianCrossingAllowed = GetValue(segmentId, false, JunctionRestrictionFlags.AllowPedestrianCrossing); #if DEBUGSAVE Log._Debug($"JunctionRestrictionsManager.SaveData: Saving end node junction "+ @@ -836,13 +836,13 @@ public bool LoadData(List data) { return ret; } - public bool IsConfigurable(ushort segmentId, bool startNode, JunctionRestrictionsFlags flags) + public bool IsConfigurable(ushort segmentId, bool startNode, JunctionRestrictionFlags flags) => segmentRestrictions[segmentId].IsConfigurable(segmentId.AtNode(startNode), flags); - public bool GetDefaultValue(ushort segmentId, bool startNode, JunctionRestrictionsFlags flags) + public bool GetDefaultValue(ushort segmentId, bool startNode, JunctionRestrictionFlags flags) => segmentRestrictions[segmentId].GetDefaultValue(segmentId.AtNode(startNode), flags); - public bool ToggleValue(ushort segmentId, bool startNode, JunctionRestrictionsFlags flags) { + public bool ToggleValue(ushort segmentId, bool startNode, JunctionRestrictionFlags flags) { if (flags == default || ((int)flags & ((int)flags - 1)) != 0) return false; @@ -850,86 +850,86 @@ public bool ToggleValue(ushort segmentId, bool startNode, JunctionRestrictionsFl return SetValue(segmentId, startNode, flags, !GetValueOrDefault(segmentId, startNode, flags)); } - public bool SetValue(ushort segmentId, bool startNode, JunctionRestrictionsFlags flags, bool? value) + public bool SetValue(ushort segmentId, bool startNode, JunctionRestrictionFlags flags, bool? value) => segmentId.ToSegment().IsValid() && flags != default && segmentRestrictions[segmentId].SetValue(segmentId.AtNode(startNode), flags, value); - public bool? GetValue(ushort segmentId, bool startNode, JunctionRestrictionsFlags flags) + public bool? GetValue(ushort segmentId, bool startNode, JunctionRestrictionFlags flags) => segmentRestrictions[segmentId].GetValue(segmentId.AtNode(startNode), flags); - public bool GetValueOrDefault(ushort segmentId, bool startNode, JunctionRestrictionsFlags flags) + public bool GetValueOrDefault(ushort segmentId, bool startNode, JunctionRestrictionFlags flags) => segmentRestrictions[segmentId].GetValueOrDefault(segmentId.AtNode(startNode), flags); - bool IJunctionRestrictionsManager.IsUturnAllowedConfigurable(ushort segmentId, bool startNode, ref NetNode node) => IsConfigurable(segmentId, startNode, JunctionRestrictionsFlags.AllowUTurn); - bool IJunctionRestrictionsManager.IsNearTurnOnRedAllowedConfigurable(ushort segmentId, bool startNode, ref NetNode node) => IsConfigurable(segmentId, startNode, JunctionRestrictionsFlags.AllowNearTurnOnRed); - bool IJunctionRestrictionsManager.IsFarTurnOnRedAllowedConfigurable(ushort segmentId, bool startNode, ref NetNode node) => IsConfigurable(segmentId, startNode, JunctionRestrictionsFlags.AllowFarTurnOnRed); - bool IJunctionRestrictionsManager.IsTurnOnRedAllowedConfigurable(bool near, ushort segmentId, bool startNode, ref NetNode node) => IsConfigurable(segmentId, startNode, near ? JunctionRestrictionsFlags.AllowNearTurnOnRed : JunctionRestrictionsFlags.AllowFarTurnOnRed); - bool IJunctionRestrictionsManager.IsLaneChangingAllowedWhenGoingStraightConfigurable(ushort segmentId, bool startNode, ref NetNode node) => IsConfigurable(segmentId, startNode, JunctionRestrictionsFlags.AllowForwardLaneChange); - bool IJunctionRestrictionsManager.IsEnteringBlockedJunctionAllowedConfigurable(ushort segmentId, bool startNode, ref NetNode node) => IsConfigurable(segmentId, startNode, JunctionRestrictionsFlags.AllowEnterWhenBlocked); - bool IJunctionRestrictionsManager.IsPedestrianCrossingAllowedConfigurable(ushort segmentId, bool startNode, ref NetNode node) => IsConfigurable(segmentId, startNode, JunctionRestrictionsFlags.AllowPedestrianCrossing); - bool IJunctionRestrictionsManager.GetDefaultUturnAllowed(ushort segmentId, bool startNode, ref NetNode node) => GetDefaultValue(segmentId, startNode, JunctionRestrictionsFlags.AllowUTurn); - bool IJunctionRestrictionsManager.GetDefaultNearTurnOnRedAllowed(ushort segmentId, bool startNode, ref NetNode node) => GetDefaultValue(segmentId, startNode, JunctionRestrictionsFlags.AllowNearTurnOnRed); - bool IJunctionRestrictionsManager.GetDefaultFarTurnOnRedAllowed(ushort segmentId, bool startNode, ref NetNode node) => GetDefaultValue(segmentId, startNode, JunctionRestrictionsFlags.AllowFarTurnOnRed); - bool IJunctionRestrictionsManager.GetDefaultTurnOnRedAllowed(bool near, ushort segmentId, bool startNode, ref NetNode node) => GetDefaultValue(segmentId, startNode, near ? JunctionRestrictionsFlags.AllowNearTurnOnRed : JunctionRestrictionsFlags.AllowFarTurnOnRed); - bool IJunctionRestrictionsManager.GetDefaultLaneChangingAllowedWhenGoingStraight(ushort segmentId, bool startNode, ref NetNode node) => GetDefaultValue(segmentId, startNode, JunctionRestrictionsFlags.AllowForwardLaneChange); - bool IJunctionRestrictionsManager.GetDefaultEnteringBlockedJunctionAllowed(ushort segmentId, bool startNode, ref NetNode node) => GetDefaultValue(segmentId, startNode, JunctionRestrictionsFlags.AllowEnterWhenBlocked); - bool IJunctionRestrictionsManager.GetDefaultPedestrianCrossingAllowed(ushort segmentId, bool startNode, ref NetNode node) => GetDefaultValue(segmentId, startNode, JunctionRestrictionsFlags.AllowPedestrianCrossing); - [Obsolete("If you must call this method, please go through IJunctionRestrictionsManager.", true)] public bool ToggleUturnAllowed(ushort segmentId, bool startNode) => ToggleValue(segmentId, startNode, JunctionRestrictionsFlags.AllowUTurn); - [Obsolete("If you must call this method, please go through IJunctionRestrictionsManager.", true)] public bool ToggleNearTurnOnRedAllowed(ushort segmentId, bool startNode) => ToggleValue(segmentId, startNode, JunctionRestrictionsFlags.AllowNearTurnOnRed); - [Obsolete("If you must call this method, please go through IJunctionRestrictionsManager.", true)] public bool ToggleFarTurnOnRedAllowed(ushort segmentId, bool startNode) => ToggleValue(segmentId, startNode, JunctionRestrictionsFlags.AllowFarTurnOnRed); - [Obsolete("If you must call this method, please go through IJunctionRestrictionsManager.", true)] public bool ToggleTurnOnRedAllowed(bool near, ushort segmentId, bool startNode) => ToggleValue(segmentId, startNode, near ? JunctionRestrictionsFlags.AllowNearTurnOnRed : JunctionRestrictionsFlags.AllowFarTurnOnRed); - [Obsolete("If you must call this method, please go through IJunctionRestrictionsManager.", true)] public bool ToggleLaneChangingAllowedWhenGoingStraight(ushort segmentId, bool startNode) => ToggleValue(segmentId, startNode, JunctionRestrictionsFlags.AllowForwardLaneChange); - [Obsolete("If you must call this method, please go through IJunctionRestrictionsManager.", true)] public bool ToggleEnteringBlockedJunctionAllowed(ushort segmentId, bool startNode) => ToggleValue(segmentId, startNode, JunctionRestrictionsFlags.AllowEnterWhenBlocked); - [Obsolete("If you must call this method, please go through IJunctionRestrictionsManager.", true)] public bool TogglePedestrianCrossingAllowed(ushort segmentId, bool startNode) => ToggleValue(segmentId, startNode, JunctionRestrictionsFlags.AllowPedestrianCrossing); - [Obsolete("If you must call this method, please go through IJunctionRestrictionsManager.", true)] public bool SetUturnAllowed(ushort segmentId, bool startNode, bool value) => SetValue(segmentId, startNode, JunctionRestrictionsFlags.AllowUTurn, value); - [Obsolete("If you must call this method, please go through IJunctionRestrictionsManager.", true)] public bool SetNearTurnOnRedAllowed(ushort segmentId, bool startNode, bool value) => SetValue(segmentId, startNode, JunctionRestrictionsFlags.AllowNearTurnOnRed, value); - [Obsolete("If you must call this method, please go through IJunctionRestrictionsManager.", true)] public bool SetFarTurnOnRedAllowed(ushort segmentId, bool startNode, bool value) => SetValue(segmentId, startNode, JunctionRestrictionsFlags.AllowFarTurnOnRed, value); - [Obsolete("If you must call this method, please go through IJunctionRestrictionsManager.", true)] public bool SetTurnOnRedAllowed(bool near, ushort segmentId, bool startNode, bool value) => SetValue(segmentId, startNode, near ? JunctionRestrictionsFlags.AllowNearTurnOnRed : JunctionRestrictionsFlags.AllowFarTurnOnRed, value); - [Obsolete("If you must call this method, please go through IJunctionRestrictionsManager.", true)] public bool SetLaneChangingAllowedWhenGoingStraight(ushort segmentId, bool startNode, bool value) => SetValue(segmentId, startNode, JunctionRestrictionsFlags.AllowForwardLaneChange, value); - [Obsolete("If you must call this method, please go through IJunctionRestrictionsManager.", true)] public bool SetEnteringBlockedJunctionAllowed(ushort segmentId, bool startNode, bool value) => SetValue(segmentId, startNode, JunctionRestrictionsFlags.AllowEnterWhenBlocked, value); - [Obsolete("If you must call this method, please go through IJunctionRestrictionsManager.", true)] public bool SetPedestrianCrossingAllowed(ushort segmentId, bool startNode, bool value) => SetValue(segmentId, startNode, JunctionRestrictionsFlags.AllowPedestrianCrossing, value); - [Obsolete("If you must call this method, please go through IJunctionRestrictionsManager.", true)] public bool SetUturnAllowed(ushort segmentId, bool startNode, TernaryBool value) => SetValue(segmentId, startNode, JunctionRestrictionsFlags.AllowUTurn, ToOptBool(value)); - [Obsolete("If you must call this method, please go through IJunctionRestrictionsManager.", true)] public bool SetNearTurnOnRedAllowed(ushort segmentId, bool startNode, TernaryBool value) => SetValue(segmentId, startNode, JunctionRestrictionsFlags.AllowNearTurnOnRed, ToOptBool(value)); - [Obsolete("If you must call this method, please go through IJunctionRestrictionsManager.", true)] public bool SetFarTurnOnRedAllowed(ushort segmentId, bool startNode, TernaryBool value) => SetValue(segmentId, startNode, JunctionRestrictionsFlags.AllowFarTurnOnRed, ToOptBool(value)); - [Obsolete("If you must call this method, please go through IJunctionRestrictionsManager.", true)] public bool SetTurnOnRedAllowed(bool near, ushort segmentId, bool startNode, TernaryBool value) => SetValue(segmentId, startNode, near ? JunctionRestrictionsFlags.AllowNearTurnOnRed : JunctionRestrictionsFlags.AllowFarTurnOnRed, ToOptBool(value)); - [Obsolete("If you must call this method, please go through IJunctionRestrictionsManager.", true)] public bool SetLaneChangingAllowedWhenGoingStraight(ushort segmentId, bool startNode, TernaryBool value) => SetValue(segmentId, startNode, JunctionRestrictionsFlags.AllowForwardLaneChange, ToOptBool(value)); - [Obsolete("If you must call this method, please go through IJunctionRestrictionsManager.", true)] public bool SetEnteringBlockedJunctionAllowed(ushort segmentId, bool startNode, TernaryBool value) => SetValue(segmentId, startNode, JunctionRestrictionsFlags.AllowEnterWhenBlocked, ToOptBool(value)); - [Obsolete("If you must call this method, please go through IJunctionRestrictionsManager.", true)] public bool SetPedestrianCrossingAllowed(ushort segmentId, bool startNode, TernaryBool value) => SetValue(segmentId, startNode, JunctionRestrictionsFlags.AllowPedestrianCrossing, ToOptBool(value)); - [Obsolete("If you must call this method, please go through IJunctionRestrictionsManager.", true)] public TernaryBool GetUturnAllowed(ushort segmentId, bool startNode) => ToTernaryBool(GetValue(segmentId, startNode, JunctionRestrictionsFlags.AllowUTurn)); - [Obsolete("If you must call this method, please go through IJunctionRestrictionsManager.", true)] public TernaryBool GetNearTurnOnRedAllowed(ushort segmentId, bool startNode) => ToTernaryBool(GetValue(segmentId, startNode, JunctionRestrictionsFlags.AllowNearTurnOnRed)); - [Obsolete("If you must call this method, please go through IJunctionRestrictionsManager.", true)] public TernaryBool GetFarTurnOnRedAllowed(ushort segmentId, bool startNode) => ToTernaryBool(GetValue(segmentId, startNode, JunctionRestrictionsFlags.AllowFarTurnOnRed)); - [Obsolete("If you must call this method, please go through IJunctionRestrictionsManager.", true)] public TernaryBool GetTurnOnRedAllowed(bool near, ushort segmentId, bool startNode) => ToTernaryBool(GetValue(segmentId, startNode, near ? JunctionRestrictionsFlags.AllowNearTurnOnRed : JunctionRestrictionsFlags.AllowFarTurnOnRed)); - [Obsolete("If you must call this method, please go through IJunctionRestrictionsManager.", true)] public TernaryBool GetLaneChangingAllowedWhenGoingStraight(ushort segmentId, bool startNode) => ToTernaryBool(GetValue(segmentId, startNode, JunctionRestrictionsFlags.AllowForwardLaneChange)); - [Obsolete("If you must call this method, please go through IJunctionRestrictionsManager.", true)] public TernaryBool GetEnteringBlockedJunctionAllowed(ushort segmentId, bool startNode) => ToTernaryBool(GetValue(segmentId, startNode, JunctionRestrictionsFlags.AllowEnterWhenBlocked)); - [Obsolete("If you must call this method, please go through IJunctionRestrictionsManager.", true)] public TernaryBool GetPedestrianCrossingAllowed(ushort segmentId, bool startNode) => ToTernaryBool(GetValue(segmentId, startNode, JunctionRestrictionsFlags.AllowPedestrianCrossing)); - [Obsolete("If you must call this method, please go through IJunctionRestrictionsManager.", true)] public bool IsUturnAllowed(ushort segmentId, bool startNode) => GetValueOrDefault(segmentId, startNode, JunctionRestrictionsFlags.AllowUTurn); - [Obsolete("If you must call this method, please go through IJunctionRestrictionsManager.", true)] public bool IsNearTurnOnRedAllowed(ushort segmentId, bool startNode) => GetValueOrDefault(segmentId, startNode, JunctionRestrictionsFlags.AllowNearTurnOnRed); - [Obsolete("If you must call this method, please go through IJunctionRestrictionsManager.", true)] public bool IsFarTurnOnRedAllowed(ushort segmentId, bool startNode) => GetValueOrDefault(segmentId, startNode, JunctionRestrictionsFlags.AllowFarTurnOnRed); - [Obsolete("If you must call this method, please go through IJunctionRestrictionsManager.", true)] public bool IsTurnOnRedAllowed(bool near, ushort segmentId, bool startNode) => GetValueOrDefault(segmentId, startNode, near ? JunctionRestrictionsFlags.AllowNearTurnOnRed : JunctionRestrictionsFlags.AllowFarTurnOnRed); - [Obsolete("If you must call this method, please go through IJunctionRestrictionsManager.", true)] public bool IsLaneChangingAllowedWhenGoingStraight(ushort segmentId, bool startNode) => GetValueOrDefault(segmentId, startNode, JunctionRestrictionsFlags.AllowForwardLaneChange); - [Obsolete("If you must call this method, please go through IJunctionRestrictionsManager.", true)] public bool IsEnteringBlockedJunctionAllowed(ushort segmentId, bool startNode) => GetValueOrDefault(segmentId, startNode, JunctionRestrictionsFlags.AllowEnterWhenBlocked); - [Obsolete("If you must call this method, please go through IJunctionRestrictionsManager.", true)] public bool IsPedestrianCrossingAllowed(ushort segmentId, bool startNode) => GetValueOrDefault(segmentId, startNode, JunctionRestrictionsFlags.AllowPedestrianCrossing); + bool IJunctionRestrictionsManager.IsUturnAllowedConfigurable(ushort segmentId, bool startNode, ref NetNode node) => IsConfigurable(segmentId, startNode, JunctionRestrictionFlags.AllowUTurn); + bool IJunctionRestrictionsManager.IsNearTurnOnRedAllowedConfigurable(ushort segmentId, bool startNode, ref NetNode node) => IsConfigurable(segmentId, startNode, JunctionRestrictionFlags.AllowNearTurnOnRed); + bool IJunctionRestrictionsManager.IsFarTurnOnRedAllowedConfigurable(ushort segmentId, bool startNode, ref NetNode node) => IsConfigurable(segmentId, startNode, JunctionRestrictionFlags.AllowFarTurnOnRed); + bool IJunctionRestrictionsManager.IsTurnOnRedAllowedConfigurable(bool near, ushort segmentId, bool startNode, ref NetNode node) => IsConfigurable(segmentId, startNode, near ? JunctionRestrictionFlags.AllowNearTurnOnRed : JunctionRestrictionFlags.AllowFarTurnOnRed); + bool IJunctionRestrictionsManager.IsLaneChangingAllowedWhenGoingStraightConfigurable(ushort segmentId, bool startNode, ref NetNode node) => IsConfigurable(segmentId, startNode, JunctionRestrictionFlags.AllowForwardLaneChange); + bool IJunctionRestrictionsManager.IsEnteringBlockedJunctionAllowedConfigurable(ushort segmentId, bool startNode, ref NetNode node) => IsConfigurable(segmentId, startNode, JunctionRestrictionFlags.AllowEnterWhenBlocked); + bool IJunctionRestrictionsManager.IsPedestrianCrossingAllowedConfigurable(ushort segmentId, bool startNode, ref NetNode node) => IsConfigurable(segmentId, startNode, JunctionRestrictionFlags.AllowPedestrianCrossing); + bool IJunctionRestrictionsManager.GetDefaultUturnAllowed(ushort segmentId, bool startNode, ref NetNode node) => GetDefaultValue(segmentId, startNode, JunctionRestrictionFlags.AllowUTurn); + bool IJunctionRestrictionsManager.GetDefaultNearTurnOnRedAllowed(ushort segmentId, bool startNode, ref NetNode node) => GetDefaultValue(segmentId, startNode, JunctionRestrictionFlags.AllowNearTurnOnRed); + bool IJunctionRestrictionsManager.GetDefaultFarTurnOnRedAllowed(ushort segmentId, bool startNode, ref NetNode node) => GetDefaultValue(segmentId, startNode, JunctionRestrictionFlags.AllowFarTurnOnRed); + bool IJunctionRestrictionsManager.GetDefaultTurnOnRedAllowed(bool near, ushort segmentId, bool startNode, ref NetNode node) => GetDefaultValue(segmentId, startNode, near ? JunctionRestrictionFlags.AllowNearTurnOnRed : JunctionRestrictionFlags.AllowFarTurnOnRed); + bool IJunctionRestrictionsManager.GetDefaultLaneChangingAllowedWhenGoingStraight(ushort segmentId, bool startNode, ref NetNode node) => GetDefaultValue(segmentId, startNode, JunctionRestrictionFlags.AllowForwardLaneChange); + bool IJunctionRestrictionsManager.GetDefaultEnteringBlockedJunctionAllowed(ushort segmentId, bool startNode, ref NetNode node) => GetDefaultValue(segmentId, startNode, JunctionRestrictionFlags.AllowEnterWhenBlocked); + bool IJunctionRestrictionsManager.GetDefaultPedestrianCrossingAllowed(ushort segmentId, bool startNode, ref NetNode node) => GetDefaultValue(segmentId, startNode, JunctionRestrictionFlags.AllowPedestrianCrossing); + [Obsolete("If you must call this method, please go through IJunctionRestrictionsManager.", true)] public bool ToggleUturnAllowed(ushort segmentId, bool startNode) => ToggleValue(segmentId, startNode, JunctionRestrictionFlags.AllowUTurn); + [Obsolete("If you must call this method, please go through IJunctionRestrictionsManager.", true)] public bool ToggleNearTurnOnRedAllowed(ushort segmentId, bool startNode) => ToggleValue(segmentId, startNode, JunctionRestrictionFlags.AllowNearTurnOnRed); + [Obsolete("If you must call this method, please go through IJunctionRestrictionsManager.", true)] public bool ToggleFarTurnOnRedAllowed(ushort segmentId, bool startNode) => ToggleValue(segmentId, startNode, JunctionRestrictionFlags.AllowFarTurnOnRed); + [Obsolete("If you must call this method, please go through IJunctionRestrictionsManager.", true)] public bool ToggleTurnOnRedAllowed(bool near, ushort segmentId, bool startNode) => ToggleValue(segmentId, startNode, near ? JunctionRestrictionFlags.AllowNearTurnOnRed : JunctionRestrictionFlags.AllowFarTurnOnRed); + [Obsolete("If you must call this method, please go through IJunctionRestrictionsManager.", true)] public bool ToggleLaneChangingAllowedWhenGoingStraight(ushort segmentId, bool startNode) => ToggleValue(segmentId, startNode, JunctionRestrictionFlags.AllowForwardLaneChange); + [Obsolete("If you must call this method, please go through IJunctionRestrictionsManager.", true)] public bool ToggleEnteringBlockedJunctionAllowed(ushort segmentId, bool startNode) => ToggleValue(segmentId, startNode, JunctionRestrictionFlags.AllowEnterWhenBlocked); + [Obsolete("If you must call this method, please go through IJunctionRestrictionsManager.", true)] public bool TogglePedestrianCrossingAllowed(ushort segmentId, bool startNode) => ToggleValue(segmentId, startNode, JunctionRestrictionFlags.AllowPedestrianCrossing); + [Obsolete("If you must call this method, please go through IJunctionRestrictionsManager.", true)] public bool SetUturnAllowed(ushort segmentId, bool startNode, bool value) => SetValue(segmentId, startNode, JunctionRestrictionFlags.AllowUTurn, value); + [Obsolete("If you must call this method, please go through IJunctionRestrictionsManager.", true)] public bool SetNearTurnOnRedAllowed(ushort segmentId, bool startNode, bool value) => SetValue(segmentId, startNode, JunctionRestrictionFlags.AllowNearTurnOnRed, value); + [Obsolete("If you must call this method, please go through IJunctionRestrictionsManager.", true)] public bool SetFarTurnOnRedAllowed(ushort segmentId, bool startNode, bool value) => SetValue(segmentId, startNode, JunctionRestrictionFlags.AllowFarTurnOnRed, value); + [Obsolete("If you must call this method, please go through IJunctionRestrictionsManager.", true)] public bool SetTurnOnRedAllowed(bool near, ushort segmentId, bool startNode, bool value) => SetValue(segmentId, startNode, near ? JunctionRestrictionFlags.AllowNearTurnOnRed : JunctionRestrictionFlags.AllowFarTurnOnRed, value); + [Obsolete("If you must call this method, please go through IJunctionRestrictionsManager.", true)] public bool SetLaneChangingAllowedWhenGoingStraight(ushort segmentId, bool startNode, bool value) => SetValue(segmentId, startNode, JunctionRestrictionFlags.AllowForwardLaneChange, value); + [Obsolete("If you must call this method, please go through IJunctionRestrictionsManager.", true)] public bool SetEnteringBlockedJunctionAllowed(ushort segmentId, bool startNode, bool value) => SetValue(segmentId, startNode, JunctionRestrictionFlags.AllowEnterWhenBlocked, value); + [Obsolete("If you must call this method, please go through IJunctionRestrictionsManager.", true)] public bool SetPedestrianCrossingAllowed(ushort segmentId, bool startNode, bool value) => SetValue(segmentId, startNode, JunctionRestrictionFlags.AllowPedestrianCrossing, value); + [Obsolete("If you must call this method, please go through IJunctionRestrictionsManager.", true)] public bool SetUturnAllowed(ushort segmentId, bool startNode, TernaryBool value) => SetValue(segmentId, startNode, JunctionRestrictionFlags.AllowUTurn, ToOptBool(value)); + [Obsolete("If you must call this method, please go through IJunctionRestrictionsManager.", true)] public bool SetNearTurnOnRedAllowed(ushort segmentId, bool startNode, TernaryBool value) => SetValue(segmentId, startNode, JunctionRestrictionFlags.AllowNearTurnOnRed, ToOptBool(value)); + [Obsolete("If you must call this method, please go through IJunctionRestrictionsManager.", true)] public bool SetFarTurnOnRedAllowed(ushort segmentId, bool startNode, TernaryBool value) => SetValue(segmentId, startNode, JunctionRestrictionFlags.AllowFarTurnOnRed, ToOptBool(value)); + [Obsolete("If you must call this method, please go through IJunctionRestrictionsManager.", true)] public bool SetTurnOnRedAllowed(bool near, ushort segmentId, bool startNode, TernaryBool value) => SetValue(segmentId, startNode, near ? JunctionRestrictionFlags.AllowNearTurnOnRed : JunctionRestrictionFlags.AllowFarTurnOnRed, ToOptBool(value)); + [Obsolete("If you must call this method, please go through IJunctionRestrictionsManager.", true)] public bool SetLaneChangingAllowedWhenGoingStraight(ushort segmentId, bool startNode, TernaryBool value) => SetValue(segmentId, startNode, JunctionRestrictionFlags.AllowForwardLaneChange, ToOptBool(value)); + [Obsolete("If you must call this method, please go through IJunctionRestrictionsManager.", true)] public bool SetEnteringBlockedJunctionAllowed(ushort segmentId, bool startNode, TernaryBool value) => SetValue(segmentId, startNode, JunctionRestrictionFlags.AllowEnterWhenBlocked, ToOptBool(value)); + [Obsolete("If you must call this method, please go through IJunctionRestrictionsManager.", true)] public bool SetPedestrianCrossingAllowed(ushort segmentId, bool startNode, TernaryBool value) => SetValue(segmentId, startNode, JunctionRestrictionFlags.AllowPedestrianCrossing, ToOptBool(value)); + [Obsolete("If you must call this method, please go through IJunctionRestrictionsManager.", true)] public TernaryBool GetUturnAllowed(ushort segmentId, bool startNode) => ToTernaryBool(GetValue(segmentId, startNode, JunctionRestrictionFlags.AllowUTurn)); + [Obsolete("If you must call this method, please go through IJunctionRestrictionsManager.", true)] public TernaryBool GetNearTurnOnRedAllowed(ushort segmentId, bool startNode) => ToTernaryBool(GetValue(segmentId, startNode, JunctionRestrictionFlags.AllowNearTurnOnRed)); + [Obsolete("If you must call this method, please go through IJunctionRestrictionsManager.", true)] public TernaryBool GetFarTurnOnRedAllowed(ushort segmentId, bool startNode) => ToTernaryBool(GetValue(segmentId, startNode, JunctionRestrictionFlags.AllowFarTurnOnRed)); + [Obsolete("If you must call this method, please go through IJunctionRestrictionsManager.", true)] public TernaryBool GetTurnOnRedAllowed(bool near, ushort segmentId, bool startNode) => ToTernaryBool(GetValue(segmentId, startNode, near ? JunctionRestrictionFlags.AllowNearTurnOnRed : JunctionRestrictionFlags.AllowFarTurnOnRed)); + [Obsolete("If you must call this method, please go through IJunctionRestrictionsManager.", true)] public TernaryBool GetLaneChangingAllowedWhenGoingStraight(ushort segmentId, bool startNode) => ToTernaryBool(GetValue(segmentId, startNode, JunctionRestrictionFlags.AllowForwardLaneChange)); + [Obsolete("If you must call this method, please go through IJunctionRestrictionsManager.", true)] public TernaryBool GetEnteringBlockedJunctionAllowed(ushort segmentId, bool startNode) => ToTernaryBool(GetValue(segmentId, startNode, JunctionRestrictionFlags.AllowEnterWhenBlocked)); + [Obsolete("If you must call this method, please go through IJunctionRestrictionsManager.", true)] public TernaryBool GetPedestrianCrossingAllowed(ushort segmentId, bool startNode) => ToTernaryBool(GetValue(segmentId, startNode, JunctionRestrictionFlags.AllowPedestrianCrossing)); + [Obsolete("If you must call this method, please go through IJunctionRestrictionsManager.", true)] public bool IsUturnAllowed(ushort segmentId, bool startNode) => GetValueOrDefault(segmentId, startNode, JunctionRestrictionFlags.AllowUTurn); + [Obsolete("If you must call this method, please go through IJunctionRestrictionsManager.", true)] public bool IsNearTurnOnRedAllowed(ushort segmentId, bool startNode) => GetValueOrDefault(segmentId, startNode, JunctionRestrictionFlags.AllowNearTurnOnRed); + [Obsolete("If you must call this method, please go through IJunctionRestrictionsManager.", true)] public bool IsFarTurnOnRedAllowed(ushort segmentId, bool startNode) => GetValueOrDefault(segmentId, startNode, JunctionRestrictionFlags.AllowFarTurnOnRed); + [Obsolete("If you must call this method, please go through IJunctionRestrictionsManager.", true)] public bool IsTurnOnRedAllowed(bool near, ushort segmentId, bool startNode) => GetValueOrDefault(segmentId, startNode, near ? JunctionRestrictionFlags.AllowNearTurnOnRed : JunctionRestrictionFlags.AllowFarTurnOnRed); + [Obsolete("If you must call this method, please go through IJunctionRestrictionsManager.", true)] public bool IsLaneChangingAllowedWhenGoingStraight(ushort segmentId, bool startNode) => GetValueOrDefault(segmentId, startNode, JunctionRestrictionFlags.AllowForwardLaneChange); + [Obsolete("If you must call this method, please go through IJunctionRestrictionsManager.", true)] public bool IsEnteringBlockedJunctionAllowed(ushort segmentId, bool startNode) => GetValueOrDefault(segmentId, startNode, JunctionRestrictionFlags.AllowEnterWhenBlocked); + [Obsolete("If you must call this method, please go through IJunctionRestrictionsManager.", true)] public bool IsPedestrianCrossingAllowed(ushort segmentId, bool startNode) => GetValueOrDefault(segmentId, startNode, JunctionRestrictionFlags.AllowPedestrianCrossing); private struct SegmentJunctionRestrictions { public JunctionRestrictions startNodeRestrictions; public JunctionRestrictions endNodeRestrictions; - public bool GetValueOrDefault(SegmentEndId segmentEndId, JunctionRestrictionsFlags flags) { + public bool GetValueOrDefault(SegmentEndId segmentEndId, JunctionRestrictionFlags flags) { return (segmentEndId.StartNode ? startNodeRestrictions : endNodeRestrictions).GetValueOrDefault(segmentEndId, flags); } - public bool? GetValue(SegmentEndId segmentEndId, JunctionRestrictionsFlags flags) { + public bool? GetValue(SegmentEndId segmentEndId, JunctionRestrictionFlags flags) { return (segmentEndId.StartNode ? startNodeRestrictions : endNodeRestrictions).GetValue(segmentEndId, flags); } - public bool GetDefaultValue(SegmentEndId segmentEndId, JunctionRestrictionsFlags flags) { + public bool GetDefaultValue(SegmentEndId segmentEndId, JunctionRestrictionFlags flags) { return (segmentEndId.StartNode ? startNodeRestrictions : endNodeRestrictions).GetDefaultValue(segmentEndId, flags); } - public bool IsConfigurable(SegmentEndId segmentEndId, JunctionRestrictionsFlags flags) { + public bool IsConfigurable(SegmentEndId segmentEndId, JunctionRestrictionFlags flags) { return (segmentEndId.StartNode ? startNodeRestrictions : endNodeRestrictions).IsConfigurable(segmentEndId, flags); } - public bool SetValue(SegmentEndId segmentEndId, JunctionRestrictionsFlags flags, bool? value) { + public bool SetValue(SegmentEndId segmentEndId, JunctionRestrictionFlags flags, bool? value) { if (segmentEndId.StartNode) return startNodeRestrictions.SetValue(segmentEndId, flags, value); else @@ -967,47 +967,47 @@ public override string ToString() { private struct JunctionRestrictions { - private JunctionRestrictionsFlags values; + private JunctionRestrictionFlags values; - private JunctionRestrictionsFlags mask; + private JunctionRestrictionFlags mask; - private JunctionRestrictionsFlags defaults; + private JunctionRestrictionFlags defaults; - private JunctionRestrictionsFlags configurables; + private JunctionRestrictionFlags configurables; - private JunctionRestrictionsFlags valid; + private JunctionRestrictionFlags valid; - public bool ClearValue(SegmentEndId segmentEndId, JunctionRestrictionsFlags flags) => SetValue(segmentEndId, flags, null); + public bool ClearValue(SegmentEndId segmentEndId, JunctionRestrictionFlags flags) => SetValue(segmentEndId, flags, null); - private void SetDefault(SegmentEndId segmentEndId, JunctionRestrictionsFlags flags, bool value) { + private void SetDefault(SegmentEndId segmentEndId, JunctionRestrictionFlags flags, bool value) { if (value) defaults |= flags; else defaults &= ~flags; } - private void SetConfigurable(SegmentEndId segmentEndId, JunctionRestrictionsFlags flags, bool value) { + private void SetConfigurable(SegmentEndId segmentEndId, JunctionRestrictionFlags flags, bool value) { if (value) configurables |= flags; else configurables &= ~flags; } - public bool GetDefaultValue(SegmentEndId segmentEndId, JunctionRestrictionsFlags flags) { + public bool GetDefaultValue(SegmentEndId segmentEndId, JunctionRestrictionFlags flags) { Recalculate(segmentEndId); return (defaults & flags) == flags; } - public bool IsConfigurable(SegmentEndId segmentEndId, JunctionRestrictionsFlags flags) { + public bool IsConfigurable(SegmentEndId segmentEndId, JunctionRestrictionFlags flags) { Recalculate(segmentEndId); return (configurables & flags) == flags; } - public bool HasValue(SegmentEndId segmentEndId, JunctionRestrictionsFlags flags) { + public bool HasValue(SegmentEndId segmentEndId, JunctionRestrictionFlags flags) { return (mask & flags) == flags; } - public bool? GetValue(SegmentEndId segmentEndId, JunctionRestrictionsFlags flags) { + public bool? GetValue(SegmentEndId segmentEndId, JunctionRestrictionFlags flags) { return (mask & flags) != flags ? null : (values & flags) == flags ? true @@ -1015,23 +1015,23 @@ public bool HasValue(SegmentEndId segmentEndId, JunctionRestrictionsFlags flags) : null; } - public bool GetValueOrDefault(SegmentEndId segmentEndId, JunctionRestrictionsFlags flags) { + public bool GetValueOrDefault(SegmentEndId segmentEndId, JunctionRestrictionFlags flags) { Recalculate(segmentEndId); return ((values & flags & mask) | (defaults & flags & ~mask)) == flags; } - public JunctionRestrictionsFlags GetFlagsWithDefaults(SegmentEndId segmentEndId) { + public JunctionRestrictionFlags GetFlagsWithDefaults(SegmentEndId segmentEndId) { return (values & mask) | (defaults & ~mask); } - private const JunctionRestrictionsFlags routingRecalculationFlags = JunctionRestrictionsFlags.All & ~JunctionRestrictionsFlags.AllowEnterWhenBlocked; + private const JunctionRestrictionFlags routingRecalculationFlags = JunctionRestrictionFlags.All & ~JunctionRestrictionFlags.AllowEnterWhenBlocked; - private bool ValidateSet(SegmentEndId segmentEndId, JunctionRestrictionsFlags flags, JunctionRestrictionsFlags newValues, JunctionRestrictionsFlags newMask) { + private bool ValidateSet(SegmentEndId segmentEndId, JunctionRestrictionFlags flags, JunctionRestrictionFlags newValues, JunctionRestrictionFlags newMask) { - const JunctionRestrictionsFlags uTurnCheckFlags - = JunctionRestrictionsFlags.AllowNearTurnOnRed - | JunctionRestrictionsFlags.AllowFarTurnOnRed - | JunctionRestrictionsFlags.AllowUTurn; + const JunctionRestrictionFlags uTurnCheckFlags + = JunctionRestrictionFlags.AllowNearTurnOnRed + | JunctionRestrictionFlags.AllowFarTurnOnRed + | JunctionRestrictionFlags.AllowUTurn; if ((newMask & flags & uTurnCheckFlags) != 0 && (newValues & newMask & flags & uTurnCheckFlags) == 0 @@ -1041,7 +1041,7 @@ const JunctionRestrictionsFlags uTurnCheckFlags return true; } - public bool SetValue(SegmentEndId segmentEndId, JunctionRestrictionsFlags flags, bool? value) { + public bool SetValue(SegmentEndId segmentEndId, JunctionRestrictionFlags flags, bool? value) { Recalculate(segmentEndId); @@ -1051,7 +1051,7 @@ public bool SetValue(SegmentEndId segmentEndId, JunctionRestrictionsFlags flags, return Set(segmentEndId, flags, newValues, newMask); } - private bool Set(SegmentEndId segmentEndId, JunctionRestrictionsFlags flags, JunctionRestrictionsFlags newValues, JunctionRestrictionsFlags newMask) { + private bool Set(SegmentEndId segmentEndId, JunctionRestrictionFlags flags, JunctionRestrictionFlags newValues, JunctionRestrictionFlags newMask) { Recalculate(segmentEndId); @@ -1094,31 +1094,31 @@ private static Calculator DelegateTo(string methodName) { return (Calculator)Delegate.CreateDelegate(typeof(Calculator), Instance, methodName); } - private static Dictionary configurableCalculators = new Dictionary() { - { JunctionRestrictionsFlags.AllowUTurn, DelegateTo(nameof(IsUturnAllowedConfigurable)) }, - { JunctionRestrictionsFlags.AllowNearTurnOnRed, DelegateTo(nameof(IsNearTurnOnRedAllowedConfigurable)) }, - { JunctionRestrictionsFlags.AllowFarTurnOnRed, DelegateTo(nameof(IsFarTurnOnRedAllowedConfigurable)) }, - { JunctionRestrictionsFlags.AllowForwardLaneChange, DelegateTo(nameof(IsLaneChangingAllowedWhenGoingStraightConfigurable)) }, - { JunctionRestrictionsFlags.AllowEnterWhenBlocked, DelegateTo(nameof(IsEnteringBlockedJunctionAllowedConfigurable)) }, - { JunctionRestrictionsFlags.AllowPedestrianCrossing, DelegateTo(nameof(IsPedestrianCrossingAllowedConfigurable)) }, + private static Dictionary configurableCalculators = new Dictionary() { + { JunctionRestrictionFlags.AllowUTurn, DelegateTo(nameof(IsUturnAllowedConfigurable)) }, + { JunctionRestrictionFlags.AllowNearTurnOnRed, DelegateTo(nameof(IsNearTurnOnRedAllowedConfigurable)) }, + { JunctionRestrictionFlags.AllowFarTurnOnRed, DelegateTo(nameof(IsFarTurnOnRedAllowedConfigurable)) }, + { JunctionRestrictionFlags.AllowForwardLaneChange, DelegateTo(nameof(IsLaneChangingAllowedWhenGoingStraightConfigurable)) }, + { JunctionRestrictionFlags.AllowEnterWhenBlocked, DelegateTo(nameof(IsEnteringBlockedJunctionAllowedConfigurable)) }, + { JunctionRestrictionFlags.AllowPedestrianCrossing, DelegateTo(nameof(IsPedestrianCrossingAllowedConfigurable)) }, }; - private static Dictionary defaultCalculators = new Dictionary() { - { JunctionRestrictionsFlags.AllowUTurn, DelegateTo(nameof(GetDefaultUturnAllowed)) }, - { JunctionRestrictionsFlags.AllowNearTurnOnRed, DelegateTo(nameof(GetDefaultNearTurnOnRedAllowed)) }, - { JunctionRestrictionsFlags.AllowFarTurnOnRed, DelegateTo(nameof(GetDefaultFarTurnOnRedAllowed)) }, - { JunctionRestrictionsFlags.AllowForwardLaneChange, DelegateTo(nameof(GetDefaultLaneChangingAllowedWhenGoingStraight)) }, - { JunctionRestrictionsFlags.AllowEnterWhenBlocked, DelegateTo(nameof(GetDefaultEnteringBlockedJunctionAllowed)) }, - { JunctionRestrictionsFlags.AllowPedestrianCrossing, DelegateTo(nameof(GetDefaultPedestrianCrossingAllowed)) }, + private static Dictionary defaultCalculators = new Dictionary() { + { JunctionRestrictionFlags.AllowUTurn, DelegateTo(nameof(GetDefaultUturnAllowed)) }, + { JunctionRestrictionFlags.AllowNearTurnOnRed, DelegateTo(nameof(GetDefaultNearTurnOnRedAllowed)) }, + { JunctionRestrictionFlags.AllowFarTurnOnRed, DelegateTo(nameof(GetDefaultFarTurnOnRedAllowed)) }, + { JunctionRestrictionFlags.AllowForwardLaneChange, DelegateTo(nameof(GetDefaultLaneChangingAllowedWhenGoingStraight)) }, + { JunctionRestrictionFlags.AllowEnterWhenBlocked, DelegateTo(nameof(GetDefaultEnteringBlockedJunctionAllowed)) }, + { JunctionRestrictionFlags.AllowPedestrianCrossing, DelegateTo(nameof(GetDefaultPedestrianCrossingAllowed)) }, }; private void Recalculate(SegmentEndId segmentEndId) { - var recalculateFlags = JunctionRestrictionsFlags.All & ~valid; + var recalculateFlags = JunctionRestrictionFlags.All & ~valid; if (recalculateFlags != default) { ref var node = ref segmentEndId.GetNodeId().ToNode(); - JunctionRestrictionsFlags newConfigurables = default; + JunctionRestrictionFlags newConfigurables = default; foreach (var c in configurableCalculators) { if ((recalculateFlags & c.Key) != 0) { @@ -1136,7 +1136,7 @@ private void Recalculate(SegmentEndId segmentEndId) { newConfigurables = args.Result; } - JunctionRestrictionsFlags newDefaults = default; + JunctionRestrictionFlags newDefaults = default; foreach (var c in defaultCalculators) { if ((recalculateFlags & c.Key) != 0) { diff --git a/TLM/TLM/Manager/Impl/LaneConnection/LaneConnectionSubManager.cs b/TLM/TLM/Manager/Impl/LaneConnection/LaneConnectionSubManager.cs index f82d71a25..ee8e38100 100644 --- a/TLM/TLM/Manager/Impl/LaneConnection/LaneConnectionSubManager.cs +++ b/TLM/TLM/Manager/Impl/LaneConnection/LaneConnectionSubManager.cs @@ -365,7 +365,7 @@ internal bool AddLaneConnection(uint sourceLaneId, uint targetLaneId, bool sourc JunctionRestrictionsManager.Instance.SetValue( sourceSegmentId, sourceStartNode, - JunctionRestrictionsFlags.AllowUTurn, + JunctionRestrictionFlags.AllowUTurn, true); } diff --git a/TLM/TLM/Manager/Impl/RoutingManager.cs b/TLM/TLM/Manager/Impl/RoutingManager.cs index c360e5d04..6ebc668ad 100644 --- a/TLM/TLM/Manager/Impl/RoutingManager.cs +++ b/TLM/TLM/Manager/Impl/RoutingManager.cs @@ -512,7 +512,7 @@ private void RecalculateLaneEndRoutingData( ExtSegmentEnd segEnd = segEndMan.ExtSegmentEnds[segEndMan.GetIndex(segmentId, startNode)]; if (segEnd.incoming) { ++numIncomingSegents; - laneSwitching |= JunctionRestrictionsManager.Instance.GetValueOrDefault(segmentId, startNode, JunctionRestrictionsFlags.AllowForwardLaneChange); + laneSwitching |= JunctionRestrictionsManager.Instance.GetValueOrDefault(segmentId, startNode, JunctionRestrictionFlags.AllowForwardLaneChange); } if (segEnd.outgoing) { @@ -1048,7 +1048,7 @@ private void RecalculateLaneEndRoutingData( bool hasUTurnRule = JunctionRestrictionsManager.Instance.GetValueOrDefault( nextSegmentId, isNodeStartNodeOfNextSegment, - JunctionRestrictionsFlags.AllowUTurn); + JunctionRestrictionFlags.AllowUTurn); bool hasFarTurnArrow = (Shortcuts.LHT && hasRightArrow) || (Shortcuts.RHT && hasLeftArrow); bool canTurn = !nodeIsRealJunction || nodeIsEndOrOneWayOut || hasFarTurnArrow || hasUTurnRule; @@ -1218,7 +1218,7 @@ private void RecalculateLaneEndRoutingData( bool laneChangesAllowed = Options.junctionRestrictionsEnabled && JunctionRestrictionsManager.Instance.GetValueOrDefault( - nextSegmentId, isNodeStartNodeOfNextSegment, JunctionRestrictionsFlags.AllowForwardLaneChange); + nextSegmentId, isNodeStartNodeOfNextSegment, JunctionRestrictionFlags.AllowForwardLaneChange); int nextCompatibleLaneCount = numNextCompatibleTransitionDatas; if (nextCompatibleLaneCount > 0) { diff --git a/TLM/TLM/Manager/Impl/VehicleBehaviorManager.cs b/TLM/TLM/Manager/Impl/VehicleBehaviorManager.cs index 2e24ee149..7aba24eb8 100644 --- a/TLM/TLM/Manager/Impl/VehicleBehaviorManager.cs +++ b/TLM/TLM/Manager/Impl/VehicleBehaviorManager.cs @@ -1702,7 +1702,7 @@ protected bool MustCheckSpace(ushort segmentId, !JunctionRestrictionsManager.Instance.GetValueOrDefault( segmentId, startNode, - JunctionRestrictionsFlags.AllowEnterWhenBlocked); + JunctionRestrictionFlags.AllowEnterWhenBlocked); } else { checkSpace = (node.m_flags & (NetNode.Flags.Junction diff --git a/TLM/TLM/UI/SubTools/ManualTrafficLightsTool.cs b/TLM/TLM/UI/SubTools/ManualTrafficLightsTool.cs index bed90a967..6ec00ea3f 100644 --- a/TLM/TLM/UI/SubTools/ManualTrafficLightsTool.cs +++ b/TLM/TLM/UI/SubTools/ManualTrafficLightsTool.cs @@ -119,7 +119,7 @@ public override void OnToolGUI(Event e) { junctionRestrictionsManager.GetValueOrDefault( segmentLights.SegmentId, segmentLights.StartNode, - JunctionRestrictionsFlags.AllowPedestrianCrossing); + JunctionRestrictionFlags.AllowPedestrianCrossing); bool visible = GeometryUtil.WorldToScreenPoint(position, out Vector3 screenPos); if (!visible) { diff --git a/TLM/TLM/UI/SubTools/TTL/TimedTrafficLightsTool.cs b/TLM/TLM/UI/SubTools/TTL/TimedTrafficLightsTool.cs index f28388691..1443cf634 100644 --- a/TLM/TLM/UI/SubTools/TTL/TimedTrafficLightsTool.cs +++ b/TLM/TLM/UI/SubTools/TTL/TimedTrafficLightsTool.cs @@ -1498,7 +1498,7 @@ private void ShowGUI() { junctionRestrictionsManager.GetValueOrDefault( liveSegmentLights.SegmentId, liveSegmentLights.StartNode, - JunctionRestrictionsFlags.AllowPedestrianCrossing); + JunctionRestrictionFlags.AllowPedestrianCrossing); bool timedActive = timedNode.IsStarted(); if (!timedActive) { diff --git a/TLM/TLM/Util/PriorityRoad.cs b/TLM/TLM/Util/PriorityRoad.cs index 4de604241..df438fec6 100644 --- a/TLM/TLM/Util/PriorityRoad.cs +++ b/TLM/TLM/Util/PriorityRoad.cs @@ -412,9 +412,9 @@ private static ArrowDirection GetDirection(ushort segmentId, ushort otherSegment private static void FixMajorSegmentRules(ushort segmentId, ushort nodeId) { Log._Debug($"FixMajorSegmentRules({segmentId}, {nodeId}) was called"); bool startNode = segmentId.ToSegment().IsStartNode(nodeId); - JunctionRestrictionsManager.Instance.SetValue(segmentId, startNode, JunctionRestrictionsFlags.AllowEnterWhenBlocked, true); + JunctionRestrictionsManager.Instance.SetValue(segmentId, startNode, JunctionRestrictionFlags.AllowEnterWhenBlocked, true); if (!Options.PriorityRoad_CrossMainR) { - JunctionRestrictionsManager.Instance.SetValue(segmentId, startNode, JunctionRestrictionsFlags.AllowPedestrianCrossing, false); + JunctionRestrictionsManager.Instance.SetValue(segmentId, startNode, JunctionRestrictionFlags.AllowPedestrianCrossing, false); } TrafficPriorityManager.Instance.SetPrioritySign(segmentId, startNode, PriorityType.Main); } @@ -423,10 +423,10 @@ private static void FixMinorSegmentRules(ushort segmentId, ushort nodeId, List JunctionRestrictionsManager.Instance; public void Record() { - uturnAllowed_ = ToTernaryBool(JRMan.GetValueOrDefault(SegmentId, StartNode, JunctionRestrictionsFlags.AllowUTurn)); - nearTurnOnRedAllowed_ = ToTernaryBool(JRMan.GetValueOrDefault(SegmentId, StartNode, JunctionRestrictionsFlags.AllowNearTurnOnRed)); - farTurnOnRedAllowed_ = ToTernaryBool(JRMan.GetValueOrDefault(SegmentId, StartNode, JunctionRestrictionsFlags.AllowFarTurnOnRed)); - laneChangingAllowedWhenGoingStraight_ = ToTernaryBool(JRMan.GetValueOrDefault(SegmentId, StartNode, JunctionRestrictionsFlags.AllowForwardLaneChange)); - enteringBlockedJunctionAllowed_ = ToTernaryBool(JRMan.GetValueOrDefault(SegmentId, StartNode, JunctionRestrictionsFlags.AllowEnterWhenBlocked)); - pedestrianCrossingAllowed_ = ToTernaryBool(JRMan.GetValueOrDefault(SegmentId, StartNode, JunctionRestrictionsFlags.AllowPedestrianCrossing)); + uturnAllowed_ = ToTernaryBool(JRMan.GetValueOrDefault(SegmentId, StartNode, JunctionRestrictionFlags.AllowUTurn)); + nearTurnOnRedAllowed_ = ToTernaryBool(JRMan.GetValueOrDefault(SegmentId, StartNode, JunctionRestrictionFlags.AllowNearTurnOnRed)); + farTurnOnRedAllowed_ = ToTernaryBool(JRMan.GetValueOrDefault(SegmentId, StartNode, JunctionRestrictionFlags.AllowFarTurnOnRed)); + laneChangingAllowedWhenGoingStraight_ = ToTernaryBool(JRMan.GetValueOrDefault(SegmentId, StartNode, JunctionRestrictionFlags.AllowForwardLaneChange)); + enteringBlockedJunctionAllowed_ = ToTernaryBool(JRMan.GetValueOrDefault(SegmentId, StartNode, JunctionRestrictionFlags.AllowEnterWhenBlocked)); + pedestrianCrossingAllowed_ = ToTernaryBool(JRMan.GetValueOrDefault(SegmentId, StartNode, JunctionRestrictionFlags.AllowPedestrianCrossing)); prioirtySign_ = priorityMan.GetPrioritySign(SegmentId, StartNode); @@ -65,12 +65,12 @@ public void Restore() { } // all necessary checks are performed internally. - JRMan.SetValue(SegmentId, StartNode, JunctionRestrictionsFlags.AllowUTurn, ToOptBool(uturnAllowed_)); - JRMan.SetValue(SegmentId, StartNode, JunctionRestrictionsFlags.AllowNearTurnOnRed, ToOptBool(nearTurnOnRedAllowed_)); - JRMan.SetValue(SegmentId, StartNode, JunctionRestrictionsFlags.AllowFarTurnOnRed, ToOptBool(farTurnOnRedAllowed_)); - JRMan.SetValue(SegmentId, StartNode, JunctionRestrictionsFlags.AllowForwardLaneChange, ToOptBool(laneChangingAllowedWhenGoingStraight_)); - JRMan.SetValue(SegmentId, StartNode, JunctionRestrictionsFlags.AllowEnterWhenBlocked, ToOptBool(enteringBlockedJunctionAllowed_)); - JRMan.SetValue(SegmentId, StartNode, JunctionRestrictionsFlags.AllowPedestrianCrossing, ToOptBool(pedestrianCrossingAllowed_)); + JRMan.SetValue(SegmentId, StartNode, JunctionRestrictionFlags.AllowUTurn, ToOptBool(uturnAllowed_)); + JRMan.SetValue(SegmentId, StartNode, JunctionRestrictionFlags.AllowNearTurnOnRed, ToOptBool(nearTurnOnRedAllowed_)); + JRMan.SetValue(SegmentId, StartNode, JunctionRestrictionFlags.AllowFarTurnOnRed, ToOptBool(farTurnOnRedAllowed_)); + JRMan.SetValue(SegmentId, StartNode, JunctionRestrictionFlags.AllowForwardLaneChange, ToOptBool(laneChangingAllowedWhenGoingStraight_)); + JRMan.SetValue(SegmentId, StartNode, JunctionRestrictionFlags.AllowEnterWhenBlocked, ToOptBool(enteringBlockedJunctionAllowed_)); + JRMan.SetValue(SegmentId, StartNode, JunctionRestrictionFlags.AllowPedestrianCrossing, ToOptBool(pedestrianCrossingAllowed_)); } public void Transfer(Dictionary map) { @@ -84,12 +84,12 @@ public void Transfer(Dictionary map) { } // all necessary checks are performed internally. - JRMan.SetValue(segmentId, StartNode, JunctionRestrictionsFlags.AllowUTurn, ToOptBool(uturnAllowed_)); - JRMan.SetValue(segmentId, StartNode, JunctionRestrictionsFlags.AllowNearTurnOnRed, ToOptBool(nearTurnOnRedAllowed_)); - JRMan.SetValue(segmentId, StartNode, JunctionRestrictionsFlags.AllowFarTurnOnRed, ToOptBool(farTurnOnRedAllowed_)); - JRMan.SetValue(segmentId, StartNode, JunctionRestrictionsFlags.AllowForwardLaneChange, ToOptBool(laneChangingAllowedWhenGoingStraight_)); - JRMan.SetValue(segmentId, StartNode, JunctionRestrictionsFlags.AllowEnterWhenBlocked, ToOptBool(enteringBlockedJunctionAllowed_)); - JRMan.SetValue(segmentId, StartNode, JunctionRestrictionsFlags.AllowPedestrianCrossing, ToOptBool(pedestrianCrossingAllowed_)); + JRMan.SetValue(segmentId, StartNode, JunctionRestrictionFlags.AllowUTurn, ToOptBool(uturnAllowed_)); + JRMan.SetValue(segmentId, StartNode, JunctionRestrictionFlags.AllowNearTurnOnRed, ToOptBool(nearTurnOnRedAllowed_)); + JRMan.SetValue(segmentId, StartNode, JunctionRestrictionFlags.AllowFarTurnOnRed, ToOptBool(farTurnOnRedAllowed_)); + JRMan.SetValue(segmentId, StartNode, JunctionRestrictionFlags.AllowForwardLaneChange, ToOptBool(laneChangingAllowedWhenGoingStraight_)); + JRMan.SetValue(segmentId, StartNode, JunctionRestrictionFlags.AllowEnterWhenBlocked, ToOptBool(enteringBlockedJunctionAllowed_)); + JRMan.SetValue(segmentId, StartNode, JunctionRestrictionFlags.AllowPedestrianCrossing, ToOptBool(pedestrianCrossingAllowed_)); } public void Transfer(uint mappedId) { diff --git a/TLM/TLM/Util/RoundaboutMassEdit.cs b/TLM/TLM/Util/RoundaboutMassEdit.cs index 48350da95..6f15d14fb 100644 --- a/TLM/TLM/Util/RoundaboutMassEdit.cs +++ b/TLM/TLM/Util/RoundaboutMassEdit.cs @@ -125,13 +125,13 @@ private static void FixRulesRoundabout(ushort segmentId, bool startNode) { JunctionRestrictionsManager.Instance.SetValue( segmentId, startNode, - JunctionRestrictionsFlags.AllowPedestrianCrossing, + JunctionRestrictionFlags.AllowPedestrianCrossing, false); } JunctionRestrictionsManager.Instance.SetValue( segmentId, startNode, - JunctionRestrictionsFlags.AllowEnterWhenBlocked, + JunctionRestrictionFlags.AllowEnterWhenBlocked, true); } @@ -143,7 +143,7 @@ internal static void FixRulesMinor(ushort segmentId, ushort nodeId) { JunctionRestrictionsManager.Instance.SetValue( segmentId, startNode, - JunctionRestrictionsFlags.AllowPedestrianCrossing, + JunctionRestrictionFlags.AllowPedestrianCrossing, false); } if (Options.RoundAboutQuickFix_PrioritySigns) { @@ -155,14 +155,14 @@ internal static void FixRulesMinor(ushort segmentId, ushort nodeId) { if (isHighway) { //ignore highway rules: //TODO remove as part of issue #569 - JunctionRestrictionsManager.Instance.SetValue(segmentId, startNode, JunctionRestrictionsFlags.AllowForwardLaneChange, true); + JunctionRestrictionsManager.Instance.SetValue(segmentId, startNode, JunctionRestrictionFlags.AllowForwardLaneChange, true); } // endif if (Options.RoundAboutQuickFix_KeepClearYieldR) { JunctionRestrictionsManager.Instance.SetValue( segmentId, startNode, - JunctionRestrictionsFlags.AllowEnterWhenBlocked, + JunctionRestrictionFlags.AllowEnterWhenBlocked, false); } } diff --git a/TLM/TMPE.API/Hook/IJunctionRestrictionsHook.cs b/TLM/TMPE.API/Hook/IJunctionRestrictionsHook.cs index 49010e72f..359685468 100644 --- a/TLM/TMPE.API/Hook/IJunctionRestrictionsHook.cs +++ b/TLM/TMPE.API/Hook/IJunctionRestrictionsHook.cs @@ -23,14 +23,14 @@ public interface IJunctionRestrictionsHook { /// /// /// Specifies which flags to invalidate. - public void InvalidateFlags(ushort segmentId, bool startNode, JunctionRestrictionsFlags flags); + public void InvalidateFlags(ushort segmentId, bool startNode, JunctionRestrictionFlags flags); /// /// Schedles the specified flags for recalculation for all segment ends on the specified node. /// /// /// Specifies which flags to invalidate. - public void InvalidateFlags(ushort nodeId, JunctionRestrictionsFlags flags); + public void InvalidateFlags(ushort nodeId, JunctionRestrictionFlags flags); public class FlagsHookArgs { @@ -48,15 +48,15 @@ public class FlagsHookArgs { /// Identifies which flags are being returned. Unnecessary computation may be avoided /// by examining this mask to see which flags are being requested. ///
- public JunctionRestrictionsFlags Mask { get; private set; } + public JunctionRestrictionFlags Mask { get; private set; } /// /// The flag return values. Changes to this property alter the outcome of the underlying operation. /// Any flags that not set in the property are ignored. /// - public JunctionRestrictionsFlags Result { get; set; } + public JunctionRestrictionFlags Result { get; set; } - public FlagsHookArgs(ushort segmentId, bool startNode, JunctionRestrictionsFlags mask, JunctionRestrictionsFlags result) { + public FlagsHookArgs(ushort segmentId, bool startNode, JunctionRestrictionFlags mask, JunctionRestrictionFlags result) { SegmentId = segmentId; StartNode = startNode; Mask = mask; diff --git a/TLM/TMPE.API/Manager/IJunctionRestrictionsManager.cs b/TLM/TMPE.API/Manager/IJunctionRestrictionsManager.cs index 55f8c2b3d..6336e5db2 100644 --- a/TLM/TMPE.API/Manager/IJunctionRestrictionsManager.cs +++ b/TLM/TMPE.API/Manager/IJunctionRestrictionsManager.cs @@ -13,7 +13,7 @@ public interface IJunctionRestrictionsManager { /// /// /// - bool IsConfigurable(ushort segmentId, bool startNode, JunctionRestrictionsFlags flags); + bool IsConfigurable(ushort segmentId, bool startNode, JunctionRestrictionFlags flags); /// /// Returns the set value (not the default) for the specified flag, or null if no value has been set. @@ -23,7 +23,7 @@ public interface IJunctionRestrictionsManager { /// /// /// - bool? GetValue(ushort segmentId, bool startNode, JunctionRestrictionsFlags flags); + bool? GetValue(ushort segmentId, bool startNode, JunctionRestrictionFlags flags); /// /// Returns the set value of the specified flag, or the default value if no value is set. @@ -33,7 +33,7 @@ public interface IJunctionRestrictionsManager { /// /// /// - bool GetValueOrDefault(ushort segmentId, bool startNode, JunctionRestrictionsFlags flags); + bool GetValueOrDefault(ushort segmentId, bool startNode, JunctionRestrictionFlags flags); /// /// Returns the default value for the specified flag. @@ -43,7 +43,7 @@ public interface IJunctionRestrictionsManager { /// /// /// - bool GetDefaultValue(ushort segmentId, bool startNode, JunctionRestrictionsFlags flags); + bool GetDefaultValue(ushort segmentId, bool startNode, JunctionRestrictionFlags flags); /// /// Sets the value of the specified flag(s). If null, clears the set value so that the default will be used. @@ -53,7 +53,7 @@ public interface IJunctionRestrictionsManager { /// /// /// true if the operation was successful, false if not configurable - bool SetValue(ushort segmentId, bool startNode, JunctionRestrictionsFlags flags, bool? value); + bool SetValue(ushort segmentId, bool startNode, JunctionRestrictionFlags flags, bool? value); /// /// Toggles the value of the specified flag. This method fails if more than one flag is specified. @@ -62,12 +62,12 @@ public interface IJunctionRestrictionsManager { /// /// /// true if the operation was successful, false if not configurable or if more than one flag was specified - bool ToggleValue(ushort segmentId, bool startNode, JunctionRestrictionsFlags flags); + bool ToggleValue(ushort segmentId, bool startNode, JunctionRestrictionFlags flags); #region IsConfigurable /// - /// This API is dprecated. Please use .
+ /// This API is dprecated. Please use .
/// Determines if u-turn behavior may be controlled at the given segment end. ///
/// segment id @@ -78,7 +78,7 @@ public interface IJunctionRestrictionsManager { bool IsUturnAllowedConfigurable(ushort segmentId, bool startNode, ref NetNode node); /// - /// This API is dprecated. Please use .
+ /// This API is dprecated. Please use .
/// Determines if turn-on-red behavior is enabled for near turns and may be controlled at /// the given segment end. ///
@@ -91,7 +91,7 @@ public interface IJunctionRestrictionsManager { bool IsNearTurnOnRedAllowedConfigurable(ushort segmentId, bool startNode, ref NetNode node); /// - /// This API is dprecated. Please use .
+ /// This API is dprecated. Please use .
/// Determines if turn-on-red behavior is enabled for far turns and may be controlled at /// the given segment end. ///
@@ -104,7 +104,7 @@ public interface IJunctionRestrictionsManager { bool IsFarTurnOnRedAllowedConfigurable(ushort segmentId, bool startNode, ref NetNode node); /// - /// This API is dprecated. Please use .
+ /// This API is dprecated. Please use .
/// Determines if turn-on-red behavior is enabled for the given turn type and that it may /// be controlled at the given segment end. ///
@@ -120,7 +120,7 @@ bool IsTurnOnRedAllowedConfigurable(bool near, ref NetNode node); /// - /// This API is dprecated. Please use .
+ /// This API is dprecated. Please use .
/// Determines if lane changing behavior may be controlled at the given segment end. ///
/// segment id @@ -134,7 +134,7 @@ bool IsLaneChangingAllowedWhenGoingStraightConfigurable( ref NetNode node); /// - /// This API is dprecated. Please use .
+ /// This API is dprecated. Please use .
/// Determines if entering blocked junctions may be controlled at the given segment end. ///
/// segment id @@ -148,7 +148,7 @@ bool IsEnteringBlockedJunctionAllowedConfigurable(ushort segmentId, ref NetNode node); /// - /// This API is dprecated. Please use .
+ /// This API is dprecated. Please use .
/// Determines if pedestrian crossings may be controlled at the given segment end. ///
/// segment id @@ -165,7 +165,7 @@ bool IsPedestrianCrossingAllowedConfigurable(ushort segmentId, #region GetDefault /// - /// This API is dprecated. Please use .
+ /// This API is dprecated. Please use .
/// Determines the default setting for u-turns at the given segment end. ///
/// segment id @@ -177,7 +177,7 @@ bool IsPedestrianCrossingAllowedConfigurable(ushort segmentId, bool GetDefaultUturnAllowed(ushort segmentId, bool startNode, ref NetNode node); /// - /// This API is dprecated. Please use .
+ /// This API is dprecated. Please use .
/// Determines the default setting for near turn-on-red at the given segment end. ///
/// segment id @@ -189,7 +189,7 @@ bool IsPedestrianCrossingAllowedConfigurable(ushort segmentId, bool GetDefaultNearTurnOnRedAllowed(ushort segmentId, bool startNode, ref NetNode node); /// - /// This API is dprecated. Please use .
+ /// This API is dprecated. Please use .
/// Determines the default setting for far turn-on-red at the given segment end. ///
/// segment id @@ -201,7 +201,7 @@ bool IsPedestrianCrossingAllowedConfigurable(ushort segmentId, bool GetDefaultFarTurnOnRedAllowed(ushort segmentId, bool startNode, ref NetNode node); /// - /// This API is dprecated. Please use .
+ /// This API is dprecated. Please use .
/// Determines the default turn-on-red setting for the given turn type at the given segment end. ///
/// for near turns? @@ -217,7 +217,7 @@ bool GetDefaultTurnOnRedAllowed(bool near, ref NetNode node); /// - /// This API is dprecated. Please use .
+ /// This API is dprecated. Please use .
/// Determines the default setting for straight lane changes at the given segment end. ///
/// segment id @@ -232,7 +232,7 @@ bool GetDefaultLaneChangingAllowedWhenGoingStraight( ref NetNode node); /// - /// This API is dprecated. Please use .
+ /// This API is dprecated. Please use .
/// Determines the default setting for entering a blocked junction at the given segment end. ///
/// segment id @@ -246,7 +246,7 @@ bool GetDefaultEnteringBlockedJunctionAllowed(ushort segmentId, ref NetNode node); /// - /// This API is dprecated. Please use .
+ /// This API is dprecated. Please use .
/// Determines the default setting for pedestrian crossings at the given segment end. ///
/// segment id @@ -264,7 +264,7 @@ bool GetDefaultPedestrianCrossingAllowed(ushort segmentId, #region IsAllowed /// - /// This API is dprecated. Please use .
+ /// This API is dprecated. Please use .
/// Determines whether u-turns are allowed at the given segment end. ///
/// segment id @@ -275,7 +275,7 @@ bool GetDefaultPedestrianCrossingAllowed(ushort segmentId, bool IsUturnAllowed(ushort segmentId, bool startNode); /// - /// This API is dprecated. Please use .
+ /// This API is dprecated. Please use .
/// Determines whether turn-on-red is allowed for near turns at the given segment end. ///
/// segment id @@ -286,7 +286,7 @@ bool GetDefaultPedestrianCrossingAllowed(ushort segmentId, bool IsNearTurnOnRedAllowed(ushort segmentId, bool startNode); /// - /// This API is dprecated. Please use .
+ /// This API is dprecated. Please use .
/// Determines whether turn-on-red is allowed for far turns at the given segment end. ///
/// segment id @@ -297,7 +297,7 @@ bool GetDefaultPedestrianCrossingAllowed(ushort segmentId, bool IsFarTurnOnRedAllowed(ushort segmentId, bool startNode); /// - /// This API is dprecated. Please use .
+ /// This API is dprecated. Please use .
/// Determines whether turn-on-red is allowed for the given turn type at the given segment end. ///
/// for near turns? @@ -309,7 +309,7 @@ bool GetDefaultPedestrianCrossingAllowed(ushort segmentId, bool IsTurnOnRedAllowed(bool near, ushort segmentId, bool startNode); /// - /// This API is dprecated. Please use .
+ /// This API is dprecated. Please use .
/// Determines whether lane changing when going straight is allowed at the given segment end. ///
/// segment id @@ -320,7 +320,7 @@ bool GetDefaultPedestrianCrossingAllowed(ushort segmentId, bool IsLaneChangingAllowedWhenGoingStraight(ushort segmentId, bool startNode); /// - /// This API is dprecated. Please use .
+ /// This API is dprecated. Please use .
/// Determines whether entering a blocked junction is allowed at the given segment end. ///
/// segment id @@ -331,7 +331,7 @@ bool GetDefaultPedestrianCrossingAllowed(ushort segmentId, bool IsEnteringBlockedJunctionAllowed(ushort segmentId, bool startNode); /// - /// This API is dprecated. Please use .
+ /// This API is dprecated. Please use .
/// Determines whether crossing the road is allowed at the given segment end. ///
/// segment id @@ -345,7 +345,7 @@ bool GetDefaultPedestrianCrossingAllowed(ushort segmentId, #region Get /// - /// This API is dprecated. Please use .
+ /// This API is dprecated. Please use .
/// Retrieves the u-turn setting for the given segment end. ///
/// segment id @@ -356,7 +356,7 @@ bool GetDefaultPedestrianCrossingAllowed(ushort segmentId, TernaryBool GetUturnAllowed(ushort segmentId, bool startNode); /// - /// This API is dprecated. Please use .
+ /// This API is dprecated. Please use .
/// Retrieves the turn-on-red setting for near turns and the given segment end. ///
/// segment id @@ -367,7 +367,7 @@ bool GetDefaultPedestrianCrossingAllowed(ushort segmentId, TernaryBool GetNearTurnOnRedAllowed(ushort segmentId, bool startNode); /// - /// This API is dprecated. Please use .
+ /// This API is dprecated. Please use .
/// Retrieves the turn-on-red setting for far turns and the given segment end. ///
/// segment id @@ -378,7 +378,7 @@ bool GetDefaultPedestrianCrossingAllowed(ushort segmentId, TernaryBool GetFarTurnOnRedAllowed(ushort segmentId, bool startNode); /// - /// This API is dprecated. Please use .
+ /// This API is dprecated. Please use .
/// Retrieves the turn-on-red setting for the given turn type and segment end. ///
/// for near turns? @@ -390,7 +390,7 @@ bool GetDefaultPedestrianCrossingAllowed(ushort segmentId, TernaryBool GetTurnOnRedAllowed(bool near, ushort segmentId, bool startNode); /// - /// This API is dprecated. Please use .
+ /// This API is dprecated. Please use .
/// Retrieves the lane changing setting for the given segment end. ///
/// segment id @@ -401,7 +401,7 @@ bool GetDefaultPedestrianCrossingAllowed(ushort segmentId, TernaryBool GetLaneChangingAllowedWhenGoingStraight(ushort segmentId, bool startNode); /// - /// This API is dprecated. Please use .
+ /// This API is dprecated. Please use .
/// Retrieves the "enter blocked junction" setting for the given segment end. ///
/// segment id @@ -412,7 +412,7 @@ bool GetDefaultPedestrianCrossingAllowed(ushort segmentId, TernaryBool GetEnteringBlockedJunctionAllowed(ushort segmentId, bool startNode); /// - /// This API is dprecated. Please use .
+ /// This API is dprecated. Please use .
/// Retrieves the pedestrian crossing setting for the given segment end. ///
/// segment id @@ -426,7 +426,7 @@ bool GetDefaultPedestrianCrossingAllowed(ushort segmentId, #region Toggle /// - /// This API is dprecated. Please use .
+ /// This API is dprecated. Please use .
/// Switches the u-turn flag for the given segment end. ///
/// segment id @@ -439,7 +439,7 @@ bool GetDefaultPedestrianCrossingAllowed(ushort segmentId, bool ToggleUturnAllowed(ushort segmentId, bool startNode); /// - /// This API is dprecated. Please use .
+ /// This API is dprecated. Please use .
/// Switches the turn-on-red flag for near turns and given segment end. ///
/// segment id @@ -452,7 +452,7 @@ bool GetDefaultPedestrianCrossingAllowed(ushort segmentId, bool ToggleNearTurnOnRedAllowed(ushort segmentId, bool startNode); /// - /// This API is dprecated. Please use .
+ /// This API is dprecated. Please use .
/// Switches the turn-on-red flag for far turns and given segment end. ///
/// segment id @@ -465,7 +465,7 @@ bool GetDefaultPedestrianCrossingAllowed(ushort segmentId, bool ToggleFarTurnOnRedAllowed(ushort segmentId, bool startNode); /// - /// This API is dprecated. Please use .
+ /// This API is dprecated. Please use .
/// Switches the turn-on-red flag for the given turn type and segment end. ///
/// for near turns? @@ -479,7 +479,7 @@ bool GetDefaultPedestrianCrossingAllowed(ushort segmentId, bool ToggleTurnOnRedAllowed(bool near, ushort segmentId, bool startNode); /// - /// This API is dprecated. Please use .
+ /// This API is dprecated. Please use .
/// Switches the lane changing flag for the given segment end. ///
/// segment id @@ -492,7 +492,7 @@ bool GetDefaultPedestrianCrossingAllowed(ushort segmentId, bool ToggleLaneChangingAllowedWhenGoingStraight(ushort segmentId, bool startNode); /// - /// This API is dprecated. Please use .
+ /// This API is dprecated. Please use .
/// Switches the "enter blocked junction" flag for the given segment end. ///
/// segment id @@ -505,7 +505,7 @@ bool GetDefaultPedestrianCrossingAllowed(ushort segmentId, bool ToggleEnteringBlockedJunctionAllowed(ushort segmentId, bool startNode); /// - /// This API is dprecated. Please use .
+ /// This API is dprecated. Please use .
/// Switches the pedestrian crossing flag for the given segment end. ///
/// segment id @@ -521,7 +521,7 @@ bool GetDefaultPedestrianCrossingAllowed(ushort segmentId, #region Set : bool /// - /// This API is dprecated. Please use .
+ /// This API is dprecated. Please use .
/// Sets the u-turn flag for the given segment end to the given value. ///
/// segment id @@ -535,7 +535,7 @@ bool GetDefaultPedestrianCrossingAllowed(ushort segmentId, bool SetUturnAllowed(ushort segmentId, bool startNode, bool value); /// - /// This API is dprecated. Please use .
+ /// This API is dprecated. Please use .
/// Sets the turn-on-red flag for near turns at the given segment end to the given value. ///
/// segment id @@ -549,7 +549,7 @@ bool GetDefaultPedestrianCrossingAllowed(ushort segmentId, bool SetNearTurnOnRedAllowed(ushort segmentId, bool startNode, bool value); /// - /// This API is dprecated. Please use .
+ /// This API is dprecated. Please use .
/// Sets the turn-on-red flag for far turns at the given segment end to the given value. ///
/// segment id @@ -563,7 +563,7 @@ bool GetDefaultPedestrianCrossingAllowed(ushort segmentId, bool SetFarTurnOnRedAllowed(ushort segmentId, bool startNode, bool value); /// - /// This API is dprecated. Please use .
+ /// This API is dprecated. Please use .
/// Sets the turn-on-red flag for the given turn type and segment end to the given value. ///
/// for near turns? @@ -578,7 +578,7 @@ bool GetDefaultPedestrianCrossingAllowed(ushort segmentId, bool SetTurnOnRedAllowed(bool near, ushort segmentId, bool startNode, bool value); /// - /// This API is dprecated. Please use .
+ /// This API is dprecated. Please use .
/// Sets the lane changing flag for the given segment end to the given value. ///
/// segment id @@ -592,7 +592,7 @@ bool GetDefaultPedestrianCrossingAllowed(ushort segmentId, bool SetLaneChangingAllowedWhenGoingStraight(ushort segmentId, bool startNode, bool value); /// - /// This API is dprecated. Please use .
+ /// This API is dprecated. Please use .
/// Sets the "enter blocked junction" flag for the given segment end to the given value. ///
/// segment id @@ -606,7 +606,7 @@ bool GetDefaultPedestrianCrossingAllowed(ushort segmentId, bool SetEnteringBlockedJunctionAllowed(ushort segmentId, bool startNode, bool value); /// - /// This API is dprecated. Please use .
+ /// This API is dprecated. Please use .
/// Sets the pedestrian crossing flag for the given segment end to the given value. ///
/// segment id @@ -623,7 +623,7 @@ bool GetDefaultPedestrianCrossingAllowed(ushort segmentId, #region Set : TernaryBool /// - /// This API is dprecated. Please use .
+ /// This API is dprecated. Please use .
/// Sets the u-turn flag for the given segment end to the given value. ///
/// segment id @@ -637,7 +637,7 @@ bool GetDefaultPedestrianCrossingAllowed(ushort segmentId, bool SetUturnAllowed(ushort segmentId, bool startNode, TernaryBool value); /// - /// This API is dprecated. Please use .
+ /// This API is dprecated. Please use .
/// Sets the turn-on-red flag for near turns at the given segment end to the given value. ///
/// segment id @@ -651,7 +651,7 @@ bool GetDefaultPedestrianCrossingAllowed(ushort segmentId, bool SetNearTurnOnRedAllowed(ushort segmentId, bool startNode, TernaryBool value); /// - /// This API is dprecated. Please use .
+ /// This API is dprecated. Please use .
/// Sets the turn-on-red flag for far turns at the given segment end to the given value. ///
/// segment id @@ -665,7 +665,7 @@ bool GetDefaultPedestrianCrossingAllowed(ushort segmentId, bool SetFarTurnOnRedAllowed(ushort segmentId, bool startNode, TernaryBool value); /// - /// This API is dprecated. Please use .
+ /// This API is dprecated. Please use .
/// Sets the turn-on-red flag for the given turn type and segment end to the given value. ///
/// for near turns? @@ -680,7 +680,7 @@ bool GetDefaultPedestrianCrossingAllowed(ushort segmentId, bool SetTurnOnRedAllowed(bool near, ushort segmentId, bool startNode, TernaryBool value); /// - /// This API is dprecated. Please use .
+ /// This API is dprecated. Please use .
/// Sets the lane changing flag for the given segment end to the given value. ///
/// segment id @@ -694,7 +694,7 @@ bool GetDefaultPedestrianCrossingAllowed(ushort segmentId, bool SetLaneChangingAllowedWhenGoingStraight(ushort segmentId, bool startNode, TernaryBool value); /// - /// This API is dprecated. Please use .
+ /// This API is dprecated. Please use .
/// Sets the "enter blocked junction" flag for the given segment end to the given value. ///
/// segment id @@ -708,7 +708,7 @@ bool GetDefaultPedestrianCrossingAllowed(ushort segmentId, bool SetEnteringBlockedJunctionAllowed(ushort segmentId, bool startNode, TernaryBool value); /// - /// This API is dprecated. Please use .
+ /// This API is dprecated. Please use .
/// Sets the pedestrian crossing flag for the given segment end to the given value. ///
/// segment id diff --git a/TLM/TMPE.API/TMPE.API.csproj b/TLM/TMPE.API/TMPE.API.csproj index 0958510b5..8bcb9f16d 100644 --- a/TLM/TMPE.API/TMPE.API.csproj +++ b/TLM/TMPE.API/TMPE.API.csproj @@ -147,7 +147,6 @@ - diff --git a/TLM/TMPE.API/Traffic/Enums/JunctionRestrictionFlags.cs b/TLM/TMPE.API/Traffic/Enums/JunctionRestrictionFlags.cs index ba8c86698..3a4059e5b 100644 --- a/TLM/TMPE.API/Traffic/Enums/JunctionRestrictionFlags.cs +++ b/TLM/TMPE.API/Traffic/Enums/JunctionRestrictionFlags.cs @@ -1,4 +1,8 @@ +using System; + namespace TrafficManager.API.Traffic.Enums { + + [Flags] public enum JunctionRestrictionFlags { AllowUTurn = 1 << 0, AllowNearTurnOnRed = 1 << 1, @@ -6,5 +10,7 @@ public enum JunctionRestrictionFlags { AllowForwardLaneChange = 1 << 3, AllowEnterWhenBlocked = 1 << 4, AllowPedestrianCrossing = 1 << 5, + + All = (1 << 6) - 1, } -} \ No newline at end of file +} diff --git a/TLM/TMPE.API/Traffic/Enums/JunctionRestrictionsFlags.cs b/TLM/TMPE.API/Traffic/Enums/JunctionRestrictionsFlags.cs deleted file mode 100644 index 4407edd55..000000000 --- a/TLM/TMPE.API/Traffic/Enums/JunctionRestrictionsFlags.cs +++ /dev/null @@ -1,16 +0,0 @@ -using System; - -namespace TrafficManager.API.Traffic.Enums { - - [Flags] - public enum JunctionRestrictionsFlags { - AllowUTurn = 1 << 0, - AllowNearTurnOnRed = 1 << 1, - AllowFarTurnOnRed = 1 << 2, - AllowForwardLaneChange = 1 << 3, - AllowEnterWhenBlocked = 1 << 4, - AllowPedestrianCrossing = 1 << 5, - - All = (1 << 6) - 1, - } -}