| | | 1 | | using Chronicler; |
| | | 2 | | using FixedMathSharp; |
| | | 3 | | using System; |
| | | 4 | | using System.Text.Json.Serialization; |
| | | 5 | | |
| | | 6 | | namespace Trailblazer.Navigation.Motor; |
| | | 7 | | |
| | | 8 | | /// <summary> |
| | | 9 | | /// Represents a host-provided snapshot of a contacted surface's stable identity and transform for the current frame. |
| | | 10 | | /// </summary> |
| | | 11 | | public struct PlatformSnapshot : IEquatable<PlatformSnapshot>, IRecordable |
| | | 12 | | { |
| | | 13 | | /// <summary> |
| | | 14 | | /// Stable identifier used to determine whether two surface snapshots refer to the same platform. |
| | | 15 | | /// </summary> |
| | | 16 | | private int _id; |
| | | 17 | | |
| | | 18 | | /// <inheritdoc cref="_id"/> |
| | 5651 | 19 | | public readonly int Id => _id; |
| | | 20 | | |
| | | 21 | | /// <summary> |
| | | 22 | | /// World-space transform sampled from the host for this frame. |
| | | 23 | | /// </summary> |
| | | 24 | | public Fixed4x4 Transform; |
| | | 25 | | |
| | | 26 | | /// <summary> |
| | | 27 | | /// Indicates that the sampled surface should not act as a kinematic carrier for platform locomotion. |
| | | 28 | | /// </summary> |
| | | 29 | | public bool Inert; |
| | | 30 | | |
| | | 31 | | /// <summary> |
| | | 32 | | /// Whether this snapshot represents an active platform sample. |
| | | 33 | | /// </summary> |
| | 4812 | 34 | | public readonly bool Active => Id != 0; |
| | | 35 | | |
| | | 36 | | /// <summary> |
| | | 37 | | /// Whether this sampled surface should participate in moving-platform attachment and motion transfer logic. |
| | | 38 | | /// </summary> |
| | 3850 | 39 | | public readonly bool SupportsKinematicMotion => Active && !Inert; |
| | | 40 | | |
| | | 41 | | /// <summary> |
| | | 42 | | /// Initializes a new instance of the PlatformSnapshot class with the specified identifier, transform, and inert sta |
| | | 43 | | /// </summary> |
| | | 44 | | /// <param name="id">The unique identifier for the platform snapshot.</param> |
| | | 45 | | /// <param name="transform">The transformation matrix representing the platform's position and orientation.</param> |
| | | 46 | | /// <param name="inert">true if the platform is inert and does not interact with other objects; otherwise, false.</p |
| | | 47 | | [JsonConstructor] |
| | | 48 | | public PlatformSnapshot(int id, Fixed4x4 transform, bool inert = false) |
| | | 49 | | { |
| | 232 | 50 | | _id = id; |
| | 232 | 51 | | Transform = transform; |
| | 232 | 52 | | Inert = inert; |
| | 232 | 53 | | } |
| | | 54 | | |
| | | 55 | | /// <summary> |
| | | 56 | | /// Determines whether two PlatformSnapshot instances are equal. |
| | | 57 | | /// </summary> |
| | 376 | 58 | | public static bool operator ==(PlatformSnapshot left, PlatformSnapshot right) => left.Equals(right); |
| | | 59 | | |
| | | 60 | | /// <summary> |
| | | 61 | | /// Determines whether two PlatformSnapshot instances are not equal. |
| | | 62 | | /// </summary> |
| | 376 | 63 | | public static bool operator !=(PlatformSnapshot left, PlatformSnapshot right) => !(left == right); |
| | | 64 | | |
| | | 65 | | /// <summary> |
| | | 66 | | /// Two snapshots are considered the same platform when they share the same stable id. |
| | | 67 | | /// </summary> |
| | 388 | 68 | | public readonly bool Equals(PlatformSnapshot other) => Id == other.Id; |
| | | 69 | | |
| | | 70 | | /// <inheritdoc/> |
| | 12 | 71 | | public override readonly bool Equals(object? obj) => obj is PlatformSnapshot h && Equals(h); |
| | | 72 | | |
| | | 73 | | /// <inheritdoc/> |
| | 0 | 74 | | public override readonly int GetHashCode() => Id; |
| | | 75 | | |
| | | 76 | | /// <inheritdoc/> |
| | | 77 | | public void RecordData(IChronicler chronicler) |
| | | 78 | | { |
| | 94 | 79 | | chronicler.LookValue(ref _id, "Id", 0); |
| | 94 | 80 | | chronicler.LookValue(ref Transform, "Transform", default); |
| | 94 | 81 | | chronicler.LookValue(ref Inert, "Inert", false); |
| | 94 | 82 | | } |
| | | 83 | | } |