Added hover and click sounds. Cleanup in SoundSystem.
This commit is contained in:
Binary file not shown.
Binary file not shown.
@@ -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; };
|
||||
|
||||
@@ -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<ALuint, Sound*> m_BGMSourcesToBuffers;
|
||||
std::map<ALuint, Sound*> m_SFXSourcesToBuffers;
|
||||
ALCdevice* m_Device = nullptr;
|
||||
ALCcontext* m_Context = nullptr;
|
||||
|
||||
//Events
|
||||
dd::EventRelay<SoundSystem, dd::Events::PlaySound> m_EPlaySFX;
|
||||
|
||||
@@ -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()) {
|
||||
|
||||
@@ -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<Sound>(event.FilePath);
|
||||
Sound *sound = ResourceManager::Load<Sound>(event.FilePath);
|
||||
if (sound == nullptr) {
|
||||
return false;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user