Link each Sound Source to a Buffer, even if OpenAL is not inited. This will help correct the SFX enable bug
git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/main/trunk@6244 178a84e3-b1eb-0310-8ba1-8eac791a3b58
This commit is contained in:
@@ -43,6 +43,10 @@ class SFXBase : public NoCopy
|
||||
{
|
||||
public:
|
||||
virtual ~SFXBase() {}
|
||||
|
||||
/** Late creation, if SFX was initially disabled */
|
||||
virtual bool init() = 0;
|
||||
|
||||
virtual void position(const Vec3 &position) = 0;
|
||||
virtual void setLoop(bool status) = 0;
|
||||
virtual void play() = 0;
|
||||
|
||||
@@ -258,18 +258,18 @@ void SFXManager::loadSingleSfx(const XMLNode* node,
|
||||
* call deleteSFX().
|
||||
* \param id Identifier of the sound effect to create.
|
||||
*/
|
||||
SFXBase* SFXManager::createSoundSource(const SFXBuffer& info,
|
||||
SFXBase* SFXManager::createSoundSource(SFXBuffer* buffer,
|
||||
const bool add_to_SFX_list)
|
||||
{
|
||||
bool positional = false;
|
||||
|
||||
if (race_manager->getNumLocalPlayers() < 2)
|
||||
{
|
||||
positional = info.isPositional();
|
||||
positional = buffer->isPositional();
|
||||
}
|
||||
|
||||
assert( alIsBuffer(info.getBuffer()) );
|
||||
SFXBase* sfx = new SFXOpenAL(info.getBuffer(), positional, info.getRolloff(), info.getGain());
|
||||
assert( alIsBuffer(buffer->getBuffer()) );
|
||||
SFXBase* sfx = new SFXOpenAL(buffer, positional, buffer->getRolloff(), buffer->getGain());
|
||||
|
||||
// debugging
|
||||
/*printf("newSfx(): id:%d buffer:%p, rolloff:%f, gain:%f %p\n", id, m_sfx_buffers[id], m_sfx_rolloff[id], m_sfx_gain[id], p);*/
|
||||
@@ -292,7 +292,7 @@ SFXBase* SFXManager::createSoundSource(const std::string &name,
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return createSoundSource( *(i->second), addToSFXList );
|
||||
return createSoundSource( i->second, addToSFXList );
|
||||
} // createSoundSource
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
|
||||
@@ -108,7 +108,7 @@ public:
|
||||
float rolloff,
|
||||
float gain);
|
||||
|
||||
SFXBase* createSoundSource(const SFXBuffer& info,
|
||||
SFXBase* createSoundSource(SFXBuffer* info,
|
||||
const bool addToSFXList=true);
|
||||
SFXBase* createSoundSource(const std::string &name,
|
||||
const bool addToSFXList=true);
|
||||
|
||||
@@ -34,7 +34,7 @@
|
||||
#include "config/user_config.hpp"
|
||||
#include "io/file_manager.hpp"
|
||||
|
||||
SFXOpenAL::SFXOpenAL(ALuint buffer, bool positional, float rolloff, float gain) : SFXBase()
|
||||
SFXOpenAL::SFXOpenAL(SFXBuffer* buffer, bool positional, float rolloff, float gain) : SFXBase()
|
||||
{
|
||||
m_soundBuffer = buffer;
|
||||
m_soundSource = 0;
|
||||
@@ -45,42 +45,51 @@ SFXOpenAL::SFXOpenAL(ALuint buffer, bool positional, float rolloff, float gain)
|
||||
// Don't initialise anything else if the sfx manager was not correctly
|
||||
// initialised. First of all the initialisation will not work, and it
|
||||
// will not be used anyway.
|
||||
if(sfx_manager->sfxAllowed())
|
||||
if (sfx_manager->sfxAllowed())
|
||||
{
|
||||
alGenSources(1, &m_soundSource );
|
||||
if (!SFXManager::checkError("generating a source")) return;
|
||||
|
||||
assert( alIsBuffer(m_soundBuffer) );
|
||||
assert( alIsSource(m_soundSource) );
|
||||
|
||||
//std::cout << "Setting a source with buffer " << m_soundBuffer << ", rolloff " << rolloff
|
||||
// << ", gain=" << m_defaultGain << ", positional=" << (positional ? "true" : "false") << std::endl;
|
||||
|
||||
alSourcei (m_soundSource, AL_BUFFER, m_soundBuffer);
|
||||
|
||||
if (!SFXManager::checkError("attaching the buffer to the source")) return;
|
||||
|
||||
alSource3f(m_soundSource, AL_POSITION, 0.0, 0.0, 0.0);
|
||||
alSource3f(m_soundSource, AL_VELOCITY, 0.0, 0.0, 0.0);
|
||||
alSource3f(m_soundSource, AL_DIRECTION, 0.0, 0.0, 0.0);
|
||||
alSourcef (m_soundSource, AL_ROLLOFF_FACTOR, rolloff );
|
||||
alSourcef (m_soundSource, AL_GAIN, m_defaultGain);
|
||||
|
||||
|
||||
if (positional) alSourcei (m_soundSource, AL_SOURCE_RELATIVE, AL_FALSE);
|
||||
else alSourcei (m_soundSource, AL_SOURCE_RELATIVE, AL_TRUE);
|
||||
|
||||
m_positional = positional;
|
||||
m_ok = SFXManager::checkError("setting up the source");
|
||||
init();
|
||||
}
|
||||
} // SFXOpenAL
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
SFXOpenAL::~SFXOpenAL()
|
||||
{
|
||||
alDeleteSources(1, &m_soundSource);
|
||||
} // ~SFXOpenAL
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
bool SFXOpenAL::init()
|
||||
{
|
||||
alGenSources(1, &m_soundSource );
|
||||
if (!SFXManager::checkError("generating a source")) return false;
|
||||
|
||||
assert( alIsBuffer(m_soundBuffer->getBuffer()) );
|
||||
assert( alIsSource(m_soundSource) );
|
||||
|
||||
//std::cout << "Setting a source with buffer " << m_soundBuffer << ", rolloff " << rolloff
|
||||
// << ", gain=" << m_defaultGain << ", positional=" << (positional ? "true" : "false") << std::endl;
|
||||
|
||||
alSourcei (m_soundSource, AL_BUFFER, m_soundBuffer->getBuffer());
|
||||
|
||||
if (!SFXManager::checkError("attaching the buffer to the source")) return false;
|
||||
|
||||
alSource3f(m_soundSource, AL_POSITION, 0.0, 0.0, 0.0);
|
||||
alSource3f(m_soundSource, AL_VELOCITY, 0.0, 0.0, 0.0);
|
||||
alSource3f(m_soundSource, AL_DIRECTION, 0.0, 0.0, 0.0);
|
||||
alSourcef (m_soundSource, AL_ROLLOFF_FACTOR, m_soundBuffer->getRolloff());
|
||||
alSourcef (m_soundSource, AL_GAIN, m_defaultGain);
|
||||
|
||||
|
||||
if (m_positional) alSourcei (m_soundSource, AL_SOURCE_RELATIVE, AL_FALSE);
|
||||
else alSourcei (m_soundSource, AL_SOURCE_RELATIVE, AL_TRUE);
|
||||
|
||||
m_ok = SFXManager::checkError("setting up the source");
|
||||
|
||||
return m_ok;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
/** Changes the pitch of a sound effect.
|
||||
* \param factor Speedup/slowdown between 0.5 and 2.0
|
||||
@@ -164,7 +173,15 @@ void SFXOpenAL::resume()
|
||||
*/
|
||||
void SFXOpenAL::play()
|
||||
{
|
||||
if(!m_ok) return;
|
||||
if (!sfx_manager->sfxAllowed()) return;
|
||||
if (!m_ok)
|
||||
{
|
||||
// lazily create OpenAL source when needed
|
||||
init();
|
||||
|
||||
// creation of OpenAL source failed, giving up
|
||||
if (!m_ok) return;
|
||||
}
|
||||
|
||||
alSourcePlay(m_soundSource);
|
||||
SFXManager::checkError("playing");
|
||||
|
||||
@@ -36,14 +36,18 @@
|
||||
class SFXOpenAL : public SFXBase
|
||||
{
|
||||
private:
|
||||
ALuint m_soundBuffer; // Buffers hold sound data.
|
||||
SFXBuffer* m_soundBuffer; // Buffers hold sound data.
|
||||
ALuint m_soundSource; // Sources are points emitting sound.
|
||||
bool m_ok;
|
||||
bool m_positional;
|
||||
float m_defaultGain;
|
||||
public:
|
||||
SFXOpenAL(ALuint buffer, bool positional, float rolloff, float gain);
|
||||
SFXOpenAL(SFXBuffer* buffer, bool positional, float rolloff, float gain);
|
||||
virtual ~SFXOpenAL();
|
||||
|
||||
/** Late creation, if SFX was initially disabled */
|
||||
virtual bool init();
|
||||
|
||||
virtual void play();
|
||||
virtual void setLoop(bool status);
|
||||
virtual void stop();
|
||||
|
||||
Reference in New Issue
Block a user