Exemple #1
0
 public CustomSegmentLights(ICustomSegmentLightsManager lightsManager, ushort segmentId, bool startNode, bool calculateAutoPedLight, bool performHousekeeping) : base(segmentId, startNode)
 {
     this.lightsManager = lightsManager;
     if (performHousekeeping)
     {
         Housekeeping(false, calculateAutoPedLight);
     }
 }
Exemple #2
0
 public bool Relocate(ushort segmentId, bool startNode, ICustomSegmentLightsManager lightsManager)
 {
     if (Relocate(segmentId, startNode))
     {
         this.lightsManager = lightsManager;
         Housekeeping(true, true);
         return(true);
     }
     return(false);
 }
Exemple #3
0
 protected CustomSegmentLights(ICustomSegmentLightsManager lightsManager,
                               ushort nodeId,
                               ushort segmentId,
                               bool calculateAutoPedLight)
     : this(
         lightsManager,
         segmentId,
         nodeId == Constants.ServiceFactory.NetService.GetSegmentNodeId(segmentId, true),
         calculateAutoPedLight)
 {
 }
Exemple #4
0
 protected CustomSegmentLights(ICustomSegmentLightsManager lightsManager,
                               ushort nodeId,
                               ushort segmentId,
                               bool calculateAutoPedLight)
     : this(
         lightsManager,
         segmentId,
         nodeId == segmentId.ToSegment().m_startNode,
         calculateAutoPedLight)
 {
 }
Exemple #5
0
 public CustomSegmentLights(ICustomSegmentLightsManager lightsManager,
                            ushort segmentId,
                            bool startNode,
                            bool calculateAutoPedLight)
     : this(
         lightsManager,
         segmentId,
         startNode,
         calculateAutoPedLight,
         true)
 {
 }
Exemple #6
0
        public ICustomSegmentLights Clone(ICustomSegmentLightsManager newLightsManager, bool performHousekeeping = true)
        {
            CustomSegmentLights clone = new CustomSegmentLights(newLightsManager != null ? newLightsManager : LightsManager, SegmentId, StartNode, false, false);

            foreach (KeyValuePair <ExtVehicleType, ICustomSegmentLight> e in CustomLights)
            {
                clone.CustomLights.Add(e.Key, (ICustomSegmentLight)e.Value.Clone());
            }
            clone.InternalPedestrianLightState = InternalPedestrianLightState;
            clone.manualPedestrianMode         = manualPedestrianMode;
            clone.VehicleTypes             = new LinkedList <ExtVehicleType>(VehicleTypes);
            clone.LastChangeFrame          = LastChangeFrame;
            clone.mainVehicleType          = mainVehicleType;
            clone.AutoPedestrianLightState = AutoPedestrianLightState;
            if (performHousekeeping)
            {
                clone.Housekeeping(false, false);
            }
            return(clone);
        }
Exemple #7
0
 public CustomSegmentLights(ICustomSegmentLightsManager lightsManager, ushort nodeId, ushort segmentId, bool calculateAutoPedLight, RoadBaseAI.TrafficLightState mainState, RoadBaseAI.TrafficLightState leftState, RoadBaseAI.TrafficLightState rightState, RoadBaseAI.TrafficLightState pedState)
     : this(lightsManager, segmentId, nodeId == SegmentGeometry.Get(segmentId).StartNodeId(), calculateAutoPedLight, mainState, leftState, rightState, pedState)
 {
 }
Exemple #8
0
 public CustomSegmentLights(ICustomSegmentLightsManager lightsManager, ushort segmentId, bool startNode, bool calculateAutoPedLight, RoadBaseAI.TrafficLightState mainState)
     : this(lightsManager, segmentId, startNode, calculateAutoPedLight, mainState, mainState, mainState, mainState == RoadBaseAI.TrafficLightState.Green ? RoadBaseAI.TrafficLightState.Red  : RoadBaseAI.TrafficLightState.Green)
 {
 }
Exemple #9
0
 protected CustomSegmentLights(ICustomSegmentLightsManager lightsManager, ushort nodeId, ushort segmentId, bool calculateAutoPedLight)
     : this(lightsManager, segmentId, nodeId == SegmentGeometry.Get(segmentId).StartNodeId(), calculateAutoPedLight)
 {
 }
        public void OnUpdate(NodeGeometry nodeGeometry)
        {
#if DEBUG
            Log._Debug($"TrafficLightSimulation: OnUpdate @ node {NodeId} ({nodeGeometry.NodeId})");
#endif

            if (!IsManualLight() && !IsTimedLight())
            {
                return;
            }

            if (!nodeGeometry.IsValid())
            {
                // node has become invalid. Remove manual/timed traffic light and destroy custom lights
                Constants.ManagerFactory.TrafficLightSimulationManager.RemoveNodeFromSimulation(NodeId, false, false);
                return;
            }

            if (!Flags.mayHaveTrafficLight(NodeId))
            {
                Log._Debug($"Housekeeping: Node {NodeId} has traffic light simulation but must not have a traffic light!");
                Constants.ManagerFactory.TrafficLightSimulationManager.RemoveNodeFromSimulation(NodeId, false, true);
                return;
            }

            ICustomSegmentLightsManager customTrafficLightsManager = Constants.ManagerFactory.CustomSegmentLightsManager;

            foreach (SegmentEndGeometry end in nodeGeometry.SegmentEndGeometries)
            {
                if (end == null)
                {
                    continue;
                }

#if DEBUG
                Log._Debug($"TrafficLightSimulation: OnUpdate @ node {NodeId}: Adding live traffic lights to segment {end.SegmentId}");
#endif

                // add custom lights

                /*if (!customTrafficLightsManager.IsSegmentLight(end.SegmentId, end.StartNode)) {
                 *      customTrafficLightsManager.AddSegmentLights(end.SegmentId, end.StartNode);
                 * }*/

                // housekeep timed light
                ICustomSegmentLights lights = customTrafficLightsManager.GetSegmentLights(end.SegmentId, end.StartNode);
                if (lights == null)
                {
                    Log.Warning($"TrafficLightSimulation.OnUpdate() @ node {NodeId}: Could not retrieve live segment lights for segment {end.SegmentId} @ start {end.StartNode}.");
                    continue;
                }
                lights.Housekeeping(true, true);
            }

            // ensure there is a physical traffic light
            Constants.ServiceFactory.NetService.ProcessNode(NodeId, delegate(ushort nodeId, ref NetNode node) {
                Constants.ManagerFactory.TrafficLightManager.AddTrafficLight(NodeId, ref node);
                return(true);
            });

            TimedLight?.OnGeometryUpdate();
            TimedLight?.Housekeeping();
        }