Esempio n. 1
0
        private static void Cleanup(ushort segmentId)
        {
#if TRACE
            Singleton <CodeProfiler> .instance.Start("CustomTrafficLights.Cleanup");
#endif
            CustomSegment customSegment = CustomSegments[segmentId];
            if (customSegment == null)
            {
#if TRACE
                Singleton <CodeProfiler> .instance.Stop("CustomTrafficLights.Cleanup");
#endif
                return;
            }

            NetManager netManager = Singleton <NetManager> .instance;
            if (customSegment.Node1 != 0 && (netManager.m_nodes.m_buffer[customSegment.Node1].m_flags & (NetNode.Flags.Created | NetNode.Flags.Deleted)) != NetNode.Flags.Created)
            {
                customSegment.Node1       = 0;
                customSegment.Node1Lights = null;
            }

            if (customSegment.Node2 != 0 && (netManager.m_nodes.m_buffer[customSegment.Node2].m_flags & (NetNode.Flags.Created | NetNode.Flags.Deleted)) != NetNode.Flags.Created)
            {
                customSegment.Node2       = 0;
                customSegment.Node2Lights = null;
            }

            if (customSegment.Node1 == 0 && customSegment.Node2 == 0)
            {
                CustomSegments[segmentId] = null;
            }
#if TRACE
            Singleton <CodeProfiler> .instance.Stop("CustomTrafficLights.Cleanup");
#endif
        }
Esempio n. 2
0
        public static bool IsSegmentLight(ushort nodeId, ushort segmentId)
        {
#if TRACE
            Singleton <CodeProfiler> .instance.Start("CustomTrafficLights.IsSegmentLight");
#endif
            CustomSegment customSegment = CustomSegments[segmentId];
            if (customSegment == null)
            {
#if TRACE
                Singleton <CodeProfiler> .instance.Stop("CustomTrafficLights.IsSegmentLight");
#endif
                return(false);
            }

            if (customSegment.Node1 == nodeId || customSegment.Node2 == nodeId)
            {
#if TRACE
                Singleton <CodeProfiler> .instance.Stop("CustomTrafficLights.IsSegmentLight");
#endif
                return(true);
            }

#if TRACE
            Singleton <CodeProfiler> .instance.Stop("CustomTrafficLights.IsSegmentLight");
#endif
            return(false);
        }
Esempio n. 3
0
        public static void RemoveSegmentLight(ushort nodeId, ushort segmentId)
        {
#if TRACE
            Singleton <CodeProfiler> .instance.Start("CustomTrafficLights.RemoveSegmentLight");
#endif
#if DEBUG
            Log.Warning($"Removing segment light: {segmentId} @ {nodeId}");
#endif

            CustomSegment customSegment = CustomSegments[segmentId];
            if (customSegment == null)
            {
#if TRACE
                Singleton <CodeProfiler> .instance.Stop("CustomTrafficLights.RemoveSegmentLight");
#endif
                return;
            }

            if (customSegment.Node1 == nodeId)
            {
                customSegment.Node1       = 0;
                customSegment.Node1Lights = null;
            }
            else if (customSegment.Node2 == nodeId)
            {
                customSegment.Node2       = 0;
                customSegment.Node2Lights = null;
            }

            Cleanup(segmentId);
#if TRACE
            Singleton <CodeProfiler> .instance.Stop("CustomTrafficLights.RemoveSegmentLight");
#endif
        }
Esempio n. 4
0
        public static void AddSegmentLights(ushort nodeId, ushort segmentId, RoadBaseAI.TrafficLightState light = RoadBaseAI.TrafficLightState.Red)
        {
#if TRACE
            Singleton <CodeProfiler> .instance.Start("CustomTrafficLights.AddSegmentLights");
#endif
#if DEBUG
            Log._Debug($"CustomTrafficLights.AddSegmentLights: Adding segment light: {segmentId} @ {nodeId}");
#endif
            Cleanup(segmentId);

            CustomSegment customSegment = CustomSegments[segmentId];
            if (customSegment != null)
            {
                if (customSegment.Node1 == nodeId || customSegment.Node2 == nodeId)
                {
#if TRACE
                    Singleton <CodeProfiler> .instance.Stop("CustomTrafficLights.AddSegmentLights");
#endif
                    return;
                }

#if DEBUG
                Log._Debug($"CustomTrafficLights.AddSegmentLights: Adding segment light: {segmentId} @ {nodeId} -- Node1={CustomSegments[segmentId].Node1} Node2={CustomSegments[segmentId].Node2}");
#endif

                if (customSegment.Node1 == 0)
                {
                    customSegment.Node1Lights = new CustomSegmentLights(nodeId, segmentId, light);
                    customSegment.Node1       = nodeId;
                }
                else
                {
                    customSegment.Node2Lights = new CustomSegmentLights(nodeId, segmentId, light);
                    customSegment.Node2       = nodeId;
                }
            }
            else
            {
                customSegment             = new CustomSegment();
                customSegment.Node1Lights = new CustomSegmentLights(nodeId, segmentId, light);
                customSegment.Node1       = nodeId;
                CustomSegments[segmentId] = customSegment;
            }
#if TRACE
            Singleton <CodeProfiler> .instance.Stop("CustomTrafficLights.AddSegmentLights");
#endif
        }
Esempio n. 5
0
        public static CustomSegmentLights GetSegmentLights(ushort nodeId, ushort segmentId)
        {
#if TRACE
            Singleton <CodeProfiler> .instance.Start("CustomTrafficLights.GetSegmentLights");
#endif
            CustomSegment customSegment = CustomSegments[segmentId];
            if (customSegment == null)
            {
#if TRACE
                Singleton <CodeProfiler> .instance.Stop("CustomTrafficLights.GetSegmentLights");
#endif
                return(null);
            }

            //Log.Message($"Get segment light: {segmentId} @ {nodeId}");

            if (customSegment.Node1 == nodeId)
            {
#if TRACE
                Singleton <CodeProfiler> .instance.Stop("CustomTrafficLights.GetSegmentLights");
#endif
                return(customSegment.Node1Lights);
            }
            if (customSegment.Node2 == nodeId)
            {
#if TRACE
                Singleton <CodeProfiler> .instance.Stop("CustomTrafficLights.GetSegmentLights");
#endif
                return(customSegment.Node2Lights);
            }

#if TRACE
            Singleton <CodeProfiler> .instance.Stop("CustomTrafficLights.GetSegmentLights");
#endif
            return(null);
        }