Terrain-specific sfx will now not be cut off when the terrain is left, instead
the sfx will finish. git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/main/trunk@5556 178a84e3-b1eb-0310-8ba1-8eac791a3b58
This commit is contained in:
@@ -43,15 +43,15 @@ class SFXBase
|
||||
public:
|
||||
virtual ~SFXBase() {}
|
||||
virtual void position(const Vec3 &position) = 0;
|
||||
virtual void loop() = 0;
|
||||
virtual void play() = 0;
|
||||
virtual void stop() = 0;
|
||||
virtual void pause() = 0;
|
||||
virtual void resume() = 0;
|
||||
virtual void speed(float factor) = 0;
|
||||
virtual void volume(float gain) = 0;
|
||||
virtual void setLoop(bool status) = 0;
|
||||
virtual void play() = 0;
|
||||
virtual void stop() = 0;
|
||||
virtual void pause() = 0;
|
||||
virtual void resume() = 0;
|
||||
virtual void speed(float factor) = 0;
|
||||
virtual void volume(float gain) = 0;
|
||||
virtual SFXManager::SFXStatus
|
||||
getStatus() = 0;
|
||||
getStatus() = 0;
|
||||
}; // SfxBase
|
||||
|
||||
|
||||
|
||||
@@ -440,6 +440,7 @@ void SFXManager::deleteSFXMapping(const std::string &name)
|
||||
*/
|
||||
void SFXManager::deleteSFX(SFXBase *sfx)
|
||||
{
|
||||
if(sfx) sfx->stop();
|
||||
std::vector<SFXBase*>::iterator i;
|
||||
i=std::find(m_all_sfx.begin(), m_all_sfx.end(), sfx);
|
||||
|
||||
|
||||
@@ -117,11 +117,11 @@ void SFXOpenAL::volume(float gain)
|
||||
//-----------------------------------------------------------------------------
|
||||
/** Loops this sound effect.
|
||||
*/
|
||||
void SFXOpenAL::loop()
|
||||
void SFXOpenAL::setLoop(bool status)
|
||||
{
|
||||
if(!m_ok) return;
|
||||
|
||||
alSourcei(m_soundSource, AL_LOOPING, AL_TRUE);
|
||||
alSourcei(m_soundSource, AL_LOOPING, status ? AL_TRUE : AL_FALSE);
|
||||
SFXManager::checkError("looping");
|
||||
} // loop
|
||||
|
||||
|
||||
@@ -45,7 +45,7 @@ public:
|
||||
SFXOpenAL(ALuint buffer, bool positional, float rolloff, float gain);
|
||||
virtual ~SFXOpenAL();
|
||||
virtual void play();
|
||||
virtual void loop();
|
||||
virtual void setLoop(bool status);
|
||||
virtual void stop();
|
||||
virtual void pause();
|
||||
virtual void resume();
|
||||
|
||||
@@ -122,7 +122,8 @@ Kart::Kart (const std::string& ident, int position,
|
||||
m_crash_sound = sfx_manager->createSoundSource( "crash" );
|
||||
m_goo_sound = sfx_manager->createSoundSource( "goo" );
|
||||
m_skid_sound = sfx_manager->createSoundSource( "skid" );
|
||||
m_terrain_sound = NULL;
|
||||
m_terrain_sound = NULL;
|
||||
m_previous_terrain_sound = NULL;
|
||||
|
||||
if(!m_engine_sound)
|
||||
{
|
||||
@@ -266,7 +267,7 @@ void Kart::createPhysics()
|
||||
if(m_engine_sound)
|
||||
{
|
||||
m_engine_sound->speed(0.6f);
|
||||
m_engine_sound->loop();
|
||||
m_engine_sound->setLoop(true);
|
||||
m_engine_sound->play();
|
||||
}
|
||||
} // createPhysics
|
||||
@@ -278,9 +279,6 @@ void Kart::createPhysics()
|
||||
*/
|
||||
Kart::~Kart()
|
||||
{
|
||||
//stop kart specific sfx
|
||||
if(m_engine_sound) m_engine_sound->stop();
|
||||
if(m_terrain_sound) m_terrain_sound->stop();
|
||||
// Delete all custom sounds (TODO: add back when properly done)
|
||||
/*
|
||||
for (int n = 0; n < SFXManager::NUM_CUSTOMS; n++)
|
||||
@@ -293,8 +291,8 @@ Kart::~Kart()
|
||||
sfx_manager->deleteSFX(m_crash_sound );
|
||||
sfx_manager->deleteSFX(m_skid_sound );
|
||||
sfx_manager->deleteSFX(m_goo_sound );
|
||||
if(m_terrain_sound) sfx_manager->deleteSFX(m_terrain_sound);
|
||||
|
||||
if(m_terrain_sound) sfx_manager->deleteSFX(m_terrain_sound);
|
||||
if(m_previous_terrain_sound) sfx_manager->deleteSFX(m_previous_terrain_sound);
|
||||
if(m_smoke_system) delete m_smoke_system;
|
||||
if(m_water_splash_system) delete m_water_splash_system;
|
||||
if(m_nitro) delete m_nitro;
|
||||
@@ -408,9 +406,12 @@ void Kart::reset()
|
||||
m_last_material = NULL;
|
||||
if(m_terrain_sound)
|
||||
{
|
||||
m_terrain_sound->stop();
|
||||
sfx_manager->deleteSFX(m_terrain_sound);
|
||||
}
|
||||
if(m_previous_terrain_sound)
|
||||
{
|
||||
sfx_manager->deleteSFX(m_previous_terrain_sound);
|
||||
}
|
||||
|
||||
m_controls.m_steer = 0.0f;
|
||||
m_controls.m_accel = 0.0f;
|
||||
@@ -480,7 +481,7 @@ void Kart::finishedRace(float time)
|
||||
m_kart_properties->getKartModel()->setAnimation(KartModel::AF_LOSE_START);
|
||||
|
||||
// Not all karts have a camera
|
||||
if (m_camera) m_camera->setMode(Camera::CM_FINAL);
|
||||
if (m_camera) m_camera->setMode(Camera::CM_REVERSE);
|
||||
|
||||
RaceGUI* m = World::getWorld()->getRaceGUI();
|
||||
if(m)
|
||||
@@ -748,24 +749,45 @@ void Kart::update(float dt)
|
||||
}
|
||||
else if(material)
|
||||
{
|
||||
// Stop a terrain specific sfx if the terrain has changed
|
||||
// If a terrain specific sfx is already being played, when a new
|
||||
// terrain is entered, an old sfx should be finished (once, not
|
||||
// looped anymore of course). The m_terrain_sound is then copied
|
||||
// to a m_previous_terrain_sound, for which looping is disabled.
|
||||
// In case that three sfx needed to be played (i.e. a previous is
|
||||
// playing, a current is playing, and a new terrain with sfx is
|
||||
// entered), the oldest (previous) sfx is stopped and deleted.
|
||||
if(m_last_material!=material)
|
||||
{
|
||||
if(m_terrain_sound)
|
||||
// First stop any previously playing terrain sound
|
||||
// and remove it, sp that m_previous_terrain_sound
|
||||
// can be used again.
|
||||
if(m_previous_terrain_sound)
|
||||
{
|
||||
m_terrain_sound->stop();
|
||||
sfx_manager->deleteSFX(m_terrain_sound);
|
||||
sfx_manager->deleteSFX(m_previous_terrain_sound);
|
||||
}
|
||||
m_previous_terrain_sound = m_terrain_sound;
|
||||
if(m_previous_terrain_sound)
|
||||
m_previous_terrain_sound->setLoop(false);
|
||||
|
||||
const std::string s = material->getSFXName();
|
||||
if(s!="")
|
||||
{
|
||||
m_terrain_sound = sfx_manager->createSoundSource(s);
|
||||
m_terrain_sound->play();
|
||||
m_terrain_sound->loop();
|
||||
m_terrain_sound->setLoop(true);
|
||||
}
|
||||
else
|
||||
m_terrain_sound = NULL;
|
||||
}
|
||||
if(m_previous_terrain_sound &&
|
||||
m_previous_terrain_sound->getStatus()==SFXManager::SFX_STOPED)
|
||||
{
|
||||
// We don't modify the position of m_previous_terrain_sound
|
||||
// anymore, so that it keeps on playing at the place where the
|
||||
// kart left the material.
|
||||
sfx_manager->deleteSFX(m_previous_terrain_sound);
|
||||
m_previous_terrain_sound = NULL;
|
||||
}
|
||||
if(m_terrain_sound)
|
||||
{
|
||||
m_terrain_sound->position(getXYZ());
|
||||
|
||||
@@ -187,6 +187,9 @@ private:
|
||||
SFXBase *m_engine_sound;
|
||||
SFXBase *m_crash_sound;
|
||||
SFXBase *m_terrain_sound;
|
||||
/** A pointer to the previous terrain sound needs to be saved so that an
|
||||
* 'older' sfx can be finished and an abrupt end of the sfx is avoided. */
|
||||
SFXBase *m_previous_terrain_sound;
|
||||
SFXBase *m_skid_sound;
|
||||
SFXBase *m_goo_sound;
|
||||
float m_time_last_crash;
|
||||
|
||||
Reference in New Issue
Block a user