Started work on audio manager

Implemented soloud
This commit is contained in:
Antoine Pilote
2023-04-02 22:35:40 -04:00
parent 0bf4c2cb18
commit 1532724a5d
11 changed files with 164 additions and 22 deletions

View File

@@ -1389,7 +1389,7 @@ namespace Nuake {
if (ImGui::MenuItem("Draw collisions", NULL, m_DebugCollisions))
{
m_DebugCollisions = !m_DebugCollisions;
PhysicsManager::Get()->SetDrawDebug(m_DebugCollisions);
PhysicsManager::Get().SetDrawDebug(m_DebugCollisions);
}
if (ImGui::MenuItem("Settings", NULL)) {}

View File

@@ -5,6 +5,7 @@
#include "src/Core/Input.h"
#include "src/Core/FileSystem.h"
#include "src/Scripting/ScriptingEngine.h"
#include "src/Audio/AudioManager.h"
#include "src/Rendering/Renderer.h"
#include "src/Rendering/Renderer2D.h"
@@ -29,7 +30,12 @@ namespace Nuake
{
Logger::Log("Nuake initializing");
PhysicsManager::Get()->Init();
AudioManager::Get().Initialize();
Logger::Log("Audio engine initialized");
AudioManager::Get().PlayTTS("Nuake Engine debug");
PhysicsManager::Get().Init();
Logger::Log("Physics initialized");
// Creates the window

View File

@@ -0,0 +1,39 @@
project 'Soloud'
location "soloud"
kind "StaticLib"
staticruntime "on"
warnings 'Off'
optimize 'Speed'
targetdir ("soloud/bin/" .. outputdir .. "/%{prj.name}")
objdir ("soloud/bin-obj/" .. outputdir .. "/%{prj.name}")
defines {
"WITH_WASAPI"
}
includedirs {
"soloud/include"
}
files {
"soloud/src/**.h",
"soloud/src/core/**.cpp",
"soloud/src/audiosource/**.c*",
"soloud/src/backend/wasapi/**.c*"
}
prebuildcommands {
}
filter "configurations:Debug"
cppdialect "C++17"
runtime "Debug"
symbols "on"
filter "configurations:Release"
cppdialect "C++17"
runtime "Release"
optimize "on"

View File

@@ -0,0 +1,44 @@
#include "AudioManager.h"
#include <soloud.h>
#include "soloud_speech.h"
#include "soloud_thread.h"
namespace Nuake
{
void AudioManager::Initialize()
{
_soloud = CreateRef<SoLoud::Soloud>();
_soloud->init();
_audioThreadRunning = true;
_audioThread = std::thread(&AudioManager::AudioThreadLoop, this);
}
void AudioManager::Deinitialize()
{
_soloud->deinit();
}
void AudioManager::PlayTTS(const std::string& text)
{
SoLoud::Speech speech;
speech.setText(text.c_str());
_soloud->play(speech);
// Wait until sounds have finished
while (_soloud->getActiveVoiceCount() > 0)
{
// Still going, sleep for a bit
SoLoud::Thread::sleep(100);
}
}
void AudioManager::AudioThreadLoop()
{
while(_audioThreadRunning)
{
}
}
}

View File

@@ -0,0 +1,46 @@
#pragma once
#include "src/Core/Core.h"
#include <mutex>
#include <thread>
namespace SoLoud
{
class Soloud;
}
namespace Nuake
{
// This is a singleton that manages everything for audio.
class AudioManager
{
private:
Ref<SoLoud::Soloud> _soloud;
bool _audioThreadRunning;
std::thread _audioThread;
std::mutex _audioMutex;
public:
AudioManager() = default;
~AudioManager() = default;
static AudioManager& Get()
{
static AudioManager instance;
return instance;
}
void Initialize();
void Deinitialize();
// Volume
float GetVolume() const;
void SetVolume(float volume);
void PlayTTS(const std::string& text);
private:
void AudioThreadLoop();
};
}

View File

@@ -17,11 +17,10 @@ namespace Nuake
bool m_DrawDebug = false;
static PhysicsManager* m_Instance;
public:
static PhysicsManager* Get()
static PhysicsManager& Get()
{
if (!m_Instance)
m_Instance = new PhysicsManager();
return m_Instance;
static PhysicsManager instance;
return instance;
}
Physics::DynamicWorld* GetWorld() { return m_World; }

View File

@@ -70,13 +70,13 @@ namespace Nuake
i >> j;
// validation
std::string projectName = "";
std::string projectName;
if (!j.contains("ProjectName"))
return nullptr;
projectName = j["ProjectName"];
std::string description = "";
std::string description;
if (j.contains("Description"))
description = j["Description"];

View File

@@ -166,13 +166,15 @@ namespace Nuake {
{
std::vector<Entity> allEntities;
auto view = m_Registry.view<NameComponent>();
for (auto e : view)
for (auto& e : view)
{
Entity newEntity(e, this);
// Check if valid for deleted entities.
if (newEntity.IsValid())
{
allEntities.push_back(newEntity);
}
}
return allEntities;
}

View File

@@ -37,7 +37,7 @@ namespace Nuake
Ref<Physics::Box> boxShape = CreateRef<Physics::Box>(boxComponent.Size);
rigidBody = CreateRef<Physics::RigidBody>(rigidBodyComponent.Mass, transform.GetGlobalPosition(), transform.GetGlobalTransform(), boxShape, ent);
PhysicsManager::Get()->RegisterBody(rigidBody);
PhysicsManager::Get().RegisterBody(rigidBody);
}
if (ent.HasComponent<CapsuleColliderComponent>())
@@ -48,7 +48,7 @@ namespace Nuake
auto capsuleShape = CreateRef<Physics::Capsule>(radius, height);
rigidBody = CreateRef<Physics::RigidBody>(rigidBodyComponent.Mass, transform.GetGlobalPosition(), transform.GetGlobalTransform(), capsuleShape, ent);
PhysicsManager::Get()->RegisterBody(rigidBody);
PhysicsManager::Get().RegisterBody(rigidBody);
}
if (ent.HasComponent<SphereColliderComponent>())
@@ -59,7 +59,7 @@ namespace Nuake
auto shape = CreateRef<Physics::Sphere>(component.Radius);
rigidBody = CreateRef<Physics::RigidBody>(rigidBodyComponent.Mass, transform.GetGlobalPosition(), transform.GetGlobalTransform(), shape, ent);
PhysicsManager::Get()->RegisterBody(rigidBody);
PhysicsManager::Get().RegisterBody(rigidBody);
}
if (ent.HasComponent<MeshColliderComponent>())
@@ -82,7 +82,7 @@ namespace Nuake
Ref<Mesh> mesh = submeshes[subMeshId];
auto shape = CreateRef<Physics::MeshShape>(mesh);
rigidBody = CreateRef<Physics::RigidBody>(rigidBodyComponent.Mass, transform.GetGlobalPosition(), transform.GetGlobalTransform(), shape, ent);
PhysicsManager::Get()->RegisterBody(rigidBody);
PhysicsManager::Get().RegisterBody(rigidBody);
}
}
}
@@ -123,7 +123,7 @@ namespace Nuake
btRigidbody->SetEntityID(Entity{ e, m_Scene });
brush.Rigidbody.push_back(btRigidbody);
PhysicsManager::Get()->RegisterBody(btRigidbody);
PhysicsManager::Get().RegisterBody(btRigidbody);
}
}
@@ -209,11 +209,11 @@ namespace Nuake
if (!Engine::IsPlayMode)
return;
PhysicsManager::Get()->Step(ts);
PhysicsManager::Get().Step(ts);
}
void PhysicsSystem::Exit()
{
PhysicsManager::Get()->Reset();
PhysicsManager::Get().Reset();
}
}

View File

@@ -33,7 +33,7 @@ namespace Nuake {
wrenGetSlotDouble(vm, 5),
wrenGetSlotDouble(vm, 6));
RaycastResult result = PhysicsManager::Get()->Raycast(v1, v2);
RaycastResult result = PhysicsManager::Get().Raycast(v1, v2);
wrenSetSlotNewList(vm, 0);
// Returns a list with 3 vectors placed sequentially

View File

@@ -13,6 +13,7 @@ include "Nuake/dependencies/glfw_p5.lua"
include "Nuake/dependencies/assimp_p5.lua"
include "Nuake/dependencies/freetype_p5.lua"
include "Nuake/dependencies/jolt_p5.lua"
include "Nuake/dependencies/soloud_p5.lua"
project "Nuake"
location "Nuake"
@@ -58,12 +59,14 @@ project "Nuake"
"%{prj.name}/../Nuake/src/Vendors/msdfgen/freetype/include",
"%{prj.name}/../Nuake/src/Vendors/msdfgen",
"%{prj.name}/../Nuake/src/Vendors/wren/src/include",
"%{prj.name}/../Nuake/Dependencies/build"
"%{prj.name}/../Nuake/Dependencies/build",
"%{prj.name}/../Nuake/Dependencies/soloud/include"
}
links
{
"Freetype"
"Freetype",
"soloud"
}
filter "system:windows"
@@ -103,7 +106,8 @@ project "Editor"
"%{prj.name}/../Nuake/Dependencies/build",
"%{prj.name}/../Nuake/src/Vendors/msdfgen",
"%{prj.name}/../Nuake/Dependencies/JoltPhysics",
"%{prj.name}/../Nuake/Dependencies/build"
"%{prj.name}/../Nuake/Dependencies/build",
"%{prj.name}/../Nuake/Dependencies/soloud/include"
}
libdirs
@@ -116,7 +120,8 @@ project "Editor"
"%{prj.name}/../Nuake/src/Vendors/msdfgen/freetype/win64",
"%{prj.name}/../Nuake/src/Vendors/msdfgen",
"%{prj.name}/../Nuake/src/Vendors/wren/src/include",
"%{prj.name}/../Nuake/dependencies/JoltPhysics/bin/%{cfg.buildcfg}-%{cfg.system}-%{cfg.architecture}/JoltPhysics/"
"%{prj.name}/../Nuake/dependencies/JoltPhysics/bin/%{cfg.buildcfg}-%{cfg.system}-%{cfg.architecture}/JoltPhysics/",
"%{prj.name}/../Nuake/dependencies/soloud/bin/%{cfg.buildcfg}-%{cfg.system}-%{cfg.architecture}"
}
links
@@ -127,7 +132,8 @@ project "Editor"
"glew32s.lib",
"opengl32.lib",
"Freetype",
"JoltPhysics"
"JoltPhysics",
"soloud"
}
filter "system:windows"