Merge remote-tracking branch 'upstream/master'
This commit is contained in:
commit
26b286ab9c
@ -40,9 +40,14 @@ public:
|
|||||||
virtual void position(const Vec3 &position) {}
|
virtual void position(const Vec3 &position) {}
|
||||||
virtual void setLoop(bool status) {}
|
virtual void setLoop(bool status) {}
|
||||||
virtual void play() {}
|
virtual void play() {}
|
||||||
|
virtual void reallyPlayNow() {}
|
||||||
virtual void stop() {}
|
virtual void stop() {}
|
||||||
|
virtual void reallyStopNow() {}
|
||||||
virtual void pause() {}
|
virtual void pause() {}
|
||||||
|
virtual void reallyPauseNow() {}
|
||||||
virtual void resume() {}
|
virtual void resume() {}
|
||||||
|
virtual void reallyResumeNow() {}
|
||||||
|
virtual void deleteSFX() { delete this; }
|
||||||
virtual void speed(float factor) {}
|
virtual void speed(float factor) {}
|
||||||
virtual void volume(float gain) {}
|
virtual void volume(float gain) {}
|
||||||
virtual SFXManager::SFXStatus getStatus() { return SFXManager::SFX_STOPPED; }
|
virtual SFXManager::SFXStatus getStatus() { return SFXManager::SFX_STOPPED; }
|
||||||
|
@ -52,8 +52,12 @@ public:
|
|||||||
virtual void play() = 0;
|
virtual void play() = 0;
|
||||||
virtual void reallyPlayNow() = 0;
|
virtual void reallyPlayNow() = 0;
|
||||||
virtual void stop() = 0;
|
virtual void stop() = 0;
|
||||||
|
virtual void reallyStopNow() = 0;
|
||||||
virtual void pause() = 0;
|
virtual void pause() = 0;
|
||||||
|
virtual void reallyPauseNow() = 0;
|
||||||
virtual void resume() = 0;
|
virtual void resume() = 0;
|
||||||
|
virtual void reallyResumeNow() = 0;
|
||||||
|
virtual void deleteSFX() = 0;
|
||||||
virtual void speed(float factor) = 0;
|
virtual void speed(float factor) = 0;
|
||||||
virtual void volume(float gain) = 0;
|
virtual void volume(float gain) = 0;
|
||||||
virtual void setMasterVolume(float gain) = 0;
|
virtual void setMasterVolume(float gain) = 0;
|
||||||
|
@ -36,27 +36,37 @@
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
//----------------------------------------------------------------------------
|
//----------------------------------------------------------------------------
|
||||||
|
/** Creates a sfx. The parameter are taken from the parameters:
|
||||||
|
* \param file File name of the buffer.
|
||||||
|
* \param positional If the sfx is positional.
|
||||||
|
* \param rolloff Rolloff value of this sfx.
|
||||||
|
* \param max_dist Maximum distance the sfx can be heard.
|
||||||
|
* \param gain Gain value of this sfx.
|
||||||
|
*/
|
||||||
SFXBuffer::SFXBuffer(const std::string& file,
|
SFXBuffer::SFXBuffer(const std::string& file,
|
||||||
bool positional,
|
bool positional,
|
||||||
float rolloff,
|
float rolloff,
|
||||||
float max_width,
|
float max_dist,
|
||||||
float gain)
|
float gain)
|
||||||
{
|
{
|
||||||
m_buffer = 0;
|
m_buffer = 0;
|
||||||
m_gain = 1.0f;
|
m_gain = 1.0f;
|
||||||
m_rolloff = 0.1f;
|
m_rolloff = 0.1f;
|
||||||
m_loaded = false;
|
m_loaded = false;
|
||||||
m_max_dist = max_width;
|
m_max_dist = max_dist;
|
||||||
|
m_duration = -1.0f;
|
||||||
m_file = file;
|
m_file = file;
|
||||||
|
|
||||||
m_rolloff = rolloff;
|
m_rolloff = rolloff;
|
||||||
m_positional = positional;
|
m_positional = positional;
|
||||||
m_gain = gain;
|
m_gain = gain;
|
||||||
}
|
} // SFXBuffer
|
||||||
|
|
||||||
//----------------------------------------------------------------------------
|
//----------------------------------------------------------------------------
|
||||||
|
/** Constructor getting the sfx parameters from an XML node.
|
||||||
|
* \param file File name of the data.
|
||||||
|
* \param node XML Node with the data for this sfx.
|
||||||
|
*/
|
||||||
SFXBuffer::SFXBuffer(const std::string& file,
|
SFXBuffer::SFXBuffer(const std::string& file,
|
||||||
const XMLNode* node)
|
const XMLNode* node)
|
||||||
{
|
{
|
||||||
@ -64,6 +74,7 @@ SFXBuffer::SFXBuffer(const std::string& file,
|
|||||||
m_gain = 1.0f;
|
m_gain = 1.0f;
|
||||||
m_rolloff = 0.1f;
|
m_rolloff = 0.1f;
|
||||||
m_max_dist = 300.0f;
|
m_max_dist = 300.0f;
|
||||||
|
m_duration = -1.0f;
|
||||||
m_positional = false;
|
m_positional = false;
|
||||||
m_loaded = false;
|
m_loaded = false;
|
||||||
m_file = file;
|
m_file = file;
|
||||||
@ -72,10 +83,15 @@ SFXBuffer::SFXBuffer(const std::string& file,
|
|||||||
node->get("positional", &m_positional );
|
node->get("positional", &m_positional );
|
||||||
node->get("volume", &m_gain );
|
node->get("volume", &m_gain );
|
||||||
node->get("max_dist", &m_max_dist );
|
node->get("max_dist", &m_max_dist );
|
||||||
}
|
node->get("duration", &m_duration );
|
||||||
|
} // SFXBuffer(XMLNode)
|
||||||
|
|
||||||
//----------------------------------------------------------------------------
|
//----------------------------------------------------------------------------
|
||||||
|
/** \brief load the buffer from file into OpenAL.
|
||||||
|
* \note If this buffer is already loaded, this call does nothing and
|
||||||
|
* returns false.
|
||||||
|
* \return Whether loading was successful.
|
||||||
|
*/
|
||||||
bool SFXBuffer::load()
|
bool SFXBuffer::load()
|
||||||
{
|
{
|
||||||
if (UserConfigParams::m_sfx == false) return false;
|
if (UserConfigParams::m_sfx == false) return false;
|
||||||
@ -103,9 +119,13 @@ bool SFXBuffer::load()
|
|||||||
|
|
||||||
m_loaded = true;
|
m_loaded = true;
|
||||||
return true;
|
return true;
|
||||||
}
|
} // load
|
||||||
|
|
||||||
//----------------------------------------------------------------------------
|
//----------------------------------------------------------------------------
|
||||||
|
/** \brief Frees the loaded buffer.
|
||||||
|
* Cannot appear in destructor because copy-constructors may be used,
|
||||||
|
* and the OpenAL source must not be deleted on a copy
|
||||||
|
*/
|
||||||
|
|
||||||
void SFXBuffer::unload()
|
void SFXBuffer::unload()
|
||||||
{
|
{
|
||||||
@ -117,7 +137,7 @@ void SFXBuffer::unload()
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
m_loaded = false;
|
m_loaded = false;
|
||||||
}
|
} // unload
|
||||||
|
|
||||||
//----------------------------------------------------------------------------
|
//----------------------------------------------------------------------------
|
||||||
/** Load a vorbis file into an OpenAL buffer
|
/** Load a vorbis file into an OpenAL buffer
|
||||||
@ -164,7 +184,7 @@ bool SFXBuffer::loadVorbisBuffer(const std::string &name, ALuint buffer)
|
|||||||
if(!data)
|
if(!data)
|
||||||
{
|
{
|
||||||
ov_clear(&oggFile);
|
ov_clear(&oggFile);
|
||||||
Log::error("SFXBuffer", "[SFXBuffer] loadVorbisBuffer() - Error : LoadVorbisBuffer() - couldn't allocate decode buffer\n");
|
Log::error("SFXBuffer", "[SFXBuffer] Could not allocate decode buffer.");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -188,9 +208,21 @@ bool SFXBuffer::loadVorbisBuffer(const std::string &name, ALuint buffer)
|
|||||||
|
|
||||||
ov_clear(&oggFile);
|
ov_clear(&oggFile);
|
||||||
fclose(file);
|
fclose(file);
|
||||||
|
|
||||||
|
// Allow the xml data to overwrite the duration, but if there is no
|
||||||
|
// duration (which is the norm), compute it:
|
||||||
|
if(m_duration < 0)
|
||||||
|
{
|
||||||
|
ALint buffer_size, frequency, bits_per_sample, channels;
|
||||||
|
alGetBufferi(buffer, AL_SIZE, &buffer_size );
|
||||||
|
alGetBufferi(buffer, AL_FREQUENCY, &frequency );
|
||||||
|
alGetBufferi(buffer, AL_CHANNELS, &channels );
|
||||||
|
alGetBufferi(buffer, AL_BITS, &bits_per_sample);
|
||||||
|
m_duration = float(buffer_size) / (frequency*channels*(bits_per_sample / 8));
|
||||||
|
}
|
||||||
return success;
|
return success;
|
||||||
#else
|
#else
|
||||||
return false;
|
return false;
|
||||||
#endif
|
#endif
|
||||||
}
|
} // loadVorbisBuffer
|
||||||
|
|
||||||
|
@ -46,18 +46,32 @@ class SFXBuffer
|
|||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
|
|
||||||
|
LEAK_CHECK()
|
||||||
|
|
||||||
/** Whether the contents of the file was loaded */
|
/** Whether the contents of the file was loaded */
|
||||||
bool m_loaded;
|
bool m_loaded;
|
||||||
|
|
||||||
/** The file that contains the OGG audio data */
|
/** The file that contains the OGG audio data */
|
||||||
std::string m_file;
|
std::string m_file;
|
||||||
|
|
||||||
|
/** The openal buffer id. */
|
||||||
ALuint m_buffer;
|
ALuint m_buffer;
|
||||||
|
|
||||||
|
/** If the sound is positional. */
|
||||||
bool m_positional;
|
bool m_positional;
|
||||||
|
|
||||||
|
/** The roll-off value. */
|
||||||
float m_rolloff;
|
float m_rolloff;
|
||||||
|
|
||||||
|
/** The volume gain value. */
|
||||||
float m_gain;
|
float m_gain;
|
||||||
|
|
||||||
|
/** Maximum distance the sfx can be heard. */
|
||||||
float m_max_dist;
|
float m_max_dist;
|
||||||
|
|
||||||
|
/** Duration of the sfx. */
|
||||||
|
float m_duration;
|
||||||
|
|
||||||
bool loadVorbisBuffer(const std::string &name, ALuint buffer);
|
bool loadVorbisBuffer(const std::string &name, ALuint buffer);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
@ -70,41 +84,43 @@ public:
|
|||||||
|
|
||||||
SFXBuffer(const std::string& file,
|
SFXBuffer(const std::string& file,
|
||||||
const XMLNode* node);
|
const XMLNode* node);
|
||||||
|
|
||||||
~SFXBuffer()
|
~SFXBuffer()
|
||||||
{
|
{
|
||||||
}
|
} // ~SFXBuffer
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* \brief load the buffer from file into OpenAL.
|
|
||||||
* \note If this buffer is already loaded, this call does nothing and returns false
|
|
||||||
* \return whether loading was successful
|
|
||||||
*/
|
|
||||||
bool load();
|
bool load();
|
||||||
|
|
||||||
/**
|
|
||||||
* \brief Frees the loaded buffer
|
|
||||||
* Cannot appear in destructor because copy-constructors may be used,
|
|
||||||
* and the OpenAL source must not be deleted on a copy
|
|
||||||
*/
|
|
||||||
void unload();
|
void unload();
|
||||||
|
|
||||||
|
// ------------------------------------------------------------------------
|
||||||
/** \return whether this buffer was loaded from disk */
|
/** \return whether this buffer was loaded from disk */
|
||||||
bool isLoaded() const { return m_loaded; }
|
bool isLoaded() const { return m_loaded; }
|
||||||
|
// ------------------------------------------------------------------------
|
||||||
/** Only returns a valid buffer if isLoaded() returned true */
|
/** Only returns a valid buffer if isLoaded() returned true */
|
||||||
ALuint getBufferID() const { return m_buffer; }
|
ALuint getBufferID() const { return m_buffer; }
|
||||||
|
// ------------------------------------------------------------------------
|
||||||
|
/** Returns if the buffer is positional. */
|
||||||
bool isPositional() const { return m_positional; }
|
bool isPositional() const { return m_positional; }
|
||||||
|
// ------------------------------------------------------------------------
|
||||||
|
/** Returns the rolloff value of this buffer. */
|
||||||
float getRolloff() const { return m_rolloff; }
|
float getRolloff() const { return m_rolloff; }
|
||||||
|
// ------------------------------------------------------------------------
|
||||||
|
/** Returns the gain for this sfx. */
|
||||||
float getGain() const { return m_gain; }
|
float getGain() const { return m_gain; }
|
||||||
|
// ------------------------------------------------------------------------
|
||||||
|
/** Returns the maximum distance this sfx can be heard. */
|
||||||
float getMaxDist() const { return m_max_dist; }
|
float getMaxDist() const { return m_max_dist; }
|
||||||
std::string getFileName() const { return m_file; }
|
// ------------------------------------------------------------------------
|
||||||
|
/** Returns the file name of this buffer. */
|
||||||
|
const std::string& getFileName() const { return m_file; }
|
||||||
|
// ------------------------------------------------------------------------
|
||||||
|
/** Sets if this buffer is positional or not. */
|
||||||
void setPositional(bool positional) { m_positional = positional; }
|
void setPositional(bool positional) { m_positional = positional; }
|
||||||
|
// ------------------------------------------------------------------------
|
||||||
|
/** Returns how long this buffer will play. */
|
||||||
|
float getDuration() const { return m_duration; }
|
||||||
|
|
||||||
LEAK_CHECK()
|
}; // class SFXBuffer
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
#endif // HEADER_SFX_BUFFER_HPP
|
#endif // HEADER_SFX_BUFFER_HPP
|
||||||
|
@ -106,9 +106,9 @@ SFXManager::SFXManager()
|
|||||||
if (!sfxAllowed()) return;
|
if (!sfxAllowed()) return;
|
||||||
|
|
||||||
setMasterSFXVolume( UserConfigParams::m_sfx_volume );
|
setMasterSFXVolume( UserConfigParams::m_sfx_volume );
|
||||||
m_sfx_to_play.lock();
|
m_sfx_commands.lock();
|
||||||
m_sfx_to_play.getData().clear();
|
m_sfx_commands.getData().clear();
|
||||||
m_sfx_to_play.unlock();
|
m_sfx_commands.unlock();
|
||||||
|
|
||||||
} // SoundManager
|
} // SoundManager
|
||||||
|
|
||||||
@ -124,13 +124,15 @@ SFXManager::~SFXManager()
|
|||||||
pthread_cond_destroy(&m_cond_request);
|
pthread_cond_destroy(&m_cond_request);
|
||||||
|
|
||||||
// ---- clear m_all_sfx
|
// ---- clear m_all_sfx
|
||||||
const int sfx_amount = (int) m_all_sfx.size();
|
// not strictly necessary, but might avoid copy&paste problems
|
||||||
|
m_all_sfx.lock();
|
||||||
|
const int sfx_amount = (int) m_all_sfx.getData().size();
|
||||||
for (int n=0; n<sfx_amount; n++)
|
for (int n=0; n<sfx_amount; n++)
|
||||||
{
|
{
|
||||||
delete m_all_sfx[n];
|
delete m_all_sfx.getData()[n];
|
||||||
}
|
}
|
||||||
m_all_sfx.clear();
|
m_all_sfx.getData().clear();
|
||||||
|
m_all_sfx.unlock();
|
||||||
// ---- clear m_quick_sounds
|
// ---- clear m_quick_sounds
|
||||||
{
|
{
|
||||||
std::map<std::string, SFXBase*>::iterator i = m_quick_sounds.begin();
|
std::map<std::string, SFXBase*>::iterator i = m_quick_sounds.begin();
|
||||||
@ -163,15 +165,13 @@ SFXManager::~SFXManager()
|
|||||||
* separate thread.
|
* separate thread.
|
||||||
* \param sfx The sound effect to be started.
|
* \param sfx The sound effect to be started.
|
||||||
*/
|
*/
|
||||||
void SFXManager::queue(SFXBase *sfx)
|
void SFXManager::queue(SFXCommands command, SFXBase *sfx)
|
||||||
{
|
{
|
||||||
// Don't add sfx that are either not working correctly (e.g. because sfx
|
SFXCommand *sfx_command = new SFXCommand(command, sfx);
|
||||||
// are disabled);
|
|
||||||
if(sfx && sfx->getStatus()==SFX_UNKNOWN ) return;
|
|
||||||
|
|
||||||
m_sfx_to_play.lock();
|
m_sfx_commands.lock();
|
||||||
m_sfx_to_play.getData().push_back(sfx);
|
m_sfx_commands.getData().push_back(sfx_command);
|
||||||
m_sfx_to_play.unlock();
|
m_sfx_commands.unlock();
|
||||||
// Wake up the sfx thread
|
// Wake up the sfx thread
|
||||||
pthread_cond_signal(&m_cond_request);
|
pthread_cond_signal(&m_cond_request);
|
||||||
|
|
||||||
@ -183,7 +183,7 @@ void SFXManager::queue(SFXBase *sfx)
|
|||||||
*/
|
*/
|
||||||
void SFXManager::stopThread()
|
void SFXManager::stopThread()
|
||||||
{
|
{
|
||||||
queue(NULL);
|
queue(SFX_EXIT, NULL);
|
||||||
} // stopThread
|
} // stopThread
|
||||||
|
|
||||||
//----------------------------------------------------------------------------
|
//----------------------------------------------------------------------------
|
||||||
@ -198,40 +198,60 @@ void* SFXManager::mainLoop(void *obj)
|
|||||||
|
|
||||||
pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, NULL);
|
pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, NULL);
|
||||||
|
|
||||||
me->m_sfx_to_play.lock();
|
me->m_sfx_commands.lock();
|
||||||
|
|
||||||
// Wait till we have an empty sfx in the queue
|
// Wait till we have an empty sfx in the queue
|
||||||
while (me->m_sfx_to_play.getData().empty() ||
|
while (me->m_sfx_commands.getData().empty() ||
|
||||||
me->m_sfx_to_play.getData().front()!=NULL )
|
me->m_sfx_commands.getData().front()->m_command!=SFX_EXIT)
|
||||||
{
|
{
|
||||||
bool empty = me->m_sfx_to_play.getData().empty();
|
bool empty = me->m_sfx_commands.getData().empty();
|
||||||
|
|
||||||
// Wait in cond_wait for a request to arrive. The 'while' is necessary
|
// Wait in cond_wait for a request to arrive. The 'while' is necessary
|
||||||
// since "spurious wakeups from the pthread_cond_wait ... may occur"
|
// since "spurious wakeups from the pthread_cond_wait ... may occur"
|
||||||
// (pthread_cond_wait man page)!
|
// (pthread_cond_wait man page)!
|
||||||
while (empty)
|
while (empty)
|
||||||
{
|
{
|
||||||
pthread_cond_wait(&me->m_cond_request, me->m_sfx_to_play.getMutex());
|
pthread_cond_wait(&me->m_cond_request, me->m_sfx_commands.getMutex());
|
||||||
empty = me->m_sfx_to_play.getData().empty();
|
empty = me->m_sfx_commands.getData().empty();
|
||||||
}
|
}
|
||||||
|
|
||||||
SFXBase *current = me->m_sfx_to_play.getData().front();
|
SFXCommand *current = me->m_sfx_commands.getData().front();
|
||||||
me->m_sfx_to_play.getData().erase(me->m_sfx_to_play.getData().begin());
|
me->m_sfx_commands.getData().erase(me->m_sfx_commands.getData().begin());
|
||||||
|
|
||||||
if (!current) // empty sfx indicates to abort the sfx manager
|
if (current->m_command == SFX_EXIT)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
me->m_sfx_to_play.unlock();
|
me->m_sfx_commands.unlock();
|
||||||
current->reallyPlayNow();
|
switch(current->m_command)
|
||||||
me->m_sfx_to_play.lock();
|
{
|
||||||
|
case SFX_PLAY: current->m_sfx->reallyPlayNow(); break;
|
||||||
|
case SFX_STOP: current->m_sfx->reallyStopNow(); break;
|
||||||
|
case SFX_PAUSE: current->m_sfx->reallyPauseNow(); break;
|
||||||
|
case SFX_RESUME: current->m_sfx->reallyResumeNow(); break;
|
||||||
|
case SFX_DELETE: {
|
||||||
|
current->m_sfx->reallyStopNow();
|
||||||
|
me->deleteSFX(current->m_sfx);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
default: assert("Not yet supported.");
|
||||||
|
}
|
||||||
|
delete current;
|
||||||
|
current = NULL;
|
||||||
|
me->m_sfx_commands.lock();
|
||||||
|
|
||||||
} // while
|
} // while
|
||||||
|
|
||||||
|
// Clean up memory to avoid leak detection
|
||||||
|
while(!me->m_sfx_commands.getData().empty())
|
||||||
|
{
|
||||||
|
delete me->m_sfx_commands.getData().front();
|
||||||
|
me->m_sfx_commands.getData().erase(me->m_sfx_commands.getData().begin());
|
||||||
|
}
|
||||||
return NULL;
|
return NULL;
|
||||||
} // mainLoop
|
} // mainLoop
|
||||||
|
|
||||||
//----------------------------------------------------------------------------
|
//----------------------------------------------------------------------------
|
||||||
/** Called then sound is globally switched on or off. It either pauses or
|
/** Called when sound is globally switched on or off. It either pauses or
|
||||||
* resumes all sound effects.
|
* resumes all sound effects.
|
||||||
* \param on If sound is switched on or off.
|
* \param on If sound is switched on or off.
|
||||||
*/
|
*/
|
||||||
@ -248,12 +268,13 @@ void SFXManager::soundToggled(const bool on)
|
|||||||
}
|
}
|
||||||
|
|
||||||
resumeAll();
|
resumeAll();
|
||||||
|
m_all_sfx.lock();
|
||||||
const int sfx_amount = (int)m_all_sfx.size();
|
const int sfx_amount = (int)m_all_sfx.getData().size();
|
||||||
for (int n=0; n<sfx_amount; n++)
|
for (int n=0; n<sfx_amount; n++)
|
||||||
{
|
{
|
||||||
m_all_sfx[n]->onSoundEnabledBack();
|
m_all_sfx.getData()[n]->onSoundEnabledBack();
|
||||||
}
|
}
|
||||||
|
m_all_sfx.unlock();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -437,7 +458,14 @@ SFXBase* SFXManager::createSoundSource(SFXBuffer* buffer,
|
|||||||
|
|
||||||
sfx->setMasterVolume(m_master_gain);
|
sfx->setMasterVolume(m_master_gain);
|
||||||
|
|
||||||
if (add_to_SFX_list) m_all_sfx.push_back(sfx);
|
if (add_to_SFX_list)
|
||||||
|
{
|
||||||
|
m_all_sfx.lock();
|
||||||
|
m_all_sfx.getData().push_back(sfx);
|
||||||
|
m_all_sfx.unlock();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
printf("");
|
||||||
|
|
||||||
return sfx;
|
return sfx;
|
||||||
} // createSoundSource
|
} // createSoundSource
|
||||||
@ -497,21 +525,26 @@ void SFXManager::deleteSFXMapping(const std::string &name)
|
|||||||
*/
|
*/
|
||||||
void SFXManager::deleteSFX(SFXBase *sfx)
|
void SFXManager::deleteSFX(SFXBase *sfx)
|
||||||
{
|
{
|
||||||
if(sfx) sfx->stop();
|
if(sfx) sfx->reallyStopNow();
|
||||||
std::vector<SFXBase*>::iterator i;
|
std::vector<SFXBase*>::iterator i;
|
||||||
i=std::find(m_all_sfx.begin(), m_all_sfx.end(), sfx);
|
|
||||||
|
|
||||||
if(i==m_all_sfx.end())
|
// The whole block needs to be locked, otherwise the iterator
|
||||||
|
// could become invalid.
|
||||||
|
m_all_sfx.lock();
|
||||||
|
i=std::find(m_all_sfx.getData().begin(), m_all_sfx.getData().end(), sfx);
|
||||||
|
|
||||||
|
if(i==m_all_sfx.getData().end())
|
||||||
{
|
{
|
||||||
Log::warn("SFXManager",
|
Log::warn("SFXManager",
|
||||||
"SFXManager::deleteSFX : Warning: sfx not found in list.");
|
"SFXManager::deleteSFX : Warning: sfx '%s' %lx not found in list.",
|
||||||
|
sfx->getBuffer()->getFileName().c_str(), sfx);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
m_all_sfx.getData().erase(i);
|
||||||
delete sfx;
|
delete sfx;
|
||||||
|
|
||||||
m_all_sfx.erase(i);
|
m_all_sfx.unlock();
|
||||||
|
|
||||||
} // deleteSFX
|
} // deleteSFX
|
||||||
|
|
||||||
//----------------------------------------------------------------------------
|
//----------------------------------------------------------------------------
|
||||||
@ -521,11 +554,13 @@ void SFXManager::deleteSFX(SFXBase *sfx)
|
|||||||
*/
|
*/
|
||||||
void SFXManager::pauseAll()
|
void SFXManager::pauseAll()
|
||||||
{
|
{
|
||||||
for (std::vector<SFXBase*>::iterator i=m_all_sfx.begin();
|
m_all_sfx.lock();
|
||||||
i!=m_all_sfx.end(); i++)
|
for (std::vector<SFXBase*>::iterator i= m_all_sfx.getData().begin();
|
||||||
|
i!=m_all_sfx.getData().end(); i++)
|
||||||
{
|
{
|
||||||
(*i)->pause();
|
(*i)->pause();
|
||||||
} // for i in m_all_sfx
|
} // for i in m_all_sfx
|
||||||
|
m_all_sfx.unlock();
|
||||||
} // pauseAll
|
} // pauseAll
|
||||||
|
|
||||||
//----------------------------------------------------------------------------
|
//----------------------------------------------------------------------------
|
||||||
@ -537,13 +572,15 @@ void SFXManager::resumeAll()
|
|||||||
// ignore unpausing if sound is disabled
|
// ignore unpausing if sound is disabled
|
||||||
if (!sfxAllowed()) return;
|
if (!sfxAllowed()) return;
|
||||||
|
|
||||||
for (std::vector<SFXBase*>::iterator i=m_all_sfx.begin();
|
m_all_sfx.lock();
|
||||||
i!=m_all_sfx.end(); i++)
|
for (std::vector<SFXBase*>::iterator i =m_all_sfx.getData().begin();
|
||||||
|
i!=m_all_sfx.getData().end(); i++)
|
||||||
{
|
{
|
||||||
SFXStatus status = (*i)->getStatus();
|
SFXStatus status = (*i)->getStatus();
|
||||||
// Initial happens when
|
// Initial happens when
|
||||||
if (status==SFX_PAUSED) (*i)->resume();
|
if (status==SFX_PAUSED) (*i)->resume();
|
||||||
} // for i in m_all_sfx
|
} // for i in m_all_sfx
|
||||||
|
m_all_sfx.unlock();
|
||||||
} // resumeAll
|
} // resumeAll
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
@ -580,11 +617,13 @@ void SFXManager::setMasterSFXVolume(float gain)
|
|||||||
|
|
||||||
// regular SFX
|
// regular SFX
|
||||||
{
|
{
|
||||||
for (std::vector<SFXBase*>::iterator i=m_all_sfx.begin();
|
m_all_sfx.lock();
|
||||||
i!=m_all_sfx.end(); i++)
|
for (std::vector<SFXBase*>::iterator i =m_all_sfx.getData().begin();
|
||||||
|
i!=m_all_sfx.getData().end(); i++)
|
||||||
{
|
{
|
||||||
(*i)->setMasterVolume(m_master_gain);
|
(*i)->setMasterVolume(m_master_gain);
|
||||||
} // for i in m_all_sfx
|
} // for i in m_all_sfx
|
||||||
|
m_all_sfx.unlock();
|
||||||
}
|
}
|
||||||
|
|
||||||
// quick SFX
|
// quick SFX
|
||||||
|
@ -19,6 +19,7 @@
|
|||||||
#ifndef HEADER_SFX_MANAGER_HPP
|
#ifndef HEADER_SFX_MANAGER_HPP
|
||||||
#define HEADER_SFX_MANAGER_HPP
|
#define HEADER_SFX_MANAGER_HPP
|
||||||
|
|
||||||
|
#include "utils/leak_check.hpp"
|
||||||
#include "utils/no_copy.hpp"
|
#include "utils/no_copy.hpp"
|
||||||
#include "utils/synchronised.hpp"
|
#include "utils/synchronised.hpp"
|
||||||
#include "utils/vec3.hpp"
|
#include "utils/vec3.hpp"
|
||||||
@ -57,6 +58,18 @@ private:
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
|
/** The various commands to be executed by the sfx manager thread
|
||||||
|
* for each sfx. */
|
||||||
|
enum SFXCommands
|
||||||
|
{
|
||||||
|
SFX_PLAY = 1,
|
||||||
|
SFX_STOP = 2,
|
||||||
|
SFX_PAUSE = 3,
|
||||||
|
SFX_RESUME = 4,
|
||||||
|
SFX_DELETE = 5,
|
||||||
|
SFX_EXIT = 6,
|
||||||
|
}; // SFXCommands
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Entries for custom SFX sounds. These are unique for each kart.
|
* Entries for custom SFX sounds. These are unique for each kart.
|
||||||
* eg. kart->playCustomSFX(SFX_MANAGER::CUSTOM_HORN)
|
* eg. kart->playCustomSFX(SFX_MANAGER::CUSTOM_HORN)
|
||||||
@ -85,6 +98,22 @@ public:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
|
/** Data structure for the queue, which stores a sfx and the command to
|
||||||
|
* execute for it. */
|
||||||
|
class SFXCommand : public NoCopy
|
||||||
|
{
|
||||||
|
private:
|
||||||
|
LEAK_CHECK()
|
||||||
|
public:
|
||||||
|
SFXBase *m_sfx;
|
||||||
|
SFXCommands m_command;
|
||||||
|
SFXCommand(SFXCommands command, SFXBase *base)
|
||||||
|
{
|
||||||
|
m_command = command;
|
||||||
|
m_sfx = base;
|
||||||
|
}
|
||||||
|
}; // SFXCommand
|
||||||
|
|
||||||
/** Listener position */
|
/** Listener position */
|
||||||
Vec3 m_position;
|
Vec3 m_position;
|
||||||
|
|
||||||
@ -93,10 +122,10 @@ private:
|
|||||||
std::map<std::string, SFXBuffer*> m_all_sfx_types;
|
std::map<std::string, SFXBuffer*> m_all_sfx_types;
|
||||||
|
|
||||||
/** The actual instances (sound sources) */
|
/** The actual instances (sound sources) */
|
||||||
std::vector<SFXBase*> m_all_sfx;
|
Synchronised<std::vector<SFXBase*> > m_all_sfx;
|
||||||
|
|
||||||
/** The list of sound effects to be played in the next update. */
|
/** The list of sound effects to be played in the next update. */
|
||||||
Synchronised< std::vector<SFXBase*> > m_sfx_to_play;
|
Synchronised< std::vector<SFXCommand*> > m_sfx_commands;
|
||||||
|
|
||||||
/** To play non-positional sounds without having to create a new object for each */
|
/** To play non-positional sounds without having to create a new object for each */
|
||||||
std::map<std::string, SFXBase*> m_quick_sounds;
|
std::map<std::string, SFXBase*> m_quick_sounds;
|
||||||
@ -121,10 +150,11 @@ private:
|
|||||||
virtual ~SFXManager();
|
virtual ~SFXManager();
|
||||||
|
|
||||||
static void* mainLoop(void *obj);
|
static void* mainLoop(void *obj);
|
||||||
|
void deleteSFX(SFXBase *sfx);
|
||||||
public:
|
public:
|
||||||
static void create();
|
static void create();
|
||||||
static void destroy();
|
static void destroy();
|
||||||
void queue(SFXBase *sfx);
|
void queue(SFXCommands command, SFXBase *sfx);
|
||||||
// ------------------------------------------------------------------------
|
// ------------------------------------------------------------------------
|
||||||
/** Static function to get the singleton sfx manager. */
|
/** Static function to get the singleton sfx manager. */
|
||||||
static SFXManager *get()
|
static SFXManager *get()
|
||||||
@ -153,7 +183,6 @@ public:
|
|||||||
SFXBase* createSoundSource(const std::string &name,
|
SFXBase* createSoundSource(const std::string &name,
|
||||||
const bool addToSFXList=true);
|
const bool addToSFXList=true);
|
||||||
|
|
||||||
void deleteSFX(SFXBase *sfx);
|
|
||||||
void deleteSFXMapping(const std::string &name);
|
void deleteSFXMapping(const std::string &name);
|
||||||
void pauseAll();
|
void pauseAll();
|
||||||
void resumeAll();
|
void resumeAll();
|
||||||
|
@ -182,9 +182,16 @@ void SFXOpenAL::setLoop(bool status)
|
|||||||
} // loop
|
} // loop
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
/** Stops playing this sound effect.
|
/** Queues a stop for this effect to the sound manager.
|
||||||
*/
|
*/
|
||||||
void SFXOpenAL::stop()
|
void SFXOpenAL::stop()
|
||||||
|
{
|
||||||
|
SFXManager::get()->queue(SFXManager::SFX_STOP, this);
|
||||||
|
} // stop
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
/** The sfx manager thread executes a stop for this sfx.
|
||||||
|
*/
|
||||||
|
void SFXOpenAL::reallyStopNow()
|
||||||
{
|
{
|
||||||
if(!m_ok) return;
|
if(!m_ok) return;
|
||||||
|
|
||||||
@ -193,23 +200,39 @@ void SFXOpenAL::stop()
|
|||||||
alSourcei(m_soundSource, AL_LOOPING, AL_FALSE);
|
alSourcei(m_soundSource, AL_LOOPING, AL_FALSE);
|
||||||
alSourceStop(m_soundSource);
|
alSourceStop(m_soundSource);
|
||||||
SFXManager::checkError("stoping");
|
SFXManager::checkError("stoping");
|
||||||
} // stop
|
} // reallyStopNow
|
||||||
|
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
/** Queues up a pause command for this sfx.
|
||||||
|
*/
|
||||||
|
void SFXOpenAL::pause()
|
||||||
|
{
|
||||||
|
SFXManager::get()->queue(SFXManager::SFX_PAUSE, this);
|
||||||
|
} // pause
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
/** Pauses a SFX that's currently played. Nothing happens it the effect is
|
/** Pauses a SFX that's currently played. Nothing happens it the effect is
|
||||||
* currently not being played.
|
* currently not being played.
|
||||||
*/
|
*/
|
||||||
void SFXOpenAL::pause()
|
void SFXOpenAL::reallyPauseNow()
|
||||||
{
|
{
|
||||||
if(!m_ok) return;
|
if(!m_ok) return;
|
||||||
alSourcePause(m_soundSource);
|
alSourcePause(m_soundSource);
|
||||||
SFXManager::checkError("pausing");
|
SFXManager::checkError("pausing");
|
||||||
} // pause
|
} // reallyPauseNow
|
||||||
|
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
/** Queues up a resume command for this sound effect.
|
||||||
|
*/
|
||||||
|
void SFXOpenAL::resume()
|
||||||
|
{
|
||||||
|
SFXManager::get()->queue(SFXManager::SFX_RESUME, this);
|
||||||
|
} // resume
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
/** Resumes a sound effect.
|
/** Resumes a sound effect.
|
||||||
*/
|
*/
|
||||||
void SFXOpenAL::resume()
|
void SFXOpenAL::reallyResumeNow()
|
||||||
{
|
{
|
||||||
if (!m_ok)
|
if (!m_ok)
|
||||||
{
|
{
|
||||||
@ -222,7 +245,17 @@ void SFXOpenAL::resume()
|
|||||||
|
|
||||||
alSourcePlay(m_soundSource);
|
alSourcePlay(m_soundSource);
|
||||||
SFXManager::checkError("resuming");
|
SFXManager::checkError("resuming");
|
||||||
} // resume
|
} // reallyResumeNow
|
||||||
|
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
/** Queues up a delete request for this object. This is necessary to avoid
|
||||||
|
* a crash if the sfx manager thread might be delayed and access this object
|
||||||
|
* after it was deleted.
|
||||||
|
*/
|
||||||
|
void SFXOpenAL::deleteSFX()
|
||||||
|
{
|
||||||
|
SFXManager::get()->queue(SFXManager::SFX_DELETE, this);
|
||||||
|
} // deleteSFX
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
/** This actually queues up the sfx in the sfx manager. It will be started
|
/** This actually queues up the sfx in the sfx manager. It will be started
|
||||||
@ -234,7 +267,7 @@ void SFXOpenAL::play()
|
|||||||
// but for STK this is correct since we don't want to start the same
|
// but for STK this is correct since we don't want to start the same
|
||||||
// sfx twice.
|
// sfx twice.
|
||||||
m_is_playing = true;
|
m_is_playing = true;
|
||||||
SFXManager::get()->queue(this);
|
SFXManager::get()->queue(SFXManager::SFX_PLAY, this);
|
||||||
} // play
|
} // play
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
|
@ -77,8 +77,12 @@ public:
|
|||||||
virtual void setLoop(bool status);
|
virtual void setLoop(bool status);
|
||||||
virtual bool isPlaying();
|
virtual bool isPlaying();
|
||||||
virtual void stop();
|
virtual void stop();
|
||||||
|
virtual void reallyStopNow();
|
||||||
virtual void pause();
|
virtual void pause();
|
||||||
|
virtual void reallyPauseNow();
|
||||||
virtual void resume();
|
virtual void resume();
|
||||||
|
virtual void reallyResumeNow();
|
||||||
|
virtual void deleteSFX();
|
||||||
virtual void speed(float factor);
|
virtual void speed(float factor);
|
||||||
virtual void position(const Vec3 &position);
|
virtual void position(const Vec3 &position);
|
||||||
virtual void volume(float gain);
|
virtual void volume(float gain);
|
||||||
|
@ -42,10 +42,7 @@ HitSFX::HitSFX(const Vec3& coord, const char* explosion_sound)
|
|||||||
*/
|
*/
|
||||||
HitSFX::~HitSFX()
|
HitSFX::~HitSFX()
|
||||||
{
|
{
|
||||||
if (m_sfx->getStatus() == SFXManager::SFX_PLAYING)
|
m_sfx->deleteSFX();
|
||||||
m_sfx->stop();
|
|
||||||
|
|
||||||
SFXManager::get()->deleteSFX(m_sfx);
|
|
||||||
} // ~HitEffect
|
} // ~HitEffect
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
|
@ -51,11 +51,11 @@ Weather::Weather(bool lightning, std::string sound)
|
|||||||
Weather::~Weather()
|
Weather::~Weather()
|
||||||
{
|
{
|
||||||
if (m_thunder_sound != NULL)
|
if (m_thunder_sound != NULL)
|
||||||
SFXManager::get()->deleteSFX(m_thunder_sound);
|
m_thunder_sound->deleteSFX();
|
||||||
|
|
||||||
if (m_weather_sound != NULL)
|
if (m_weather_sound != NULL)
|
||||||
SFXManager::get()->deleteSFX(m_weather_sound);
|
m_weather_sound->deleteSFX();
|
||||||
}
|
} // ~Weather
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
@ -80,13 +80,13 @@ Attachment::~Attachment()
|
|||||||
|
|
||||||
if (m_bomb_sound)
|
if (m_bomb_sound)
|
||||||
{
|
{
|
||||||
SFXManager::get()->deleteSFX(m_bomb_sound);
|
m_bomb_sound->deleteSFX();
|
||||||
m_bomb_sound = NULL;
|
m_bomb_sound = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (m_bubble_explode_sound)
|
if (m_bubble_explode_sound)
|
||||||
{
|
{
|
||||||
SFXManager::get()->deleteSFX(m_bubble_explode_sound);
|
m_bubble_explode_sound->deleteSFX();
|
||||||
m_bubble_explode_sound = NULL;
|
m_bubble_explode_sound = NULL;
|
||||||
}
|
}
|
||||||
} // ~Attachment
|
} // ~Attachment
|
||||||
@ -139,7 +139,7 @@ void Attachment::set(AttachmentType type, float time,
|
|||||||
break;
|
break;
|
||||||
case ATTACH_BOMB:
|
case ATTACH_BOMB:
|
||||||
m_node->setMesh(attachment_manager->getMesh(type));
|
m_node->setMesh(attachment_manager->getMesh(type));
|
||||||
if (m_bomb_sound) SFXManager::get()->deleteSFX(m_bomb_sound);
|
if (m_bomb_sound) m_bomb_sound->deleteSFX();
|
||||||
m_bomb_sound = SFXManager::get()->createSoundSource("clock");
|
m_bomb_sound = SFXManager::get()->createSoundSource("clock");
|
||||||
m_bomb_sound->setLoop(true);
|
m_bomb_sound->setLoop(true);
|
||||||
m_bomb_sound->position(m_kart->getXYZ());
|
m_bomb_sound->position(m_kart->getXYZ());
|
||||||
@ -198,8 +198,7 @@ void Attachment::clear()
|
|||||||
|
|
||||||
if (m_bomb_sound)
|
if (m_bomb_sound)
|
||||||
{
|
{
|
||||||
m_bomb_sound->stop();
|
m_bomb_sound->deleteSFX();
|
||||||
SFXManager::get()->deleteSFX(m_bomb_sound);
|
|
||||||
m_bomb_sound = NULL;
|
m_bomb_sound = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -460,8 +459,7 @@ void Attachment::update(float dt)
|
|||||||
|
|
||||||
if (m_bomb_sound)
|
if (m_bomb_sound)
|
||||||
{
|
{
|
||||||
m_bomb_sound->stop();
|
m_bomb_sound->deleteSFX();
|
||||||
SFXManager::get()->deleteSFX(m_bomb_sound);
|
|
||||||
m_bomb_sound = NULL;
|
m_bomb_sound = NULL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -474,7 +472,7 @@ void Attachment::update(float dt)
|
|||||||
if (m_time_left < 0)
|
if (m_time_left < 0)
|
||||||
{
|
{
|
||||||
m_time_left = 0.0f;
|
m_time_left = 0.0f;
|
||||||
if (m_bubble_explode_sound) SFXManager::get()->deleteSFX(m_bubble_explode_sound);
|
if (m_bubble_explode_sound) m_bubble_explode_sound->deleteSFX();
|
||||||
m_bubble_explode_sound = SFXManager::get()->createSoundSource("bubblegum_explode");
|
m_bubble_explode_sound = SFXManager::get()->createSoundSource("bubblegum_explode");
|
||||||
m_bubble_explode_sound->position(m_kart->getXYZ());
|
m_bubble_explode_sound->position(m_kart->getXYZ());
|
||||||
m_bubble_explode_sound->play();
|
m_bubble_explode_sound->play();
|
||||||
|
@ -87,9 +87,9 @@ Bowling::Bowling(AbstractKart *kart)
|
|||||||
*/
|
*/
|
||||||
Bowling::~Bowling()
|
Bowling::~Bowling()
|
||||||
{
|
{
|
||||||
if(m_roll_sfx->getStatus()==SFXManager::SFX_PLAYING)
|
// This will stop the sfx and delete the object.
|
||||||
m_roll_sfx->stop();
|
m_roll_sfx->deleteSFX();
|
||||||
SFXManager::get()->deleteSFX(m_roll_sfx);
|
|
||||||
} // ~RubberBall
|
} // ~RubberBall
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
@ -53,7 +53,7 @@ Powerup::Powerup(AbstractKart* kart)
|
|||||||
*/
|
*/
|
||||||
Powerup::~Powerup()
|
Powerup::~Powerup()
|
||||||
{
|
{
|
||||||
if(m_sound_use) SFXManager::get()->deleteSFX(m_sound_use);
|
if(m_sound_use) m_sound_use->deleteSFX();
|
||||||
} // ~Powerup
|
} // ~Powerup
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
@ -88,7 +88,7 @@ void Powerup::set(PowerupManager::PowerupType type, int n)
|
|||||||
|
|
||||||
if(m_sound_use != NULL)
|
if(m_sound_use != NULL)
|
||||||
{
|
{
|
||||||
SFXManager::get()->deleteSFX(m_sound_use);
|
m_sound_use->deleteSFX();
|
||||||
m_sound_use = NULL;
|
m_sound_use = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -109,7 +109,7 @@ RubberBall::~RubberBall()
|
|||||||
{
|
{
|
||||||
if(m_ping_sfx->getStatus()==SFXManager::SFX_PLAYING)
|
if(m_ping_sfx->getStatus()==SFXManager::SFX_PLAYING)
|
||||||
m_ping_sfx->stop();
|
m_ping_sfx->stop();
|
||||||
SFXManager::get()->deleteSFX(m_ping_sfx);
|
m_ping_sfx->deleteSFX();
|
||||||
} // ~RubberBall
|
} // ~RubberBall
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
|
@ -100,7 +100,7 @@ Swatter::~Swatter()
|
|||||||
}
|
}
|
||||||
if (m_swat_sound)
|
if (m_swat_sound)
|
||||||
{
|
{
|
||||||
SFXManager::get()->deleteSFX(m_swat_sound);
|
m_swat_sound->deleteSFX();
|
||||||
}
|
}
|
||||||
} // ~Swatter
|
} // ~Swatter
|
||||||
|
|
||||||
|
@ -74,11 +74,11 @@ PlayerController::PlayerController(AbstractKart *kart,
|
|||||||
*/
|
*/
|
||||||
PlayerController::~PlayerController()
|
PlayerController::~PlayerController()
|
||||||
{
|
{
|
||||||
SFXManager::get()->deleteSFX(m_bzzt_sound);
|
m_bzzt_sound->deleteSFX();
|
||||||
SFXManager::get()->deleteSFX(m_wee_sound );
|
m_wee_sound ->deleteSFX();
|
||||||
SFXManager::get()->deleteSFX(m_ugh_sound );
|
m_ugh_sound ->deleteSFX();
|
||||||
SFXManager::get()->deleteSFX(m_grab_sound);
|
m_grab_sound->deleteSFX();
|
||||||
SFXManager::get()->deleteSFX(m_full_sound);
|
m_full_sound->deleteSFX();
|
||||||
} // ~PlayerController
|
} // ~PlayerController
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
|
@ -246,15 +246,15 @@ Kart::~Kart()
|
|||||||
SFXManager::get()->deleteSFX(m_custom_sounds[n]);
|
SFXManager::get()->deleteSFX(m_custom_sounds[n]);
|
||||||
}*/
|
}*/
|
||||||
|
|
||||||
SFXManager::get()->deleteSFX(m_engine_sound );
|
m_engine_sound->deleteSFX();
|
||||||
SFXManager::get()->deleteSFX(m_crash_sound );
|
m_crash_sound ->deleteSFX();
|
||||||
SFXManager::get()->deleteSFX(m_skid_sound );
|
m_skid_sound ->deleteSFX();
|
||||||
SFXManager::get()->deleteSFX(m_goo_sound );
|
m_goo_sound ->deleteSFX();
|
||||||
SFXManager::get()->deleteSFX(m_beep_sound );
|
m_beep_sound ->deleteSFX();
|
||||||
SFXManager::get()->deleteSFX(m_boing_sound );
|
m_boing_sound ->deleteSFX();
|
||||||
delete m_kart_gfx;
|
delete m_kart_gfx;
|
||||||
if(m_terrain_sound) SFXManager::get()->deleteSFX(m_terrain_sound);
|
if(m_terrain_sound) m_terrain_sound->deleteSFX();
|
||||||
if(m_previous_terrain_sound) SFXManager::get()->deleteSFX(m_previous_terrain_sound);
|
if(m_previous_terrain_sound) m_previous_terrain_sound->deleteSFX();
|
||||||
if(m_collision_particles) delete m_collision_particles;
|
if(m_collision_particles) delete m_collision_particles;
|
||||||
if(m_slipstream) delete m_slipstream;
|
if(m_slipstream) delete m_slipstream;
|
||||||
if(m_sky_particles_emitter) delete m_sky_particles_emitter;
|
if(m_sky_particles_emitter) delete m_sky_particles_emitter;
|
||||||
@ -363,15 +363,14 @@ void Kart::reset()
|
|||||||
|
|
||||||
if(m_terrain_sound)
|
if(m_terrain_sound)
|
||||||
{
|
{
|
||||||
SFXManager::get()->deleteSFX(m_terrain_sound);
|
m_terrain_sound->deleteSFX();
|
||||||
|
m_terrain_sound = NULL;
|
||||||
}
|
}
|
||||||
if(m_previous_terrain_sound)
|
if(m_previous_terrain_sound)
|
||||||
{
|
{
|
||||||
SFXManager::get()->deleteSFX(m_previous_terrain_sound);
|
m_previous_terrain_sound->deleteSFX();
|
||||||
}
|
|
||||||
|
|
||||||
m_terrain_sound = NULL;
|
|
||||||
m_previous_terrain_sound = NULL;
|
m_previous_terrain_sound = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
if(m_engine_sound)
|
if(m_engine_sound)
|
||||||
m_engine_sound->stop();
|
m_engine_sound->stop();
|
||||||
@ -1430,7 +1429,7 @@ void Kart::handleMaterialSFX(const Material *material)
|
|||||||
// can be used again.
|
// can be used again.
|
||||||
if(m_previous_terrain_sound)
|
if(m_previous_terrain_sound)
|
||||||
{
|
{
|
||||||
SFXManager::get()->deleteSFX(m_previous_terrain_sound);
|
m_previous_terrain_sound->deleteSFX();
|
||||||
}
|
}
|
||||||
m_previous_terrain_sound = m_terrain_sound;
|
m_previous_terrain_sound = m_terrain_sound;
|
||||||
if(m_previous_terrain_sound)
|
if(m_previous_terrain_sound)
|
||||||
@ -1467,7 +1466,7 @@ void Kart::handleMaterialSFX(const Material *material)
|
|||||||
// We don't modify the position of m_previous_terrain_sound
|
// We don't modify the position of m_previous_terrain_sound
|
||||||
// anymore, so that it keeps on playing at the place where the
|
// anymore, so that it keeps on playing at the place where the
|
||||||
// kart left the material.
|
// kart left the material.
|
||||||
SFXManager::get()->deleteSFX(m_previous_terrain_sound);
|
m_previous_terrain_sound->deleteSFX();
|
||||||
m_previous_terrain_sound = NULL;
|
m_previous_terrain_sound = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1592,7 +1591,7 @@ void Kart::handleMaterialGFX()
|
|||||||
(m_terrain_sound == NULL ||
|
(m_terrain_sound == NULL ||
|
||||||
m_terrain_sound->getStatus() == SFXManager::SFX_STOPPED))
|
m_terrain_sound->getStatus() == SFXManager::SFX_STOPPED))
|
||||||
{
|
{
|
||||||
if (m_previous_terrain_sound) SFXManager::get()->deleteSFX(m_previous_terrain_sound);
|
if (m_previous_terrain_sound) m_previous_terrain_sound->deleteSFX();
|
||||||
m_previous_terrain_sound = m_terrain_sound;
|
m_previous_terrain_sound = m_terrain_sound;
|
||||||
if(m_previous_terrain_sound)
|
if(m_previous_terrain_sound)
|
||||||
m_previous_terrain_sound->setLoop(false);
|
m_previous_terrain_sound->setLoop(false);
|
||||||
|
@ -73,7 +73,7 @@ void LinearWorld::init()
|
|||||||
*/
|
*/
|
||||||
LinearWorld::~LinearWorld()
|
LinearWorld::~LinearWorld()
|
||||||
{
|
{
|
||||||
SFXManager::get()->deleteSFX(m_last_lap_sfx);
|
m_last_lap_sfx->deleteSFX();
|
||||||
} // ~LinearWorld
|
} // ~LinearWorld
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
|
@ -60,7 +60,7 @@ SoccerWorld::SoccerWorld() : WorldWithRank()
|
|||||||
*/
|
*/
|
||||||
SoccerWorld::~SoccerWorld()
|
SoccerWorld::~SoccerWorld()
|
||||||
{
|
{
|
||||||
SFXManager::get()->deleteSFX(m_goal_sound);
|
m_goal_sound->deleteSFX();
|
||||||
} // ~SoccerWorld
|
} // ~SoccerWorld
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
|
@ -74,9 +74,9 @@ void WorldStatus::reset()
|
|||||||
*/
|
*/
|
||||||
WorldStatus::~WorldStatus()
|
WorldStatus::~WorldStatus()
|
||||||
{
|
{
|
||||||
SFXManager::get()->deleteSFX(m_prestart_sound);
|
m_prestart_sound->deleteSFX();
|
||||||
SFXManager::get()->deleteSFX(m_start_sound);
|
m_start_sound->deleteSFX();
|
||||||
SFXManager::get()->deleteSFX(m_track_intro_sound);
|
m_track_intro_sound->deleteSFX();
|
||||||
IrrlichtDevice *device = irr_driver->getDevice();
|
IrrlichtDevice *device = irr_driver->getDevice();
|
||||||
|
|
||||||
if (device->getTimer()->isStopped())
|
if (device->getTimer()->isStopped())
|
||||||
|
@ -1419,6 +1419,9 @@ void Track::handleAnimatedTextures(scene::ISceneNode *node, const XMLNode &xml)
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// to lower case, for case-insensitive comparison
|
||||||
|
name = StringUtils::toLowerCase(name);
|
||||||
|
|
||||||
for(unsigned int i=0; i<node->getMaterialCount(); i++)
|
for(unsigned int i=0; i<node->getMaterialCount(); i++)
|
||||||
{
|
{
|
||||||
video::SMaterial &irrMaterial=node->getMaterial(i);
|
video::SMaterial &irrMaterial=node->getMaterial(i);
|
||||||
@ -1426,8 +1429,12 @@ void Track::handleAnimatedTextures(scene::ISceneNode *node, const XMLNode &xml)
|
|||||||
{
|
{
|
||||||
video::ITexture* t=irrMaterial.getTexture(j);
|
video::ITexture* t=irrMaterial.getTexture(j);
|
||||||
if(!t) continue;
|
if(!t) continue;
|
||||||
const std::string texture_name =
|
std::string texture_name =
|
||||||
StringUtils::getBasename(core::stringc(t->getName()).c_str());
|
StringUtils::getBasename(core::stringc(t->getName()).c_str());
|
||||||
|
|
||||||
|
// to lower case, for case-insensitive comparison
|
||||||
|
texture_name = StringUtils::toLowerCase(texture_name);
|
||||||
|
|
||||||
if (texture_name != name) continue;
|
if (texture_name != name) continue;
|
||||||
core::matrix4 *m = &irrMaterial.getTextureMatrix(j);
|
core::matrix4 *m = &irrMaterial.getTextureMatrix(j);
|
||||||
m_animated_textures.push_back(new MovingTexture(m, *texture_node));
|
m_animated_textures.push_back(new MovingTexture(m, *texture_node));
|
||||||
|
@ -382,8 +382,9 @@ void TrackObjectPresentationMesh::reset()
|
|||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
|
||||||
TrackObjectPresentationSound::TrackObjectPresentationSound(const XMLNode& xml_node, scene::ISceneNode* parent) :
|
TrackObjectPresentationSound::TrackObjectPresentationSound(const XMLNode& xml_node,
|
||||||
TrackObjectPresentation(xml_node)
|
scene::ISceneNode* parent)
|
||||||
|
: TrackObjectPresentation(xml_node)
|
||||||
{
|
{
|
||||||
// TODO: respect 'parent' if any
|
// TODO: respect 'parent' if any
|
||||||
|
|
||||||
@ -440,8 +441,9 @@ TrackObjectPresentationSound::TrackObjectPresentationSound(const XMLNode& xml_no
|
|||||||
{
|
{
|
||||||
ItemManager::get()->newItem(m_init_xyz, trigger_distance, this);
|
ItemManager::get()->newItem(m_init_xyz, trigger_distance, this);
|
||||||
}
|
}
|
||||||
}
|
} // TrackObjectPresentationSound
|
||||||
|
|
||||||
|
// ----------------------------------------------------------------------------
|
||||||
void TrackObjectPresentationSound::update(float dt)
|
void TrackObjectPresentationSound::update(float dt)
|
||||||
{
|
{
|
||||||
if (m_sound != NULL)
|
if (m_sound != NULL)
|
||||||
@ -451,16 +453,18 @@ void TrackObjectPresentationSound::update(float dt)
|
|||||||
// moved
|
// moved
|
||||||
m_sound->position(m_xyz);
|
m_sound->position(m_xyz);
|
||||||
}
|
}
|
||||||
}
|
} // update
|
||||||
|
|
||||||
|
// ----------------------------------------------------------------------------
|
||||||
void TrackObjectPresentationSound::onTriggerItemApproached(Item* who)
|
void TrackObjectPresentationSound::onTriggerItemApproached(Item* who)
|
||||||
{
|
{
|
||||||
if (m_sound != NULL && m_sound->getStatus() != SFXManager::SFX_PLAYING)
|
if (m_sound != NULL && m_sound->getStatus() != SFXManager::SFX_PLAYING)
|
||||||
{
|
{
|
||||||
m_sound->play();
|
m_sound->play();
|
||||||
}
|
}
|
||||||
}
|
} // onTriggerItemApproached
|
||||||
|
|
||||||
|
// ----------------------------------------------------------------------------
|
||||||
void TrackObjectPresentationSound::triggerSound(bool loop)
|
void TrackObjectPresentationSound::triggerSound(bool loop)
|
||||||
{
|
{
|
||||||
if (m_sound != NULL)
|
if (m_sound != NULL)
|
||||||
@ -468,34 +472,37 @@ void TrackObjectPresentationSound::triggerSound(bool loop)
|
|||||||
m_sound->setLoop(loop);
|
m_sound->setLoop(loop);
|
||||||
m_sound->play();
|
m_sound->play();
|
||||||
}
|
}
|
||||||
}
|
} // triggerSound
|
||||||
|
|
||||||
|
// ----------------------------------------------------------------------------
|
||||||
void TrackObjectPresentationSound::stopSound()
|
void TrackObjectPresentationSound::stopSound()
|
||||||
{
|
{
|
||||||
if (m_sound != NULL) m_sound->stop();
|
if (m_sound != NULL) m_sound->stop();
|
||||||
}
|
} // stopSound
|
||||||
|
|
||||||
|
// ----------------------------------------------------------------------------
|
||||||
TrackObjectPresentationSound::~TrackObjectPresentationSound()
|
TrackObjectPresentationSound::~TrackObjectPresentationSound()
|
||||||
{
|
{
|
||||||
if (m_sound)
|
if (m_sound)
|
||||||
{
|
{
|
||||||
//delete m_sound->getBuffer();
|
m_sound->deleteSFX();
|
||||||
SFXManager::get()->deleteSFX(m_sound);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
} // ~TrackObjectPresentationSound
|
||||||
|
|
||||||
void TrackObjectPresentationSound::move(const core::vector3df& xyz, const core::vector3df& hpr,
|
// ----------------------------------------------------------------------------
|
||||||
|
void TrackObjectPresentationSound::move(const core::vector3df& xyz,
|
||||||
|
const core::vector3df& hpr,
|
||||||
const core::vector3df& scale)
|
const core::vector3df& scale)
|
||||||
{
|
{
|
||||||
m_xyz = xyz;
|
m_xyz = xyz;
|
||||||
if (m_sound != NULL) m_sound->position(xyz);
|
if (m_sound != NULL) m_sound->position(xyz);
|
||||||
}
|
} // move
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
TrackObjectPresentationBillboard::TrackObjectPresentationBillboard(const XMLNode& xml_node,
|
||||||
TrackObjectPresentationBillboard::TrackObjectPresentationBillboard(const XMLNode& xml_node, scene::ISceneNode* parent) :
|
scene::ISceneNode* parent)
|
||||||
TrackObjectPresentationSceneNode(xml_node)
|
: TrackObjectPresentationSceneNode(xml_node)
|
||||||
{
|
{
|
||||||
std::string texture_name;
|
std::string texture_name;
|
||||||
float width, height;
|
float width, height;
|
||||||
@ -529,6 +536,7 @@ TrackObjectPresentationBillboard::TrackObjectPresentationBillboard(const XMLNode
|
|||||||
m_node->setPosition(m_init_xyz);
|
m_node->setPosition(m_init_xyz);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ----------------------------------------------------------------------------
|
||||||
void TrackObjectPresentationBillboard::update(float dt)
|
void TrackObjectPresentationBillboard::update(float dt)
|
||||||
{
|
{
|
||||||
if (m_fade_out_when_close)
|
if (m_fade_out_when_close)
|
||||||
@ -554,6 +562,7 @@ void TrackObjectPresentationBillboard::update(float dt)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ----------------------------------------------------------------------------
|
||||||
TrackObjectPresentationBillboard::~TrackObjectPresentationBillboard()
|
TrackObjectPresentationBillboard::~TrackObjectPresentationBillboard()
|
||||||
{
|
{
|
||||||
if (m_node)
|
if (m_node)
|
||||||
@ -613,6 +622,7 @@ TrackObjectPresentationParticles::TrackObjectPresentationParticles(const XMLNode
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ----------------------------------------------------------------------------
|
||||||
TrackObjectPresentationParticles::~TrackObjectPresentationParticles()
|
TrackObjectPresentationParticles::~TrackObjectPresentationParticles()
|
||||||
{
|
{
|
||||||
if (m_emitter)
|
if (m_emitter)
|
||||||
@ -626,6 +636,7 @@ TrackObjectPresentationParticles::~TrackObjectPresentationParticles()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ----------------------------------------------------------------------------
|
||||||
void TrackObjectPresentationParticles::update(float dt)
|
void TrackObjectPresentationParticles::update(float dt)
|
||||||
{
|
{
|
||||||
if (m_emitter != NULL)
|
if (m_emitter != NULL)
|
||||||
@ -634,6 +645,7 @@ void TrackObjectPresentationParticles::update(float dt)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ----------------------------------------------------------------------------
|
||||||
void TrackObjectPresentationParticles::triggerParticles()
|
void TrackObjectPresentationParticles::triggerParticles()
|
||||||
{
|
{
|
||||||
if (m_emitter != NULL)
|
if (m_emitter != NULL)
|
||||||
@ -671,6 +683,7 @@ TrackObjectPresentationLight::TrackObjectPresentationLight(const XMLNode& xml_no
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ----------------------------------------------------------------------------
|
||||||
TrackObjectPresentationLight::~TrackObjectPresentationLight()
|
TrackObjectPresentationLight::~TrackObjectPresentationLight()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
@ -693,6 +706,7 @@ TrackObjectPresentationActionTrigger::TrackObjectPresentationActionTrigger(const
|
|||||||
ItemManager::get()->newItem(m_init_xyz, trigger_distance, this);
|
ItemManager::get()->newItem(m_init_xyz, trigger_distance, this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ----------------------------------------------------------------------------
|
||||||
void TrackObjectPresentationActionTrigger::onTriggerItemApproached(Item* who)
|
void TrackObjectPresentationActionTrigger::onTriggerItemApproached(Item* who)
|
||||||
{
|
{
|
||||||
if (!m_action_active) return;
|
if (!m_action_active) return;
|
||||||
|
Loading…
Reference in New Issue
Block a user