From b3efe91aa824a5a4aa3999e414c90a5f717c27a6 Mon Sep 17 00:00:00 2001 From: BeanCheeseBurrito <mrbeancheeseburrito@protonmail.com> Date: Mon, 12 Aug 2024 02:39:52 -0700 Subject: [PATCH] Update box2d submodule to v3.0.0 --- .github/workflows/ci.yml | 18 ++-- .gitmodules | 6 +- Box2D.NET.Bindgen/Box2D.NET.Bindgen.csproj | 3 +- Box2D.NET.Bindgen/Program.cs | 13 +-- Box2D.NET.Bindings/B2.g.cs | 115 +++++++++++++++------ Box2D.NET.Examples/CSharp/HelloWorld.cs | 5 +- Box2D.NET.Native/Box2D.NET.Native.csproj | 72 ++++++------- Box2D.NET.Native/Box2D.NET.Native.targets | 8 +- Box2D.NET.Native/build.zig | 110 ++++++++++---------- Box2D.NET.Tests/WorldTests.cs | 9 +- Directory.Build.props | 5 +- native/box2c | 1 - native/box2d | 1 + 13 files changed, 212 insertions(+), 154 deletions(-) delete mode 160000 native/box2c create mode 160000 native/box2d diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 23d7b88..0506908 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -8,13 +8,13 @@ on: push-packages: description: 'Push nuget packages' required: true - default: 'false' + default: false type: boolean use-auto-generated-version: description: 'Use auto-generated version' required: true - default: 'true' + default: true type: boolean nuget-registry: @@ -69,22 +69,22 @@ jobs: - name: Build Projects shell: bash run: | - dotnet build --property:Deterministic=true -c Debug - dotnet build --property:Deterministic=true -c Release + dotnet build -c Debug + dotnet build -c Release - name: Run Tests shell: bash - run: dotnet test --no-build --verbosity minimal + run: dotnet test - name: Pack Nuget Packages shell: bash run: | if [ '${{ github.event.inputs.nuget-registry }}' == 'NuGet' ]; then - dotnet pack --no-build --property:NugetVersionSuffix=$NugetVersionSuffix -c Debug - dotnet pack --no-build --property:NugetVersionSuffix=$NugetVersionSuffix -c Release + dotnet pack --property:NugetVersionSuffix=$NugetVersionSuffix -c Debug + dotnet pack --property:NugetVersionSuffix=$NugetVersionSuffix -c Release else - dotnet pack --no-build --property:NugetVersionSuffix=$NugetVersionSuffix --property:DebugType=embedded -c Debug - dotnet pack --no-build --property:NugetVersionSuffix=$NugetVersionSuffix --property:DebugType=embedded -c Release + dotnet pack --property:NugetVersionSuffix=$NugetVersionSuffix --property:Box2DPackPdb=true -c Debug + dotnet pack --property:NugetVersionSuffix=$NugetVersionSuffix --property:Box2DPackPdb=true -c Release fi - name: Upload Artifacts diff --git a/.gitmodules b/.gitmodules index e2241e7..a645241 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,3 +1,3 @@ -[submodule "native/box2c"] - path = native/box2c - url = https://github.com/erincatto/box2c +[submodule "native/box2d"] + path = native/box2d + url = https://github.com/erincatto/box2d diff --git a/Box2D.NET.Bindgen/Box2D.NET.Bindgen.csproj b/Box2D.NET.Bindgen/Box2D.NET.Bindgen.csproj index 57fc9fd..ec0391d 100644 --- a/Box2D.NET.Bindgen/Box2D.NET.Bindgen.csproj +++ b/Box2D.NET.Bindgen/Box2D.NET.Bindgen.csproj @@ -6,11 +6,12 @@ <ImplicitUsings>enable</ImplicitUsings> <Nullable>enable</Nullable> <ContinuousIntegrationBuild>false</ContinuousIntegrationBuild> + <Deterministic>false</Deterministic> <RuntimeIdentifier Condition="'$(RuntimeIdentifier)' == ''">$(NETCoreSdkRuntimeIdentifier)</RuntimeIdentifier> </PropertyGroup> <ItemGroup> - <PackageReference Include="Bindgen.NET" Version="0.1.13"/> + <PackageReference Include="Bindgen.NET" Version="0.1.14"/> </ItemGroup> </Project> diff --git a/Box2D.NET.Bindgen/Program.cs b/Box2D.NET.Bindgen/Program.cs index 04e318b..c7b5576 100644 --- a/Box2D.NET.Bindgen/Program.cs +++ b/Box2D.NET.Bindgen/Program.cs @@ -1,7 +1,7 @@ using System.Runtime.CompilerServices; using Bindgen.NET; -const string library = "box2c"; +const string library = "box2d"; BindingOptions options = new() { @@ -12,10 +12,11 @@ DllFilePaths = { library, - "runtimes/linux-x64/native/" + library, - "runtimes/linux-arm64/native/" + library, - "runtimes/osx-x64/native/" + library, - "runtimes/osx-arm64/native/" + library, + "lib" + library, + "runtimes/linux-x64/native/lib" + library, + "runtimes/linux-arm64/native/lib" + library, + "runtimes/osx-x64/native/lib" + library, + "runtimes/osx-arm64/native/lib" + library, "runtimes/win-x64/native/" + library, "runtimes/win-arm64/native/" + library }, @@ -70,7 +71,7 @@ string GetCurrentFilePath([CallerFilePath] string filePath = "") string GetNativeDirectory(string path) { - return GetCurrentFilePath() + "/../../native/box2c/" + path; + return GetCurrentFilePath() + "/../../native/box2d/" + path; } string GetOutputDirectory(string fileName) diff --git a/Box2D.NET.Bindings/B2.g.cs b/Box2D.NET.Bindings/B2.g.cs index 9395992..69ec726 100644 --- a/Box2D.NET.Bindings/B2.g.cs +++ b/Box2D.NET.Bindings/B2.g.cs @@ -67,9 +67,6 @@ public static unsafe partial class B2 [System.Runtime.InteropServices.DllImport(BindgenInternal.DllImportPath, EntryPoint = "b2Body_EnableSleep", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl)] public static extern void BodyEnableSleep(BodyId bodyId, byte enableSleep); - [System.Runtime.InteropServices.DllImport(BindgenInternal.DllImportPath, EntryPoint = "b2Body_GetAngle", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl)] - public static extern float BodyGetAngle(BodyId bodyId); - [System.Runtime.InteropServices.DllImport(BindgenInternal.DllImportPath, EntryPoint = "b2Body_GetAngularDamping", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl)] public static extern float BodyGetAngularDamping(BodyId bodyId); @@ -203,7 +200,7 @@ public static unsafe partial class B2 public static extern void BodySetSleepThreshold(BodyId bodyId, float sleepVelocity); [System.Runtime.InteropServices.DllImport(BindgenInternal.DllImportPath, EntryPoint = "b2Body_SetTransform", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl)] - public static extern void BodySetTransform(BodyId bodyId, Vec2 position, float angle); + public static extern void BodySetTransform(BodyId bodyId, Vec2 position, Rot rotation); [System.Runtime.InteropServices.DllImport(BindgenInternal.DllImportPath, EntryPoint = "b2Body_SetType", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl)] public static extern void BodySetType(BodyId bodyId, BodyType type); @@ -233,28 +230,28 @@ public static unsafe partial class B2 public static extern Manifold CollideCapsuleAndCircle(Capsule* capsuleA, Transform xfA, Circle* circleB, Transform xfB); [System.Runtime.InteropServices.DllImport(BindgenInternal.DllImportPath, EntryPoint = "b2CollideCapsules", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl)] - public static extern Manifold CollideCapsules(Capsule* capsuleA, Transform xfA, Capsule* capsuleB, Transform xfB, DistanceCache* cache); + public static extern Manifold CollideCapsules(Capsule* capsuleA, Transform xfA, Capsule* capsuleB, Transform xfB); [System.Runtime.InteropServices.DllImport(BindgenInternal.DllImportPath, EntryPoint = "b2CollideCircles", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl)] public static extern Manifold CollideCircles(Circle* circleA, Transform xfA, Circle* circleB, Transform xfB); [System.Runtime.InteropServices.DllImport(BindgenInternal.DllImportPath, EntryPoint = "b2CollidePolygonAndCapsule", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl)] - public static extern Manifold CollidePolygonAndCapsule(Polygon* polygonA, Transform xfA, Capsule* capsuleB, Transform xfB, DistanceCache* cache); + public static extern Manifold CollidePolygonAndCapsule(Polygon* polygonA, Transform xfA, Capsule* capsuleB, Transform xfB); [System.Runtime.InteropServices.DllImport(BindgenInternal.DllImportPath, EntryPoint = "b2CollidePolygonAndCircle", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl)] public static extern Manifold CollidePolygonAndCircle(Polygon* polygonA, Transform xfA, Circle* circleB, Transform xfB); [System.Runtime.InteropServices.DllImport(BindgenInternal.DllImportPath, EntryPoint = "b2CollidePolygons", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl)] - public static extern Manifold CollidePolygons(Polygon* polyA, Transform xfA, Polygon* polyB, Transform xfB, DistanceCache* cache); + public static extern Manifold CollidePolygons(Polygon* polygonA, Transform xfA, Polygon* polygonB, Transform xfB); [System.Runtime.InteropServices.DllImport(BindgenInternal.DllImportPath, EntryPoint = "b2CollideSegmentAndCapsule", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl)] - public static extern Manifold CollideSegmentAndCapsule(Segment* segmentA, Transform xfA, Capsule* capsuleB, Transform xfB, DistanceCache* cache); + public static extern Manifold CollideSegmentAndCapsule(Segment* segmentA, Transform xfA, Capsule* capsuleB, Transform xfB); [System.Runtime.InteropServices.DllImport(BindgenInternal.DllImportPath, EntryPoint = "b2CollideSegmentAndCircle", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl)] public static extern Manifold CollideSegmentAndCircle(Segment* segmentA, Transform xfA, Circle* circleB, Transform xfB); [System.Runtime.InteropServices.DllImport(BindgenInternal.DllImportPath, EntryPoint = "b2CollideSegmentAndPolygon", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl)] - public static extern Manifold CollideSegmentAndPolygon(Segment* segmentA, Transform xfA, Polygon* polygonB, Transform xfB, DistanceCache* cache); + public static extern Manifold CollideSegmentAndPolygon(Segment* segmentA, Transform xfA, Polygon* polygonB, Transform xfB); [System.Runtime.InteropServices.DllImport(BindgenInternal.DllImportPath, EntryPoint = "b2CollideSmoothSegmentAndCapsule", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl)] public static extern Manifold CollideSmoothSegmentAndCapsule(SmoothSegment* smoothSegmentA, Transform xfA, Capsule* capsuleB, Transform xfB, DistanceCache* cache); @@ -1058,7 +1055,7 @@ public static unsafe partial class B2 public static extern CastOutput ShapeCastSegment(ShapeCastInput* input, Segment* shape); [System.Runtime.InteropServices.DllImport(BindgenInternal.DllImportPath, EntryPoint = "b2ShapeDistance", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl)] - public static extern DistanceOutput ShapeDistance(DistanceCache* cache, DistanceInput* input); + public static extern DistanceOutput ShapeDistance(DistanceCache* cache, DistanceInput* input, Simplex* simplexes, int simplexCapacity); [System.Runtime.InteropServices.DllImport(BindgenInternal.DllImportPath, EntryPoint = "b2SleepMilliseconds", CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl)] public static extern void SleepMilliseconds(int milliseconds); @@ -1268,7 +1265,7 @@ public partial struct BodyDef public Vec2 position; - public float angle; + public Rot rotation; public Vec2 linearVelocity; @@ -1296,6 +1293,8 @@ public partial struct BodyDef public byte automaticMass; + public byte allowFastRotation; + public int internalValue; } @@ -1512,8 +1511,6 @@ public partial struct DebugDraw public partial struct DistanceCache { - public float metric; - public ushort count; public fixed byte indexA[3]; @@ -1580,6 +1577,8 @@ public partial struct DistanceOutput public float distance; public int iterations; + + public int simplexCount; } public partial struct DistanceProxy @@ -1739,7 +1738,7 @@ public partial struct MassData public Vec2 center; - public float I; + public float rotationalInertia; } public partial struct Mat22 @@ -2124,6 +2123,8 @@ public partial struct ShapeDef public Filter filter; + public uint customColor; + public byte isSensor; public byte enableSensorEvents; @@ -2148,6 +2149,32 @@ public partial struct ShapeId public ushort revision; } + public partial struct Simplex + { + public SimplexVertex v1; + + public SimplexVertex v2; + + public SimplexVertex v3; + + public int count; + } + + public partial struct SimplexVertex + { + public Vec2 wA; + + public Vec2 wB; + + public Vec2 w; + + public float a; + + public int indexA; + + public int indexB; + } + public partial struct SmoothSegment { public Vec2 ghost1; @@ -2212,7 +2239,7 @@ public partial struct TreeNode public uint categoryBits; - public AnonymousRecord_collision_L586_C2 AnonymousRecord_collision_L586_C2_Field; + public AnonymousRecord_collision_L608_C2 AnonymousRecord_collision_L608_C2_Field; public int child1; @@ -2226,12 +2253,12 @@ public partial struct TreeNode public fixed byte pad[9]; - public ref int parent => ref AnonymousRecord_collision_L586_C2_Field.parent; + public ref int parent => ref AnonymousRecord_collision_L608_C2_Field.parent; - public ref int next => ref AnonymousRecord_collision_L586_C2_Field.next; + public ref int next => ref AnonymousRecord_collision_L608_C2_Field.next; [System.Runtime.InteropServices.StructLayout(System.Runtime.InteropServices.LayoutKind.Explicit)] - public partial struct AnonymousRecord_collision_L586_C2 + public partial struct AnonymousRecord_collision_L608_C2 { [System.Runtime.InteropServices.FieldOffset(0)] public int parent; @@ -2339,6 +2366,8 @@ public partial struct WorldDef public float jointDampingRatio; + public float maximumLinearVelocity; + public byte enableSleep; public byte enableContinous; @@ -2524,7 +2553,11 @@ public enum HexColor : uint colorWhite = 16777215, colorWhiteSmoke = 16119285, colorYellow = 16776960, - colorYellowGreen = 10145074 + colorYellowGreen = 10145074, + colorBox2DRed = 14430514, + colorBox2DBlue = 3190463, + colorBox2DGreen = 9226532, + colorBox2DYellow = 16772748 } public enum JointType : uint @@ -2873,6 +2906,14 @@ public enum TOIState : uint public const HexColor colorYellowGreen = HexColor.colorYellowGreen; + public const HexColor colorBox2DRed = HexColor.colorBox2DRed; + + public const HexColor colorBox2DBlue = HexColor.colorBox2DBlue; + + public const HexColor colorBox2DGreen = HexColor.colorBox2DGreen; + + public const HexColor colorBox2DYellow = HexColor.colorBox2DYellow; + public const JointType distanceJoint = JointType.distanceJoint; public const JointType motorJoint = JointType.motorJoint; @@ -2919,19 +2960,20 @@ public enum TOIState : uint public partial class BindgenInternal { - public const string DllImportPath = "box2c"; + public const string DllImportPath = "box2d"; static BindgenInternal() { DllFilePaths = new System.Collections.Generic.List<string> { - "box2c", - "runtimes/linux-x64/native/box2c", - "runtimes/linux-arm64/native/box2c", - "runtimes/osx-x64/native/box2c", - "runtimes/osx-arm64/native/box2c", - "runtimes/win-x64/native/box2c", - "runtimes/win-arm64/native/box2c" + "box2d", + "libbox2d", + "runtimes/linux-x64/native/libbox2d", + "runtimes/linux-arm64/native/libbox2d", + "runtimes/osx-x64/native/libbox2d", + "runtimes/osx-arm64/native/libbox2d", + "runtimes/win-x64/native/box2d", + "runtimes/win-arm64/native/box2d" }; } } @@ -2983,8 +3025,8 @@ public partial class BindgenInternal public static bool TryLoad(string path, out System.IntPtr handle) { -#if NET5_0_OR_GREATER - return System.Runtime.InteropServices.NativeLibrary.TryLoad(path, out handle); +#if NETCOREAPP3_0_OR_GREATER + return System.Runtime.InteropServices.NativeLibrary.TryLoad(path, System.Reflection.Assembly.GetExecutingAssembly(), null, out handle); #else handle = System.IntPtr.Zero; if (IsLinux) @@ -2999,7 +3041,7 @@ public static bool TryLoad(string path, out System.IntPtr handle) public static System.IntPtr GetExport(string symbol) { -#if NET5_0_OR_GREATER +#if NETCOREAPP3_0_OR_GREATER return System.Runtime.InteropServices.NativeLibrary.GetExport(LibraryHandle, symbol); #else if (IsLinux) @@ -3044,6 +3086,14 @@ public static System.IntPtr GetExport(string symbol) public static void ResolveLibrary() { + System.IntPtr handle = default; +#if NETCOREAPP3_0_OR_GREATER + foreach (string dllFilePath in DllFilePaths) + { + if (TryLoad(dllFilePath, out handle)) + goto Return; + } +#else string fileExtension; if (IsLinux) fileExtension = ".so"; @@ -3053,12 +3103,12 @@ public static void ResolveLibrary() fileExtension = ".dll"; else throw new System.InvalidOperationException("Can't determine native library file extension for the current system."); - System.IntPtr handle = default; foreach (string dllFilePath in DllFilePaths) { string fileName = System.IO.Path.GetFileName(dllFilePath); string parentDir = $"{dllFilePath}/.."; - string searchDir = System.IO.Path.IsPathRooted(dllFilePath) ? System.IO.Path.GetFullPath(parentDir) + "/" : System.IO.Path.GetFullPath(System.AppDomain.CurrentDomain.BaseDirectory + parentDir) + "/"; + string exeDir = System.IO.Path.GetFullPath(System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location)!); + string searchDir = System.IO.Path.IsPathRooted(dllFilePath) ? System.IO.Path.GetFullPath(parentDir) + "/" : System.IO.Path.GetFullPath($"{exeDir}/{parentDir}") + "/"; if (TryLoad($"{searchDir}{fileName}", out handle)) goto Return; if (TryLoad($"{searchDir}{fileName}{fileExtension}", out handle)) @@ -3076,6 +3126,7 @@ public static void ResolveLibrary() goto Return; } +#endif #if NET7_0_OR_GREATER handle = System.Runtime.InteropServices.NativeLibrary.GetMainProgramHandle(); #else diff --git a/Box2D.NET.Examples/CSharp/HelloWorld.cs b/Box2D.NET.Examples/CSharp/HelloWorld.cs index 925c765..0b36dfc 100644 --- a/Box2D.NET.Examples/CSharp/HelloWorld.cs +++ b/Box2D.NET.Examples/CSharp/HelloWorld.cs @@ -4,6 +4,7 @@ public static unsafe class HelloWorld { public static void Main() { + Console.WriteLine(B2.Normalize(default)); // Create a world B2.WorldDef worldDef = B2.DefaultWorldDef(); worldDef.gravity = new B2.Vec2 { x = 0, y = -9.81f }; @@ -32,10 +33,10 @@ public static void Main() { B2.WorldStep(worldId, timeStep, subStepCount); B2.Vec2 position = B2.BodyGetPosition(bodyId); - float angle = B2.BodyGetAngle(bodyId); + B2.Rot rotation = B2.BodyGetRotation(bodyId); Console.WriteLine($"Position: ({position.x}, {position.y})"); - Console.WriteLine($"Angle: {angle}"); + Console.WriteLine($"Angle: {MathF.Atan2(rotation.s, rotation.c)}"); Console.WriteLine(); } } diff --git a/Box2D.NET.Native/Box2D.NET.Native.csproj b/Box2D.NET.Native/Box2D.NET.Native.csproj index 391c30c..3df7f3a 100644 --- a/Box2D.NET.Native/Box2D.NET.Native.csproj +++ b/Box2D.NET.Native/Box2D.NET.Native.csproj @@ -2,13 +2,13 @@ <PropertyGroup> <TargetFramework>netstandard1.0</TargetFramework> - <IncludeBuildOutput>false</IncludeBuildOutput> <NoWarn>$(NoWarn);NU5128</NoWarn> </PropertyGroup> <PropertyGroup> <IsPackable>true</IsPackable> <IncludeContentInPack>true</IncludeContentInPack> + <IncludeBuildOutput>false</IncludeBuildOutput> <Version>0.0.8</Version> <Title Condition="'$(Configuration)' == 'Debug'">Box2D.NET.Native.Debug</Title> @@ -30,36 +30,36 @@ <NativeIsWindows Condition="'$([System.Runtime.InteropServices.RuntimeInformation]::IsOSPlatform($([System.Runtime.InteropServices.OSPlatform]::Windows)))' == 'true'">true</NativeIsWindows> <NativeProcessorArch>$([System.Runtime.InteropServices.RuntimeInformation]::ProcessArchitecture)</NativeProcessorArch> - <NativeLibName>box2c</NativeLibName> + <NativeLibName>box2d</NativeLibName> </PropertyGroup> <ItemGroup> - <PackageReference Include="Vezel.Zig.Toolsets.linux-x64" Version="0.11.0.1" Condition="'$(NativeProcessorArch)' == 'X64' And '$(NativeIsLinux)' == 'true'"> + <PackageReference Include="Vezel.Zig.Toolsets.linux-x64" Version="0.13.0.1" Condition="'$(NativeProcessorArch)' == 'X64' And '$(NativeIsLinux)' == 'true'"> <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> <PrivateAssets>all</PrivateAssets> </PackageReference> - <PackageReference Include="Vezel.Zig.Toolsets.osx-x64" Version="0.11.0.1" Condition="'$(NativeProcessorArch)' == 'X64' And '$(NativeIsOsx)' == 'true'"> + <PackageReference Include="Vezel.Zig.Toolsets.osx-x64" Version="0.13.0.1" Condition="'$(NativeProcessorArch)' == 'X64' And '$(NativeIsOsx)' == 'true'"> <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> <PrivateAssets>all</PrivateAssets> </PackageReference> - <PackageReference Include="Vezel.Zig.Toolsets.win-x64" Version="0.11.0.1" Condition="'$(NativeProcessorArch)' == 'X64' And '$(NativeIsWindows)' == 'true'"> + <PackageReference Include="Vezel.Zig.Toolsets.win-x64" Version="0.13.0.1" Condition="'$(NativeProcessorArch)' == 'X64' And '$(NativeIsWindows)' == 'true'"> <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> <PrivateAssets>all</PrivateAssets> </PackageReference> - <PackageReference Include="Vezel.Zig.Toolsets.linux-arm64" Version="0.11.0.1" Condition="'$(NativeProcessorArch)' == 'Arm64' And '$(NativeIsLinux)' == 'true'"> + <PackageReference Include="Vezel.Zig.Toolsets.linux-arm64" Version="0.13.0.1" Condition="'$(NativeProcessorArch)' == 'Arm64' And '$(NativeIsLinux)' == 'true'"> <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> <PrivateAssets>all</PrivateAssets> </PackageReference> - <PackageReference Include="Vezel.Zig.Toolsets.osx-arm64" Version="0.11.0.1" Condition="'$(NativeProcessorArch)' == 'Arm64' And '$(NativeIsOsx)' == 'true'"> + <PackageReference Include="Vezel.Zig.Toolsets.osx-arm64" Version="0.13.0.1" Condition="'$(NativeProcessorArch)' == 'Arm64' And '$(NativeIsOsx)' == 'true'"> <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> <PrivateAssets>all</PrivateAssets> </PackageReference> - <PackageReference Include="Vezel.Zig.Toolsets.win-arm64" Version="0.11.0.1" Condition="'$(NativeProcessorArch)' == 'Arm64' And '$(NativeIsWindows)' == 'true'"> + <PackageReference Include="Vezel.Zig.Toolsets.win-arm64" Version="0.13.0.1" Condition="'$(NativeProcessorArch)' == 'Arm64' And '$(NativeIsWindows)' == 'true'"> <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> <PrivateAssets>all</PrivateAssets> </PackageReference> @@ -67,40 +67,40 @@ <ItemGroup> <!--X64--> - <Content Condition="'$(Configuration)' == 'Debug' And Exists('debug/linux-x64/libbox2c.so')" Include="debug/linux-x64/libbox2c.so" PackagePath="runtimes/linux-x64/native/libbox2c.so"/> - <Content Condition="'$(Configuration)' == 'Debug' And Exists('debug/osx-x64/libbox2c.dylib')" Include="debug/osx-x64/libbox2c.dylib" PackagePath="runtimes/osx-x64/native/libbox2c.dylib"/> - <Content Condition="'$(Configuration)' == 'Debug' And Exists('debug/win-x64/box2c.dll')" Include="debug/win-x64/box2c.dll" PackagePath="runtimes/win-x64/native/box2c.dll"/> - <Content Condition="'$(Configuration)' == 'Debug' And Exists('debug/win-x64/box2c.pdb')" Include="debug/win-x64/box2c.pdb" PackagePath="runtimes/win-x64/native/box2c.pdb"/> + <Content Condition="'$(Configuration)' == 'Debug' And Exists('debug/linux-x64/libbox2d.so')" Include="debug/linux-x64/libbox2d.so" PackagePath="runtimes/linux-x64/native/libbox2d.so"/> + <Content Condition="'$(Configuration)' == 'Debug' And Exists('debug/osx-x64/libbox2d.dylib')" Include="debug/osx-x64/libbox2d.dylib" PackagePath="runtimes/osx-x64/native/libbox2d.dylib"/> + <Content Condition="'$(Configuration)' == 'Debug' And Exists('debug/win-x64/box2d.dll')" Include="debug/win-x64/box2d.dll" PackagePath="runtimes/win-x64/native/box2d.dll"/> + <Content Condition="'$(Configuration)' == 'Debug' And Exists('debug/win-x64/box2d.pdb')" Include="debug/win-x64/box2d.pdb" PackagePath="runtimes/win-x64/native/box2d.pdb"/> - <Content Condition="'$(Configuration)' == 'Release' And Exists('release/linux-x64/libbox2c.so')" Include="release/linux-x64/libbox2c.so" PackagePath="runtimes/linux-x64/native/libbox2c.so"/> - <Content Condition="'$(Configuration)' == 'Release' And Exists('release/osx-x64/libbox2c.dylib')" Include="release/osx-x64/libbox2c.dylib" PackagePath="runtimes/osx-x64/native/libbox2c.dylib"/> - <Content Condition="'$(Configuration)' == 'Release' And Exists('release/win-x64/box2c.dll')" Include="release/win-x64/box2c.dll" PackagePath="runtimes/win-x64/native/box2c.dll"/> + <Content Condition="'$(Configuration)' == 'Release' And Exists('release/linux-x64/libbox2d.so')" Include="release/linux-x64/libbox2d.so" PackagePath="runtimes/linux-x64/native/libbox2d.so"/> + <Content Condition="'$(Configuration)' == 'Release' And Exists('release/osx-x64/libbox2d.dylib')" Include="release/osx-x64/libbox2d.dylib" PackagePath="runtimes/osx-x64/native/libbox2d.dylib"/> + <Content Condition="'$(Configuration)' == 'Release' And Exists('release/win-x64/box2d.dll')" Include="release/win-x64/box2d.dll" PackagePath="runtimes/win-x64/native/box2d.dll"/> <!--Arm64--> - <Content Condition="'$(Configuration)' == 'Debug' And Exists('debug/linux-arm64/libbox2c.so')" Include="debug/linux-arm64/libbox2c.so" PackagePath="runtimes/linux-arm64/native/libbox2c.so"/> - <Content Condition="'$(Configuration)' == 'Debug' And Exists('debug/osx-arm64/libbox2c.dylib')" Include="debug/osx-arm64/libbox2c.dylib" PackagePath="runtimes/osx-arm64/native/libbox2c.dylib"/> - <Content Condition="'$(Configuration)' == 'Debug' And Exists('debug/win-arm64/box2c.dll')" Include="debug/win-arm64/box2c.dll" PackagePath="runtimes/win-arm64/native/box2c.dll"/> - <Content Condition="'$(Configuration)' == 'Debug' And Exists('debug/win-arm64/box2c.pdb')" Include="debug/win-arm64/box2c.pdb" PackagePath="runtimes/win-arm64/native/box2c.pdb"/> - - <Content Condition="'$(Configuration)' == 'Release' And Exists('release/linux-arm64/libbox2c.so')" Include="release/linux-arm64/libbox2c.so" PackagePath="runtimes/linux-arm64/native/libbox2c.so"/> - <Content Condition="'$(Configuration)' == 'Release' And Exists('release/osx-arm64/libbox2c.dylib')" Include="release/osx-arm64/libbox2c.dylib" PackagePath="runtimes/osx-arm64/native/libbox2c.dylib"/> - <Content Condition="'$(Configuration)' == 'Release' And Exists('release/win-arm64/box2c.dll')" Include="release/win-arm64/box2c.dll" PackagePath="runtimes/win-arm64/native/box2c.dll"/> + <Content Condition="'$(Configuration)' == 'Debug' And Exists('debug/linux-arm64/libbox2d.so')" Include="debug/linux-arm64/libbox2d.so" PackagePath="runtimes/linux-arm64/native/libbox2d.so"/> + <Content Condition="'$(Configuration)' == 'Debug' And Exists('debug/osx-arm64/libbox2d.dylib')" Include="debug/osx-arm64/libbox2d.dylib" PackagePath="runtimes/osx-arm64/native/libbox2d.dylib"/> + <Content Condition="'$(Configuration)' == 'Debug' And Exists('debug/win-arm64/box2d.dll')" Include="debug/win-arm64/box2d.dll" PackagePath="runtimes/win-arm64/native/box2d.dll"/> + <Content Condition="'$(Configuration)' == 'Debug' And Exists('debug/win-arm64/box2d.pdb')" Include="debug/win-arm64/box2d.pdb" PackagePath="runtimes/win-arm64/native/box2d.pdb"/> + + <Content Condition="'$(Configuration)' == 'Release' And Exists('release/linux-arm64/libbox2d.so')" Include="release/linux-arm64/libbox2d.so" PackagePath="runtimes/linux-arm64/native/libbox2d.so"/> + <Content Condition="'$(Configuration)' == 'Release' And Exists('release/osx-arm64/libbox2d.dylib')" Include="release/osx-arm64/libbox2d.dylib" PackagePath="runtimes/osx-arm64/native/libbox2d.dylib"/> + <Content Condition="'$(Configuration)' == 'Release' And Exists('release/win-arm64/box2d.dll')" Include="release/win-arm64/box2d.dll" PackagePath="runtimes/win-arm64/native/box2d.dll"/> </ItemGroup> <Target Name="Compile Native Library" AfterTargets="build"> - <Exec Command="$(ZigExePath) build -Doptimize=Debug --prefix debug --prefix-lib-dir linux-x64 -Dtarget=x86_64-linux-gnu"/> - <Exec Command="$(ZigExePath) build -Doptimize=Debug --prefix debug --prefix-lib-dir win-x64 -Dtarget=x86_64-windows-gnu"/> - <Exec Command="$(ZigExePath) build -Doptimize=Debug --prefix debug --prefix-lib-dir osx-x64 -Dtarget=x86_64-macos"/> - <Exec Command="$(ZigExePath) build -Doptimize=Debug --prefix debug --prefix-lib-dir linux-arm64 -Dtarget=aarch64-linux-gnu"/> - <Exec Command="$(ZigExePath) build -Doptimize=Debug --prefix debug --prefix-lib-dir win-arm64 -Dtarget=aarch64-windows-gnu"/> - <Exec Command="$(ZigExePath) build -Doptimize=Debug --prefix debug --prefix-lib-dir osx-arm64 -Dtarget=aarch64-macos"/> - - <Exec Command="$(ZigExePath) build -Doptimize=ReleaseFast --prefix release --prefix-lib-dir linux-x64 -Dtarget=x86_64-linux-gnu"/> - <Exec Command="$(ZigExePath) build -Doptimize=ReleaseFast --prefix release --prefix-lib-dir win-x64 -Dtarget=x86_64-windows-gnu"/> - <Exec Command="$(ZigExePath) build -Doptimize=ReleaseFast --prefix release --prefix-lib-dir osx-x64 -Dtarget=x86_64-macos"/> - <Exec Command="$(ZigExePath) build -Doptimize=ReleaseFast --prefix release --prefix-lib-dir linux-arm64 -Dtarget=aarch64-linux-gnu"/> - <Exec Command="$(ZigExePath) build -Doptimize=ReleaseFast --prefix release --prefix-lib-dir win-arm64 -Dtarget=aarch64-windows-gnu"/> - <Exec Command="$(ZigExePath) build -Doptimize=ReleaseFast --prefix release --prefix-lib-dir osx-arm64 -Dtarget=aarch64-macos"/> + <Exec Command="$(ZigExePath) build -Doptimize=Debug --prefix debug --prefix-lib-dir linux-x64 --prefix-exe-dir linux-x64 -Dtarget=x86_64-linux-gnu"/> + <Exec Command="$(ZigExePath) build -Doptimize=Debug --prefix debug --prefix-lib-dir win-x64 --prefix-exe-dir win-x64 -Dtarget=x86_64-windows-gnu"/> + <Exec Command="$(ZigExePath) build -Doptimize=Debug --prefix debug --prefix-lib-dir osx-x64 --prefix-exe-dir osx-x64 -Dtarget=x86_64-macos"/> + <Exec Command="$(ZigExePath) build -Doptimize=Debug --prefix debug --prefix-lib-dir linux-arm64 --prefix-exe-dir linux-arm64 -Dtarget=aarch64-linux-gnu"/> + <Exec Command="$(ZigExePath) build -Doptimize=Debug --prefix debug --prefix-lib-dir win-arm64 --prefix-exe-dir win-arm64 -Dtarget=aarch64-windows-gnu"/> + <Exec Command="$(ZigExePath) build -Doptimize=Debug --prefix debug --prefix-lib-dir osx-arm64 --prefix-exe-dir osx-arm64 -Dtarget=aarch64-macos"/> + + <Exec Command="$(ZigExePath) build -Doptimize=ReleaseFast --prefix release --prefix-lib-dir linux-x64 --prefix-exe-dir linux-x64 -Dtarget=x86_64-linux-gnu"/> + <Exec Command="$(ZigExePath) build -Doptimize=ReleaseFast --prefix release --prefix-lib-dir win-x64 --prefix-exe-dir win-x64 -Dtarget=x86_64-windows-gnu"/> + <Exec Command="$(ZigExePath) build -Doptimize=ReleaseFast --prefix release --prefix-lib-dir osx-x64 --prefix-exe-dir osx-x64 -Dtarget=x86_64-macos"/> + <Exec Command="$(ZigExePath) build -Doptimize=ReleaseFast --prefix release --prefix-lib-dir linux-arm64 --prefix-exe-dir linux-arm64 -Dtarget=aarch64-linux-gnu"/> + <Exec Command="$(ZigExePath) build -Doptimize=ReleaseFast --prefix release --prefix-lib-dir win-arm64 --prefix-exe-dir win-arm64 -Dtarget=aarch64-windows-gnu"/> + <Exec Command="$(ZigExePath) build -Doptimize=ReleaseFast --prefix release --prefix-lib-dir osx-arm64 --prefix-exe-dir osx-arm64 -Dtarget=aarch64-macos"/> </Target> </Project> diff --git a/Box2D.NET.Native/Box2D.NET.Native.targets b/Box2D.NET.Native/Box2D.NET.Native.targets index 21e5887..ecd9be2 100644 --- a/Box2D.NET.Native/Box2D.NET.Native.targets +++ b/Box2D.NET.Native/Box2D.NET.Native.targets @@ -1,28 +1,28 @@ <Project> <ItemGroup> <Content Condition="'$(Configuration)' == 'Debug' And '$([System.Runtime.InteropServices.RuntimeInformation]::ProcessArchitecture)' == 'X64'" - Include="$(MSBuildThisFileDirectory)debug/linux-x64/libbox2c.so;$(MSBuildThisFileDirectory)debug/osx-x64/libbox2c.dylib;$(MSBuildThisFileDirectory)debug/win-x64/box2c.dll;$(MSBuildThisFileDirectory)debug/win-x64/box2c.pdb"> + Include="$(MSBuildThisFileDirectory)debug/linux-x64/libbox2d.so;$(MSBuildThisFileDirectory)debug/osx-x64/libbox2d.dylib;$(MSBuildThisFileDirectory)debug/win-x64/box2d.dll;$(MSBuildThisFileDirectory)debug/win-x64/box2d.pdb"> <Link>%(Filename)%(Extension)</Link> <CopyToOutputDirectory>Always</CopyToOutputDirectory> <Pack>false</Pack> </Content> <Content Condition="'$(Configuration)' == 'Debug' And '$([System.Runtime.InteropServices.RuntimeInformation]::ProcessArchitecture)' == 'Arm64'" - Include="$(MSBuildThisFileDirectory)debug/linux-arm64/libbox2c.so;$(MSBuildThisFileDirectory)debug/osx-arm64/libbox2c.dylib;$(MSBuildThisFileDirectory)debug/win-arm64/box2c.dll;$(MSBuildThisFileDirectory)debug/win-arm64/box2c.pdb"> + Include="$(MSBuildThisFileDirectory)debug/linux-arm64/libbox2d.so;$(MSBuildThisFileDirectory)debug/osx-arm64/libbox2d.dylib;$(MSBuildThisFileDirectory)debug/win-arm64/box2d.dll;$(MSBuildThisFileDirectory)debug/win-arm64/box2d.pdb"> <Link>%(Filename)%(Extension)</Link> <CopyToOutputDirectory>Always</CopyToOutputDirectory> <Pack>false</Pack> </Content> <Content Condition="'$(Configuration)' == 'Release' And '$([System.Runtime.InteropServices.RuntimeInformation]::ProcessArchitecture)' == 'X64'" - Include="$(MSBuildThisFileDirectory)release/linux-x64/libbox2c.so;$(MSBuildThisFileDirectory)release/osx-x64/libbox2c.dylib;$(MSBuildThisFileDirectory)release/win-x64/box2c.dll"> + Include="$(MSBuildThisFileDirectory)release/linux-x64/libbox2d.so;$(MSBuildThisFileDirectory)release/osx-x64/libbox2d.dylib;$(MSBuildThisFileDirectory)release/win-x64/box2d.dll"> <Link>%(Filename)%(Extension)</Link> <CopyToOutputDirectory>Always</CopyToOutputDirectory> <Pack>false</Pack> </Content> <Content Condition="'$(Configuration)' == 'Release' And '$([System.Runtime.InteropServices.RuntimeInformation]::ProcessArchitecture)' == 'Arm64'" - Include="$(MSBuildThisFileDirectory)release/linux-arm64/libbox2c.so;$(MSBuildThisFileDirectory)release/osx-arm64/libbox2c.dylib;$(MSBuildThisFileDirectory)release/win-arm64/box2c.dll"> + Include="$(MSBuildThisFileDirectory)release/linux-arm64/libbox2d.so;$(MSBuildThisFileDirectory)release/osx-arm64/libbox2d.dylib;$(MSBuildThisFileDirectory)release/win-arm64/box2d.dll"> <Link>%(Filename)%(Extension)</Link> <CopyToOutputDirectory>Always</CopyToOutputDirectory> <Pack>false</Pack> diff --git a/Box2D.NET.Native/build.zig b/Box2D.NET.Native/build.zig index df8d6d8..4e9f309 100644 --- a/Box2D.NET.Native/build.zig +++ b/Box2D.NET.Native/build.zig @@ -1,64 +1,68 @@ const std = @import("std"); -const Build = std.build; +const Build = std.Build; const LazyPath = Build.LazyPath; -pub fn compileLibrary(b: *Build, lib: *Build.Step.Compile) void { - lib.linkLibC(); - lib.strip = lib.optimize != .Debug; +pub fn build(b: *Build) void { + const target = b.standardTargetOptions(.{}); + const optimize = b.standardOptimizeOption(.{}); - if (lib.optimize != .Debug) { + const lib = b.addSharedLibrary(.{ + .name = "box2d", + .target = target, + .optimize = optimize, + .strip = optimize != .Debug, + }); + + if (optimize != .Debug) { lib.defineCMacro("NDEBUG", null); } - lib.addIncludePath(LazyPath.relative("../native/box2c/src")); - lib.addIncludePath(LazyPath.relative("../native/box2c/include")); - lib.addIncludePath(LazyPath.relative("../native/box2c/extern/simde")); + lib.linkLibC(); - lib.addCSourceFiles(&.{ - "../native/box2c/src/aabb.c", - "../native/box2c/src/allocate.c", - "../native/box2c/src/array.c", - "../native/box2c/src/bitset.c", - "../native/box2c/src/block_array.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/hull.c", - "../native/box2c/src/id_pool.c", - "../native/box2c/src/island.c", - "../native/box2c/src/joint.c", - "../native/box2c/src/manifold.c", - "../native/box2c/src/math_functions.c", - "../native/box2c/src/motor_joint.c", - "../native/box2c/src/mouse_joint.c", - "../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/solver_set.c", - "../native/box2c/src/stack_allocator.c", - "../native/box2c/src/table.c", - "../native/box2c/src/timer.c", - "../native/box2c/src/types.c", - "../native/box2c/src/weld_joint.c", - "../native/box2c/src/wheel_joint.c", - "../native/box2c/src/world.c", - }, &.{}); + lib.addIncludePath(b.path("../native/box2d/src")); + lib.addIncludePath(b.path("../native/box2d/include")); + lib.addIncludePath(b.path("../native/box2d/extern/simde")); - b.installArtifact(lib); -} - -pub fn build(b: *Build) void { - const name = "box2c"; - const target = b.standardTargetOptions(.{}); - const optimize = b.standardOptimizeOption(.{}); + lib.addCSourceFiles(.{ + .files = &.{ + "../native/box2d/src/aabb.c", + "../native/box2d/src/allocate.c", + "../native/box2d/src/array.c", + "../native/box2d/src/bitset.c", + "../native/box2d/src/block_array.c", + "../native/box2d/src/body.c", + "../native/box2d/src/broad_phase.c", + "../native/box2d/src/constraint_graph.c", + "../native/box2d/src/contact.c", + "../native/box2d/src/contact_solver.c", + "../native/box2d/src/core.c", + "../native/box2d/src/distance.c", + "../native/box2d/src/distance_joint.c", + "../native/box2d/src/dynamic_tree.c", + "../native/box2d/src/geometry.c", + "../native/box2d/src/hull.c", + "../native/box2d/src/id_pool.c", + "../native/box2d/src/island.c", + "../native/box2d/src/joint.c", + "../native/box2d/src/manifold.c", + "../native/box2d/src/math_functions.c", + "../native/box2d/src/motor_joint.c", + "../native/box2d/src/mouse_joint.c", + "../native/box2d/src/prismatic_joint.c", + "../native/box2d/src/revolute_joint.c", + "../native/box2d/src/shape.c", + "../native/box2d/src/solver.c", + "../native/box2d/src/solver_set.c", + "../native/box2d/src/stack_allocator.c", + "../native/box2d/src/table.c", + "../native/box2d/src/timer.c", + "../native/box2d/src/types.c", + "../native/box2d/src/weld_joint.c", + "../native/box2d/src/wheel_joint.c", + "../native/box2d/src/world.c", + }, + .flags = &.{}, + }); - compileLibrary(b, b.addSharedLibrary(.{ .name = name, .target = target, .optimize = optimize })); + b.installArtifact(lib); } diff --git a/Box2D.NET.Tests/WorldTests.cs b/Box2D.NET.Tests/WorldTests.cs index 8b1b918..5cab2c9 100644 --- a/Box2D.NET.Tests/WorldTests.cs +++ b/Box2D.NET.Tests/WorldTests.cs @@ -37,6 +37,7 @@ public void HelloWorld() 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); // Define another box shape for our dynamic body. @@ -61,7 +62,7 @@ public void HelloWorld() int subStepCount = 4; B2.Vec2 position = B2.BodyGetPosition(bodyId); - float angle = B2.BodyGetAngle(bodyId); + B2.Rot rotation = B2.BodyGetRotation(bodyId); // This is our little game loop. for (int i = 0; i < 90; i++) @@ -72,9 +73,7 @@ public void HelloWorld() // Now print the position and angle of the body. position = B2.BodyGetPosition(bodyId); - angle = B2.BodyGetAngle(bodyId); - - //printf("%4.2f %4.2f %4.2f\n", position.x, position.y, angle); + rotation = B2.BodyGetRotation(bodyId); } // When the world destructor is called, all bodies and joints are freed. This can @@ -83,7 +82,7 @@ public void HelloWorld() Assert.True(Math.Abs(position.x) < 0.01f); Assert.True(Math.Abs(position.y - 1.00f) < 0.01f); - Assert.True(Math.Abs(angle) < 0.01f); + Assert.True(Math.Abs(Math.Atan2(rotation.s, rotation.c)) < 0.01f); } } } diff --git a/Directory.Build.props b/Directory.Build.props index b85a063..d73a6b4 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -1,7 +1,8 @@ <Project> <PropertyGroup> <IsPackable>false</IsPackable> - <NoWarn>$(NoWarn);NETSDK1138;NETSDK1201</NoWarn> - <ContinuousIntegrationBuild Condition="'$(GITHUB_ACTIONS)' == 'true'">true</ContinuousIntegrationBuild> + <ContinuousIntegrationBuild Condition="'$(GITHUB_ACTIONS)' == 'true' And '$(ContinuousIntegrationBuild)' == ''">true</ContinuousIntegrationBuild> + <Deterministic Condition="'$(GITHUB_ACTIONS)' == 'true' And '$(Deterministic)' == ''">true</Deterministic> + <AllowedOutputExtensionsInPackageBuildOutputFolder Condition="'$(Box2DPackPdb)' == 'true'">$(AllowedOutputExtensionsInPackageBuildOutputFolder);.pdb</AllowedOutputExtensionsInPackageBuildOutputFolder> </PropertyGroup> </Project> diff --git a/native/box2c b/native/box2c deleted file mode 160000 index 1d7d1cf..0000000 --- a/native/box2c +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 1d7d1cf14722a06f6a7b1c3b0850e70bcbec8558 diff --git a/native/box2d b/native/box2d new file mode 160000 index 0000000..8e7a17c --- /dev/null +++ b/native/box2d @@ -0,0 +1 @@ +Subproject commit 8e7a17c5c942dbf2fdea8b9d09983410dcc0429d