Skip to content

Commit e2def40

Browse files
committed
added B2DynamicTreeTest
1 parent 3d36ee8 commit e2def40

File tree

4 files changed

+528
-9
lines changed

4 files changed

+528
-9
lines changed

src/Box2D.NET/B2DynamicTrees.cs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
using System;
66
using System.Runtime.CompilerServices;
7+
using System.Runtime.InteropServices;
78
using static Box2D.NET.B2Constants;
89
using static Box2D.NET.B2Diagnostics;
910
using static Box2D.NET.B2Buffers;
@@ -1084,11 +1085,11 @@ internal static void b2DynamicTree_ValidateNoEnlarged(B2DynamicTree tree)
10841085
[MethodImpl(MethodImplOptions.AggressiveInlining)]
10851086
public static int b2DynamicTree_GetByteCount(B2DynamicTree tree)
10861087
{
1087-
// TODO: @ikpil, check
1088-
// int size = sizeof( b2DynamicTree ) + sizeof( b2TreeNode ) * tree.nodeCapacity +
1089-
// tree.rebuildCapacity * ( sizeof( int ) + sizeof( b2AABB ) + sizeof( B2Vec2 ) + sizeof( int ) );
1090-
//return (int)size;
1091-
return -1;
1088+
// int size = Marshal.SizeOf<B2DynamicTree>() + Marshal.SizeOf<B2TreeNode>() * tree.nodeCapacity +
1089+
// tree.rebuildCapacity * (sizeof(int) + Marshal.SizeOf<B2AABB>() + Marshal.SizeOf<B2Vec2>() + sizeof(int));
1090+
int size = sizeof(int) * 6 + sizeof(ulong) * 4 + Marshal.SizeOf<B2TreeNode>() * tree.nodeCapacity +
1091+
tree.rebuildCapacity * (sizeof(int) + Marshal.SizeOf<B2AABB>() + Marshal.SizeOf<B2Vec2>() + sizeof(int));
1092+
return (int)size;
10921093
}
10931094

10941095
/// Get proxy user data
@@ -1166,7 +1167,7 @@ public static B2TreeStats b2DynamicTree_Query<T>(B2DynamicTree tree, in B2AABB a
11661167
/// Query an AABB for overlapping proxies. The callback class is called for each proxy that overlaps the supplied AABB.
11671168
/// No filtering is performed.
11681169
/// @return performance data
1169-
internal static B2TreeStats b2DynamicTree_QueryAll<T>(B2DynamicTree tree, in B2AABB aabb, b2TreeQueryCallbackFcn<T> callback, ref T context)
1170+
public static B2TreeStats b2DynamicTree_QueryAll<T>(B2DynamicTree tree, in B2AABB aabb, b2TreeQueryCallbackFcn<T> callback, ref T context)
11701171
{
11711172
B2TreeStats result = new B2TreeStats();
11721173

@@ -1232,7 +1233,7 @@ internal static B2TreeStats b2DynamicTree_QueryAll<T>(B2DynamicTree tree, in B2A
12321233
/// @param callback a callback class that is called for each proxy that is hit by the ray
12331234
/// @param context user context that is passed to the callback
12341235
/// @return performance data
1235-
public static B2TreeStats b2DynamicTree_RayCast<T>(B2DynamicTree tree, ref B2RayCastInput input, ulong maskBits,
1236+
public static B2TreeStats b2DynamicTree_RayCast<T>(B2DynamicTree tree, in B2RayCastInput input, ulong maskBits,
12361237
b2TreeRayCastCallbackFcn<T> callback, ref T context) where T : struct
12371238
{
12381239
B2TreeStats result = new B2TreeStats();

src/Box2D.NET/B2FixedArray32.cs

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
// SPDX-FileCopyrightText: 2025 Ikpil Choi([email protected])
2+
// SPDX-License-Identifier: MIT
3+
4+
using System;
5+
using System.Runtime.CompilerServices;
6+
using System.Runtime.InteropServices;
7+
8+
#pragma warning disable CS0169
9+
10+
namespace Box2D.NET
11+
{
12+
[StructLayout(LayoutKind.Sequential)]
13+
public struct B2FixedArray32<T> where T : unmanaged
14+
{
15+
public const int Size = 32;
16+
17+
private T _v0000;
18+
private T _v0001;
19+
private T _v0002;
20+
private T _v0003;
21+
private T _v0004;
22+
private T _v0005;
23+
private T _v0006;
24+
private T _v0007;
25+
private T _v0008;
26+
private T _v0009;
27+
private T _v0010;
28+
private T _v0011;
29+
private T _v0012;
30+
private T _v0013;
31+
private T _v0014;
32+
private T _v0015;
33+
private T _v0016;
34+
private T _v0017;
35+
private T _v0018;
36+
private T _v0019;
37+
private T _v0020;
38+
private T _v0021;
39+
private T _v0022;
40+
private T _v0023;
41+
private T _v0024;
42+
private T _v0025;
43+
private T _v0026;
44+
private T _v0027;
45+
private T _v0028;
46+
private T _v0029;
47+
private T _v0030;
48+
private T _v0031;
49+
50+
public int Length => Size;
51+
52+
public ref T this[int index]
53+
{
54+
[MethodImpl(MethodImplOptions.AggressiveInlining)]
55+
get => ref AsSpan()[index];
56+
}
57+
58+
[MethodImpl(MethodImplOptions.AggressiveInlining)]
59+
public Span<T> AsSpan()
60+
{
61+
return MemoryMarshal.CreateSpan(ref _v0000, Size);
62+
}
63+
64+
}
65+
}

src/Box2D.NET/B2Worlds.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1997,7 +1997,7 @@ public static B2TreeStats b2World_CastRay(B2WorldId worldId, B2Vec2 origin, B2Ve
19971997
for (int i = 0; i < (int)B2BodyType.b2_bodyTypeCount; ++i)
19981998
{
19991999
B2TreeStats treeResult =
2000-
b2DynamicTree_RayCast(world.broadPhase.trees[i], ref input, filter.maskBits, RayCastCallback, ref worldContext);
2000+
b2DynamicTree_RayCast(world.broadPhase.trees[i], input, filter.maskBits, RayCastCallback, ref worldContext);
20012001
treeStats.nodeVisits += treeResult.nodeVisits;
20022002
treeStats.leafVisits += treeResult.leafVisits;
20032003

@@ -2052,7 +2052,7 @@ public static B2RayResult b2World_CastRayClosest(B2WorldId worldId, B2Vec2 origi
20522052
for (int i = 0; i < (int)B2BodyType.b2_bodyTypeCount; ++i)
20532053
{
20542054
B2TreeStats treeResult =
2055-
b2DynamicTree_RayCast(world.broadPhase.trees[i], ref input, filter.maskBits, RayCastCallback, ref worldContext);
2055+
b2DynamicTree_RayCast(world.broadPhase.trees[i], input, filter.maskBits, RayCastCallback, ref worldContext);
20562056
result.nodeVisits += treeResult.nodeVisits;
20572057
result.leafVisits += treeResult.leafVisits;
20582058

0 commit comments

Comments
 (0)