| | | 1 | | using GridForge.Spatial; |
| | | 2 | | using SwiftCollections; |
| | | 3 | | using System; |
| | | 4 | | |
| | | 5 | | namespace Trailblazer.Pathing; |
| | | 6 | | |
| | | 7 | | /// <summary> |
| | | 8 | | /// Represents the result of a flow field survey operation, including the mapping of world voxel indices |
| | | 9 | | /// to their associated flow fields and related survey metadata. |
| | | 10 | | /// </summary> |
| | | 11 | | /// <remarks> |
| | | 12 | | /// Use this class to access the flow fields generated by a survey operation, along with information |
| | | 13 | | /// about which charts were utilized and the request key associated with the result. The class provides an empty result |
| | | 14 | | /// instance for cases where no survey data is available. |
| | | 15 | | /// </remarks> |
| | | 16 | | public class FlowFieldSurveyResult : SurveyResult |
| | | 17 | | { |
| | | 18 | | /// <summary> |
| | | 19 | | /// Gets the collection of flow fields associated with each world voxel index. |
| | | 20 | | /// </summary> |
| | | 21 | | /// <remarks> |
| | | 22 | | /// The returned dictionary maps each unique world voxel index to its corresponding flow field. |
| | | 23 | | /// The property may be null if no flow fields have been initialized or assigned. |
| | | 24 | | /// </remarks> |
| | | 25 | | public SwiftDictionary<WorldVoxelIndex, FlowField>? Fields { get; private set; } |
| | | 26 | | |
| | | 27 | | internal FlowFieldSamplingGrid[] SamplingGrids { get; private set; } = Array.Empty<FlowFieldSamplingGrid>(); |
| | | 28 | | |
| | | 29 | | /// <inheritdoc/> |
| | 1881 | 30 | | public override bool HasPath => IsValid && Fields != null && Fields.Count > 0; |
| | | 31 | | |
| | | 32 | | /// <summary> |
| | | 33 | | /// Represents an empty result for a flow field survey operation. |
| | | 34 | | /// </summary> |
| | | 35 | | /// <remarks> |
| | | 36 | | /// Use this field to represent a default or uninitialized survey result when no data is available. |
| | | 37 | | /// </remarks> |
| | 1 | 38 | | public static readonly FlowFieldSurveyResult Empty = new(); |
| | | 39 | | |
| | 254 | 40 | | private FlowFieldSurveyResult() { } |
| | | 41 | | |
| | | 42 | | /// <summary> |
| | | 43 | | /// Creates a new instance of the FlowFieldSurveyResult class using the specified flow fields, utilized charts, and |
| | | 44 | | /// </summary> |
| | | 45 | | /// <param name="context">The world context that owns the survey result.</param> |
| | | 46 | | /// <param name="fields">A dictionary mapping world voxel indices to their corresponding flow fields. Cannot be null |
| | | 47 | | /// <param name="chartsUtilized">An array of chart identifiers that were utilized during the survey. If null, an emp |
| | | 48 | | /// <param name="key">A unique integer key representing the request associated with this survey result.</param> |
| | | 49 | | /// <returns>A FlowFieldSurveyResult instance initialized with the provided flow fields, charts, and request key.</r |
| | | 50 | | public static FlowFieldSurveyResult Create( |
| | | 51 | | TrailblazerWorldContext context, |
| | | 52 | | SwiftDictionary<WorldVoxelIndex, FlowField> fields, |
| | | 53 | | string[] chartsUtilized, |
| | | 54 | | int key) |
| | | 55 | | { |
| | 4 | 56 | | PathRequestContextResolver.ThrowIfUnusable(context); |
| | 4 | 57 | | return Create( |
| | 4 | 58 | | context, |
| | 4 | 59 | | fields, |
| | 4 | 60 | | chartsUtilized, |
| | 4 | 61 | | key, |
| | 4 | 62 | | Array.Empty<FlowFieldSamplingGrid>()); |
| | | 63 | | } |
| | | 64 | | |
| | | 65 | | internal static FlowFieldSurveyResult Create( |
| | | 66 | | TrailblazerWorldContext context, |
| | | 67 | | SwiftDictionary<WorldVoxelIndex, FlowField> fields, |
| | | 68 | | string[] chartsUtilized, |
| | | 69 | | int key, |
| | | 70 | | FlowFieldSamplingGrid[] samplingGrids) |
| | | 71 | | { |
| | 126 | 72 | | return new FlowFieldSurveyResult() |
| | 126 | 73 | | { |
| | 126 | 74 | | IsValid = true, |
| | 126 | 75 | | IsInUse = false, |
| | 126 | 76 | | Context = context, |
| | 126 | 77 | | ChartsUtilized = chartsUtilized ?? Array.Empty<string>(), |
| | 126 | 78 | | Fields = fields, |
| | 126 | 79 | | SamplingGrids = samplingGrids ?? Array.Empty<FlowFieldSamplingGrid>(), |
| | 126 | 80 | | LastUsedFrame = -1, |
| | 126 | 81 | | RequestHashKey = key |
| | 126 | 82 | | }; |
| | | 83 | | } |
| | | 84 | | |
| | | 85 | | /// <inheritdoc/> |
| | | 86 | | public override void Reset() |
| | | 87 | | { |
| | 22 | 88 | | base.Reset(); |
| | 22 | 89 | | Fields = null; |
| | 22 | 90 | | SamplingGrids = Array.Empty<FlowFieldSamplingGrid>(); |
| | 22 | 91 | | } |
| | | 92 | | } |