Added a announcer volume channel.
This commit is contained in:
@@ -0,0 +1,17 @@
|
||||
#ifndef Events_PlayAnnouncerVoice_h__
|
||||
#define Events_PlayAnnouncerVoice_h__
|
||||
|
||||
#include <string>
|
||||
#include "../Engine/Core/EventBroker.h"
|
||||
|
||||
namespace Events
|
||||
{
|
||||
|
||||
struct PlayAnonuncerVoice : public Event
|
||||
{
|
||||
std::string FilePath = "";
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,16 @@
|
||||
#ifndef Events_SetAnnouncerGain_h__
|
||||
#define Events_SetAnnouncerGain_h__
|
||||
|
||||
#include "../Engine/Core/EventBroker.h"
|
||||
|
||||
namespace Events
|
||||
{
|
||||
|
||||
struct SetAnnouncerGain : public Event
|
||||
{
|
||||
float Gain = 1;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif //
|
||||
@@ -19,11 +19,13 @@
|
||||
#include "../Engine/Sound/EPlaySoundOnEntity.h"
|
||||
#include "../Engine/Sound/EPlaySoundOnPosition.h"
|
||||
#include "../Engine/Sound/EPlayBackgroundMusic.h"
|
||||
#include "../Engine/Sound/EPlayAnnouncerVoice.h"
|
||||
#include "../Engine/Sound/EPauseSound.h"
|
||||
#include "../Engine/Sound/EContinueSound.h"
|
||||
#include "../Engine/Sound/EStopSound.h"
|
||||
#include "../Engine/Sound/ESetBGMGain.h"
|
||||
#include "../Engine/Sound/ESetSFXGain.h"
|
||||
#include "../Engine/Sound/ESetAnnouncerGain.h"
|
||||
#include "../Engine/Sound/EChangeBGM.h"
|
||||
#include "../Engine/Core/EPause.h"
|
||||
#include "../Engine/Core/EComponentAttached.h"
|
||||
@@ -34,7 +36,8 @@ typedef std::pair<ALuint, std::vector<ALuint>> QueuedBuffers;
|
||||
|
||||
enum class SoundType {
|
||||
SFX,
|
||||
BGM
|
||||
BGM,
|
||||
Announcer
|
||||
};
|
||||
|
||||
struct Source
|
||||
@@ -98,6 +101,7 @@ private:
|
||||
|
||||
float m_BGMVolumeChannel = 1.0f;
|
||||
float m_SFXVolumeChannel = 1.0f;
|
||||
float m_AnnouncerVolumeChannel = 1.0f;
|
||||
EntityWrapper m_LocalPlayer = EntityWrapper();
|
||||
|
||||
// Events
|
||||
@@ -107,6 +111,8 @@ private:
|
||||
bool OnPlaySoundOnPosition(const Events::PlaySoundOnPosition &e);
|
||||
EventRelay<SoundManager, Events::PlayBackgroundMusic> m_EPlayBackgroundMusic;
|
||||
bool OnPlayBackgroundMusic(const Events::PlayBackgroundMusic &e);
|
||||
EventRelay<SoundManager, Events::PlayAnonuncerVoice> m_EPlayAnnouncerVoice;
|
||||
bool OnPlayAnnouncerVoice(const Events::PlayAnonuncerVoice& e);
|
||||
EventRelay<SoundManager, Events::PauseSound> m_EPauseSound;
|
||||
bool OnPauseSound(const Events::PauseSound &e);
|
||||
EventRelay<SoundManager, Events::StopSound> m_EStopSound;
|
||||
@@ -117,6 +123,8 @@ private:
|
||||
bool OnSetBGMGain(const Events::SetBGMGain &e);
|
||||
EventRelay<SoundManager, Events::SetSFXGain> m_ESetSFXGain;
|
||||
bool OnSetSFXGain(const Events::SetSFXGain &e);
|
||||
EventRelay<SoundManager, Events::SetAnnouncerGain> m_ESetAnnouncerGain;
|
||||
bool OnSetAnnouncerGain(const Events::SetAnnouncerGain& e);
|
||||
EventRelay<SoundManager, Events::ComponentAttached> m_EComponentAttached;
|
||||
bool OnComponentAttached(const Events::ComponentAttached &e);
|
||||
EventRelay<SoundManager, Events::Pause> m_EPause;
|
||||
|
||||
@@ -20,6 +20,7 @@
|
||||
#include "../Engine/Collision/ETrigger.h"
|
||||
#include "../Engine/Sound/EPlaySoundOnEntity.h"
|
||||
#include "../Engine/Sound/EPlayBackgroundMusic.h"
|
||||
#include "../Engine/Sound/EPlayAnnouncerVoice.h"
|
||||
#include "../Game/Events/EDoubleJump.h"
|
||||
#include "../Game/Events/EDashAbility.h"
|
||||
|
||||
|
||||
@@ -36,4 +36,5 @@ ResourceLoading=true
|
||||
[Sound]
|
||||
BGMVolume=1.0
|
||||
SFXVolume=1.0
|
||||
AnnouncerVolume=1.0
|
||||
Announcer=female
|
||||
@@ -7,6 +7,7 @@ SoundManager::SoundManager(World* world, EventBroker* eventBroker)
|
||||
m_World = world;
|
||||
m_BGMVolumeChannel = config->Get<float>("Sound.BGMVolume", 1.f);
|
||||
m_SFXVolumeChannel = config->Get<float>("Sound.SFXVolume", 1.f);
|
||||
m_AnnouncerVolumeChannel = config->Get<float>("Sound.AnnouncerVolume", 1.f);
|
||||
|
||||
initOpenAL();
|
||||
alSpeedOfSound(340.29f);
|
||||
@@ -19,16 +20,19 @@ SoundManager::SoundManager(World* world, EventBroker* eventBroker)
|
||||
EVENT_SUBSCRIBE_MEMBER(m_EPlaySoundOnEntity, &SoundManager::OnPlaySoundOnEntity);
|
||||
EVENT_SUBSCRIBE_MEMBER(m_EPlaySoundOnPosition, &SoundManager::OnPlaySoundOnPosition);
|
||||
EVENT_SUBSCRIBE_MEMBER(m_EPlayBackgroundMusic, &SoundManager::OnPlayBackgroundMusic);
|
||||
EVENT_SUBSCRIBE_MEMBER(m_EPlayAnnouncerVoice, &SoundManager::OnPlayAnnouncerVoice);
|
||||
EVENT_SUBSCRIBE_MEMBER(m_EStopSound, &SoundManager::OnStopSound);
|
||||
EVENT_SUBSCRIBE_MEMBER(m_EPauseSound, &SoundManager::OnPauseSound);
|
||||
EVENT_SUBSCRIBE_MEMBER(m_EContinueSound, &SoundManager::OnContinueSound);
|
||||
EVENT_SUBSCRIBE_MEMBER(m_ESetBGMGain, &SoundManager::OnSetBGMGain);
|
||||
EVENT_SUBSCRIBE_MEMBER(m_ESetSFXGain, &SoundManager::OnSetSFXGain);
|
||||
EVENT_SUBSCRIBE_MEMBER(m_ESetAnnouncerGain, &SoundManager::OnSetAnnouncerGain);
|
||||
EVENT_SUBSCRIBE_MEMBER(m_EPause, &SoundManager::OnPause);
|
||||
EVENT_SUBSCRIBE_MEMBER(m_EResume, &SoundManager::OnResume);
|
||||
EVENT_SUBSCRIBE_MEMBER(m_EComponentAttached, &SoundManager::OnComponentAttached);
|
||||
EVENT_SUBSCRIBE_MEMBER(m_EPlayerSpawned, &SoundManager::OnPlayerSpawned);
|
||||
EVENT_SUBSCRIBE_MEMBER(m_EPlayQueueOnEntity, &SoundManager::OnPlayQueueOnEntity);
|
||||
EVENT_SUBSCRIBE_MEMBER(m_EChangeBGM, &SoundManager::OnChangeBGM);
|
||||
}
|
||||
|
||||
SoundManager::~SoundManager()
|
||||
@@ -272,6 +276,28 @@ bool SoundManager::OnPlayBackgroundMusic(const Events::PlayBackgroundMusic & e)
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool SoundManager::OnPlayAnnouncerVoice(const Events::PlayAnonuncerVoice& e)
|
||||
{
|
||||
auto listenerComponents = m_World->GetComponents("Listener");
|
||||
for (auto it = listenerComponents->begin(); it != listenerComponents->end(); it++) {
|
||||
if ((*it).EntityID != m_LocalPlayer.ID) {
|
||||
break;
|
||||
}
|
||||
auto emitterChild = m_World->CreateEntity((*it).EntityID);
|
||||
auto emitter = m_World->AttachComponent(emitterChild, "SoundEmitter");
|
||||
(bool&)emitter["Loop"] = false;
|
||||
(std::string&)emitter["FilePath"] = e.FilePath;
|
||||
m_World->AttachComponent(emitterChild, "Transform");
|
||||
Source* source = createSource(e.FilePath);
|
||||
source->Type = SoundType::Announcer;
|
||||
setSoundProperties(source, &emitter);
|
||||
m_Sources[emitterChild] = source;
|
||||
playSound(source);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool SoundManager::OnSetBGMGain(const Events::SetBGMGain & e)
|
||||
{
|
||||
m_BGMVolumeChannel = e.Gain;
|
||||
@@ -284,6 +310,13 @@ bool SoundManager::OnSetSFXGain(const Events::SetSFXGain & e)
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool SoundManager::OnSetAnnouncerGain(const Events::SetAnnouncerGain& e)
|
||||
{
|
||||
m_AnnouncerVolumeChannel = e.Gain;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool SoundManager::OnComponentAttached(const Events::ComponentAttached & e)
|
||||
{
|
||||
if (e.Component.Info.Name == "SoundEmitter") {
|
||||
@@ -361,7 +394,13 @@ void SoundManager::setGain(Source * source, float gain)
|
||||
|
||||
void SoundManager::setSoundProperties(Source* source, ComponentWrapper* soundComponent)
|
||||
{
|
||||
float gain = (source->Type == SoundType::SFX) ? m_SFXVolumeChannel : m_BGMVolumeChannel;
|
||||
float gain;
|
||||
switch (source->Type) {
|
||||
case SoundType::SFX: gain = m_SFXVolumeChannel; break;
|
||||
case SoundType::BGM: gain = m_BGMVolumeChannel; break;
|
||||
case SoundType::Announcer: gain = m_AnnouncerVolumeChannel; break;
|
||||
default: gain = 1.f; break;
|
||||
}
|
||||
alSourcef(source->ALsource, AL_GAIN, (float)(double)(*soundComponent)["Gain"] * gain);
|
||||
alSourcef(source->ALsource, AL_PITCH, (float)(double)(*soundComponent)["Pitch"]);
|
||||
alSourcei(source->ALsource, AL_LOOPING, (int)(bool)(*soundComponent)["Loop"]);
|
||||
|
||||
@@ -36,8 +36,7 @@ bool SoundSystem::OnPlayerSpawned(const Events::PlayerSpawned &e)
|
||||
{
|
||||
if (e.PlayerID == -1) { // Local player
|
||||
m_World->AttachComponent(e.Player.ID, "Listener");
|
||||
Events::PlaySoundOnEntity go;
|
||||
go.EmitterID = LocalPlayer.ID;
|
||||
Events::PlayAnonuncerVoice go;
|
||||
go.FilePath = "Audio/announcer/" + m_Announcer + "/go.wav";
|
||||
m_EventBroker->Publish(go);
|
||||
// TEMP: starts bgm
|
||||
@@ -92,13 +91,12 @@ bool SoundSystem::OnCaptured(const Events::Captured & e)
|
||||
{
|
||||
int homeTeam = (int)m_World->GetComponent(e.CapturePointID, "Team")["Team"];
|
||||
int team = (int)m_World->GetComponent(LocalPlayer.ID, "Team")["Team"];
|
||||
Events::PlaySoundOnEntity ev;
|
||||
Events::PlayAnonuncerVoice ev;
|
||||
if (team == homeTeam) {
|
||||
ev.FilePath = "Audio/announcer/" + m_Announcer + "/objective_achieved.wav";
|
||||
} else {
|
||||
ev.FilePath = "Audio/announcer/" + m_Announcer + "/objective_failed.wav"; // have not been tested
|
||||
}
|
||||
ev.EmitterID = LocalPlayer.ID;
|
||||
m_EventBroker->Publish(ev);
|
||||
// Temp for play test.
|
||||
m_DrumsIsPlaying = false;
|
||||
|
||||
Reference in New Issue
Block a user