Merge branch 'master' of github.com:sippeangelo/Escape-the-Dawn

This commit is contained in:
2014-03-11 04:19:09 +01:00
3 changed files with 11 additions and 12 deletions
+3 -2
View File
@@ -72,9 +72,10 @@ void GameWorld::Initialize()
model->ModelFile = "ship.obj";
auto soundEmitter = AddComponent<Components::SoundEmitter>(ent, "SoundEmitter");
soundEmitter->Gain = 1;
soundEmitter->MaxDistance = 10;
soundEmitter->MaxDistance = FLT_MAX;
soundEmitter->ReferenceDistance = 10;
soundEmitter->Loop = true;
soundEmitter->ReferenceDistance = 0.1;
soundEmitter->Pitch = 1;
GetSystem<Systems::SoundSystem>("SoundSystem")->PlaySound(soundEmitter, "Sounds/hallelujah.wav");
+2 -3
View File
@@ -23,11 +23,10 @@ public:
void UpdateEntity(double dt, EntityID entity, EntityID parent) override;
void OnComponentCreated(std::string type, std::shared_ptr<Component> component) override;
void PlaySound(std::shared_ptr<Components::SoundEmitter> emitter, std::string fileName);
ALuint LoadFile(std::string fileName);
ALuint CreateSource();
private:
ALCcontext* context;
ALuint LoadFile(std::string fileName);
ALuint CreateSource();
//File-info
char type[4];
+4 -5
View File
@@ -1,14 +1,12 @@
#include "SoundSystem.h"
#include "World.h"
//#include <fstream>
Systems::SoundSystem::SoundSystem(World* world)
: System(world)
{
//initialize OpenAL
ALCdevice* Device = alcOpenDevice(NULL);
ALCcontext* context;
if(Device)
{
context = alcCreateContext(Device, NULL);
@@ -57,6 +55,7 @@ void Systems::SoundSystem::UpdateEntity(double dt, EntityID entity, EntityID par
if(soundEmitter != nullptr)
{
ALuint source = m_Source[soundEmitter.get()];
alSourcei(source, AL_GAIN, soundEmitter->Gain);
alSourcei(source, AL_MAX_DISTANCE, soundEmitter->MaxDistance);
alSourcei(source, AL_REFERENCE_DISTANCE, soundEmitter->ReferenceDistance);
alSourcef(source, AL_PITCH, soundEmitter->Pitch);
@@ -65,7 +64,7 @@ void Systems::SoundSystem::UpdateEntity(double dt, EntityID entity, EntityID par
glm::vec3 emitterPos = transformComponent->Position;
ALfloat sourcePos[3] = { emitterPos.x, emitterPos.y, -emitterPos.z };
glm::vec3 emitterVel= transformComponent->Position;
glm::vec3 emitterVel= transformComponent->Velocity;
ALfloat sourceVel[3] = { emitterVel.x, emitterVel.y, -emitterVel.z };
alSourcefv(source, AL_POSITION, sourcePos);
@@ -159,7 +158,7 @@ ALuint Systems::SoundSystem::LoadFile(std::string fileName)
ALuint buffer;
alGenBuffers(1, &buffer);
alBufferData(buffer, format, buf, dataSize, sampleRate);
//delete[] buf;
delete[] buf;
m_BufferCache[fileName] = buffer;
return buffer;