Beispiel #1
0
        public void Update()
        {
            uint currentFrameIndex = Singleton <SimulationManager> .instance.m_currentFrameIndex >> 6;

            if (lastFrame < currentFrameIndex)
            {
                lastFrame = currentFrameIndex;

                foreach (var nodeID in nodeDictionary.Keys)
                {
                    var node = GetNodeSimulation(nodeID);

                    if (node.FlagManualTrafficLights || (node.FlagTimedTrafficLights && node.TimedTrafficLightsActive))
                    {
                        var data = TrafficLightTool.GetNetNode(nodeID);
                        node.SimulationStep(ref data);
                        TrafficLightTool.SetNetNode(nodeID, data);
                    }
                }
            }
        }
Beispiel #2
0
        public void Update()
        {
            uint currentFrameIndex = Singleton <SimulationManager> .instance.m_currentFrameIndex >> 6;

            if (lastFrame < currentFrameIndex)
            {
                lastFrame = currentFrameIndex;

                List <ushort> clearedNodes = new List <ushort>();

                foreach (var nodeID in nodeDictionary.Keys)
                {
                    var data = TrafficLightTool.GetNetNode(nodeID);

                    try
                    {
                        for (var i = 0; i < 8; i++)
                        {
                            var sgmid = data.GetSegment(i);

                            if (sgmid != 0)
                            {
                                if (!TrafficLightsManual.IsSegmentLight(nodeID, sgmid))
                                {
                                    if (nodeDictionary[nodeID].FlagTimedTrafficLights)
                                    {
                                        // TODO: this fails after an upgrade
                                        var timedNode = TrafficLightsTimed.GetTimedLight(nodeID);

                                        for (var j = 0; j < timedNode.nodeGroup.Count; j++)
                                        {
                                            var nodeSim = CustomRoadAI.GetNodeSimulation(timedNode.nodeGroup[j]);

                                            nodeSim.TimedTrafficLightsActive = false;

                                            clearedNodes.Add(timedNode.nodeGroup[j]);
                                            TrafficLightsTimed.RemoveTimedLight(timedNode.nodeGroup[j]);
                                        }
                                    }
                                }
                            }
                        }
                    }
                    catch (Exception e)
                    {
                        Debug.Log(e);
                        //Log.Warning("Error on Update: \n" + e.Message + "\n\nStacktrace:\n\n" + e.StackTrace);
                    }
                }

                if (clearedNodes.Count > 0)
                {
                    for (var i = 0; i < clearedNodes.Count; i++)
                    {
                        CustomRoadAI.RemoveNodeFromSimulation(clearedNodes[i]);
                    }
                }

                foreach (var nodeID in nodeDictionary.Keys)
                {
                    var node = GetNodeSimulation(nodeID);

                    if (node.FlagManualTrafficLights || (node.FlagTimedTrafficLights && node.TimedTrafficLightsActive))
                    {
                        var data = TrafficLightTool.GetNetNode(nodeID);

                        node.SimulationStep(ref data);
                        TrafficLightTool.SetNetNode(nodeID, data);

                        if (clearedNodes.Count > 0)
                        {
                            break;
                        }
                    }
                }
            }
        }