Still work on #886.

- fixed resume sound after that when speed was near to 0 (broken in previous commit)
- pause sound while explosion animation

Tested on bridges in hacienda and snowmountain.

git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/main/trunk@14171 178a84e3-b1eb-0310-8ba1-8eac791a3b58
This commit is contained in:
deveee 2013-09-29 22:19:48 +00:00
parent b1c375528e
commit 4673c41987
3 changed files with 13 additions and 20 deletions

View File

@ -938,8 +938,9 @@ void Material::initParticlesEffect(const XMLNode *node)
/** Adjusts the pitch of the given sfx depending on the given speed. /** Adjusts the pitch of the given sfx depending on the given speed.
* \param sfx The sound effect to adjust. * \param sfx The sound effect to adjust.
* \param speed The speed of the kart. * \param speed The speed of the kart.
* \param should_be_paused Pause for other reasons, i.e. kart is rescued.
*/ */
void Material::setSFXSpeed(SFXBase *sfx, float speed) const void Material::setSFXSpeed(SFXBase *sfx, float speed, bool should_be_paused) const
{ {
// Still make a sound when driving backwards on the material. // Still make a sound when driving backwards on the material.
if (speed < 0) speed = -speed; if (speed < 0) speed = -speed;
@ -947,14 +948,14 @@ void Material::setSFXSpeed(SFXBase *sfx, float speed) const
// If we paused it due to too low speed earlier, we can continue now. // If we paused it due to too low speed earlier, we can continue now.
if (sfx->getStatus() == SFXManager::SFX_PAUSED) if (sfx->getStatus() == SFXManager::SFX_PAUSED)
{ {
if (speed<m_sfx_min_speed) return; if (speed<m_sfx_min_speed || should_be_paused == 1) return;
// TODO: Do we first need to stop the sound completely so it // TODO: Do we first need to stop the sound completely so it
// starts over? // starts over?
sfx->play(); sfx->play();
} }
else if (sfx->getStatus() == SFXManager::SFX_PLAYING) else if (sfx->getStatus() == SFXManager::SFX_PLAYING)
{ {
if (speed<m_sfx_min_speed) if (speed<m_sfx_min_speed || should_be_paused == 1)
{ {
// Pausing it to differentiate with sounds that ended etc // Pausing it to differentiate with sounds that ended etc
sfx->pause(); sfx->pause();

View File

@ -253,7 +253,7 @@ public:
bool complain_if_not_found=true); bool complain_if_not_found=true);
~Material (); ~Material ();
void setSFXSpeed(SFXBase *sfx, float speed) const; void setSFXSpeed(SFXBase *sfx, float speed, bool should_be_paused) const;
void setMaterialProperties(video::SMaterial *m, scene::IMeshBuffer* mb); void setMaterialProperties(video::SMaterial *m, scene::IMeshBuffer* mb);
void adjustForFog(scene::ISceneNode* parent, video::SMaterial *m, bool use_fog) const; void adjustForFog(scene::ISceneNode* parent, video::SMaterial *m, bool use_fog) const;

View File

@ -1406,20 +1406,6 @@ void Kart::handleMaterialSFX(const Material *material)
} }
} }
if(m_terrain_sound)
{
if((m_flying || dynamic_cast<RescueAnimation*>(getKartAnimation())) &&
m_terrain_sound->getStatus()!=SFXManager::SFX_PAUSED)
{
m_terrain_sound->pause();
}
else if(m_terrain_sound->getStatus()==SFXManager::SFX_PAUSED &&
!m_flying && !dynamic_cast<RescueAnimation*>(getKartAnimation()))
{
m_terrain_sound->resume();
}
}
if(m_previous_terrain_sound && if(m_previous_terrain_sound &&
m_previous_terrain_sound->getStatus()==SFXManager::SFX_STOPPED) m_previous_terrain_sound->getStatus()==SFXManager::SFX_STOPPED)
{ {
@ -1430,12 +1416,18 @@ void Kart::handleMaterialSFX(const Material *material)
m_previous_terrain_sound = NULL; m_previous_terrain_sound = NULL;
} }
bool m_schedule_pause = m_flying ||
dynamic_cast<RescueAnimation*>(getKartAnimation()) ||
dynamic_cast<ExplosionAnimation*>(getKartAnimation());
// terrain sound is not necessarily a looping sound so check its status before // terrain sound is not necessarily a looping sound so check its status before
// setting its speed, to avoid 'ressuscitating' sounds that had already stopped // setting its speed, to avoid 'ressuscitating' sounds that had already stopped
if(m_terrain_sound && m_terrain_sound->getStatus()==SFXManager::SFX_PLAYING) if(m_terrain_sound &&
(m_terrain_sound->getStatus()==SFXManager::SFX_PLAYING ||
m_terrain_sound->getStatus()==SFXManager::SFX_PAUSED))
{ {
m_terrain_sound->position(getXYZ()); m_terrain_sound->position(getXYZ());
material->setSFXSpeed(m_terrain_sound, m_speed); material->setSFXSpeed(m_terrain_sound, m_speed, m_schedule_pause);
} }
} // handleMaterialSFX } // handleMaterialSFX