| | | 1 | | //======================================================================= |
| | | 2 | | // NavigationWorkBudget.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 SwiftCollections.Utility; |
| | | 10 | | |
| | | 11 | | namespace Trailblazer.Pathing; |
| | | 12 | | |
| | | 13 | | /// <summary> |
| | | 14 | | /// Defines finite deterministic work limits shared by a complete navigation query. |
| | | 15 | | /// </summary> |
| | | 16 | | public readonly struct NavigationWorkBudget : IEquatable<NavigationWorkBudget> |
| | | 17 | | { |
| | | 18 | | /// <summary>Gets the maximum number of address or lookup probes.</summary> |
| | | 19 | | public int MaxLookupProbes { get; } |
| | | 20 | | |
| | | 21 | | /// <summary>Gets the maximum number of endpoint candidates examined.</summary> |
| | | 22 | | public int MaxEndpointCandidates { get; } |
| | | 23 | | |
| | | 24 | | /// <summary>Gets the maximum number of graph nodes expanded.</summary> |
| | | 25 | | public int MaxExpandedNodes { get; } |
| | | 26 | | |
| | | 27 | | /// <summary>Gets the maximum number of graph edges evaluated.</summary> |
| | | 28 | | public int MaxEvaluatedEdges { get; } |
| | | 29 | | |
| | | 30 | | /// <summary>Gets the maximum number of connection witness or polyline legs evaluated.</summary> |
| | | 31 | | public int MaxConnectionLegs { get; } |
| | | 32 | | |
| | | 33 | | /// <summary>Gets the maximum number of transition candidates examined.</summary> |
| | | 34 | | public int MaxTransitionCandidates { get; } |
| | | 35 | | |
| | | 36 | | /// <summary>Gets the maximum number of transition pairs evaluated.</summary> |
| | | 37 | | public int MaxTransitionPairs { get; } |
| | | 38 | | |
| | | 39 | | /// <summary>Gets the maximum number of staged or nested path legs attempted.</summary> |
| | | 40 | | public int MaxStagedLegAttempts { get; } |
| | | 41 | | |
| | | 42 | | /// <summary>Gets the maximum number of navigation-ray trace intervals visited.</summary> |
| | | 43 | | public int MaxTraceIntervals { get; } |
| | | 44 | | |
| | | 45 | | /// <summary>Gets the maximum number of covered-voxel intervals visited.</summary> |
| | | 46 | | public int MaxCoveredVoxelIntervals { get; } |
| | | 47 | | |
| | | 48 | | /// <summary>Gets the maximum number of path-simplification rays evaluated.</summary> |
| | | 49 | | public int MaxSimplificationRays { get; } |
| | | 50 | | |
| | | 51 | | /// <summary> |
| | | 52 | | /// Creates a finite navigation work budget. Zero disables the corresponding category of work. |
| | | 53 | | /// </summary> |
| | | 54 | | /// <exception cref="ArgumentOutOfRangeException">Thrown when any limit is negative.</exception> |
| | | 55 | | public NavigationWorkBudget( |
| | | 56 | | int maxLookupProbes, |
| | | 57 | | int maxEndpointCandidates, |
| | | 58 | | int maxExpandedNodes, |
| | | 59 | | int maxEvaluatedEdges, |
| | | 60 | | int maxConnectionLegs, |
| | | 61 | | int maxTransitionCandidates, |
| | | 62 | | int maxTransitionPairs, |
| | | 63 | | int maxStagedLegAttempts, |
| | | 64 | | int maxTraceIntervals, |
| | | 65 | | int maxCoveredVoxelIntervals, |
| | | 66 | | int maxSimplificationRays) |
| | | 67 | | { |
| | 2113 | 68 | | SwiftThrowHelper.ThrowIfNegative(maxLookupProbes, nameof(maxLookupProbes)); |
| | 2108 | 69 | | SwiftThrowHelper.ThrowIfNegative(maxEndpointCandidates, nameof(maxEndpointCandidates)); |
| | 2107 | 70 | | SwiftThrowHelper.ThrowIfNegative(maxExpandedNodes, nameof(maxExpandedNodes)); |
| | 2106 | 71 | | SwiftThrowHelper.ThrowIfNegative(maxEvaluatedEdges, nameof(maxEvaluatedEdges)); |
| | 2105 | 72 | | SwiftThrowHelper.ThrowIfNegative(maxConnectionLegs, nameof(maxConnectionLegs)); |
| | 2104 | 73 | | SwiftThrowHelper.ThrowIfNegative(maxTransitionCandidates, nameof(maxTransitionCandidates)); |
| | 2103 | 74 | | SwiftThrowHelper.ThrowIfNegative(maxTransitionPairs, nameof(maxTransitionPairs)); |
| | 2102 | 75 | | SwiftThrowHelper.ThrowIfNegative(maxStagedLegAttempts, nameof(maxStagedLegAttempts)); |
| | 2101 | 76 | | SwiftThrowHelper.ThrowIfNegative(maxTraceIntervals, nameof(maxTraceIntervals)); |
| | 2100 | 77 | | SwiftThrowHelper.ThrowIfNegative(maxCoveredVoxelIntervals, nameof(maxCoveredVoxelIntervals)); |
| | 2099 | 78 | | SwiftThrowHelper.ThrowIfNegative(maxSimplificationRays, nameof(maxSimplificationRays)); |
| | | 79 | | |
| | 2098 | 80 | | MaxLookupProbes = maxLookupProbes; |
| | 2098 | 81 | | MaxEndpointCandidates = maxEndpointCandidates; |
| | 2098 | 82 | | MaxExpandedNodes = maxExpandedNodes; |
| | 2098 | 83 | | MaxEvaluatedEdges = maxEvaluatedEdges; |
| | 2098 | 84 | | MaxConnectionLegs = maxConnectionLegs; |
| | 2098 | 85 | | MaxTransitionCandidates = maxTransitionCandidates; |
| | 2098 | 86 | | MaxTransitionPairs = maxTransitionPairs; |
| | 2098 | 87 | | MaxStagedLegAttempts = maxStagedLegAttempts; |
| | 2098 | 88 | | MaxTraceIntervals = maxTraceIntervals; |
| | 2098 | 89 | | MaxCoveredVoxelIntervals = maxCoveredVoxelIntervals; |
| | 2098 | 90 | | MaxSimplificationRays = maxSimplificationRays; |
| | 2098 | 91 | | } |
| | | 92 | | |
| | | 93 | | /// <inheritdoc/> |
| | | 94 | | public bool Equals(NavigationWorkBudget other) => |
| | 2716 | 95 | | MaxLookupProbes == other.MaxLookupProbes |
| | 2716 | 96 | | && MaxEndpointCandidates == other.MaxEndpointCandidates |
| | 2716 | 97 | | && MaxExpandedNodes == other.MaxExpandedNodes |
| | 2716 | 98 | | && MaxEvaluatedEdges == other.MaxEvaluatedEdges |
| | 2716 | 99 | | && MaxConnectionLegs == other.MaxConnectionLegs |
| | 2716 | 100 | | && MaxTransitionCandidates == other.MaxTransitionCandidates |
| | 2716 | 101 | | && MaxTransitionPairs == other.MaxTransitionPairs |
| | 2716 | 102 | | && MaxStagedLegAttempts == other.MaxStagedLegAttempts |
| | 2716 | 103 | | && MaxTraceIntervals == other.MaxTraceIntervals |
| | 2716 | 104 | | && MaxCoveredVoxelIntervals == other.MaxCoveredVoxelIntervals |
| | 2716 | 105 | | && MaxSimplificationRays == other.MaxSimplificationRays; |
| | | 106 | | |
| | | 107 | | /// <inheritdoc/> |
| | 207 | 108 | | public override bool Equals(object? obj) => obj is NavigationWorkBudget other && Equals(other); |
| | | 109 | | |
| | | 110 | | /// <inheritdoc/> |
| | | 111 | | public override int GetHashCode() |
| | | 112 | | { |
| | 3372 | 113 | | int hash = SwiftHashTools.CombineHashCodes(MaxLookupProbes, MaxEndpointCandidates); |
| | 3372 | 114 | | hash = SwiftHashTools.CombineHashCodes(hash, MaxExpandedNodes); |
| | 3372 | 115 | | hash = SwiftHashTools.CombineHashCodes(hash, MaxEvaluatedEdges); |
| | 3372 | 116 | | hash = SwiftHashTools.CombineHashCodes(hash, MaxConnectionLegs); |
| | 3372 | 117 | | hash = SwiftHashTools.CombineHashCodes(hash, MaxTransitionCandidates); |
| | 3372 | 118 | | hash = SwiftHashTools.CombineHashCodes(hash, MaxTransitionPairs); |
| | 3372 | 119 | | hash = SwiftHashTools.CombineHashCodes(hash, MaxStagedLegAttempts); |
| | 3372 | 120 | | hash = SwiftHashTools.CombineHashCodes(hash, MaxTraceIntervals); |
| | 3372 | 121 | | hash = SwiftHashTools.CombineHashCodes(hash, MaxCoveredVoxelIntervals); |
| | 3372 | 122 | | return SwiftHashTools.CombineHashCodes(hash, MaxSimplificationRays); |
| | | 123 | | } |
| | | 124 | | |
| | | 125 | | /// <summary>Returns whether two budgets have exactly equal limits.</summary> |
| | 2498 | 126 | | public static bool operator ==(NavigationWorkBudget left, NavigationWorkBudget right) => left.Equals(right); |
| | | 127 | | |
| | | 128 | | /// <summary>Returns whether two budgets differ.</summary> |
| | 1 | 129 | | public static bool operator !=(NavigationWorkBudget left, NavigationWorkBudget right) => !left.Equals(right); |
| | | 130 | | |
| | | 131 | | } |