예제 #1
0
        /// <summary>
        /// Adds a lane connection between two lanes
        /// </summary>
        /// <param name="laneId1"></param>
        /// <param name="laneId2"></param>
        /// <param name="startNode1"></param>
        /// <returns></returns>
        internal bool AddLaneConnection(uint laneId1, uint laneId2, bool startNode1)
        {
            bool ret = Flags.AddLaneConnection(laneId1, laneId2, startNode1);

#if DEBUGCONN
            Log._Debug($"LaneConnectionManager.AddLaneConnection({laneId1}, {laneId2}, {startNode1}): ret={ret}");
#endif
            if (ret)
            {
                ushort commonNodeId;
                bool   startNode2;
                GetCommonNodeId(laneId1, laneId2, startNode1, out commonNodeId, out startNode2);
                RecalculateLaneArrows(laneId1, commonNodeId, startNode1);
                RecalculateLaneArrows(laneId2, commonNodeId, startNode2);

                NetManager netManager = Singleton <NetManager> .instance;

                ushort segmentId1 = netManager.m_lanes.m_buffer[laneId1].m_segment;
                ushort segmentId2 = netManager.m_lanes.m_buffer[laneId2].m_segment;

                if (segmentId1 == segmentId2)
                {
                    JunctionRestrictionsManager.Instance.SetUturnAllowed(segmentId1, startNode1, true);
                }

                SubscribeToSegmentGeometry(segmentId1);
                SubscribeToSegmentGeometry(segmentId2);
            }

            return(ret);
        }
        /// <summary>
        /// Adds a lane connection between two lanes
        /// </summary>
        /// <param name="sourceLaneId"></param>
        /// <param name="targetLaneId"></param>
        /// <param name="sourceStartNode"></param>
        /// <returns></returns>
        internal bool AddLaneConnection(uint sourceLaneId, uint targetLaneId, bool sourceStartNode)
        {
            if (sourceLaneId == targetLaneId)
            {
                return(false);
            }

            bool ret = Flags.AddLaneConnection(sourceLaneId, targetLaneId, sourceStartNode);

#if DEBUGCONN
            bool debug = GlobalConfig.Instance.Debug.Switches[23];
            if (debug)
            {
                Log._Debug($"LaneConnectionManager.AddLaneConnection({sourceLaneId}, {targetLaneId}, {sourceStartNode}): ret={ret}");
            }
#endif
            if (ret)
            {
                ushort commonNodeId;
                bool   targetStartNode;
                GetCommonNodeId(sourceLaneId, targetLaneId, sourceStartNode, out commonNodeId, out targetStartNode);
                RecalculateLaneArrows(sourceLaneId, commonNodeId, sourceStartNode);
                RecalculateLaneArrows(targetLaneId, commonNodeId, targetStartNode);

                NetManager netManager = Singleton <NetManager> .instance;

                ushort sourceSegmentId = netManager.m_lanes.m_buffer[sourceLaneId].m_segment;
                ushort targetSegmentId = netManager.m_lanes.m_buffer[targetLaneId].m_segment;

                if (sourceSegmentId == targetSegmentId)
                {
                    JunctionRestrictionsManager.Instance.SetUturnAllowed(sourceSegmentId, sourceStartNode, true);
                }

                RoutingManager.Instance.RequestRecalculation(sourceSegmentId, false);
                RoutingManager.Instance.RequestRecalculation(targetSegmentId, false);

                if (OptionsManager.Instance.MayPublishSegmentChanges())
                {
                    Services.NetService.PublishSegmentChanges(sourceSegmentId);
                    Services.NetService.PublishSegmentChanges(targetSegmentId);
                }
            }

            return(ret);
        }
        /// <summary>
        /// Adds a lane connection between two lanes
        /// </summary>
        /// <param name="sourceLaneId">From lane id</param>
        /// <param name="targetLaneId">To lane id</param>
        /// <param name="sourceStartNode">The affected node</param>
        /// <returns></returns>
        internal bool AddLaneConnection(uint sourceLaneId,
                                        uint targetLaneId,
                                        bool sourceStartNode)
        {
            if (sourceLaneId == targetLaneId)
            {
                return(false);
            }

            bool ret = Flags.AddLaneConnection(sourceLaneId, targetLaneId, sourceStartNode);

#if DEBUG
            bool logLaneConnections = DebugSwitch.LaneConnections.Get();
#else
            const bool logLaneConnections = false;
#endif

            if (logLaneConnections)
            {
                Log._Debug($"LaneConnectionManager.AddLaneConnection({sourceLaneId}, " +
                           $"{targetLaneId}, {sourceStartNode}): ret={ret}");
            }

            if (!ret)
            {
                return(false);
            }

            GetCommonNodeId(
                sourceLaneId,
                targetLaneId,
                sourceStartNode,
                out ushort commonNodeId,
                out bool targetStartNode);

            RecalculateLaneArrows(sourceLaneId, commonNodeId, sourceStartNode);
            RecalculateLaneArrows(targetLaneId, commonNodeId, targetStartNode);

            NetManager netManager = Singleton <NetManager> .instance;

            ushort sourceSegmentId = netManager.m_lanes.m_buffer[sourceLaneId].m_segment;
            ushort targetSegmentId = netManager.m_lanes.m_buffer[targetLaneId].m_segment;

            if (sourceSegmentId == targetSegmentId)
            {
                JunctionRestrictionsManager.Instance.SetUturnAllowed(
                    sourceSegmentId,
                    sourceStartNode,
                    true);
            }

            RoutingManager.Instance.RequestRecalculation(sourceSegmentId, false);
            RoutingManager.Instance.RequestRecalculation(targetSegmentId, false);

            if (OptionsManager.Instance.MayPublishSegmentChanges())
            {
                Services.NetService.PublishSegmentChanges(sourceSegmentId);
                Services.NetService.PublishSegmentChanges(targetSegmentId);
            }

            // return ret, ret is true at this point
            return(true);
        }