/// <summary>
        /// start mapping for <paramref name="intersectionInfo"/>
        /// </summary>
        /// <param name="newSegmentIds">segment list provided by LoadPaths.</param>
        public static void ApplyTrafficRules(BuildingInfo intersectionInfo, ushort[] newSegmentIds)
        {
            /****************/
            /* Preparation: */
            /****************/

            Log._Debug($"PlaceIntersectionUtil.ApplyTrafficRules({intersectionInfo?.ToString() ?? "null"})");

            if (!Shortcuts.InSimulationThread())
            {
                Log.Error("must be called from simulation thread");
                return;
            }
            if (intersectionInfo == null)
            {
                Log.Error("intersectionInfo is null");
                return;
            }

            var map = new Dictionary <InstanceID, InstanceID>();

            var Asset2Data = TMPELifecycle.Instance.Asset2Data;

            Log._Debug("PlaceIntersectionUtil.ApplyTrafficRules(): Asset2Data.keys=" +
                       Asset2Data.Select(item => item.Key).ToSTR());

            if (Asset2Data.TryGetValue(intersectionInfo, out var assetData))
            {
                Log._Debug("PlaceIntersectionUtil.ApplyTrafficRules(): assetData =" + assetData);
            }
            else
            {
                Log._Debug("PlaceIntersectionUtil.ApplyTrafficRules(): assetData not found (the asset does not have TMPE data)");
                return;
            }

            var pathNetworkIDs = assetData.PathNetworkIDs;

            if (pathNetworkIDs == null)
            {
                return;
            }

            /***********************/
            /* Create segment map: */
            /***********************/
            Shortcuts.AssertNotNull(newSegmentIds, "newSegmentIds");
            FillSegmentsMap(oldSegments: pathNetworkIDs, newSegmentIds: newSegmentIds, map: map);

            // Note to previous solution:
            // Node/segment calculation shouldn't be performed at this state!
            // Forcing it here may trigger another 'fake' LoadPaths call breaking other mods attached to that method!

            /*****************************************/
            /* Queue traffic rules transfer process: */
            /*****************************************/
            UtilityManager.Instance.QueueTransferRecordable(assetData.Record, map);

            OnPlaceIntersection?.Invoke(intersectionInfo, map);
        }
Exemplo n.º 2
0
        /// <summary>
        /// start mapping for <paramref name="intersectionInfo"/>
        /// </summary>
        /// <param name="newSegmentIds">segment list provided by LoadPaths.</param>
        public static void ApplyTrafficRules(BuildingInfo intersectionInfo, ushort[] newSegmentIds)
        {
            /*************************
             * Prepration: */

            Log._Debug($"PlaceIntersectionUtil.ApplyTrafficRules({intersectionInfo?.ToString() ?? "null"})");

            if (!Shortcuts.InSimulationThread())
            {
                Log.Error("must be called from simulation thread");
                return;
            }
            if (intersectionInfo == null)
            {
                Log.Error("intersectionInfo is null");
                return;
            }

            var map = new Dictionary <InstanceID, InstanceID>();

            var Asset2Data = TMPELifecycle.Instance.Asset2Data;

            Log._Debug("PlaceIntersectionUtil.ApplyTrafficRules(): Asset2Data.keys=" +
                       Asset2Data.Select(item => item.Key).ToSTR());

            if (Asset2Data.TryGetValue(intersectionInfo, out var assetData))
            {
                Log.Info("PlaceIntersectionUtil.ApplyTrafficRules(): assetData =" + assetData);
            }
            else
            {
                Log.Info("PlaceIntersectionUtil.ApplyTrafficRules(): assetData not found (the asset does not have TMPE data)");
                return;
            }

            var pathNetworkIDs = assetData.PathNetworkIDs;

            if (pathNetworkIDs == null)
            {
                return;
            }

            /*************************
             * Apply traffic rules: */

            MapSegments(oldSegments: pathNetworkIDs, newSegmentIds: newSegmentIds, map: map);

            foreach (var item in map)
            {
                CalculateNetwork(item.Value);
            }

            assetData.Record.Transfer(map);

            OnPlaceIntersection?.Invoke(intersectionInfo, map);
        }
Exemplo n.º 3
0
 ///<summary>maps old netowkr ids to new network ids</summary>
 /// <param name="newSegmentIds">segment list provided by LoadPaths.</param>
 public static void MapSegments(
     SegmentNetworkIDs[] oldSegments,
     ushort[] newSegmentIds,
     Dictionary <InstanceID, InstanceID> map)
 {
     Shortcuts.Assert(oldSegments.Length == newSegmentIds.Length);
     for (int i = 0; i < newSegmentIds.Length; ++i)
     {
         // load paths load segments in the same order as they were stored.
         oldSegments[i].MapInstanceIDs(newSegmentId: newSegmentIds[i], map: map);
     }
 }