Skip to content

Commit

Permalink
Added sound module disable option, fixed games project building
Browse files Browse the repository at this point in the history
- Refactored cmake build options for modules
- added new option MODULE_SOUNDS_ENABLED
- fixed UITranformComponent usage in game projects
- disabled blur by default
- fixed codacy issues
  • Loading branch information
denyskryvytskyi committed May 4, 2024
1 parent f36901d commit 218a9b6
Show file tree
Hide file tree
Showing 23 changed files with 133 additions and 82 deletions.
23 changes: 14 additions & 9 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,10 @@ set_property(GLOBAL PROPERTY USE_FOLDERS ON)

option(BUILD_SANDBOX "build sandbox projects" ON)
option(BUILD_GAMES "build games" ON)
option(EDITOR_MODE "Enable ImGUI editor overlay" ON)
option(PROFILE_MODE "Enable functions profiling" ON)
option(THREE_D_MODE "Enable 3D module with Assimp support" ON)
option(MODULE_EDITOR_ENABLED "Enable ImGUI-based editor" ON)
option(MODULE_3D_ENABLED "Enable 3D module with Assimp support" ON)
option(MODULE_SOUND_ENABLED "Enable sound module with irrklang support" ON)

if(WIN32)
add_compile_definitions(
Expand All @@ -25,16 +26,20 @@ else()
message("This is not supported platform for now!")
endif()

if (EDITOR_MODE)
add_compile_definitions(EDITOR_MODE)
endif()

if (PROFILE_MODE)
add_compile_definitions(PROFILE_MODE)
endif()

if (THREE_D_MODE)
add_compile_definitions(THREE_D_MODE)
if (MODULE_EDITOR_ENABLED)
add_compile_definitions(MODULE_EDITOR_ENABLED)
endif()

if (MODULE_3D_ENABLED)
add_compile_definitions(MODULE_3D_ENABLED)
endif()

if (MODULE_SOUND_ENABLED)
add_compile_definitions(MODULE_SOUND_ENABLED)
endif()

add_subdirectory(Engine)
Expand All @@ -43,7 +48,7 @@ set(ElvenEngine_ROOT_DIR ${CMAKE_CURRENT_SOURCE_DIR})


if (BUILD_SANDBOX)
if (THREE_D_MODE)
if (MODULE_3D_ENABLED)
add_subdirectory(Sandbox3D)
set(STARTUP_PROJECT_NAME "Sandbox3D")
else()
Expand Down
71 changes: 45 additions & 26 deletions Engine/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ set(ENGINE_HEADERS
)

#editor stuff
if (EDITOR_MODE)
if (MODULE_EDITOR_ENABLED)
set(ENGINE_HEADERS
${ENGINE_HEADERS}
"src/Editor/ImGuiOverlay.h"
Expand Down Expand Up @@ -148,7 +148,7 @@ set(ENGINE_SOURCES
${ENGINE_HEADERS}
)

if (EDITOR_MODE)
if (MODULE_EDITOR_ENABLED)
set(ENGINE_SOURCES
${ENGINE_SOURCES}
"src/Editor/ImGuiOverlay.cpp"
Expand Down Expand Up @@ -180,22 +180,32 @@ ${VENDOR_PATH}/spdlog/include
${VENDOR_PATH}/stb/include
${VENDOR_PATH}/json/include
${VENDOR_PATH}/freetype/include
${VENDOR_PATH}/irrklang/include
${VENDOR_PATH}/fmt/include
${VENDOR_PATH}/assimp/include
${PROJECT_SOURCE_DIR}/build_vendor/assimp/include # include generated config.h for assimp
)

if (EDITOR_MODE)
if (MODULE_EDITOR_ENABLED)
set(ENGINE_INCLUDE_DIRS
${ENGINE_INCLUDE_DIRS}
${VENDOR_PATH}/imgui/include
)
endif()

target_include_directories(${LIBRARY_NAME}
PUBLIC ${ENGINE_INCLUDE_DIRS}
)
if (MODULE_SOUND_ENABLED)
set(ENGINE_INCLUDE_DIRS
${ENGINE_INCLUDE_DIRS}
${VENDOR_PATH}/irrklang/include
)
endif()

if (MODULE_3D_ENABLED)
set(ENGINE_INCLUDE_DIRS
${ENGINE_INCLUDE_DIRS}
${VENDOR_PATH}/assimp/include
${PROJECT_SOURCE_DIR}/build_vendor/assimp/include # include generated config.h for assimp
)
endif()

target_include_directories(${LIBRARY_NAME} PUBLIC ${ENGINE_INCLUDE_DIRS})

set(VENDOR_PATH_DEBUG ${PROJECT_SOURCE_DIR}/build_vendor/lib/Debug/)
set(VENDOR_PATH_RELEASE ${PROJECT_SOURCE_DIR}/build_vendor/lib/Release/)
Expand All @@ -206,39 +216,48 @@ find_library(spdlog_d NAMES spdlogd PATHS ${VENDOR_PATH_DEBUG})
find_library(stb_d NAMES stb PATHS ${VENDOR_PATH_DEBUG})
find_library(freetype_d NAMES freetyped PATHS ${VENDOR_PATH_DEBUG})
find_library(fmt_d NAMES fmtd PATHS ${VENDOR_PATH_DEBUG})
find_library(imgui_d NAMES imgui imguid PATHS ${VENDOR_PATH_DEBUG})
find_library(assimp_d NAMES assimp-vc143-mtd PATHS ${VENDOR_PATH_DEBUG})
find_library(zlib_d NAMES zlibstaticd PATHS ${VENDOR_PATH_DEBUG})

find_library(glad NAMES glad PATHS ${VENDOR_PATH_RELEASE})
find_library(glfw NAMES glfw3 PATHS ${VENDOR_PATH_RELEASE})
find_library(spdlog NAMES spdlog PATHS ${VENDOR_PATH_RELEASE})
find_library(stb NAMES stb PATHS ${VENDOR_PATH_RELEASE})
find_library(freetype NAMES freetype PATHS ${VENDOR_PATH_RELEASE})
find_library(fmt NAMES fmt PATHS ${VENDOR_PATH_RELEASE})
find_library(imgui NAMES imgui PATHS ${VENDOR_PATH_RELEASE})
find_library(irrklang NAMES irrKlang.lib PATHS ${VENDOR_PATH}/irrklang/lib)
find_library(assimp NAMES assimp-vc143-mt PATHS ${VENDOR_PATH_RELEASE})
find_library(zlib NAMES zlibstatic PATHS ${VENDOR_PATH_RELEASE})

set(VENDOR
debug ${glfw_d} optimized ${glfw}
debug ${glad_d} optimized ${glad}
debug ${spdlog_d} optimized ${spdlog}
debug ${stb_d} optimized ${stb}
debug ${freetype_d} optimized ${freetype}
debug ${irrklang} optimized ${irrklang}
debug ${fmt_d} optimized ${fmt}
debug ${glfw_d} optimized ${glfw}
debug ${glad_d} optimized ${glad}
debug ${spdlog_d} optimized ${spdlog}
debug ${stb_d} optimized ${stb}
debug ${freetype_d} optimized ${freetype}
debug ${fmt_d} optimized ${fmt}
)

if (EDITOR_MODE)
if (MODULE_EDITOR_ENABLED)
find_library(imgui_d NAMES imgui imguid PATHS ${VENDOR_PATH_DEBUG})
find_library(imgui NAMES imgui PATHS ${VENDOR_PATH_RELEASE})

set(VENDOR
${VENDOR}
debug ${imgui_d} optimized ${imgui}

)
endif()

if (MODULE_SOUND_ENABLED)
find_library(irrklang NAMES irrKlang.lib PATHS ${VENDOR_PATH}/irrklang/lib)

set(VENDOR
${VENDOR}
debug ${irrklang} optimized ${irrklang}
)
endif()

if (THREE_D_MODE)
if (MODULE_3D_ENABLED)
find_library(assimp_d NAMES assimp-vc143-mtd PATHS ${VENDOR_PATH_DEBUG})
find_library(zlib_d NAMES zlibstaticd PATHS ${VENDOR_PATH_DEBUG})
find_library(assimp NAMES assimp-vc143-mt PATHS ${VENDOR_PATH_RELEASE})
find_library(zlib NAMES zlibstatic PATHS ${VENDOR_PATH_RELEASE})

set(VENDOR
${VENDOR}
debug ${assimp_d} optimized ${assimp}
Expand Down
6 changes: 3 additions & 3 deletions Engine/src/Core/Application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ Application::Application()
gAudioManager.Init();
gSceneManager.Init();

#if EDITOR_MODE
#if MODULE_EDITOR_ENABLED
if (gEngineSettings.enableEditor) {
m_imGuiOverlay.Init();
m_editor.OnInit();
Expand Down Expand Up @@ -80,7 +80,7 @@ Application::~Application()
{
OnDestroy();

#if EDITOR_MODE
#if MODULE_EDITOR_ENABLED
if (gEngineSettings.enableEditor) {
m_imGuiOverlay.Shutdown();
}
Expand Down Expand Up @@ -153,7 +153,7 @@ void Application::Run()
m_renderer.EndScene();
}

#if EDITOR_MODE
#if MODULE_EDITOR_ENABLED
if (gEngineSettings.enableEditor) {
PROFILE_SCOPE("ImGui Render in: ");
m_imGuiOverlay.Begin();
Expand Down
6 changes: 3 additions & 3 deletions Engine/src/Core/Application.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#include "Renderer/Renderer.h"
#include "Scene/Entity.h"

#if EDITOR_MODE
#if MODULE_EDITOR_ENABLED
# include "Editor/Editor.h"
# include "Editor/ImGuiOverlay.h"
#endif
Expand Down Expand Up @@ -48,7 +48,7 @@ class Application {
virtual void OnUpdate(float dt) {};
virtual void OnRender(float dt) {};
virtual void OnProcessInput(float dt) {};
#if EDITOR_MODE
#if MODULE_EDITOR_ENABLED
virtual void OnImguiRender() {};
#endif
virtual void OnDestroy() {};
Expand Down Expand Up @@ -76,7 +76,7 @@ class Application {
ecs::Entity m_fpsCounterEntityId { 0 };
bool m_isPaused { false };

#if EDITOR_MODE
#if MODULE_EDITOR_ENABLED
ImGuiOverlay m_imGuiOverlay;
editor::Editor m_editor;
#endif
Expand Down
3 changes: 1 addition & 2 deletions Engine/src/Editor/Editor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,6 @@ void DrawPostProcessSettings(Renderer& renderer)
const bool is_selected = (currentIndex == i);
if (ImGui::Selectable(items[i], is_selected)) {
currentIndex = i;
itemStr = items[currentIndex];
postProcessor.GradientMaskType = static_cast<PostProcessor::BlurGradientMaskType>(currentIndex);
}

Expand All @@ -125,7 +124,7 @@ void DrawPostProcessSettings(Renderer& renderer)
ImVec4 tint_col = ImVec4(1.0f, 1.0f, 1.0f, 1.0f);
ImVec4 border_col = ImVec4(1.0f, 1.0f, 1.0f, 0.5f);

ImGui::Image((void*)(intptr_t)postProcessor.GetMaskTextureId(), ImVec2(kMaskPreviewWidth, kMaskPreviewHeight), uv_min, uv_max, tint_col, border_col);
ImGui::Image(reinterpret_cast<void*>((intptr_t)postProcessor.GetMaskTextureId()), ImVec2(kMaskPreviewWidth, kMaskPreviewHeight), uv_min, uv_max, tint_col, border_col);
ImGui::TreePop();
}
}
Expand Down
2 changes: 1 addition & 1 deletion Engine/src/Editor/Panels/SceneHierarchyPanel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ void SceneHierarchyPanel::DrawEntity(const ecs::Entity parentEntity)
nodeName = fmt::format("Entity_{}", m_entityNameCounter++);
}

const bool opened = ImGui::TreeNodeEx((void*)(intptr_t)nodeEntity, flags, nodeName.c_str());
const bool opened = ImGui::TreeNodeEx(reinterpret_cast<void*>((intptr_t)nodeEntity), flags, nodeName.c_str());
if (ImGui::IsItemClicked()) {
m_selectedEntity = nodeEntity;
}
Expand Down
2 changes: 1 addition & 1 deletion Engine/src/Elven.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

#include "Events/EventManager.h"

#if EDITOR_MODE
#if MODULE_EDITOR_ENABLED
# include "Editor/ImGuiOverlay.h"
#endif

Expand Down
2 changes: 1 addition & 1 deletion Engine/src/Renderer/PostProcessor.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class PostProcessor {
void CreateExponentialGradientMask(unsigned char* data);

public:
bool IsBlurEnabled { true };
bool IsBlurEnabled { false };
int BlurMaskThreshold { 0 };
BlurGradientMaskType GradientMaskType { BlurGradientMaskType::Linear };

Expand Down
23 changes: 22 additions & 1 deletion Engine/src/Resources/AudioManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,26 @@
#include "Core/Profiler.h"
#include "Core/Timer.h"

#include <irrKlang.h>
#if MODULE_SOUND_ENABLED
# include <irrKlang.h>
#endif

namespace elv {

AudioManager gAudioManager;

void AudioManager::Init()
{
#if MODULE_SOUND_ENABLED
m_engine = irrklang::createIrrKlangDevice();
#else
EL_CORE_WARN("Sound module is disabled!")
#endif
}

void AudioManager::Shutdown()
{
#if MODULE_SOUND_ENABLED
for (auto& it : m_sounds) {
if (it.second.sound) {
it.second.sound->stop();
Expand All @@ -27,10 +34,13 @@ void AudioManager::Shutdown()
}

m_engine->drop();
#else
#endif
}

void AudioManager::AddSound(const std::string& name, const std::string& path)
{
#if MODULE_SOUND_ENABLED
irrklang::ISoundSource* source = nullptr;
{
PROFILE_TO_LOG(fmt::format("Audio file {} is loaded in:", name));
Expand All @@ -39,20 +49,24 @@ void AudioManager::AddSound(const std::string& name, const std::string& path)
if (source) {
m_sounds.insert({ name, { nullptr, source } });
}
#endif
}

void AudioManager::SetVolume(const std::string& name, float volume)
{
#if MODULE_SOUND_ENABLED
auto it = m_sounds.find(name);
if (it != m_sounds.end() && it->second.sound) {
it->second.sound->setVolume(volume);
} else {
EL_CORE_WARN("Set volume failed: {0} sound isn't exist.", name);
}
#endif
}

void AudioManager::Play(const std::string& name, bool looped)
{
#if MODULE_SOUND_ENABLED
auto it = m_sounds.find(name);
if (it != m_sounds.end()) {
if (it->second.sound) {
Expand All @@ -69,20 +83,24 @@ void AudioManager::Play(const std::string& name, bool looped)
} else {
EL_CORE_WARN("Audio play failed: {0} isn't exist.", name);
}
#endif
}

void AudioManager::Pause(const std::string& name)
{
#if MODULE_SOUND_ENABLED
auto it = m_sounds.find(name);
if (it != m_sounds.end() && it->second.sound) {
it->second.sound->setIsPaused(true);
} else {
EL_CORE_WARN("Audio pause failed: {0} isn't exist.", name);
}
#endif
}

void AudioManager::Stop(const std::string& name)
{
#if MODULE_SOUND_ENABLED
auto it = m_sounds.find(name);
if (it != m_sounds.end() && it->second.sound) {
it->second.sound->stop();
Expand All @@ -91,15 +109,18 @@ void AudioManager::Stop(const std::string& name)
} else {
EL_CORE_WARN("Audio stop failed: {0} isn't exist.", name);
}
#endif
}
std::vector<std::string> AudioManager::GetSounds() const
{
std::vector<std::string> names;
#if MODULE_SOUND_ENABLED

for (const auto soundInfo : m_sounds) {
names.emplace_back(soundInfo.first);
}

#endif
return names;
}
} // namespace elv
Loading

0 comments on commit 218a9b6

Please sign in to comment.