Skip to content

Commit

Permalink
rm ode;
Browse files Browse the repository at this point in the history
  • Loading branch information
bjornbytes committed May 19, 2024
1 parent f70d987 commit 33d3efe
Show file tree
Hide file tree
Showing 8 changed files with 20 additions and 1,546 deletions.
3 changes: 0 additions & 3 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,6 @@
[submodule "deps/msdfgen"]
path = deps/msdfgen
url = https://github.com/bjornbytes/msdfgen
[submodule "deps/ode"]
path = deps/ode
url = https://github.com/bjornbytes/ode
[submodule "deps/luajit"]
path = deps/luajit
url = https://github.com/WohlSoft/LuaJIT
Expand Down
57 changes: 12 additions & 45 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -35,17 +35,13 @@ option(LOVR_PROFILE "Enable Tracy integration" OFF)

option(LOVR_SYSTEM_GLFW "Use the system-provided glfw" OFF)
option(LOVR_SYSTEM_LUA "Use the system-provided Lua" OFF)
option(LOVR_SYSTEM_ODE "Use the system-provided ODE" OFF)
option(LOVR_SYSTEM_OPENXR "Use the system-provided OpenXR" OFF)

option(LOVR_BUILD_EXE "Build an executable (or an apk on Android)" ON)
option(LOVR_BUILD_SHARED "Build a shared library (takes precedence over LOVR_BUILD_EXE)" 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)

set(LOVR_PHYSICS_LIBRARY "ODE" CACHE STRING "Physics library to use")
set_property(CACHE LOVR_PHYSICS_LIBRARY PROPERTY STRINGS ODE JOLT)

# Setup
if(EMSCRIPTEN)
string(CONCAT EMSCRIPTEN_LINKER_FLAGS
Expand Down Expand Up @@ -161,38 +157,13 @@ if(LOVR_ENABLE_DATA)
endif()
endif()

# ODE
# Jolt
if(LOVR_ENABLE_PHYSICS)
if(LOVR_PHYSICS_LIBRARY STREQUAL "ODE")
if(LOVR_SYSTEM_ODE)
pkg_search_module(ODE REQUIRED ode)
pkg_search_module(CCD REQUIRED ccd)
include_directories(${ODE_INCLUDE_DIRS} ${CCD_INCLUDE_DIRS})
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -lstdc++")
set(LOVR_PHYSICS_LIB ode ccd)
else()
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()
elseif(LOVR_PHYSICS_LIBRARY STREQUAL "JOLT")
set(BUILD_SHARED_LIBS OFF)
set(DEBUG_RENDERER_IN_DEBUG_AND_RELEASE OFF CACHE BOOL "")
set(PROFILER_IN_DEBUG_AND_RELEASE OFF CACHE BOOL "")
add_subdirectory(deps/jolt-physics-sharp jolt)
set(LOVR_PHYSICS_LIB joltc)
endif()
set(BUILD_SHARED_LIBS OFF)
set(DEBUG_RENDERER_IN_DEBUG_AND_RELEASE OFF CACHE BOOL "")
set(PROFILER_IN_DEBUG_AND_RELEASE OFF CACHE BOOL "")
add_subdirectory(deps/jolt-physics-sharp jolt)
set(LOVR_JOLT joltc)
endif()

# glslang
Expand Down Expand Up @@ -350,7 +321,7 @@ target_link_libraries(lovr
${LOVR_GLFW}
${LOVR_LUA}
${LOVR_MSDF}
${LOVR_PHYSICS_LIB}
${LOVR_JOLT}
${LOVR_GLSLANG}
${LOVR_OPENXR}
${LOVR_OCULUS_AUDIO}
Expand Down Expand Up @@ -558,18 +529,14 @@ endif()

if(LOVR_ENABLE_PHYSICS)
target_sources(lovr PRIVATE
src/modules/physics/physics.c
src/api/l_physics.c
src/api/l_physics_collider.c
src/api/l_physics_contact.c
src/api/l_physics_joints.c
src/api/l_physics_shapes.c
src/api/l_physics_world.c
)
if(LOVR_PHYSICS_LIBRARY STREQUAL "ODE")
target_sources(lovr PRIVATE src/modules/physics/physics_ode.c)
elseif(LOVR_PHYSICS_LIBRARY STREQUAL "JOLT")
target_sources(lovr PRIVATE src/modules/physics/physics_jolt.c)
endif()
else()
target_compile_definitions(lovr PRIVATE LOVR_DISABLE_PHYSICS)
endif()
Expand Down Expand Up @@ -724,7 +691,7 @@ if(WIN32)

move_dll(${LOVR_GLFW})
move_dll(${LOVR_LUA})
move_dll(${LOVR_PHYSICS_LIB})
move_dll(${LOVR_JOLT})
move_dll(${LOVR_MSDF})
move_dll(${LOVR_OCULUS_AUDIO})
move_dll(${LOVR_PHONON})
Expand Down Expand Up @@ -775,7 +742,7 @@ elseif(APPLE)
endfunction()
move_lib(${LOVR_GLFW})
move_lib(${LOVR_LUA})
move_lib(${LOVR_PHYSICS_LIB})
move_lib(${LOVR_JOLT})
move_lib(${LOVR_MSDF})
move_lib(${LOVR_OCULUS_AUDIO})
move_lib(${LOVR_PHONON})
Expand Down Expand Up @@ -803,7 +770,7 @@ elseif(ANDROID)
# Dynamically linked targets output libraries in raw/lib/<ABI> for easy including in apk with aapt
set_target_properties(
lovr
${LOVR_PHYSICS_LIB}
${LOVR_JOLT}
${LOVR_MSDF}
PROPERTIES LIBRARY_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/raw/lib/${ANDROID_ABI}"
)
Expand Down Expand Up @@ -926,7 +893,7 @@ elseif(UNIX)
endfunction()
move_lib(${LOVR_GLFW})
move_lib(${LOVR_LUA})
move_lib(${LOVR_PHYSICS_LIB})
move_lib(${LOVR_JOLT})
move_lib(${LOVR_MSDF})
move_lib(${LOVR_OPENXR})
move_lib(${LOVR_OCULUS_AUDIO})
Expand Down
64 changes: 2 additions & 62 deletions Tupfile.lua
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ config = {
glfw = true,
luajit = false,
glslang = true,
physics = 'ode',
utf8 = true,
modules = {
audio = true,
Expand Down Expand Up @@ -293,65 +292,7 @@ if config.modules.data then
end

if config.modules.physics then
cflags += '-Ideps/ode/include'
lflags += '-lode'

-- ou
ode_cflags += '-DMAC_OS_X_VERSION=1030'
ode_cflags += '-D_OU_NAMESPACE=odeou'
ode_cflags += '-D_OU_FEATURE_SET=_OU_FEATURE_SET_TLS'
ode_cflags += '-DdATOMICS_ENABLED=1'
ode_cflags += '-Ideps/ode/ou/include'
ode_src += 'deps/ode/ou/src/ou/*.cpp'

-- ccd
ode_cflags += '-Ideps/ode/libccd/src'
ode_cflags += '-Ideps/ode/libccd/src/custom'
ode_cflags += {
'-DdLIBCCD_ENABLED',
'-DdLIBCCD_INTERNAL',
'-DdLIBCCD_BOX_CYL',
'-DdLIBCCD_CYL_CYL',
'-DdLIBCCD_CAP_CYL',
'-DdLIBCCD_CONVEX_BOX',
'-DdLIBCCD_CONVEX_CAP',
'-DdLIBCCD_CONVEX_CYL',
'-DdLIBCCD_CONVEX_SPHERE',
'-DdLIBCCD_CONVEX_CONVEX'
}
ode_c_src += 'deps/ode/libccd/src/*.c'

-- OPCODE
ode_cflags += '-Ideps/ode/OPCODE'
ode_src += 'deps/ode/OPCODE/*.cpp'
ode_src += 'deps/ode/OPCODE/Ice/*.cpp'

-- ode
ode_cflags += '-fPIC'
ode_cflags += config.optimize and '-DdNODEBUG' or ''
ode_cflags += '-Wno-implicit-float-conversion'
ode_cflags += '-Wno-array-bounds'
ode_cflags += '-Wno-undefined-var-template'
ode_cflags += '-Wno-undefined-bool-conversion'
ode_cflags += '-Wno-unused-value'
ode_cflags += '-Wno-null-dereference'
ode_cflags += '-Ideps/ode/include'
ode_cflags += '-Ideps/ode/ode/src'
ode_c_src += 'deps/ode/ode/src/*.c'
ode_src += {
'deps/ode/ode/src/*.cpp',
'deps/ode/ode/src/joints/*.cpp'
}

for i = #ode_src, 1, -1 do
if ode_src[i]:match('gimpact') or ode_src[i]:match('dif') then
table.remove(ode_src, i)
end
end

tup.foreach_rule(ode_c_src, '^ CC ode/%b^ $(cc) $(flags) $(ode_cflags) -c %f -o %o', '.obj/ode/%B.o')
tup.foreach_rule(ode_src, '^ CC ode/%b^ $(cxx) $(flags) $(ode_cflags) -c %f -o %o', '.obj/ode/%B.o')
tup.rule('.obj/ode/*.o', '^ LD %o^ $(cxx) $(flags) -shared -o %o %f', lib('ode'))
error('Compiling Jolt is not supported yet')
end

if config.headsets.openxr then
Expand Down Expand Up @@ -408,8 +349,7 @@ for module, enabled in pairs(config.modules) do
if enabled then
override = {
audio = 'src/modules/audio/audio.c',
headset = 'src/modules/headset/headset.c',
physics = ('src/modules/physics/physics_%s.c'):format(config.physics)
headset = 'src/modules/headset/headset.c'
}
src += override[module] or ('src/modules/%s/*.c'):format(module)
src += ('src/api/l_%s*.c'):format(module)
Expand Down
1 change: 0 additions & 1 deletion deps/ode
Submodule ode deleted from 3f3b4d
18 changes: 6 additions & 12 deletions src/api/l_physics_shapes.c
Original file line number Diff line number Diff line change
Expand Up @@ -92,20 +92,14 @@ Shape* luax_newmeshshape(lua_State* L, int index) {

luax_readmesh(L, index, &vertices, &vertexCount, &indices, &indexCount, &shouldFree);

// If we do not own the mesh data, we must make a copy
// ode's trimesh collider needs to own the triangle info for the lifetime of the geom
// Note that if shouldFree is true, we don't free the data and let the physics module do it when
// the collider/shape is destroyed
if (!shouldFree) {
float* v = vertices;
uint32_t* i = indices;
vertices = lovrMalloc(3 * vertexCount * sizeof(float));
indices = lovrMalloc(indexCount * sizeof(uint32_t));
memcpy(vertices, v, 3 * vertexCount * sizeof(float));
memcpy(indices, i, indexCount * sizeof(uint32_t));
Shape* shape = lovrMeshShapeCreate(vertexCount, vertices, indexCount, indices);

if (shouldFree) {
lovrFree(vertices);
lovrFree(indices);
}

return lovrMeshShapeCreate(vertexCount, vertices, indexCount, indices);
return shape;
}

Shape* luax_newterrainshape(lua_State* L, int index) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1932,11 +1932,6 @@ MeshShape* lovrMeshShapeCreate(int vertexCount, float vertices[], int indexCount
shape->handle = (JPH_Shape*) JPH_MeshShapeSettings_CreateShape(shape_settings);
JPH_ShapeSettings_Destroy((JPH_ShapeSettings*) shape_settings);
lovrFree(indexedTriangles);
// Note that we're responsible for freeing the vertices/indices when we're done with them because
// ODE took ownership of mesh data. If ODE gets removed, we should probably get rid of this and
// have the caller free the vertices/indices themselves.
lovrFree(vertices);
lovrFree(indices);
return shape;
}

Expand Down
2 changes: 0 additions & 2 deletions src/modules/physics/physics.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@

#pragma once

#define MAX_CONTACTS 10
#define MAX_TAGS 31
#define NO_TAG ~0u

typedef struct World World;
typedef struct Collider Collider;
Expand Down
Loading

0 comments on commit 33d3efe

Please sign in to comment.