예제 #1
0
        /// <summary>
        /// Destroys the traffic light and removes it
        /// </summary>
        /// <param name="nodeId"></param>
        /// <param name="destroyGroup"></param>
        public void RemoveNodeFromSimulation(ushort nodeId, bool destroyGroup, bool removeTrafficLight)
        {
            if (!TrafficLightSimulations.ContainsKey(nodeId))
            {
                return;
            }

            TrafficLightSimulation sim = TrafficLightSimulations[nodeId];

            if (sim.TimedLight != null)
            {
                // remove/destroy other timed traffic lights in group
                List <ushort> oldNodeGroup = new List <ushort>(sim.TimedLight.NodeGroup);
                foreach (var timedNodeId in oldNodeGroup)
                {
                    var otherNodeSim = GetNodeSimulation(timedNodeId);
                    if (otherNodeSim == null)
                    {
                        continue;
                    }

                    if (destroyGroup || timedNodeId == nodeId)
                    {
                        //Log._Debug($"Slave: Removing simulation @ node {timedNodeId}");
                        otherNodeSim.DestroyTimedTrafficLight();
                        otherNodeSim.DestroyManualTrafficLight();
                        otherNodeSim.NodeGeoUnsubscriber?.Dispose();
                        TrafficLightSimulations.Remove(timedNodeId);
                        if (removeTrafficLight)
                        {
                            Flags.setNodeTrafficLight(timedNodeId, false);
                        }
                    }
                    else
                    {
                        otherNodeSim.TimedLight.RemoveNodeFromGroup(nodeId);
                    }
                }
            }

            //Flags.setNodeTrafficLight(nodeId, false);
            sim.DestroyTimedTrafficLight();
            sim.DestroyManualTrafficLight();
            sim.NodeGeoUnsubscriber?.Dispose();
            TrafficLightSimulations.Remove(nodeId);
            if (removeTrafficLight)
            {
                Flags.setNodeTrafficLight(nodeId, false);
            }
        }