Skip to content

Commit a7ca459

Browse files
Update box2d to 3.1.0 and change build script to glob files
1 parent bbbec4f commit a7ca459

File tree

8 files changed

+1095
-687
lines changed

8 files changed

+1095
-687
lines changed

Box2D.NET.Bindgen/Program.cs

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,9 @@
1111
SystemIncludeDirectories = { Path.Combine(BuildConstants.ZigLibPath, "include") },
1212
IncludeDirectories = { GetIncludeDirectory() },
1313

14-
TreatInputFileAsRawSourceCode = true,
1514
OutputFile = GetOutputDirectory(),
16-
InputFile = """
17-
#include <box2d/base.h>
18-
#include <box2d/box2d.h>
19-
#include <box2d/collision.h>
20-
#include <box2d/id.h>
21-
#include <box2d/math_functions.h>
22-
#include <box2d/types.h>
23-
""",
15+
InputFile = GetInputFile(),
16+
TreatInputFileAsRawSourceCode = true,
2417

2518
GenerateDisableRuntimeMarshallingAttribute = true,
2619

@@ -63,3 +56,13 @@ string GetOutputDirectory()
6356
{
6457
return GetCurrentFilePath() + "/../../Box2D.NET.Bindings/B2.g.cs";
6558
}
59+
60+
// Generates an input file that includes all Box2D headers.
61+
string GetInputFile()
62+
{
63+
IEnumerable<string> headerFiles = Directory
64+
.EnumerateFiles(GetIncludeDirectory(), "*.h", SearchOption.AllDirectories)
65+
.Select((string filePath) => $"#include <{Path.GetRelativePath(GetIncludeDirectory(), filePath)}>");
66+
67+
return string.Join('\n', headerFiles);
68+
}

Box2D.NET.Bindings/B2.g.cs

Lines changed: 1045 additions & 627 deletions
Large diffs are not rendered by default.

Box2D.NET.Examples/CSharp/HelloWorld.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ public static void Main()
1919
// Create a shape
2020
B2.Polygon box = B2.MakeBox(1, 1);
2121
B2.ShapeDef shapeDef = B2.DefaultShapeDef();
22-
shapeDef.friction = 0.6f;
22+
shapeDef.material.friction = 0.6f;
2323
shapeDef.density = 1.0f;
2424

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

Box2D.NET.Native/Box2D.NET.Native.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@
143143

144144
<!-- Here we need host not target toolset to compile/cross-compile -->
145145
<ItemGroup>
146-
<PackageReference Include="Vezel.Zig.Toolsets.$(HostRuntime)" Version="0.13.0.1">
146+
<PackageReference Include="Vezel.Zig.Toolsets.$(HostRuntime)" Version="0.14.0.1">
147147
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
148148
<PrivateAssets>all</PrivateAssets>
149149
</PackageReference>

Box2D.NET.Native/build.zig

Lines changed: 30 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -18,48 +18,28 @@ const src_flags = [_][]const u8{
1818
const include_paths = [_][]const u8{
1919
"../native/box2d/src",
2020
"../native/box2d/include",
21-
"../native/box2d/extern/simde",
2221
};
2322

24-
const src_files = [_][]const u8{
25-
"../native/box2d/src/aabb.c",
26-
"../native/box2d/src/allocate.c",
27-
"../native/box2d/src/array.c",
28-
"../native/box2d/src/bitset.c",
29-
"../native/box2d/src/block_array.c",
30-
"../native/box2d/src/body.c",
31-
"../native/box2d/src/broad_phase.c",
32-
"../native/box2d/src/constraint_graph.c",
33-
"../native/box2d/src/contact.c",
34-
"../native/box2d/src/contact_solver.c",
35-
"../native/box2d/src/core.c",
36-
"../native/box2d/src/distance.c",
37-
"../native/box2d/src/distance_joint.c",
38-
"../native/box2d/src/dynamic_tree.c",
39-
"../native/box2d/src/geometry.c",
40-
"../native/box2d/src/hull.c",
41-
"../native/box2d/src/id_pool.c",
42-
"../native/box2d/src/island.c",
43-
"../native/box2d/src/joint.c",
44-
"../native/box2d/src/manifold.c",
45-
"../native/box2d/src/math_functions.c",
46-
"../native/box2d/src/motor_joint.c",
47-
"../native/box2d/src/mouse_joint.c",
48-
"../native/box2d/src/prismatic_joint.c",
49-
"../native/box2d/src/revolute_joint.c",
50-
"../native/box2d/src/shape.c",
51-
"../native/box2d/src/solver.c",
52-
"../native/box2d/src/solver_set.c",
53-
"../native/box2d/src/stack_allocator.c",
54-
"../native/box2d/src/table.c",
55-
"../native/box2d/src/timer.c",
56-
"../native/box2d/src/types.c",
57-
"../native/box2d/src/weld_joint.c",
58-
"../native/box2d/src/wheel_joint.c",
59-
"../native/box2d/src/world.c",
60-
};
23+
// Collect all C source files in the given directory and its subdirectories.
24+
fn getSourceFiles(b: *std.Build, dir_path: []const u8) !std.ArrayList([]const u8) {
25+
var list = std.ArrayList([]const u8).init(b.allocator);
26+
27+
var dir = try std.fs.cwd().openDir(dir_path, .{ .iterate = true });
28+
defer dir.close();
29+
30+
var walker = try dir.walk(b.allocator);
31+
defer walker.deinit();
32+
33+
while (try walker.next()) |entry| {
34+
if (entry.kind == .file and std.mem.endsWith(u8, entry.path, ".c")) {
35+
try list.append(b.pathJoin(&.{ dir_path, entry.path }));
36+
}
37+
}
38+
39+
return list;
40+
}
6141

62-
pub fn compile(b: *Build, options: BuildOptions) void {
42+
pub fn compile(b: *Build, options: BuildOptions) !void {
6343
const lib = switch (options.library_type) {
6444
.Shared => b.addSharedLibrary(.{
6545
.name = "box2d",
@@ -79,22 +59,25 @@ pub fn compile(b: *Build, options: BuildOptions) void {
7959
};
8060

8161
if (options.optimize != .Debug) {
82-
lib.defineCMacro("NDEBUG", null);
62+
lib.root_module.addCMacro("NDEBUG", "");
8363
}
8464

85-
for (include_paths) |path| {
86-
lib.addIncludePath(b.path(path));
87-
}
65+
const source_files = try getSourceFiles(b, "../native/box2d/src");
66+
defer source_files.deinit();
8867

89-
for (src_files) |file| {
68+
for (source_files.items) |file| {
9069
lib.addCSourceFile(.{ .file = b.path(file), .flags = &src_flags });
9170
}
9271

72+
for (include_paths) |path| {
73+
lib.addIncludePath(b.path(path));
74+
}
75+
9376
switch (options.target.result.os.tag) {
9477
.windows => {
9578
// Temporary fix to get rid of undefined symbol errors when statically linking in Native AOT.
9679
if (options.library_type == LibraryType.Static) {
97-
// lib.addCSourceFile(.{ .file = b.path("../native/windows.c"), .flags = &src_flags });
80+
lib.addCSourceFile(.{ .file = b.path("../native/windows.c"), .flags = &src_flags });
9881
}
9982
},
10083
.ios => {
@@ -166,8 +149,8 @@ pub fn compile(b: *Build, options: BuildOptions) void {
166149
b.installArtifact(lib);
167150
}
168151

169-
pub fn build(b: *Build) void {
170-
compile(b, .{
152+
pub fn build(b: *Build) !void {
153+
try compile(b, .{
171154
.optimize = b.standardOptimizeOption(.{}),
172155
.target = b.standardTargetOptions(.{}),
173156
.library_type = b.option(LibraryType, "library-type", "Compile as a static or shared library.") orelse LibraryType.Shared,

Box2D.NET.Tests/WorldTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ public void HelloWorld()
5050
shapeDef.density = 1.0f;
5151

5252
// Override the default friction.
53-
shapeDef.friction = 0.3f;
53+
shapeDef.material.friction = 0.3f;
5454

5555
// Add the shape to the body.
5656
B2.CreatePolygonShape(bodyId, &shapeDef, &dynamicBox);

native/box2d

Submodule box2d updated 228 files

native/windows.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
// Temporary fix for undefined symbol errors when statically linking on windows.
2+
int __isnanf(float) { }
3+
int __fpclassifyf(float) { }
4+
int printf(const char *, ...) { }

0 commit comments

Comments
 (0)