< Summary

Information
Class: Trailblazer.Navigation.Motor.LocomotionForces
Assembly: Trailblazer
File(s): /home/runner/work/Trailblazer/Trailblazer/src/Trailblazer/Navigation/Motor/Locomotion/Forces/LocomotionForces.cs
Line coverage
100%
Covered lines: 21
Uncovered lines: 0
Coverable lines: 21
Total lines: 116
Line coverage: 100%
Branch coverage
100%
Covered branches: 14
Total branches: 14
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%
get_GravityForce()100%22100%
set_GravityForce(...)100%11100%
get_HasGravityForceOverride()100%11100%
get_TerminalVelocity()100%22100%
set_TerminalVelocity(...)100%11100%
get_HasTerminalVelocityOverride()100%11100%
ClearGravityForceOverride()100%11100%
ClearTerminalVelocityOverride()100%11100%
RecordData(...)100%1010100%

File(s)

/home/runner/work/Trailblazer/Trailblazer/src/Trailblazer/Navigation/Motor/Locomotion/Forces/LocomotionForces.cs

#LineLine coverage
 1//=======================================================================
 2// LocomotionForces.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 Chronicler;
 9using FixedMathSharp;
 10
 11namespace Trailblazer.Navigation.Motor;
 12
 13/// <summary>
 14/// Holds the gravity and terminal velocity forces applied to a object, with support for per-instance overrides and glob
 15/// </summary>
 16public sealed class LocomotionForces : IRecordable
 17{
 18    /// <summary>
 19    /// Simulation-wide gravity defaults applied to all <see cref="MoveLocomotion"/> instances
 20    /// that do not carry a per-instance override.
 21    /// </summary>
 22    /// <remarks>
 23    /// Assign fields on this instance to shift gravity for every unoverridden object at once.
 24    /// Call <see cref="GlobalEnvironmentForces.Reset"/> to restore the defaults.
 25    /// </remarks>
 126    public static readonly GlobalEnvironmentForces GlobalForces = new();
 27
 28    #region Configurable Parameters
 29
 30    /// <summary>
 31    /// The gravity force applied to this object.
 32    /// Returns the per-instance override when one is set;
 33    /// otherwise delegates to <see cref="GlobalEnvironmentForces"/> so a single global change takes effect for all unov
 34    /// Assigning this property sets the per-instance override.
 35    /// Call <see cref="ClearGravityForceOverride"/> to remove the override and restore global tracking.
 36    /// </summary>
 37    public Fixed64 GravityForce
 38    {
 223639        get => _gravityForceOverride ?? GlobalForces.GravityForce;
 440        set => _gravityForceOverride = value;
 41    }
 42
 43    private Fixed64? _gravityForceOverride;
 44
 45    /// <summary>
 46    /// Returns true when this instance carries a per-instance gravity override.
 47    /// When false, <see cref="GravityForce"/> follows <see cref="GlobalEnvironmentForces"/>.
 48    /// </summary>
 749    public bool HasGravityForceOverride => _gravityForceOverride.HasValue;
 50
 51
 52    /// <summary>
 53    /// The terminal fall velocity cap for this object.
 54    /// Returns the per-instance override when one is set; otherwise delegates to
 55    /// <see cref="GlobalEnvironmentForces"/>.
 56    /// Assigning this property sets the per-instance override.
 57    /// Call <see cref="ClearTerminalVelocityOverride"/> to remove the override and restore global tracking.
 58    /// </summary>
 59    public Fixed64 TerminalVelocity
 60    {
 167461        get => _terminalVelocityOverride ?? GlobalForces.TerminalVelocity;
 362        set => _terminalVelocityOverride = value;
 63    }
 64
 65    private Fixed64? _terminalVelocityOverride;
 66
 67    /// <summary>
 68    /// Returns true when this instance carries a per-instance terminal velocity override.
 69    /// When false, <see cref="TerminalVelocity"/> follows <see cref="GlobalEnvironmentForces"/>.
 70    /// </summary>
 571    public bool HasTerminalVelocityOverride => _terminalVelocityOverride.HasValue;
 72
 73    #endregion
 74
 75    #region Overrides
 76
 77    /// <summary>
 78    /// Removes the per-instance gravity override so this object tracks
 79    /// <see cref="GlobalEnvironmentForces"/>.
 80    /// </summary>
 181    public void ClearGravityForceOverride() => _gravityForceOverride = null;
 82
 83    /// <summary>
 84    /// Removes the per-instance terminal velocity override so this object tracks
 85    /// <see cref="GlobalEnvironmentForces"/>.
 86    /// </summary>
 187    public void ClearTerminalVelocityOverride() => _terminalVelocityOverride = null;
 88
 89    #endregion
 90
 91    #region Serialization
 92
 93    /// <inheritdoc />
 94    public void RecordData(IChronicler chronicler)
 95    {
 96        // Gravity and terminal velocity are stored as per-instance overrides.
 97        // Serialize the presence flag first so loading knows whether to restore an override or clear it.
 16898        bool hasGravityOverride = _gravityForceOverride.HasValue;
 16899        Fixed64 gravityForce = _gravityForceOverride ?? GlobalForces.GravityForce;
 168100        RecordValues.Look(chronicler, ref hasGravityOverride, "HasGravityOverride", false);
 168101        RecordValues.Look(chronicler, ref gravityForce, "GravityForce", GlobalForces.GravityForce);
 102
 168103        bool hasTerminalVelocityOverride = _terminalVelocityOverride.HasValue;
 168104        Fixed64 terminalVelocity = _terminalVelocityOverride ?? GlobalForces.TerminalVelocity;
 168105        RecordValues.Look(chronicler, ref hasTerminalVelocityOverride, "HasTerminalVelocityOverride", false);
 168106        RecordValues.Look(chronicler, ref terminalVelocity, "TerminalVelocity", GlobalForces.TerminalVelocity);
 107
 168108        if (chronicler.Mode == SerializationMode.Loading)
 109        {
 79110            _gravityForceOverride = hasGravityOverride ? gravityForce : null;
 79111            _terminalVelocityOverride = hasTerminalVelocityOverride ? terminalVelocity : null;
 112        }
 168113    }
 114
 115    #endregion
 116}