Created a primitive SoundSystem. Can play a sound with 'P' button. Using resourcemanager. Not using the created components yet.

This commit is contained in:
stiffly
2016-01-07 15:22:46 +01:00
parent 49884d7e60
commit d8c4c6e5ff
15 changed files with 338 additions and 5 deletions
+62
View File
@@ -0,0 +1,62 @@
#ifndef SoundSystem_h__
#define SoundSystem_h__
#include <unordered_map>
#include "glm/common.hpp"
#include "OpenAL/al.h"
#include "OpenAL/alc.h"
#include "Core/World.h"
#include "Core/EventBroker.h"
#include "Sound/Sound.h"
#include "Sound/EPlaySound.h"
struct Source
{
Sound* SoundResource;
ALuint ALsource;
};
class SoundSystem
{
public:
SoundSystem() { }
SoundSystem(EventBroker* eventBroker);
~SoundSystem();
void Update() { } // Update emitters
private:
// Private setters and getters for working with glm
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) { alListener3f(AL_ORIENTATION, ori.x, ori.y, ori.z); };
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); };
void setSourceOri(ALuint source, glm::vec3 ori) { ALfloat sori[3] = { ori.x, ori.y, ori.z }; alSourcefv(source, AL_ORIENTATION, sori); };
// Logic
World* m_World;
EventBroker* m_EventBroker;
ALuint createSource();
void playSound(Source source);
void stopSound(Source source);
void stopEmitter(EntityID emitter);
// OpenAL system variables
ALCdevice* m_ALCdevice = nullptr;
ALCcontext* m_ALCcontext = nullptr;
// Logic
std::unordered_map<EntityID, Source> m_Sources;
// Events
EventRelay<SoundSystem, Events::PlaySound> m_EPlaySound;
bool OnPlaySound(const Events::PlaySound &e);
};
#endif