Started implementation of events for InputSystem and SoundSystem

This commit is contained in:
2014-04-28 19:55:31 +02:00
parent 5870a4d7bf
commit 57d29d0db7
25 changed files with 201 additions and 71 deletions
+17 -2
View File
@@ -2,8 +2,7 @@
#include "SoundSystem.h"
#include "World.h"
Systems::SoundSystem::SoundSystem(World* world)
: System(world)
void Systems::SoundSystem::Initialize()
{
//initialize OpenAL
ALCdevice* Device = alcOpenDevice(NULL);
@@ -22,6 +21,10 @@ Systems::SoundSystem::SoundSystem(World* world)
alSpeedOfSound(340.29f); // Speed of sound
alDistanceModel(AL_INVERSE_DISTANCE_CLAMPED);
// Subscribe to events
m_EPlaySound = decltype(m_EPlaySound)(std::bind(&Systems::SoundSystem::OnPlaySound, this, std::placeholders::_1));
EventBroker->Subscribe(m_EPlaySound);
}
void Systems::SoundSystem::RegisterComponents(ComponentFactory* cf)
@@ -143,3 +146,15 @@ ALuint Systems::SoundSystem::CreateSource()
return source;
}
bool Systems::SoundSystem::OnPlaySound(const Events::PlaySound &event)
{
LOG_DEBUG("Events::PlaySound.Resource = %s", event.Resource.c_str());
ALuint buffer = *m_World->GetResourceManager()->Load<Sound>("Sound", event.Resource);
ALuint source = m_Sources.begin()->second;
alSourcei(source, AL_BUFFER, buffer);
alSourcePlay(source);
return true;
}