Created addSingleSfx() to the sfx_manager. Extends ability of sfx_manager to load custom sounds during run-time. Will be used for loading character voices. Replaced SFXType with int in several places and added bounds checking.

git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/main/branches/irrlicht@3891 178a84e3-b1eb-0310-8ba1-8eac791a3b58
This commit is contained in:
rforder 2009-08-19 18:34:49 +00:00
parent b5e25d1298
commit 6c0f94190b
2 changed files with 62 additions and 4 deletions

View File

@ -214,11 +214,55 @@ bool loadVorbisBuffer(const char *name, ALuint buffer)
return success;
}
/*
addSingleSfx()
Introduces a mechanism by which one can load sound effects beyond the basic
enumerated types. This will be used when loading custom sound effects for
individual karts (character voices) so that we can avoid creating an
enumeration for each effect, for each kart.
sfxFile must be an absolute pathname, so get that straight first.
*/
int SFXManager::addSingleSfx(std::string sfxFile,
int positional,
float rolloff,
float gain)
/* Returns sfx ID */
{
int sfxID;
m_sfx_buffers.push_back(0);
sfxID = m_sfx_buffers.size() - 1;
/* FIXME: Check for existance of file before resizing vectors */
m_sfx_rolloff.push_back(rolloff);
m_sfx_positional.push_back(positional);
m_sfx_gain.push_back(gain);
alGenBuffers(1, &(m_sfx_buffers[sfxID]));
if (!checkError("generating a buffer")) return -1;
if (!loadVorbisBuffer(sfxFile.c_str(), sfxID))
{
printf("Failed to load sound effect %s\n", sfxFile.c_str());
}
return sfxID;
}
void SFXManager::loadSingleSfx(const lisp::Lisp* lisp,
const char *name, SFXType item)
const char *name, int item)
{
if (item < 0 || item >= m_sfx_gain.size())
{
printf("loadSingleSfx: Invalid SFX ID.\n");
return;
}
const lisp::Lisp* sfxLisp = lisp->getLisp(name);
std::string wav; float rolloff = 0.1f; float gain = 1.0f; int positional = 0;
@ -249,9 +293,16 @@ void SFXManager::loadSingleSfx(const lisp::Lisp* lisp,
* call deleteSFX().
* \param id Identifier of the sound effect to create.
*/
SFXBase *SFXManager::newSFX(SFXType id)
SFXBase *SFXManager::newSFX(int id)
{
bool positional = false;
if (id < 0 || id >= m_sfx_gain.size())
{
printf("newSFX: Invalid SFX ID.\n");
return NULL;
}
if(race_manager->getNumLocalPlayers() < 2)
positional = m_sfx_positional[id]!=0;

View File

@ -67,15 +67,22 @@ private:
std::vector<SFXBase*> m_all_sfx;
bool m_initialized;
float m_masterGain;
void loadSfx();
void loadSingleSfx(const lisp::Lisp *lisp,
const char *name,
SFXType type);
int type);
int addSingleSfx( std::string filename,
int positional,
float rolloff,
float gain);
public:
SFXManager();
virtual ~SFXManager();
bool sfxAllowed();
SFXBase *newSFX(SFXType id);
SFXBase *newSFX(int id);
void deleteSFX(SFXBase *sfx);
void pauseAll();
void resumeAll();