Merge branch 'master' of github.com:teamfisk/AgileBreakOut

This commit is contained in:
2015-10-01 10:55:04 +02:00
12 changed files with 281 additions and 111 deletions
+3 -3
View File
@@ -263,7 +263,7 @@ void dd::OBJ::ParseMaterial()
ParseColorMap(currentLine, ss, prefix, arg, colorMap);
}
// HACK: Should we really have to specify the full path here?
// HACK: Should we really have to specify the full FilePath here?
colorMap.FileName = (m_MaterialPath.branch_path() / colorMap.FileName).string();
currentMaterial->DiffuseTexture = colorMap;
continue;
@@ -280,7 +280,7 @@ void dd::OBJ::ParseMaterial()
ParseColorMap(currentLine, ss, prefix, arg, colorMap);
}
// HACK: Should we really have to specify the full path here?
// HACK: Should we really have to specify the full FilePath here?
colorMap.FileName = (m_MaterialPath.branch_path() / colorMap.FileName).string();
currentMaterial->SpecularMap = colorMap;
continue;
@@ -297,7 +297,7 @@ void dd::OBJ::ParseMaterial()
ParseBumpMap(currentLine, ss, prefix, arg, bumpMap);
}
// HACK: Should we really have to specify the full path here?
// HACK: Should we really have to specify the full FilePath here?
bumpMap.FileName = (m_MaterialPath.branch_path() / bumpMap.FileName).string();
currentMaterial->NormalMap = bumpMap;
continue;
+1 -1
View File
@@ -195,7 +195,7 @@ void dd::Systems::LevelSystem::CreateBrick(int row, int line, glm::vec2 spacesBe
//sound
auto collisionSound = m_World->AddComponent<Components::CollisionSound>(brick);
collisionSound->filePath = "Sounds/Brick/shortbrickbreak.wav";
collisionSound->FilePath = "Sounds/Brick/shortbrickbreak.wav";
m_World->CommitEntity(brick);
return;
+46 -44
View File
@@ -4,7 +4,7 @@
dd::Systems::SoundSystem::~SoundSystem()
{
alcCloseDevice(m_Device);
}
};
void dd::Systems::SoundSystem::Initialize()
{
@@ -19,24 +19,28 @@ void dd::Systems::SoundSystem::Initialize()
else {
LOG_ERROR("OpenAL failed to initialize.");
}
alGetError();
//Probably unnecessary. vec3(0) probably default.
const ALfloat pos[3] = {0, 0, 0};
//alListenerfv(AL_POSITION, pos);
m_SFXMasterVolume = 1.f;
m_BGMMasterVolume = 1.f;
//Subscribe to events
EVENT_SUBSCRIBE_MEMBER(m_EContact, &SoundSystem::OnContact);
EVENT_SUBSCRIBE_MEMBER(m_EPlaySFX, &SoundSystem::OnPlaySound);
EVENT_SUBSCRIBE_MEMBER(m_EStopSound, &SoundSystem::OnStopSound);
EVENT_SUBSCRIBE_MEMBER(m_EMasterVolume, &SoundSystem::OnMasterVolume);
//Todo: Move this
{
dd::Events::PlaySound e;
e.FilePath = "Sounds/BGM/under-the-sea-instrumental.wav";
e.IsAmbient = true;
EventBroker->Publish(e);
}
{
dd::Events::PlaySound e;
e.FilePath = "Sounds/BGM/water-flowing.wav";
e.Gain = 0.3f;
e.IsAmbient = true;
EventBroker->Publish(e);
}
}
void dd::Systems::SoundSystem::Update(double dt)
@@ -44,7 +48,7 @@ void dd::Systems::SoundSystem::Update(double dt)
//Clean up none-active sources
//Only used for SFX's. BGM's are handled on stop sound.
std::vector<ALuint> deleteList;
for (auto item : m_SFXSourcesToBuffers) {
for (auto& item : m_SFXSourcesToBuffers) {
ALint sourceState;
alGetSourcei(item.first, AL_SOURCE_STATE, &sourceState);
if (sourceState == AL_STOPPED) {
@@ -70,32 +74,32 @@ ALuint dd::Systems::SoundSystem::CreateSource()
bool dd::Systems::SoundSystem::OnPlaySound(const dd::Events::PlaySound &event)
{
//Loading and binding sound buffer to source
Sound *sound = ResourceManager::Load<Sound>(event.path);
Sound *sound = ResourceManager::Load<Sound>(event.FilePath);
if (sound == nullptr) {
return false;
}
ALuint source = CreateSource();
ALuint buffer = sound->Buffer();
alSourcei(source, AL_BUFFER, buffer);
sound->SetGain(event.Gain);
//Sound settings
float relativeVolume = 1.f;
if (event.isAmbient) {
if (event.IsAmbient) {
alSourcei(source, AL_LOOPING, AL_TRUE);
relativeVolume = m_BGMMasterVolume;
m_BGMSourcesToBuffers[source] = sound;
}
else if (!event.isAmbient)
else if (!event.IsAmbient)
{
m_SFXSourcesToBuffers[source] = sound;
alSourcei(source, AL_LOOPING, AL_FALSE);
relativeVolume = m_SFXMasterVolume;
}
alSourcef(source, AL_GAIN, (event.volume * relativeVolume));
alSourcef(source, AL_PITCH, event.pitch);
alSourcef(source, AL_GAIN, (sound->Gain() * relativeVolume));
alSourcef(source, AL_PITCH, event.Pitch);
//Play
alSourcePlay(source);
@@ -104,53 +108,50 @@ bool dd::Systems::SoundSystem::OnPlaySound(const dd::Events::PlaySound &event)
bool dd::Systems::SoundSystem::OnStopSound(const dd::Events::StopSound &event)
{
//TODO: Delete sources for bgms
ALuint itemToDelete;
for (auto item : m_BGMSourcesToBuffers)
ALuint itemToDeleted;
for (auto& item : m_BGMSourcesToBuffers)
{
if (item.second->Path() == event.path) {
itemToDelete = item.first;
if (item.second->Path() == event.FilePath) {
itemToDeleted = item.first;
break;
}
}
alSourceStop(itemToDelete);
alDeleteSources(1, &itemToDelete);
m_BGMSourcesToBuffers.erase(itemToDelete);
alSourceStop(itemToDeleted);
alDeleteSources(1, &itemToDeleted);
m_BGMSourcesToBuffers.erase(itemToDeleted);
//Should not because SFX's should be very short.
//Should not happen because SFX's should be very short.
for (auto item : m_SFXSourcesToBuffers)
{
if (item.second->Path() == event.path) {
if (item.second->Path() == event.FilePath) {
alSourceStop(item.first);
return true;
}
}
return false;
}
bool dd::Systems::SoundSystem::OnMasterVolume(const dd::Events::MasterVolume &event)
{
//TODO: Make the volume depend on the value given when stored.
//TODO: .. now it ONLY uses the master volume
if (event.isAmbient) {
m_BGMMasterVolume = event.gain;
for (auto item : m_BGMSourcesToBuffers)
if (event.IsAmbient) {
m_BGMMasterVolume = event.Gain;
for (auto& item : m_BGMSourcesToBuffers)
{
alSourcef(item.first, AL_GAIN, event.gain);
alSourcef(item.first, AL_GAIN, (item.second->Gain() * m_BGMMasterVolume));
}
return true;
}
else if (!event.isAmbient) {
m_SFXMasterVolume = event.gain;
for (auto item : m_SFXSourcesToBuffers)
else if (!event.IsAmbient) {
m_SFXMasterVolume = event.Gain;
for (auto& item : m_SFXSourcesToBuffers)
{
alSourcef(item.first, AL_GAIN, event.gain);
alSourcef(item.first, AL_GAIN, (item.second->Gain() * m_SFXMasterVolume));
}
return true;
}
return false;
}
//On contact: play the sound given in the CCOllisionSound.
bool dd::Systems::SoundSystem::OnContact(const dd::Events::Contact &event)
{
//Check which entity has the collisionSound component.
@@ -165,10 +166,11 @@ bool dd::Systems::SoundSystem::OnContact(const dd::Events::Contact &event)
//Send play-sound event
dd::Events::PlaySound e;
e.path = collisionSound->filePath;
e.isAmbient = false;
e.FilePath = collisionSound->FilePath;
e.IsAmbient = false;
EventBroker->Publish(e);
//return true;
return true;
}
+183
View File
@@ -0,0 +1,183 @@
#include "PrecompiledHeader.h"
#include "Sound/SoundSystem.h"
dd::Systems::SoundSystem::~SoundSystem()
{
alcCloseDevice(m_Device);
};
void dd::Systems::SoundSystem::Initialize()
{
//initialize OpenAL
m_Device = alcOpenDevice(NULL);
ALCcontext* context;
if (m_Device) {
context = alcCreateContext(m_Device, NULL);
alcMakeContextCurrent(context);
}
else {
LOG_ERROR("OpenAL failed to initialize.");
}
alGetError();
//Subscribe to events
EVENT_SUBSCRIBE_MEMBER(m_EContact, &SoundSystem::OnContact);
EVENT_SUBSCRIBE_MEMBER(m_EPlaySFX, &SoundSystem::OnPlaySound);
EVENT_SUBSCRIBE_MEMBER(m_EStopSound, &SoundSystem::OnStopSound);
EVENT_SUBSCRIBE_MEMBER(m_EMasterVolume, &SoundSystem::OnMasterVolume);
<<<<<<< HEAD
//Todo: Move this
{
dd::Events::PlaySound e;
e.FilePath = "Sounds/BGM/under-the-sea-instrumental.wav";
e.IsAmbient = true;
EventBroker->Publish(e);
}
{
dd::Events::PlaySound e;
e.FilePath = "Sounds/BGM/water-flowing.wav";
e.Gain = 0.3f;
e.IsAmbient = true;
EventBroker->Publish(e);
}
=======
>>>>>>> origin/master
}
void dd::Systems::SoundSystem::Update(double dt)
{
//Clean up none-active sources
//Only used for SFX's. BGM's are handled on stop sound.
std::vector<ALuint> deleteList;
for (auto& item : m_SFXSourcesToBuffers) {
ALint sourceState;
alGetSourcei(item.first, AL_SOURCE_STATE, &sourceState);
if (sourceState == AL_STOPPED) {
deleteList.push_back(item.first);
}
}
for (int i = 0; i < deleteList.size(); i++) {
alDeleteSources(1, &deleteList[i]);
//alDeleteBuffers(1, &m_SourcesToBuffers[deleteList[i]]);
m_SFXSourcesToBuffers.erase(deleteList[i]);
}
}
ALuint dd::Systems::SoundSystem::CreateSource()
{
ALuint source;
alGenSources((ALuint)1, &source);
return source;
}
bool dd::Systems::SoundSystem::OnPlaySound(const dd::Events::PlaySound &event)
{
//Loading and binding sound buffer to source
Sound *sound = ResourceManager::Load<Sound>(event.FilePath);
if (sound == nullptr) {
return false;
}
ALuint source = CreateSource();
ALuint buffer = sound->Buffer();
alSourcei(source, AL_BUFFER, buffer);
//Sound settings
float relativeVolume = 1.f;
if (event.IsAmbient) {
alSourcei(source, AL_LOOPING, AL_TRUE);
relativeVolume = m_BGMMasterVolume;
m_BGMSourcesToBuffers[source] = sound;
}
else if (!event.IsAmbient)
{
m_SFXSourcesToBuffers[source] = sound;
alSourcei(source, AL_LOOPING, AL_FALSE);
relativeVolume = m_SFXMasterVolume;
}
alSourcef(source, AL_GAIN, (event.Gain * relativeVolume));
alSourcef(source, AL_PITCH, event.Pitch);
//Play
alSourcePlay(source);
return true;
}
bool dd::Systems::SoundSystem::OnStopSound(const dd::Events::StopSound &event)
{
ALuint itemToDeleted;
for (auto& item : m_BGMSourcesToBuffers)
{
if (item.second->Path() == event.FilePath) {
itemToDeleted = item.first;
break;
}
}
alSourceStop(itemToDeleted);
alDeleteSources(1, &itemToDeleted);
m_BGMSourcesToBuffers.erase(itemToDeleted);
//Should not happen because SFX's should be very short.
for (auto item : m_SFXSourcesToBuffers)
{
if (item.second->Path() == event.FilePath) {
alSourceStop(item.first);
return true;
}
}
return false;
}
bool dd::Systems::SoundSystem::OnMasterVolume(const dd::Events::MasterVolume &event)
{
//TODO: Make the Gain depend on the value given when stored.
//TODO: .. now it ONLY uses the master Gain
if (event.IsAmbient) {
m_BGMMasterVolume = event.Gain;
for (auto& item : m_BGMSourcesToBuffers)
{
alSourcef(item.first, AL_GAIN, event.Gain);
}
return true;
}
else if (!event.IsAmbient) {
m_SFXMasterVolume = event.Gain;
for (auto& item : m_SFXSourcesToBuffers)
{
alSourcef(item.first, AL_GAIN, event.Gain);
}
return true;
}
return false;
}
bool dd::Systems::SoundSystem::OnContact(const dd::Events::Contact &event)
{
//Check which entity has the collisionSound component.
auto collisionSound = m_World->GetComponent<Components::CollisionSound>(event.Entity1);
if (collisionSound == nullptr) {
collisionSound = m_World->GetComponent<Components::CollisionSound>(event.Entity2);
if (collisionSound == nullptr) {
//None of the entities had a collisionSound component.
return false;
}
}
//Send play-sound event
dd::Events::PlaySound e;
e.FilePath = collisionSound->FilePath;
e.IsAmbient = false;
EventBroker->Publish(e);
return true;
}