Fix #373 + small bug introduced by r11160

* Make sound work when driving back by taking absolute value of
   the speed.
 * r11160 made the sound not restart at all when coming to a halt and
   then speeding up again on materials (eg bridge in Coyote Canyon).
   Fix this by instead of stopping the sound, pausing it and allowing
   restarting only if the material sound was paused. Don't allow when
   stopped to take into account that music can be in stopped state
   when it's non-looping and it had been played once already.


git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/main/trunk@11271 178a84e3-b1eb-0310-8ba1-8eac791a3b58
This commit is contained in:
wardje 2012-06-02 21:28:32 +00:00
parent dfd945bc77
commit 4c3e6d864d
2 changed files with 22 additions and 12 deletions

View File

@ -807,16 +807,23 @@ void Material::initParticlesEffect(const XMLNode *node)
*/
void Material::setSFXSpeed(SFXBase *sfx, float speed) const
{
if(sfx->getStatus()==SFXManager::SFX_STOPPED)
// Still make a sound when driving backwards on the material.
if (speed < 0) speed = -speed;
// If we paused it due to too low speed earlier, we can continue now.
if (sfx->getStatus() == SFXManager::SFX_PAUSED)
{
if (speed<m_sfx_min_speed) return;
// TODO: Do we first need to stop the sound completely so it
// starts over?
sfx->play();
}
else if (sfx->getStatus() == SFXManager::SFX_PLAYING)
{
if (speed<m_sfx_min_speed)
{
sfx->stop();
// Pausing it to differentiate with sounds that ended etc
sfx->pause();
return;
}
}

View File

@ -1215,7 +1215,7 @@ void Kart::handleMaterialSFX(const Material *material)
if(getLastMaterial()!=material)
{
// First stop any previously playing terrain sound
// and remove it, sp that m_previous_terrain_sound
// and remove it, so that m_previous_terrain_sound
// can be used again.
if(m_previous_terrain_sound)
{
@ -1230,8 +1230,9 @@ void Kart::handleMaterialSFX(const Material *material)
{
m_terrain_sound = sfx_manager->createSoundSource(s);
// in multiplayer mode, sounds are NOT positional (because we have multiple listeners)
// so the sounds of all AIs would be constantly heard. So silence AI karts.
// In multiplayer mode sounds are NOT positional, because we have
// multiple listeners. This would make the sounds of all AIs be
// audible at all times. So silence AI karts.
if (race_manager->getNumLocalPlayers() > 1)
{
if (!m_controller->isPlayerController())
@ -1260,7 +1261,9 @@ void Kart::handleMaterialSFX(const Material *material)
// terrain sound is not necessarily a looping sound so check its status before
// 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());
material->setSFXSpeed(m_terrain_sound, m_speed);
@ -1269,7 +1272,7 @@ void Kart::handleMaterialSFX(const Material *material)
} // handleMaterialSFX
//-----------------------------------------------------------------------------
/** Handles material specific sfx, mostly particle effects. Particle
/** Handles material specific GFX, mostly particle effects. Particle
* effects can be triggered by two different situations: either
* because a kart drives on top of a terrain with a special effect,
* or because the kart is driving or falling under a surface (e.g.