Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/Box2D.NET.Samples/Box2D.NET.Samples.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@
<PropertyGroup Condition="'$(Configuration)' == 'Release'">
<DefineConstants>$(DefineConstants);ENABLED</DefineConstants>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)' == 'Debug'">
<DefineConstants>$(DefineConstants);B2_SNOOP_TOI_COUNTERS;ENABLED</DefineConstants>
<DefineConstants>$(DefineConstants);B2_SNOOP_TOI_COUNTERS;ENABLED;B2_SNOOP_TABLE_COUNTERS;B2_SNOOP_PAIR_COUNTERS</DefineConstants>
</PropertyGroup>

<ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion src/Box2D.NET.Samples/Samples/Benchmarks/BenchmarkSmash.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public override void UpdateGui()
float height = 110.0f;
ImGui.SetNextWindowPos(new Vector2(10.0f, m_context.camera.m_height - height - 50.0f), ImGuiCond.Once);
ImGui.SetNextWindowSize(new Vector2(220.0f, height));
ImGui.Begin("Benchmark: Barrel", ImGuiWindowFlags.NoResize);
ImGui.Begin("Benchmark: Smash", ImGuiWindowFlags.NoResize);

bool changed = false;
if (ImGui.SliderInt("rows", ref m_rowCount, 1, MaxRowCount, "%d"))
Expand Down
8 changes: 8 additions & 0 deletions src/Box2D.NET.Shared/Box2D.NET.Shared.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,14 @@
<PackageReleaseNotes>https://github.com/ikpil/Box2D.NET/blob/main/CHANGELOG.md</PackageReleaseNotes>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)' == 'Release'">
<DefineConstants>$(DefineConstants);ENABLED</DefineConstants>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)' == 'Debug'">
<DefineConstants>$(DefineConstants);B2_SNOOP_TOI_COUNTERS;ENABLED;B2_SNOOP_TABLE_COUNTERS;B2_SNOOP_PAIR_COUNTERS</DefineConstants>
</PropertyGroup>

<ItemGroup>
<None Include="../../README.md" Pack="true" PackagePath="\"/>
</ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion src/Box2D.NET/B2BoardPhases.cs
Original file line number Diff line number Diff line change
Expand Up @@ -523,7 +523,7 @@ public static void b2ValidateBroadphase(B2BroadPhase bp)

public static void b2ValidateNoEnlarged(B2BroadPhase bp)
{
#if B2_VALIDATE
#if DEBUG
for (int j = 0; j < (int)B2BodyType.b2_bodyTypeCount; ++j)
{
B2DynamicTree tree = bp.trees[j];
Expand Down
4 changes: 2 additions & 2 deletions src/Box2D.NET/B2ContactSim.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public class B2ContactSim
{
public int contactId;

#if B2_VALIDATE
#if DEBUG
public int bodyIdA;
public int bodyIdB;
#endif
Expand Down Expand Up @@ -45,7 +45,7 @@ public void CopyFrom(B2ContactSim other)
{
contactId = other.contactId;

#if B2_VALIDATE
#if DEBUG
bodyIdA = other.bodyIdA;
bodyIdB = other.bodyIdB;
#endif
Expand Down
8 changes: 4 additions & 4 deletions src/Box2D.NET/B2ContactSolvers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public static void b2PrepareOverflowContacts(B2StepContext context)
B2ContactSim[] contacts = color.contactSims.data;
B2BodyState[] awakeStates = context.states;

#if B2_VALIDATE
#if DEBUG
B2Body[] bodies = world.bodies.data;
#endif

Expand All @@ -61,7 +61,7 @@ public static void b2PrepareOverflowContacts(B2StepContext context)
int indexA = contactSim.bodySimIndexA;
int indexB = contactSim.bodySimIndexB;

#if B2_VALIDATE
#if DEBUG
B2Body bodyA = bodies[contactSim.bodyIdA];
int validIndexA = bodyA.setIndex == (int)B2SetType.b2_awakeSet ? bodyA.localIndex : B2_NULL_INDEX;
B2_ASSERT(indexA == validIndexA);
Expand Down Expand Up @@ -1123,7 +1123,7 @@ public static void b2PrepareContactsTask(int startIndex, int endIndex, B2StepCon
Span<B2ContactSim> contacts = context.contacts;
Span<B2ContactConstraintSIMD> constraints = context.simdContactConstraints;
B2BodyState[] awakeStates = context.states;
#if B2_VALIDATE
#if DEBUG
B2Body[] bodies = world.bodies.data;
#endif

Expand All @@ -1148,7 +1148,7 @@ public static void b2PrepareContactsTask(int startIndex, int endIndex, B2StepCon
int indexA = contactSim.bodySimIndexA;
int indexB = contactSim.bodySimIndexB;

#if B2_VALIDATE
#if DEBUG
B2Body bodyA = bodies[contactSim.bodyIdA];
int validIndexA = bodyA.setIndex == (int)B2SetType.b2_awakeSet ? bodyA.localIndex : B2_NULL_INDEX;
B2Body bodyB = bodies[contactSim.bodyIdB];
Expand Down
2 changes: 1 addition & 1 deletion src/Box2D.NET/B2Contacts.cs
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ public static void b2CreateContact(B2World world, B2Shape shapeA, B2Shape shapeB
ref B2ContactSim contactSim = ref b2Array_Add(ref set.contactSims);
contactSim.contactId = contactId;

#if B2_VALIDATE
#if DEBUG
contactSim.bodyIdA = shapeA.bodyId;
contactSim.bodyIdB = shapeB.bodyId;
#endif
Expand Down
8 changes: 4 additions & 4 deletions src/Box2D.NET/B2DynamicTrees.cs
Original file line number Diff line number Diff line change
Expand Up @@ -921,7 +921,7 @@ public static B2AABB b2DynamicTree_GetRootBounds(B2DynamicTree tree)
return empty;
}

#if B2_VALIDATE
#if DEBUG
// Compute the height of a sub-tree.
public static int b2ComputeHeight(B2DynamicTree tree, int nodeId)
{
Expand Down Expand Up @@ -1025,7 +1025,7 @@ public static void b2ValidateMetrics(B2DynamicTree tree, int index)
/// Validate this tree. For testing.
public static void b2DynamicTree_Validate(B2DynamicTree tree)
{
#if B2_VALIDATE
#if DEBUG
if (tree.root == B2_NULL_INDEX)
{
return;
Expand Down Expand Up @@ -1056,7 +1056,7 @@ public static void b2DynamicTree_Validate(B2DynamicTree tree)
/// Validate this tree has no enlarged AABBs. For testing.
public static void b2DynamicTree_ValidateNoEnlarged(B2DynamicTree tree)
{
#if B2_VALIDATE
#if DEBUG
int capacity = tree.nodeCapacity;
B2TreeNode[] nodes = tree.nodes;
for (int i = 0; i < capacity; ++i)
Expand Down Expand Up @@ -1986,7 +1986,7 @@ public static int b2DynamicTree_Rebuild(B2DynamicTree tree, bool fullBuild)
node = ref nodes[nodeIndex];
}

#if B2_VALIDATE
#if DEBUG
int capacity = tree.nodeCapacity;
for (int i = 0; i < capacity; ++i)
{
Expand Down
2 changes: 1 addition & 1 deletion src/Box2D.NET/B2IdPools.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public static void b2FreeId(B2IdPool pool, int id)
b2Array_Push(ref pool.freeArray, id);
}

#if B2_VALIDATE
#if DEBUG
public static void b2ValidateFreeId(B2IdPool pool, int id)
{
int freeCount = pool.freeArray.count;
Expand Down
2 changes: 1 addition & 1 deletion src/Box2D.NET/B2Islands.cs
Original file line number Diff line number Diff line change
Expand Up @@ -881,7 +881,7 @@ public static void b2SplitIslandTask(int startIndex, int endIndex, uint threadIn
b2TracyCZoneEnd(B2TracyCZone.split);
}

#if B2_VALIDATE
#if DEBUG
public static void b2ValidateIsland(B2World world, int islandId)
{
B2Island island = b2Array_Get(ref world.islands, islandId);
Expand Down
2 changes: 1 addition & 1 deletion src/Box2D.NET/B2Worlds.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2775,7 +2775,7 @@ public static void b2World_EnableSpeculative(B2WorldId worldId, bool flag)
world.enableSpeculative = flag;
}

#if B2_VALIDATE
#if DEBUG
// When validating islands ids I have to compare the root island
// ids because islands are not merged until the next time step.
public static int b2GetRootIslandId(B2World world, int islandId)
Expand Down
2 changes: 1 addition & 1 deletion src/Box2D.NET/Box2D.NET.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)' == 'Debug'">
<DefineConstants>$(DefineConstants);B2_SNOOP_TOI_COUNTERS;B2_VALIDATE;ENABLED;B2_SNOOP_TABLE_COUNTERS;B2_SNOOP_PAIR_COUNTERS;B2_SNOOP_TOI_COUNTERS</DefineConstants>
<DefineConstants>$(DefineConstants);B2_SNOOP_TOI_COUNTERS;ENABLED;B2_SNOOP_TABLE_COUNTERS;B2_SNOOP_PAIR_COUNTERS</DefineConstants>
</PropertyGroup>

</Project>
21 changes: 21 additions & 0 deletions test/Box2D.NET.Test/B2BoardPhasesTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -624,4 +624,25 @@ public void Test_B2BoardPhases_b2BroadPhase_TestOverlap()
Assert.That(b2BroadPhase_TestOverlap(bp, proxyKey1, proxyKey1), Is.True,
"A proxy should be considered to overlap with itself");
}

[Test]
public void Test_B2BoardPhases_b2BroadPhase_GetShapeIndex()
{
// Arrange: Create a new BroadPhase object
B2BroadPhase bp = null;
b2CreateBroadPhase(ref bp);

// Create a proxy with a known shape index
var aabb = new B2AABB
{
lowerBound = new B2Vec2(0, 0),
upperBound = new B2Vec2(1, 1)
};
int shapeIndex = 123;
int proxyKey = b2BroadPhase_CreateProxy(bp, B2BodyType.b2_dynamicBody, aabb, 0x0001, shapeIndex, false);

// Act & Assert: Verify that the shape index is correctly extracted
Assert.That(b2BroadPhase_GetShapeIndex(bp, proxyKey), Is.EqualTo(shapeIndex),
"Should correctly extract shape index from proxy key");
}
}
16 changes: 10 additions & 6 deletions test/Box2D.NET.Test/Box2D.NET.Test.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,27 +5,31 @@
<IsPackable>false</IsPackable>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)' == 'Release'">
<DefineConstants>$(DefineConstants);ENABLED</DefineConstants>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)' == 'Debug'">
<DefineConstants>$(DefineConstants);B2_SNOOP_TOI_COUNTERS;B2_VALIDATE;ENABLED;B2_SNOOP_TABLE_COUNTERS;B2_SNOOP_PAIR_COUNTERS;B2_SNOOP_TOI_COUNTERS</DefineConstants>
<DefineConstants>$(DefineConstants);B2_SNOOP_TOI_COUNTERS;ENABLED;B2_SNOOP_TABLE_COUNTERS;B2_SNOOP_PAIR_COUNTERS</DefineConstants>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="coverlet.collector" Version="6.0.4">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.13.0" />
<PackageReference Include="NUnit" Version="4.3.2" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.13.0"/>
<PackageReference Include="NUnit" Version="4.3.2"/>
<PackageReference Include="NUnit.Analyzers" Version="4.7.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="NUnit3TestAdapter" Version="5.0.0" />
<PackageReference Include="NUnit3TestAdapter" Version="5.0.0"/>
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\src\Box2D.NET\Box2D.NET.csproj" />
<ProjectReference Include="..\..\src\Box2D.NET.Shared\Box2D.NET.Shared.csproj" />
<ProjectReference Include="..\..\src\Box2D.NET\Box2D.NET.csproj"/>
<ProjectReference Include="..\..\src\Box2D.NET.Shared\Box2D.NET.Shared.csproj"/>
</ItemGroup>

</Project>
8 changes: 8 additions & 0 deletions tools/Box2D.NET.Benchmark/Box2D.NET.Benchmark.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,12 @@
<ProjectReference Include="..\..\src\Box2D.NET\Box2D.NET.csproj" />
</ItemGroup>

<PropertyGroup Condition="'$(Configuration)' == 'Release'">
<DefineConstants>$(DefineConstants);ENABLED</DefineConstants>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)' == 'Debug'">
<DefineConstants>$(DefineConstants);B2_SNOOP_TOI_COUNTERS;ENABLED;B2_SNOOP_TABLE_COUNTERS;B2_SNOOP_PAIR_COUNTERS</DefineConstants>
</PropertyGroup>

</Project>
Loading