Skip to content

Commit

Permalink
Update submodule and generate bindings for all headers
Browse files Browse the repository at this point in the history
  • Loading branch information
BeanCheeseBurrito committed Feb 25, 2024
1 parent 2eeeb0b commit 7ba2d74
Show file tree
Hide file tree
Showing 7 changed files with 866 additions and 142 deletions.
25 changes: 24 additions & 1 deletion Box2D.NET.Bindgen/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,29 +25,52 @@

TreatInputFileAsRawSourceCode = true,
InputFile = """
#include <box2d/api.h>
#include <box2d/box2d.h>
#include <box2d/callbacks.h>
#include <box2d/color.h>
#include <box2d/constants.h>
#include <box2d/debug_draw.h>
#include <box2d/distance.h>
#include <box2d/dynamic_tree.h>
#include <box2d/event_types.h>
#include <box2d/geometry.h>
#include <box2d/hull.h>
#include <box2d/id.h>
#include <box2d/joint_types.h>
#include <box2d/manifold.h>
#include <box2d/math.h>
#include <box2d/math_types.h>
#include <box2d/timer.h>
#include <box2d/types.h>
""",
OutputFile = GetOutputDirectory("B2.g.cs"),

RemappedPrefixes =
{
("b2AABB_", "AABB"),
("b2Body_", "Body"),
("b2Chain_", "Chain"),
("b2DistanceJoint_", "DistanceJoint"),
("b2DynamicTree_", "DynamicTree"),
("b2Joint_", "Joint"),
("b2MotorJoint_", "MotorJoint"),
("b2MouseJoint_", "MouseJoint"),
("b2PrismaticJoint_", "PrismaticJoint"),
("b2RevoluteJoint_", "RevoluteJoint"),
("b2Rot_", "Rot"),
("b2Shape_", "Shape"),
("b2Vec2_", "Vec2"),
("b2WheelJoint_", "WheelJoint"),
("b2WeldJoint_", "WeldJoint"),
("b2World_", "World"),
("b2_", ""),
("b2", ""),
},

GenerateMacros = true,
GenerateExternVariables = true
GenerateExternVariables = true,
SuppressedWarnings = { "CS9084" }
};

BindingGenerator.Generate(options);
Expand Down
868 changes: 824 additions & 44 deletions Box2D.NET.Bindings/B2.g.cs

Large diffs are not rendered by default.

79 changes: 0 additions & 79 deletions Box2D.NET.Bindings/B2Extensions.cs

This file was deleted.

11 changes: 5 additions & 6 deletions Box2D.NET.Examples/CSharp/HelloWorld.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,33 +5,32 @@ public static unsafe class HelloWorld
public static void Main()
{
// Create a world
B2.WorldDef worldDef = B2.DefaultWorldDef;
B2.WorldDef worldDef = B2.DefaultWorldDef();
worldDef.gravity = new B2.Vec2 { x = 0, y = -9.81f };

B2.WorldId worldId = B2.CreateWorld(&worldDef);

// Create a body
B2.BodyDef bodyDef = B2.DefaultBodyDef;
B2.BodyDef bodyDef = B2.DefaultBodyDef();
bodyDef.type = B2.dynamicBody;

B2.BodyId bodyId = B2.CreateBody(worldId, &bodyDef);

// Create a shape
B2.Polygon box = B2.MakeBox(1, 1);
B2.ShapeDef shapeDef = B2.DefaultShapeDef;
B2.ShapeDef shapeDef = B2.DefaultShapeDef();
shapeDef.friction = 0.6f;
shapeDef.density = 1.0f;

B2.ShapeId shapeId = B2.CreatePolygonShape(bodyId, &shapeDef, &box);

// Run the simulation
const float timeStep = 1.0f / 60.0f;
const int velocityIterations = 6;
const int positionIterations = 2;
const int subStepCount = 4;

for (int i = 0; i < 60; i++)
{
B2.WorldStep(worldId, timeStep, velocityIterations, positionIterations);
B2.WorldStep(worldId, timeStep, subStepCount);
B2.Vec2 position = B2.BodyGetPosition(bodyId);
float angle = B2.BodyGetAngle(bodyId);

Expand Down
6 changes: 4 additions & 2 deletions Box2D.NET.Native/build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -17,21 +17,21 @@ pub fn compileLibrary(b: *Build, lib: *Build.Step.Compile) void {
lib.addCSourceFiles(&.{
"../native/box2c/src/aabb.c",
"../native/box2c/src/allocate.c",
"../native/box2c/src/arena_allocator.c",
"../native/box2c/src/array.c",
"../native/box2c/src/bitset.c",
"../native/box2c/src/block_allocator.c",
"../native/box2c/src/body.c",
"../native/box2c/src/broad_phase.c",
"../native/box2c/src/constraint_graph.c",
"../native/box2c/src/contact.c",
"../native/box2c/src/contact_solver.c",
"../native/box2c/src/core.c",
"../native/box2c/src/distance.c",
"../native/box2c/src/distance_joint.c",
"../native/box2c/src/dynamic_tree.c",
"../native/box2c/src/geometry.c",
"../native/box2c/src/graph.c",
"../native/box2c/src/hull.c",
"../native/box2c/src/implementation.c",
"../native/box2c/src/island.c",
"../native/box2c/src/joint.c",
"../native/box2c/src/manifold.c",
Expand All @@ -42,6 +42,8 @@ pub fn compileLibrary(b: *Build, lib: *Build.Step.Compile) void {
"../native/box2c/src/prismatic_joint.c",
"../native/box2c/src/revolute_joint.c",
"../native/box2c/src/shape.c",
"../native/box2c/src/solver.c",
"../native/box2c/src/stack_allocator.c",
"../native/box2c/src/table.c",
"../native/box2c/src/timer.c",
"../native/box2c/src/types.c",
Expand Down
17 changes: 8 additions & 9 deletions Box2D.NET.Tests/WorldTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@ public void HelloWorld()
B2.Vec2 gravity = new B2.Vec2 { x = 0.0f, y = -10.0f };

// Construct a world object, which will hold and simulate the rigid bodies.
B2.WorldDef worldDef = B2.DefaultWorldDef;
B2.WorldDef worldDef = B2.DefaultWorldDef();
worldDef.gravity = gravity;

B2.WorldId worldId = B2.CreateWorld(&worldDef);

// Define the ground body.
B2.BodyDef groundBodyDef = B2.DefaultBodyDef;
B2.BodyDef groundBodyDef = B2.DefaultBodyDef();
groundBodyDef.position = new B2.Vec2 { x = 0.0f, y = -10.0f };

// Call the body factory which allocates memory for the ground body
Expand All @@ -31,11 +31,11 @@ public void HelloWorld()
B2.Polygon groundBox = B2.MakeBox(50.0f, 10.0f);

// Add the box shape to the ground body.
B2.ShapeDef groundShapeDef = B2.DefaultShapeDef;
B2.ShapeDef groundShapeDef = B2.DefaultShapeDef();
B2.CreatePolygonShape(groundBodyId, &groundShapeDef, &groundBox);

// Define the dynamic body. We set its position and call the body factory.
B2.BodyDef bodyDef = B2.DefaultBodyDef;
B2.BodyDef bodyDef = B2.DefaultBodyDef();
bodyDef.type = B2.dynamicBody;
bodyDef.position = new B2.Vec2 { x = 0.0f, y = 4.0f };
B2.BodyId bodyId = B2.CreateBody(worldId, &bodyDef);
Expand All @@ -44,7 +44,7 @@ public void HelloWorld()
B2.Polygon dynamicBox = B2.MakeBox(1.0f, 1.0f);

// Define the dynamic body shape
B2.ShapeDef shapeDef = B2.DefaultShapeDef;
B2.ShapeDef shapeDef = B2.DefaultShapeDef();

// Set the box density to be non-zero, so it will be dynamic.
shapeDef.density = 1.0f;
Expand All @@ -56,11 +56,10 @@ public void HelloWorld()
B2.CreatePolygonShape(bodyId, &shapeDef, &dynamicBox);

// Prepare for simulation. Typically we use a time step of 1/60 of a
// second (60Hz) and 10 iterations. This provides a high quality simulation
// second (60Hz) and 4 sub-steps. This provides a high quality simulation
// in most game scenarios.
float timeStep = 1.0f / 60.0f;
int velocityIterations = 6;
int relaxIterations = 2;
int subStepCount = 4;

B2.Vec2 position = B2.BodyGetPosition(bodyId);
float angle = B2.BodyGetAngle(bodyId);
Expand All @@ -70,7 +69,7 @@ public void HelloWorld()
{
// Instruct the world to perform a single step of simulation.
// It is generally best to keep the time step and iterations fixed.
B2.WorldStep(worldId, timeStep, velocityIterations, relaxIterations);
B2.WorldStep(worldId, timeStep, subStepCount);

// Now print the position and angle of the body.
position = B2.BodyGetPosition(bodyId);
Expand Down
2 changes: 1 addition & 1 deletion native/box2c
Submodule box2c updated 85 files
+24 −4 docs/migration.md
+30 −7 include/box2d/api.h
+274 −60 include/box2d/box2d.h
+37 −19 include/box2d/callbacks.h
+14 −6 include/box2d/color.h
+3 −3 include/box2d/constants.h
+1 −1 include/box2d/debug_draw.h
+5 −4 include/box2d/distance.h
+10 −5 include/box2d/dynamic_tree.h
+2 −2 include/box2d/event_types.h
+39 −14 include/box2d/geometry.h
+23 −34 include/box2d/id.h
+46 −103 include/box2d/joint_types.h
+0 −15 include/box2d/joint_util.h
+22 −20 include/box2d/manifold.h
+142 −46 include/box2d/math.h
+20 −7 include/box2d/math_cpp.h
+47 −0 include/box2d/math_types.h
+3 −0 include/box2d/timer.h
+42 −165 include/box2d/types.h
+2 −0 samples/CMakeLists.txt
+37 −34 samples/collection/benchmark.cpp
+100 −0 samples/collection/donut.cpp
+24 −0 samples/collection/donut.h
+54 −56 samples/collection/human.cpp
+1 −2 samples/collection/human.h
+39 −39 samples/collection/sample_bodies.cpp
+92 −20 samples/collection/sample_continuous.cpp
+1 −1 samples/collection/sample_dynamic_tree.cpp
+140 −126 samples/collection/sample_events.cpp
+344 −172 samples/collection/sample_joints.cpp
+13 −12 samples/collection/sample_manifold.cpp
+41 −39 samples/collection/sample_ray_cast.cpp
+10 −11 samples/collection/sample_robustness.cpp
+1 −1 samples/collection/sample_shape_cast.cpp
+215 −59 samples/collection/sample_shapes.cpp
+449 −63 samples/collection/sample_stacking.cpp
+2 −2 samples/collection/sample_time_of_impact.cpp
+8 −9 samples/main.cpp
+48 −28 samples/sample.cpp
+1 −6 samples/sample.h
+2 −3 samples/settings.h
+10 −6 src/CMakeLists.txt
+3 −2 src/aabb.c
+2 −2 src/aabb.h
+139 −57 src/body.c
+59 −33 src/body.h
+3 −3 src/broad_phase.c
+2 −0 src/broad_phase.h
+401 −0 src/constraint_graph.c
+5 −7 src/constraint_graph.h
+19 −6 src/contact.c
+514 −387 src/contact_solver.c
+37 −25 src/contact_solver.h
+2 −2 src/core.h
+12 −18 src/distance.c
+145 −139 src/distance_joint.c
+17 −17 src/geometry.c
+8 −0 src/implementation.c
+2 −2 src/island.c
+352 −172 src/joint.c
+52 −85 src/joint.h
+194 −103 src/manifold.c
+15 −0 src/math.c
+91 −125 src/motor_joint.c
+99 −84 src/mouse_joint.c
+1 −1 src/pool.h
+192 −239 src/prismatic_joint.c
+198 −254 src/revolute_joint.c
+214 −66 src/shape.c
+2 −2 src/shape.h
+233 −618 src/solver.c
+74 −56 src/solver.h
+1 −1 src/stack_allocator.c
+0 −0 src/stack_allocator.h
+59 −0 src/types.c
+146 −142 src/weld_joint.c
+237 −287 src/wheel_joint.c
+151 −112 src/world.c
+12 −9 src/world.h
+1 −1 test/test_collision.c
+7 −8 test/test_determinism.c
+9 −9 test/test_distance.c
+3 −3 test/test_shape.c
+19 −17 test/test_world.c

0 comments on commit 7ba2d74

Please sign in to comment.