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