Sound channel volume not overriding individual volume for sounds.
This commit is contained in:
@@ -16,10 +16,13 @@ class Sound : public Resource
|
|||||||
public:
|
public:
|
||||||
ALuint Buffer() { return m_Buffer; };
|
ALuint Buffer() { return m_Buffer; };
|
||||||
std::string Path() { return m_Path; };
|
std::string Path() { return m_Path; };
|
||||||
|
float Gain() { return m_Gain; };
|
||||||
|
void SetGain(const float Gain) { m_Gain = Gain; };
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Sound(std::string path);
|
Sound(std::string path);
|
||||||
|
|
||||||
|
float m_Gain = 1;
|
||||||
ALuint m_Buffer;
|
ALuint m_Buffer;
|
||||||
std::string m_Path;
|
std::string m_Path;
|
||||||
|
|
||||||
|
|||||||
@@ -81,6 +81,7 @@ bool dd::Systems::SoundSystem::OnPlaySound(const dd::Events::PlaySound &event)
|
|||||||
ALuint source = CreateSource();
|
ALuint source = CreateSource();
|
||||||
ALuint buffer = sound->Buffer();
|
ALuint buffer = sound->Buffer();
|
||||||
alSourcei(source, AL_BUFFER, buffer);
|
alSourcei(source, AL_BUFFER, buffer);
|
||||||
|
sound->SetGain(event.Gain);
|
||||||
|
|
||||||
//Sound settings
|
//Sound settings
|
||||||
float relativeVolume = 1.f;
|
float relativeVolume = 1.f;
|
||||||
@@ -97,10 +98,9 @@ bool dd::Systems::SoundSystem::OnPlaySound(const dd::Events::PlaySound &event)
|
|||||||
relativeVolume = m_SFXMasterVolume;
|
relativeVolume = m_SFXMasterVolume;
|
||||||
}
|
}
|
||||||
|
|
||||||
alSourcef(source, AL_GAIN, (event.Gain * relativeVolume));
|
alSourcef(source, AL_GAIN, (sound->Gain() * relativeVolume));
|
||||||
alSourcef(source, AL_PITCH, event.Pitch);
|
alSourcef(source, AL_PITCH, event.Pitch);
|
||||||
|
|
||||||
|
|
||||||
//Play
|
//Play
|
||||||
alSourcePlay(source);
|
alSourcePlay(source);
|
||||||
return true;
|
return true;
|
||||||
@@ -133,13 +133,11 @@ bool dd::Systems::SoundSystem::OnStopSound(const dd::Events::StopSound &event)
|
|||||||
|
|
||||||
bool dd::Systems::SoundSystem::OnMasterVolume(const dd::Events::MasterVolume &event)
|
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) {
|
if (event.IsAmbient) {
|
||||||
m_BGMMasterVolume = event.Gain;
|
m_BGMMasterVolume = event.Gain;
|
||||||
for (auto& item : m_BGMSourcesToBuffers)
|
for (auto& item : m_BGMSourcesToBuffers)
|
||||||
{
|
{
|
||||||
alSourcef(item.first, AL_GAIN, event.Gain);
|
alSourcef(item.first, AL_GAIN, (item.second->Gain() * m_BGMMasterVolume));
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -147,7 +145,7 @@ bool dd::Systems::SoundSystem::OnMasterVolume(const dd::Events::MasterVolume &ev
|
|||||||
m_SFXMasterVolume = event.Gain;
|
m_SFXMasterVolume = event.Gain;
|
||||||
for (auto& item : m_SFXSourcesToBuffers)
|
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 true;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user