Cleaning up new custom kart sfx code, better documentation, more readable.
git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/main/branches/irrlicht@3896 178a84e3-b1eb-0310-8ba1-8eac791a3b58
This commit is contained in:
parent
97bbad19e7
commit
8da41850d3
@ -213,6 +213,36 @@ bool loadVorbisBuffer(const char *name, ALuint buffer)
|
||||
|
||||
return success;
|
||||
}
|
||||
/*
|
||||
|
||||
getCustomTagName(int id)
|
||||
|
||||
|
||||
Uses CustomSFX as input (see sfx_manager.hpp) and returns associated config
|
||||
string tag. Used when loading custom sfx in KartProperties::getAllData().
|
||||
|
||||
TODO: Fix this to take advantage of some string array initialization trick
|
||||
I'm just too stupid with C++ to figure it out. The switch code is
|
||||
less then ideal.
|
||||
*/
|
||||
|
||||
const char *SFXManager::getCustomTagName(int id)
|
||||
{
|
||||
switch (id)
|
||||
{
|
||||
case CUSTOM_HORN: return "horn-sound"; // Replaces horn
|
||||
case CUSTOM_CRASH: return "crash-sound"; // Played when colliding with another kart
|
||||
case CUSTOM_WIN: return "win-sound"; // Played when racer wins
|
||||
case CUSTOM_EXPLODE: return "explode-sound"; // Played when kart explodes
|
||||
case CUSTOM_GOO: return "goo-sound"; // Played when driving through goo
|
||||
case CUSTOM_PASS: return "pass-sound"; // Played when passing another kart
|
||||
case CUSTOM_ZIPPER: return "zipper-sound"; // Played when kart hits zipper
|
||||
case CUSTOM_NAME: return "name-sound"; // Introduction "I'm Tux!"
|
||||
case CUSTOM_BOMB: return "bomb-sound"; // Played when dynamite is attached to kart
|
||||
case CUSTOM_SHOOT: return "shoot-sound"; // Played when weapon is used
|
||||
};
|
||||
return "";
|
||||
} // getCustomTagName
|
||||
|
||||
/*
|
||||
|
||||
@ -252,9 +282,10 @@ int SFXManager::addSingleSfx(std::string sfxFile,
|
||||
}
|
||||
|
||||
// debugging
|
||||
printf("addSingleSfx() id:%d sfxFile:%s\n", sfxID, sfxFile.c_str());
|
||||
/*printf("addSingleSfx() id:%d sfxFile:%s\n", sfxID, sfxFile.c_str());*/
|
||||
|
||||
return sfxID;
|
||||
}
|
||||
} // addSingleSFX
|
||||
|
||||
void SFXManager::loadSingleSfx(const lisp::Lisp* lisp,
|
||||
const char *name, int item)
|
||||
|
@ -57,26 +57,21 @@ public:
|
||||
*/
|
||||
enum CustomSFX
|
||||
{
|
||||
CUSTOM_HORN,
|
||||
CUSTOM_CRASH,
|
||||
CUSTOM_WIN,
|
||||
CUSTOM_EXPLODE,
|
||||
CUSTOM_HORN, // Replaces default horn
|
||||
CUSTOM_CRASH, // Played when colliding with another kart
|
||||
CUSTOM_WIN, // Played when racer wins
|
||||
CUSTOM_EXPLODE, // Played when struck by bowling ball or dynamite
|
||||
CUSTOM_GOO, // Played when driving through goo
|
||||
CUSTOM_PASS, // Played when passing another kart
|
||||
CUSTOM_ZIPPER, // Played when kart hits zipper
|
||||
CUSTOM_NAME, // Introduction "I'm Tux!"
|
||||
CUSTOM_BOMB, // Played when dynamite is attached to kart
|
||||
CUSTOM_SHOOT, // Played when weapon is used
|
||||
NUM_CUSTOMS
|
||||
};
|
||||
|
||||
// LISP (or in the future xml) tag for each custom sound
|
||||
// TODO: fix this to use some kind of string array ini, I'm just too stupid with c++ to figure it out
|
||||
static const char *getCustomTagName(int id)
|
||||
{
|
||||
switch (id)
|
||||
{
|
||||
case 0: return "horn-sound";
|
||||
case 1: return "crash-sound";
|
||||
case 2: return "win-sound";
|
||||
case 3: return "explode-sound";
|
||||
};
|
||||
return "";
|
||||
}
|
||||
const char *getCustomTagName(int id);
|
||||
|
||||
|
||||
/** Status of a sound effect. */
|
||||
|
@ -107,10 +107,14 @@ Kart::Kart (const std::string& kart_name, int position,
|
||||
for (int n = 0; n < SFXManager::NUM_CUSTOMS; n++)
|
||||
{
|
||||
int id = m_kart_properties->getCustomSfxId((SFXManager::CustomSFX)n);
|
||||
m_custom_sounds[n] = sfx_manager->newSFX(id);
|
||||
|
||||
// If id == -1 the custom sound was not defined in the .irrkart config file
|
||||
if (id != -1)
|
||||
m_custom_sounds[n] = sfx_manager->newSFX(id);
|
||||
}
|
||||
|
||||
m_engine_sound = sfx_manager->newSFX(m_kart_properties->getEngineSfxType());
|
||||
m_beep_sound = sfx_manager->newSFX( SFXManager::SOUND_BEEP );
|
||||
m_crash_sound = sfx_manager->newSFX( SFXManager::SOUND_CRASH );
|
||||
m_goo_sound = sfx_manager->newSFX( SFXManager::SOUND_GOO );
|
||||
m_skid_sound = sfx_manager->newSFX( SFXManager::SOUND_SKID );
|
||||
|
@ -127,6 +127,7 @@ private:
|
||||
bool m_eliminated;
|
||||
|
||||
std::vector<SFXBase*> m_custom_sounds;
|
||||
SFXBase *m_beep_sound;
|
||||
SFXBase *m_engine_sound;
|
||||
SFXBase *m_crash_sound;
|
||||
SFXBase *m_skid_sound;
|
||||
|
@ -202,21 +202,26 @@ void KartProperties::getAllData(const lisp::Lisp* lisp)
|
||||
lisp->get("brake-factor", m_brake_factor);
|
||||
lisp->get("mass", m_mass);
|
||||
|
||||
// Load custom kart SFX files ===================================================
|
||||
std::string tempFile;
|
||||
|
||||
// Load custom kart SFX files
|
||||
for (int i = 0; i < SFXManager::NUM_CUSTOMS; i++)
|
||||
{
|
||||
// Get lisp string tag for each custom sfx
|
||||
std::string tempFile;
|
||||
// Get filename associated with each custom sfx tag in sfx config
|
||||
if (lisp->get(sfx_manager->getCustomTagName(i), tempFile))
|
||||
{
|
||||
// retrieve filename, load file and store id in vector
|
||||
// determine absolute filename
|
||||
// TODO: will this work with add-on packs (is data dir the same)?
|
||||
tempFile = file_manager->getDataDir() + "/karts/" + getIdent() + "/" + tempFile;
|
||||
|
||||
// Create sfx in sfx manager and store id
|
||||
m_custom_sfx_id[i] = sfx_manager->addSingleSfx(tempFile, 1, 0.2f,1.0f);
|
||||
printf("%s custom SFX #%d : %s\n", getIdent().c_str(), i, tempFile.c_str());
|
||||
|
||||
// debugging
|
||||
printf("%s custom sfx %s:\t %s\n", getIdent().c_str(), sfx_manager->getCustomTagName(i), tempFile.c_str());
|
||||
}
|
||||
else
|
||||
{
|
||||
// if there is no filename associated with a given tag
|
||||
m_custom_sfx_id[i] = -1;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user