< Summary

Information
Class: Trailblazer.Pathing.PreparedNavigationMap
Assembly: Trailblazer
File(s): /home/runner/work/Trailblazer/Trailblazer/src/Trailblazer/Pathing/Map/Operations/PreparedNavigationMap.cs
Line coverage
100%
Covered lines: 56
Uncovered lines: 0
Coverable lines: 56
Total lines: 105
Line coverage: 100%
Branch coverage
100%
Covered branches: 12
Total branches: 12
Branch coverage: 100%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.ctor(...)100%22100%
EstimateRetainedBytes(...)100%1010100%

File(s)

/home/runner/work/Trailblazer/Trailblazer/src/Trailblazer/Pathing/Map/Operations/PreparedNavigationMap.cs

#LineLine coverage
 1//=======================================================================
 2// PreparedNavigationMap.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;
 9
 10namespace Trailblazer.Pathing;
 11
 12/// <summary>Wraps an inert validated map bake before deterministic runtime admission.</summary>
 13public sealed class PreparedNavigationMap
 14{
 15    private const long DefaultCellRetainedBytes = 64L;
 16    private const long TransitionRuleRetainedBytes = 80L;
 17
 18    /// <summary>Creates an inert prepared-map descriptor from a validated immutable map.</summary>
 201419    public PreparedNavigationMap(
 201420        NavigationMap map,
 201421        long bakeVersion,
 201422        NavigationMapCheckpointStamp? checkpointStamp = null)
 23    {
 201424        SwiftThrowHelper.ThrowIfNull(map, nameof(map));
 201425        SwiftThrowHelper.ThrowIfArgument(bakeVersion <= 0, nameof(bakeVersion));
 201426        SwiftThrowHelper.ThrowIfArgument(
 201427            checkpointStamp.HasValue
 201428            && !string.Equals(checkpointStamp.Value.MapId, map.MapId, System.StringComparison.Ordinal),
 201429            nameof(checkpointStamp),
 201430            "Checkpoint map id must match the prepared map.");
 31
 201432        Map = map;
 201433        BakeVersion = bakeVersion;
 201434        BakedCellLookup = NavigationBakedCellLookup.Create(map);
 201435        RetainedBytes = NavigationByteCount.SaturatingAdd(
 201436            EstimateRetainedBytes(map),
 201437            BakedCellLookup.RetainedBytes);
 201438        CheckpointStamp = checkpointStamp;
 201439    }
 40
 41    /// <summary>Gets the immutable prepared map asset.</summary>
 42    public NavigationMap Map { get; }
 43
 44    /// <summary>Gets the immutable bake identity assigned during preparation.</summary>
 45    public long BakeVersion { get; }
 46
 47    /// <summary>Gets the deterministic retained-byte reservation for the prepared bake.</summary>
 48    public long RetainedBytes { get; }
 49
 50    /// <summary>Gets the checkpoint base stamp, when this preparation absorbed overlay state.</summary>
 51    public NavigationMapCheckpointStamp? CheckpointStamp { get; }
 52
 53    internal NavigationBakedCellLookup BakedCellLookup { get; }
 54
 55    private static long EstimateRetainedBytes(NavigationMap map)
 56    {
 201457        long bytes = NavigationByteCount.SaturatingAdd(
 201458            128L,
 201459            (long)map.MapId.Length * sizeof(char));
 201460        bytes = NavigationByteCount.SaturatingAdd(bytes, map.NativePortalTemplateRetainedBytes);
 201461        bytes = NavigationByteCount.SaturatingAdd(bytes, (long)map.Cells.Count * 96L);
 201462        if (map.DefaultCell.HasValue)
 6163            bytes = NavigationByteCount.SaturatingAdd(bytes, DefaultCellRetainedBytes);
 201464        ReadOnlySpan<TraversalTransitionRule> rules = map.TransitionRuleSpan;
 417065        for (int i = 0; i < rules.Length; i++)
 66        {
 7167            bytes = NavigationByteCount.SaturatingAdd(bytes, TransitionRuleRetainedBytes);
 7168            bytes = NavigationByteCount.SaturatingAdd(
 7169                bytes,
 7170                (long)rules[i].Id.Length * sizeof(char));
 71        }
 459272        for (int i = 0; i < map.Connections.Count; i++)
 73        {
 28274            NavigationConnection connection = map.Connections[i];
 28275            bytes = NavigationByteCount.SaturatingAdd(bytes, 160L);
 28276            bytes = NavigationByteCount.SaturatingAdd(
 28277                bytes,
 28278                (long)connection.Id.Length * sizeof(char));
 28279            bytes = NavigationByteCount.SaturatingAdd(
 28280                bytes,
 28281                (long)connection.Destination.MapId.Length * sizeof(char));
 98082            for (int witness = 0; witness < connection.Witnesses.Count; witness++)
 83            {
 20884                bytes = NavigationByteCount.SaturatingAdd(bytes, 32L);
 20885                bytes = NavigationByteCount.SaturatingAdd(
 20886                    bytes,
 20887                    (long)connection.Witnesses[witness].MapId.Length * sizeof(char));
 88            }
 89        }
 90
 431291        for (int i = 0; i < map.Transitions.Count; i++)
 92        {
 14293            TraversalTransitionDefinition transition = map.Transitions[i];
 14294            bytes = NavigationByteCount.SaturatingAdd(bytes, 144L);
 14295            bytes = NavigationByteCount.SaturatingAdd(
 14296                bytes,
 14297                (long)transition.Id.Length * sizeof(char));
 14298            bytes = NavigationByteCount.SaturatingAdd(
 14299                bytes,
 142100                (long)transition.Destination.MapId.Length * sizeof(char));
 101        }
 102
 2014103        return bytes;
 104    }
 105}