Merge pull request #214 from teamfisk/PerfectSoundForRelease

Perfect sound for release
This commit is contained in:
William Moberg
2016-03-13 21:01:21 +01:00
3 changed files with 41 additions and 27 deletions
+3 -1
View File
@@ -30,6 +30,7 @@
#include "../Engine/Core/EPause.h" #include "../Engine/Core/EPause.h"
#include "../Engine/Core/EComponentAttached.h" #include "../Engine/Core/EComponentAttached.h"
#include "../Core/EPlayerSpawned.h" #include "../Core/EPlayerSpawned.h"
#include "../Rendering/ESetCamera.h"
typedef std::pair<ALuint, std::vector<ALuint>> QueuedBuffers; typedef std::pair<ALuint, std::vector<ALuint>> QueuedBuffers;
@@ -91,7 +92,6 @@ private:
void matchBGMLoop(); void matchBGMLoop();
Source* m_CurrentBGM = nullptr; Source* m_CurrentBGM = nullptr;
Source* m_CurrentBGMCombo = nullptr; Source* m_CurrentBGMCombo = nullptr;
bool m_DrumLoopHasBeenStarted = false;
// Logic // Logic
World* m_World = nullptr; World* m_World = nullptr;
@@ -139,6 +139,8 @@ private:
bool OnPlayQueueOnEntity(const Events::PlayQueueOnEntity &e); bool OnPlayQueueOnEntity(const Events::PlayQueueOnEntity &e);
EventRelay<SoundManager, Events::ChangeBGM> m_EChangeBGM; EventRelay<SoundManager, Events::ChangeBGM> m_EChangeBGM;
bool OnChangeBGM(const Events::ChangeBGM &e); bool OnChangeBGM(const Events::ChangeBGM &e);
EventRelay<SoundManager, Events::SetCamera> m_ESetCamera;
bool OnSetCamera(const Events::SetCamera& e);
}; };
+33 -16
View File
@@ -30,10 +30,7 @@ SoundManager::SoundManager(World* world, EventBroker* eventBroker)
EVENT_SUBSCRIBE_MEMBER(m_EPlayerSpawned, &SoundManager::OnPlayerSpawned); EVENT_SUBSCRIBE_MEMBER(m_EPlayerSpawned, &SoundManager::OnPlayerSpawned);
EVENT_SUBSCRIBE_MEMBER(m_EPlayQueueOnEntity, &SoundManager::OnPlayQueueOnEntity); EVENT_SUBSCRIBE_MEMBER(m_EPlayQueueOnEntity, &SoundManager::OnPlayQueueOnEntity);
EVENT_SUBSCRIBE_MEMBER(m_EChangeBGM, &SoundManager::OnChangeBGM); EVENT_SUBSCRIBE_MEMBER(m_EChangeBGM, &SoundManager::OnChangeBGM);
EVENT_SUBSCRIBE_MEMBER(m_ESetCamera, &SoundManager::OnSetCamera);
Events::ChangeBGM e;
e.FilePath = "Audio/bgm/MenuMusic.wav";
m_EventBroker->Publish(e);
} }
SoundManager::~SoundManager() SoundManager::~SoundManager()
@@ -67,8 +64,7 @@ void SoundManager::Update(double dt)
deleteInactiveEmitters(); deleteInactiveEmitters();
updateEmitters(dt); updateEmitters(dt);
updateListener(dt); updateListener(dt);
if (m_DrumLoopHasBeenStarted) matchBGMLoop();
matchBGMLoop();
} }
void SoundManager::deleteInactiveEmitters() void SoundManager::deleteInactiveEmitters()
@@ -363,15 +359,6 @@ bool SoundManager::OnPlayerSpawned(const Events::PlayerSpawned &e)
{ {
if (e.PlayerID == -1) { // Local player if (e.PlayerID == -1) { // Local player
m_LocalPlayer = e.Player; m_LocalPlayer = e.Player;
if (m_DrumLoopHasBeenStarted) {
return true;
}
m_CurrentBGMCombo = createSource("Audio/BGM/Layer2.wav");
m_CurrentBGMCombo->Type = SoundType::BGM;
alSourcei(m_CurrentBGMCombo->ALsource, AL_LOOPING, 1);
setGain(m_CurrentBGMCombo, 0);
playSound(m_CurrentBGMCombo);
m_DrumLoopHasBeenStarted = true;
return true; return true;
} }
return false; return false;
@@ -394,7 +381,9 @@ bool SoundManager::OnPlayQueueOnEntity(const Events::PlayQueueOnEntity &e)
bool SoundManager::OnChangeBGM(const Events::ChangeBGM &e) bool SoundManager::OnChangeBGM(const Events::ChangeBGM &e)
{ {
if (m_CurrentBGM != nullptr) { if (m_CurrentBGM != nullptr) {
stopSound(m_CurrentBGM); if (getSourceState(m_CurrentBGM->ALsource) == AL_PLAYING) {
stopSound(m_CurrentBGM);
}
} }
m_CurrentBGM = createSource(e.FilePath); m_CurrentBGM = createSource(e.FilePath);
m_CurrentBGM->Type = SoundType::BGM; m_CurrentBGM->Type = SoundType::BGM;
@@ -403,6 +392,34 @@ bool SoundManager::OnChangeBGM(const Events::ChangeBGM &e)
return true; return true;
} }
bool SoundManager::OnSetCamera(const Events::SetCamera& e)
{
if (e.CameraEntity.Name() == "Overview_Camera_Start_Menu") {
if (m_CurrentBGMCombo != nullptr) {
if (getSourceState(m_CurrentBGMCombo->ALsource) == AL_PLAYING) {
stopSound(m_CurrentBGMCombo);
}
}
Events::ChangeBGM changeBGM;
changeBGM.FilePath = "Audio/BGM/MenuMusic.wav";
m_EventBroker->Publish(changeBGM);
} else if (e.CameraEntity.Name() == "PickTeamCamera") {
Events::ChangeBGM changeBGM;
changeBGM.FilePath = "Audio/BGM/Layer1.wav";
m_EventBroker->Publish(changeBGM);
if (m_CurrentBGMCombo != nullptr) {
if (getSourceState(m_CurrentBGMCombo->ALsource) == AL_PLAYING) {
stopSound(m_CurrentBGMCombo);
}
}
m_CurrentBGMCombo = createSource("Audio/BGM/Layer2.wav");
m_CurrentBGMCombo->Type = SoundType::BGM;
alSourcei(m_CurrentBGMCombo->ALsource, AL_LOOPING, 1);
setGain(m_CurrentBGMCombo, 0);
playSound(m_CurrentBGMCombo);
}
}
ALenum SoundManager::getSourceState(ALuint source) ALenum SoundManager::getSourceState(ALuint source)
{ {
ALenum state; ALenum state;
-5
View File
@@ -30,11 +30,6 @@ bool SoundSystem::OnPlayerSpawned(const Events::PlayerSpawned &e)
Events::PlayAnonuncerVoice go; Events::PlayAnonuncerVoice go;
go.FilePath = "Audio/Announcer/" + m_Announcer + "/Go.wav"; go.FilePath = "Audio/Announcer/" + m_Announcer + "/Go.wav";
m_EventBroker->Publish(go); m_EventBroker->Publish(go);
{
Events::ChangeBGM ev;
ev.FilePath = "Audio/BGM/Layer1.wav";
m_EventBroker->Publish(ev);
}
} }
return true; return true;
} }