Added logic for mastervolume. And a coresponding event.
(sources need to be updated for it to be fully working)
This commit is contained in:
@@ -0,0 +1,27 @@
|
|||||||
|
//
|
||||||
|
// Created by Adam on 2015-09-24.
|
||||||
|
//
|
||||||
|
|
||||||
|
#ifndef EVENTS_EMASTERVOLUME_H__
|
||||||
|
#define EVENTS_EMASTERVOLUME_H__
|
||||||
|
|
||||||
|
#include "Core/EventBroker.h"
|
||||||
|
|
||||||
|
namespace dd
|
||||||
|
{
|
||||||
|
|
||||||
|
namespace Events
|
||||||
|
{
|
||||||
|
|
||||||
|
struct MasterVolume : public Event
|
||||||
|
{
|
||||||
|
float gain = 1;
|
||||||
|
//To determine what channel group to apply the change to.
|
||||||
|
bool isAmbient = false;
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
@@ -14,7 +14,7 @@ struct PlaySound : Event
|
|||||||
std::string path;
|
std::string path;
|
||||||
float volume = 1.f;
|
float volume = 1.f;
|
||||||
float pitch = 1.f;
|
float pitch = 1.f;
|
||||||
bool loop = false;
|
bool isAmbient = false;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,6 +10,7 @@
|
|||||||
#include "Sound.h"
|
#include "Sound.h"
|
||||||
#include "Sound/EPlaySound.h"
|
#include "Sound/EPlaySound.h"
|
||||||
#include "Sound/EStopSound.h"
|
#include "Sound/EStopSound.h"
|
||||||
|
#include "Sound/EMasterVolume.h"
|
||||||
#include "Physics/EContact.h"
|
#include "Physics/EContact.h"
|
||||||
#include "Game/CBall.h"
|
#include "Game/CBall.h"
|
||||||
#include "Game/CBrick.h"
|
#include "Game/CBrick.h"
|
||||||
@@ -38,9 +39,11 @@ private:
|
|||||||
dd::EventRelay<SoundSystem, dd::Events::PlaySound> m_EPlaySFX;
|
dd::EventRelay<SoundSystem, dd::Events::PlaySound> m_EPlaySFX;
|
||||||
dd::EventRelay<SoundSystem, dd::Events::Contact> m_EContact;
|
dd::EventRelay<SoundSystem, dd::Events::Contact> m_EContact;
|
||||||
dd::EventRelay<SoundSystem, dd::Events::StopSound> m_EStopSound;
|
dd::EventRelay<SoundSystem, dd::Events::StopSound> m_EStopSound;
|
||||||
|
dd::EventRelay<SoundSystem, dd::Events::MasterVolume> m_EMasterVolume;
|
||||||
bool OnPlaySound(const dd::Events::PlaySound &event);
|
bool OnPlaySound(const dd::Events::PlaySound &event);
|
||||||
bool OnContact(const dd::Events::Contact &event);
|
bool OnContact(const dd::Events::Contact &event);
|
||||||
bool OnStopSound(const dd::Events::StopSound &event);
|
bool OnStopSound(const dd::Events::StopSound &event);
|
||||||
|
bool OnMasterVolume(const dd::Events::MasterVolume &event);
|
||||||
|
|
||||||
ALuint CreateSource();
|
ALuint CreateSource();
|
||||||
|
|
||||||
@@ -48,7 +51,7 @@ private:
|
|||||||
|
|
||||||
ALCdevice* m_Device;
|
ALCdevice* m_Device;
|
||||||
|
|
||||||
//Temp
|
float m_BGMMasterVolume, m_SFXMasterVolume;
|
||||||
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -22,34 +22,45 @@ void dd::Systems::SoundSystem::Initialize()
|
|||||||
|
|
||||||
alGetError();
|
alGetError();
|
||||||
|
|
||||||
|
//Probably unnecessary. vec3(0) probably default.
|
||||||
const ALfloat pos[3] = {0, 0, 0};
|
const ALfloat pos[3] = {0, 0, 0};
|
||||||
alListenerfv(AL_POSITION, pos);
|
//alListenerfv(AL_POSITION, pos);
|
||||||
|
|
||||||
|
m_SFXMasterVolume = 1.f;
|
||||||
|
m_BGMMasterVolume = 1.f;
|
||||||
|
|
||||||
//Subscribe to events
|
//Subscribe to events
|
||||||
EVENT_SUBSCRIBE_MEMBER(m_EContact, &SoundSystem::OnContact);
|
EVENT_SUBSCRIBE_MEMBER(m_EContact, &SoundSystem::OnContact);
|
||||||
EVENT_SUBSCRIBE_MEMBER(m_EPlaySFX, &SoundSystem::OnPlaySound);
|
EVENT_SUBSCRIBE_MEMBER(m_EPlaySFX, &SoundSystem::OnPlaySound);
|
||||||
EVENT_SUBSCRIBE_MEMBER(m_EStopSound, &SoundSystem::OnStopSound);
|
EVENT_SUBSCRIBE_MEMBER(m_EStopSound, &SoundSystem::OnStopSound);
|
||||||
|
EVENT_SUBSCRIBE_MEMBER(m_EMasterVolume, &SoundSystem::OnMasterVolume);
|
||||||
|
|
||||||
|
|
||||||
//Todo: Move this
|
//Todo: Move this
|
||||||
{
|
{
|
||||||
dd::Events::PlaySound e;
|
dd::Events::PlaySound e;
|
||||||
e.path = "Sounds/BGM/soft-guitar.wav";
|
e.path = "Sounds/BGM/under-the-sea-instrumental.wav";
|
||||||
e.loop = true;
|
e.isAmbient = true;
|
||||||
EventBroker->Publish(e);
|
EventBroker->Publish(e);
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
dd::Events::PlaySound e;
|
dd::Events::PlaySound e;
|
||||||
e.path = "Sounds/BGM/water-flowing.wav";
|
e.path = "Sounds/BGM/water-flowing.wav";
|
||||||
e.volume = 0.3f;
|
e.volume = 0.3f;
|
||||||
e.loop = true;
|
e.isAmbient = true;
|
||||||
|
EventBroker->Publish(e);
|
||||||
|
}
|
||||||
|
{
|
||||||
|
dd::Events::MasterVolume e;
|
||||||
|
e.isAmbient = true;
|
||||||
|
e.gain = 0.001f;
|
||||||
EventBroker->Publish(e);
|
EventBroker->Publish(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void dd::Systems::SoundSystem::Update(double dt)
|
void dd::Systems::SoundSystem::Update(double dt)
|
||||||
{
|
{
|
||||||
//LOG_INFO("Sources : %i", m_SourcesToBuffers.size());
|
//Clean up none-active sources
|
||||||
|
|
||||||
std::vector<ALuint> deleteList;
|
std::vector<ALuint> deleteList;
|
||||||
for (auto item : m_SourcesToBuffers) {
|
for (auto item : m_SourcesToBuffers) {
|
||||||
ALint sourceState;
|
ALint sourceState;
|
||||||
@@ -64,7 +75,6 @@ void dd::Systems::SoundSystem::Update(double dt)
|
|||||||
//alDeleteBuffers(1, &m_SourcesToBuffers[deleteList[i]]);
|
//alDeleteBuffers(1, &m_SourcesToBuffers[deleteList[i]]);
|
||||||
m_SourcesToBuffers.erase(deleteList[i]);
|
m_SourcesToBuffers.erase(deleteList[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ALuint dd::Systems::SoundSystem::CreateSource()
|
ALuint dd::Systems::SoundSystem::CreateSource()
|
||||||
@@ -88,16 +98,20 @@ bool dd::Systems::SoundSystem::OnPlaySound(const dd::Events::PlaySound &event)
|
|||||||
alSourcei(source, AL_BUFFER, buffer);
|
alSourcei(source, AL_BUFFER, buffer);
|
||||||
|
|
||||||
//Sound settings
|
//Sound settings
|
||||||
alSourcef(source, AL_GAIN, event.volume);
|
float relativeVolume = 1.f;
|
||||||
alSourcef(source, AL_PITCH, event.pitch);
|
if (event.isAmbient) {
|
||||||
if (event.loop) {
|
|
||||||
alSourcei(source, AL_LOOPING, AL_TRUE);
|
alSourcei(source, AL_LOOPING, AL_TRUE);
|
||||||
|
relativeVolume = m_BGMMasterVolume;
|
||||||
}
|
}
|
||||||
else if (!event.loop)
|
else if (!event.isAmbient)
|
||||||
{
|
{
|
||||||
alSourcei(source, AL_LOOPING, AL_FALSE);
|
alSourcei(source, AL_LOOPING, AL_FALSE);
|
||||||
|
relativeVolume = m_SFXMasterVolume;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
alSourcef(source, AL_GAIN, (event.volume * relativeVolume));
|
||||||
|
alSourcef(source, AL_PITCH, event.pitch);
|
||||||
|
|
||||||
|
|
||||||
//Play
|
//Play
|
||||||
alSourcePlay(source);
|
alSourcePlay(source);
|
||||||
@@ -115,6 +129,18 @@ bool dd::Systems::SoundSystem::OnStopSound(const dd::Events::StopSound &event)
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool dd::Systems::SoundSystem::OnMasterVolume(const dd::Events::MasterVolume &event)
|
||||||
|
{
|
||||||
|
if (event.isAmbient) {
|
||||||
|
m_BGMMasterVolume = event.gain;
|
||||||
|
}
|
||||||
|
else if (!event.isAmbient) {
|
||||||
|
m_SFXMasterVolume = event.gain;
|
||||||
|
}
|
||||||
|
m_World->GetEntities();
|
||||||
|
}
|
||||||
|
|
||||||
|
//On contact: play the sound given in the CCOllisionSound.
|
||||||
bool dd::Systems::SoundSystem::OnContact(const dd::Events::Contact &event)
|
bool dd::Systems::SoundSystem::OnContact(const dd::Events::Contact &event)
|
||||||
{
|
{
|
||||||
//Check which entity has the collisionSound component.
|
//Check which entity has the collisionSound component.
|
||||||
@@ -127,16 +153,12 @@ bool dd::Systems::SoundSystem::OnContact(const dd::Events::Contact &event)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
|
||||||
//dd::Events::StopSound e;
|
|
||||||
//e.path = "Sounds/BGM/soft-guitar.wav";
|
|
||||||
//EventBroker->Publish(e);
|
|
||||||
}
|
|
||||||
//Send play-sound event
|
//Send play-sound event
|
||||||
dd::Events::PlaySound e;
|
dd::Events::PlaySound e;
|
||||||
e.path = collisionSound->filePath;
|
e.path = collisionSound->filePath;
|
||||||
|
e.isAmbient = false;
|
||||||
EventBroker->Publish(e);
|
EventBroker->Publish(e);
|
||||||
return true;
|
//return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user