Added an event to change the background music.
This commit is contained in:
+1
-1
Submodule assets updated: 1e7adc749e...00329bcf3e
@@ -0,0 +1,16 @@
|
||||
#ifndef Events_ChangeBGM_h__
|
||||
#define Events_ChangeBGM_h__
|
||||
|
||||
#include <string>
|
||||
#include "../Engine/Core/EventBroker.h"
|
||||
|
||||
namespace Events
|
||||
{
|
||||
|
||||
struct ChangeBGM : Event
|
||||
{
|
||||
std::string FilePath = "";
|
||||
};
|
||||
|
||||
}
|
||||
#endif // Events_ChangeBGM_h__
|
||||
@@ -24,10 +24,12 @@
|
||||
#include "../Engine/Sound/EStopSound.h"
|
||||
#include "../Engine/Sound/ESetBGMGain.h"
|
||||
#include "../Engine/Sound/ESetSFXGain.h"
|
||||
#include "../Engine/Sound/EChangeBGM.h"
|
||||
#include "../Engine/Core/EPause.h"
|
||||
#include "../Engine/Core/EComponentAttached.h"
|
||||
#include "../Core/EPlayerSpawned.h"
|
||||
|
||||
|
||||
typedef std::pair<ALuint, std::vector<ALuint>> QueuedBuffers;
|
||||
|
||||
enum class SoundType {
|
||||
@@ -125,6 +127,8 @@ private:
|
||||
bool OnPlayerSpawned(const Events::PlayerSpawned &e);
|
||||
EventRelay<SoundManager, Events::PlayQueueOnEntity> m_EPlayQueueOnEntity;
|
||||
bool OnPlayQueueOnEntity(const Events::PlayQueueOnEntity &e);
|
||||
EventRelay<SoundManager, Events::ChangeBGM> m_EChangeBGM;
|
||||
bool OnChangeBGM(const Events::ChangeBGM &e);
|
||||
|
||||
|
||||
};
|
||||
|
||||
@@ -13,6 +13,9 @@ SoundManager::SoundManager(World* world, EventBroker* eventBroker)
|
||||
alDistanceModel(AL_LINEAR_DISTANCE);
|
||||
alDopplerFactor(1);
|
||||
|
||||
//m_CurrentBGM = createSource("Audio/lalala.wav");
|
||||
//playSound(m_CurrentBGM);
|
||||
|
||||
EVENT_SUBSCRIBE_MEMBER(m_EPlaySoundOnEntity, &SoundManager::OnPlaySoundOnEntity);
|
||||
EVENT_SUBSCRIBE_MEMBER(m_EPlaySoundOnPosition, &SoundManager::OnPlaySoundOnPosition);
|
||||
EVENT_SUBSCRIBE_MEMBER(m_EPlayBackgroundMusic, &SoundManager::OnPlayBackgroundMusic);
|
||||
@@ -59,7 +62,8 @@ void SoundManager::Update(double dt)
|
||||
deleteInactiveEmitters();
|
||||
updateEmitters(dt);
|
||||
updateListener(dt);
|
||||
mainMenuLoop();
|
||||
if(false)
|
||||
mainMenuLoop();
|
||||
}
|
||||
|
||||
void SoundManager::deleteInactiveEmitters()
|
||||
@@ -171,8 +175,10 @@ Source* SoundManager::createSource(std::string filePath)
|
||||
void SoundManager::mainMenuLoop()
|
||||
{
|
||||
float time = getTimeOffsetSeconds(m_CurrentBGM);
|
||||
//LOG_INFO("%f/%f", time, m_CurrentBGM->Duration);
|
||||
// TODO: config?
|
||||
if (m_CurrentBGM->Duration - time <= 5) { // 5 is hard coded value that Petter recommended
|
||||
m_CurrentBGM = createSource("Audio/crosscounter.wav");
|
||||
m_CurrentBGM = createSource("Audio/lalala.wav");
|
||||
playSound(m_CurrentBGM);
|
||||
}
|
||||
}
|
||||
@@ -329,6 +335,18 @@ bool SoundManager::OnPlayQueueOnEntity(const Events::PlayQueueOnEntity &e)
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool SoundManager::OnChangeBGM(const Events::ChangeBGM &e)
|
||||
{
|
||||
if (m_CurrentBGM == nullptr) {
|
||||
return false;
|
||||
}
|
||||
stopSound(m_CurrentBGM);
|
||||
m_CurrentBGM = createSource(e.FilePath);
|
||||
playSound(m_CurrentBGM);
|
||||
return true;
|
||||
}
|
||||
|
||||
ALenum SoundManager::getSourceState(ALuint source)
|
||||
{
|
||||
ALenum state;
|
||||
|
||||
@@ -114,11 +114,6 @@ bool SoundSystem::OnPlayerDamage(const Events::PlayerDamage & e)
|
||||
std::vector<std::string> paths;
|
||||
paths.push_back("Audio/hurt/hurt" + std::to_string(rand) + ".wav");
|
||||
|
||||
// // Breathe
|
||||
// int ammountOfbreaths = (static_cast<int>(e.Damage) / 10) + 2; // TEMP: Idk something stupid like this shit
|
||||
// for (int i = 0; i < ammountOfbreaths; i++) {
|
||||
// paths.push_back("Audio/exhausted/breath.wav");
|
||||
// }
|
||||
Events::PlayQueueOnEntity ev;
|
||||
ev.Emitter = LocalPlayer;
|
||||
ev.FilePaths = paths;
|
||||
|
||||
Reference in New Issue
Block a user