@@ -6,9 +6,10 @@ namespace TrafficManager.Util.Record {
66 using TrafficManager . API . Traffic . Enums ;
77 using TrafficManager . Manager . Impl ;
88 using TrafficManager . State ;
9+ using TrafficManager . Util . Extensions ;
910
1011 [ Serializable ]
11- class SegmentEndRecord : IRecordable {
12+ public class SegmentEndRecord : IRecordable {
1213 public SegmentEndRecord ( int segmentEndIndex ) {
1314 SegmentEndManager . Instance .
1415 GetSegmentAndNodeFromIndex ( segmentEndIndex , out ushort segmentId , out bool startNode ) ;
@@ -23,7 +24,7 @@ public SegmentEndRecord(ushort segmentId, bool startNode) {
2324
2425 public ushort SegmentId { get ; private set ; }
2526 public bool StartNode { get ; private set ; }
26- InstanceID InstanceID => new InstanceID { NetSegment = SegmentId } ;
27+ private InstanceID InstanceID => new InstanceID { NetSegment = SegmentId } ;
2728
2829 private TernaryBool uturnAllowed_ ;
2930 private TernaryBool nearTurnOnRedAllowed_ ;
@@ -38,6 +39,18 @@ public SegmentEndRecord(ushort segmentId, bool startNode) {
3839 private static TrafficPriorityManager priorityMan => TrafficPriorityManager . Instance ;
3940 private static JunctionRestrictionsManager JRMan => JunctionRestrictionsManager . Instance ;
4041
42+ public bool IsDefault ( ) {
43+ return
44+ uturnAllowed_ == TernaryBool . Undefined &&
45+ nearTurnOnRedAllowed_ == TernaryBool . Undefined &&
46+ farTurnOnRedAllowed_ == TernaryBool . Undefined &&
47+ laneChangingAllowedWhenGoingStraight_ == TernaryBool . Undefined &&
48+ enteringBlockedJunctionAllowed_ == TernaryBool . Undefined &&
49+ pedestrianCrossingAllowed_ == TernaryBool . Undefined &&
50+ prioirtySign_ == PriorityType . None &&
51+ arrowLanes_ . AreDefault ( ) ;
52+ }
53+
4154 public void Record ( ) {
4255 uturnAllowed_ = JRMan . GetUturnAllowed ( SegmentId , StartNode ) ;
4356 nearTurnOnRedAllowed_ = JRMan . GetNearTurnOnRedAllowed ( SegmentId , StartNode ) ;
@@ -49,13 +62,13 @@ public void Record() {
4962 prioirtySign_ = priorityMan . GetPrioritySign ( SegmentId , StartNode ) ;
5063
5164 arrowLanes_ = LaneArrowsRecord . GetLanes ( SegmentId , StartNode ) ;
52- foreach ( IRecordable lane in arrowLanes_ )
53- lane . Record ( ) ;
65+ foreach ( IRecordable lane in arrowLanes_ . EmptyIfNull ( ) )
66+ lane ? . Record ( ) ;
5467 }
5568
5669 public void Restore ( ) {
57- foreach ( IRecordable lane in arrowLanes_ )
58- lane . Restore ( ) ;
70+ foreach ( IRecordable lane in arrowLanes_ . EmptyIfNull ( ) )
71+ lane ? . Restore ( ) ;
5972
6073 if ( priorityMan . MaySegmentHavePrioritySign ( SegmentId , StartNode ) &&
6174 prioirtySign_ != priorityMan . GetPrioritySign ( SegmentId , StartNode ) ) {
@@ -74,8 +87,8 @@ public void Restore() {
7487
7588 public void Transfer ( Dictionary < InstanceID , InstanceID > map ) {
7689 ushort segmentId = map [ InstanceID ] . NetSegment ;
77- foreach ( IRecordable lane in arrowLanes_ )
78- lane . Transfer ( map ) ;
90+ foreach ( IRecordable lane in arrowLanes_ . EmptyIfNull ( ) )
91+ lane ? . Transfer ( map ) ;
7992
8093 if ( priorityMan . MaySegmentHavePrioritySign ( segmentId , StartNode ) &&
8194 prioirtySign_ != priorityMan . GetPrioritySign ( segmentId , StartNode ) ) {
@@ -95,8 +108,9 @@ public void Transfer(uint mappedId) {
95108 ushort segmentId = ( ushort ) mappedId ;
96109
97110 var mappedLanes = SpeedLimitLaneRecord . GetLanes ( segmentId ) ;
98- for ( int i = 0 ; i == arrowLanes_ . Count ; ++ i ) {
99- arrowLanes_ [ i ] . Transfer ( mappedLanes [ i ] . LaneId ) ;
111+ int n = arrowLanes_ ? . Count ?? 0 ;
112+ for ( int i = 0 ; i == n ; ++ i ) {
113+ arrowLanes_ [ i ] ? . Transfer ( mappedLanes [ i ] . LaneId ) ;
100114 }
101115 }
102116
0 commit comments