Skip to content

Commit

Permalink
[Audio] Fixed linking issues when not using audio
Browse files Browse the repository at this point in the history
- Fixed a few places for other linking issues when not using the overlay

- Renamed RAZ_USE_SOL2 to RAZ_USE_LUA
  - The public option should be general
  • Loading branch information
Razakhel committed Sep 26, 2023
1 parent 467b59b commit 9771d7e
Show file tree
Hide file tree
Showing 13 changed files with 104 additions and 44 deletions.
24 changes: 14 additions & 10 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -283,9 +283,9 @@ if (RAZ_PLATFORM_LINUX)
endif ()
endif ()

################
# RaZ - OpenAL #
################
######################
# RaZ - Audio/OpenAL #
######################

find_package(OpenAL)

Expand Down Expand Up @@ -319,19 +319,24 @@ if (RAZ_USE_AUDIO)
target_link_libraries(RaZ PRIVATE ${OPENAL_LIBRARY})
endif ()
target_compile_definitions(RaZ PUBLIC RAZ_USE_AUDIO)

message(STATUS "[RaZ] Audio ENABLED")
else ()
file(
GLOB
RAZ_AUDIO_FILES

"${PROJECT_SOURCE_DIR}/src/RaZ/Audio/*"
"${PROJECT_SOURCE_DIR}/src/RaZ/Data/WavLoad.cpp"
"${PROJECT_SOURCE_DIR}/src/RaZ/Data/WavSave.cpp"
"${PROJECT_SOURCE_DIR}/src/RaZ/Script/LuaAudio.cpp"

"${PROJECT_SOURCE_DIR}/include/RaZ/Audio/*"
"${PROJECT_SOURCE_DIR}/include/RaZ/Data/WavFormat.hpp"
)

list(REMOVE_ITEM RAZ_FILES ${RAZ_AUDIO_FILES})

message(STATUS "[RaZ] Audio DISABLED")
endif ()

#########################
Expand Down Expand Up @@ -398,10 +403,6 @@ endif ()
# Compiling & linking external libraries
add_subdirectory(extern)

if (RAZ_USE_LIBPNG)
target_link_libraries(RaZ PRIVATE libpng)
endif ()

if (RAZ_USE_GLEW)
target_link_libraries(RaZ PRIVATE GLEW)
endif ()
Expand Down Expand Up @@ -434,7 +435,11 @@ else ()
target_compile_definitions(RaZ PUBLIC RAZ_NO_OVERLAY)
endif ()

if (RAZ_USE_SOL2)
if (RAZ_USE_LIBPNG)
target_link_libraries(RaZ PRIVATE libpng)
endif ()

if (RAZ_USE_LUA)
target_link_libraries(RaZ PRIVATE Sol2 Lua)
else ()
file(
Expand All @@ -444,7 +449,6 @@ else ()
"${PROJECT_SOURCE_DIR}/src/RaZ/Script/*"
"${PROJECT_SOURCE_DIR}/include/RaZ/Script/*"
)

list(REMOVE_ITEM RAZ_FILES ${RAZ_LUA_FILES})

target_compile_definitions(RaZ PUBLIC RAZ_NO_LUA)
Expand Down
8 changes: 4 additions & 4 deletions cmake/FindFBX.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -96,11 +96,11 @@ if (FBX_LIBRARY AND FBX_INCLUDE_DIR)
set(FBX_FOUND ON)
set(FBX_DEFINITIONS -DFBXSDK_SHARED)

message("[FBX] Found:")
message(" - Include directory: ${FBX_INCLUDE_DIR}")
message(" - Library: ${FBX_LIBRARY}")
message(STATUS "[FBX] Found:")
message(STATUS " - Include directory: ${FBX_INCLUDE_DIR}")
message(STATUS " - Library: ${FBX_LIBRARY}")
if (WIN32)
message(" - DLL: ${FBX_DLL}")
message(STATUS " - DLL: ${FBX_DLL}")
endif ()

if (UNIX)
Expand Down
8 changes: 4 additions & 4 deletions cmake/FindOpenAL.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -111,10 +111,10 @@ find_path(
if (OPENAL_LIBRARY AND OPENAL_INCLUDE_DIR)
set(OpenAL_FOUND ON)

message("[OpenAL] Found:")
message(" - Include directory: ${OPENAL_INCLUDE_DIR}")
message(" - Library: ${OPENAL_LIBRARY}")
message(STATUS "[OpenAL] Found:")
message(STATUS " - Include directory: ${OPENAL_INCLUDE_DIR}")
message(STATUS " - Library: ${OPENAL_LIBRARY}")
if (WIN32)
message(" - DLL: ${OPENAL_DLL}")
message(STATUS " - DLL: ${OPENAL_DLL}")
endif ()
endif ()
4 changes: 2 additions & 2 deletions examples/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ target_link_libraries(RaZ_MinDemo RaZ_Examples)
add_executable(RaZ_PhysicsDemo physicsDemo.cpp)
target_link_libraries(RaZ_PhysicsDemo RaZ_Examples)

if (RAZ_USE_SOL2)
if (RAZ_USE_LUA)
add_executable(RaZ_ScriptDemo scriptDemo.cpp)
target_link_libraries(RaZ_ScriptDemo RaZ_Examples)
endif()
Expand Down Expand Up @@ -89,7 +89,7 @@ if (RAZ_USE_EMSCRIPTEN)
set_target_properties(RaZ_AudioDemo PROPERTIES SUFFIX ".html")
endif ()

if (RAZ_USE_SOL2)
if (RAZ_USE_LUA)
set_target_properties(RaZ_ScriptDemo PROPERTIES SUFFIX ".html")
endif()

Expand Down
4 changes: 2 additions & 2 deletions extern/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ if (RAZ_USE_IMGUI)
include(ImGui)
endif ()

option(RAZ_USE_SOL2 "Use Sol2" ON)
if (RAZ_USE_SOL2)
option(RAZ_USE_LUA "Use Lua scripting (with Sol2)" ON)
if (RAZ_USE_LUA)
include(Sol2)
endif ()
2 changes: 2 additions & 0 deletions src/RaZ/Script/LuaCore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,10 @@ void LuaWrapper::registerCoreTypes() {
sol::usertype<World> world = state.new_usertype<World>("World",
sol::constructors<World(),
World(std::size_t)>());
#if defined(RAZ_USE_AUDIO)
world["addAudioSystem"] = sol::overload(&World::addSystem<AudioSystem>,
&World::addSystem<AudioSystem, const char*>);
#endif
world["addBvhSystem"] = &World::addSystem<BvhSystem>;
world["addPhysicsSystem"] = &World::addSystem<PhysicsSystem>;
world["addRenderSystem"] = sol::overload(&World::addSystem<RenderSystem>,
Expand Down
14 changes: 14 additions & 0 deletions src/RaZ/Script/LuaEntity.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#include "RaZ/Entity.hpp"
#if defined(RAZ_USE_AUDIO)
#include "RaZ/Audio/Listener.hpp"
#include "RaZ/Audio/Sound.hpp"
#endif
#include "RaZ/Data/Mesh.hpp"
#include "RaZ/Math/Transform.hpp"
#include "RaZ/Physics/Collider.hpp"
Expand Down Expand Up @@ -39,29 +41,41 @@ void LuaWrapper::registerEntityTypes() {
entity["addComponent"] = bindComponents<Camera,
Collider,
Light,
#if defined(RAZ_USE_AUDIO)
Listener,
#endif
Mesh,
MeshRenderer,
RigidBody,
#if defined(RAZ_USE_AUDIO)
Sound,
#endif
Transform>();
entity["hasCamera"] = &Entity::hasComponent<Camera>;
entity["hasCollider"] = &Entity::hasComponent<Collider>;
entity["hasLight"] = &Entity::hasComponent<Light>;
#if defined(RAZ_USE_AUDIO)
entity["hasListener"] = &Entity::hasComponent<Listener>;
#endif
entity["hasMesh"] = &Entity::hasComponent<Mesh>;
entity["hasMeshRenderer"] = &Entity::hasComponent<MeshRenderer>;
entity["hasRigidBody"] = &Entity::hasComponent<RigidBody>;
#if defined(RAZ_USE_AUDIO)
entity["hasSound"] = &Entity::hasComponent<Sound>;
#endif
entity["hasTransform"] = &Entity::hasComponent<Transform>;
entity["getCamera"] = [] (Entity& e) { return &e.getComponent<Camera>(); };
entity["getCollider"] = [] (Entity& e) { return &e.getComponent<Collider>(); };
entity["getLight"] = [] (Entity& e) { return &e.getComponent<Light>(); };
#if defined(RAZ_USE_AUDIO)
entity["getListener"] = [] (Entity& e) { return &e.getComponent<Listener>(); };
#endif
entity["getMesh"] = [] (Entity& e) { return &e.getComponent<Mesh>(); };
entity["getMeshRenderer"] = [] (Entity& e) { return &e.getComponent<MeshRenderer>(); };
entity["getRigidBody"] = [] (Entity& e) { return &e.getComponent<RigidBody>(); };
#if defined(RAZ_USE_AUDIO)
entity["getSound"] = [] (Entity& e) { return &e.getComponent<Sound>(); };
#endif
entity["getTransform"] = [] (Entity& e) { return &e.getComponent<Transform>(); };
}
}
Expand Down
4 changes: 4 additions & 0 deletions src/RaZ/Script/LuaFileFormat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@
#include "RaZ/Data/OffFormat.hpp"
#include "RaZ/Data/PngFormat.hpp"
#include "RaZ/Data/TgaFormat.hpp"
#if defined(RAZ_USE_AUDIO)
#include "RaZ/Data/WavFormat.hpp"
#endif
#include "RaZ/Render/MeshRenderer.hpp"
#include "RaZ/Script/LuaWrapper.hpp"
#include "RaZ/Utils/FilePath.hpp"
Expand Down Expand Up @@ -81,11 +83,13 @@ void LuaWrapper::registerFileFormatTypes() {
PickOverload<const FilePath&, bool>(&TgaFormat::load));
}

#if defined(RAZ_USE_AUDIO)
{
sol::table wavFormat = state["WavFormat"].get_or_create<sol::table>();
wavFormat["load"] = &WavFormat::load;
wavFormat["save"] = &WavFormat::save;
}
#endif
}

} // namespace Raz
4 changes: 4 additions & 0 deletions src/RaZ/Script/LuaWrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ namespace Raz {
void LuaWrapper::registerTypes() {
[[maybe_unused]] static const bool _ = [] () {
registerAnimationTypes();
#if defined(RAZ_USE_AUDIO)
registerAudioTypes();
#endif
registerCoreTypes();
registerDataTypes();
registerEntityTypes();
Expand All @@ -20,7 +22,9 @@ void LuaWrapper::registerTypes() {
registerMatrixTypes();
registerMeshTypes();
registerMeshRendererTypes();
#if !defined(RAZ_NO_OVERLAY)
registerOverlayTypes();
#endif
registerPhysicsTypes();
registerRenderTypes();
registerRenderGraphTypes();
Expand Down
41 changes: 27 additions & 14 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -70,27 +70,40 @@ set(
include/*.hpp
)

if (RAZ_USE_AUDIO)
list(APPEND RAZ_TESTS_SRC src/RaZ/Audio/*.cpp)

if (WIN32)
# Copying OpenAL's DLL to the tests folder
file(COPY_FILE "${OPENAL_DLL}" "${CMAKE_BINARY_DIR}/tests/OpenAL32.dll")
file(COPY_FILE "${OPENAL_DLL}" "${CMAKE_BINARY_DIR}/tests/libopenal-1.dll")
endif ()
endif ()

if (RAZ_USE_SOL2)
if (RAZ_USE_LUA)
list(APPEND RAZ_TESTS_SRC src/RaZ/Script/*.cpp)
endif ()

file(
GLOB
RAZ_TESTS_FILES
RAZ_TEST_FILES

${RAZ_TESTS_SRC}
)

############################
# RaZ Tests - Audio/OpenAL #
############################

if (RAZ_USE_AUDIO)
file(
GLOB
RAZ_AUDIO_FILES

"${PROJECT_SOURCE_DIR}/src/RaZ/Audio/*.cpp"
)
list(APPEND RAZ_TEST_FILES ${RAZ_AUDIO_TEST_FILES})

if (WIN32)
# Copying OpenAL's DLL to the tests folder
file(COPY_FILE "${OPENAL_DLL}" "${CMAKE_BINARY_DIR}/tests/OpenAL32.dll")
file(COPY_FILE "${OPENAL_DLL}" "${CMAKE_BINARY_DIR}/tests/libopenal-1.dll")
endif ()
else ()
list(REMOVE_ITEM RAZ_TEST_FILES "${PROJECT_SOURCE_DIR}/src/RaZ/Data/WavFormat.cpp")
list(REMOVE_ITEM RAZ_TEST_FILES "${PROJECT_SOURCE_DIR}/src/RaZ/Script/LuaAudio.cpp")
endif ()

###############################
# RaZ Tests - FBX file format #
###############################
Expand All @@ -101,7 +114,7 @@ if (MSVC AND RAZ_USE_FBX)
else ()
list(
REMOVE_ITEM
RAZ_TESTS_FILES
RAZ_TEST_FILES

"${PROJECT_SOURCE_DIR}/src/RaZ/Data/FbxFormat.cpp"
)
Expand All @@ -111,7 +124,7 @@ endif ()
# RaZ Tests - Build #
#####################

target_sources(RaZ_Tests PRIVATE ${RAZ_TESTS_FILES})
target_sources(RaZ_Tests PRIVATE ${RAZ_TEST_FILES})

target_include_directories(
RaZ_Tests
Expand Down
2 changes: 2 additions & 0 deletions tests/src/RaZ/Render/RenderSystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ TEST_CASE("RenderSystem Cook-Torrance ball") {
CHECK_THAT(renderFrame(world), IsNearlyEqualToImage(Raz::ImageFormat::load(RAZ_TESTS_ROOT "assets/renders/cook-torrance_ball_cubemap_base.png", true)));
}

#if !defined(RAZ_NO_OVERLAY)
TEST_CASE("RenderSystem overlay render") {
Raz::World world(1);

Expand Down Expand Up @@ -156,3 +157,4 @@ TEST_CASE("RenderSystem overlay render") {
overlay3.disable();
}
}
#endif
31 changes: 23 additions & 8 deletions tests/src/RaZ/Script/LuaCore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,33 +46,42 @@ TEST_CASE("LuaCore Entity") {
entity:addComponent(Camera.new())
entity:addComponent(Collider.new())
entity:addComponent(Light.new(LightType.POINT, 1))
entity:addComponent(Listener.new())
entity:addComponent(Mesh.new())
entity:addComponent(MeshRenderer.new())
entity:addComponent(RigidBody.new(0, 0))
entity:addComponent(Sound.new())
entity:addComponent(Transform.new())
assert(entity:hasCamera())
assert(entity:hasCollider())
assert(entity:hasLight())
assert(entity:hasListener())
assert(entity:hasMesh())
assert(entity:hasMeshRenderer())
assert(entity:hasRigidBody())
assert(entity:hasSound())
assert(entity:hasTransform())
assert(entity:getCamera() ~= nil)
assert(entity:getCollider() ~= nil)
assert(entity:getLight() ~= nil)
assert(entity:getListener() ~= nil)
assert(entity:getMesh() ~= nil)
assert(entity:getMeshRenderer() ~= nil)
assert(entity:getRigidBody() ~= nil)
assert(entity:getSound() ~= nil)
assert(entity:getTransform() ~= nil)
)"));

#if defined(RAZ_USE_AUDIO)
CHECK(Raz::LuaWrapper::execute(R"(
local entity = Entity.new(0)
entity:addComponent(Listener.new())
entity:addComponent(Sound.new())
assert(entity:hasListener())
assert(entity:hasSound())
assert(entity:getListener() ~= nil)
assert(entity:getSound() ~= nil)
)"));
#endif
}

TEST_CASE("LuaCore World") {
Expand All @@ -86,14 +95,20 @@ TEST_CASE("LuaCore World") {
world:refresh()
world:destroy()
world:addAudioSystem()
world:addAudioSystem("")
world:addBvhSystem()
world:addPhysicsSystem()
world:addRenderSystem()
world:addRenderSystem(1, 1)
)"));

#if defined(RAZ_USE_AUDIO)
CHECK(Raz::LuaWrapper::execute(R"(
local world = World.new()
world:addAudioSystem()
world:addAudioSystem("")
)"));
#endif

#if !defined(RAZ_NO_WINDOW)
CHECK(Raz::LuaWrapper::execute(R"(
local world = World.new()
Expand Down
Loading

0 comments on commit 9771d7e

Please sign in to comment.