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
2 changes: 1 addition & 1 deletion src/Box2D.NET.Samples/Graphics/SolidPolygonRender.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public struct SolidPolygonRender

public SolidPolygonRender()
{
polygons = new List<PolygonData>();
polygons = new List<PolygonData>(10 * SolidPolygons.e_batchSize);
vaoId = new uint[1];
vboIds = new uint[2];
}
Expand Down
6 changes: 4 additions & 2 deletions src/Box2D.NET.Samples/Primitives/SampleEntry.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,14 @@ public class SampleEntry
public readonly string Name;
public readonly string Title;
public readonly Func<SampleContext, Sample> CreateFcn;
public readonly Func<B2Capacity> CapacityFcn;

public SampleEntry(string category, string name, Func<SampleContext, Sample> createFcn)
public SampleEntry(string category, string name, Func<SampleContext, Sample> createFcn, Func<B2Capacity> capacityFcn)
{
Category = category;
Name = name;
Title = $"{Category} : {Name}";
CreateFcn = createFcn;
CapacityFcn = capacityFcn;
}
}
}
3 changes: 2 additions & 1 deletion src/Box2D.NET.Samples/SampleContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ public class SampleContext

// These are persisted
public int sampleIndex = 0;
public B2Capacity capacity;


public B2DebugDraw debugDraw;
Expand Down Expand Up @@ -75,7 +76,7 @@ private SampleContext(string signature, Glfw glfw)
debugDraw.DrawCircleFcn = DrawCircleFcn;
debugDraw.DrawSolidCircleFcn = DrawSolidCircleFcn;
debugDraw.DrawSolidCapsuleFcn = DrawSolidCapsuleFcn;
debugDraw.drawLineFcn = DrawLineFcn;
debugDraw.DrawLineFcn = DrawLineFcn;
debugDraw.DrawTransformFcn = DrawTransformFcn;
debugDraw.DrawPointFcn = DrawPointFcn;
debugDraw.DrawStringFcn = DrawStringFcn;
Expand Down
29 changes: 29 additions & 0 deletions src/Box2D.NET.Samples/Samples/Benchmarks/BenchmarkCompounds.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// SPDX-FileCopyrightText: 2025 Erin Catto
// SPDX-FileCopyrightText: 2025 Ikpil Choi(ikpil@naver.com)
// SPDX-License-Identifier: MIT

using static Box2D.NET.Shared.Benchmarks;

namespace Box2D.NET.Samples.Samples.Benchmarks;

public class BenchmarkCompounds : Sample
{
private static readonly int SampleBenchmarkCompounds = SampleFactory.Shared.RegisterSample("Benchmark", "Compounds", Create);

private static Sample Create(SampleContext context)
{
return new BenchmarkCompounds(context);
}

public BenchmarkCompounds(SampleContext context) : base(context)
{
if (m_context.restart == false)
{
m_context.camera.center = new B2Vec2(0.0f, 50.0f);
m_context.camera.zoom = 25.0f * 2.2f;
m_context.enableSleep = false;
}

CreateCompounds(m_worldId);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,16 @@

namespace Box2D.NET.Samples.Samples.Benchmarks;

public class BenchmarkCompound : Sample
public class BenchmarkLargeCompounds : Sample
{
private static readonly int SampleCompound = SampleFactory.Shared.RegisterSample("Benchmark", "Compound", Create);
private static readonly int SampleLargeCompounds = SampleFactory.Shared.RegisterSample("Benchmark", "Large Compounds", Create);

private static Sample Create(SampleContext context)
{
return new BenchmarkCompound(context);
return new BenchmarkLargeCompounds(context);
}

public BenchmarkCompound(SampleContext context) : base(context)
public BenchmarkLargeCompounds(SampleContext context) : base(context)
{
if (m_context.restart == false)
{
Expand Down Expand Up @@ -105,4 +105,4 @@ public BenchmarkCompound(SampleContext context) : base(context)
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,19 @@ namespace Box2D.NET.Samples.Samples.Benchmarks;

public class BenchmarkManyPyramids : Sample
{
private static readonly int SampleBenchmarkManyPyramids = SampleFactory.Shared.RegisterSample("Benchmark", "Many Pyramids", Create);
private static readonly int SampleBenchmarkManyPyramids =
SampleFactory.Shared.RegisterSampleWithCapacity("Benchmark", "Many Pyramids", Create, GetCapacity);

private static Sample Create(SampleContext context)
{
return new BenchmarkManyPyramids(context);
}

private static B2Capacity GetCapacity()
{
return GetManyPyramidsCapacity();
}

public BenchmarkManyPyramids(SampleContext context) : base(context)
{
if (m_context.restart == false)
Expand Down
2 changes: 1 addition & 1 deletion src/Box2D.NET.Samples/Samples/Benchmarks/BenchmarkSleep.cs
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ public override void Step()
if (m_stepCount > 20)
{
// Creating and destroying a joint will engage the island splitter.
b2FilterJointDef jointDef = b2DefaultFilterJointDef();
B2FilterJointDef jointDef = b2DefaultFilterJointDef();
jointDef.@base.bodyIdA = m_bodies[0];
jointDef.@base.bodyIdB = m_bodies[1];
B2JointId jointId = b2CreateFilterJoint(m_worldId, jointDef);
Expand Down
9 changes: 9 additions & 0 deletions src/Box2D.NET.Samples/Samples/Benchmarks/BenchmarkWasher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
// SPDX-License-Identifier: MIT

using static Box2D.NET.Shared.Benchmarks;
using static Box2D.NET.B2Worlds;

namespace Box2D.NET.Samples.Samples.Benchmarks;

Expand All @@ -25,4 +26,12 @@ private BenchmarkWasher(SampleContext context) : base(context)

CreateWasher(m_worldId);
}

public override void Step()
{
base.Step();

B2ContactEvents events = b2World_GetContactEvents(m_worldId);
DrawTextLine($"hits = {events.hitCount}");
}
}
2 changes: 1 addition & 1 deletion src/Box2D.NET.Samples/Samples/Collisions/DynamicTree.cs
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ void BuildTree()

float y = -4.0f;

m_tree = b2DynamicTree_Create();
m_tree = b2DynamicTree_Create(16);

B2Vec2 aabbMargin = new B2Vec2(0.1f, 0.1f);

Expand Down
2 changes: 1 addition & 1 deletion src/Box2D.NET.Samples/Samples/Joints/FilterJoint.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public FilterJoint(SampleContext context) : base(context)
B2BodyId bodyId2 = b2CreateBody(m_worldId, bodyDef);
b2CreatePolygonShape(bodyId2, shapeDef, box);

b2FilterJointDef jointDef = b2DefaultFilterJointDef();
B2FilterJointDef jointDef = b2DefaultFilterJointDef();
jointDef.@base.bodyIdA = bodyId1;
jointDef.@base.bodyIdB = bodyId2;

Expand Down
Loading
Loading