< 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: 209
Line coverage: 100%
Branch coverage
83%
Covered branches: 5
Total branches: 6
Branch coverage: 83.3%
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(...)75%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
 1using Chronicler;
 2using FixedMathSharp;
 3using System;
 4using System.Runtime.CompilerServices;
 5
 6namespace Trailblazer.Navigation.Motor;
 7
 8/// <summary>
 9/// Represents a movement request for a object to pass to <see cref="NavMotor"/>,
 10/// containing the current origin, foot position, rotation, direction, speed, and frame-owned locomotion intent.
 11/// </summary>
 12[Serializable]
 13public struct TrekRequest : IRecordable
 14{
 15    /// <summary>
 16    /// The world position from which the scout is requesting movement.
 17    /// </summary>
 18    public Vector3d Origin;
 19
 20    /// <summary>
 21    /// The position of the scout's foot in world space, used for ground detection and platform interaction.
 22    /// </summary>
 23    public Vector3d? FootPosition;
 24
 25    /// <summary>
 26    /// The desired rotation of the scout in world space, used for orientation and facing direction.
 27    /// </summary>
 28    public FixedQuaternion Rotation;
 29
 30    /// <summary>
 31    /// Normalized distance of movement
 32    /// </summary>
 33    public Vector3d Direction;
 34
 35    /// <summary>
 36    /// Optional world-space facing direction that overrides the default "face movement" behavior for this request.
 37    /// </summary>
 38    public Vector3d? FacingDirection;
 39
 40    /// <summary>
 41    /// The speed at which the scout wants to move.
 42    /// </summary>
 43    public TrekRate Rate;
 44
 45    /// <summary>
 46    /// Indicates whether the scout is requesting to jump.
 47    /// </summary>
 48    public bool IsRequestingJump;
 49
 50    /// <summary>
 51    /// Per-frame host query result that authoritatively answers whether jump may spend host-owned resources this frame.
 52    /// </summary>
 53    public bool CanAffordJump;
 54
 55    /// <summary>
 56    /// Indicates whether the scout is requesting controlled flight.
 57    /// </summary>
 58    public bool IsRequestingFlight;
 59
 60    /// <summary>
 61    /// Indicates whether the scout is requesting active swimming while traversing liquid.
 62    /// </summary>
 63    public bool IsRequestingSwim;
 64
 65    /// <summary>
 66    /// Indicates whether the scout is requesting climb engagement or continuation.
 67    /// </summary>
 68    public bool IsRequestingClimb;
 69
 70    /// <summary>
 71    /// Initializes a new instance of the TrekRequest class with default values.
 72    /// </summary>
 73    public TrekRequest()
 74    {
 45775        CanAffordJump = true;
 45776    }
 77
 78    /// <summary>
 79    /// Sets the current movement request parameters, including direction, rate, and action flags such as jump, flight, 
 80    /// </summary>
 81    /// <param name="direction">The movement direction vector to apply for the request.</param>
 82    /// <param name="rate">The rate at which the movement should be performed.</param>
 83    /// <param name="isRequestingJump">true to request a jump action; otherwise, false.</param>
 84    /// <param name="isRequestingFlight">true to request a flight action; otherwise, false.</param>
 85    /// <param name="isRequestingSwim">true to request active swim control while in liquid; otherwise, false.</param>
 86    /// <param name="isRequestingClimb">true to request a climb action; otherwise, false.</param>
 87    /// <param name="facingDirection">
 88    /// An optional vector specifying the desired facing direction.
 89    /// If null or equal to Vector3d.Zero, the facing direction is not changed.</param>
 90    /// <param name="canAffordJump">true if the jump action can be afforded; otherwise, false. Defaults to true.</param>
 91    [MethodImpl(MethodImplOptions.AggressiveInlining)]
 92    public void SetRequest(
 93        Vector3d direction,
 94        TrekRate rate,
 95        bool isRequestingJump,
 96        bool isRequestingFlight,
 97        bool isRequestingSwim,
 98        bool isRequestingClimb,
 99        Vector3d? facingDirection = null,
 100        bool canAffordJump = true)
 101    {
 70102        Direction = direction;
 70103        FacingDirection = facingDirection.HasValue && facingDirection.Value != Vector3d.Zero
 70104            ? facingDirection
 70105            : null;
 70106        Rate = rate;
 70107        IsRequestingJump = isRequestingJump;
 70108        CanAffordJump = canAffordJump;
 70109        IsRequestingFlight = isRequestingFlight;
 70110        IsRequestingSwim = isRequestingSwim;
 70111        IsRequestingClimb = isRequestingClimb;
 70112    }
 113
 114    /// <summary>
 115    /// Sets the transient state for the current frame, including origin, optional foot position, rotation, and optional
 116    /// </summary>
 117    /// <remarks>
 118    /// If <paramref name="direction"/> is null, the current direction is retained for this frame.
 119    /// This method is intended for per-frame updates where only some state components may change.
 120    /// </remarks>
 121    /// <param name="origin">The new origin position to set for the transient state.</param>
 122    /// <param name="footPosition">The foot position to set for the transient state, or null to leave it unset.</param>
 123    /// <param name="rotation">The rotation to apply to the transient state.</param>
 124    /// <param name="direction">The direction to set for the transient state, or null to preserve the existing direction
 125    [MethodImpl(MethodImplOptions.AggressiveInlining)]
 126    public void SetTransientState(
 127        Vector3d origin,
 128        Vector3d? footPosition,
 129        FixedQuaternion rotation,
 130        Vector3d? direction)
 131    {
 44132        Origin = origin;
 44133        FootPosition = footPosition;
 44134        Rotation = rotation;
 135
 136        // Only update direction if a new value is provided,
 137        // otherwise preserve the existing direction for this frame.
 44138        if (direction.HasValue)
 36139            Direction = direction.Value;
 44140    }
 141
 142    /// <summary>
 143    /// Creates a deep copy of the current <see cref="TrekRequest"/> instance.
 144    /// </summary>
 145    [MethodImpl(MethodImplOptions.AggressiveInlining)]
 1146    public TrekRequest Clone() => new()
 1147    {
 1148        Origin = Origin,
 1149        Rotation = Rotation,
 1150        Direction = Direction,
 1151        FacingDirection = FacingDirection,
 1152        Rate = Rate,
 1153        IsRequestingJump = IsRequestingJump,
 1154        CanAffordJump = CanAffordJump,
 1155        IsRequestingFlight = IsRequestingFlight,
 1156        IsRequestingSwim = IsRequestingSwim,
 1157        IsRequestingClimb = IsRequestingClimb,
 1158        FootPosition = FootPosition
 1159    };
 160
 161    /// <summary>
 162    /// Resets the per-frame movement data.
 163    /// </summary>
 164    public void Reset()
 165    {
 2034166        Origin = Vector3d.Zero;
 2034167        FootPosition = null;
 2034168        Rotation = FixedQuaternion.Identity;
 2034169        Direction = Vector3d.Zero;
 2034170        FacingDirection = null;
 2034171        IsRequestingJump = false;
 2034172        CanAffordJump = true;
 2034173        Rate = TrekRate.Stationary;
 2034174        IsRequestingFlight = false;
 2034175        IsRequestingSwim = false;
 2034176        IsRequestingClimb = false;
 2034177    }
 178
 179    /// <summary>
 180    /// Resets only the transient movement data that should be cleared each frame,
 181    /// while preserving any persistent data that may be set externally.
 182    /// </summary>
 183    public void ResetTransient()
 184    {
 3185        Origin = Vector3d.Zero;
 3186        FootPosition = null;
 3187        Rotation = FixedQuaternion.Identity;
 3188        Direction = Vector3d.Zero;
 3189        IsRequestingJump = false;
 3190        CanAffordJump = true;
 3191        IsRequestingClimb = false;
 3192    }
 193
 194    /// <inheritdoc/>
 195    public void RecordData(IChronicler chronicler)
 196    {
 130197        RecordValues.Look(chronicler, ref Origin, "Origin", Vector3d.Zero);
 130198        RecordValues.Look(chronicler, ref FootPosition, "FootPosition", null);
 130199        RecordValues.Look(chronicler, ref Rotation, "Rotation", FixedQuaternion.Identity);
 130200        RecordValues.Look(chronicler, ref Direction, "Direction", Vector3d.Zero);
 130201        RecordValues.Look(chronicler, ref FacingDirection, "FacingDirection", null);
 130202        RecordValues.Look(chronicler, ref Rate, "Rate", TrekRate.Stationary);
 130203        RecordValues.Look(chronicler, ref IsRequestingJump, "IsRequestingJump", false);
 130204        RecordValues.Look(chronicler, ref CanAffordJump, "CanAffordJump", true);
 130205        RecordValues.Look(chronicler, ref IsRequestingFlight, "IsRequestingFlight", false);
 130206        RecordValues.Look(chronicler, ref IsRequestingSwim, "IsRequestingSwim", false);
 130207        RecordValues.Look(chronicler, ref IsRequestingClimb, "IsRequestingClimb", false);
 130208    }
 209}