< 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: 109
Line coverage: 100%
Branch coverage
64%
Covered branches: 9
Total branches: 14
Branch coverage: 64.2%
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()50%22100%
set_TerminalVelocity(...)100%11100%
get_HasTerminalVelocityOverride()100%11100%
ClearGravityForceOverride()100%11100%
ClearTerminalVelocityOverride()100%11100%
RecordData(...)60%1010100%

File(s)

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

#LineLine coverage
 1using Chronicler;
 2using FixedMathSharp;
 3
 4namespace Trailblazer.Navigation.Motor;
 5
 6/// <summary>
 7/// Holds the gravity and terminal velocity forces applied to a object, with support for per-instance overrides and glob
 8/// </summary>
 9public sealed class LocomotionForces : IRecordable
 10{
 11    /// <summary>
 12    /// Simulation-wide gravity defaults applied to all <see cref="MoveLocomotion"/> instances
 13    /// that do not carry a per-instance override.
 14    /// </summary>
 15    /// <remarks>
 16    /// Assign fields on this instance to shift gravity for every unoverridden object at once.
 17    /// Call <see cref="GlobalEnvironmentForces.Reset"/> to restore the defaults.
 18    /// </remarks>
 119    public static readonly GlobalEnvironmentForces GlobalForces = new();
 20
 21    #region Configurable Parameters
 22
 23    /// <summary>
 24    /// The gravity force applied to this object.
 25    /// Returns the per-instance override when one is set;
 26    /// otherwise delegates to <see cref="GlobalEnvironmentForces"/> so a single global change takes effect for all unov
 27    /// Assigning this property sets the per-instance override.
 28    /// Call <see cref="ClearGravityForceOverride"/> to remove the override and restore global tracking.
 29    /// </summary>
 30    public Fixed64 GravityForce
 31    {
 214032        get => _gravityForceOverride ?? GlobalForces.GravityForce;
 233        set => _gravityForceOverride = value;
 34    }
 35
 36    private Fixed64? _gravityForceOverride;
 37
 38    /// <summary>
 39    /// Returns true when this instance carries a per-instance gravity override.
 40    /// When false, <see cref="GravityForce"/> follows <see cref="GlobalEnvironmentForces"/>.
 41    /// </summary>
 542    public bool HasGravityForceOverride => _gravityForceOverride.HasValue;
 43
 44
 45    /// <summary>
 46    /// The terminal fall velocity cap for this object.
 47    /// Returns the per-instance override when one is set; otherwise delegates to
 48    /// <see cref="GlobalEnvironmentForces"/>.
 49    /// Assigning this property sets the per-instance override.
 50    /// Call <see cref="ClearTerminalVelocityOverride"/> to remove the override and restore global tracking.
 51    /// </summary>
 52    public Fixed64 TerminalVelocity
 53    {
 166154        get => _terminalVelocityOverride ?? GlobalForces.TerminalVelocity;
 155        set => _terminalVelocityOverride = value;
 56    }
 57
 58    private Fixed64? _terminalVelocityOverride;
 59
 60    /// <summary>
 61    /// Returns true when this instance carries a per-instance terminal velocity override.
 62    /// When false, <see cref="TerminalVelocity"/> follows <see cref="GlobalEnvironmentForces"/>.
 63    /// </summary>
 364    public bool HasTerminalVelocityOverride => _terminalVelocityOverride.HasValue;
 65
 66    #endregion
 67
 68    #region Overrides
 69
 70    /// <summary>
 71    /// Removes the per-instance gravity override so this object tracks
 72    /// <see cref="GlobalEnvironmentForces"/>.
 73    /// </summary>
 174    public void ClearGravityForceOverride() => _gravityForceOverride = null;
 75
 76    /// <summary>
 77    /// Removes the per-instance terminal velocity override so this object tracks
 78    /// <see cref="GlobalEnvironmentForces"/>.
 79    /// </summary>
 180    public void ClearTerminalVelocityOverride() => _terminalVelocityOverride = null;
 81
 82    #endregion
 83
 84    #region Serialization
 85
 86    /// <inheritdoc />
 87    public void RecordData(IChronicler chronicler)
 88    {
 89        // Gravity and terminal velocity are stored as per-instance overrides.
 90        // Serialize the presence flag first so loading knows whether to restore an override or clear it.
 10691        bool hasGravityOverride = _gravityForceOverride.HasValue;
 10692        Fixed64 gravityForce = _gravityForceOverride ?? GlobalForces.GravityForce;
 10693        RecordValues.Look(chronicler, ref hasGravityOverride, "HasGravityOverride", false);
 10694        RecordValues.Look(chronicler, ref gravityForce, "GravityForce", GlobalForces.GravityForce);
 95
 10696        bool hasTerminalVelocityOverride = _terminalVelocityOverride.HasValue;
 10697        Fixed64 terminalVelocity = _terminalVelocityOverride ?? GlobalForces.TerminalVelocity;
 10698        RecordValues.Look(chronicler, ref hasTerminalVelocityOverride, "HasTerminalVelocityOverride", false);
 10699        RecordValues.Look(chronicler, ref terminalVelocity, "TerminalVelocity", GlobalForces.TerminalVelocity);
 100
 106101        if (chronicler.Mode == SerializationMode.Loading)
 102        {
 53103            _gravityForceOverride = hasGravityOverride ? gravityForce : null;
 53104            _terminalVelocityOverride = hasTerminalVelocityOverride ? terminalVelocity : null;
 105        }
 106106    }
 107
 108    #endregion
 109}