< Summary

Information
Class: Trailblazer.Navigation.Motor.TrekRequest
Assembly: Trailblazer
File(s): /home/runner/work/Trailblazer/Trailblazer/src/Trailblazer/Navigation/Motor/Trek/TrekRequest.cs
Line coverage
100%
Covered lines: 65
Uncovered lines: 0
Coverable lines: 65
Total lines: 216
Line coverage: 100%
Branch coverage
100%
Covered branches: 6
Total branches: 6
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%11100%
SetRequest(...)100%44100%
SetTransientState(...)100%22100%
Clone()100%11100%
Reset()100%11100%
ResetTransient()100%11100%
RecordData(...)100%11100%

File(s)

/home/runner/work/Trailblazer/Trailblazer/src/Trailblazer/Navigation/Motor/Trek/TrekRequest.cs

#LineLine coverage
 1//=======================================================================
 2// TrekRequest.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 Chronicler;
 11using FixedMathSharp;
 12
 13namespace Trailblazer.Navigation.Motor;
 14
 15/// <summary>
 16/// Represents a movement request for a object to pass to <see cref="NavMotor"/>,
 17/// containing the current origin, foot position, rotation, direction, speed, and frame-owned locomotion intent.
 18/// </summary>
 19[Serializable]
 20public struct TrekRequest : IRecordable
 21{
 22    /// <summary>
 23    /// The world position from which the scout is requesting movement.
 24    /// </summary>
 25    public Vector3d Origin;
 26
 27    /// <summary>
 28    /// The position of the scout's foot in world space, used for ground detection and platform interaction.
 29    /// </summary>
 30    public Vector3d? FootPosition;
 31
 32    /// <summary>
 33    /// The desired rotation of the scout in world space, used for orientation and facing direction.
 34    /// </summary>
 35    public FixedQuaternion Rotation;
 36
 37    /// <summary>
 38    /// Normalized distance of movement
 39    /// </summary>
 40    public Vector3d Direction;
 41
 42    /// <summary>
 43    /// Optional world-space facing direction that overrides the default "face movement" behavior for this request.
 44    /// </summary>
 45    public Vector3d? FacingDirection;
 46
 47    /// <summary>
 48    /// The speed at which the scout wants to move.
 49    /// </summary>
 50    public TrekRate Rate;
 51
 52    /// <summary>
 53    /// Indicates whether the scout is requesting to jump.
 54    /// </summary>
 55    public bool IsRequestingJump;
 56
 57    /// <summary>
 58    /// Per-frame host query result that authoritatively answers whether jump may spend host-owned resources this frame.
 59    /// </summary>
 60    public bool CanAffordJump;
 61
 62    /// <summary>
 63    /// Indicates whether the scout is requesting controlled flight.
 64    /// </summary>
 65    public bool IsRequestingFlight;
 66
 67    /// <summary>
 68    /// Indicates whether the scout is requesting active swimming while traversing liquid.
 69    /// </summary>
 70    public bool IsRequestingSwim;
 71
 72    /// <summary>
 73    /// Indicates whether the scout is requesting climb engagement or continuation.
 74    /// </summary>
 75    public bool IsRequestingClimb;
 76
 77    /// <summary>
 78    /// Initializes a new instance of the TrekRequest class with default values.
 79    /// </summary>
 80    public TrekRequest()
 81    {
 68782        CanAffordJump = true;
 68783    }
 84
 85    /// <summary>
 86    /// Sets the current movement request parameters, including direction, rate, and action flags such as jump, flight, 
 87    /// </summary>
 88    /// <param name="direction">The movement direction vector to apply for the request.</param>
 89    /// <param name="rate">The rate at which the movement should be performed.</param>
 90    /// <param name="isRequestingJump">true to request a jump action; otherwise, false.</param>
 91    /// <param name="isRequestingFlight">true to request a flight action; otherwise, false.</param>
 92    /// <param name="isRequestingSwim">true to request active swim control while in liquid; otherwise, false.</param>
 93    /// <param name="isRequestingClimb">true to request a climb action; otherwise, false.</param>
 94    /// <param name="facingDirection">
 95    /// An optional vector specifying the desired facing direction.
 96    /// If null or equal to Vector3d.Zero, the facing direction is not changed.</param>
 97    /// <param name="canAffordJump">true if the jump action can be afforded; otherwise, false. Defaults to true.</param>
 98    [MethodImpl(MethodImplOptions.AggressiveInlining)]
 99    public void SetRequest(
 100        Vector3d direction,
 101        TrekRate rate,
 102        bool isRequestingJump,
 103        bool isRequestingFlight,
 104        bool isRequestingSwim,
 105        bool isRequestingClimb,
 106        Vector3d? facingDirection = null,
 107        bool canAffordJump = true)
 108    {
 119109        Direction = direction;
 119110        FacingDirection = facingDirection.HasValue && facingDirection.Value != Vector3d.Zero
 119111            ? facingDirection
 119112            : null;
 119113        Rate = rate;
 119114        IsRequestingJump = isRequestingJump;
 119115        CanAffordJump = canAffordJump;
 119116        IsRequestingFlight = isRequestingFlight;
 119117        IsRequestingSwim = isRequestingSwim;
 119118        IsRequestingClimb = isRequestingClimb;
 119119    }
 120
 121    /// <summary>
 122    /// Sets the transient state for the current frame, including origin, optional foot position, rotation, and optional
 123    /// </summary>
 124    /// <remarks>
 125    /// If <paramref name="direction"/> is null, the current direction is retained for this frame.
 126    /// This method is intended for per-frame updates where only some state components may change.
 127    /// </remarks>
 128    /// <param name="origin">The new origin position to set for the transient state.</param>
 129    /// <param name="footPosition">The foot position to set for the transient state, or null to leave it unset.</param>
 130    /// <param name="rotation">The rotation to apply to the transient state.</param>
 131    /// <param name="direction">The direction to set for the transient state, or null to preserve the existing direction
 132    [MethodImpl(MethodImplOptions.AggressiveInlining)]
 133    public void SetTransientState(
 134        Vector3d origin,
 135        Vector3d? footPosition,
 136        FixedQuaternion rotation,
 137        Vector3d? direction)
 138    {
 30139        Origin = origin;
 30140        FootPosition = footPosition;
 30141        Rotation = rotation;
 142
 143        // Only update direction if a new value is provided,
 144        // otherwise preserve the existing direction for this frame.
 30145        if (direction.HasValue)
 22146            Direction = direction.Value;
 30147    }
 148
 149    /// <summary>
 150    /// Creates a deep copy of the current <see cref="TrekRequest"/> instance.
 151    /// </summary>
 152    [MethodImpl(MethodImplOptions.AggressiveInlining)]
 78153    public TrekRequest Clone() => new()
 78154    {
 78155        Origin = Origin,
 78156        Rotation = Rotation,
 78157        Direction = Direction,
 78158        FacingDirection = FacingDirection,
 78159        Rate = Rate,
 78160        IsRequestingJump = IsRequestingJump,
 78161        CanAffordJump = CanAffordJump,
 78162        IsRequestingFlight = IsRequestingFlight,
 78163        IsRequestingSwim = IsRequestingSwim,
 78164        IsRequestingClimb = IsRequestingClimb,
 78165        FootPosition = FootPosition
 78166    };
 167
 168    /// <summary>
 169    /// Resets the per-frame movement data.
 170    /// </summary>
 171    public void Reset()
 172    {
 2178173        Origin = Vector3d.Zero;
 2178174        FootPosition = null;
 2178175        Rotation = FixedQuaternion.Identity;
 2178176        Direction = Vector3d.Zero;
 2178177        FacingDirection = null;
 2178178        IsRequestingJump = false;
 2178179        CanAffordJump = true;
 2178180        Rate = TrekRate.Stationary;
 2178181        IsRequestingFlight = false;
 2178182        IsRequestingSwim = false;
 2178183        IsRequestingClimb = false;
 2178184    }
 185
 186    /// <summary>
 187    /// Resets only the transient movement data that should be cleared each frame,
 188    /// while preserving any persistent data that may be set externally.
 189    /// </summary>
 190    public void ResetTransient()
 191    {
 12192        Origin = Vector3d.Zero;
 12193        FootPosition = null;
 12194        Rotation = FixedQuaternion.Identity;
 12195        Direction = Vector3d.Zero;
 12196        IsRequestingJump = false;
 12197        CanAffordJump = true;
 12198        IsRequestingClimb = false;
 12199    }
 200
 201    /// <inheritdoc/>
 202    public void RecordData(IChronicler chronicler)
 203    {
 143204        RecordValues.Look(chronicler, ref Origin, "Origin", Vector3d.Zero);
 143205        RecordValues.Look(chronicler, ref FootPosition, "FootPosition", null);
 143206        RecordValues.Look(chronicler, ref Rotation, "Rotation", FixedQuaternion.Identity);
 143207        RecordValues.Look(chronicler, ref Direction, "Direction", Vector3d.Zero);
 143208        RecordValues.Look(chronicler, ref FacingDirection, "FacingDirection", null);
 143209        RecordValues.Look(chronicler, ref Rate, "Rate", TrekRate.Stationary);
 143210        RecordValues.Look(chronicler, ref IsRequestingJump, "IsRequestingJump", false);
 143211        RecordValues.Look(chronicler, ref CanAffordJump, "CanAffordJump", true);
 143212        RecordValues.Look(chronicler, ref IsRequestingFlight, "IsRequestingFlight", false);
 143213        RecordValues.Look(chronicler, ref IsRequestingSwim, "IsRequestingSwim", false);
 143214        RecordValues.Look(chronicler, ref IsRequestingClimb, "IsRequestingClimb", false);
 143215    }
 216}