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/Core/Engine.h b/include/Core/Engine.h index 35eafa8..492fa30 100755 --- a/include/Core/Engine.h +++ b/include/Core/Engine.h @@ -229,6 +229,8 @@ public: //ResourceManager::Update(); if (m_GameIsRunning) { m_World->Update(dt); + } else { + m_EventBroker->Process(); } m_EventBroker->Process(); m_FrameStack->UpdateLayered(dt); @@ -428,17 +430,17 @@ private: m_GameIsRunning = true; //Todo: Move this { - dd::Events::PlaySound e; - e.FilePath = "Sounds/BGM/under-the-sea-instrumental.wav"; - e.IsAmbient = true; - m_EventBroker->Publish(e); +// dd::Events::PlaySound e; +// e.FilePath = "Sounds/BGM/under-the-sea-instrumental.wav"; +// e.IsAmbient = true; +// m_EventBroker->Publish(e); } { - dd::Events::PlaySound e; - e.FilePath = "Sounds/BGM/water-flowing.wav"; - e.Gain = 0.3f; - e.IsAmbient = true; - m_EventBroker->Publish(e); +// dd::Events::PlaySound e; +// e.FilePath = "Sounds/BGM/water-flowing.wav"; +// e.Gain = 0.3f; +// e.IsAmbient = true; +// m_EventBroker->Publish(e); } return true; diff --git a/include/GUI/Button.h b/include/GUI/Button.h index dcfdae6..e25f8c0 100644 --- a/include/GUI/Button.h +++ b/include/GUI/Button.h @@ -75,6 +75,10 @@ protected: Events::ButtonEnter e; e.FrameName = m_Name; EventBroker->Publish(e); + Events::PlaySound soundEvent; + soundEvent.FilePath = "Sounds/GUI/hover.wav"; + EventBroker->Publish(soundEvent); + } else if (!isOver && m_MouseIsOver) { // Leave if (!m_IsDown) { if (!m_TextureReleased.empty()) { diff --git a/include/GUI/Slider.h b/include/GUI/Slider.h index de53245..a4987a6 100644 --- a/include/GUI/Slider.h +++ b/include/GUI/Slider.h @@ -7,6 +7,7 @@ #include "GUI/EButtonRelease.h" #include "GUI/ESliderUpdate.h" #include "Core/EMouseMove.h" +#include "Sound/EPlaySound.h" namespace dd { @@ -79,6 +80,11 @@ private: if (event.Button == m_SliderButton) { m_IsGrabbed = true; } + else { + Events::PlaySound e; + e.FilePath = "Sounds/GUI/click.wav"; + EventBroker->Publish(e); + } return true; } diff --git a/include/GUI/TextureFrame.h b/include/GUI/TextureFrame.h index 5db574c..1bc340d 100644 --- a/include/GUI/TextureFrame.h +++ b/include/GUI/TextureFrame.h @@ -62,6 +62,7 @@ public: if (m_Texture == nullptr) { m_Texture = ResourceManager::Load("Textures/Core/ErrorTexture.png"); } + SizeToTexture(); } diff --git a/include/Game/EGameStart.h b/include/Game/EGameStart.h index bfee0fd..faf89a2 100644 --- a/include/Game/EGameStart.h +++ b/include/Game/EGameStart.h @@ -1,7 +1,3 @@ -// -// Created by Adam on 2015-09-25. -// - #ifndef EVENTS_EGAMESTART_H__ #define EVENTS_EGAMESTART_H__ 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 950a020..5349258 100644 --- a/include/Sound/SoundSystem.h +++ b/include/Sound/SoundSystem.h @@ -10,15 +10,17 @@ #include "Core/ResourceManager.h" #include "Core/ConfigFile.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" +#include "Game/EGameStart.h" + namespace dd { @@ -41,6 +43,7 @@ private: std::map m_BGMSourcesToBuffers; std::map m_SFXSourcesToBuffers; ALCdevice* m_Device = nullptr; + ALCcontext* m_Context = nullptr; //Events dd::EventRelay m_EPlaySFX; @@ -52,6 +55,9 @@ private: bool OnStopSound(const dd::Events::StopSound &event); dd::EventRelay m_EMasterVolume; bool OnMasterVolume(const dd::Events::MasterVolume &event); + dd::EventRelay m_EGameStart; + bool OnGameStart(const dd::Events::GameStart &event); + ALuint CreateSource(); }; 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 b96f327..7580b99 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,42 +23,26 @@ 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); EVENT_SUBSCRIBE_MEMBER(m_EPlaySFX, &SoundSystem::OnPlaySound); EVENT_SUBSCRIBE_MEMBER(m_EStopSound, &SoundSystem::OnStopSound); EVENT_SUBSCRIBE_MEMBER(m_EMasterVolume, &SoundSystem::OnMasterVolume); + EVENT_SUBSCRIBE_MEMBER(m_EGameStart, &SoundSystem::OnGameStart); m_SFXMasterVolume = ResourceManager::Load("Config.ini")->GetValue("Audio.SFXVolume", 1.f); m_BGMMasterVolume = ResourceManager::Load("Config.ini")->GetValue("Audio.BGMVolume", 1.f); - - //Todo: Move this - { - dd::Events::PlaySound e; - e.FilePath = "Sounds/BGM/under-the-sea-instrumental.wav"; - e.IsAmbient = true; - EventBroker->Publish(e); - } - { - dd::Events::PlaySound e; - e.FilePath = "Sounds/BGM/water-flowing.wav"; - e.Gain = 0.3f; - e.IsAmbient = true; - EventBroker->Publish(e); - } - - } void dd::Systems::SoundSystem::Update(double dt) @@ -63,7 +60,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]); } } @@ -175,11 +171,30 @@ bool dd::Systems::SoundSystem::OnContact(const dd::Events::Contact &event) dd::Events::PlaySound e; e.FilePath = collisionSound->FilePath; e.IsAmbient = false; + e.Gain = 0.8f; EventBroker->Publish(e); } return true; } +bool dd::Systems::SoundSystem::OnGameStart(const dd::Events::GameStart &event) +{ + { + dd::Events::PlaySound e; + e.FilePath = "Sounds/BGM/under-the-sea-instrumental.wav"; + e.IsAmbient = true; + EventBroker->Publish(e); + } + { + dd::Events::PlaySound e; + e.FilePath = "Sounds/BGM/water-flowing.wav"; + e.Gain = 0.3f; + e.IsAmbient = true; + EventBroker->Publish(e); + } + return true; +} +