Skip to content

Commit f00c737

Browse files
committed
wip2
1 parent e6384fc commit f00c737

9 files changed

Lines changed: 418 additions & 94 deletions

File tree

src/Box2D.NET.Samples/Primitives/SampleEntry.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,14 @@ public class SampleEntry
1313
public readonly string Name;
1414
public readonly string Title;
1515
public readonly Func<SampleContext, Sample> CreateFcn;
16+
public readonly Func<B2Capacity> CapacityFcn;
1617

17-
public SampleEntry(string category, string name, Func<SampleContext, Sample> createFcn)
18+
public SampleEntry(string category, string name, Func<SampleContext, Sample> createFcn, Func<B2Capacity> capacityFcn = null)
1819
{
1920
Category = category;
2021
Name = name;
2122
Title = $"{Category} : {Name}";
2223
CreateFcn = createFcn;
24+
CapacityFcn = capacityFcn;
2325
}
24-
}
26+
}

src/Box2D.NET.Samples/SampleContext.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ public class SampleContext
4141

4242
// These are persisted
4343
public int sampleIndex = 0;
44+
public B2Capacity capacity;
4445

4546

4647
public B2DebugDraw debugDraw;

src/Box2D.NET.Samples/Samples/Benchmarks/BenchmarkCompound.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,16 @@
1010

1111
namespace Box2D.NET.Samples.Samples.Benchmarks;
1212

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

1717
private static Sample Create(SampleContext context)
1818
{
19-
return new BenchmarkCompound(context);
19+
return new BenchmarkLargeCompounds(context);
2020
}
2121

22-
public BenchmarkCompound(SampleContext context) : base(context)
22+
public BenchmarkLargeCompounds(SampleContext context) : base(context)
2323
{
2424
if (m_context.restart == false)
2525
{
@@ -105,4 +105,4 @@ public BenchmarkCompound(SampleContext context) : base(context)
105105
}
106106
}
107107
}
108-
}
108+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// SPDX-FileCopyrightText: 2025 Erin Catto
2+
// SPDX-FileCopyrightText: 2025 Ikpil Choi(ikpil@naver.com)
3+
// SPDX-License-Identifier: MIT
4+
5+
using static Box2D.NET.Shared.Benchmarks;
6+
7+
namespace Box2D.NET.Samples.Samples.Benchmarks;
8+
9+
public class BenchmarkCompounds : Sample
10+
{
11+
private static readonly int SampleBenchmarkCompounds = SampleFactory.Shared.RegisterSample("Benchmark", "Compounds", Create);
12+
13+
private static Sample Create(SampleContext context)
14+
{
15+
return new BenchmarkCompounds(context);
16+
}
17+
18+
public BenchmarkCompounds(SampleContext context) : base(context)
19+
{
20+
if (m_context.restart == false)
21+
{
22+
m_context.camera.center = new B2Vec2(0.0f, 50.0f);
23+
m_context.camera.zoom = 25.0f * 2.2f;
24+
m_context.enableSleep = false;
25+
}
26+
27+
CreateCompounds(m_worldId);
28+
}
29+
}

src/Box2D.NET.Samples/Samples/Benchmarks/BenchmarkManyPyramids.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,19 @@ namespace Box2D.NET.Samples.Samples.Benchmarks;
88

99
public class BenchmarkManyPyramids : Sample
1010
{
11-
private static readonly int SampleBenchmarkManyPyramids = SampleFactory.Shared.RegisterSample("Benchmark", "Many Pyramids", Create);
11+
private static readonly int SampleBenchmarkManyPyramids =
12+
SampleFactory.Shared.RegisterSampleWithCapacity("Benchmark", "Many Pyramids", Create, GetCapacity);
1213

1314
private static Sample Create(SampleContext context)
1415
{
1516
return new BenchmarkManyPyramids(context);
1617
}
1718

19+
private static B2Capacity GetCapacity()
20+
{
21+
return GetManyPyramidsCapacity();
22+
}
23+
1824
public BenchmarkManyPyramids(SampleContext context) : base(context)
1925
{
2026
if (m_context.restart == false)

src/Box2D.NET.Samples/Samples/Benchmarks/BenchmarkWasher.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
// SPDX-License-Identifier: MIT
44

55
using static Box2D.NET.Shared.Benchmarks;
6+
using static Box2D.NET.B2Worlds;
67

78
namespace Box2D.NET.Samples.Samples.Benchmarks;
89

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

2627
CreateWasher(m_worldId);
2728
}
29+
30+
public override void Step()
31+
{
32+
base.Step();
33+
34+
B2ContactEvents events = b2World_GetContactEvents(m_worldId);
35+
DrawTextLine($"hits = {events.hitCount}");
36+
}
2837
}

0 commit comments

Comments
 (0)