/// <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 DEBUG Log._Debug($"TrafficLightSimulationManager.RemoveNodeFromSimulation({nodeId}, {destroyGroup}, {removeTrafficLight}) called."); #endif if (!TrafficLightSimulations[nodeId].HasSimulation()) { return; } TrafficLightManager tlm = TrafficLightManager.Instance; if (TrafficLightSimulations[nodeId].IsTimedLight()) { // remove/destroy all timed traffic lights in group List <ushort> oldNodeGroup = new List <ushort>(TrafficLightSimulations[nodeId].TimedLight.NodeGroup); foreach (var timedNodeId in oldNodeGroup) { if (!TrafficLightSimulations[timedNodeId].HasSimulation()) { continue; } if (destroyGroup || timedNodeId == nodeId) { //Log._Debug($"Slave: Removing simulation @ node {timedNodeId}"); //TrafficLightSimulations[timedNodeId].Destroy(); RemoveNodeFromSimulation(timedNodeId); if (removeTrafficLight) { Constants.ServiceFactory.NetService.ProcessNode(timedNodeId, delegate(ushort nId, ref NetNode node) { tlm.RemoveTrafficLight(timedNodeId, ref node); return(true); }); } } else { if (TrafficLightSimulations[timedNodeId].IsTimedLight()) { TrafficLightSimulations[timedNodeId].TimedLight.RemoveNodeFromGroup(nodeId); } } } } //Flags.setNodeTrafficLight(nodeId, false); //sim.DestroyTimedTrafficLight(); //TrafficLightSimulations[nodeId].DestroyManualTrafficLight(); 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) { Log._Debug($"TrafficLightSimulationManager.RemoveNodeFromSimulation({nodeId}, " + $"{destroyGroup}, {removeTrafficLight}) called."); if (!TrafficLightSimulations[nodeId].HasSimulation()) { return; } TrafficLightManager tlm = TrafficLightManager.Instance; if (TrafficLightSimulations[nodeId].IsTimedLight()) { // remove/destroy all timed traffic lights in group var oldNodeGroup = new List <ushort>(TrafficLightSimulations[nodeId].timedLight.NodeGroup); foreach (ushort timedNodeId in oldNodeGroup) { if (!TrafficLightSimulations[timedNodeId].HasSimulation()) { continue; } if (destroyGroup || timedNodeId == nodeId) { // Log._Debug($"Slave: Removing simulation @ node {timedNodeId}"); // TrafficLightSimulations[timedNodeId].Destroy(); RemoveNodeFromSimulation(timedNodeId); if (removeTrafficLight) { tlm.RemoveTrafficLight(timedNodeId, ref timedNodeId.ToNode()); } } else { if (TrafficLightSimulations[timedNodeId].IsTimedLight()) { TrafficLightSimulations[timedNodeId].timedLight.RemoveNodeFromGroup(nodeId); } } } } // Flags.setNodeTrafficLight(nodeId, false); // sim.DestroyTimedTrafficLight(); // TrafficLightSimulations[nodeId].DestroyManualTrafficLight(); RemoveNodeFromSimulation(nodeId); if (removeTrafficLight) { tlm.RemoveTrafficLight(nodeId, ref nodeId.ToNode()); } }