diff --git a/assets/Sounds/GUI/click.wav b/assets/Sounds/GUI/click.wav new file mode 100644 index 0000000..cda8f60 Binary files /dev/null and b/assets/Sounds/GUI/click.wav differ diff --git a/assets/Sounds/GUI/hover.wav b/assets/Sounds/GUI/hover.wav new file mode 100644 index 0000000..8d3baef Binary files /dev/null and b/assets/Sounds/GUI/hover.wav differ diff --git a/include/Sound/Sound.h b/include/Sound/Sound.h index 1e892b7..7271bc2 100644 --- a/include/Sound/Sound.h +++ b/include/Sound/Sound.h @@ -14,6 +14,7 @@ class Sound : public Resource friend class ResourceManager; public: + ~Sound(); ALuint Buffer() { return m_Buffer; }; std::string Path() { return m_Path; }; float Gain() { return m_Gain; }; diff --git a/include/Sound/SoundSystem.h b/include/Sound/SoundSystem.h index 8892577..a410927 100644 --- a/include/Sound/SoundSystem.h +++ b/include/Sound/SoundSystem.h @@ -9,15 +9,16 @@ #include "Core/EventBroker.h" #include "Core/ResourceManager.h" #include "Sound.h" -#include "Sound/EPlaySound.h" -#include "Sound/EStopSound.h" -#include "Sound/EMasterVolume.h" #include "Sound/CCollisionSound.h" -#include "Physics/EContact.h" #include "Game/CBall.h" #include "Game/CBrick.h" #include "Game/CPad.h" +#include "Sound/EPlaySound.h" +#include "Sound/EStopSound.h" +#include "Sound/EMasterVolume.h" #include "Physics/ECreateParticleSequence.h" +#include "Physics/EContact.h" + namespace dd { @@ -40,6 +41,7 @@ private: std::map m_BGMSourcesToBuffers; std::map m_SFXSourcesToBuffers; ALCdevice* m_Device = nullptr; + ALCcontext* m_Context = nullptr; //Events dd::EventRelay m_EPlaySFX; diff --git a/src/game/Sound/Sound.cpp b/src/game/Sound/Sound.cpp index f98f8eb..0fb9da2 100644 --- a/src/game/Sound/Sound.cpp +++ b/src/game/Sound/Sound.cpp @@ -6,6 +6,11 @@ dd::Sound::Sound(std::string path) m_Path = path; } +dd::Sound::~Sound() +{ + alDeleteBuffers(1, &m_Buffer); +} + ALuint dd::Sound::LoadFile(std::string path) { if (m_BufferCache.find(path) != m_BufferCache.end()) { diff --git a/src/game/Sound/SoundSystem.cpp b/src/game/Sound/SoundSystem.cpp index c11d84e..65465e3 100644 --- a/src/game/Sound/SoundSystem.cpp +++ b/src/game/Sound/SoundSystem.cpp @@ -3,6 +3,19 @@ dd::Systems::SoundSystem::~SoundSystem() { + for (auto &bgm : m_BGMSourcesToBuffers) { + alSourceStop(bgm.first); + alDeleteSources(1, &bgm.first); + bgm.second->~Sound(); + } + for (auto &sfx : m_SFXSourcesToBuffers) { + alSourceStop(sfx.first); + alDeleteSources(1, &sfx.first); + sfx.second->~Sound(); + } + m_BGMSourcesToBuffers.clear(); + m_SFXSourcesToBuffers.clear(); + alcDestroyContext(m_Context); alcCloseDevice(m_Device); } @@ -10,16 +23,16 @@ void dd::Systems::SoundSystem::Initialize() { //initialize OpenAL m_Device = alcOpenDevice(NULL); - ALCcontext* context; + if (m_Device) { - context = alcCreateContext(m_Device, NULL); - alcMakeContextCurrent(context); + m_Context = alcCreateContext(m_Device, NULL); + alcMakeContextCurrent(m_Context); } else { LOG_ERROR("OpenAL failed to initialize."); } - alGetError(); + //alGetError(); //Subscribe to events EVENT_SUBSCRIBE_MEMBER(m_EContact, &SoundSystem::OnContact); @@ -60,7 +73,6 @@ void dd::Systems::SoundSystem::Update(double dt) for (int i = 0; i < deleteList.size(); i++) { alDeleteSources(1, &deleteList[i]); - //alDeleteBuffers(1, &m_SourcesToBuffers[deleteList[i]]); m_SFXSourcesToBuffers.erase(deleteList[i]); } } @@ -76,7 +88,7 @@ ALuint dd::Systems::SoundSystem::CreateSource() bool dd::Systems::SoundSystem::OnPlaySound(const dd::Events::PlaySound &event) { //Loading and binding sound buffer to source - Sound *sound = ResourceManager::Load(event.FilePath); + Sound *sound = ResourceManager::Load(event.FilePath); if (sound == nullptr) { return false; }