Add specifying SFX rolloff type
git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/main/trunk@11356 178a84e3-b1eb-0310-8ba1-8eac791a3b58
This commit is contained in:
parent
c77be89a27
commit
1574ff472d
@ -38,18 +38,20 @@
|
||||
|
||||
SFXBuffer::SFXBuffer(const std::string& file,
|
||||
bool positional,
|
||||
ALuint rolloffType,
|
||||
float rolloff,
|
||||
float gain)
|
||||
{
|
||||
m_buffer = 0;
|
||||
m_gain = 1.0f;
|
||||
m_rolloff = 0.1f;
|
||||
m_loaded = false;
|
||||
m_file = file;
|
||||
m_buffer = 0;
|
||||
m_gain = 1.0f;
|
||||
m_rolloff = 0.1f;
|
||||
m_loaded = false;
|
||||
m_file = file;
|
||||
|
||||
m_rolloff = rolloff;
|
||||
m_positional = positional;
|
||||
m_gain = gain;
|
||||
m_rolloff = rolloff;
|
||||
m_positional = positional;
|
||||
m_gain = gain;
|
||||
m_rolloffType = rolloffType;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
@ -57,16 +59,27 @@ SFXBuffer::SFXBuffer(const std::string& file,
|
||||
SFXBuffer::SFXBuffer(const std::string& file,
|
||||
const XMLNode* node)
|
||||
{
|
||||
m_buffer = 0;
|
||||
m_gain = 1.0f;
|
||||
m_rolloff = 0.1f;
|
||||
m_positional = false;
|
||||
m_loaded = false;
|
||||
m_file = file;
|
||||
m_buffer = 0;
|
||||
m_gain = 1.0f;
|
||||
m_rolloff = 0.1f;
|
||||
m_positional = false;
|
||||
m_loaded = false;
|
||||
m_file = file;
|
||||
m_rolloffType = AL_INVERSE_DISTANCE_CLAMPED;
|
||||
|
||||
node->get("rolloff", &m_rolloff );
|
||||
node->get("positional", &m_positional );
|
||||
node->get("volume", &m_gain );
|
||||
|
||||
std::string rolloffType;
|
||||
node->get("rolloff_type", &rolloffType);
|
||||
|
||||
if (rolloffType == "inverse")
|
||||
m_rolloffType = AL_INVERSE_DISTANCE_CLAMPED;
|
||||
else if (rolloffType == "linear")
|
||||
m_rolloffType = AL_LINEAR_DISTANCE_CLAMPED;
|
||||
else if (rolloffType != "")
|
||||
fprintf(stderr, "[SfxBuffer] Unknown rolloff type '%s'\n", rolloffType.c_str());
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
|
@ -55,15 +55,17 @@ private:
|
||||
bool m_positional;
|
||||
float m_rolloff;
|
||||
float m_gain;
|
||||
ALuint m_rolloffType;
|
||||
|
||||
bool loadVorbisBuffer(const std::string &name, ALuint buffer);
|
||||
|
||||
public:
|
||||
|
||||
SFXBuffer(const std::string& file,
|
||||
bool positional,
|
||||
float rolloff,
|
||||
float gain);
|
||||
SFXBuffer(const std::string& file,
|
||||
bool positional,
|
||||
ALuint rolloffType,
|
||||
float rolloff,
|
||||
float gain);
|
||||
|
||||
SFXBuffer(const std::string& file,
|
||||
const XMLNode* node);
|
||||
@ -99,6 +101,7 @@ public:
|
||||
|
||||
void setPositional(bool positional) { m_positional = positional; }
|
||||
|
||||
ALuint getRolloffType() const { return m_rolloffType; }
|
||||
|
||||
};
|
||||
|
||||
|
@ -184,11 +184,12 @@ void SFXManager::loadSfx()
|
||||
SFXBuffer* SFXManager::addSingleSfx(const std::string &sfx_name,
|
||||
const std::string &sfx_file,
|
||||
bool positional,
|
||||
ALuint rolloff_type,
|
||||
float rolloff,
|
||||
float gain)
|
||||
{
|
||||
|
||||
SFXBuffer* buffer = new SFXBuffer(sfx_file, positional, rolloff, gain);
|
||||
SFXBuffer* buffer = new SFXBuffer(sfx_file, positional, rolloff_type, rolloff, gain);
|
||||
|
||||
m_all_sfx_types[sfx_name] = buffer;
|
||||
|
||||
@ -249,6 +250,7 @@ SFXBuffer* SFXManager::loadSingleSfx(const XMLNode* node,
|
||||
|
||||
return addSingleSfx(sfx_name, full_path,
|
||||
tmpbuffer.isPositional(),
|
||||
tmpbuffer.getRolloffType(),
|
||||
tmpbuffer.getRolloff(),
|
||||
tmpbuffer.getGain());
|
||||
|
||||
|
@ -109,6 +109,7 @@ public:
|
||||
SFXBuffer* addSingleSfx(const std::string &sfx_name,
|
||||
const std::string &filename,
|
||||
bool positional,
|
||||
ALuint rolloff_type,
|
||||
float rolloff,
|
||||
float gain);
|
||||
|
||||
|
@ -44,6 +44,7 @@ SFXOpenAL::SFXOpenAL(SFXBuffer* buffer, bool positional, float gain) : SFXBase()
|
||||
m_defaultGain = gain;
|
||||
m_loop = false;
|
||||
m_gain = -1.0f;
|
||||
m_rolloffType = buffer->getRolloffType();
|
||||
|
||||
// Don't initialise anything else if the sfx manager was not correctly
|
||||
// initialised. First of all the initialisation will not work, and it
|
||||
@ -84,7 +85,18 @@ bool SFXOpenAL::init()
|
||||
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);
|
||||
alSourcef (m_soundSource, AL_ROLLOFF_FACTOR, m_soundBuffer->getRolloff());
|
||||
|
||||
alDistanceModel(m_rolloffType);
|
||||
|
||||
if (m_rolloffType == AL_INVERSE_DISTANCE_CLAMPED)
|
||||
{
|
||||
alSourcef (m_soundSource, AL_ROLLOFF_FACTOR, m_soundBuffer->getRolloff());
|
||||
}
|
||||
else if (m_rolloffType == AL_LINEAR_DISTANCE_CLAMPED)
|
||||
{
|
||||
alSourcef (m_soundSource, AL_MAX_DISTANCE, m_soundBuffer->getRolloff());
|
||||
}
|
||||
|
||||
|
||||
if (m_gain < 0.0f)
|
||||
{
|
||||
|
@ -43,6 +43,8 @@ private:
|
||||
bool m_positional;
|
||||
float m_defaultGain;
|
||||
|
||||
int m_rolloffType;
|
||||
|
||||
/** The OpenAL source contains this info, but if audio is disabled initially then
|
||||
the sound source won't be created and we'll be left with no clue when enabling
|
||||
sounds later */
|
||||
|
@ -87,6 +87,17 @@ TrackObject::TrackObject(const XMLNode &xml_node)
|
||||
|
||||
xml_node.get("conditions", &m_trigger_condition);
|
||||
|
||||
ALuint rolloffType = AL_INVERSE_DISTANCE_CLAMPED;
|
||||
std::string rolloffTypeStr;
|
||||
xml_node.get("rolloff_type", &rolloffTypeStr );
|
||||
|
||||
if (rolloffTypeStr == "inverse")
|
||||
rolloffType = AL_INVERSE_DISTANCE_CLAMPED;
|
||||
else if (rolloffTypeStr == "linear")
|
||||
rolloffType = AL_LINEAR_DISTANCE_CLAMPED;
|
||||
else if (rolloffTypeStr != "")
|
||||
fprintf(stderr, "[TrackObject] Unknown rolloff type '%s'\n", rolloffTypeStr.c_str());
|
||||
|
||||
// first try track dir, then global dir
|
||||
std::string soundfile = file_manager->getModelFile(sound);
|
||||
if (!file_manager->fileExists(soundfile))
|
||||
@ -96,6 +107,7 @@ TrackObject::TrackObject(const XMLNode &xml_node)
|
||||
|
||||
SFXBuffer* buffer = new SFXBuffer(soundfile,
|
||||
true /* positional */,
|
||||
rolloffType,
|
||||
rolloff,
|
||||
volume);
|
||||
buffer->load();
|
||||
|
Loading…
x
Reference in New Issue
Block a user