Assured the volume channels were working. Playing around with drumloop

This commit is contained in:
stiffly
2016-02-03 10:17:53 +01:00
parent 88ad127d8d
commit a64d227cab
3 changed files with 43 additions and 14 deletions
+1 -1
Submodule assets updated: 5bf03ccd54...cde9a43029
+10 -3
View File
@@ -9,6 +9,8 @@
#include "OpenAL/al.h"
#include "OpenAL/alc.h"
#include "imgui/imgui.h"
#include "Core/World.h"
#include "Core/EventBroker.h"
#include "Core/Transform.h" // Absolute transform
@@ -29,6 +31,7 @@
#include "Core/EPlayerDeath.h"
#include "Core/EPlayerHealthPickup.h"
#include "Core/EComponentAttached.h"
#include "Collision/ETrigger.h"
enum class SoundType {
SFX,
@@ -90,8 +93,11 @@ private:
World* m_World = nullptr;
EventBroker* m_EventBroker = nullptr;
std::unordered_map<EntityID, Source*> m_Sources;
float m_BGMVolumeChannel = 1.f;
float m_SFXVolumeChannel = 1.f;
float m_BGMVolumeChannel = 1.0f;
float m_SFXVolumeChannel = 1.0f;
bool m_EditorEnabled = false;
const double m_PlayerFootstepInterval = 1.0;
double m_TimeSinceLastFootstep = 0;
@@ -117,7 +123,6 @@ private:
bool OnSetBGMGain(const Events::SetBGMGain &e); // Not tested
EventRelay<SoundSystem, Events::SetSFXGain> m_ESetSFXGain;
bool OnSetSFXGain(const Events::SetSFXGain &e); // Not tested
EventRelay<SoundSystem, Events::Shoot> m_EShoot;
bool OnShoot(const Events::Shoot &e);
EventRelay<SoundSystem, Events::PlayerSpawned> m_EPlayerSpawned;
@@ -134,6 +139,8 @@ private:
bool OnPlayerHealthPickup(const Events::PlayerHealthPickup &e);
EventRelay<SoundSystem, Events::ComponentAttached> m_EComponentAttached;
bool OnComponentAttached(const Events::ComponentAttached &e);
EventRelay<SoundSystem, Events::TriggerTouch> m_ETriggerTouch;
bool OnTriggerTouch(const Events::TriggerTouch &e);
+32 -10
View File
@@ -25,6 +25,7 @@ SoundSystem::SoundSystem(World* world, EventBroker* eventBroker, bool editorMode
EVENT_SUBSCRIBE_MEMBER(m_EPlayerDamage, &SoundSystem::OnPlayerDamage);
EVENT_SUBSCRIBE_MEMBER(m_EInputCommand, &SoundSystem::OnInputCommand);
EVENT_SUBSCRIBE_MEMBER(m_ECaptured, &SoundSystem::OnCaptured);
EVENT_SUBSCRIBE_MEMBER(m_ETriggerTouch, &SoundSystem::OnTriggerTouch);
}
SoundSystem::~SoundSystem()
@@ -60,6 +61,10 @@ void SoundSystem::Update(double dt)
deleteInactiveEmitters(); // can be optimized with "EEntityDeleted"
updateEmitters(dt);
updateListener(dt);
// Editor debug info
ImGui::SliderFloat("BGM", &m_BGMVolumeChannel, 0.0f, 1.0f, "%.3f", 1.0f);
ImGui::SliderFloat("SFX", &m_SFXVolumeChannel, 0.0f, 1.0f, "%.3f", 1.0f);
}
void SoundSystem::deleteInactiveEmitters()
@@ -287,11 +292,12 @@ bool SoundSystem::OnPlayBackgroundMusic(const Events::PlayBackgroundMusic & e)
for (auto it = listenerComponents->begin(); it != listenerComponents->end(); it++) {
auto emitterChild = m_World->CreateEntity((*it).EntityID);
auto emitter = m_World->AttachComponent(emitterChild, "SoundEmitter");
(bool&)emitter["Loop"] = true;
(bool&)emitter["Loop"] = false;
(std::string&)emitter["FilePath"] = e.FilePath;
m_World->AttachComponent(emitterChild, "Transform");
Source* source = createSource(e.FilePath);
source->Type = SoundType::BGM;
setSoundProperties(source, &emitter);
m_Sources[emitterChild] = source;
playSound(source);
}
@@ -334,6 +340,12 @@ bool SoundSystem::OnPlayerSpawned(const Events::PlayerSpawned & e)
event.EmitterID = child;
event.FilePath = "Audio/announcer/go.wav";
m_EventBroker->Publish(event);
// TEMP: starts bgm
{
Events::PlayBackgroundMusic ev;
ev.FilePath = "Audio/bgm/ambient.wav";
m_EventBroker->Publish(ev);
}
}
return true;
}
@@ -384,15 +396,15 @@ bool SoundSystem::OnCaptured(const Events::Captured & e)
bool SoundSystem::OnPlayerDamage(const Events::PlayerDamage & e)
{
//if (e.Player.ID == m_LocalPlayer) {
Events::PlaySoundOnEntity ev;
EntityID child = m_World->CreateEntity(m_LocalPlayer);
m_World->AttachComponent(child, "Transform");
m_World->AttachComponent(child, "SoundEmitter");
ev.EmitterID = child;
std::uniform_int_distribution<int> dist(1, 12);
int rand = dist(generator);
ev.FilePath = "Audio/hurt/hurt" + std::to_string(rand) + ".wav";
m_EventBroker->Publish(ev);
Events::PlaySoundOnEntity ev;
EntityID child = m_World->CreateEntity(m_LocalPlayer);
m_World->AttachComponent(child, "Transform");
m_World->AttachComponent(child, "SoundEmitter");
ev.EmitterID = child;
std::uniform_int_distribution<int> dist(1, 12);
int rand = dist(generator);
ev.FilePath = "Audio/hurt/hurt" + std::to_string(rand) + ".wav";
m_EventBroker->Publish(ev);
//}
return false;
}
@@ -433,6 +445,16 @@ bool SoundSystem::OnComponentAttached(const Events::ComponentAttached & e)
return false;
}
bool SoundSystem::OnTriggerTouch(const Events::TriggerTouch & e)
{
if (m_World->HasComponent(e.Trigger.ID, "CapturePoint")) {
Events::PlayBackgroundMusic ev;
ev.FilePath = "Audio/bgm/drumstest.wav";
m_EventBroker->Publish(ev);
}
return false;
}
void SoundSystem::setListenerOri(glm::vec3 ori)
{
// Calculate forward and up vector.