< Summary

Information
Class: Trailblazer.Pathing.NavigationAStarPayload
Assembly: Trailblazer
File(s): /home/runner/work/Trailblazer/Trailblazer/src/Trailblazer/Pathing/Search/AStar/NavigationAStarPayload.cs
Line coverage
100%
Covered lines: 69
Uncovered lines: 0
Coverable lines: 69
Total lines: 135
Line coverage: 100%
Branch coverage
100%
Covered branches: 10
Total branches: 10
Branch coverage: 100%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.cctor()100%11100%
.ctor(...)100%11100%
get_HasPath()100%11100%
get_RetainedBytes()100%11100%
GetRetainedBytes(...)100%11100%
GetMaximumRetainedBytes(...)100%11100%
IsReusableResult(...)100%66100%
GetGuidePointArrayRetainedBytes(...)100%22100%
GetTransitionInstructionArrayRetainedBytes(...)100%22100%
Align8(...)100%11100%

File(s)

/home/runner/work/Trailblazer/Trailblazer/src/Trailblazer/Pathing/Search/AStar/NavigationAStarPayload.cs

#LineLine coverage
 1//=======================================================================
 2// NavigationAStarPayload.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
 8using System;
 9using System.Runtime.CompilerServices;
 10using FixedMathSharp;
 11
 12namespace Trailblazer.Pathing;
 13
 14/// <summary>Stores one immutable fixed-point A* result independent of graph slots.</summary>
 15internal sealed class NavigationAStarPayload
 16{
 17    private const long ObjectHeaderBytes = 16L;
 18    private const long ArrayHeaderBytes = 24L;
 19    private const long ReferenceSlotBytes = 8L;
 20    private const long Int64Bytes = 8L;
 21    private const long ByteBytes = 1L;
 22    private const long Fixed64Bytes = Int64Bytes;
 23    private const long NullableUInt64Bytes = 16L;
 124    private static readonly long BaseRetainedBytes = Align8(
 125        ObjectHeaderBytes
 126        + Unsafe.SizeOf<NavigationAStarPayloadKey>()
 127        + (3L * ReferenceSlotBytes)
 128        + Fixed64Bytes
 129        + NullableUInt64Bytes
 130        + ByteBytes);
 31
 29332    internal NavigationAStarPayload(
 29333        NavigationAStarPayloadKey key,
 29334        NavigationAStarGuidePoint[] guidePoints,
 29335        NavigationTransitionInstruction[] transitionInstructions,
 29336        Fixed64 cost,
 29337        GraphDependencyStamp dependencies,
 29338        ulong? worldChangeSequence,
 29339        NavigationSurfaceAStarStatus status)
 40    {
 29341        SwiftThrowHelper.ThrowIfNull(guidePoints, nameof(guidePoints));
 29342        SwiftThrowHelper.ThrowIfNull(
 29343            transitionInstructions,
 29344            nameof(transitionInstructions));
 29345        SwiftThrowHelper.ThrowIfNull(dependencies, nameof(dependencies));
 29346        SwiftThrowHelper.ThrowIfArgument(
 29347            !IsReusableResult(status, guidePoints.Length),
 29348            paramName: nameof(status),
 29349            message: "Only successful paths and exact no-path results are reusable.");
 29250        Key = key;
 29251        GuidePoints = guidePoints;
 29252        TransitionInstructions = transitionInstructions;
 29253        Cost = cost;
 29254        Dependencies = dependencies;
 29255        WorldChangeSequence = worldChangeSequence;
 29256        Status = status;
 29257    }
 58
 59    internal NavigationAStarPayloadKey Key { get; }
 60
 61    internal NavigationAStarGuidePoint[] GuidePoints { get; }
 62
 63    internal NavigationTransitionInstruction[] TransitionInstructions { get; }
 64
 63465    internal bool HasPath => GuidePoints.Length != 0;
 66
 67    internal Fixed64 Cost { get; }
 68
 69    internal GraphDependencyStamp Dependencies { get; }
 70
 71    internal ulong? WorldChangeSequence { get; }
 72
 73    internal NavigationSurfaceAStarStatus Status { get; }
 74
 429575    internal long RetainedBytes => GetRetainedBytes(
 429576        GuidePoints.Length,
 429577        TransitionInstructions.Length,
 429578        Dependencies);
 79
 80    internal static long GetRetainedBytes(
 81        int guidePointCount,
 82        int transitionInstructionCount,
 83        GraphDependencyStamp dependencies)
 84    {
 450985        SwiftThrowHelper.ThrowIfNegative(guidePointCount, nameof(guidePointCount));
 450986        SwiftThrowHelper.ThrowIfNegative(
 450987            transitionInstructionCount,
 450988            nameof(transitionInstructionCount));
 450989        SwiftThrowHelper.ThrowIfNull(dependencies, nameof(dependencies));
 450990        return checked(
 450991        BaseRetainedBytes
 450992        + GetGuidePointArrayRetainedBytes(guidePointCount)
 450993        + GetTransitionInstructionArrayRetainedBytes(transitionInstructionCount)
 450994        + dependencies.RetainedBytes);
 95    }
 96
 97    internal static long GetMaximumRetainedBytes(
 98        int guidePointCount,
 99        int transitionInstructionCount,
 100        int componentCount,
 101        int pageCount)
 102    {
 440103        SwiftThrowHelper.ThrowIfNegative(guidePointCount, nameof(guidePointCount));
 440104        SwiftThrowHelper.ThrowIfNegative(
 440105            transitionInstructionCount,
 440106            nameof(transitionInstructionCount));
 440107        return checked(
 440108            BaseRetainedBytes
 440109            + GetGuidePointArrayRetainedBytes(guidePointCount)
 440110            + GetTransitionInstructionArrayRetainedBytes(transitionInstructionCount)
 440111            + GraphDependencyStamp.GetRetainedBytes(componentCount, pageCount));
 112    }
 113
 114    internal static bool IsReusableResult(
 115        NavigationSurfaceAStarStatus status,
 116        int guidePointCount) =>
 299117        (status == NavigationSurfaceAStarStatus.Success && guidePointCount > 0)
 299118        || (status == NavigationSurfaceAStarStatus.NoPath && guidePointCount == 0);
 119
 120    private static long GetGuidePointArrayRetainedBytes(int length) =>
 4949121        length == 0
 4949122            ? 0L
 4949123            : Align8(checked(
 4949124                ArrayHeaderBytes
 4949125                + ((long)length * Unsafe.SizeOf<NavigationAStarGuidePoint>())));
 126
 127    private static long GetTransitionInstructionArrayRetainedBytes(int length) =>
 4949128        length == 0
 4949129            ? 0L
 4949130            : Align8(checked(
 4949131                ArrayHeaderBytes
 4949132                + ((long)length * Unsafe.SizeOf<NavigationTransitionInstruction>())));
 133
 5131134    private static long Align8(long value) => checked((value + 7L) & ~7L);
 135}