| | | 1 | | //======================================================================= |
| | | 2 | | // ColliderRuntimeShapeState.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 System; |
| | | 9 | | using System.Runtime.CompilerServices; |
| | | 10 | | |
| | | 11 | | namespace Gravitas.Colliders; |
| | | 12 | | |
| | | 13 | | /// <summary> |
| | | 14 | | /// Tracks the last shape snapshot and determines when 3D runtime geometry needs rebuilding. |
| | | 15 | | /// </summary> |
| | | 16 | | internal class ColliderRuntimeShapeState<TSnapshot> |
| | | 17 | | where TSnapshot : IEquatable<TSnapshot> |
| | | 18 | | { |
| | | 19 | | private TSnapshot _snapshot = default!; |
| | | 20 | | private bool _hasSnapshot; |
| | 24932 | 21 | | private bool _dirty = true; |
| | | 22 | | |
| | | 23 | | public uint RuntimeVersion { get; private set; } |
| | 251536 | 24 | | public bool IsDirty => _dirty; |
| | | 25 | | |
| | | 26 | | [MethodImpl(MethodImplOptions.AggressiveInlining)] |
| | 17350 | 27 | | public void MarkDirty() => _dirty = true; |
| | | 28 | | |
| | | 29 | | [MethodImpl(MethodImplOptions.AggressiveInlining)] |
| | | 30 | | public bool ShouldRebuild(in TSnapshot snapshot) => |
| | 414384 | 31 | | _dirty || !_hasSnapshot || !_snapshot.Equals(snapshot); |
| | | 32 | | |
| | | 33 | | [MethodImpl(MethodImplOptions.AggressiveInlining)] |
| | | 34 | | public void Commit(in TSnapshot snapshot) |
| | | 35 | | { |
| | 219540 | 36 | | _snapshot = snapshot; |
| | 219540 | 37 | | _hasSnapshot = true; |
| | 219540 | 38 | | _dirty = false; |
| | 219540 | 39 | | RuntimeVersion++; |
| | 219540 | 40 | | } |
| | | 41 | | } |