| | | 1 | | //======================================================================= |
| | | 2 | | // SolverContactBuffer2D.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 System.Runtime.CompilerServices; |
| | | 10 | | |
| | | 11 | | namespace Gravitas.CollisionHandling; |
| | | 12 | | |
| | | 13 | | /// <summary> |
| | | 14 | | /// Fixed-capacity pure 2D solver contact buffer. |
| | | 15 | | /// </summary> |
| | | 16 | | internal struct SolverContactBuffer2D |
| | | 17 | | { |
| | | 18 | | private SolverContact2D _contact0; |
| | | 19 | | private SolverContact2D _contact1; |
| | | 20 | | private Fixed64 _normalImpulse0; |
| | | 21 | | private Fixed64 _normalImpulse1; |
| | | 22 | | private ContactNormalImpulseResult2D _normalResult0; |
| | | 23 | | private ContactNormalImpulseResult2D _normalResult1; |
| | | 24 | | private Fixed64 _tangentImpulse0; |
| | | 25 | | private Fixed64 _tangentImpulse1; |
| | | 26 | | |
| | | 27 | | public int Count { get; private set; } |
| | | 28 | | |
| | | 29 | | public void Add(SolverContact2D contact) |
| | | 30 | | { |
| | 1011 | 31 | | if (Count == 0) |
| | 991 | 32 | | _contact0 = contact; |
| | | 33 | | else |
| | 20 | 34 | | _contact1 = contact; |
| | | 35 | | |
| | 1011 | 36 | | Count++; |
| | 1011 | 37 | | } |
| | | 38 | | |
| | | 39 | | [MethodImpl(MethodImplOptions.AggressiveInlining)] |
| | 5107 | 40 | | public SolverContact2D GetContact(int index) => index == 0 ? _contact0 : _contact1; |
| | | 41 | | |
| | | 42 | | [MethodImpl(MethodImplOptions.AggressiveInlining)] |
| | 2008 | 43 | | public Fixed64 GetNormalImpulse(int index) => index == 0 ? _normalImpulse0 : _normalImpulse1; |
| | | 44 | | |
| | | 45 | | [MethodImpl(MethodImplOptions.AggressiveInlining)] |
| | | 46 | | public ContactNormalImpulseResult2D GetNormalResult(int index) => |
| | 2011 | 47 | | index == 0 ? _normalResult0 : _normalResult1; |
| | | 48 | | |
| | | 49 | | [MethodImpl(MethodImplOptions.AggressiveInlining)] |
| | 1003 | 50 | | public Fixed64 GetTangentImpulse(int index) => index == 0 ? _tangentImpulse0 : _tangentImpulse1; |
| | | 51 | | |
| | | 52 | | [MethodImpl(MethodImplOptions.AggressiveInlining)] |
| | | 53 | | public void SetNormalImpulse( |
| | | 54 | | int index, |
| | | 55 | | Fixed64 impulse, |
| | | 56 | | ContactNormalImpulseResult2D normalResult) |
| | | 57 | | { |
| | 1006 | 58 | | if (index == 0) |
| | | 59 | | { |
| | 987 | 60 | | _normalImpulse0 = impulse; |
| | 987 | 61 | | _normalResult0 = normalResult; |
| | 987 | 62 | | return; |
| | | 63 | | } |
| | | 64 | | |
| | 19 | 65 | | _normalImpulse1 = impulse; |
| | 19 | 66 | | _normalResult1 = normalResult; |
| | 19 | 67 | | } |
| | | 68 | | |
| | | 69 | | public void SetTangentImpulse(int index, Fixed64 impulse) |
| | | 70 | | { |
| | 1003 | 71 | | if (index == 0) |
| | | 72 | | { |
| | 984 | 73 | | _tangentImpulse0 = impulse; |
| | 984 | 74 | | return; |
| | | 75 | | } |
| | | 76 | | |
| | 19 | 77 | | _tangentImpulse1 = impulse; |
| | 19 | 78 | | } |
| | | 79 | | } |