mirror of
https://github.com/antopilo/Nuake.git
synced 2026-09-09 20:08:57 +03:00
Removed audio from core engine and moved to module only
This commit is contained in:
@@ -42,7 +42,6 @@
|
||||
#include "Nuake/Rendering/SceneRenderer.h"
|
||||
#include <Nuake/Rendering/Buffers/Framebuffer.h>
|
||||
#include "UIDemoWindow.h"
|
||||
#include <Nuake/Audio/AudioManager.h>
|
||||
|
||||
#include <Nuake/UI/ImUI.h>
|
||||
#include "Nuake/FileSystem/FileSystem.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())
|
||||
{
|
||||
|
||||
@@ -5,6 +5,8 @@
|
||||
#include "Nuake/Modules/ModuleDB.h"
|
||||
#include <Nuake/Core/Logger.h>
|
||||
|
||||
#include "Nuake/Audio/AudioManager.h"
|
||||
|
||||
void PlayAudio(int id, Nuake::Matrix4 volume)
|
||||
{
|
||||
|
||||
@@ -42,37 +44,13 @@ void AudioModule_Startup()
|
||||
module.BindFunction<PlayAudio>("PlayAudio", "id", "volume");
|
||||
module.BindFunction<StopAudio>("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<std::string_view> 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<Audio::AudioSystem>();
|
||||
|
||||
module.OnUpdate.AddStatic([](float ts) {
|
||||
AudioManager::Get().AudioUpdate();
|
||||
});
|
||||
}
|
||||
|
||||
void AudioModule_Shutdown()
|
||||
|
||||
@@ -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<AnimationSystem>(this));
|
||||
m_Systems.push_back(CreateRef<TransformSystem>(this));
|
||||
m_Systems.push_back(CreateRef<ParticleSystem>(this));
|
||||
//m_Systems.push_back(CreateRef<AudioSystem>(this));
|
||||
|
||||
m_SceneRenderer = CreateRef<SceneRenderer>();
|
||||
m_SceneRenderer->Init();
|
||||
|
||||
@@ -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 <future>
|
||||
|
||||
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<TransformComponent, AudioEmitterComponent>();
|
||||
for (auto& e : view)
|
||||
{
|
||||
auto [transformComponent, audioEmitterComponent] = view.get<TransformComponent, AudioEmitterComponent>(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();
|
||||
}
|
||||
}
|
||||
@@ -1,20 +0,0 @@
|
||||
#pragma once
|
||||
#include "Nuake/Scene/Systems/System.h"
|
||||
|
||||
namespace Nuake
|
||||
{
|
||||
class AudioSystem : public System
|
||||
{
|
||||
private:
|
||||
std::unordered_map<uint32_t, bool> 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;
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user