| | | 1 | | //======================================================================= |
| | | 2 | | // PhysicsMixedPartition.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 GridForge.Grids; |
| | | 9 | | using GridForge.Spatial; |
| | | 10 | | using SwiftCollections; |
| | | 11 | | using System.Runtime.CompilerServices; |
| | | 12 | | |
| | | 13 | | namespace Gravitas; |
| | | 14 | | |
| | | 15 | | internal enum MixedPartitionMobilityKind |
| | | 16 | | { |
| | | 17 | | Dynamic = 0, |
| | | 18 | | Kinematic = 1, |
| | | 19 | | Static = 2 |
| | | 20 | | } |
| | | 21 | | |
| | | 22 | | /// <summary> |
| | | 23 | | /// GridForge voxel partition that stores cross-dimensional broad-phase memberships. |
| | | 24 | | /// </summary> |
| | | 25 | | internal sealed class PhysicsMixedPartition : IVoxelPartition, IRetainedPhysicsPartition<GravitasMixedCollisionService> |
| | | 26 | | { |
| | | 27 | | private GravitasMixedCollisionService? _owner; |
| | 28425 | 28 | | private int _emptySinceFrame = -1; |
| | 28425 | 29 | | private int _retainedIndex = -1; |
| | | 30 | | |
| | 28425 | 31 | | public PhysicsMixedPartition() |
| | | 32 | | { |
| | 28425 | 33 | | ActivationId = -1; |
| | 28425 | 34 | | } |
| | | 35 | | |
| | | 36 | | public WorldVoxelIndex WorldIndex { get; set; } |
| | | 37 | | |
| | | 38 | | public bool IsPartitioned { get; set; } |
| | | 39 | | |
| | | 40 | | public SwiftSparseSet? ContainedDynamic3DObjects; |
| | | 41 | | |
| | | 42 | | public SwiftSparseSet? ContainedAwakeDynamic3DObjects; |
| | | 43 | | |
| | | 44 | | public SwiftSparseSet? ContainedKinematic3DObjects; |
| | | 45 | | |
| | | 46 | | public SwiftSparseSet? ContainedStatic3DObjects; |
| | | 47 | | |
| | | 48 | | public SwiftSparseSet? ContainedDynamic2DObjects; |
| | | 49 | | |
| | | 50 | | public SwiftSparseSet? ContainedAwakeDynamic2DObjects; |
| | | 51 | | |
| | | 52 | | public SwiftSparseSet? ContainedKinematic2DObjects; |
| | | 53 | | |
| | | 54 | | public SwiftSparseSet? ContainedStatic2DObjects; |
| | | 55 | | |
| | | 56 | | public int ActivationId { get; private set; } |
| | | 57 | | |
| | 10544 | 58 | | public bool IsAllocated => ActivationId != -1; |
| | | 59 | | |
| | | 60 | | internal bool IsEmpty => |
| | 23176824 | 61 | | (ContainedDynamic3DObjects?.Count ?? 0) == 0 |
| | 23176824 | 62 | | && (ContainedKinematic3DObjects?.Count ?? 0) == 0 |
| | 23176824 | 63 | | && (ContainedStatic3DObjects?.Count ?? 0) == 0 |
| | 23176824 | 64 | | && (ContainedDynamic2DObjects?.Count ?? 0) == 0 |
| | 23176824 | 65 | | && (ContainedKinematic2DObjects?.Count ?? 0) == 0 |
| | 23176824 | 66 | | && (ContainedStatic2DObjects?.Count ?? 0) == 0; |
| | | 67 | | |
| | 2247 | 68 | | internal int EmptySinceFrame => _emptySinceFrame; |
| | | 69 | | |
| | 75705 | 70 | | internal int RetainedIndex => _retainedIndex; |
| | | 71 | | |
| | | 72 | | internal int AwakeDynamicObjectCount => |
| | 4088 | 73 | | (ContainedAwakeDynamic3DObjects?.Count ?? 0) + (ContainedAwakeDynamic2DObjects?.Count ?? 0); |
| | | 74 | | |
| | | 75 | | private int MovableDynamicObjectCount => |
| | 23163 | 76 | | (ContainedDynamic3DObjects?.Count ?? 0) + (ContainedDynamic2DObjects?.Count ?? 0); |
| | | 77 | | |
| | | 78 | | public GravitasMixedCollisionService Owner |
| | | 79 | | { |
| | | 80 | | get |
| | | 81 | | { |
| | 272093 | 82 | | SwiftThrowHelper.ThrowIfTrue( |
| | 272093 | 83 | | _owner == null, |
| | 272093 | 84 | | nameof(PhysicsMixedPartition), |
| | 272093 | 85 | | "PhysicsMixedPartition is missing its owner collision service."); |
| | 272091 | 86 | | return _owner!; |
| | | 87 | | } |
| | | 88 | | } |
| | | 89 | | |
| | | 90 | | public void OnAddToVoxel(Voxel voxel) |
| | | 91 | | { |
| | 37848 | 92 | | SwiftThrowHelper.ThrowIfTrue( |
| | 37848 | 93 | | _owner == null, |
| | 37848 | 94 | | nameof(PhysicsMixedPartition), |
| | 37848 | 95 | | "PhysicsMixedPartition is missing its owner collision service."); |
| | 37848 | 96 | | WorldIndex = voxel.WorldIndex; |
| | 37848 | 97 | | IsPartitioned = true; |
| | 37848 | 98 | | } |
| | | 99 | | |
| | | 100 | | internal void Distribute( |
| | | 101 | | SwiftList<int> dynamic3DIds, |
| | | 102 | | SwiftList<int> kinematic3DIds, |
| | | 103 | | SwiftList<int> static3DIds, |
| | | 104 | | SwiftList<int> dynamic2DIds, |
| | | 105 | | SwiftList<int> kinematic2DIds, |
| | | 106 | | SwiftList<int> static2DIds) |
| | | 107 | | { |
| | 9967 | 108 | | int total3DCount = (ContainedDynamic3DObjects?.Count ?? 0) |
| | 9967 | 109 | | + (ContainedKinematic3DObjects?.Count ?? 0) |
| | 9967 | 110 | | + (ContainedStatic3DObjects?.Count ?? 0); |
| | 9967 | 111 | | int total2DCount = (ContainedDynamic2DObjects?.Count ?? 0) |
| | 9967 | 112 | | + (ContainedKinematic2DObjects?.Count ?? 0) |
| | 9967 | 113 | | + (ContainedStatic2DObjects?.Count ?? 0); |
| | 9967 | 114 | | if (total3DCount == 0 || total2DCount == 0 || AwakeDynamicObjectCount == 0) |
| | 6128 | 115 | | return; |
| | | 116 | | |
| | 3839 | 117 | | CopySortedIds(ContainedDynamic3DObjects, dynamic3DIds); |
| | 3839 | 118 | | CopySortedIds(ContainedKinematic3DObjects, kinematic3DIds); |
| | 3839 | 119 | | CopySortedIds(ContainedStatic3DObjects, static3DIds); |
| | 3839 | 120 | | CopySortedIds(ContainedDynamic2DObjects, dynamic2DIds); |
| | 3839 | 121 | | CopySortedIds(ContainedKinematic2DObjects, kinematic2DIds); |
| | 3839 | 122 | | CopySortedIds(ContainedStatic2DObjects, static2DIds); |
| | | 123 | | |
| | 3839 | 124 | | GravitasMixedCollisionService owner = Owner; |
| | 14794 | 125 | | for (int i = 0; i < dynamic3DIds.Count; i++) |
| | | 126 | | { |
| | 3558 | 127 | | int id3D = dynamic3DIds[i]; |
| | 12432 | 128 | | for (int j = 0; j < dynamic2DIds.Count; j++) |
| | 2658 | 129 | | owner.ProcessPartitionCandidate(id3D, dynamic2DIds[j]); |
| | | 130 | | |
| | 7422 | 131 | | for (int j = 0; j < kinematic2DIds.Count; j++) |
| | 153 | 132 | | owner.ProcessPartitionCandidate(id3D, kinematic2DIds[j]); |
| | | 133 | | |
| | 8844 | 134 | | for (int j = 0; j < static2DIds.Count; j++) |
| | 864 | 135 | | owner.ProcessPartitionCandidate(id3D, static2DIds[j]); |
| | | 136 | | } |
| | | 137 | | |
| | 13520 | 138 | | for (int i = 0; i < dynamic2DIds.Count; i++) |
| | | 139 | | { |
| | 2921 | 140 | | int id2D = dynamic2DIds[i]; |
| | 6094 | 141 | | for (int j = 0; j < kinematic3DIds.Count; j++) |
| | 126 | 142 | | owner.ProcessPartitionCandidate(kinematic3DIds[j], id2D); |
| | | 143 | | |
| | 7106 | 144 | | for (int j = 0; j < static3DIds.Count; j++) |
| | 632 | 145 | | owner.ProcessPartitionCandidate(static3DIds[j], id2D); |
| | | 146 | | } |
| | 3839 | 147 | | } |
| | | 148 | | |
| | | 149 | | public void AddDynamic3DObject(int id) |
| | | 150 | | { |
| | 10255 | 151 | | ContainedDynamic3DObjects ??= Owner.RentPartitionMembership(); |
| | 10255 | 152 | | bool shouldActivate = MovableDynamicObjectCount == 0; |
| | 10255 | 153 | | if (!ContainedDynamic3DObjects.Add(id)) |
| | 2 | 154 | | return; |
| | | 155 | | |
| | 10253 | 156 | | MarkOccupied(); |
| | 10253 | 157 | | SetDynamic3DObjectAwake(id, IsDynamic3DObjectAwake(id)); |
| | 10253 | 158 | | if (shouldActivate) |
| | 9154 | 159 | | ActivationId = Owner.ActivatePartition(this); |
| | 10253 | 160 | | } |
| | | 161 | | |
| | | 162 | | public void AddStatic3DObject(int id) |
| | | 163 | | { |
| | 32614 | 164 | | ContainedStatic3DObjects ??= Owner.RentPartitionMembership(); |
| | 32614 | 165 | | if (ContainedStatic3DObjects.Add(id)) |
| | 32613 | 166 | | MarkOccupied(); |
| | 32614 | 167 | | } |
| | | 168 | | |
| | | 169 | | public void AddKinematic3DObject(int id) |
| | | 170 | | { |
| | 9670 | 171 | | ContainedKinematic3DObjects ??= Owner.RentPartitionMembership(); |
| | 9670 | 172 | | if (ContainedKinematic3DObjects.Add(id)) |
| | 9669 | 173 | | MarkOccupied(); |
| | 9670 | 174 | | } |
| | | 175 | | |
| | | 176 | | public void AddDynamic2DObject(int id) |
| | | 177 | | { |
| | 6670 | 178 | | ContainedDynamic2DObjects ??= Owner.RentPartitionMembership(); |
| | 6670 | 179 | | bool shouldActivate = MovableDynamicObjectCount == 0; |
| | 6670 | 180 | | if (!ContainedDynamic2DObjects.Add(id)) |
| | 2 | 181 | | return; |
| | | 182 | | |
| | 6668 | 183 | | MarkOccupied(); |
| | 6668 | 184 | | SetDynamic2DObjectAwake(id, IsDynamic2DObjectAwake(id)); |
| | 6668 | 185 | | if (shouldActivate) |
| | 3978 | 186 | | ActivationId = Owner.ActivatePartition(this); |
| | 6668 | 187 | | } |
| | | 188 | | |
| | | 189 | | public void AddStatic2DObject(int id) |
| | | 190 | | { |
| | 4875 | 191 | | ContainedStatic2DObjects ??= Owner.RentPartitionMembership(); |
| | 4875 | 192 | | if (ContainedStatic2DObjects.Add(id)) |
| | 4874 | 193 | | MarkOccupied(); |
| | 4875 | 194 | | } |
| | | 195 | | |
| | | 196 | | public void AddKinematic2DObject(int id) |
| | | 197 | | { |
| | 3842 | 198 | | ContainedKinematic2DObjects ??= Owner.RentPartitionMembership(); |
| | 3842 | 199 | | if (ContainedKinematic2DObjects.Add(id)) |
| | 3841 | 200 | | MarkOccupied(); |
| | 3842 | 201 | | } |
| | | 202 | | |
| | | 203 | | public void RemoveDynamic3DObject(int id) |
| | | 204 | | { |
| | 3874 | 205 | | if (ContainedDynamic3DObjects?.Remove(id) != true) |
| | 3 | 206 | | return; |
| | | 207 | | |
| | 3871 | 208 | | RemoveAndReleaseIfEmpty(ref ContainedAwakeDynamic3DObjects, id); |
| | 3871 | 209 | | ReleaseIfEmpty(ref ContainedDynamic3DObjects); |
| | 3871 | 210 | | DeactivateIfNoDynamicMembers(); |
| | 3871 | 211 | | MarkEmptyIfUnoccupied(); |
| | 3871 | 212 | | } |
| | | 213 | | |
| | | 214 | | public void RemoveStatic3DObject(int id) |
| | | 215 | | { |
| | 859 | 216 | | if (ContainedStatic3DObjects?.Remove(id) == true) |
| | | 217 | | { |
| | 856 | 218 | | ReleaseIfEmpty(ref ContainedStatic3DObjects); |
| | 856 | 219 | | MarkEmptyIfUnoccupied(); |
| | | 220 | | } |
| | 859 | 221 | | } |
| | | 222 | | |
| | | 223 | | public void RemoveKinematic3DObject(int id) |
| | | 224 | | { |
| | 6485 | 225 | | if (ContainedKinematic3DObjects?.Remove(id) == true) |
| | | 226 | | { |
| | 6482 | 227 | | ReleaseIfEmpty(ref ContainedKinematic3DObjects); |
| | 6482 | 228 | | MarkEmptyIfUnoccupied(); |
| | | 229 | | } |
| | 6485 | 230 | | } |
| | | 231 | | |
| | | 232 | | public void RemoveDynamic2DObject(int id) |
| | | 233 | | { |
| | 2370 | 234 | | if (ContainedDynamic2DObjects?.Remove(id) != true) |
| | 3 | 235 | | return; |
| | | 236 | | |
| | 2367 | 237 | | RemoveAndReleaseIfEmpty(ref ContainedAwakeDynamic2DObjects, id); |
| | 2367 | 238 | | ReleaseIfEmpty(ref ContainedDynamic2DObjects); |
| | 2367 | 239 | | DeactivateIfNoDynamicMembers(); |
| | 2367 | 240 | | MarkEmptyIfUnoccupied(); |
| | 2367 | 241 | | } |
| | | 242 | | |
| | | 243 | | public void RemoveStatic2DObject(int id) |
| | | 244 | | { |
| | 293 | 245 | | if (ContainedStatic2DObjects?.Remove(id) == true) |
| | | 246 | | { |
| | 290 | 247 | | ReleaseIfEmpty(ref ContainedStatic2DObjects); |
| | 290 | 248 | | MarkEmptyIfUnoccupied(); |
| | | 249 | | } |
| | 293 | 250 | | } |
| | | 251 | | |
| | | 252 | | public void RemoveKinematic2DObject(int id) |
| | | 253 | | { |
| | 2399 | 254 | | if (ContainedKinematic2DObjects?.Remove(id) == true) |
| | | 255 | | { |
| | 2396 | 256 | | ReleaseIfEmpty(ref ContainedKinematic2DObjects); |
| | 2396 | 257 | | MarkEmptyIfUnoccupied(); |
| | | 258 | | } |
| | 2399 | 259 | | } |
| | | 260 | | |
| | | 261 | | public void SetDynamic3DObjectAwake(int id, bool awake) |
| | | 262 | | { |
| | 18064 | 263 | | if (ContainedDynamic3DObjects?.Contains(id) != true) |
| | 5513 | 264 | | return; |
| | | 265 | | |
| | 12551 | 266 | | if (awake) |
| | | 267 | | { |
| | 11018 | 268 | | ContainedAwakeDynamic3DObjects ??= Owner.RentPartitionMembership(); |
| | 11018 | 269 | | ContainedAwakeDynamic3DObjects.Add(id); |
| | 11018 | 270 | | return; |
| | | 271 | | } |
| | | 272 | | |
| | 1533 | 273 | | RemoveAndReleaseIfEmpty(ref ContainedAwakeDynamic3DObjects, id); |
| | 1533 | 274 | | } |
| | | 275 | | |
| | | 276 | | public void SetDynamic2DObjectAwake(int id, bool awake) |
| | | 277 | | { |
| | 8211 | 278 | | if (ContainedDynamic2DObjects?.Contains(id) != true) |
| | 29 | 279 | | return; |
| | | 280 | | |
| | 8182 | 281 | | if (awake) |
| | | 282 | | { |
| | 6107 | 283 | | ContainedAwakeDynamic2DObjects ??= Owner.RentPartitionMembership(); |
| | 6107 | 284 | | ContainedAwakeDynamic2DObjects.Add(id); |
| | 6107 | 285 | | return; |
| | | 286 | | } |
| | | 287 | | |
| | 2075 | 288 | | RemoveAndReleaseIfEmpty(ref ContainedAwakeDynamic2DObjects, id); |
| | 2075 | 289 | | } |
| | | 290 | | |
| | | 291 | | public void OnRemoveFromVoxel(Voxel voxel) |
| | | 292 | | { |
| | 37848 | 293 | | Owner.ReleasePartition(this); |
| | 37848 | 294 | | } |
| | | 295 | | |
| | | 296 | | internal void SetOwner(GravitasMixedCollisionService owner) |
| | | 297 | | { |
| | 37864 | 298 | | SwiftThrowHelper.ThrowIfNull(owner, nameof(owner)); |
| | 37864 | 299 | | SwiftThrowHelper.ThrowIfArgument( |
| | 37864 | 300 | | _owner != null && !ReferenceEquals(_owner, owner), |
| | 37864 | 301 | | nameof(owner), |
| | 37864 | 302 | | "PhysicsMixedPartition is already owned by a different collision service."); |
| | | 303 | | |
| | 37863 | 304 | | _owner = owner; |
| | 37863 | 305 | | } |
| | | 306 | | |
| | 23100429 | 307 | | internal bool IsOwnedBy(GravitasMixedCollisionService owner) => ReferenceEquals(_owner, owner); |
| | | 308 | | |
| | | 309 | | [MethodImpl(MethodImplOptions.AggressiveInlining)] |
| | | 310 | | internal void SetRetainedIndex(int index) |
| | | 311 | | { |
| | 63919 | 312 | | SwiftThrowHelper.ThrowIfNegative(index, nameof(index)); |
| | 63919 | 313 | | _retainedIndex = index; |
| | 63919 | 314 | | } |
| | | 315 | | |
| | | 316 | | [MethodImpl(MethodImplOptions.AggressiveInlining)] |
| | 37857 | 317 | | internal void ClearRetainedIndex() => _retainedIndex = -1; |
| | | 318 | | |
| | 75705 | 319 | | int IRetainedPhysicsPartition<GravitasMixedCollisionService>.RetainedIndex => RetainedIndex; |
| | | 320 | | |
| | 23100257 | 321 | | bool IRetainedPhysicsPartition<GravitasMixedCollisionService>.IsEmpty => IsEmpty; |
| | | 322 | | |
| | 2242 | 323 | | int IRetainedPhysicsPartition<GravitasMixedCollisionService>.EmptySinceFrame => EmptySinceFrame; |
| | | 324 | | |
| | 23100429 | 325 | | bool IRetainedPhysicsPartition<GravitasMixedCollisionService>.IsOwnedBy(GravitasMixedCollisionService owner) => IsOw |
| | | 326 | | |
| | 63919 | 327 | | void IRetainedPhysicsPartition<GravitasMixedCollisionService>.SetRetainedIndex(int index) => SetRetainedIndex(index) |
| | | 328 | | |
| | 37857 | 329 | | void IRetainedPhysicsPartition<GravitasMixedCollisionService>.ClearRetainedIndex() => ClearRetainedIndex(); |
| | | 330 | | |
| | | 331 | | internal void ResetRetainedMembership() |
| | | 332 | | { |
| | 1 | 333 | | ReleaseAllMembership(); |
| | 1 | 334 | | ActivationId = -1; |
| | 1 | 335 | | MarkEmpty(Owner.Context.FrameCount); |
| | 1 | 336 | | } |
| | | 337 | | |
| | | 338 | | internal void ResetForPool() |
| | | 339 | | { |
| | 37859 | 340 | | if (ActivationId != -1) |
| | 8391 | 341 | | Owner.DeactivatePartition(ActivationId); |
| | | 342 | | |
| | 37859 | 343 | | ReleaseAllMembership(); |
| | 37859 | 344 | | _owner = null; |
| | 37859 | 345 | | ActivationId = -1; |
| | 37859 | 346 | | IsPartitioned = false; |
| | 37859 | 347 | | _emptySinceFrame = -1; |
| | 37859 | 348 | | _retainedIndex = -1; |
| | 37859 | 349 | | } |
| | | 350 | | |
| | 37848 | 351 | | public void SetParentIndex(WorldVoxelIndex parentIndex) => WorldIndex = parentIndex; |
| | | 352 | | |
| | | 353 | | internal void Copy3DColliderIds(SwiftList<int> destination) |
| | | 354 | | { |
| | 25574 | 355 | | destination.FastClear(); |
| | 25574 | 356 | | AppendIds(ContainedDynamic3DObjects, destination); |
| | 25574 | 357 | | AppendIds(ContainedKinematic3DObjects, destination); |
| | 25574 | 358 | | AppendIds(ContainedStatic3DObjects, destination); |
| | 25574 | 359 | | destination.SortInPlace(); |
| | 25574 | 360 | | } |
| | | 361 | | |
| | | 362 | | internal void Copy2DColliderIds(SwiftList<int> destination) |
| | | 363 | | { |
| | 15936 | 364 | | destination.FastClear(); |
| | 15936 | 365 | | AppendIds(ContainedDynamic2DObjects, destination); |
| | 15936 | 366 | | AppendIds(ContainedKinematic2DObjects, destination); |
| | 15936 | 367 | | AppendIds(ContainedStatic2DObjects, destination); |
| | 15936 | 368 | | destination.SortInPlace(); |
| | 15936 | 369 | | } |
| | | 370 | | |
| | | 371 | | internal void CopyStaticStyle3DColliderIds(SwiftList<int> destination) |
| | | 372 | | { |
| | 7277 | 373 | | destination.FastClear(); |
| | 7277 | 374 | | AppendIds(ContainedKinematic3DObjects, destination); |
| | 7277 | 375 | | AppendIds(ContainedStatic3DObjects, destination); |
| | 7277 | 376 | | destination.SortInPlace(); |
| | 7277 | 377 | | } |
| | | 378 | | |
| | | 379 | | internal void CopyStaticStyle2DColliderIds(SwiftList<int> destination) |
| | | 380 | | { |
| | 11387 | 381 | | destination.FastClear(); |
| | 11387 | 382 | | AppendIds(ContainedKinematic2DObjects, destination); |
| | 11387 | 383 | | AppendIds(ContainedStatic2DObjects, destination); |
| | 11387 | 384 | | destination.SortInPlace(); |
| | 11387 | 385 | | } |
| | | 386 | | |
| | | 387 | | private static void AppendIds(SwiftSparseSet? source, SwiftList<int> destination) |
| | | 388 | | { |
| | 161858 | 389 | | if (source == null) |
| | 126682 | 390 | | return; |
| | | 391 | | |
| | 150012 | 392 | | for (int i = 0; i < source.Count; i++) |
| | 39830 | 393 | | destination.Add(source.DenseKeys[i]); |
| | 35176 | 394 | | } |
| | | 395 | | |
| | | 396 | | private static void CopySortedIds(SwiftSparseSet? source, SwiftList<int> destination) |
| | | 397 | | { |
| | 23034 | 398 | | if (source == null) |
| | | 399 | | { |
| | 15336 | 400 | | destination.FastClear(); |
| | 15336 | 401 | | return; |
| | | 402 | | } |
| | | 403 | | |
| | 7698 | 404 | | source.CopySortedKeysTo(destination); |
| | 7698 | 405 | | } |
| | | 406 | | |
| | | 407 | | [MethodImpl(MethodImplOptions.AggressiveInlining)] |
| | | 408 | | private void RemoveAndReleaseIfEmpty(ref SwiftSparseSet? membership, int id) |
| | | 409 | | { |
| | 9846 | 410 | | membership?.Remove(id); |
| | 9846 | 411 | | ReleaseIfEmpty(ref membership); |
| | 9846 | 412 | | } |
| | | 413 | | |
| | | 414 | | [MethodImpl(MethodImplOptions.AggressiveInlining)] |
| | | 415 | | private void ReleaseIfEmpty(ref SwiftSparseSet? membership) |
| | | 416 | | { |
| | 26108 | 417 | | if (membership?.Count == 0) |
| | 22375 | 418 | | Owner.ReleasePartitionMembership(ref membership); |
| | 26108 | 419 | | } |
| | | 420 | | |
| | | 421 | | private void ReleaseAllMembership() |
| | | 422 | | { |
| | 37860 | 423 | | GravitasMixedCollisionService owner = Owner; |
| | 37860 | 424 | | owner.ReleasePartitionMembership(ref ContainedDynamic3DObjects); |
| | 37860 | 425 | | owner.ReleasePartitionMembership(ref ContainedAwakeDynamic3DObjects); |
| | 37860 | 426 | | owner.ReleasePartitionMembership(ref ContainedKinematic3DObjects); |
| | 37860 | 427 | | owner.ReleasePartitionMembership(ref ContainedStatic3DObjects); |
| | 37860 | 428 | | owner.ReleasePartitionMembership(ref ContainedDynamic2DObjects); |
| | 37860 | 429 | | owner.ReleasePartitionMembership(ref ContainedAwakeDynamic2DObjects); |
| | 37860 | 430 | | owner.ReleasePartitionMembership(ref ContainedKinematic2DObjects); |
| | 37860 | 431 | | owner.ReleasePartitionMembership(ref ContainedStatic2DObjects); |
| | 37860 | 432 | | } |
| | | 433 | | |
| | | 434 | | private bool IsDynamic3DObjectAwake(int id) |
| | | 435 | | { |
| | 10253 | 436 | | if (!Owner.Context.Physics.TryGetColliderById(id, out Gravitas.Colliders.LSCollider? collider)) |
| | 6 | 437 | | return true; |
| | | 438 | | |
| | 10247 | 439 | | SolidBody? body = collider!.Body; |
| | 10247 | 440 | | return body == null || body.IsAwakeForCollision; |
| | | 441 | | } |
| | | 442 | | |
| | | 443 | | private bool IsDynamic2DObjectAwake(int id) |
| | | 444 | | { |
| | 6668 | 445 | | if (!Owner.Context.Physics2D.TryGetColliderById(id, out Gravitas.Colliders.LSCollider2D? collider)) |
| | 4 | 446 | | return true; |
| | | 447 | | |
| | 6664 | 448 | | SolidBody2D? body = collider!.Body; |
| | 6664 | 449 | | return body == null || body.IsAwakeForCollision; |
| | | 450 | | } |
| | | 451 | | |
| | | 452 | | [MethodImpl(MethodImplOptions.AggressiveInlining)] |
| | | 453 | | private void DeactivateIfNoDynamicMembers() |
| | | 454 | | { |
| | 6238 | 455 | | if (MovableDynamicObjectCount > 0) |
| | 1498 | 456 | | return; |
| | | 457 | | |
| | 4740 | 458 | | Owner.DeactivatePartition(ActivationId); |
| | 4740 | 459 | | ActivationId = -1; |
| | 4740 | 460 | | } |
| | | 461 | | |
| | | 462 | | [MethodImpl(MethodImplOptions.AggressiveInlining)] |
| | 67918 | 463 | | private void MarkOccupied() => _emptySinceFrame = -1; |
| | | 464 | | |
| | | 465 | | [MethodImpl(MethodImplOptions.AggressiveInlining)] |
| | | 466 | | private void MarkEmptyIfUnoccupied() |
| | | 467 | | { |
| | 16262 | 468 | | if (IsEmpty) |
| | 14206 | 469 | | MarkEmpty(Owner.Context.FrameCount); |
| | 16262 | 470 | | } |
| | | 471 | | |
| | | 472 | | [MethodImpl(MethodImplOptions.AggressiveInlining)] |
| | 14207 | 473 | | private void MarkEmpty(int frame) => _emptySinceFrame = frame; |
| | | 474 | | } |