| | | 1 | | //======================================================================= |
| | | 2 | | // ColliderPartitionState2D.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.Runtime.CompilerServices; |
| | | 9 | | using FixedMathSharp; |
| | | 10 | | using GridForge.Spatial; |
| | | 11 | | using SwiftCollections; |
| | | 12 | | |
| | | 13 | | namespace Gravitas.Colliders; |
| | | 14 | | |
| | | 15 | | /// <summary> |
| | | 16 | | /// Tracks planar partition memberships, previous grid bounds, and broad-phase changes. |
| | | 17 | | /// </summary> |
| | | 18 | | internal struct ColliderPartitionState2D |
| | | 19 | | { |
| | | 20 | | public bool IsPartitioned { get; private set; } |
| | | 21 | | |
| | | 22 | | public uint BroadPhaseVersion { get; private set; } |
| | | 23 | | |
| | | 24 | | public Vector2d LastGridBoundsMin { get; private set; } |
| | | 25 | | |
| | | 26 | | public Vector2d LastGridBoundsMax { get; private set; } |
| | | 27 | | |
| | | 28 | | public int LastPartitionKind { get; private set; } |
| | | 29 | | |
| | | 30 | | public SwiftList<WorldVoxelIndex>? Coordinates; |
| | | 31 | | |
| | | 32 | | [MethodImpl(MethodImplOptions.AggressiveInlining)] |
| | 22047 | 33 | | public void MarkBroadPhaseChanged() => BroadPhaseVersion++; |
| | | 34 | | |
| | | 35 | | [MethodImpl(MethodImplOptions.AggressiveInlining)] |
| | | 36 | | public void MarkPartitioned() |
| | | 37 | | { |
| | 22047 | 38 | | IsPartitioned = true; |
| | 22047 | 39 | | MarkBroadPhaseChanged(); |
| | 22047 | 40 | | } |
| | | 41 | | |
| | | 42 | | [MethodImpl(MethodImplOptions.AggressiveInlining)] |
| | 3080 | 43 | | public void MarkUnpartitioned() => IsPartitioned = false; |
| | | 44 | | |
| | | 45 | | [MethodImpl(MethodImplOptions.AggressiveInlining)] |
| | | 46 | | public bool MatchesGridBounds(Vector2d min, Vector2d max, int partitionKind) => |
| | 14916 | 47 | | IsPartitioned |
| | 14916 | 48 | | && LastGridBoundsMin == min |
| | 14916 | 49 | | && LastGridBoundsMax == max |
| | 14916 | 50 | | && LastPartitionKind == partitionKind; |
| | | 51 | | |
| | | 52 | | [MethodImpl(MethodImplOptions.AggressiveInlining)] |
| | | 53 | | public void SetPreviousGridBounds(Vector2d min, Vector2d max, int partitionKind = 0) |
| | | 54 | | { |
| | 22047 | 55 | | LastGridBoundsMin = min; |
| | 22047 | 56 | | LastGridBoundsMax = max; |
| | 22047 | 57 | | LastPartitionKind = partitionKind; |
| | 22047 | 58 | | } |
| | | 59 | | |
| | | 60 | | [MethodImpl(MethodImplOptions.AggressiveInlining)] |
| | 1344 | 61 | | public void ClearCoordinates() => Coordinates?.Clear(); |
| | | 62 | | } |