/// <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 DEBUG Log.Warning($"TrafficLightSimulationManager.RemoveNodeFromSimulation({nodeId}, {destroyGroup}, {removeTrafficLight}) called."); #endif TrafficLightSimulation sim = TrafficLightSimulations[nodeId]; if (sim == null) { return; } TrafficLightManager tlm = TrafficLightManager.Instance; if (sim.TimedLight != null) { // remove/destroy all 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(); ((TrafficLightSimulation)otherNodeSim).NodeGeoUnsubscriber?.Dispose(); RemoveNodeFromSimulation(timedNodeId); if (removeTrafficLight) { Constants.ServiceFactory.NetService.ProcessNode(timedNodeId, delegate(ushort nId, ref NetNode node) { tlm.RemoveTrafficLight(timedNodeId, ref node); return(true); }); } } else { otherNodeSim.TimedLight.RemoveNodeFromGroup(nodeId); } } } //Flags.setNodeTrafficLight(nodeId, false); //sim.DestroyTimedTrafficLight(); sim.DestroyManualTrafficLight(); sim.NodeGeoUnsubscriber?.Dispose(); RemoveNodeFromSimulation(nodeId); if (removeTrafficLight) { Constants.ServiceFactory.NetService.ProcessNode(nodeId, delegate(ushort nId, ref NetNode node) { tlm.RemoveTrafficLight(nodeId, ref node); return(true); }); } }
/// <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 (!HasSimulation(nodeId)) { return; } TrafficLightSimulation sim = TrafficLightSimulations[nodeId]; TrafficLightManager tlm = TrafficLightManager.Instance; if (sim.TimedLight != null) { // remove/destroy all 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(); RemoveNodeFromSimulation(timedNodeId); if (removeTrafficLight) { tlm.RemoveTrafficLight(timedNodeId); } } else { otherNodeSim.TimedLight.RemoveNodeFromGroup(nodeId); } } } //Flags.setNodeTrafficLight(nodeId, false); //sim.DestroyTimedTrafficLight(); sim.DestroyManualTrafficLight(); sim.NodeGeoUnsubscriber?.Dispose(); RemoveNodeFromSimulation(nodeId); if (removeTrafficLight) { tlm.RemoveTrafficLight(nodeId); } }