| | | 1 | | //======================================================================= |
| | | 2 | | // ContinuousCollisionMode.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 SwiftCollections; |
| | | 9 | | using System.Runtime.CompilerServices; |
| | | 10 | | |
| | | 11 | | namespace Gravitas; |
| | | 12 | | |
| | | 13 | | /// <summary> |
| | | 14 | | /// Selects how a body guards its frame movement against tunneling. |
| | | 15 | | /// </summary> |
| | | 16 | | public enum ContinuousCollisionMode : byte |
| | | 17 | | { |
| | | 18 | | /// <summary> |
| | | 19 | | /// Uses the owning context's default continuous-collision mode. |
| | | 20 | | /// </summary> |
| | | 21 | | Inherit = 0, |
| | | 22 | | |
| | | 23 | | /// <summary> |
| | | 24 | | /// Uses the existing discrete integration path without a movement sweep. |
| | | 25 | | /// </summary> |
| | | 26 | | Discrete = 1, |
| | | 27 | | |
| | | 28 | | /// <summary> |
| | | 29 | | /// Sweeps the body through its intended frame displacement before committing position. |
| | | 30 | | /// </summary> |
| | | 31 | | Continuous = 2, |
| | | 32 | | |
| | | 33 | | /// <summary> |
| | | 34 | | /// Sweeps only when the intended frame displacement is larger than the body proxy radius. |
| | | 35 | | /// </summary> |
| | | 36 | | Auto = 3 |
| | | 37 | | } |
| | | 38 | | |
| | | 39 | | internal static class ContinuousCollisionModeSupport |
| | | 40 | | { |
| | | 41 | | [MethodImpl(MethodImplOptions.AggressiveInlining)] |
| | | 42 | | internal static bool IsValid(this ContinuousCollisionMode mode) => |
| | 1101 | 43 | | (byte)mode <= (byte)ContinuousCollisionMode.Auto; |
| | | 44 | | |
| | | 45 | | [MethodImpl(MethodImplOptions.AggressiveInlining)] |
| | | 46 | | internal static void ThrowIfInvalid(this ContinuousCollisionMode mode, string parameterName) |
| | | 47 | | { |
| | 1101 | 48 | | SwiftThrowHelper.ThrowIfArgumentOutOfRange( |
| | 1101 | 49 | | !mode.IsValid(), |
| | 1101 | 50 | | (int)mode, |
| | 1101 | 51 | | parameterName, |
| | 1101 | 52 | | "Continuous collision mode must be Inherit, Discrete, Continuous, or Auto."); |
| | 1089 | 53 | | } |
| | | 54 | | } |