Merge pull request #1143 from AbigailBuccaneer/fix/1087-positional-sounds

Fix global sounds being positioned at camera
1008-fix
krzys_h 2018-05-07 20:43:03 +02:00 committed by GitHub
commit 05fe7431c4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 11 additions and 4 deletions

View File

@ -314,10 +314,15 @@ bool CALSound::SearchFreeBuffer(SoundType sound, int &channel, bool &alreadyLoad
int CALSound::Play(SoundType sound, float amplitude, float frequency, bool loop) int CALSound::Play(SoundType sound, float amplitude, float frequency, bool loop)
{ {
return Play(sound, m_eye, amplitude, frequency, loop); return Play(sound, Math::Vector{}, true, amplitude, frequency, loop);
} }
int CALSound::Play(SoundType sound, const Math::Vector &pos, float amplitude, float frequency, bool loop) int CALSound::Play(SoundType sound, const Math::Vector &pos, float amplitude, float frequency, bool loop)
{
return Play(sound, pos, false, amplitude, frequency, loop);
}
int CALSound::Play(SoundType sound, const Math::Vector &pos, bool relativeToListener, float amplitude, float frequency, bool loop)
{ {
if (!m_enabled) if (!m_enabled)
{ {
@ -347,7 +352,7 @@ int CALSound::Play(SoundType sound, const Math::Vector &pos, float amplitude, fl
CChannel* chn = m_channels[channel].get(); CChannel* chn = m_channels[channel].get();
chn->SetPosition(pos); chn->SetPosition(pos, relativeToListener);
chn->SetVolumeAtrib(1.0f); chn->SetVolumeAtrib(1.0f);
// setting initial values // setting initial values

View File

@ -116,6 +116,7 @@ public:
private: private:
void CleanUp(); void CleanUp();
int Play(SoundType sound, const Math::Vector &pos, bool relativeToListener, float amplitude, float frequency, bool loop);
int GetPriority(SoundType); int GetPriority(SoundType);
bool SearchFreeBuffer(SoundType sound, int &channel, bool &alreadyLoaded); bool SearchFreeBuffer(SoundType sound, int &channel, bool &alreadyLoaded);
bool CheckChannel(int &channel); bool CheckChannel(int &channel);

View File

@ -94,7 +94,7 @@ bool CChannel::Pause()
return true; return true;
} }
bool CChannel::SetPosition(const Math::Vector &pos) bool CChannel::SetPosition(const Math::Vector &pos, bool relativeToListener)
{ {
if (!m_ready || m_buffer == nullptr) if (!m_ready || m_buffer == nullptr)
{ {
@ -102,6 +102,7 @@ bool CChannel::SetPosition(const Math::Vector &pos)
} }
alSource3f(m_source, AL_POSITION, pos.x, pos.y, pos.z); alSource3f(m_source, AL_POSITION, pos.x, pos.y, pos.z);
alSourcei(m_source, AL_SOURCE_RELATIVE, relativeToListener);
if (CheckOpenALError()) if (CheckOpenALError())
{ {
GetLogger()->Debug("Could not set sound position. Code: %d\n", GetOpenALErrorCode()); GetLogger()->Debug("Could not set sound position. Code: %d\n", GetOpenALErrorCode());

View File

@ -59,7 +59,7 @@ public:
bool Pause(); bool Pause();
bool Stop(); bool Stop();
bool SetPosition(const Math::Vector &pos); bool SetPosition(const Math::Vector &pos, bool relativeToListener = false);
bool SetFrequency(float freq); bool SetFrequency(float freq);
float GetFrequency(); float GetFrequency();