Jolt physics engine integration

This commit is contained in:
Josip Miskovic 2024-01-30 18:22:27 +01:00
parent 06bfbbaa6b
commit 1ad8f23fb8
6 changed files with 1524 additions and 26 deletions

3
.gitmodules vendored
View File

@ -31,3 +31,6 @@
[submodule "plugins/lovr-http"] [submodule "plugins/lovr-http"]
path = plugins/lovr-http path = plugins/lovr-http
url = https://github.com/bjornbytes/lovr-http url = https://github.com/bjornbytes/lovr-http
[submodule "deps/jolt-physics-sharp"]
path = deps/jolt-physics-sharp
url = https://github.com/amerkoleci/JoltPhysicsSharp

View File

@ -41,6 +41,10 @@ option(LOVR_BUILD_SHARED "Build a shared library (takes precedence over LOVR_BUI
option(LOVR_BUILD_BUNDLE "On macOS, build a .app bundle instead of a raw program" OFF) option(LOVR_BUILD_BUNDLE "On macOS, build a .app bundle instead of a raw program" OFF)
option(LOVR_BUILD_WITH_SYMBOLS "Build with C function symbols exposed" OFF) option(LOVR_BUILD_WITH_SYMBOLS "Build with C function symbols exposed" OFF)
set(LOVR_PHYSICS_LIBRARY "JOLT" CACHE STRING "Physics library to use")
set_property(CACHE LOVR_PHYSICS_LIBRARY PROPERTY STRINGS ODE JOLT)
message(STATUS "Physics library: ${LOVR_PHYSICS_LIBRARY}")
# Setup # Setup
if(EMSCRIPTEN) if(EMSCRIPTEN)
string(CONCAT EMSCRIPTEN_LINKER_FLAGS string(CONCAT EMSCRIPTEN_LINKER_FLAGS
@ -158,27 +162,37 @@ endif()
# ODE # ODE
if(LOVR_ENABLE_PHYSICS) if(LOVR_ENABLE_PHYSICS)
if(LOVR_SYSTEM_ODE) if(LOVR_PHYSICS_LIBRARY STREQUAL "ODE")
pkg_search_module(ODE REQUIRED ode) if(LOVR_SYSTEM_ODE)
pkg_search_module(CCD REQUIRED ccd) pkg_search_module(ODE REQUIRED ode)
include_directories(${ODE_INCLUDE_DIRS} ${CCD_INCLUDE_DIRS}) pkg_search_module(CCD REQUIRED ccd)
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -lstdc++") include_directories(${ODE_INCLUDE_DIRS} ${CCD_INCLUDE_DIRS})
set(LOVR_ODE ode ccd) set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -lstdc++")
else() set(LOVR_PHYSICS_LIB ode ccd)
if(EMSCRIPTEN)
set(ODE_BUILD_SHARED OFF CACHE BOOL "")
else() else()
set(ODE_BUILD_SHARED ON CACHE BOOL "") if(EMSCRIPTEN)
set(ODE_BUILD_SHARED OFF CACHE BOOL "")
else()
set(ODE_BUILD_SHARED ON CACHE BOOL "")
endif()
add_subdirectory(deps/ode ode)
if(MSVC)
set_target_properties(ode PROPERTIES COMPILE_FLAGS "/wd4244 /wd4267")
target_compile_definitions(ode PRIVATE _CRT_SECURE_NO_WARNINGS)
else()
set_target_properties(ode PROPERTIES COMPILE_FLAGS "-Wno-unused-volatile-lvalue -Wno-array-bounds -Wno-undefined-var-template")
endif()
include_directories(deps/ode/include "${CMAKE_CURRENT_BINARY_DIR}/ode/include")
set(LOVR_PHYSICS_LIB ode)
endif() endif()
add_subdirectory(deps/ode ode) elseif(LOVR_PHYSICS_LIBRARY STREQUAL "JOLT")
if(MSVC) set(BUILD_SHARED_LIBS OFF)
set_target_properties(ode PROPERTIES COMPILE_FLAGS "/wd4244 /wd4267") include_directories(deps/jolt-physics-sharp/src/joltc)
target_compile_definitions(ode PRIVATE _CRT_SECURE_NO_WARNINGS) add_subdirectory(deps/jolt-physics-sharp/src/joltc jolt)
else() target_compile_options(joltc PRIVATE -Wno-comment)
set_target_properties(ode PROPERTIES COMPILE_FLAGS "-Wno-unused-volatile-lvalue -Wno-array-bounds -Wno-undefined-var-template") set(PHYSICS_REPO_ROOT ${CMAKE_SOURCE_DIR}/deps/jolt-physics-sharp/src/joltc)
endif() include(deps/jolt-physics-sharp/src/joltc/Jolt/Jolt.cmake)
include_directories(deps/ode/include "${CMAKE_CURRENT_BINARY_DIR}/ode/include") set(LOVR_PHYSICS_LIB joltc)
set(LOVR_ODE ode)
endif() endif()
endif() endif()
@ -336,7 +350,7 @@ target_link_libraries(lovr
${LOVR_GLFW} ${LOVR_GLFW}
${LOVR_LUA} ${LOVR_LUA}
${LOVR_MSDF} ${LOVR_MSDF}
${LOVR_ODE} ${LOVR_PHYSICS_LIB}
${LOVR_GLSLANG} ${LOVR_GLSLANG}
${LOVR_OPENXR} ${LOVR_OPENXR}
${LOVR_OCULUS_AUDIO} ${LOVR_OCULUS_AUDIO}
@ -533,13 +547,19 @@ endif()
if(LOVR_ENABLE_PHYSICS) if(LOVR_ENABLE_PHYSICS)
target_sources(lovr PRIVATE target_sources(lovr PRIVATE
src/modules/physics/physics.c
src/api/l_physics.c src/api/l_physics.c
src/api/l_physics_collider.c src/api/l_physics_collider.c
src/api/l_physics_joints.c src/api/l_physics_joints.c
src/api/l_physics_shapes.c src/api/l_physics_shapes.c
src/api/l_physics_world.c src/api/l_physics_world.c
) )
if(LOVR_PHYSICS_LIBRARY STREQUAL "ODE")
message(STATUS "Using ODE physics library")
target_sources(lovr PRIVATE src/modules/physics/physics_ode.c)
elseif(LOVR_PHYSICS_LIBRARY STREQUAL "JOLT")
message(STATUS "Using JOLT physics library")
target_sources(lovr PRIVATE src/modules/physics/physics_jolt.c)
endif()
else() else()
target_compile_definitions(lovr PRIVATE LOVR_DISABLE_PHYSICS) target_compile_definitions(lovr PRIVATE LOVR_DISABLE_PHYSICS)
endif() endif()
@ -693,7 +713,7 @@ if(WIN32)
move_dll(${LOVR_GLFW}) move_dll(${LOVR_GLFW})
move_dll(${LOVR_LUA}) move_dll(${LOVR_LUA})
move_dll(${LOVR_ODE}) move_dll(${LOVR_PHYSICS_LIB})
move_dll(${LOVR_MSDF}) move_dll(${LOVR_MSDF})
move_dll(${LOVR_OCULUS_AUDIO}) move_dll(${LOVR_OCULUS_AUDIO})
move_dll(${LOVR_PHONON}) move_dll(${LOVR_PHONON})
@ -744,7 +764,7 @@ elseif(APPLE)
endfunction() endfunction()
move_lib(${LOVR_GLFW}) move_lib(${LOVR_GLFW})
move_lib(${LOVR_LUA}) move_lib(${LOVR_LUA})
move_lib(${LOVR_ODE}) move_lib(${LOVR_PHYSICS_LIB})
move_lib(${LOVR_MSDF}) move_lib(${LOVR_MSDF})
move_lib(${LOVR_OCULUS_AUDIO}) move_lib(${LOVR_OCULUS_AUDIO})
move_lib(${LOVR_PHONON}) move_lib(${LOVR_PHONON})
@ -772,7 +792,7 @@ elseif(ANDROID)
# Dynamically linked targets output libraries in raw/lib/<ABI> for easy including in apk with aapt # Dynamically linked targets output libraries in raw/lib/<ABI> for easy including in apk with aapt
set_target_properties( set_target_properties(
lovr lovr
${LOVR_ODE} ${LOVR_PHYSICS_LIB}
${LOVR_MSDF} ${LOVR_MSDF}
PROPERTIES LIBRARY_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/raw/lib/${ANDROID_ABI}" PROPERTIES LIBRARY_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/raw/lib/${ANDROID_ABI}"
) )
@ -895,7 +915,7 @@ elseif(UNIX)
endfunction() endfunction()
move_lib(${LOVR_GLFW}) move_lib(${LOVR_GLFW})
move_lib(${LOVR_LUA}) move_lib(${LOVR_LUA})
move_lib(${LOVR_ODE}) move_lib(${LOVR_PHYSICS_LIB})
move_lib(${LOVR_MSDF}) move_lib(${LOVR_MSDF})
move_lib(${LOVR_OPENXR}) move_lib(${LOVR_OPENXR})
move_lib(${LOVR_OCULUS_AUDIO}) move_lib(${LOVR_OCULUS_AUDIO})

1
deps/jolt-physics-sharp vendored Submodule

@ -0,0 +1 @@
Subproject commit 0d3dcfaf205297856f60e7a7ff87fa34106e16a5

File diff suppressed because it is too large Load Diff

View File

@ -36,7 +36,7 @@ void lovrLog(int level, const char* tag, const char* format, ...) {
va_end(args); va_end(args);
} }
// Refcounting // Refcounting; to be reference-counted the object must have uint ref field as struct's first member
#if ATOMIC_INT_LOCK_FREE != 2 #if ATOMIC_INT_LOCK_FREE != 2
#error "Lock-free integer atomics are not supported on this platform, but are required for refcounting" #error "Lock-free integer atomics are not supported on this platform, but are required for refcounting"
#endif #endif