Moved SFXStatus enum to SFXBase.

This commit is contained in:
hiker 2014-10-14 08:05:04 +11:00
parent 5cf7b0dca9
commit 665f146923
17 changed files with 100 additions and 94 deletions

View File

@ -23,7 +23,6 @@
#include "audio/sfx_base.hpp"
/**
* \brief Dummy sound when ogg or openal aren't available
* \ingroup audio
@ -50,7 +49,7 @@ public:
virtual void deleteSFX() { delete this; }
virtual void speed(float factor) {}
virtual void volume(float gain) {}
virtual SFXManager::SFXStatus getStatus() { return SFXManager::SFX_STOPPED; }
virtual SFXStatus getStatus() { return SFX_STOPPED; }
virtual void onSoundEnabledBack() {}
virtual void setRolloff(float rolloff) {}
virtual bool isPlaying() { return false; }

View File

@ -42,6 +42,13 @@ class Vec3;
class SFXBase : public NoCopy
{
public:
/** Status of a sound effect. */
enum SFXStatus
{
SFX_UNKNOWN = -1, SFX_STOPPED = 0, SFX_PAUSED = 1, SFX_PLAYING = 2,
SFX_INITIAL = 3
};
virtual ~SFXBase() {}
/** Late creation, if SFX was initially disabled */
@ -64,9 +71,9 @@ public:
virtual void onSoundEnabledBack() = 0;
virtual void setRolloff(float rolloff) = 0;
virtual const SFXBuffer* getBuffer() const = 0;
virtual SFXManager::SFXStatus getStatus() = 0;
virtual SFXStatus getStatus() = 0;
}; // SfxBase
}; // SFXBase
#endif // HEADER_SFX_HPP

View File

@ -167,6 +167,10 @@ SFXManager::~SFXManager()
*/
void SFXManager::queue(SFXCommands command, SFXBase *sfx)
{
// Don't add sfx that are either not working correctly (e.g. because sfx
// are disabled);
if(sfx && sfx->getStatus()==SFXBase::SFX_UNKNOWN) return;
SFXCommand *sfx_command = new SFXCommand(command, sfx);
m_sfx_commands.lock();
@ -576,9 +580,7 @@ void SFXManager::resumeAll()
for (std::vector<SFXBase*>::iterator i =m_all_sfx.getData().begin();
i!=m_all_sfx.getData().end(); i++)
{
SFXStatus status = (*i)->getStatus();
// Initial happens when
if (status==SFX_PAUSED) (*i)->resume();
(*i)->resume();
} // for i in m_all_sfx
m_all_sfx.unlock();
} // resumeAll

View File

@ -89,13 +89,6 @@ public:
NUM_CUSTOMS
};
/** Status of a sound effect. */
enum SFXStatus
{
SFX_UNKNOWN = -1, SFX_STOPPED = 0, SFX_PAUSED = 1, SFX_PLAYING = 2,
SFX_INITIAL = 3
};
private:
/** Data structure for the queue, which stores a sfx and the command to

View File

@ -40,16 +40,16 @@
SFXOpenAL::SFXOpenAL(SFXBuffer* buffer, bool positional, float gain, bool ownsBuffer) : SFXBase()
{
m_soundBuffer = buffer;
m_soundSource = 0;
m_ok = false;
m_is_playing = false;
m_positional = positional;
m_defaultGain = gain;
m_loop = false;
m_gain = -1.0f;
m_master_gain = 1.0f;
m_owns_buffer = ownsBuffer;
m_sound_buffer = buffer;
m_sound_source = 0;
m_ok = false;
m_is_playing = false;
m_positional = positional;
m_defaultGain = gain;
m_loop = false;
m_gain = -1.0f;
m_master_gain = 1.0f;
m_owns_buffer = ownsBuffer;
// Don't initialise anything else if the sfx manager was not correctly
// initialised. First of all the initialisation will not work, and it
@ -66,13 +66,13 @@ SFXOpenAL::~SFXOpenAL()
{
if (m_ok)
{
alDeleteSources(1, &m_soundSource);
alDeleteSources(1, &m_sound_source);
}
if (m_owns_buffer && m_soundBuffer != NULL)
if (m_owns_buffer && m_sound_buffer != NULL)
{
m_soundBuffer->unload();
delete m_soundBuffer;
m_sound_buffer->unload();
delete m_sound_buffer;
}
} // ~SFXOpenAL
@ -80,40 +80,40 @@ SFXOpenAL::~SFXOpenAL()
bool SFXOpenAL::init()
{
alGenSources(1, &m_soundSource );
alGenSources(1, &m_sound_source );
if (!SFXManager::checkError("generating a source")) return false;
assert( alIsBuffer(m_soundBuffer->getBufferID()) );
assert( alIsSource(m_soundSource) );
assert( alIsBuffer(m_sound_buffer->getBufferID()) );
assert( alIsSource(m_sound_source) );
//Log::info("SFXOpenAL", "Setting a source with buffer, %p, rolloff %f, gain = %f, position = %s",
// m_soundBuffer, rolloff, m_defaultGain, positional ? "true" : "false");
// m_sound_buffer, rolloff, m_defaultGain, positional ? "true" : "false");
alSourcei (m_soundSource, AL_BUFFER, m_soundBuffer->getBufferID());
alSourcei (m_sound_source, AL_BUFFER, m_sound_buffer->getBufferID());
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);
alSource3f(m_sound_source, AL_POSITION, 0.0, 0.0, 0.0);
alSource3f(m_sound_source, AL_VELOCITY, 0.0, 0.0, 0.0);
alSource3f(m_sound_source, AL_DIRECTION, 0.0, 0.0, 0.0);
alSourcef (m_soundSource, AL_ROLLOFF_FACTOR, m_soundBuffer->getRolloff());
alSourcef (m_soundSource, AL_MAX_DISTANCE, m_soundBuffer->getMaxDist());
alSourcef (m_sound_source, AL_ROLLOFF_FACTOR, m_sound_buffer->getRolloff());
alSourcef (m_sound_source, AL_MAX_DISTANCE, m_sound_buffer->getMaxDist());
if (m_gain < 0.0f)
{
alSourcef (m_soundSource, AL_GAIN, m_defaultGain * m_master_gain);
alSourcef (m_sound_source, AL_GAIN, m_defaultGain * m_master_gain);
}
else
{
alSourcef (m_soundSource, AL_GAIN, m_gain * m_master_gain);
alSourcef (m_sound_source, AL_GAIN, m_gain * m_master_gain);
}
if (m_positional) alSourcei (m_soundSource, AL_SOURCE_RELATIVE, AL_FALSE);
else alSourcei (m_soundSource, AL_SOURCE_RELATIVE, AL_TRUE);
if (m_positional) alSourcei (m_sound_source, AL_SOURCE_RELATIVE, AL_FALSE);
else alSourcei (m_sound_source, AL_SOURCE_RELATIVE, AL_TRUE);
alSourcei(m_soundSource, AL_LOOPING, m_loop ? AL_TRUE : AL_FALSE);
alSourcei(m_sound_source, AL_LOOPING, m_loop ? AL_TRUE : AL_FALSE);
m_ok = SFXManager::checkError("setting up the source");
@ -137,7 +137,7 @@ void SFXOpenAL::speed(float factor)
{
factor = 0.5f;
}
alSourcef(m_soundSource,AL_PITCH,factor);
alSourcef(m_sound_source,AL_PITCH,factor);
SFXManager::checkError("changing the speed");
} // speed
@ -151,7 +151,7 @@ void SFXOpenAL::volume(float gain)
if(!m_ok) return;
alSourcef(m_soundSource, AL_GAIN, m_gain * m_master_gain);
alSourcef(m_sound_source, AL_GAIN, m_gain * m_master_gain);
SFXManager::checkError("setting volume");
} // volume
@ -163,7 +163,7 @@ void SFXOpenAL::setMasterVolume(float gain)
if(!m_ok) return;
alSourcef(m_soundSource, AL_GAIN,
alSourcef(m_sound_source, AL_GAIN,
(m_gain < 0.0f ? m_defaultGain : m_gain) * m_master_gain);
SFXManager::checkError("setting volume");
} //setMasterVolume
@ -177,7 +177,7 @@ void SFXOpenAL::setLoop(bool status)
if(!m_ok) return;
alSourcei(m_soundSource, AL_LOOPING, status ? AL_TRUE : AL_FALSE);
alSourcei(m_sound_source, AL_LOOPING, status ? AL_TRUE : AL_FALSE);
SFXManager::checkError("looping");
} // loop
@ -197,8 +197,8 @@ void SFXOpenAL::reallyStopNow()
m_is_playing = false;
m_loop = false;
alSourcei(m_soundSource, AL_LOOPING, AL_FALSE);
alSourceStop(m_soundSource);
alSourcei(m_sound_source, AL_LOOPING, AL_FALSE);
alSourceStop(m_sound_source);
SFXManager::checkError("stoping");
} // reallyStopNow
@ -217,7 +217,7 @@ void SFXOpenAL::pause()
void SFXOpenAL::reallyPauseNow()
{
if(!m_ok) return;
alSourcePause(m_soundSource);
alSourcePause(m_sound_source);
SFXManager::checkError("pausing");
} // reallyPauseNow
@ -243,7 +243,8 @@ void SFXOpenAL::reallyResumeNow()
if (!m_ok) return;
}
alSourcePlay(m_soundSource);
if(getStatus()==SFX_PAUSED)
alSourcePlay(m_sound_source);
SFXManager::checkError("resuming");
} // reallyResumeNow
@ -285,7 +286,7 @@ void SFXOpenAL::reallyPlayNow()
if (!m_ok) return;
}
alSourcePlay(m_soundSource);
alSourcePlay(m_sound_source);
SFXManager::checkError("playing");
} // reallyPlayNow
@ -307,7 +308,7 @@ void SFXOpenAL::position(const Vec3 &position)
return;
if (!m_ok)
{
Log::warn("SFX", "Position called on non-ok SFX <%s>", m_soundBuffer->getFileName().c_str());
Log::warn("SFX", "Position called on non-ok SFX <%s>", m_sound_buffer->getFileName().c_str());
return;
}
if (!m_positional)
@ -322,16 +323,16 @@ void SFXOpenAL::position(const Vec3 &position)
return;
}
alSource3f(m_soundSource, AL_POSITION,
alSource3f(m_sound_source, AL_POSITION,
(float)position.getX(), (float)position.getY(), (float)position.getZ());
if (SFXManager::get()->getListenerPos().distance(position) > m_soundBuffer->getMaxDist())
if (SFXManager::get()->getListenerPos().distance(position) > m_sound_buffer->getMaxDist())
{
alSourcef(m_soundSource, AL_GAIN, 0);
alSourcef(m_sound_source, AL_GAIN, 0);
}
else
{
alSourcef(m_soundSource, AL_GAIN, (m_gain < 0.0f ? m_defaultGain : m_gain) * m_master_gain);
alSourcef(m_sound_source, AL_GAIN, (m_gain < 0.0f ? m_defaultGain : m_gain) * m_master_gain);
}
SFXManager::checkError("positioning");
@ -340,19 +341,19 @@ void SFXOpenAL::position(const Vec3 &position)
//-----------------------------------------------------------------------------
/** Returns the status of this sound effect.
*/
SFXManager::SFXStatus SFXOpenAL::getStatus()
SFXBase::SFXStatus SFXOpenAL::getStatus()
{
if(!m_ok) return SFXManager::SFX_UNKNOWN;
if(!m_ok) return SFX_UNKNOWN;
int state = 0;
alGetSourcei(m_soundSource, AL_SOURCE_STATE, &state);
alGetSourcei(m_sound_source, AL_SOURCE_STATE, &state);
switch(state)
{
case AL_STOPPED: return SFXManager::SFX_STOPPED;
case AL_PLAYING: return SFXManager::SFX_PLAYING;
case AL_PAUSED: return SFXManager::SFX_PAUSED;
case AL_INITIAL: return SFXManager::SFX_INITIAL;
default: return SFXManager::SFX_UNKNOWN;
case AL_STOPPED: return SFX_STOPPED;
case AL_PLAYING: return SFX_PLAYING;
case AL_PAUSED: return SFX_PAUSED;
case AL_INITIAL: return SFX_INITIAL;
default: return SFX_UNKNOWN;
}
} // getStatus
@ -365,10 +366,10 @@ void SFXOpenAL::onSoundEnabledBack()
if (!m_ok) init();
if (m_ok)
{
alSourcef(m_soundSource, AL_GAIN, 0);
alSourcef(m_sound_source, AL_GAIN, 0);
play();
pause();
alSourcef(m_soundSource, AL_GAIN, (m_gain < 0.0f ? m_defaultGain : m_gain) * m_master_gain);
alSourcef(m_sound_source, AL_GAIN, (m_gain < 0.0f ? m_defaultGain : m_gain) * m_master_gain);
}
}
}
@ -377,7 +378,7 @@ void SFXOpenAL::onSoundEnabledBack()
void SFXOpenAL::setRolloff(float rolloff)
{
alSourcef (m_soundSource, AL_ROLLOFF_FACTOR, rolloff);
alSourcef (m_sound_source, AL_ROLLOFF_FACTOR, rolloff);
}
#endif //if HAVE_OGGVORBIS

View File

@ -28,7 +28,6 @@
# include <AL/al.h>
#endif
#include "audio/sfx_base.hpp"
#include "audio/sfx_manager.hpp"
#include "utils/leak_check.hpp"
/**
@ -38,8 +37,12 @@
class SFXOpenAL : public SFXBase
{
private:
SFXBuffer* m_soundBuffer; //!< Buffers hold sound data.
ALuint m_soundSource; //!< Sources are points emitting sound.
/** Buffers hold sound data. */
SFXBuffer* m_sound_buffer;
/** Sources are points emitting sound. */
ALuint m_sound_source;
bool m_ok;
bool m_positional;
float m_defaultGain;
@ -87,11 +90,11 @@ public:
virtual void position(const Vec3 &position);
virtual void volume(float gain);
virtual void setMasterVolume(float gain);
virtual SFXManager::SFXStatus getStatus();
virtual SFXStatus getStatus();
virtual void onSoundEnabledBack();
virtual void setRolloff(float rolloff);
virtual const SFXBuffer* getBuffer() const { return m_soundBuffer; }
virtual const SFXBuffer* getBuffer() const { return m_sound_buffer; }
LEAK_CHECK()

View File

@ -64,7 +64,7 @@ void HitSFX::setPlayerKartHit()
*/
bool HitSFX::updateAndDelete(float dt)
{
SFXManager::SFXStatus status = m_sfx->getStatus();
if(status==SFXManager::SFX_INITIAL) return false;
return status!= SFXManager::SFX_PLAYING;
SFXBase::SFXStatus status = m_sfx->getStatus();
if(status==SFXBase::SFX_INITIAL) return false;
return status!= SFXBase::SFX_PLAYING;
} // updateAndDelete

View File

@ -646,14 +646,14 @@ void Material::setSFXSpeed(SFXBase *sfx, float speed, bool should_be_paused) con
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 (sfx->getStatus() == SFXBase::SFX_PAUSED)
{
if (speed<m_sfx_min_speed || should_be_paused == 1) return;
// TODO: Do we first need to stop the sound completely so it
// starts over?
sfx->play();
}
else if (sfx->getStatus() == SFXManager::SFX_PLAYING)
else if (sfx->getStatus() == SFXBase::SFX_PLAYING)
{
if (speed<m_sfx_min_speed || should_be_paused == 1)
{

View File

@ -172,7 +172,7 @@ bool Bowling::updateAndDelete(float dt)
return true;
}
if (m_roll_sfx->getStatus()==SFXManager::SFX_PLAYING)
if (m_roll_sfx->getStatus()==SFXBase::SFX_PLAYING)
m_roll_sfx->position(getXYZ());
return false;

View File

@ -107,7 +107,7 @@ RubberBall::RubberBall(AbstractKart *kart)
*/
RubberBall::~RubberBall()
{
if(m_ping_sfx->getStatus()==SFXManager::SFX_PLAYING)
if(m_ping_sfx->getStatus()==SFXBase::SFX_PLAYING)
m_ping_sfx->stop();
m_ping_sfx->deleteSFX();
} // ~RubberBall
@ -541,7 +541,7 @@ float RubberBall::updateHeight()
if(m_height_timer>m_interval)
{
m_height_timer -= m_interval;
if(m_ping_sfx->getStatus()!=SFXManager::SFX_PLAYING)
if(m_ping_sfx->getStatus()!=SFXBase::SFX_PLAYING)
{
m_ping_sfx->position(getXYZ());
m_ping_sfx->play();

View File

@ -439,7 +439,7 @@ void PlayerController::handleZipper(bool play_sound)
// Only play a zipper sound if it's not already playing, and
// if the material has changed (to avoid machine gun effect
// on conveyor belt zippers).
if (play_sound || (m_wee_sound->getStatus() != SFXManager::SFX_PLAYING &&
if (play_sound || (m_wee_sound->getStatus() != SFXBase::SFX_PLAYING &&
m_kart->getMaterial()!=m_kart->getLastMaterial() ) )
{
m_wee_sound->play();

View File

@ -1079,6 +1079,7 @@ void Kart::eliminate()
*/
void Kart::update(float dt)
{
Log::verbose("sfx", "%s crash state %d", getIdent().c_str(), m_crash_sound->getStatus());
if ( UserConfigParams::m_graphical_effects )
{
// update star effect (call will do nothing if stars are not activated)
@ -1461,7 +1462,7 @@ void Kart::handleMaterialSFX(const Material *material)
}
if(m_previous_terrain_sound &&
m_previous_terrain_sound->getStatus()==SFXManager::SFX_STOPPED)
m_previous_terrain_sound->getStatus()==SFXBase::SFX_STOPPED)
{
// We don't modify the position of m_previous_terrain_sound
// anymore, so that it keeps on playing at the place where the
@ -1477,8 +1478,8 @@ 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 ||
m_terrain_sound->getStatus()==SFXManager::SFX_PAUSED))
(m_terrain_sound->getStatus()==SFXBase::SFX_PLAYING ||
m_terrain_sound->getStatus()==SFXBase::SFX_PAUSED))
{
m_terrain_sound->position(getXYZ());
material->setSFXSpeed(m_terrain_sound, m_speed, m_schedule_pause);
@ -1589,7 +1590,7 @@ void Kart::handleMaterialGFX()
const std::string &s = surface_material->getSFXName();
if (s != "" && !dynamic_cast<RescueAnimation*>(getKartAnimation())&&
(m_terrain_sound == NULL ||
m_terrain_sound->getStatus() == SFXManager::SFX_STOPPED))
m_terrain_sound->getStatus() == SFXBase::SFX_STOPPED))
{
if (m_previous_terrain_sound) m_previous_terrain_sound->deleteSFX();
m_previous_terrain_sound = m_terrain_sound;
@ -1892,12 +1893,12 @@ void Kart::crashed(const Material* m, AbstractKart *k)
// it's not already playing.
if (isShielded() || (k != NULL && k->isShielded()))
{
if (m_boing_sound->getStatus() != SFXManager::SFX_PLAYING)
if (m_boing_sound->getStatus() != SFXBase::SFX_PLAYING)
m_boing_sound->play();
}
else
{
if(m_crash_sound->getStatus() != SFXManager::SFX_PLAYING)
if(m_crash_sound->getStatus() != SFXBase::SFX_PLAYING)
m_crash_sound->play();
}
}

View File

@ -155,7 +155,7 @@ void LinearWorld::update(float dt)
WorldWithRank::update(dt);
if (m_last_lap_sfx_playing &&
m_last_lap_sfx->getStatus() != SFXManager::SFX_PLAYING)
m_last_lap_sfx->getStatus() != SFXBase::SFX_PLAYING)
{
if(music_manager->getCurrentMusic())
music_manager->getCurrentMusic()->resetTemporaryVolume();

View File

@ -121,7 +121,7 @@ void SoccerWorld::reset()
}
if (m_goal_sound != NULL &&
m_goal_sound->getStatus() == SFXManager::SFX_PLAYING)
m_goal_sound->getStatus() == SFXBase::SFX_PLAYING)
{
m_goal_sound->stop();
}

View File

@ -162,7 +162,7 @@ void WorldStatus::update(const float dt)
// ... phase. Since the sound effect is about 3 seconds
// long, we use the aux timer to force the next phase
// after 3.5 seconds.
if (m_track_intro_sound->getStatus() == SFXManager::SFX_PLAYING &&
if (m_track_intro_sound->getStatus() == SFXBase::SFX_PLAYING &&
m_auxiliary_timer < 3.5f)
return;

View File

@ -116,7 +116,7 @@ void RaceResultGUI::tearDown()
m_font->setMonospaceDigits(m_was_monospace);
if (m_finish_sound != NULL &&
m_finish_sound->getStatus() == SFXManager::SFX_PLAYING)
m_finish_sound->getStatus() == SFXBase::SFX_PLAYING)
{
m_finish_sound->stop();
}
@ -600,7 +600,7 @@ void RaceResultGUI::onUpdate(float dt)
renderGlobal(dt);
if (m_finish_sound != NULL &&
m_finish_sound->getStatus() != SFXManager::SFX_PLAYING)
m_finish_sound->getStatus() != SFXBase::SFX_PLAYING)
{
try
{

View File

@ -458,7 +458,7 @@ void TrackObjectPresentationSound::update(float dt)
// ----------------------------------------------------------------------------
void TrackObjectPresentationSound::onTriggerItemApproached(Item* who)
{
if (m_sound != NULL && m_sound->getStatus() != SFXManager::SFX_PLAYING)
if (m_sound != NULL && m_sound->getStatus() != SFXBase::SFX_PLAYING)
{
m_sound->play();
}