| | | 1 | | //======================================================================= |
| | | 2 | | // GravitasJointDiagnosticView.cs |
| | | 3 | | //======================================================================= |
| | | 4 | | // MIT License, Copyright (c) 2026-present David Oravsky (mrdav30) |
| | | 5 | | // See LICENSE file in the project root for full license information. |
| | | 6 | | //======================================================================= |
| | | 7 | | |
| | | 8 | | using FixedMathSharp; |
| | | 9 | | using Gravitas.Colliders; |
| | | 10 | | |
| | | 11 | | namespace Gravitas.Diagnostics; |
| | | 12 | | |
| | | 13 | | /// <summary> |
| | | 14 | | /// Typed read-only view over a joint diagnostic event. |
| | | 15 | | /// </summary> |
| | | 16 | | public readonly struct GravitasJointDiagnosticView |
| | | 17 | | { |
| | 108 | 18 | | internal GravitasJointDiagnosticView(GravitasDiagnosticEvent diagnosticEvent) => Event = diagnosticEvent; |
| | | 19 | | |
| | | 20 | | /// <summary>Gets the underlying diagnostic event.</summary> |
| | | 21 | | public GravitasDiagnosticEvent Event { get; } |
| | | 22 | | |
| | | 23 | | /// <summary>Gets the simulation frame in which the joint event was captured.</summary> |
| | 1 | 24 | | public long Frame => Event.Frame; |
| | | 25 | | |
| | | 26 | | /// <summary>Gets the event's sequence within its capture buffer.</summary> |
| | 1 | 27 | | public int Sequence => Event.Sequence; |
| | | 28 | | |
| | | 29 | | /// <summary>Gets the joint event kind.</summary> |
| | 99 | 30 | | public GravitasDiagnosticEventKind Kind => Event.Kind; |
| | | 31 | | |
| | | 32 | | /// <summary>Gets the context-local joint identifier.</summary> |
| | 4 | 33 | | public int JointId => Event.JointId; |
| | | 34 | | |
| | | 35 | | /// <summary>Gets the first endpoint's context-local collider identifier.</summary> |
| | 1 | 36 | | public int ColliderAId => Event.ColliderAId; |
| | | 37 | | |
| | | 38 | | /// <summary>Gets the second endpoint's context-local collider identifier.</summary> |
| | 1 | 39 | | public int ColliderBId => Event.ColliderBId; |
| | | 40 | | |
| | | 41 | | /// <summary>Gets the first endpoint collider's dimension.</summary> |
| | 1 | 42 | | public GravitasColliderDimension ColliderADimension => Event.ColliderADimension; |
| | | 43 | | |
| | | 44 | | /// <summary>Gets the second endpoint collider's dimension.</summary> |
| | 1 | 45 | | public GravitasColliderDimension ColliderBDimension => Event.ColliderBDimension; |
| | | 46 | | |
| | | 47 | | /// <summary>Gets the first endpoint's 3D collider type.</summary> |
| | 1 | 48 | | public ColliderType ColliderAType => Event.ColliderAType; |
| | | 49 | | |
| | | 50 | | /// <summary>Gets the second endpoint's 3D collider type.</summary> |
| | 1 | 51 | | public ColliderType ColliderBType => Event.ColliderBType; |
| | | 52 | | |
| | | 53 | | /// <summary>Gets the first endpoint's 2D collider type.</summary> |
| | 1 | 54 | | public ColliderType2D ColliderA2DType => Event.ColliderA2DType; |
| | | 55 | | |
| | | 56 | | /// <summary>Gets the second endpoint's 2D collider type.</summary> |
| | 1 | 57 | | public ColliderType2D ColliderB2DType => Event.ColliderB2DType; |
| | | 58 | | |
| | | 59 | | /// <summary>Gets the accumulated impulse magnitude for an impulse event.</summary> |
| | 1 | 60 | | public Fixed64 ImpulseMagnitude => Event.ScalarA; |
| | | 61 | | |
| | | 62 | | /// <summary>Gets the limit error reported by an impulse or limit event.</summary> |
| | 2 | 63 | | public Fixed64 LimitError => Kind == GravitasDiagnosticEventKind.JointLimitReached |
| | 2 | 64 | | ? Event.ScalarB |
| | 2 | 65 | | : LimitErrorMagnitude; |
| | | 66 | | |
| | | 67 | | /// <summary>Gets the linear anchor-error magnitude for an impulse event.</summary> |
| | 1 | 68 | | public Fixed64 LinearAnchorErrorMagnitude => Event.ScalarB; |
| | | 69 | | |
| | | 70 | | /// <summary>Gets the motor impulse magnitude for an impulse event.</summary> |
| | 97 | 71 | | public Fixed64 MotorImpulseMagnitude => Event.Vector.X; |
| | | 72 | | |
| | | 73 | | /// <summary>Gets the motor error magnitude for an impulse event.</summary> |
| | 97 | 74 | | public Fixed64 MotorErrorMagnitude => Event.Vector.Y; |
| | | 75 | | |
| | | 76 | | /// <summary>Gets the limit-error magnitude stored by an impulse event.</summary> |
| | 2 | 77 | | public Fixed64 LimitErrorMagnitude => Event.Vector.Z; |
| | | 78 | | |
| | | 79 | | /// <summary>Gets the prepared solver-row count for an impulse event.</summary> |
| | 1 | 80 | | public int RowCount => Event.DataA; |
| | | 81 | | |
| | | 82 | | /// <summary>Gets the clamped solver-row count for an impulse event.</summary> |
| | 97 | 83 | | public int ClampedRowCount => Event.DataB; |
| | | 84 | | } |