| | | 1 | | //======================================================================= |
| | | 2 | | // NavigationStructuralCompositionWork.cs |
| | | 3 | | //======================================================================= |
| | | 4 | | // MIT License, Copyright (c) 2024-present David Oravsky (mrdav30) |
| | | 5 | | // See LICENSE file in the project root for full license information. |
| | | 6 | | //======================================================================= |
| | | 7 | | |
| | | 8 | | using System; |
| | | 9 | | using GridForge.Grids; |
| | | 10 | | using GridForge.Spatial; |
| | | 11 | | |
| | | 12 | | namespace Trailblazer.Pathing; |
| | | 13 | | |
| | | 14 | | /// <summary> |
| | | 15 | | /// Retains the pre-change structural root and a canonical cursor while explicit dependency and |
| | | 16 | | /// affected-component work is debited across fixed-step maintenance boundaries. |
| | | 17 | | /// </summary> |
| | | 18 | | internal sealed class NavigationStructuralCompositionWork |
| | | 19 | | { |
| | | 20 | | private const long BaseRetainedBytes = 112L; |
| | | 21 | | |
| | | 22 | | private readonly GridWorld _world; |
| | | 23 | | private readonly int _batchChangeCount; |
| | | 24 | | private readonly NavigationWorldGraph _sourceGraph; |
| | | 25 | | private readonly NavigationOperationCandidate _candidate; |
| | | 26 | | private readonly NavigationOperationFrameChange[] _changes; |
| | 1121 | 27 | | private PersistentStringMap<bool> _changedMapIds = PersistentStringMap<bool>.Empty; |
| | 1121 | 28 | | private NavigationSurfaceComponentKeySet _affectedComponents = |
| | 1121 | 29 | | NavigationSurfaceComponentKeySet.Empty; |
| | 1121 | 30 | | private NavigationSurfaceComponentKeySet _publishedAffectedComponents = |
| | 1121 | 31 | | NavigationSurfaceComponentKeySet.Empty; |
| | 1121 | 32 | | private NavigationCellAddressSet _affectedAddresses = NavigationCellAddressSet.Empty; |
| | 1121 | 33 | | private NavigationSurfaceComponentKeySet _affectedMediumStates = |
| | 1121 | 34 | | NavigationSurfaceComponentKeySet.Empty; |
| | | 35 | | private int _affectedMemberCount; |
| | 1121 | 36 | | private PersistentStringMap<bool> _wholeMapIds = PersistentStringMap<bool>.Empty; |
| | | 37 | | private NavigationWorldGraph.StructuralPreparationWork? _preparation; |
| | | 38 | | private NavigationAutomaticSeamRefreshWork? _seamRefresh; |
| | | 39 | | private NavigationWorldGraph? _preparedGraph; |
| | | 40 | | private NavigationMaterializedComponentWork? _componentUpdate; |
| | | 41 | | private string? _pendingMapId; |
| | | 42 | | private NavigationSurfaceComponentKey? _pendingComponentKey; |
| | 1121 | 43 | | private TraversalMedium _pendingMedium = TraversalMedium.Solid; |
| | | 44 | | private NavigationCellAddress? _pendingExactAddress; |
| | | 45 | | private int _pendingMapComponentOrdinal; |
| | | 46 | | private int _explicitSourceIndex; |
| | | 47 | | private int _changeIndex; |
| | | 48 | | private int _overlayIndex; |
| | | 49 | | private int _overlayCellIndex; |
| | | 50 | | private int _capturePhase; |
| | | 51 | | private int _seamSourceIndex; |
| | | 52 | | private int _seamCapturePhase; |
| | | 53 | | private string? _pendingSeamMapId; |
| | | 54 | | private bool _seamCaptureComplete; |
| | | 55 | | private bool _exactCaptureComplete; |
| | | 56 | | private bool _pendingWholeMap; |
| | | 57 | | private int _explicitOwnerIndex; |
| | | 58 | | private int _explicitEndpointStage; |
| | | 59 | | private int _seamEndpointIndex; |
| | | 60 | | private int _preparedMapOrdinal; |
| | | 61 | | private int _preparedMapAddressOrdinal; |
| | | 62 | | private int _addressBakedCursor; |
| | | 63 | | private int _addressDynamicCursor; |
| | 1121 | 64 | | private readonly VoxelIndex[] _addressScratch = new VoxelIndex[1]; |
| | | 65 | | private int _incidentAddressIndex; |
| | 1121 | 66 | | private TraversalMedium _incidentMedium = TraversalMedium.Gas; |
| | | 67 | | private bool _incidentNodeActive; |
| | | 68 | | private bool _incidentOutgoingComplete; |
| | | 69 | | private NavigationSurfaceEdgeEnumerator _incidentOutgoing; |
| | | 70 | | private NavigationIncomingSurfaceEdgeEnumerator _incidentIncoming; |
| | | 71 | | private NavigationCellAddress? _pendingIncidentAddress; |
| | | 72 | | private bool _allClosePublished; |
| | | 73 | | private bool _affectedClosurePublished; |
| | | 74 | | private bool _allCloseRepublishRequired; |
| | | 75 | | |
| | 1121 | 76 | | internal NavigationStructuralCompositionWork( |
| | 1121 | 77 | | GridWorld world, |
| | 1121 | 78 | | NavigationWorldGraph sourceGraph, |
| | 1121 | 79 | | NavigationOperationCandidate candidate, |
| | 1121 | 80 | | NavigationOperationFrameChange[] changes, |
| | 1121 | 81 | | int changeCount) |
| | | 82 | | { |
| | 1121 | 83 | | _world = world; |
| | 1121 | 84 | | _sourceGraph = sourceGraph; |
| | 1121 | 85 | | _candidate = candidate; |
| | 1121 | 86 | | _changes = changes; |
| | 1121 | 87 | | _batchChangeCount = changeCount; |
| | 1121 | 88 | | } |
| | | 89 | | |
| | 4 | 90 | | internal int CapturedChangedMapCount => _changedMapIds.Count; |
| | | 91 | | |
| | 12626 | 92 | | internal bool IsChangedMapCaptureComplete => _capturePhase == 4 |
| | 12626 | 93 | | && _seamCaptureComplete |
| | 12626 | 94 | | && _exactCaptureComplete; |
| | | 95 | | |
| | 521 | 96 | | internal NavigationSurfaceComponentKeySet AffectedComponents => _affectedComponents; |
| | | 97 | | |
| | 13250 | 98 | | internal bool RequiresAffectedClosurePublication => _allClosePublished |
| | 13250 | 99 | | && IsChangedMapCaptureComplete |
| | 13250 | 100 | | && !_affectedClosurePublished; |
| | | 101 | | |
| | 13076 | 102 | | internal bool RequiresAllClosePublication => _allCloseRepublishRequired; |
| | | 103 | | |
| | | 104 | | internal string GetCapturedChangedMapIdAt(int ordinal) => |
| | 4 | 105 | | _changedMapIds.GetKeyAt(ordinal); |
| | | 106 | | |
| | 293860 | 107 | | internal NavigationWorldGraph PreparedGraph => _preparedGraph!; |
| | | 108 | | |
| | 270469 | 109 | | internal long RetainedBytes => checked( |
| | 270469 | 110 | | BaseRetainedBytes |
| | 270469 | 111 | | + _changedMapIds.RetainedBytes |
| | 270469 | 112 | | + _wholeMapIds.RetainedBytes |
| | 270469 | 113 | | + (_componentUpdate == null ? _affectedAddresses.RetainedBytes : 0L) |
| | 270469 | 114 | | + (_componentUpdate == null ? _affectedMediumStates.RetainedBytes : 0L) |
| | 270469 | 115 | | + (_componentUpdate == null |
| | 270469 | 116 | | && !ReferenceEquals(_publishedAffectedComponents, _affectedComponents) |
| | 270469 | 117 | | ? _affectedComponents.RetainedBytes |
| | 270469 | 118 | | : 0L) |
| | 270469 | 119 | | + (_preparation?.RetainedBytes ?? 0) |
| | 270469 | 120 | | + (_seamRefresh?.RetainedBytes ?? 0) |
| | 270469 | 121 | | + (_componentUpdate?.RetainedBytes ?? 0) |
| | 270469 | 122 | | ); |
| | | 123 | | |
| | 270819 | 124 | | internal int PersistentPageCount => checked( |
| | 270819 | 125 | | 1 |
| | 270819 | 126 | | + _changedMapIds.PersistentNodeCount |
| | 270819 | 127 | | + _wholeMapIds.PersistentNodeCount |
| | 270819 | 128 | | + (_componentUpdate == null ? _affectedAddresses.PersistentPageCount : 0) |
| | 270819 | 129 | | + (_componentUpdate == null ? _affectedMediumStates.PersistentPageCount : 0) |
| | 270819 | 130 | | + (_componentUpdate == null |
| | 270819 | 131 | | && !ReferenceEquals(_publishedAffectedComponents, _affectedComponents) |
| | 270819 | 132 | | ? _affectedComponents.PersistentPageCount |
| | 270819 | 133 | | : 0) |
| | 270819 | 134 | | + (_preparation?.PersistentPageCount ?? 0) |
| | 270819 | 135 | | + (_seamRefresh?.PersistentPageCount ?? 0) |
| | 270819 | 136 | | + (_componentUpdate?.PersistentPageCount ?? 0)); |
| | | 137 | | |
| | 17 | 138 | | internal bool IsComplete => IsLifecycleComplete( |
| | 17 | 139 | | IsChangedMapCaptureComplete, |
| | 17 | 140 | | _preparation?.IsComplete, |
| | 17 | 141 | | _seamRefresh?.IsComplete, |
| | 17 | 142 | | _affectedComponents.Count, |
| | 17 | 143 | | _affectedAddresses.Count, |
| | 17 | 144 | | _componentUpdate?.IsComplete); |
| | | 145 | | |
| | | 146 | | internal static bool IsLifecycleComplete( |
| | | 147 | | bool captureComplete, |
| | | 148 | | bool? preparationComplete, |
| | | 149 | | bool? seamRefreshComplete, |
| | | 150 | | int affectedComponentCount, |
| | | 151 | | int affectedAddressCount, |
| | 26 | 152 | | bool? componentUpdateComplete) => captureComplete |
| | 26 | 153 | | && preparationComplete == true |
| | 26 | 154 | | && seamRefreshComplete == true |
| | 26 | 155 | | && (affectedComponentCount == 0 && affectedAddressCount == 0 |
| | 26 | 156 | | || componentUpdateComplete == true); |
| | | 157 | | |
| | 1082 | 158 | | internal NavigationWorldGraph Result => _componentUpdate?.Result |
| | 1082 | 159 | | ?? PreparedGraph.WithSurfaceComponents(_sourceGraph.SurfaceComponents); |
| | | 160 | | |
| | | 161 | | internal bool Advance(MaintenanceWorkMeter meter) |
| | | 162 | | { |
| | 37 | 163 | | return Advance( |
| | 37 | 164 | | meter, |
| | 37 | 165 | | long.MaxValue, |
| | 37 | 166 | | int.MaxValue, |
| | 37 | 167 | | out _); |
| | | 168 | | } |
| | | 169 | | |
| | | 170 | | internal bool Advance( |
| | | 171 | | MaintenanceWorkMeter meter, |
| | | 172 | | long maximumRetainedBytes, |
| | | 173 | | int maximumPersistentPages, |
| | | 174 | | out bool capacityExceeded) |
| | | 175 | | { |
| | 11838 | 176 | | capacityExceeded = false; |
| | 11838 | 177 | | if (_capturePhase != 4 && !AdvanceChangedMapCapture(meter)) |
| | 1612 | 178 | | return false; |
| | 10226 | 179 | | _preparation ??= new NavigationWorldGraph.StructuralPreparationWork( |
| | 10226 | 180 | | _sourceGraph, |
| | 10226 | 181 | | _candidate, |
| | 10226 | 182 | | _changes, |
| | 10226 | 183 | | _batchChangeCount, |
| | 10226 | 184 | | _changedMapIds, |
| | 10226 | 185 | | _sourceGraph.GraphVersion + 1); |
| | | 186 | | // Topology-native edges, seams, cache invalidations, explicit edges, reverse dependencies, |
| | | 187 | | // and weak components all consume the same maintenance meter. |
| | 10226 | 188 | | if (!_preparation.IsComplete && !_preparation.Advance(meter)) |
| | 1443 | 189 | | return false; |
| | 8783 | 190 | | _seamRefresh ??= new NavigationAutomaticSeamRefreshWork( |
| | 8783 | 191 | | _world, |
| | 8783 | 192 | | _sourceGraph, |
| | 8783 | 193 | | _preparation.Result, |
| | 8783 | 194 | | _changes, |
| | 8783 | 195 | | _batchChangeCount); |
| | 8783 | 196 | | if (ExceedsCapacity(maximumRetainedBytes, maximumPersistentPages)) |
| | | 197 | | { |
| | 2 | 198 | | capacityExceeded = true; |
| | 2 | 199 | | return false; |
| | | 200 | | } |
| | 236271 | 201 | | while (!_seamRefresh.IsComplete) |
| | | 202 | | { |
| | 232101 | 203 | | long seamRevision = _seamRefresh.Revision; |
| | 232101 | 204 | | NavigationAutomaticSeamRefreshWork.SeamAdvanceStatus seamStatus = |
| | 232101 | 205 | | _seamRefresh.AdvanceOne(meter); |
| | 232101 | 206 | | if (_seamRefresh.Revision != seamRevision) |
| | | 207 | | { |
| | 1 | 208 | | ResetSeamState(); |
| | 1 | 209 | | return false; |
| | | 210 | | } |
| | 232100 | 211 | | if (ExceedsCapacity(maximumRetainedBytes, maximumPersistentPages)) |
| | | 212 | | { |
| | 3 | 213 | | capacityExceeded = true; |
| | 3 | 214 | | return false; |
| | | 215 | | } |
| | 232097 | 216 | | if (seamStatus == NavigationAutomaticSeamRefreshWork.SeamAdvanceStatus.Blocked) |
| | 4607 | 217 | | return false; |
| | | 218 | | } |
| | 4170 | 219 | | if (!_seamCaptureComplete && !AdvanceSeamChangedMapCapture(meter)) |
| | 52 | 220 | | return false; |
| | 4118 | 221 | | _preparedGraph ??= _preparation.Result.WithAutomaticSeams(_seamRefresh.Result); |
| | 4118 | 222 | | if (!_exactCaptureComplete && !AdvanceExactAffectedCapture(meter)) |
| | 1728 | 223 | | return false; |
| | 2390 | 224 | | if (RequiresAffectedClosurePublication || RequiresAllClosePublication) |
| | 168 | 225 | | return false; |
| | 2222 | 226 | | if (_affectedComponents.Count == 0 && _affectedAddresses.Count == 0) |
| | 89 | 227 | | return true; |
| | 2133 | 228 | | _componentUpdate ??= new NavigationMaterializedComponentWork( |
| | 2133 | 229 | | PreparedGraph, |
| | 2133 | 230 | | _affectedMediumStates, |
| | 2133 | 231 | | _affectedComponents, |
| | 2133 | 232 | | _affectedAddresses, |
| | 2133 | 233 | | checked(_affectedMemberCount + _affectedAddresses.Count), |
| | 2133 | 234 | | world: null, |
| | 2133 | 235 | | baselineCaptures: null, |
| | 2133 | 236 | | affectedMapOrdinals: null, |
| | 2133 | 237 | | affectedMapCount: 0, |
| | 2133 | 238 | | events: null, |
| | 2133 | 239 | | eventCount: 0); |
| | 2133 | 240 | | bool complete = _componentUpdate.Advance(meter); |
| | 2133 | 241 | | if (ExceedsCapacity(maximumRetainedBytes, maximumPersistentPages)) |
| | | 242 | | { |
| | 171 | 243 | | capacityExceeded = true; |
| | 171 | 244 | | return false; |
| | | 245 | | } |
| | 1962 | 246 | | return complete; |
| | | 247 | | } |
| | | 248 | | |
| | | 249 | | private bool ExceedsCapacity(long maximumRetainedBytes, int maximumPersistentPages) => |
| | 243016 | 250 | | RetainedBytes > maximumRetainedBytes |
| | 243016 | 251 | | || PersistentPageCount > maximumPersistentPages; |
| | | 252 | | |
| | | 253 | | internal void MarkAffectedClosurePublished() |
| | | 254 | | { |
| | 177 | 255 | | _publishedAffectedComponents = _affectedComponents; |
| | 177 | 256 | | _affectedClosurePublished = true; |
| | 177 | 257 | | } |
| | | 258 | | |
| | | 259 | | internal void RecordAffectedClosurePublication( |
| | | 260 | | NavigationCandidatePublication publication) |
| | | 261 | | { |
| | 170 | 262 | | if (publication == NavigationCandidatePublication.Published) |
| | 167 | 263 | | MarkAffectedClosurePublished(); |
| | 170 | 264 | | } |
| | | 265 | | |
| | | 266 | | internal void MarkAllClosePublished() |
| | | 267 | | { |
| | 167 | 268 | | _allClosePublished = true; |
| | 167 | 269 | | _allCloseRepublishRequired = false; |
| | 167 | 270 | | } |
| | | 271 | | |
| | | 272 | | internal void MarkInitialClosurePublished() |
| | | 273 | | { |
| | 177 | 274 | | if (IsChangedMapCaptureComplete) |
| | 10 | 275 | | MarkAffectedClosurePublished(); |
| | | 276 | | else |
| | 167 | 277 | | MarkAllClosePublished(); |
| | 167 | 278 | | } |
| | | 279 | | |
| | | 280 | | internal void MarkAllCloseRepublished() |
| | | 281 | | { |
| | 2 | 282 | | _allClosePublished = true; |
| | 2 | 283 | | _allCloseRepublishRequired = false; |
| | 2 | 284 | | _affectedClosurePublished = false; |
| | 2 | 285 | | _publishedAffectedComponents = NavigationSurfaceComponentKeySet.Empty; |
| | 2 | 286 | | } |
| | | 287 | | |
| | | 288 | | internal void RecordAllClosePublication( |
| | | 289 | | NavigationCandidatePublication publication) |
| | | 290 | | { |
| | 4 | 291 | | if (publication == NavigationCandidatePublication.Published) |
| | 2 | 292 | | MarkAllCloseRepublished(); |
| | 4 | 293 | | } |
| | | 294 | | |
| | | 295 | | internal bool RevalidateAutomaticSeamsForPublication() |
| | | 296 | | { |
| | 485 | 297 | | if (_seamRefresh == null || !_seamCaptureComplete) |
| | 1 | 298 | | return true; |
| | 484 | 299 | | long revision = _seamRefresh.Revision; |
| | 484 | 300 | | if (_seamRefresh.RevalidateForPublication()) |
| | 481 | 301 | | return true; |
| | | 302 | | System.Diagnostics.Debug.Assert(_seamRefresh.Revision != revision, |
| | | 303 | | "Failed seam revalidation resets the refresh and advances its revision."); |
| | 3 | 304 | | ResetSeamState(); |
| | 3 | 305 | | return false; |
| | | 306 | | } |
| | | 307 | | |
| | | 308 | | private bool AdvanceChangedMapCapture(MaintenanceWorkMeter meter) |
| | | 309 | | { |
| | 17868 | 310 | | while (true) |
| | | 311 | | { |
| | 20602 | 312 | | if (_capturePhase == 0) |
| | | 313 | | { |
| | 19253 | 314 | | if (!HasNextRawMapId()) |
| | | 315 | | { |
| | 938 | 316 | | _capturePhase = 4; |
| | 938 | 317 | | return true; |
| | | 318 | | } |
| | 18315 | 319 | | if (!meter.TryConsumeComponentNodes(1)) |
| | 262 | 320 | | return false; |
| | 18053 | 321 | | if (!TryTakeNextRawScope( |
| | 18053 | 322 | | out _pendingMapId, |
| | 18053 | 323 | | out _pendingExactAddress, |
| | 18053 | 324 | | out _pendingWholeMap)) |
| | | 325 | | { |
| | 184 | 326 | | _capturePhase = 4; |
| | 184 | 327 | | return true; |
| | | 328 | | } |
| | 17869 | 329 | | _pendingComponentKey = null; |
| | 17869 | 330 | | _pendingMedium = _pendingWholeMap |
| | 17869 | 331 | | ? (TraversalMedium)((int)TraversalMedium.Liquid + 1) |
| | 17869 | 332 | | : TraversalMedium.Solid; |
| | 17869 | 333 | | _pendingMapComponentOrdinal = 0; |
| | 17869 | 334 | | _addressBakedCursor = 0; |
| | 17869 | 335 | | _addressDynamicCursor = 0; |
| | 17869 | 336 | | _capturePhase = 1; |
| | | 337 | | } |
| | 19218 | 338 | | if (_capturePhase == 1) |
| | | 339 | | { |
| | 17870 | 340 | | if (!_changedMapIds.ContainsKey(_pendingMapId!)) |
| | | 341 | | { |
| | 1364 | 342 | | if (!meter.TryConsumeDependencyEntries(1)) |
| | 1 | 343 | | return false; |
| | 1363 | 344 | | _changedMapIds = _changedMapIds.Set(_pendingMapId!, true); |
| | | 345 | | } |
| | 17869 | 346 | | _capturePhase = 2; |
| | | 347 | | } |
| | 19217 | 348 | | if (_capturePhase == 2) |
| | | 349 | | { |
| | 68906 | 350 | | while (_pendingExactAddress.HasValue |
| | 68906 | 351 | | && _pendingMedium <= TraversalMedium.Liquid) |
| | | 352 | | { |
| | 49690 | 353 | | TraversalMedium medium = _pendingMedium++; |
| | 49690 | 354 | | if (!HasMediumStateChanged(_pendingExactAddress.Value, medium) |
| | 49690 | 355 | | || !_sourceGraph.TryGetSurfaceComponent( |
| | 49690 | 356 | | _pendingExactAddress.Value, |
| | 49690 | 357 | | medium, |
| | 49690 | 358 | | out NavigationSurfaceComponentKey componentKey, |
| | 49690 | 359 | | out _) |
| | 49690 | 360 | | || _affectedComponents.Contains(componentKey)) |
| | | 361 | | { |
| | | 362 | | continue; |
| | | 363 | | } |
| | 93 | 364 | | if (!meter.TryConsumeDependencyEntries(1)) |
| | | 365 | | { |
| | 1 | 366 | | _pendingMedium--; |
| | 1 | 367 | | return false; |
| | | 368 | | } |
| | 92 | 369 | | AddAffectedComponent(componentKey); |
| | | 370 | | } |
| | 19216 | 371 | | if (_pendingExactAddress.HasValue) |
| | | 372 | | { |
| | 16564 | 373 | | if (!_affectedAddresses.Contains(_pendingExactAddress.Value)) |
| | | 374 | | { |
| | 16563 | 375 | | if (!meter.TryConsumeDependencyEntries(1)) |
| | 2 | 376 | | return false; |
| | 16561 | 377 | | _affectedAddresses = _affectedAddresses.Add( |
| | 16561 | 378 | | _pendingExactAddress.Value); |
| | | 379 | | } |
| | | 380 | | } |
| | 2652 | 381 | | else if (_pendingWholeMap) |
| | | 382 | | { |
| | 2489 | 383 | | if (_sourceGraph.TryGetMap( |
| | 2489 | 384 | | _pendingMapId!, |
| | 2489 | 385 | | out NavigationMapInstance? sourceInstance)) |
| | | 386 | | { |
| | 1396 | 387 | | NavigationMapInstance instance = sourceInstance!; |
| | 7908 | 388 | | while (_pendingComponentKey.HasValue |
| | 7908 | 389 | | || _pendingMedium <= TraversalMedium.Liquid |
| | 7908 | 390 | | || _pendingMapComponentOrdinal < instance.AddressCount) |
| | | 391 | | { |
| | 7857 | 392 | | if (_pendingComponentKey.HasValue) |
| | | 393 | | { |
| | 145 | 394 | | NavigationSurfaceComponentKey pendingKey = |
| | 145 | 395 | | _pendingComponentKey.Value; |
| | 145 | 396 | | if (!_affectedComponents.Contains(pendingKey)) |
| | | 397 | | { |
| | 14 | 398 | | if (!meter.TryConsumeDependencyEntries(1)) |
| | 1 | 399 | | return false; |
| | 13 | 400 | | AddAffectedComponent(pendingKey); |
| | | 401 | | } |
| | 144 | 402 | | _pendingComponentKey = null; |
| | 144 | 403 | | continue; |
| | | 404 | | } |
| | 7712 | 405 | | if (_pendingMedium <= TraversalMedium.Liquid) |
| | | 406 | | { |
| | 4776 | 407 | | TraversalMedium medium = _pendingMedium++; |
| | 4776 | 408 | | var currentAddress = new NavigationCellAddress( |
| | 4776 | 409 | | _pendingMapId!, |
| | 4776 | 410 | | _addressScratch[0]); |
| | 4776 | 411 | | if (HasMediumStateChanged(currentAddress, medium) |
| | 4776 | 412 | | && _sourceGraph.TryGetSurfaceComponent( |
| | 4776 | 413 | | currentAddress, |
| | 4776 | 414 | | medium, |
| | 4776 | 415 | | out NavigationSurfaceComponentKey membershipKey, |
| | 4776 | 416 | | out _)) |
| | | 417 | | { |
| | 144 | 418 | | _pendingComponentKey = membershipKey; |
| | | 419 | | } |
| | 144 | 420 | | continue; |
| | | 421 | | } |
| | 2936 | 422 | | if (!meter.TryConsumeComponentNodes(1)) |
| | 1344 | 423 | | return false; |
| | 1592 | 424 | | instance.CopyCanonicalAddressChunk( |
| | 1592 | 425 | | ref _addressBakedCursor, |
| | 1592 | 426 | | ref _addressDynamicCursor, |
| | 1592 | 427 | | _addressScratch); |
| | 1592 | 428 | | _pendingMapComponentOrdinal++; |
| | 1592 | 429 | | _pendingMedium = TraversalMedium.Solid; |
| | | 430 | | } |
| | | 431 | | } |
| | 1144 | 432 | | if (!_wholeMapIds.ContainsKey(_pendingMapId!)) |
| | | 433 | | { |
| | 1141 | 434 | | if (!meter.TryConsumeDependencyEntries(1)) |
| | 1 | 435 | | return false; |
| | 1140 | 436 | | _wholeMapIds = _wholeMapIds.Set(_pendingMapId!, true); |
| | | 437 | | } |
| | | 438 | | } |
| | 17868 | 439 | | _pendingMapId = null; |
| | 17868 | 440 | | _pendingComponentKey = null; |
| | 17868 | 441 | | _pendingMedium = TraversalMedium.Solid; |
| | 17868 | 442 | | _pendingExactAddress = null; |
| | 17868 | 443 | | _pendingMapComponentOrdinal = 0; |
| | 17868 | 444 | | _addressBakedCursor = 0; |
| | 17868 | 445 | | _addressDynamicCursor = 0; |
| | 17868 | 446 | | _pendingWholeMap = false; |
| | 17868 | 447 | | _capturePhase = 0; |
| | | 448 | | } |
| | | 449 | | } |
| | | 450 | | } |
| | | 451 | | |
| | | 452 | | private bool AdvanceSeamChangedMapCapture(MaintenanceWorkMeter meter) |
| | | 453 | | { |
| | 1524 | 454 | | while (_seamSourceIndex < _seamRefresh!.ChangedMapCount || _seamCapturePhase != 0) |
| | | 455 | | { |
| | 404 | 456 | | if (_seamCapturePhase == 0) |
| | | 457 | | { |
| | 401 | 458 | | if (!meter.TryConsumeComponentNodes(1)) |
| | 49 | 459 | | return false; |
| | 352 | 460 | | _pendingSeamMapId = _seamRefresh.GetChangedMapIdAt(_seamSourceIndex++); |
| | 352 | 461 | | _seamCapturePhase = 1; |
| | | 462 | | } |
| | | 463 | | System.Diagnostics.Debug.Assert(_seamCapturePhase == 1, |
| | | 464 | | "a metered seam-map read always advances directly into its ownership phase"); |
| | 355 | 465 | | if (!_changedMapIds.ContainsKey(_pendingSeamMapId!)) |
| | | 466 | | { |
| | 35 | 467 | | if (!meter.TryConsumeDependencyEntries(1)) |
| | 3 | 468 | | return false; |
| | 32 | 469 | | _changedMapIds = _changedMapIds.Set(_pendingSeamMapId!, true); |
| | | 470 | | } |
| | 352 | 471 | | _pendingSeamMapId = null; |
| | 352 | 472 | | _seamCapturePhase = 0; |
| | | 473 | | } |
| | 1120 | 474 | | _seamCaptureComplete = true; |
| | 1120 | 475 | | return true; |
| | | 476 | | } |
| | | 477 | | |
| | | 478 | | private bool AdvanceExactAffectedCapture(MaintenanceWorkMeter meter) |
| | | 479 | | { |
| | 19991 | 480 | | while (_explicitOwnerIndex < _candidate.ExplicitChangedOwnerCount) |
| | | 481 | | { |
| | 17160 | 482 | | NavigationConnectionOwnerKey owner = |
| | 17160 | 483 | | _candidate.GetExplicitChangedOwnerAt(_explicitOwnerIndex); |
| | 17160 | 484 | | _sourceGraph.ExplicitConnections.TryGet( |
| | 17160 | 485 | | owner, |
| | 17160 | 486 | | out NavigationExplicitConnectionRecord prior); |
| | 17160 | 487 | | _candidate.ExplicitConnections.TryGet( |
| | 17160 | 488 | | owner, |
| | 17160 | 489 | | out NavigationExplicitConnectionRecord next); |
| | 17160 | 490 | | NavigationExplicitConnectionRecord? record = _explicitEndpointStage < 2 |
| | 17160 | 491 | | ? prior |
| | 17160 | 492 | | : next; |
| | 17160 | 493 | | if (record != null && record.IsActive) |
| | | 494 | | { |
| | 8600 | 495 | | if (!meter.TryConsumeDependencyEntries(1)) |
| | 16 | 496 | | return false; |
| | 8584 | 497 | | CaptureAffectedAddress( |
| | 8584 | 498 | | (_explicitEndpointStage & 1) == 0 |
| | 8584 | 499 | | ? record.Source |
| | 8584 | 500 | | : record.Destination, |
| | 8584 | 501 | | includeVolume: false); |
| | | 502 | | } |
| | 17144 | 503 | | _explicitEndpointStage++; |
| | 17144 | 504 | | if (_explicitEndpointStage == 4) |
| | | 505 | | { |
| | 4286 | 506 | | _explicitEndpointStage = 0; |
| | 4286 | 507 | | _explicitOwnerIndex++; |
| | | 508 | | } |
| | | 509 | | } |
| | | 510 | | |
| | 3215 | 511 | | while (_seamEndpointIndex < _seamRefresh!.ChangedStructuralEndpointCount) |
| | | 512 | | { |
| | 403 | 513 | | if (!meter.TryConsumeDependencyEntries(1)) |
| | 19 | 514 | | return false; |
| | 384 | 515 | | CaptureAffectedAddress( |
| | 384 | 516 | | _seamRefresh.GetChangedStructuralEndpointAt(_seamEndpointIndex++), |
| | 384 | 517 | | includeVolume: true); |
| | | 518 | | } |
| | | 519 | | |
| | 12918 | 520 | | while (_preparedMapOrdinal < PreparedGraph.MapCount) |
| | | 521 | | { |
| | 11723 | 522 | | NavigationMapInstance instance = PreparedGraph.GetInstance(_preparedMapOrdinal); |
| | 11723 | 523 | | if (!_wholeMapIds.ContainsKey(instance.MapId)) |
| | | 524 | | { |
| | 8976 | 525 | | _preparedMapOrdinal++; |
| | 8976 | 526 | | continue; |
| | | 527 | | } |
| | 18886 | 528 | | while (_preparedMapAddressOrdinal < instance.AddressCount) |
| | | 529 | | { |
| | 17756 | 530 | | if (!meter.TryConsumeComponentNodes(1)) |
| | 1617 | 531 | | return false; |
| | 16139 | 532 | | instance.CopyCanonicalAddressChunk( |
| | 16139 | 533 | | ref _addressBakedCursor, |
| | 16139 | 534 | | ref _addressDynamicCursor, |
| | 16139 | 535 | | _addressScratch); |
| | 16139 | 536 | | _preparedMapAddressOrdinal++; |
| | 16139 | 537 | | var address = new NavigationCellAddress( |
| | 16139 | 538 | | instance.MapId, |
| | 16139 | 539 | | _addressScratch[0]); |
| | 16139 | 540 | | if (PreparedGraph.HasEffectiveCell(address) |
| | 16139 | 541 | | && !HasSameStructuralMedia(address)) |
| | 14711 | 542 | | _affectedAddresses = _affectedAddresses.Add(address); |
| | | 543 | | } |
| | 1130 | 544 | | _preparedMapOrdinal++; |
| | 1130 | 545 | | _preparedMapAddressOrdinal = 0; |
| | 1130 | 546 | | _addressBakedCursor = 0; |
| | 1130 | 547 | | _addressDynamicCursor = 0; |
| | | 548 | | } |
| | 729114 | 549 | | while (_incidentAddressIndex < _affectedAddresses.Count |
| | 729114 | 550 | | || _incidentNodeActive |
| | 729114 | 551 | | || _pendingIncidentAddress.HasValue) |
| | | 552 | | { |
| | 727995 | 553 | | if (_pendingIncidentAddress.HasValue) |
| | | 554 | | { |
| | 147183 | 555 | | NavigationCellAddress address = _pendingIncidentAddress.Value; |
| | 147183 | 556 | | if (_sourceGraph.TryGetSurfaceComponent( |
| | 147183 | 557 | | address, |
| | 147183 | 558 | | TraversalMedium.Solid, |
| | 147183 | 559 | | out NavigationSurfaceComponentKey component, |
| | 147183 | 560 | | out _) |
| | 147183 | 561 | | && !_affectedComponents.Contains(component)) |
| | | 562 | | { |
| | 47 | 563 | | if (!meter.TryConsumeDependencyEntries(1)) |
| | 5 | 564 | | return false; |
| | 42 | 565 | | AddAffectedComponent(component); |
| | | 566 | | } |
| | 147178 | 567 | | _pendingIncidentAddress = null; |
| | 147178 | 568 | | continue; |
| | | 569 | | } |
| | 580812 | 570 | | if (!_incidentNodeActive) |
| | | 571 | | { |
| | 35450 | 572 | | NavigationCellAddress address = |
| | 35450 | 573 | | _affectedAddresses.GetAt(_incidentAddressIndex); |
| | 106346 | 574 | | while (_incidentMedium <= TraversalMedium.Liquid) |
| | | 575 | | { |
| | 70898 | 576 | | TraversalMedium medium = _incidentMedium++; |
| | 70898 | 577 | | if (!HasMediumStateChanged(address, medium)) |
| | | 578 | | continue; |
| | 796 | 579 | | var affectedState = new NavigationSurfaceComponentKey(address, medium); |
| | | 580 | | System.Diagnostics.Debug.Assert( |
| | | 581 | | !_affectedMediumStates.Contains(affectedState), |
| | | 582 | | "the canonical affected-address cursor visits each exact medium once"); |
| | 796 | 583 | | if (!meter.TryConsumeDependencyEntries(1)) |
| | | 584 | | { |
| | 2 | 585 | | _incidentMedium--; |
| | 2 | 586 | | return false; |
| | | 587 | | } |
| | 794 | 588 | | _affectedMediumStates = _affectedMediumStates.Add(affectedState); |
| | | 589 | | } |
| | 35448 | 590 | | if (!PreparedGraph.TryGetStructuralMediumStateRef( |
| | 35448 | 591 | | address, |
| | 35448 | 592 | | TraversalMedium.Solid, |
| | 35448 | 593 | | out NavigationMediumStateRef solidState)) |
| | | 594 | | { |
| | 790 | 595 | | _incidentMedium = TraversalMedium.Gas; |
| | 790 | 596 | | _incidentAddressIndex++; |
| | 790 | 597 | | continue; |
| | | 598 | | } |
| | 34658 | 599 | | NavigationNodeRef node = solidState.Node; |
| | 34658 | 600 | | _incidentOutgoing = PreparedGraph.EnumerateStructuralSurfaceEdges(node); |
| | 34658 | 601 | | _incidentIncoming = |
| | 34658 | 602 | | PreparedGraph.EnumerateIncomingStructuralSurfaceEdges(node); |
| | 34658 | 603 | | _incidentOutgoingComplete = false; |
| | 34658 | 604 | | _incidentNodeActive = true; |
| | | 605 | | } |
| | 580020 | 606 | | int remainingEdges = meter.RemainingSurfaceComponentEdges; |
| | 580020 | 607 | | if (!_incidentOutgoingComplete) |
| | | 608 | | { |
| | 220364 | 609 | | NavigationSurfaceEdgeAdvanceStatus status = |
| | 220364 | 610 | | _incidentOutgoing.AdvanceOne(meter, ref remainingEdges); |
| | 220364 | 611 | | if (status == NavigationSurfaceEdgeAdvanceStatus.Blocked) |
| | 26 | 612 | | return false; |
| | 220338 | 613 | | if (status == NavigationSurfaceEdgeAdvanceStatus.Pending) |
| | | 614 | | continue; |
| | 108247 | 615 | | if (status == NavigationSurfaceEdgeAdvanceStatus.Edge) |
| | | 616 | | { |
| | 73589 | 617 | | bool found = PreparedGraph.TryGetNodeAddress( |
| | 73589 | 618 | | _incidentOutgoing.Current.Target, |
| | 73589 | 619 | | out NavigationCellAddress address); |
| | | 620 | | System.Diagnostics.Debug.Assert(found, |
| | | 621 | | "A structural outgoing edge targets a node in the prepared graph."); |
| | 73589 | 622 | | _pendingIncidentAddress = address; |
| | 73589 | 623 | | continue; |
| | | 624 | | } |
| | 34658 | 625 | | _incidentOutgoingComplete = true; |
| | | 626 | | } |
| | 394314 | 627 | | NavigationSurfaceEdgeAdvanceStatus incomingStatus = |
| | 394314 | 628 | | _incidentIncoming.AdvanceOne(meter, ref remainingEdges); |
| | 394314 | 629 | | if (incomingStatus == NavigationSurfaceEdgeAdvanceStatus.Blocked) |
| | 43 | 630 | | return false; |
| | 394271 | 631 | | if (incomingStatus == NavigationSurfaceEdgeAdvanceStatus.Pending) |
| | | 632 | | continue; |
| | 108247 | 633 | | if (incomingStatus == NavigationSurfaceEdgeAdvanceStatus.Edge) |
| | | 634 | | { |
| | 73589 | 635 | | bool found = PreparedGraph.TryGetNodeAddress( |
| | 73589 | 636 | | _incidentIncoming.Current.Predecessor, |
| | 73589 | 637 | | out NavigationCellAddress address); |
| | | 638 | | System.Diagnostics.Debug.Assert(found, |
| | | 639 | | "A structural incoming edge originates at a node in the prepared graph."); |
| | 73589 | 640 | | _pendingIncidentAddress = address; |
| | 73589 | 641 | | continue; |
| | | 642 | | } |
| | 34658 | 643 | | _incidentOutgoing = default; |
| | 34658 | 644 | | _incidentIncoming = default; |
| | 34658 | 645 | | _incidentNodeActive = false; |
| | 34658 | 646 | | _incidentMedium = TraversalMedium.Gas; |
| | 34658 | 647 | | _incidentAddressIndex++; |
| | | 648 | | } |
| | 1119 | 649 | | _exactCaptureComplete = true; |
| | 1119 | 650 | | return true; |
| | | 651 | | } |
| | | 652 | | |
| | | 653 | | private void CaptureAffectedAddress( |
| | | 654 | | NavigationCellAddress address, |
| | | 655 | | bool includeVolume) |
| | | 656 | | { |
| | 8968 | 657 | | _affectedAddresses = _affectedAddresses.Add(address); |
| | 8968 | 658 | | TraversalMedium maximum = includeVolume |
| | 8968 | 659 | | ? TraversalMedium.Liquid |
| | 8968 | 660 | | : TraversalMedium.Solid; |
| | 8968 | 661 | | for (TraversalMedium medium = TraversalMedium.Solid; |
| | 18704 | 662 | | medium <= maximum; |
| | 9736 | 663 | | medium++) |
| | | 664 | | { |
| | 9736 | 665 | | if (_sourceGraph.TryGetSurfaceComponent( |
| | 9736 | 666 | | address, |
| | 9736 | 667 | | medium, |
| | 9736 | 668 | | out NavigationSurfaceComponentKey component, |
| | 9736 | 669 | | out _)) |
| | | 670 | | { |
| | 8334 | 671 | | AddAffectedComponent(component); |
| | | 672 | | } |
| | | 673 | | } |
| | 8968 | 674 | | } |
| | | 675 | | |
| | | 676 | | private void AddAffectedComponent(NavigationSurfaceComponentKey key) |
| | | 677 | | { |
| | 8481 | 678 | | if (_affectedComponents.Contains(key)) |
| | 8301 | 679 | | return; |
| | 180 | 680 | | _affectedComponents = _affectedComponents.Add(key); |
| | 180 | 681 | | _sourceGraph.SurfaceComponents.TryGet(key, out NavigationSurfaceComponent component); |
| | | 682 | | System.Diagnostics.Debug.Assert( |
| | | 683 | | component != null, |
| | | 684 | | "Affected keys originate from resolved source-graph components."); |
| | 180 | 685 | | _affectedMemberCount = checked(_affectedMemberCount + component.Members.Count); |
| | 180 | 686 | | } |
| | | 687 | | |
| | | 688 | | private void ResetSeamState() |
| | | 689 | | { |
| | 4 | 690 | | _changedMapIds = PersistentStringMap<bool>.Empty; |
| | 4 | 691 | | _affectedComponents = NavigationSurfaceComponentKeySet.Empty; |
| | 4 | 692 | | _affectedAddresses = NavigationCellAddressSet.Empty; |
| | 4 | 693 | | _affectedMediumStates = NavigationSurfaceComponentKeySet.Empty; |
| | 4 | 694 | | _affectedMemberCount = 0; |
| | 4 | 695 | | _wholeMapIds = PersistentStringMap<bool>.Empty; |
| | 4 | 696 | | _pendingMapId = null; |
| | 4 | 697 | | _pendingComponentKey = null; |
| | 4 | 698 | | _pendingMedium = TraversalMedium.Solid; |
| | 4 | 699 | | _pendingExactAddress = null; |
| | 4 | 700 | | _pendingMapComponentOrdinal = 0; |
| | 4 | 701 | | _pendingWholeMap = false; |
| | 4 | 702 | | _explicitSourceIndex = 0; |
| | 4 | 703 | | _changeIndex = 0; |
| | 4 | 704 | | _overlayIndex = 0; |
| | 4 | 705 | | _overlayCellIndex = 0; |
| | 4 | 706 | | _capturePhase = 0; |
| | 4 | 707 | | _seamSourceIndex = 0; |
| | 4 | 708 | | _seamCapturePhase = 0; |
| | 4 | 709 | | _pendingSeamMapId = null; |
| | 4 | 710 | | _seamCaptureComplete = false; |
| | 4 | 711 | | _exactCaptureComplete = false; |
| | 4 | 712 | | _explicitOwnerIndex = 0; |
| | 4 | 713 | | _explicitEndpointStage = 0; |
| | 4 | 714 | | _seamEndpointIndex = 0; |
| | 4 | 715 | | _preparedMapOrdinal = 0; |
| | 4 | 716 | | _preparedMapAddressOrdinal = 0; |
| | 4 | 717 | | _addressBakedCursor = 0; |
| | 4 | 718 | | _addressDynamicCursor = 0; |
| | 4 | 719 | | _incidentAddressIndex = 0; |
| | 4 | 720 | | _incidentMedium = TraversalMedium.Gas; |
| | 4 | 721 | | _incidentNodeActive = false; |
| | 4 | 722 | | _incidentOutgoingComplete = false; |
| | 4 | 723 | | _incidentOutgoing = default; |
| | 4 | 724 | | _incidentIncoming = default; |
| | 4 | 725 | | _pendingIncidentAddress = null; |
| | 4 | 726 | | _preparation = null; |
| | 4 | 727 | | _seamRefresh = null; |
| | 4 | 728 | | _preparedGraph = null; |
| | 4 | 729 | | _componentUpdate = null; |
| | 4 | 730 | | if (_affectedClosurePublished) |
| | 2 | 731 | | _allCloseRepublishRequired = true; |
| | 4 | 732 | | _affectedClosurePublished = false; |
| | 4 | 733 | | _publishedAffectedComponents = NavigationSurfaceComponentKeySet.Empty; |
| | 4 | 734 | | } |
| | | 735 | | |
| | | 736 | | private bool HasNextRawMapId() => |
| | 19253 | 737 | | _explicitSourceIndex < _candidate.ExplicitChangedSourceCount |
| | 19253 | 738 | | || _changeIndex < _batchChangeCount; |
| | | 739 | | |
| | | 740 | | private bool TryTakeNextRawScope( |
| | | 741 | | out string mapId, |
| | | 742 | | out NavigationCellAddress? exactAddress, |
| | | 743 | | out bool wholeMap) |
| | | 744 | | { |
| | 18053 | 745 | | if (_explicitSourceIndex < _candidate.ExplicitChangedSourceCount) |
| | | 746 | | { |
| | 124 | 747 | | mapId = _candidate.GetExplicitChangedSourceAt(_explicitSourceIndex++); |
| | 124 | 748 | | exactAddress = null; |
| | 124 | 749 | | wholeMap = false; |
| | 124 | 750 | | return true; |
| | | 751 | | } |
| | | 752 | | while (true) |
| | | 753 | | { |
| | 17948 | 754 | | NavigationOperationFrameChange change = _changes[_changeIndex]; |
| | 17948 | 755 | | if (change.Kind != NavigationOperationFrameChangeKind.Overlay) |
| | | 756 | | { |
| | 1143 | 757 | | _changeIndex++; |
| | 1143 | 758 | | mapId = change.MapId!; |
| | 1143 | 759 | | exactAddress = null; |
| | 1143 | 760 | | wholeMap = true; |
| | 1143 | 761 | | return true; |
| | | 762 | | } |
| | 16805 | 763 | | ReadOnlySpan<NavigationMapOverlayDelta> maps = |
| | 16805 | 764 | | change.PreparedOverlay!.Transaction.MapSpan; |
| | 16805 | 765 | | NavigationMapOverlayDelta map = maps[_overlayIndex]; |
| | 16805 | 766 | | if (_overlayCellIndex < map.CellSpan.Length) |
| | | 767 | | { |
| | 16573 | 768 | | mapId = map.MapId; |
| | 16573 | 769 | | var address = new NavigationCellAddress( |
| | 16573 | 770 | | map.MapId, |
| | 16573 | 771 | | map.CellSpan[_overlayCellIndex++].Index); |
| | 16573 | 772 | | exactAddress = HasSameStructuralMedia(address) ? null : address; |
| | 16573 | 773 | | wholeMap = false; |
| | 16573 | 774 | | return true; |
| | | 775 | | } |
| | 232 | 776 | | bool hasNonCellStructuralDelta = !map.ConnectionSpan.IsEmpty |
| | 232 | 777 | | || !map.TransitionSpan.IsEmpty; |
| | 232 | 778 | | if (hasNonCellStructuralDelta && _overlayCellIndex == map.CellSpan.Length) |
| | | 779 | | { |
| | 29 | 780 | | _overlayCellIndex++; |
| | 29 | 781 | | mapId = map.MapId; |
| | 29 | 782 | | exactAddress = null; |
| | 29 | 783 | | wholeMap = false; |
| | 29 | 784 | | return true; |
| | | 785 | | } |
| | 203 | 786 | | _overlayIndex++; |
| | 203 | 787 | | _overlayCellIndex = 0; |
| | 203 | 788 | | if (_overlayIndex == maps.Length) |
| | | 789 | | { |
| | 188 | 790 | | _overlayIndex = 0; |
| | 188 | 791 | | _changeIndex++; |
| | 188 | 792 | | if (_changeIndex == _batchChangeCount) |
| | | 793 | | { |
| | 184 | 794 | | mapId = null!; |
| | 184 | 795 | | exactAddress = null; |
| | 184 | 796 | | wholeMap = false; |
| | 184 | 797 | | return false; |
| | | 798 | | } |
| | | 799 | | } |
| | | 800 | | } |
| | | 801 | | } |
| | | 802 | | |
| | | 803 | | private bool HasSameStructuralMedia(NavigationCellAddress address) |
| | | 804 | | { |
| | 32711 | 805 | | bool priorAddressed = _sourceGraph.TryGetSemanticState( |
| | 32711 | 806 | | address, |
| | 32711 | 807 | | out NavigationCellSemanticSource priorSource, |
| | 32711 | 808 | | out bool priorHasCell, |
| | 32711 | 809 | | out NavigationCell priorCell); |
| | 32711 | 810 | | bool nextAddressed = _candidate.TryGetSemanticState( |
| | 32711 | 811 | | address, |
| | 32711 | 812 | | out NavigationCellSemanticSource nextSource, |
| | 32711 | 813 | | out bool nextHasCell, |
| | 32711 | 814 | | out NavigationCell nextCell); |
| | 32711 | 815 | | TraversalMedia priorMedia = priorAddressed && priorHasCell |
| | 32711 | 816 | | ? priorCell.Media |
| | 32711 | 817 | | : TraversalMedia.None; |
| | 32711 | 818 | | TraversalMedia nextMedia = nextAddressed && nextHasCell |
| | 32711 | 819 | | ? nextCell.Media |
| | 32711 | 820 | | : TraversalMedia.None; |
| | 32711 | 821 | | return priorMedia == nextMedia; |
| | | 822 | | } |
| | | 823 | | |
| | | 824 | | private bool HasMediumStateChanged( |
| | | 825 | | NavigationCellAddress address, |
| | | 826 | | TraversalMedium medium) |
| | | 827 | | { |
| | 125364 | 828 | | _sourceGraph.TryGetSemanticState( |
| | 125364 | 829 | | address, |
| | 125364 | 830 | | out _, |
| | 125364 | 831 | | out bool priorHasCell, |
| | 125364 | 832 | | out NavigationCell priorCell); |
| | 125364 | 833 | | _candidate.TryGetSemanticState( |
| | 125364 | 834 | | address, |
| | 125364 | 835 | | out _, |
| | 125364 | 836 | | out bool nextHasCell, |
| | 125364 | 837 | | out NavigationCell nextCell); |
| | 125364 | 838 | | bool prior = priorHasCell && priorCell.SupportsMedium(medium); |
| | 125364 | 839 | | bool next = nextHasCell && nextCell.SupportsMedium(medium); |
| | 125364 | 840 | | return prior != next; |
| | | 841 | | } |
| | | 842 | | |
| | | 843 | | internal static long GetMinimumScratchBytes( |
| | | 844 | | int sourceMapCount, |
| | | 845 | | int candidateMapCount, |
| | | 846 | | int changedMapCount, |
| | | 847 | | long overlayCellCount) |
| | | 848 | | { |
| | 1112 | 849 | | long semanticPages = overlayCellCount == 0 ? 0 : ((overlayCellCount + 63) / 64) + 1; |
| | 1112 | 850 | | return checked( |
| | 1112 | 851 | | NavigationAutomaticSeamRefreshWork.FixedRetainedBytes |
| | 1112 | 852 | | + 256L |
| | 1112 | 853 | | + ((long)candidateMapCount * 256L) |
| | 1112 | 854 | | + (semanticPages * 4_504L)); |
| | | 855 | | } |
| | | 856 | | |
| | | 857 | | internal static int GetMinimumScratchPages( |
| | | 858 | | int candidateMapCount, |
| | | 859 | | long overlayCellCount) |
| | | 860 | | { |
| | 1111 | 861 | | long semanticPages = overlayCellCount == 0 ? 0 : ((overlayCellCount + 63) / 64) + 1; |
| | 1111 | 862 | | return checked( |
| | 1111 | 863 | | 2 + 4 |
| | 1111 | 864 | | + (candidateMapCount * 2) |
| | 1111 | 865 | | + checked((int)Math.Min(int.MaxValue, semanticPages * 2L))); |
| | | 866 | | } |
| | | 867 | | |
| | | 868 | | } |