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:
stiffly
2016-02-08 14:01:32 +01:00
parent 12c05d5a1c
commit 3a5c0a2762
7 changed files with 211 additions and 188 deletions
+3
View File
@@ -1,6 +1,9 @@
#ifndef Sound_h__
#define Sound_h__
#include <OpenAL/al.h>
#include <OpenAL/alc.h>
#include "Core/ResourceManager.h"
class Sound : public Resource
+16 -49
View File
@@ -15,6 +15,7 @@
#include "Core/EventBroker.h"
#include "Core/Transform.h" // Absolute transform
#include "Sound/Sound.h"
#include "../Engine/Sound/EPlayQueueOnEntity.h"
#include "Sound/EPlaySoundOnEntity.h"
#include "Sound/EPlaySoundOnPosition.h"
#include "Sound/EPlayBackgroundMusic.h"
@@ -23,19 +24,9 @@
#include "Sound/EStopSound.h"
#include "Sound/ESetBGMGain.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 "Game/Events/EDoubleJump.h"
#include "Game/Events/EDashAbility.h"
#include "Core/EComponentAttached.h"
#include "../Core/EPlayerSpawned.h"
typedef std::pair<ALuint, std::vector<ALuint>> QueuedBuffers;
@@ -61,20 +52,6 @@ public:
// Update emitters / listener
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:
// Help functions for working with OpenaAL
void setListenerPos(glm::vec3 pos) { alListener3f(AL_POSITION, pos.x, pos.y, pos.z); };
@@ -92,25 +69,30 @@ private:
void deleteInactiveEmitters();
void stopEmitters();
void updateListener(double dt);
Source* createSource(std::string filePath);
ALenum getSourceState(ALuint source);
void setGain(Source* source, float gain);
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;
// Logic
World* m_World = nullptr;
EventBroker* m_EventBroker = nullptr;
// OpenAL system variables
ALCdevice* m_ALCdevice = nullptr;
ALCcontext* m_ALCcontext = nullptr;
float m_BGMVolumeChannel = 1.0f;
float m_SFXVolumeChannel = 1.0f;
bool m_EditorEnabled = false;
EntityWrapper m_LocalPlayer = EntityWrapper();
std::default_random_engine generator;
// Events
EventRelay<SoundManager, Events::PlaySoundOnEntity> m_EPlaySoundOnEntity;
@@ -129,31 +111,16 @@ private:
bool OnSetBGMGain(const Events::SetBGMGain &e);
EventRelay<SoundManager, Events::SetSFXGain> m_ESetSFXGain;
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;
bool OnComponentAttached(const Events::ComponentAttached &e);
EventRelay<SoundManager, Events::TriggerTouch> m_ETriggerTouch;
bool OnTriggerTouch(const Events::TriggerTouch &e);
EventRelay<SoundManager, Events::Pause> m_EPause;
bool OnPause(const Events::Pause &e);
EventRelay<SoundManager, Events::Resume> m_EResume;
bool OnResume(const Events::Resume &e);
EventRelay<SoundManager, Events::DoubleJump> m_EDoubleJump;
bool OnDoubleJump(const Events::DoubleJump &e);
EventRelay<SoundManager, Events::DashAbility> m_EDashAbility;
bool OnDashAbility(const Events::DashAbility &e);
EventRelay<SoundManager, Events::PlayerSpawned> m_EPlayerSpawned;
bool OnPlayerSpawned(const Events::PlayerSpawned &e);
EventRelay<SoundManager, Events::PlayQueueOnEntity> m_EPlayQueueOnEntity;
bool OnPlayQueueOnEntity(const Events::PlayQueueOnEntity &e);
};
+1 -1
View File
@@ -30,7 +30,7 @@
#include "Network/Client.h"
// Sound
//#include "Sound/SoundManager.h"
#include "Sound/SoundManager.h"
#include "Systems/SoundSystem.h"
class Game
+38 -2
View File
@@ -1,13 +1,29 @@
#ifndef Systems_SoundSystem_h__
#define Systems_SoundSystem_h__
#include <random>
#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/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:
SoundSystem(World* world, EventBroker* eventbroker);
@@ -23,6 +39,8 @@ private:
// Logic for playing a sound when a player jumps
void playerJumps();
// Helper function
EntityID createChildEmitter(EntityWrapper parent);
// Walking logic
// 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.
bool m_LeftFoot = false;
std::default_random_engine generator;
EventRelay<SoundSystem, Events::PlayerSpawned> m_EPlayerSpawned;
bool OnPlayerSpawned(const Events::PlayerSpawned &e);
EventRelay<SoundSystem, Events::InputCommand> m_InputCommand;
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