Skip to content

Commit 5deb43f

Browse files
committed
refactor: B2AABB and B2QueryFilter usage to use 'in' parameters
- Updated BroadPhase and World APIs (e.g., `b2BroadPhase_CreateProxy`, `b2World_OverlapAABB`) to accept `B2AABB` and `B2QueryFilter` as `in` parameters. - Updated `B2WorldQueryContext` constructor and `DrawBounds` helper to use `in` parameters. - This change optimizes performance by reducing struct copying and ensures read-only access to these data structures.
1 parent 5d96ea1 commit 5deb43f

File tree

4 files changed

+6
-6
lines changed

4 files changed

+6
-6
lines changed

src/Box2D.NET.Samples/Graphics/Draws.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ public static void DrawTransform(Draw draw, in B2Transform transform, float scal
7474
AddLine(ref draw.lines, p1, p2, B2HexColor.b2_colorGreen);
7575
}
7676

77-
public static void DrawBounds(Draw draw, B2AABB aabb, B2HexColor c)
77+
public static void DrawBounds(Draw draw, in B2AABB aabb, B2HexColor c)
7878
{
7979
B2Vec2 p1 = aabb.lowerBound;
8080
B2Vec2 p2 = new B2Vec2(aabb.upperBound.X, aabb.lowerBound.Y);

src/Box2D.NET/B2BoardPhases.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ public static void b2UnBufferMove(B2BroadPhase bp, int proxyKey)
130130
}
131131
}
132132

133-
public static int b2BroadPhase_CreateProxy(B2BroadPhase bp, B2BodyType proxyType, B2AABB aabb, ulong categoryBits, int shapeIndex, bool forcePairCreation)
133+
public static int b2BroadPhase_CreateProxy(B2BroadPhase bp, B2BodyType proxyType, in B2AABB aabb, ulong categoryBits, int shapeIndex, bool forcePairCreation)
134134
{
135135
B2_ASSERT(0 <= proxyType && proxyType < B2BodyType.b2_bodyTypeCount);
136136
int proxyId = b2DynamicTree_CreateProxy(bp.trees[(int)proxyType], aabb, categoryBits, (ulong)shapeIndex);
@@ -155,7 +155,7 @@ public static void b2BroadPhase_DestroyProxy(B2BroadPhase bp, int proxyKey)
155155
b2DynamicTree_DestroyProxy(bp.trees[(int)proxyType], proxyId);
156156
}
157157

158-
public static void b2BroadPhase_MoveProxy(B2BroadPhase bp, int proxyKey, B2AABB aabb)
158+
public static void b2BroadPhase_MoveProxy(B2BroadPhase bp, int proxyKey, in B2AABB aabb)
159159
{
160160
B2BodyType proxyType = B2_PROXY_TYPE(proxyKey);
161161
int proxyId = B2_PROXY_ID(proxyKey);
@@ -164,7 +164,7 @@ public static void b2BroadPhase_MoveProxy(B2BroadPhase bp, int proxyKey, B2AABB
164164
b2BufferMove(bp, proxyKey);
165165
}
166166

167-
public static void b2BroadPhase_EnlargeProxy(B2BroadPhase bp, int proxyKey, B2AABB aabb)
167+
public static void b2BroadPhase_EnlargeProxy(B2BroadPhase bp, int proxyKey, in B2AABB aabb)
168168
{
169169
B2_ASSERT(proxyKey != B2_NULL_INDEX);
170170
B2BodyType typeIndex = B2_PROXY_TYPE(proxyKey);

src/Box2D.NET/B2WorldQueryContext.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ public struct B2WorldQueryContext
1111
public B2QueryFilter filter;
1212
public object userContext;
1313

14-
public B2WorldQueryContext(B2World world, b2OverlapResultFcn fcn, B2QueryFilter filter, object userContext)
14+
public B2WorldQueryContext(B2World world, b2OverlapResultFcn fcn, in B2QueryFilter filter, object userContext)
1515
{
1616
this.world = world;
1717
this.fcn = fcn;

src/Box2D.NET/B2Worlds.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1832,7 +1832,7 @@ static bool TreeQueryCallback(int proxyId, ulong userData, ref B2WorldQueryConte
18321832
return result;
18331833
}
18341834

1835-
public static B2TreeStats b2World_OverlapAABB(B2WorldId worldId, B2AABB aabb, B2QueryFilter filter, b2OverlapResultFcn fcn, object context)
1835+
public static B2TreeStats b2World_OverlapAABB(B2WorldId worldId, in B2AABB aabb, in B2QueryFilter filter, b2OverlapResultFcn fcn, object context)
18361836
{
18371837
B2TreeStats treeStats = new B2TreeStats();
18381838

0 commit comments

Comments
 (0)