SoundSystem does not longer inherit from SoundManager. SoundManager is a individual class that listens to events. The SoundManager only listens to the local player.
This commit is contained in:
@@ -1,6 +1,9 @@
|
|||||||
#ifndef Sound_h__
|
#ifndef Sound_h__
|
||||||
#define Sound_h__
|
#define Sound_h__
|
||||||
|
|
||||||
|
#include <OpenAL/al.h>
|
||||||
|
#include <OpenAL/alc.h>
|
||||||
|
|
||||||
#include "Core/ResourceManager.h"
|
#include "Core/ResourceManager.h"
|
||||||
|
|
||||||
class Sound : public Resource
|
class Sound : public Resource
|
||||||
|
|||||||
@@ -15,6 +15,7 @@
|
|||||||
#include "Core/EventBroker.h"
|
#include "Core/EventBroker.h"
|
||||||
#include "Core/Transform.h" // Absolute transform
|
#include "Core/Transform.h" // Absolute transform
|
||||||
#include "Sound/Sound.h"
|
#include "Sound/Sound.h"
|
||||||
|
#include "../Engine/Sound/EPlayQueueOnEntity.h"
|
||||||
#include "Sound/EPlaySoundOnEntity.h"
|
#include "Sound/EPlaySoundOnEntity.h"
|
||||||
#include "Sound/EPlaySoundOnPosition.h"
|
#include "Sound/EPlaySoundOnPosition.h"
|
||||||
#include "Sound/EPlayBackgroundMusic.h"
|
#include "Sound/EPlayBackgroundMusic.h"
|
||||||
@@ -23,19 +24,9 @@
|
|||||||
#include "Sound/EStopSound.h"
|
#include "Sound/EStopSound.h"
|
||||||
#include "Sound/ESetBGMGain.h"
|
#include "Sound/ESetBGMGain.h"
|
||||||
#include "Sound/ESetSFXGain.h"
|
#include "Sound/ESetSFXGain.h"
|
||||||
#include "Core/EShoot.h"
|
|
||||||
#include "Core/EPlayerSpawned.h"
|
|
||||||
#include "Input/EInputCommand.h"
|
|
||||||
#include "Core/ECaptured.h"
|
|
||||||
#include "Core/EPlayerDamage.h"
|
|
||||||
#include "Core/EPlayerDeath.h"
|
|
||||||
#include "Core/EPlayerHealthPickup.h"
|
|
||||||
#include "Core/EComponentAttached.h"
|
|
||||||
#include "Collision/ETrigger.h"
|
|
||||||
#include "Core/EPause.h"
|
#include "Core/EPause.h"
|
||||||
#include "Game/Events/EDoubleJump.h"
|
#include "Core/EComponentAttached.h"
|
||||||
#include "Game/Events/EDashAbility.h"
|
#include "../Core/EPlayerSpawned.h"
|
||||||
|
|
||||||
|
|
||||||
typedef std::pair<ALuint, std::vector<ALuint>> QueuedBuffers;
|
typedef std::pair<ALuint, std::vector<ALuint>> QueuedBuffers;
|
||||||
|
|
||||||
@@ -61,20 +52,6 @@ public:
|
|||||||
// Update emitters / listener
|
// Update emitters / listener
|
||||||
void Update(double dt);
|
void Update(double dt);
|
||||||
|
|
||||||
protected:
|
|
||||||
// Specific logic
|
|
||||||
void playSound(Source* source);
|
|
||||||
// Need to be the same format (sample rate etc)
|
|
||||||
void playQueue(QueuedBuffers qb);
|
|
||||||
void stopSound(Source* source);
|
|
||||||
void playerJumps();
|
|
||||||
void playerStep(double dt);
|
|
||||||
EntityID createChildEmitter(EntityWrapper localPlayer);
|
|
||||||
|
|
||||||
// Logic
|
|
||||||
World* m_World = nullptr;
|
|
||||||
EventBroker* m_EventBroker = nullptr;
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
// Help functions for working with OpenaAL
|
// Help functions for working with OpenaAL
|
||||||
void setListenerPos(glm::vec3 pos) { alListener3f(AL_POSITION, pos.x, pos.y, pos.z); };
|
void setListenerPos(glm::vec3 pos) { alListener3f(AL_POSITION, pos.x, pos.y, pos.z); };
|
||||||
@@ -92,25 +69,30 @@ private:
|
|||||||
void deleteInactiveEmitters();
|
void deleteInactiveEmitters();
|
||||||
void stopEmitters();
|
void stopEmitters();
|
||||||
void updateListener(double dt);
|
void updateListener(double dt);
|
||||||
Source* createSource(std::string filePath);
|
|
||||||
ALenum getSourceState(ALuint source);
|
ALenum getSourceState(ALuint source);
|
||||||
void setGain(Source* source, float gain);
|
void setGain(Source* source, float gain);
|
||||||
void setSoundProperties(Source* source, ComponentWrapper* soundComponent);
|
void setSoundProperties(Source* source, ComponentWrapper* soundComponent);
|
||||||
|
|
||||||
|
// Specific logic
|
||||||
|
void playSound(Source* source);
|
||||||
|
// Need to be the same format (sample rate etc)
|
||||||
|
void playQueue(QueuedBuffers qb);
|
||||||
|
void stopSound(Source* source);
|
||||||
|
Source* createSource(std::string filePath);
|
||||||
std::unordered_map<EntityID, Source*> m_Sources;
|
std::unordered_map<EntityID, Source*> m_Sources;
|
||||||
|
|
||||||
|
// Logic
|
||||||
|
World* m_World = nullptr;
|
||||||
|
EventBroker* m_EventBroker = nullptr;
|
||||||
|
|
||||||
// OpenAL system variables
|
// OpenAL system variables
|
||||||
ALCdevice* m_ALCdevice = nullptr;
|
ALCdevice* m_ALCdevice = nullptr;
|
||||||
ALCcontext* m_ALCcontext = nullptr;
|
ALCcontext* m_ALCcontext = nullptr;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
float m_BGMVolumeChannel = 1.0f;
|
float m_BGMVolumeChannel = 1.0f;
|
||||||
float m_SFXVolumeChannel = 1.0f;
|
float m_SFXVolumeChannel = 1.0f;
|
||||||
bool m_EditorEnabled = false;
|
bool m_EditorEnabled = false;
|
||||||
EntityWrapper m_LocalPlayer = EntityWrapper();
|
EntityWrapper m_LocalPlayer = EntityWrapper();
|
||||||
std::default_random_engine generator;
|
|
||||||
|
|
||||||
// Events
|
// Events
|
||||||
EventRelay<SoundManager, Events::PlaySoundOnEntity> m_EPlaySoundOnEntity;
|
EventRelay<SoundManager, Events::PlaySoundOnEntity> m_EPlaySoundOnEntity;
|
||||||
@@ -129,31 +111,16 @@ private:
|
|||||||
bool OnSetBGMGain(const Events::SetBGMGain &e);
|
bool OnSetBGMGain(const Events::SetBGMGain &e);
|
||||||
EventRelay<SoundManager, Events::SetSFXGain> m_ESetSFXGain;
|
EventRelay<SoundManager, Events::SetSFXGain> m_ESetSFXGain;
|
||||||
bool OnSetSFXGain(const Events::SetSFXGain &e);
|
bool OnSetSFXGain(const Events::SetSFXGain &e);
|
||||||
EventRelay<SoundManager, Events::Shoot> m_EShoot;
|
|
||||||
bool OnShoot(const Events::Shoot &e);
|
|
||||||
EventRelay<SoundManager, Events::PlayerSpawned> m_EPlayerSpawned;
|
|
||||||
bool OnPlayerSpawned(const Events::PlayerSpawned &e);
|
|
||||||
EventRelay<SoundManager, Events::Captured> m_ECaptured;
|
|
||||||
bool OnCaptured(const Events::Captured &e);
|
|
||||||
EventRelay<SoundManager, Events::PlayerDamage> m_EPlayerDamage;
|
|
||||||
bool OnPlayerDamage(const Events::PlayerDamage &e);
|
|
||||||
EventRelay<SoundManager, Events::PlayerDeath> m_EPlayerDeath;
|
|
||||||
bool OnPlayerDeath(const Events::PlayerDeath &e);
|
|
||||||
EventRelay<SoundManager, Events::PlayerHealthPickup> m_EPlayerHealthPickup;
|
|
||||||
bool OnPlayerHealthPickup(const Events::PlayerHealthPickup &e);
|
|
||||||
EventRelay<SoundManager, Events::ComponentAttached> m_EComponentAttached;
|
EventRelay<SoundManager, Events::ComponentAttached> m_EComponentAttached;
|
||||||
bool OnComponentAttached(const Events::ComponentAttached &e);
|
bool OnComponentAttached(const Events::ComponentAttached &e);
|
||||||
EventRelay<SoundManager, Events::TriggerTouch> m_ETriggerTouch;
|
|
||||||
bool OnTriggerTouch(const Events::TriggerTouch &e);
|
|
||||||
EventRelay<SoundManager, Events::Pause> m_EPause;
|
EventRelay<SoundManager, Events::Pause> m_EPause;
|
||||||
bool OnPause(const Events::Pause &e);
|
bool OnPause(const Events::Pause &e);
|
||||||
EventRelay<SoundManager, Events::Resume> m_EResume;
|
EventRelay<SoundManager, Events::Resume> m_EResume;
|
||||||
bool OnResume(const Events::Resume &e);
|
bool OnResume(const Events::Resume &e);
|
||||||
EventRelay<SoundManager, Events::DoubleJump> m_EDoubleJump;
|
EventRelay<SoundManager, Events::PlayerSpawned> m_EPlayerSpawned;
|
||||||
bool OnDoubleJump(const Events::DoubleJump &e);
|
bool OnPlayerSpawned(const Events::PlayerSpawned &e);
|
||||||
EventRelay<SoundManager, Events::DashAbility> m_EDashAbility;
|
EventRelay<SoundManager, Events::PlayQueueOnEntity> m_EPlayQueueOnEntity;
|
||||||
bool OnDashAbility(const Events::DashAbility &e);
|
bool OnPlayQueueOnEntity(const Events::PlayQueueOnEntity &e);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|||||||
+1
-1
@@ -30,7 +30,7 @@
|
|||||||
#include "Network/Client.h"
|
#include "Network/Client.h"
|
||||||
|
|
||||||
// Sound
|
// Sound
|
||||||
//#include "Sound/SoundManager.h"
|
#include "Sound/SoundManager.h"
|
||||||
#include "Systems/SoundSystem.h"
|
#include "Systems/SoundSystem.h"
|
||||||
|
|
||||||
class Game
|
class Game
|
||||||
|
|||||||
@@ -1,13 +1,29 @@
|
|||||||
#ifndef Systems_SoundSystem_h__
|
#ifndef Systems_SoundSystem_h__
|
||||||
#define Systems_SoundSystem_h__
|
#define Systems_SoundSystem_h__
|
||||||
|
|
||||||
|
#include <random>
|
||||||
|
|
||||||
#include "../Engine/Core/System.h"
|
#include "../Engine/Core/System.h"
|
||||||
#include "../Engine/Sound/SoundManager.h"
|
#include "../Engine/Core/ResourceManager.h"
|
||||||
|
#include "../Engine/Sound/Sound.h"
|
||||||
|
#include "../Engine/Sound/EPlayQueueOnEntity.h"
|
||||||
#include "../Engine/Core/EPlayerSpawned.h"
|
#include "../Engine/Core/EPlayerSpawned.h"
|
||||||
#include "../Engine/Input/EInputCommand.h"
|
#include "../Engine/Input/EInputCommand.h"
|
||||||
|
#include "../Engine/Core/EShoot.h"
|
||||||
|
#include "../Engine/Core/EPlayerSpawned.h"
|
||||||
|
#include "../Engine/Input/EInputCommand.h"
|
||||||
|
#include "../Engine/Core/ECaptured.h"
|
||||||
|
#include "../Engine/Core/EPlayerDamage.h"
|
||||||
|
#include "../Engine/Core/EPlayerDeath.h"
|
||||||
|
#include "../Engine/Core/EPlayerHealthPickup.h"
|
||||||
|
#include "../Engine/Collision/ETrigger.h"
|
||||||
|
#include "../Engine/Sound/EPlaySoundOnEntity.h"
|
||||||
|
#include "../Engine/Sound/EPlayBackgroundMusic.h"
|
||||||
|
#include "../Game/Events/EDoubleJump.h"
|
||||||
|
#include "../Game/Events/EDashAbility.h"
|
||||||
|
|
||||||
|
|
||||||
class SoundSystem : public PureSystem, ImpureSystem, SoundManager
|
class SoundSystem : public PureSystem, ImpureSystem
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
SoundSystem(World* world, EventBroker* eventbroker);
|
SoundSystem(World* world, EventBroker* eventbroker);
|
||||||
@@ -23,6 +39,8 @@ private:
|
|||||||
|
|
||||||
// Logic for playing a sound when a player jumps
|
// Logic for playing a sound when a player jumps
|
||||||
void playerJumps();
|
void playerJumps();
|
||||||
|
// Helper function
|
||||||
|
EntityID createChildEmitter(EntityWrapper parent);
|
||||||
|
|
||||||
// Walking logic
|
// Walking logic
|
||||||
// Keeps track of how far the player has walked within this "key press session".
|
// Keeps track of how far the player has walked within this "key press session".
|
||||||
@@ -34,10 +52,28 @@ private:
|
|||||||
// Determine what sound file to play.
|
// Determine what sound file to play.
|
||||||
bool m_LeftFoot = false;
|
bool m_LeftFoot = false;
|
||||||
|
|
||||||
|
std::default_random_engine generator;
|
||||||
|
|
||||||
EventRelay<SoundSystem, Events::PlayerSpawned> m_EPlayerSpawned;
|
EventRelay<SoundSystem, Events::PlayerSpawned> m_EPlayerSpawned;
|
||||||
bool OnPlayerSpawned(const Events::PlayerSpawned &e);
|
bool OnPlayerSpawned(const Events::PlayerSpawned &e);
|
||||||
EventRelay<SoundSystem, Events::InputCommand> m_InputCommand;
|
EventRelay<SoundSystem, Events::InputCommand> m_InputCommand;
|
||||||
bool OnInputCommand(const Events::InputCommand &e);
|
bool OnInputCommand(const Events::InputCommand &e);
|
||||||
|
EventRelay<SoundSystem, Events::DoubleJump> m_EDoubleJump;
|
||||||
|
bool OnDoubleJump(const Events::DoubleJump &e);
|
||||||
|
EventRelay<SoundSystem, Events::DashAbility> m_EDashAbility;
|
||||||
|
bool OnDashAbility(const Events::DashAbility &e);
|
||||||
|
EventRelay<SoundSystem, Events::TriggerTouch> m_ETriggerTouch;
|
||||||
|
bool OnTriggerTouch(const Events::TriggerTouch &e);
|
||||||
|
EventRelay<SoundSystem, Events::Shoot> m_EShoot;
|
||||||
|
bool OnShoot(const Events::Shoot &e);
|
||||||
|
EventRelay<SoundSystem, Events::Captured> m_ECaptured;
|
||||||
|
bool OnCaptured(const Events::Captured &e);
|
||||||
|
EventRelay<SoundSystem, Events::PlayerDamage> m_EPlayerDamage;
|
||||||
|
bool OnPlayerDamage(const Events::PlayerDamage &e);
|
||||||
|
EventRelay<SoundSystem, Events::PlayerDeath> m_EPlayerDeath;
|
||||||
|
bool OnPlayerDeath(const Events::PlayerDeath &e);
|
||||||
|
EventRelay<SoundSystem, Events::PlayerHealthPickup> m_EPlayerHealthPickup;
|
||||||
|
bool OnPlayerHealthPickup(const Events::PlayerHealthPickup &e);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -20,16 +20,11 @@ SoundManager::SoundManager(World* world, EventBroker* eventBroker, bool editorMo
|
|||||||
EVENT_SUBSCRIBE_MEMBER(m_EContinueSound, &SoundManager::OnContinueSound);
|
EVENT_SUBSCRIBE_MEMBER(m_EContinueSound, &SoundManager::OnContinueSound);
|
||||||
EVENT_SUBSCRIBE_MEMBER(m_ESetBGMGain, &SoundManager::OnSetBGMGain);
|
EVENT_SUBSCRIBE_MEMBER(m_ESetBGMGain, &SoundManager::OnSetBGMGain);
|
||||||
EVENT_SUBSCRIBE_MEMBER(m_ESetSFXGain, &SoundManager::OnSetSFXGain);
|
EVENT_SUBSCRIBE_MEMBER(m_ESetSFXGain, &SoundManager::OnSetSFXGain);
|
||||||
EVENT_SUBSCRIBE_MEMBER(m_EShoot, &SoundManager::OnShoot);
|
|
||||||
EVENT_SUBSCRIBE_MEMBER(m_EPlayerSpawned, &SoundManager::OnPlayerSpawned);
|
|
||||||
EVENT_SUBSCRIBE_MEMBER(m_EPlayerDamage, &SoundManager::OnPlayerDamage);
|
|
||||||
EVENT_SUBSCRIBE_MEMBER(m_ECaptured, &SoundManager::OnCaptured);
|
|
||||||
EVENT_SUBSCRIBE_MEMBER(m_ETriggerTouch, &SoundManager::OnTriggerTouch);
|
|
||||||
EVENT_SUBSCRIBE_MEMBER(m_EPause, &SoundManager::OnPause);
|
EVENT_SUBSCRIBE_MEMBER(m_EPause, &SoundManager::OnPause);
|
||||||
EVENT_SUBSCRIBE_MEMBER(m_EResume, &SoundManager::OnResume);
|
EVENT_SUBSCRIBE_MEMBER(m_EResume, &SoundManager::OnResume);
|
||||||
EVENT_SUBSCRIBE_MEMBER(m_EComponentAttached, &SoundManager::OnComponentAttached);
|
EVENT_SUBSCRIBE_MEMBER(m_EComponentAttached, &SoundManager::OnComponentAttached);
|
||||||
EVENT_SUBSCRIBE_MEMBER(m_EDoubleJump, &SoundManager::OnDoubleJump);
|
EVENT_SUBSCRIBE_MEMBER(m_EPlayerSpawned, &SoundManager::OnPlayerSpawned);
|
||||||
EVENT_SUBSCRIBE_MEMBER(m_EDashAbility, &SoundManager::OnDashAbility);
|
EVENT_SUBSCRIBE_MEMBER(m_EPlayQueueOnEntity, &SoundManager::OnPlayQueueOnEntity);
|
||||||
}
|
}
|
||||||
|
|
||||||
SoundManager::~SoundManager()
|
SoundManager::~SoundManager()
|
||||||
@@ -135,18 +130,21 @@ void SoundManager::updateListener(double dt)
|
|||||||
{
|
{
|
||||||
// Should only be one listener.
|
// Should only be one listener.
|
||||||
auto listenerComponents = m_World->GetComponents("Listener");
|
auto listenerComponents = m_World->GetComponents("Listener");
|
||||||
if (listenerComponents == nullptr) {
|
if (listenerComponents == nullptr || !m_LocalPlayer.Valid()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
for (auto it = listenerComponents->begin(); it != listenerComponents->end(); it++) {
|
for (auto it = listenerComponents->begin(); it != listenerComponents->end(); it++) {
|
||||||
EntityID listener = (*it).EntityID;
|
EntityWrapper listener(m_World, (*it).EntityID);
|
||||||
glm::vec3 previousPos;
|
if (listener.IsChildOf(m_LocalPlayer) || listener == m_LocalPlayer) {
|
||||||
alGetListener3f(AL_POSITION, &previousPos.x, &previousPos.y, &previousPos.z); // Get previous pos
|
glm::vec3 previousPos;
|
||||||
glm::vec3 nextPos = Transform::AbsolutePosition(m_World, listener); // Get next (current) pos
|
alGetListener3f(AL_POSITION, &previousPos.x, &previousPos.y, &previousPos.z); // Get previous pos
|
||||||
glm::vec3 velocity = glm::vec3(nextPos - previousPos) / (float)dt; // Calculate velocity
|
glm::vec3 nextPos = Transform::AbsolutePosition(listener); // Get next (current) pos
|
||||||
setListenerPos(nextPos);
|
glm::vec3 velocity = glm::vec3(nextPos - previousPos) / (float)dt; // Calculate velocity
|
||||||
setListenerVel(velocity);
|
setListenerPos(nextPos);
|
||||||
setListenerOri(glm::eulerAngles(Transform::AbsoluteOrientation(m_World, listener)));
|
setListenerVel(velocity);
|
||||||
|
setListenerOri(glm::eulerAngles(Transform::AbsoluteOrientation(listener)));
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -181,21 +179,6 @@ void SoundManager::stopSound(Source* source)
|
|||||||
alSourceStop(source->ALsource);
|
alSourceStop(source->ALsource);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void SoundManager::playerStep(double dt)
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
EntityID SoundManager::createChildEmitter(EntityWrapper localPlayer)
|
|
||||||
{
|
|
||||||
EntityID child = m_World->CreateEntity(localPlayer.ID);
|
|
||||||
m_World->AttachComponent(child, "Transform");
|
|
||||||
m_World->AttachComponent(child, "SoundEmitter");
|
|
||||||
return child;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool SoundManager::OnPlaySoundOnEntity(const Events::PlaySoundOnEntity & e)
|
bool SoundManager::OnPlaySoundOnEntity(const Events::PlaySoundOnEntity & e)
|
||||||
{
|
{
|
||||||
Source* source = createSource(e.FilePath);
|
Source* source = createSource(e.FilePath);
|
||||||
@@ -272,87 +255,6 @@ bool SoundManager::OnSetSFXGain(const Events::SetSFXGain & e)
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool SoundManager::OnShoot(const Events::Shoot & e)
|
|
||||||
{
|
|
||||||
Source* source = createSource("Audio/laser/laser1.wav");
|
|
||||||
//auto emitterID = m_World->CreateEntity(e.Player.ID);
|
|
||||||
//m_World->AttachComponent(emitterID, "Transform");
|
|
||||||
//auto emitter = m_World->AttachComponent(emitterID, "SoundEmitter");
|
|
||||||
source->Type = SoundType::SFX;
|
|
||||||
m_Sources[createChildEmitter(m_LocalPlayer)] = source;
|
|
||||||
playSound(source);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool SoundManager::OnPlayerSpawned(const Events::PlayerSpawned & e)
|
|
||||||
{
|
|
||||||
if (e.PlayerID == -1) { // Local player
|
|
||||||
m_World->AttachComponent(e.Player.ID, "Listener");
|
|
||||||
m_LocalPlayer.ID = e.Player.ID;
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
bool SoundManager::OnCaptured(const Events::Captured & e)
|
|
||||||
{
|
|
||||||
int homeTeam = (int)m_World->GetComponent(e.CapturePointID, "Team")["Team"];
|
|
||||||
int team = (int)m_World->GetComponent(m_LocalPlayer.ID, "Team")["Team"];
|
|
||||||
Events::PlaySoundOnEntity ev;
|
|
||||||
if (team == homeTeam) {
|
|
||||||
ev.FilePath = "Audio/announcer/objective_achieved.wav";
|
|
||||||
} else {
|
|
||||||
ev.FilePath = "Audio/announcer/objective_failed.wav"; // have not been tested
|
|
||||||
}
|
|
||||||
ev.EmitterID = createChildEmitter(m_LocalPlayer);
|
|
||||||
m_EventBroker->Publish(ev);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool SoundManager::OnPlayerDamage(const Events::PlayerDamage & e)
|
|
||||||
{
|
|
||||||
// Should check for only local players here...
|
|
||||||
|
|
||||||
std::uniform_int_distribution<int> dist(1, 12);
|
|
||||||
int rand = dist(generator);
|
|
||||||
Source* source = createSource("Audio/hurt/hurt" + std::to_string(rand) + ".wav");
|
|
||||||
source->Type = SoundType::SFX;
|
|
||||||
m_Sources[createChildEmitter(m_LocalPlayer)] = source;
|
|
||||||
|
|
||||||
// Breathe
|
|
||||||
std::vector<ALuint> buffers;
|
|
||||||
buffers.push_back(source->SoundResource->Buffer());
|
|
||||||
int ammountOfbreaths = (static_cast<int>(e.Damage) / 10) + 2; // TEMP: Idk something stupid like this shit
|
|
||||||
for (int i = 0; i < ammountOfbreaths; i++) {
|
|
||||||
buffers.push_back(ResourceManager::Load<Sound>("Audio/exhausted/breath.wav")->Buffer());
|
|
||||||
}
|
|
||||||
playQueue(QueuedBuffers(std::make_pair(source->ALsource, buffers)));
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool SoundManager::OnPlayerDeath(const Events::PlayerDeath & e)
|
|
||||||
{
|
|
||||||
if (e.PlayerID == m_LocalPlayer.ID) {
|
|
||||||
Events::PlaySoundOnEntity ev;
|
|
||||||
ev.EmitterID = createChildEmitter(m_LocalPlayer);
|
|
||||||
ev.FilePath = "Audio/die/die2.wav"; // should random between a bunch
|
|
||||||
m_EventBroker->Publish(ev);
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool SoundManager::OnPlayerHealthPickup(const Events::PlayerHealthPickup & e)
|
|
||||||
{
|
|
||||||
if (e.PlayerHealedID == m_LocalPlayer.ID) {
|
|
||||||
Events::PlaySoundOnEntity ev;
|
|
||||||
ev.EmitterID = createChildEmitter(m_LocalPlayer);
|
|
||||||
ev.FilePath = "Audio/pickup/pickup2.wav";
|
|
||||||
m_EventBroker->Publish(ev);
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool SoundManager::OnComponentAttached(const Events::ComponentAttached & e)
|
bool SoundManager::OnComponentAttached(const Events::ComponentAttached & e)
|
||||||
{
|
{
|
||||||
if (e.Component.Info.Name == "SoundEmitter") {
|
if (e.Component.Info.Name == "SoundEmitter") {
|
||||||
@@ -363,16 +265,6 @@ bool SoundManager::OnComponentAttached(const Events::ComponentAttached & e)
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool SoundManager::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;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool SoundManager::OnPause(const Events::Pause & e)
|
bool SoundManager::OnPause(const Events::Pause & e)
|
||||||
{
|
{
|
||||||
for (auto it = m_Sources.begin(); it != m_Sources.end(); it++) {
|
for (auto it = m_Sources.begin(); it != m_Sources.end(); it++) {
|
||||||
@@ -389,22 +281,29 @@ bool SoundManager::OnResume(const Events::Resume &e)
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool SoundManager::OnDoubleJump(const Events::DoubleJump & e)
|
|
||||||
|
bool SoundManager::OnPlayerSpawned(const Events::PlayerSpawned &e)
|
||||||
{
|
{
|
||||||
Events::PlaySoundOnEntity ev;
|
if (e.PlayerID == -1) { // Local player
|
||||||
ev.EmitterID = createChildEmitter(m_LocalPlayer);
|
m_LocalPlayer = e.Player;
|
||||||
ev.FilePath = "Audio/jump/jump2.wav";
|
return true;
|
||||||
m_EventBroker->Publish(ev);
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool SoundManager::OnDashAbility(const Events::DashAbility &e)
|
|
||||||
|
bool SoundManager::OnPlayQueueOnEntity(const Events::PlayQueueOnEntity &e)
|
||||||
{
|
{
|
||||||
Events::PlaySoundOnEntity ev;
|
Source* source = createSource(*e.FilePaths.begin());
|
||||||
ev.EmitterID = createChildEmitter(m_LocalPlayer);
|
std::vector<ALuint> buffers;
|
||||||
ev.FilePath = "Audio/jump/dash1.wav";
|
buffers.push_back(source->SoundResource->Buffer());
|
||||||
m_EventBroker->Publish(ev);
|
source->Type = SoundType::BGM;
|
||||||
return false;
|
std::vector<std::string>::const_iterator it;
|
||||||
|
for (it = e.FilePaths.begin() + 1; it != e.FilePaths.end(); it++) {
|
||||||
|
buffers.push_back(ResourceManager::Load<Sound>(*it)->Buffer());
|
||||||
|
}
|
||||||
|
playQueue(QueuedBuffers(source->ALsource, buffers));
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
ALenum SoundManager::getSourceState(ALuint source)
|
ALenum SoundManager::getSourceState(ALuint source)
|
||||||
|
|||||||
@@ -71,6 +71,8 @@ Game::Game(int argc, char* argv[])
|
|||||||
fp.MergeEntities(m_World);
|
fp.MergeEntities(m_World);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Create the sound manager
|
||||||
|
m_SoundManager = new SoundManager(m_World, m_EventBroker, true);
|
||||||
|
|
||||||
// Create Octrees
|
// Create Octrees
|
||||||
m_OctreeCollision = new Octree<EntityAABB>(AABB(glm::vec3(-100), glm::vec3(100)), 4);
|
m_OctreeCollision = new Octree<EntityAABB>(AABB(glm::vec3(-100), glm::vec3(100)), 4);
|
||||||
@@ -123,6 +125,7 @@ Game::~Game()
|
|||||||
delete m_OctreeFrustrumCulling;
|
delete m_OctreeFrustrumCulling;
|
||||||
delete m_OctreeCollision;
|
delete m_OctreeCollision;
|
||||||
delete m_OctreeTrigger;
|
delete m_OctreeTrigger;
|
||||||
|
delete m_SoundManager;
|
||||||
delete m_World;
|
delete m_World;
|
||||||
delete m_FrameStack;
|
delete m_FrameStack;
|
||||||
delete m_InputProxy;
|
delete m_InputProxy;
|
||||||
@@ -150,6 +153,8 @@ void Game::Tick()
|
|||||||
m_InputProxy->Process();
|
m_InputProxy->Process();
|
||||||
m_EventBroker->Swap();
|
m_EventBroker->Swap();
|
||||||
|
|
||||||
|
m_SoundManager->Update(dt);
|
||||||
|
|
||||||
// Update network
|
// Update network
|
||||||
if (m_IsClientOrServer) {
|
if (m_IsClientOrServer) {
|
||||||
m_ClientOrServer->Update();
|
m_ClientOrServer->Update();
|
||||||
|
|||||||
@@ -4,12 +4,18 @@ SoundSystem::SoundSystem(World* world, EventBroker* eventbroker)
|
|||||||
: System(world, eventbroker)
|
: System(world, eventbroker)
|
||||||
, PureSystem("SoundEmitter")
|
, PureSystem("SoundEmitter")
|
||||||
, ImpureSystem()
|
, ImpureSystem()
|
||||||
, SoundManager(world, eventbroker, true)
|
|
||||||
{
|
{
|
||||||
m_World = world;
|
m_World = world;
|
||||||
m_EventBroker = eventbroker;
|
m_EventBroker = eventbroker;
|
||||||
EVENT_SUBSCRIBE_MEMBER(m_EPlayerSpawned, &SoundSystem::OnPlayerSpawned);
|
EVENT_SUBSCRIBE_MEMBER(m_EPlayerSpawned, &SoundSystem::OnPlayerSpawned);
|
||||||
EVENT_SUBSCRIBE_MEMBER(m_InputCommand, &SoundSystem::OnInputCommand);
|
EVENT_SUBSCRIBE_MEMBER(m_InputCommand, &SoundSystem::OnInputCommand);
|
||||||
|
EVENT_SUBSCRIBE_MEMBER(m_EDoubleJump, &SoundSystem::OnDoubleJump);
|
||||||
|
EVENT_SUBSCRIBE_MEMBER(m_EDashAbility, &SoundSystem::OnDashAbility);
|
||||||
|
EVENT_SUBSCRIBE_MEMBER(m_EShoot, &SoundSystem::OnShoot);
|
||||||
|
EVENT_SUBSCRIBE_MEMBER(m_EPlayerSpawned, &SoundSystem::OnPlayerSpawned);
|
||||||
|
EVENT_SUBSCRIBE_MEMBER(m_EPlayerDamage, &SoundSystem::OnPlayerDamage);
|
||||||
|
EVENT_SUBSCRIBE_MEMBER(m_ECaptured, &SoundSystem::OnCaptured);
|
||||||
|
EVENT_SUBSCRIBE_MEMBER(m_ETriggerTouch, &SoundSystem::OnTriggerTouch);
|
||||||
}
|
}
|
||||||
|
|
||||||
void SoundSystem::UpdateComponent(EntityWrapper& entity, ComponentWrapper& cComponent, double dt)
|
void SoundSystem::UpdateComponent(EntityWrapper& entity, ComponentWrapper& cComponent, double dt)
|
||||||
@@ -20,8 +26,6 @@ void SoundSystem::UpdateComponent(EntityWrapper& entity, ComponentWrapper& cComp
|
|||||||
void SoundSystem::Update(double dt)
|
void SoundSystem::Update(double dt)
|
||||||
{
|
{
|
||||||
playerStep(dt);
|
playerStep(dt);
|
||||||
// Update listener and emitters.
|
|
||||||
SoundManager::Update(dt);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void SoundSystem::playerStep(double dt)
|
void SoundSystem::playerStep(double dt)
|
||||||
@@ -83,6 +87,12 @@ bool SoundSystem::OnInputCommand(const Events::InputCommand & e)
|
|||||||
m_DistanceMoved = 0.f;
|
m_DistanceMoved = 0.f;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (e.Command == "TakeDamage" && e.Value > 0) {
|
||||||
|
Events::PlayerDamage ev;
|
||||||
|
ev.Player = m_LocalPlayer;
|
||||||
|
ev.Damage = 1.0;
|
||||||
|
m_EventBroker->Publish(ev);
|
||||||
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -97,3 +107,106 @@ void SoundSystem::playerJumps()
|
|||||||
m_EventBroker->Publish(e);
|
m_EventBroker->Publish(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool SoundSystem::OnShoot(const Events::Shoot & e)
|
||||||
|
{
|
||||||
|
Events::PlaySoundOnEntity ev;
|
||||||
|
ev.EmitterID = createChildEmitter(m_LocalPlayer);
|
||||||
|
ev.FilePath = "Audio/laser/laser1.wav";
|
||||||
|
m_EventBroker->Publish(ev);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool SoundSystem::OnCaptured(const Events::Captured & e)
|
||||||
|
{
|
||||||
|
int homeTeam = (int)m_World->GetComponent(e.CapturePointID, "Team")["Team"];
|
||||||
|
int team = (int)m_World->GetComponent(m_LocalPlayer.ID, "Team")["Team"];
|
||||||
|
Events::PlaySoundOnEntity ev;
|
||||||
|
if (team == homeTeam) {
|
||||||
|
ev.FilePath = "Audio/announcer/objective_achieved.wav";
|
||||||
|
} else {
|
||||||
|
ev.FilePath = "Audio/announcer/objective_failed.wav"; // have not been tested
|
||||||
|
}
|
||||||
|
ev.EmitterID = createChildEmitter(m_LocalPlayer);
|
||||||
|
m_EventBroker->Publish(ev);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Testing purposes atm...
|
||||||
|
bool SoundSystem::OnPlayerDamage(const Events::PlayerDamage & e)
|
||||||
|
{
|
||||||
|
// Should check for only local players here...
|
||||||
|
std::uniform_int_distribution<int> dist(1, 12);
|
||||||
|
int rand = dist(generator);
|
||||||
|
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 = m_LocalPlayer;
|
||||||
|
ev.FilePaths = paths;
|
||||||
|
m_EventBroker->Publish(ev);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool SoundSystem::OnPlayerDeath(const Events::PlayerDeath & e)
|
||||||
|
{
|
||||||
|
if (e.PlayerID == m_LocalPlayer.ID) {
|
||||||
|
Events::PlaySoundOnEntity ev;
|
||||||
|
ev.EmitterID = createChildEmitter(m_LocalPlayer);
|
||||||
|
ev.FilePath = "Audio/die/die2.wav"; // should random between a bunch
|
||||||
|
m_EventBroker->Publish(ev);
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool SoundSystem::OnPlayerHealthPickup(const Events::PlayerHealthPickup & e)
|
||||||
|
{
|
||||||
|
if (e.PlayerHealedID == m_LocalPlayer.ID) {
|
||||||
|
Events::PlaySoundOnEntity ev;
|
||||||
|
ev.EmitterID = createChildEmitter(m_LocalPlayer);
|
||||||
|
ev.FilePath = "Audio/pickup/pickup2.wav";
|
||||||
|
m_EventBroker->Publish(ev);
|
||||||
|
}
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool SoundSystem::OnDoubleJump(const Events::DoubleJump & e)
|
||||||
|
{
|
||||||
|
Events::PlaySoundOnEntity ev;
|
||||||
|
ev.EmitterID = createChildEmitter(m_LocalPlayer);
|
||||||
|
ev.FilePath = "Audio/jump/jump2.wav";
|
||||||
|
m_EventBroker->Publish(ev);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool SoundSystem::OnDashAbility(const Events::DashAbility &e)
|
||||||
|
{
|
||||||
|
Events::PlaySoundOnEntity ev;
|
||||||
|
ev.EmitterID = createChildEmitter(m_LocalPlayer);
|
||||||
|
ev.FilePath = "Audio/jump/dash1.wav";
|
||||||
|
m_EventBroker->Publish(ev);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
EntityID SoundSystem::createChildEmitter(EntityWrapper localPlayer)
|
||||||
|
{
|
||||||
|
EntityID child = m_World->CreateEntity(localPlayer.ID);
|
||||||
|
m_World->AttachComponent(child, "Transform");
|
||||||
|
m_World->AttachComponent(child, "SoundEmitter");
|
||||||
|
return child;
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user