Refactoring and commenting.
This commit is contained in:
@@ -6,7 +6,7 @@
|
||||
|
||||
namespace Events
|
||||
{
|
||||
|
||||
// Continues to play a sound from where it was paused.
|
||||
struct ContinueSound : Event
|
||||
{
|
||||
EntityID EmitterID;
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
|
||||
namespace Events
|
||||
{
|
||||
|
||||
// Pauses a playing sound
|
||||
struct PauseSound : Event
|
||||
{
|
||||
EntityID EmitterID;
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
|
||||
namespace Events
|
||||
{
|
||||
|
||||
// Play a sound that will be heared the same anywhere
|
||||
struct PlayBackgroundMusic : public Event
|
||||
{
|
||||
std::string FilePath = "";
|
||||
|
||||
@@ -1,18 +0,0 @@
|
||||
#ifndef Events_PlaySound_h__
|
||||
#define Events_PlaySound_h__
|
||||
|
||||
#include "Core/EventBroker.h"
|
||||
#include "Core/Entity.h"
|
||||
|
||||
namespace Events
|
||||
{
|
||||
|
||||
struct PlaySound : Event
|
||||
{
|
||||
std::string FilePath;
|
||||
EntityID EmitterID;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -10,6 +10,7 @@ namespace Events
|
||||
|
||||
// Plays a sound on an entity with a SoundEmitter component attached.
|
||||
// Sound behavior is thereby specified in the SoundEmitter component.
|
||||
// ?(???)??
|
||||
struct PlaySoundOnEntity : public Event
|
||||
{
|
||||
EntityID EmitterID = 0;
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
namespace Events
|
||||
{
|
||||
|
||||
// Plays a sound on a given position
|
||||
// Plays a sound on a given position. Idk if this would be useful.
|
||||
struct PlaySoundOnPosition : public Event
|
||||
{
|
||||
glm::vec3 Position = glm::vec3(0);
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
|
||||
namespace Events
|
||||
{
|
||||
|
||||
// Set the "volume" for all background sounds
|
||||
struct SetBGMGain : public Event
|
||||
{
|
||||
float Gain;
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
|
||||
namespace Events
|
||||
{
|
||||
|
||||
// Set the "volume" for all effect sounds
|
||||
struct SetSFXGain : public Event
|
||||
{
|
||||
float Gain;
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
|
||||
namespace Events
|
||||
{
|
||||
|
||||
// Stops a sound emitter, and will also delete it.
|
||||
struct StopSound : Event
|
||||
{
|
||||
EntityID EmitterID;
|
||||
|
||||
@@ -12,7 +12,6 @@
|
||||
#include "Core/EventBroker.h"
|
||||
#include "Rendering/RenderQueueFactory.h" // Absolute transform
|
||||
#include "Sound/Sound.h"
|
||||
#include "Sound/EPlaySound.h"
|
||||
#include "Sound/EPlaySoundOnEntity.h"
|
||||
#include "Sound/EPlaySoundOnPosition.h"
|
||||
#include "Sound/EPlayBackgroundMusic.h"
|
||||
@@ -22,13 +21,17 @@
|
||||
#include "Sound/ESetBGMGain.h"
|
||||
#include "Sound/ESetSFXGain.h"
|
||||
|
||||
enum class SoundType {
|
||||
SFX,
|
||||
BGM
|
||||
};
|
||||
|
||||
struct Source
|
||||
{
|
||||
Source() { }
|
||||
Sound* SoundResource = nullptr;
|
||||
ALuint ALsource;
|
||||
bool HasBeenPlayed = false;
|
||||
SoundType Type;
|
||||
};
|
||||
|
||||
class SoundSystem
|
||||
@@ -42,15 +45,15 @@ public:
|
||||
private:
|
||||
// Help functions for working with OpenaAL
|
||||
void setListenerPos(glm::vec3 pos) { alListener3f(AL_POSITION, pos.x, pos.y, pos.z); };
|
||||
glm::vec3 listnerPos() { glm::vec3 pos; alGetListener3f(AL_POSITION, &pos.x, &pos.y, &pos.z); return pos; };
|
||||
void setListenerVel(glm::vec3 vel) { alListener3f(AL_VELOCITY, vel.x, vel.y, vel.z); };
|
||||
glm::vec3 listenerVel() { glm::vec3 vel; alGetListener3f(AL_VELOCITY, &vel.x, &vel.y, &vel.z); return vel; };
|
||||
void setListenerOri(glm::vec3 ori);
|
||||
glm::vec3 listnerPos() { glm::vec3 pos; alGetListener3f(AL_POSITION, &pos.x, &pos.y, &pos.z); return pos; };
|
||||
glm::vec3 listenerVel() { glm::vec3 vel; alGetListener3f(AL_VELOCITY, &vel.x, &vel.y, &vel.z); return vel; };
|
||||
glm::vec3 listenerOri() { glm::vec3 ori; alGetListener3f(AL_ORIENTATION, &ori.x, &ori.y, &ori.z); return ori; };
|
||||
void setSourcePos(ALuint source, glm::vec3 pos) { ALfloat spos[3] = { pos.x, pos.y, pos.z }; alSourcefv(source, AL_POSITION, spos); };
|
||||
void setSourceVel(ALuint source, glm::vec3 vel) { ALfloat svel[3] = { vel.x, vel.y, vel.z }; alSourcefv(source, AL_VELOCITY, svel); };
|
||||
|
||||
// Logic
|
||||
// Logic
|
||||
void initOpenAL();
|
||||
void updateEmitters();
|
||||
void updateListener();
|
||||
@@ -60,9 +63,9 @@ private:
|
||||
void playSound(Source* source);
|
||||
void stopSound(Source* source);
|
||||
void stopEmitters();
|
||||
bool isPlaying(ALuint source);
|
||||
ALenum getSourceState(ALuint source);
|
||||
void setGain(Source* source, float gain);
|
||||
void setSoundProperties(ALuint source, float gain, float pitch, bool loop, float maxDistance, float rollOffFactor, float referenceDistance);
|
||||
void setSoundProperties(ALuint source, ComponentWrapper* soundComponent);
|
||||
|
||||
// OpenAL system variables
|
||||
ALCdevice* m_ALCdevice = nullptr;
|
||||
@@ -72,25 +75,23 @@ private:
|
||||
World* m_World = nullptr;
|
||||
EventBroker* m_EventBroker = nullptr;
|
||||
std::unordered_map<EntityID, Source*> m_Sources;
|
||||
float m_BGMVolumeChannel = 1.f;
|
||||
float m_BGMVolumeChannel = 1.0f;
|
||||
float m_SFXVolumeChannel = 1.f;
|
||||
bool m_EditorEnabled = false;
|
||||
|
||||
// Events
|
||||
EventRelay<SoundSystem, Events::PlaySound> m_EPlaySound;
|
||||
bool OnPlaySound(const Events::PlaySound &e);
|
||||
EventRelay<SoundSystem, Events::PlaySoundOnEntity> m_EPlaySoundOnEntity;
|
||||
bool OnPlaySoundOnEntity(const Events::PlaySoundOnEntity &e);
|
||||
EventRelay<SoundSystem, Events::PlaySoundOnPosition> m_EPlaySoundOnPosition;
|
||||
bool OnPlaySoundOnPosition(const Events::PlaySoundOnPosition &e);
|
||||
EventRelay<SoundSystem, Events::PlayBackgroundMusic> m_EPlayBackgroundMusic;
|
||||
bool OnPlayBackgroundMusic(const Events::PlayBackgroundMusic &e);
|
||||
EventRelay<SoundSystem, Events::PauseSound> m_EPauseSound;
|
||||
bool OnPauseSound(const Events::PauseSound &e);
|
||||
EventRelay<SoundSystem, Events::StopSound> m_EStopSound;
|
||||
bool OnStopSound(const Events::StopSound &e);
|
||||
EventRelay<SoundSystem, Events::ContinueSound> m_EContinueSound;
|
||||
bool OnContinueSound(const Events::ContinueSound &e);
|
||||
EventRelay<SoundSystem, Events::PlayBackgroundMusic> m_EPlayBackgroundMusic;
|
||||
bool OnPlayBackgroundMusic(const Events::PlayBackgroundMusic &e);
|
||||
EventRelay<SoundSystem, Events::SetBGMGain> m_ESetBGMGain;
|
||||
bool OnSetBGMGain(const Events::SetBGMGain &e); // Not tested
|
||||
EventRelay<SoundSystem, Events::SetSFXGain> m_ESetSFXGain;
|
||||
|
||||
Reference in New Issue
Block a user