Răsfoiți Sursa

Add Jolt Physics (#1685)

* Add joltphysics

* Update xmake.lua

* Update xmake.lua

* Update xmake.lua

* Add mingw
Jérôme Leclercq 2 ani în urmă
părinte
comite
b4fb44c1a6
2 a modificat fișierele cu 182 adăugiri și 0 ștergeri
  1. 109 0
      packages/j/joltphysics/port/xmake.lua
  2. 73 0
      packages/j/joltphysics/xmake.lua

+ 109 - 0
packages/j/joltphysics/port/xmake.lua

@@ -0,0 +1,109 @@
+add_rules("mode.asan", "mode.debug", "mode.releasedbg", "mode.release")
+
+option("cross_platform_deterministic", { default = false, description = "Turns on behavior to attempt cross platform determinism. If this is set, JPH_USE_FMADD is ignored", defines = "JPH_CROSS_PLATFORM_DETERMINISTIC" })
+option("debug_renderer", { default = true, description = "Adds support to draw lines and triangles, used to be able to debug draw the state of the world", defines = "JPH_DEBUG_RENDERER"})
+option("double_precision", { default = false, description = "Compiles the library so that all positions are stored in doubles instead of floats. This makes larger worlds possible", defines = "JPH_DOUBLE_PRECISION" })
+option("profile", { default = false, description = "Turns on the internal profiler", defines = "JPH_PROFILE_ENABLED"})
+
+option("inst_avx", { default = false, description = "Enable AVX CPU instructions (x86/x64 only)" })
+option("inst_avx2", { default = false, description = "Enable AVX2 CPU instructions (x86/x64 only)" })
+option("inst_avx512", { default = false, description = "Enable AVX512F+AVX512VL CPU instructions (x86/x64 only)" })
+option("inst_f16c", { default = false, description = "Enable half float CPU instructions (x86/x64 only)" })
+option("inst_fmadd", { default = false, description = "Enable fused multiply add CPU instructions (x86/x64 only)" })
+option("inst_lzcnt", { default = false, description = "Enable the lzcnt CPU instruction (x86/x64 only" })
+option("inst_sse4_1", { default = false, description = "Enable SSE4.1 CPU instructions (x86/x64 only" })
+option("inst_sse4_2", { default = false, description = "Enable SSE4.2 CPU instructions (x86/x64 only" })
+option("inst_tzcnt", { default = false, description = "Enable the tzcnt CPU instruction (x86/x64 only" })
+
+if has_config("cross_platform_deterministic") then
+    set_fpmodels("precise")
+else
+    set_fpmodels("fast")
+end
+
+if is_mode("asan") then
+    add_defines("JPH_DISABLE_TEMP_ALLOCATOR")
+    add_defines("JPH_DISABLE_CUSTOM_ALLOCATOR")
+end
+
+set_languages("c++17")
+
+target("Jolt")
+    set_kind("$(kind)")
+    add_includedirs(".")
+    add_headerfiles("(Jolt/**.h)", "(Jolt/**.inl)")
+    add_files("Jolt/**.cpp")
+    add_options("cross_platform_deterministic", "debug_renderer", "double_precision", "profile")
+
+    if is_plat("windows") then
+        add_syslinks("Advapi32")
+    elseif is_plat("linux") then
+        add_syslinks("pthread")
+    end
+
+    on_config(function (target)
+        -- handle instruction sets flags
+        if is_arch("x86", "x64", "x86_64") then
+            if target:has_tool("cxx", "cl") then
+                target:add("cxflags", "/arch:SSE2", {force = true})
+                if has_config("inst_avx512") then
+                    target:add("cxflags", "/arch:AVX512", {force = true})
+                elseif has_config("inst_avx2") then
+                    target:add("cxflags", "/arch:AVX2", {force = true})
+                elseif has_config("inst_avx") then
+                    target:add("cxflags", "/arch:AVX", {force = true})
+                end
+                if has_config("inst_sse4_1") then
+                    target:add("defines", "JPH_USE_SSE4_1")
+                end
+                if has_config("inst_sse4_2") then
+                    target:add("defines", "JPH_USE_SSE4_2")
+                end
+                if has_config("inst_lzcnt") then
+                    target:add("defines", "JPH_USE_LZCNT")
+                end
+                if has_config("inst_tzcnt") then
+                    target:add("defines", "JPH_USE_TZCNT")
+                end
+                if has_config("inst_f16c") then
+                    target:add("defines", "JPH_USE_F16C")
+                end
+                if has_config("inst_fmadd") and not has_config("cross_platform_deterministic") then
+                    target:add("defines", "JPH_USE_FMADD")
+                end
+            elseif target:has_tool("cxx", "clang", "gcc") then
+                if has_config("inst_avx512") then
+                    target:add("cxflags", "-mavx512f", "-mavx512vl", "-mavx512dq", "-mavx2", "-mbmi", "-mpopcnt", "-mlzcnt", "-mf16c", {force = true})
+                elseif has_config("inst_avx2") then
+                    target:add("cxflags", "-mavx2", "-mbmi", "-mpopcnt", "-mlzcnt", "-mf16c", {force = true})
+                elseif has_config("inst_avx") then
+                    target:add("cxflags", "-mavx", "-mpopcnt", {force = true})
+                elseif has_config("inst_sse4_2") then
+                    target:add("cxflags", "-msse4.2", "-mpopcnt", {force = true})
+                elseif has_config("inst_sse4_1") then
+                    target:add("cxflags", "-msse4.1", {force = true})
+                else
+                    target:add("cxflags", "-msse2", {force = true})
+                end
+                if has_config("inst_lzcnt") then
+                    target:add("cxflags", "-mlzcnt", {force = true})
+                end
+                if has_config("inst_tzcnt") then
+                    target:add("cxflags", "-mbmi", {force = true})
+                end
+                if has_config("inst_f16c") then
+                    target:add("cxflags", "-mf16c", {force = true})
+                end
+                if has_config("inst_fmadd") and not has_config("cross_platform_deterministic") then
+                    target:add("cxflags", "-mfma", {force = true})
+                end
+            end
+        end
+        if is_plat("linux", "macosx", "mingw", "iphoneos", "wasm") then
+            if target:has_tool("cxx", "gcc") then
+                target:add("cxflags", "-Wno-comment", "-Wno-stringop-overflow", "-ffp-contract=off", {force = true})
+            else
+                target:add("cxflags", "-ffp-contract=off", {force = true})
+            end
+        end
+    end)

+ 73 - 0
packages/j/joltphysics/xmake.lua

@@ -0,0 +1,73 @@
+package("joltphysics")
+    set_homepage("https://github.com/jrouwe/JoltPhysics")
+    set_description("A multi core friendly rigid body physics and collision detection library suitable for games and VR applications.")
+    set_license("MIT")
+
+    add_urls("https://github.com/jrouwe/JoltPhysics/archive/refs/tags/$(version).tar.gz",
+             "https://github.com/jrouwe/JoltPhysics.git")
+    add_versions("v2.0.1", "96ae2e8691c4802e56bf2587da30f2cc86b8abe82a78bc2398065bd87dd718af")
+
+    add_configs("cross_platform_deterministic", { description = "Turns on behavior to attempt cross platform determinism", default = false, type = "boolean" })
+    add_configs("debug_renderer", { description = "Adds support to draw lines and triangles, used to be able to debug draw the state of the world", default = true, type = "boolean" })
+    add_configs("double_precision", { description = "Compiles the library so that all positions are stored in doubles instead of floats. This makes larger worlds possible", default = false, type = "boolean" })
+    add_configs("profile", { description = "Turns on the internal profiler", defines = "JPH_PROFILE_ENABLED"})
+
+    if is_arch("x86", "x64", "x86_64") then
+        add_configs("inst_avx", { description = "Enable AVX CPU instructions (x86/x64 only)", default = false, type = "boolean" })
+        add_configs("inst_avx2", { description = "Enable AVX2 CPU instructions (x86/x64 only)", default = false, type = "boolean" })
+        add_configs("inst_avx512", { description = "Enable AVX512F+AVX512VL CPU instructions (x86/x64 only)", default = false, type = "boolean" })
+        add_configs("inst_f16c", { description = "Enable half float CPU instructions (x86/x64 only)", default = false, type = "boolean" })
+        add_configs("inst_fmadd", { description = "Enable fused multiply add CPU instructions (x86/x64 only)", default = false, type = "boolean" })
+        add_configs("inst_lzcnt", { description = "Enable the lzcnt CPU instruction (x86/x64 only)", default = false, type = "boolean" })
+        add_configs("inst_sse4_1", { description = "Enable SSE4.1 CPU instructions (x86/x64 only)", default = false, type = "boolean" })
+        add_configs("inst_sse4_2", { description = "Enable SSE4.2 CPU instructions (x86/x64 only)", default = false, type = "boolean" })
+        add_configs("inst_tzcnt", { description = "Enable the tzcnt CPU instruction (x86/x64 only)", default = false, type = "boolean" })
+    end
+
+    -- jolt physics doesn't support dynamic link
+    add_configs("shared", {description = "Build shared library.", default = false, type = "boolean", readonly = true})
+
+    if is_plat("linux", "macosx", "iphoneos", "bsd", "wasm") then
+        add_syslinks("pthread")
+    end
+
+    on_load(function (package)
+        if package:is_plat("windows") and not package:config("shared") then
+            package:add("syslinks", "Advapi32")
+        end
+        if package:config("cross_platform_deterministic") then
+            package:add("defines", "JPH_CROSS_PLATFORM_DETERMINISTIC")
+        end
+        if package:config("double_precision") then
+            package:add("defines", "JPH_DOUBLE_PRECISION")
+        end
+    end)
+
+    on_install("windows|x64", "windows|x86", "mingw", "linux", "macosx", "iphoneos", "android|arm64-v8a", "wasm", function (package)
+        os.cp(path.join(os.scriptdir(), "port", "xmake.lua"), "xmake.lua")
+        local configs = {}
+        configs.cross_platform_deterministic = package:config("cross_platform_deterministic")
+        configs.double_precision = package:config("double_precision")
+        if is_arch("x86", "x64", "x86_64") then
+            configs.inst_avx    = package:config("inst_avx")
+            configs.inst_avx2   = package:config("inst_avx2")
+            configs.inst_avx512 = package:config("inst_avx512")
+            configs.inst_f16c   = package:config("inst_f16c")
+            configs.inst_fmadd  = package:config("inst_fmadd")
+            configs.inst_lzcnt  = package:config("inst_lzcnt")
+            configs.inst_sse4_1 = package:config("inst_sse4_1")
+            configs.inst_sse4_2 = package:config("inst_sse4_2")
+            configs.inst_tzcnt  = package:config("inst_tzcnt")
+        end
+        import("package.tools.xmake").install(package, configs)
+    end)
+
+    on_test(function (package)
+        assert(package:check_cxxsnippets({test = [[
+            void test() {
+                JPH::RegisterDefaultAllocator();
+                JPH::PhysicsSystem physics_system;
+                physics_system.OptimizeBroadPhase();
+            }
+        ]]}, {configs = {languages = "c++17"}, includes = {"Jolt/Jolt.h", "Jolt/Physics/PhysicsSystem.h"}}))
+    end)