Merge branch 'master' of github.com:sippeangelo/Escape-the-Dawn
This commit is contained in:
@@ -72,9 +72,10 @@ void GameWorld::Initialize()
|
|||||||
model->ModelFile = "ship.obj";
|
model->ModelFile = "ship.obj";
|
||||||
auto soundEmitter = AddComponent<Components::SoundEmitter>(ent, "SoundEmitter");
|
auto soundEmitter = AddComponent<Components::SoundEmitter>(ent, "SoundEmitter");
|
||||||
soundEmitter->Gain = 1;
|
soundEmitter->Gain = 1;
|
||||||
soundEmitter->MaxDistance = 10;
|
soundEmitter->MaxDistance = FLT_MAX;
|
||||||
|
soundEmitter->ReferenceDistance = 10;
|
||||||
soundEmitter->Loop = true;
|
soundEmitter->Loop = true;
|
||||||
soundEmitter->ReferenceDistance = 0.1;
|
|
||||||
soundEmitter->Pitch = 1;
|
soundEmitter->Pitch = 1;
|
||||||
GetSystem<Systems::SoundSystem>("SoundSystem")->PlaySound(soundEmitter, "Sounds/hallelujah.wav");
|
GetSystem<Systems::SoundSystem>("SoundSystem")->PlaySound(soundEmitter, "Sounds/hallelujah.wav");
|
||||||
|
|
||||||
|
|||||||
@@ -23,11 +23,10 @@ public:
|
|||||||
void UpdateEntity(double dt, EntityID entity, EntityID parent) override;
|
void UpdateEntity(double dt, EntityID entity, EntityID parent) override;
|
||||||
void OnComponentCreated(std::string type, std::shared_ptr<Component> component) override;
|
void OnComponentCreated(std::string type, std::shared_ptr<Component> component) override;
|
||||||
void PlaySound(std::shared_ptr<Components::SoundEmitter> emitter, std::string fileName);
|
void PlaySound(std::shared_ptr<Components::SoundEmitter> emitter, std::string fileName);
|
||||||
ALuint LoadFile(std::string fileName);
|
|
||||||
ALuint CreateSource();
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
ALCcontext* context;
|
ALuint LoadFile(std::string fileName);
|
||||||
|
ALuint CreateSource();
|
||||||
|
|
||||||
//File-info
|
//File-info
|
||||||
char type[4];
|
char type[4];
|
||||||
@@ -37,7 +36,7 @@ private:
|
|||||||
short bytesPerSample, bitsPerSample;
|
short bytesPerSample, bitsPerSample;
|
||||||
DWORD dataSize;
|
DWORD dataSize;
|
||||||
|
|
||||||
|
|
||||||
std::map<Component*, ALuint> m_Source;
|
std::map<Component*, ALuint> m_Source;
|
||||||
std::map<std::string, ALuint> m_BufferCache; // string = fileName
|
std::map<std::string, ALuint> m_BufferCache; // string = fileName
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,14 +1,12 @@
|
|||||||
#include "SoundSystem.h"
|
#include "SoundSystem.h"
|
||||||
#include "World.h"
|
#include "World.h"
|
||||||
//#include <fstream>
|
|
||||||
|
|
||||||
|
|
||||||
Systems::SoundSystem::SoundSystem(World* world)
|
Systems::SoundSystem::SoundSystem(World* world)
|
||||||
: System(world)
|
: System(world)
|
||||||
{
|
{
|
||||||
//initialize OpenAL
|
//initialize OpenAL
|
||||||
ALCdevice* Device = alcOpenDevice(NULL);
|
ALCdevice* Device = alcOpenDevice(NULL);
|
||||||
|
ALCcontext* context;
|
||||||
if(Device)
|
if(Device)
|
||||||
{
|
{
|
||||||
context = alcCreateContext(Device, NULL);
|
context = alcCreateContext(Device, NULL);
|
||||||
@@ -24,7 +22,7 @@ Systems::SoundSystem::SoundSystem(World* world)
|
|||||||
|
|
||||||
void Systems::SoundSystem::Update(double dt)
|
void Systems::SoundSystem::Update(double dt)
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Systems::SoundSystem::UpdateEntity(double dt, EntityID entity, EntityID parent)
|
void Systems::SoundSystem::UpdateEntity(double dt, EntityID entity, EntityID parent)
|
||||||
@@ -57,6 +55,7 @@ void Systems::SoundSystem::UpdateEntity(double dt, EntityID entity, EntityID par
|
|||||||
if(soundEmitter != nullptr)
|
if(soundEmitter != nullptr)
|
||||||
{
|
{
|
||||||
ALuint source = m_Source[soundEmitter.get()];
|
ALuint source = m_Source[soundEmitter.get()];
|
||||||
|
alSourcei(source, AL_GAIN, soundEmitter->Gain);
|
||||||
alSourcei(source, AL_MAX_DISTANCE, soundEmitter->MaxDistance);
|
alSourcei(source, AL_MAX_DISTANCE, soundEmitter->MaxDistance);
|
||||||
alSourcei(source, AL_REFERENCE_DISTANCE, soundEmitter->ReferenceDistance);
|
alSourcei(source, AL_REFERENCE_DISTANCE, soundEmitter->ReferenceDistance);
|
||||||
alSourcef(source, AL_PITCH, soundEmitter->Pitch);
|
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;
|
glm::vec3 emitterPos = transformComponent->Position;
|
||||||
ALfloat sourcePos[3] = { emitterPos.x, emitterPos.y, -emitterPos.z };
|
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 };
|
ALfloat sourceVel[3] = { emitterVel.x, emitterVel.y, -emitterVel.z };
|
||||||
|
|
||||||
alSourcefv(source, AL_POSITION, sourcePos);
|
alSourcefv(source, AL_POSITION, sourcePos);
|
||||||
@@ -159,7 +158,7 @@ ALuint Systems::SoundSystem::LoadFile(std::string fileName)
|
|||||||
ALuint buffer;
|
ALuint buffer;
|
||||||
alGenBuffers(1, &buffer);
|
alGenBuffers(1, &buffer);
|
||||||
alBufferData(buffer, format, buf, dataSize, sampleRate);
|
alBufferData(buffer, format, buf, dataSize, sampleRate);
|
||||||
//delete[] buf;
|
delete[] buf;
|
||||||
|
|
||||||
m_BufferCache[fileName] = buffer;
|
m_BufferCache[fileName] = buffer;
|
||||||
return buffer;
|
return buffer;
|
||||||
|
|||||||
Reference in New Issue
Block a user