< Summary

Information
Class: Trailblazer.Pathing.FlowFieldPathRequest
Assembly: Trailblazer
File(s): /home/runner/work/Trailblazer/Trailblazer/src/Trailblazer/Pathing/Search/FlowField/FlowFieldPathRequest.cs
Line coverage
97%
Covered lines: 45
Uncovered lines: 1
Coverable lines: 46
Total lines: 133
Line coverage: 97.8%
Branch coverage
72%
Covered branches: 13
Total branches: 18
Branch coverage: 72.2%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.ctor()100%11100%
TryCreateWithSize(...)100%22100%
TryCreate(...)100%11100%
Create(...)62.5%8896.42%
Equals(...)50%22100%
Equals(...)100%22100%
GetHashCode()75%44100%

File(s)

/home/runner/work/Trailblazer/Trailblazer/src/Trailblazer/Pathing/Search/FlowField/FlowFieldPathRequest.cs

#LineLine coverage
 1using FixedMathSharp;
 2using GridForge.Grids;
 3using System;
 4using System.Diagnostics.CodeAnalysis;
 5using System.Runtime.CompilerServices;
 6
 7namespace Trailblazer.Pathing;
 8
 9/// <summary>
 10/// A pathfinding request used for flow field generation. Contains configuration for
 11/// destination targeting, dynamic agent sizing, and walkability override.
 12/// Implements value-based equality for guide pooling.
 13/// </summary>
 14public class FlowFieldPathRequest : PathRequest, IEquatable<FlowFieldPathRequest>
 15{
 16    /// <summary>
 17    /// Specifies the default value for the extra flood range used in calculations or operations that require an
 18    /// additional range parameter.
 19    /// </summary>
 20    public const int DefaultExtraFloodRange = 10;
 21
 22    /// <summary>
 23    /// The maximum Y-axis height delta a unit can step or climb per voxel while the field is built.
 24    /// Voxels exceeding this are ignored even if walkable and adjacent.
 25    /// </summary>
 26    public Fixed64 MaxClimbHeight { get; set; }
 27
 28    /// <summary>
 29    /// Limits how much extra distance the flood will expand after the target is reached.
 30    /// </summary>
 31    public int ExtraFloodRange { get; set; }
 32
 58233    private FlowFieldPathRequest() { }
 34
 35    /// <summary>
 36    /// Attempts to create a new context-bound flow field path request using the specified origin, destination, and unit
 37    /// </summary>
 38    [MethodImpl(MethodImplOptions.AggressiveInlining)]
 39    public static bool TryCreateWithSize(
 40        TrailblazerWorldContext context,
 41        Vector3d origin,
 42        Vector3d destination,
 43        Fixed64 unitSize,
 44        [NotNullWhen(true)] out FlowFieldPathRequest? request)
 45    {
 4846        request = Create(context, origin, destination, unitSize);
 4847        if (request == null)
 348            return false;
 4549        return true;
 50    }
 51
 52    /// <summary>
 53    /// Attempts to create a new context-bound flow field path request using the context's voxel size.
 54    /// </summary>
 55    [MethodImpl(MethodImplOptions.AggressiveInlining)]
 56    public static bool TryCreate(
 57        TrailblazerWorldContext context,
 58        Vector3d origin,
 59        Vector3d destination,
 60        [NotNullWhen(true)] out FlowFieldPathRequest? request) =>
 4761        TryCreateWithSize(context, origin, destination, context.VoxelSize, out request);
 62
 63    /// <summary>
 64    /// Creates a context-bound flow field path request.
 65    /// </summary>
 66    public static FlowFieldPathRequest? Create(
 67        TrailblazerWorldContext context,
 68        Vector3d origin,
 69        Vector3d destination,
 70        Fixed64 unitSize,
 71        bool allowUnwalkableEndpoints = false,
 72        bool allowTraversalTransitions = false)
 73    {
 30174        PathRequestContextResolver.ThrowIfUnusable(context);
 30175        if (!SolidVoxelFinder.TryGetPathEdgeVoxels(
 30176            context,
 30177            origin,
 30178            destination,
 30179            out Voxel? startNode,
 30180            out Voxel? endNode,
 30181            unitSize,
 30182            allowUnwalkableEndpoints))
 83        {
 1084            return null;
 85        }
 86
 29187        if (startNode == null || endNode == null)
 088            return null;
 89
 29190        FlowFieldPathRequest request = new()
 29191        {
 29192            Context = context,
 29193            Origin = origin,
 29194            StartNode = startNode,
 29195            TargetPosition = destination,
 29196            EndNode = endNode,
 29197            UnitSize = unitSize,
 29198            AllowUnwalkableEndpoints = allowUnwalkableEndpoints,
 29199            AllowTraversalTransitions = allowTraversalTransitions,
 291100            MaxClimbHeight = context.VoxelSize,
 291101            ExtraFloodRange = DefaultExtraFloodRange
 291102        };
 103
 291104        if (context.Pathing.TryGetMaxSearchSize(startNode, endNode, out int searchSize))
 291105            request.MaxPathSearchRange = searchSize;
 106
 291107        return request;
 108    }
 109
 110    /// <inheritdoc/>
 111    public override bool Equals(object? obj) =>
 1112        obj is FlowFieldPathRequest other && Equals(other);
 113
 114    /// <inheritdoc/>
 115    public bool Equals(FlowFieldPathRequest? other) =>
 2116        other != null && RequestCacheKey == other.RequestCacheKey;
 117
 118    /// <inheritdoc/>
 119    public override int GetHashCode()
 120    {
 121        // Note: For FlowFields we don't care about the start voxel (only that the FlowField contains it)
 2777122        PathRequestHashBuilder hash = PathRequestHashBuilder.Create();
 2777123        hash.Add(EndNode?.SpawnToken ?? 0);
 2777124        hash.Add(UnitSize.GetHashCode());
 2777125        hash.Add(AllowUnwalkableEndpoints);
 2777126        hash.Add(AllowTraversalTransitions);
 2777127        hash.Add(MaxClimbHeight.GetHashCode());
 2777128        hash.Add(ExtraFloodRange);
 2777129        hash.Add(MaxPathSearchRange);
 2777130        hash.Add(AllowTraversalTransitions ? Context.Pathing.State.TransitionRegistryState.RegistryVersion : 0);
 2777131        return hash.ToHashCode();
 132    }
 133}