/// <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); }
/// <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); }