From 2876ee701b1facf3756b1406bac773f5c12ba83b Mon Sep 17 00:00:00 2001 From: Antoine Pilote Date: Wed, 2 Apr 2025 16:49:53 -0400 Subject: [PATCH] Removed audio from core engine and moved to module only --- .../Source/Editor/Windows/EditorInterface.cpp | 1 - Nuake/Source/Nuake/Core/MulticastDelegate.h | 2 +- .../Nuake/Modules/AudioModule/AudioModule.cpp | 36 ++---- Nuake/Source/Nuake/Scene/Scene.cpp | 2 - .../Nuake/Scene/Systems/AudioSystem.cpp | 113 ------------------ .../Source/Nuake/Scene/Systems/AudioSystem.h | 20 ---- 6 files changed, 8 insertions(+), 166 deletions(-) delete mode 100644 Nuake/Source/Nuake/Scene/Systems/AudioSystem.cpp delete mode 100644 Nuake/Source/Nuake/Scene/Systems/AudioSystem.h diff --git a/Editor/Source/Editor/Windows/EditorInterface.cpp b/Editor/Source/Editor/Windows/EditorInterface.cpp index 5a573e35..b10531d9 100644 --- a/Editor/Source/Editor/Windows/EditorInterface.cpp +++ b/Editor/Source/Editor/Windows/EditorInterface.cpp @@ -42,7 +42,6 @@ #include "Nuake/Rendering/SceneRenderer.h" #include #include "UIDemoWindow.h" -#include #include #include "Nuake/FileSystem/FileSystem.h" diff --git a/Nuake/Source/Nuake/Core/MulticastDelegate.h b/Nuake/Source/Nuake/Core/MulticastDelegate.h index ac5349e2..ea28a591 100644 --- a/Nuake/Source/Nuake/Core/MulticastDelegate.h +++ b/Nuake/Source/Nuake/Core/MulticastDelegate.h @@ -63,7 +63,7 @@ public: // Remove a callable using the token returned by Add() void Remove(DelegateHandle& handle) { - ASSERT(handle.IsValid()); + //assert(handle.IsValid()); if (handle.IsValid() && handle.id < delegates.size()) { diff --git a/Nuake/Source/Nuake/Modules/AudioModule/AudioModule.cpp b/Nuake/Source/Nuake/Modules/AudioModule/AudioModule.cpp index 2afe3445..6d0b6e3d 100644 --- a/Nuake/Source/Nuake/Modules/AudioModule/AudioModule.cpp +++ b/Nuake/Source/Nuake/Modules/AudioModule/AudioModule.cpp @@ -5,6 +5,8 @@ #include "Nuake/Modules/ModuleDB.h" #include +#include "Nuake/Audio/AudioManager.h" + void PlayAudio(int id, Nuake::Matrix4 volume) { @@ -42,37 +44,13 @@ void AudioModule_Startup() module.BindFunction("PlayAudio", "id", "volume"); module.BindFunction("StopAudio"); - Logger::Log("AudioModule exposed API:", "Module", VERBOSE); - - auto reflection = module.Resolve(); - auto metaTypeid = entt::hashed_string(module.Name.c_str()); - auto s = reflection.func(metaTypeid); - for (auto [id, func] : reflection.func()) - { - const std::string_view returnType = func.ret().info().name(); - const std::string_view funcName = module.GetTypeName(id); - - std::string msg = std::string(returnType) + " " + std::string(funcName) + "("; - auto argNames = module.GetFuncArgNames(id); - std::vector args; - for (int i = 0; i < func.arity(); i++) - { - const std::string argType = std::string(func.arg(i).info().name()); - args.push_back(argType); - - msg += argType + " " + argNames[i]; - - if (i < func.arity() - 1) - { - msg += ", "; - } - } - msg += ")"; - - Logger::Log(msg, "", VERBOSE); - } + AudioManager::Get().Initialize(); SceneSystemDB::Get().RegisterSceneSystem(); + + module.OnUpdate.AddStatic([](float ts) { + AudioManager::Get().AudioUpdate(); + }); } void AudioModule_Shutdown() diff --git a/Nuake/Source/Nuake/Scene/Scene.cpp b/Nuake/Source/Nuake/Scene/Scene.cpp index bdb74ed6..0e2bb62f 100644 --- a/Nuake/Source/Nuake/Scene/Scene.cpp +++ b/Nuake/Source/Nuake/Scene/Scene.cpp @@ -14,7 +14,6 @@ #include "Nuake/Scene/Systems/QuakeMapBuilder.h" #include "Nuake/Scene/Systems/ParticleSystem.h" #include "Nuake/Scene/Systems/AnimationSystem.h" -#include "Nuake/Scene/Systems/AudioSystem.h" #include "Nuake/Scene/Systems/UISystem.h" #include "Nuake/Rendering/SceneRenderer.h" @@ -74,7 +73,6 @@ namespace Nuake m_Systems.push_back(CreateRef(this)); m_Systems.push_back(CreateRef(this)); m_Systems.push_back(CreateRef(this)); - //m_Systems.push_back(CreateRef(this)); m_SceneRenderer = CreateRef(); m_SceneRenderer->Init(); diff --git a/Nuake/Source/Nuake/Scene/Systems/AudioSystem.cpp b/Nuake/Source/Nuake/Scene/Systems/AudioSystem.cpp deleted file mode 100644 index d8b687db..00000000 --- a/Nuake/Source/Nuake/Scene/Systems/AudioSystem.cpp +++ /dev/null @@ -1,113 +0,0 @@ -#include "AudioSystem.h" - -#include "Engine.h" -#include "Nuake/Scene/Scene.h" -#include "Nuake/Scene/Entities/Entity.h" -#include "Nuake/Scene/Components/AudioEmitterComponent.h" -#include "Nuake/FileSystem/File.h" -#include "Nuake/Audio/AudioManager.h" - -#include - -namespace Nuake -{ - AudioSystem::AudioSystem(Scene* scene) - { - m_Scene = scene; - } - - bool AudioSystem::Init() - { - AudioManager::Get().StopAll(); - - return true; - } - - void AudioSystem::Update(Timestep ts) - { - auto& audioManager = AudioManager::Get(); - - // Update 3D listener of the audio system - auto currentCamera = m_Scene->GetCurrentCamera(); - - Vector3 direction = currentCamera->GetDirection(); - Vector3 position = currentCamera->GetTranslation(); - if (!Engine::IsPlayMode()) - { - direction.x *= -1.0f; - direction.z *= -1.0f; - } - - audioManager.SetListenerPosition(position, std::move(direction), currentCamera->GetUp()); - - auto view = m_Scene->m_Registry.view(); - for (auto& e : view) - { - auto [transformComponent, audioEmitterComponent] = view.get(e); - - if (audioEmitterComponent.FilePath.file == nullptr || !audioEmitterComponent.FilePath.file->Exist()) - { - // Doesn't have a file - continue; - } - - const bool isPlaying = audioEmitterComponent.IsPlaying; - const std::string absoluteFilePath = audioEmitterComponent.FilePath.file->GetAbsolutePath(); - const bool isVoiceActive = audioManager.IsVoiceActive(absoluteFilePath); - - AudioRequest audioRequest; - audioRequest.audioFile = absoluteFilePath; - audioRequest.pan = audioEmitterComponent.Pan; - audioRequest.volume = audioEmitterComponent.Volume; - audioRequest.speed = audioEmitterComponent.PlaybackSpeed; - audioRequest.spatialized = audioEmitterComponent.Spatialized; - audioRequest.Loop = audioEmitterComponent.Loop; - audioRequest.position = transformComponent.GetGlobalTransform()[3]; - audioRequest.MinDistance = audioEmitterComponent.MinDistance; - audioRequest.MaxDistance = audioEmitterComponent.MaxDistance; - audioRequest.AttenuationFactor = audioEmitterComponent.AttenuationFactor; - - if (isVoiceActive) - { - if (!isPlaying && audioEmitterComponent.Loop) - { - audioManager.StopVoice(absoluteFilePath); // Stop audio - } - else - { - // Update the active voice with new params - audioManager.UpdateVoice(audioRequest); - } - } - - if (isPlaying) - { - // Reset the play status to false since the audio has been fired - if (!audioEmitterComponent.Loop) - { - audioManager.QueueWavAudio(std::move(audioRequest)); - audioEmitterComponent.IsPlaying = false; - } - else if (!isVoiceActive) - { - audioManager.QueueWavAudio(std::move(audioRequest)); - } - } - } - } - - void AudioSystem::FixedUpdate(Timestep ts) - { - - } - - void AudioSystem::EditorUpdate() - { - - } - - void AudioSystem::Exit() - { - AudioManager::Get().StopAll(); - } -} diff --git a/Nuake/Source/Nuake/Scene/Systems/AudioSystem.h b/Nuake/Source/Nuake/Scene/Systems/AudioSystem.h deleted file mode 100644 index b5c9393e..00000000 --- a/Nuake/Source/Nuake/Scene/Systems/AudioSystem.h +++ /dev/null @@ -1,20 +0,0 @@ -#pragma once -#include "Nuake/Scene/Systems/System.h" - -namespace Nuake -{ - class AudioSystem : public System - { - private: - std::unordered_map m_StatusCache; - - public: - AudioSystem(Scene* scene); - bool Init() override; - void Update(Timestep ts) override; - void Draw() override {} - void EditorUpdate() override; - void FixedUpdate(Timestep ts) override; - void Exit() override; - }; -}