Skip to content

Commit 8f49218

Browse files
committed
added B2_ASSERT
1 parent 7e0c3d3 commit 8f49218

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

70 files changed

+991
-973
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@
44

55
using System;
66
using System.Collections.Generic;
7-
using System.Diagnostics;
87
using System.Runtime.InteropServices;
98
using Silk.NET.OpenGL;
109
using Box2D.NET.Samples.Helpers;
1110
using Box2D.NET.Samples.Primitives;
1211
using static Box2D.NET.B2MathFunction;
12+
using static Box2D.NET.B2Cores;
1313

1414
namespace Box2D.NET.Samples.Graphics;
1515

@@ -113,7 +113,7 @@ public void Flush()
113113
return;
114114
}
115115

116-
Debug.Assert(count % 2 == 0);
116+
B2_ASSERT(count % 2 == 0);
117117

118118
_gl.Enable(GLEnum.LineSmooth);
119119
_gl.Enable(GLEnum.Blend);

src/Box2D.NET.Samples/Helpers/SvgParser.cs

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

55
using System;
6-
using System.Diagnostics;
76
using System.Globalization;
7+
using static Box2D.NET.B2Cores;
88

99
namespace Box2D.NET.Samples.Helpers;
1010

@@ -39,7 +39,7 @@ public static int ParsePath(string svgPath, B2Vec2 offset, Span<B2Vec2> points,
3939
}
4040
}
4141

42-
Debug.Assert(char.IsDigit(svgPath[ptr]) || svgPath[ptr] == '-');
42+
B2_ASSERT(char.IsDigit(svgPath[ptr]) || svgPath[ptr] == '-');
4343

4444

4545
float x = 0.0f;
@@ -55,7 +55,7 @@ public static int ParsePath(string svgPath, B2Vec2 offset, Span<B2Vec2> points,
5555
}
5656
else
5757
{
58-
Debug.Assert(false);
58+
B2_ASSERT(false);
5959
}
6060

6161
break;
@@ -66,7 +66,7 @@ public static int ParsePath(string svgPath, B2Vec2 offset, Span<B2Vec2> points,
6666
}
6767
else
6868
{
69-
Debug.Assert(false);
69+
B2_ASSERT(false);
7070
}
7171

7272
break;
@@ -77,7 +77,7 @@ public static int ParsePath(string svgPath, B2Vec2 offset, Span<B2Vec2> points,
7777
}
7878
else
7979
{
80-
Debug.Assert(false);
80+
B2_ASSERT(false);
8181
}
8282

8383
break;
@@ -90,7 +90,7 @@ public static int ParsePath(string svgPath, B2Vec2 offset, Span<B2Vec2> points,
9090
}
9191
else
9292
{
93-
Debug.Assert(false);
93+
B2_ASSERT(false);
9494
}
9595

9696
break;
@@ -101,7 +101,7 @@ public static int ParsePath(string svgPath, B2Vec2 offset, Span<B2Vec2> points,
101101
}
102102
else
103103
{
104-
Debug.Assert(false);
104+
B2_ASSERT(false);
105105
}
106106

107107
break;
@@ -112,13 +112,13 @@ public static int ParsePath(string svgPath, B2Vec2 offset, Span<B2Vec2> points,
112112
}
113113
else
114114
{
115-
Debug.Assert(false);
115+
B2_ASSERT(false);
116116
}
117117

118118
break;
119119

120120
default:
121-
Debug.Assert(false);
121+
B2_ASSERT(false);
122122
break;
123123
}
124124

src/Box2D.NET.Samples/SampleApp.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -423,16 +423,16 @@ public byte[] AllocFcn(uint size, int alignment)
423423
{
424424
// Allocation must be a multiple of alignment or risk a seg fault
425425
// https://en.cppreference.com/w/c/memory/aligned_alloc
426-
Debug.Assert(IsPowerOfTwo(alignment));
426+
B2_ASSERT(IsPowerOfTwo(alignment));
427427
long sizeAligned = ((size - 1) | (uint)(alignment - 1)) + 1;
428-
Debug.Assert((sizeAligned & (alignment - 1)) == 0);
428+
B2_ASSERT((sizeAligned & (alignment - 1)) == 0);
429429

430430
// #if defined( _WIN64 ) || defined( _WIN32 )
431431
// void* ptr = _aligned_malloc( sizeAligned, alignment );
432432
// #else
433433
// void* ptr = aligned_alloc(alignment, sizeAligned);
434434
// #endif
435-
// Debug.Assert(ptr != nullptr);
435+
// B2_ASSERT(ptr != nullptr);
436436
// return ptr;
437437
return null;
438438
}
@@ -476,14 +476,14 @@ private void CreateUI(string glslVersion)
476476
// if (success == false)
477477
// {
478478
// Logger.Information("ImGui_ImplGlfw_InitForOpenGL failed\n");
479-
// Debug.Assert(false);
479+
// B2_ASSERT(false);
480480
// }
481481
//
482482
// success = ImGui_ImplOpenGL3_Init(glslVersion);
483483
// if (success == false)
484484
// {
485485
// Logger.Information("ImGui_ImplOpenGL3_Init failed\n");
486-
// Debug.Assert(false);
486+
// B2_ASSERT(false);
487487
// }
488488
//
489489

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@
22
// SPDX-FileCopyrightText: 2025 Ikpil Choi([email protected])
33
// SPDX-License-Identifier: MIT
44

5-
using System.Diagnostics;
65
using static Box2D.NET.B2Ids;
76
using static Box2D.NET.B2Geometries;
87
using static Box2D.NET.B2Types;
98
using static Box2D.NET.B2Bodies;
109
using static Box2D.NET.B2Shapes;
1110
using static Box2D.NET.B2Worlds;
1211
using static Box2D.NET.B2Timers;
12+
using static Box2D.NET.B2Cores;
1313

1414
namespace Box2D.NET.Samples.Samples.Benchmarks;
1515

@@ -105,7 +105,7 @@ void CreateScene()
105105
float x = 0.5f * i * shift + (j - i) * shift - centerx;
106106
bodyDef.position = new B2Vec2(x, y);
107107

108-
Debug.Assert(index < e_maxBodyCount);
108+
B2_ASSERT(index < e_maxBodyCount);
109109
m_bodies[index] = b2CreateBody(m_worldId, ref bodyDef);
110110
b2CreatePolygonShape(m_bodies[index], ref shapeDef, ref box);
111111

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
// SPDX-FileCopyrightText: 2025 Ikpil Choi([email protected])
33
// SPDX-License-Identifier: MIT
44

5-
using System.Diagnostics;
65
using System.Numerics;
76
using ImGuiNET;
87
using static Box2D.NET.B2Ids;
@@ -11,6 +10,7 @@
1110
using static Box2D.NET.B2MathFunction;
1211
using static Box2D.NET.B2Bodies;
1312
using static Box2D.NET.B2Shapes;
13+
using static Box2D.NET.B2Cores;
1414

1515
namespace Box2D.NET.Samples.Samples.Benchmarks;
1616

@@ -182,7 +182,7 @@ public override void Step(Settings settings)
182182

183183
for (int i = 0; i < m_tumblerCount; ++i)
184184
{
185-
Debug.Assert(m_bodyIndex < m_bodyCount);
185+
B2_ASSERT(m_bodyIndex < m_bodyCount);
186186

187187
B2BodyDef bodyDef = b2DefaultBodyDef();
188188
bodyDef.type = B2BodyType.b2_dynamicBody;

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@
22
// SPDX-FileCopyrightText: 2025 Ikpil Choi([email protected])
33
// SPDX-License-Identifier: MIT
44

5-
using System.Diagnostics;
65
using static Box2D.NET.B2Ids;
76
using static Box2D.NET.B2Geometries;
87
using static Box2D.NET.B2Types;
98
using static Box2D.NET.B2Bodies;
109
using static Box2D.NET.B2Shapes;
1110
using static Box2D.NET.B2Timers;
11+
using static Box2D.NET.B2Cores;
1212

1313
namespace Box2D.NET.Samples.Samples.Benchmarks;
1414

@@ -110,7 +110,7 @@ void CreateScene()
110110
float x = 0.5f * i * shift + (j - i) * shift - centerx;
111111
bodyDef.position = new B2Vec2(x, y);
112112

113-
Debug.Assert(index < e_maxBodyCount);
113+
B2_ASSERT(index < e_maxBodyCount);
114114
m_bodies[index] = b2CreateBody(m_worldId, ref bodyDef);
115115
b2CreatePolygonShape(m_bodies[index], ref shapeDef, ref box);
116116

src/Box2D.NET.Samples/Samples/Car.cs

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
// SPDX-FileCopyrightText: 2025 Ikpil Choi([email protected])
33
// SPDX-License-Identifier: MIT
44

5-
using System.Diagnostics;
65
using static Box2D.NET.B2Joints;
76
using static Box2D.NET.B2Ids;
87
using static Box2D.NET.B2Hulls;
@@ -12,7 +11,7 @@
1211
using static Box2D.NET.B2Bodies;
1312
using static Box2D.NET.B2Shapes;
1413
using static Box2D.NET.B2WheelJoints;
15-
14+
using static Box2D.NET.B2Cores;
1615

1716
namespace Box2D.NET.Samples.Samples;
1817

@@ -27,11 +26,11 @@ public struct Car
2726

2827
public void Spawn(B2WorldId worldId, B2Vec2 position, float scale, float hertz, float dampingRatio, float torque, object userData)
2928
{
30-
Debug.Assert(m_isSpawned == false);
29+
B2_ASSERT(m_isSpawned == false);
3130

32-
Debug.Assert(B2_IS_NULL(m_chassisId));
33-
Debug.Assert(B2_IS_NULL(m_frontWheelId));
34-
Debug.Assert(B2_IS_NULL(m_rearWheelId));
31+
B2_ASSERT(B2_IS_NULL(m_chassisId));
32+
B2_ASSERT(B2_IS_NULL(m_frontWheelId));
33+
B2_ASSERT(B2_IS_NULL(m_rearWheelId));
3534

3635
B2Vec2[] vertices = new B2Vec2[6]
3736
{
@@ -118,7 +117,7 @@ public void Spawn(B2WorldId worldId, B2Vec2 position, float scale, float hertz,
118117

119118
public void Despawn()
120119
{
121-
Debug.Assert(m_isSpawned == true);
120+
B2_ASSERT(m_isSpawned == true);
122121

123122
b2DestroyJoint(m_rearAxleId);
124123
b2DestroyJoint(m_frontAxleId);

src/Box2D.NET.Samples/Samples/Characters/Mover.cs

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

55
using System;
6-
using System.Diagnostics;
76
using System.Numerics;
87
using Box2D.NET.Samples.Helpers;
98
using ImGuiNET;
@@ -17,6 +16,7 @@
1716
using static Box2D.NET.B2Geometries;
1817
using static Box2D.NET.B2Joints;
1918
using static Box2D.NET.B2Distances;
19+
using static Box2D.NET.B2Cores;
2020

2121
namespace Box2D.NET.Samples.Samples.Characters;
2222

@@ -498,7 +498,7 @@ public override void UpdateGui()
498498

499499
static bool PlaneResultFcn(B2ShapeId shapeId, ref B2PlaneResult planeResult, object context)
500500
{
501-
Debug.Assert(planeResult.hit == true);
501+
B2_ASSERT(planeResult.hit == true);
502502

503503
Mover self = (Mover)context;
504504
float maxPush = float.MaxValue;
@@ -512,7 +512,7 @@ static bool PlaneResultFcn(B2ShapeId shapeId, ref B2PlaneResult planeResult, obj
512512

513513
if (self.m_planeCount < m_planeCapacity)
514514
{
515-
Debug.Assert(b2IsValidPlane(planeResult.plane));
515+
B2_ASSERT(b2IsValidPlane(planeResult.plane));
516516
self.m_planes[self.m_planeCount] = new B2CollisionPlane(planeResult.plane, maxPush, 0.0f, clipVelocity);
517517
self.m_planeCount += 1;
518518
}
@@ -557,26 +557,26 @@ public override void Keyboard(Keys key)
557557
public override void Step(Settings settings)
558558
{
559559
base.Step(settings);
560-
560+
561561
bool pause = false;
562-
if ( settings.pause )
562+
if (settings.pause)
563563
{
564564
pause = settings.singleStep != true;
565565
}
566566

567567
float timeStep = settings.hertz > 0.0f ? 1.0f / settings.hertz : 0.0f;
568-
if ( pause )
568+
if (pause)
569569
{
570570
timeStep = 0.0f;
571571
}
572572

573-
if ( timeStep > 0.0f )
573+
if (timeStep > 0.0f)
574574
{
575575
B2Vec2 point;
576576
point.X = m_elevatorBase.X;
577577
point.Y = m_elevatorAmplitude * MathF.Cos(1.0f * m_time + B2_PI) + m_elevatorBase.Y;
578578

579-
b2Body_SetTargetTransform( m_elevatorId, new B2Transform( point, b2Rot_identity ), timeStep );
579+
b2Body_SetTargetTransform(m_elevatorId, new B2Transform(point, b2Rot_identity), timeStep);
580580
}
581581

582582
m_time += timeStep;
@@ -595,7 +595,7 @@ public override void Step(Settings settings)
595595
throttle += 1.0f;
596596
}
597597

598-
if (InputAction.Press == GetKey(Keys.Space) )
598+
if (InputAction.Press == GetKey(Keys.Space))
599599
{
600600
if (m_onGround && m_jumpReleased)
601601
{
@@ -630,7 +630,7 @@ public override void Draw(Settings settings)
630630
{
631631
B2Vec2 p1 = b2TransformPoint(ref m_transform, m_capsule.center1);
632632
B2Vec2 p2 = b2TransformPoint(ref m_transform, m_capsule.center2);
633-
633+
634634
B2HexColor color = m_onGround ? B2HexColor.b2_colorOrange : B2HexColor.b2_colorAquamarine;
635635
m_context.draw.DrawSolidCapsule(p1, p2, m_capsule.radius, color);
636636
m_context.draw.DrawSegment(m_transform.p, m_transform.p + m_velocity, B2HexColor.b2_colorPurple);

0 commit comments

Comments
 (0)