Converted sound effects file to XML. Along the way, refactored the audio code to be more flexible. before, when a sound changed, you needed to edit the config file of STK, edit the enum in the header, edit the loader in the .cpp... was annoying. Now you only need to edit the config file.
git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/main/trunk@4728 178a84e3-b1eb-0310-8ba1-8eac791a3b58
This commit is contained in:
parent
b167931b9c
commit
93cc5209f7
@ -53,11 +53,7 @@ SFXManager::SFXManager()
|
|||||||
// The sound manager initialises OpenAL
|
// The sound manager initialises OpenAL
|
||||||
m_initialized = sound_manager->initialized();
|
m_initialized = sound_manager->initialized();
|
||||||
m_masterGain = 1.0f;
|
m_masterGain = 1.0f;
|
||||||
m_sfx_buffers.resize(NUM_SOUNDS);
|
if (!m_initialized) return;
|
||||||
m_sfx_positional.resize(NUM_SOUNDS);
|
|
||||||
m_sfx_rolloff.resize(NUM_SOUNDS);
|
|
||||||
m_sfx_gain.resize(NUM_SOUNDS);
|
|
||||||
if(!m_initialized) return;
|
|
||||||
|
|
||||||
loadSfx();
|
loadSfx();
|
||||||
setMasterSFXVolume( UserConfigParams::m_sfx_volume );
|
setMasterSFXVolume( UserConfigParams::m_sfx_volume );
|
||||||
@ -67,18 +63,33 @@ SFXManager::SFXManager()
|
|||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
SFXManager::~SFXManager()
|
SFXManager::~SFXManager()
|
||||||
{
|
{
|
||||||
//make sure there aren't any stray sfx's sitting around anywhere
|
// ---- clear m_all_sfx
|
||||||
for(std::vector<SFXBase*>::iterator i=m_all_sfx.begin();
|
const int sfxAmount = m_all_sfx.size();
|
||||||
i!=m_all_sfx.end(); i++)
|
for (int n=0; n<sfxAmount; n++)
|
||||||
{
|
{
|
||||||
delete (*i);
|
delete m_all_sfx[n];
|
||||||
} // for i in m_all_sfx
|
}
|
||||||
m_all_sfx.clear();
|
m_all_sfx.clear();
|
||||||
|
|
||||||
//the unbuffer all of the buffers
|
// ---- clear m_quick_sounds
|
||||||
for(unsigned int ii = 0; ii != m_sfx_buffers.size(); ii++)
|
|
||||||
{
|
{
|
||||||
alDeleteBuffers(1, &(m_sfx_buffers[ii]));
|
std::map<std::string, SFXBase*>::iterator i = m_quick_sounds.begin();
|
||||||
|
for (; i != m_quick_sounds.end(); i++)
|
||||||
|
{
|
||||||
|
SFXBase* snd = (*i).second;
|
||||||
|
delete snd;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
m_quick_sounds.clear();
|
||||||
|
|
||||||
|
// ---- clear m_all_sfx_types
|
||||||
|
{
|
||||||
|
std::map<std::string, SFXBufferInfo>::iterator i = m_all_sfx_types.begin();
|
||||||
|
for (; i != m_all_sfx_types.end(); i++)
|
||||||
|
{
|
||||||
|
(*i).second.freeBuffer();
|
||||||
|
}
|
||||||
|
m_all_sfx_types.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
sfx_manager = NULL;
|
sfx_manager = NULL;
|
||||||
@ -97,56 +108,35 @@ bool SFXManager::sfxAllowed()
|
|||||||
*/
|
*/
|
||||||
void SFXManager::loadSfx()
|
void SFXManager::loadSfx()
|
||||||
{
|
{
|
||||||
// TODO : implement as XML
|
std::string sfx_config_name = file_manager->getSFXFile("sfx.xml");
|
||||||
const lisp::Lisp* root = 0;
|
XMLNode* root = file_manager->createXMLTree(sfx_config_name);
|
||||||
std::string sfx_config_name = file_manager->getSFXFile("sfx.config");
|
if (!root)
|
||||||
try
|
|
||||||
{
|
{
|
||||||
lisp::Parser parser;
|
std::cerr << "Could not read sounf effects XML file " << sfx_config_name.c_str() << std::endl;
|
||||||
root = parser.parse(sfx_config_name);
|
|
||||||
}
|
|
||||||
catch(std::exception& e)
|
|
||||||
{
|
|
||||||
(void)e; // avoid warning about unreferenced local variable
|
|
||||||
std::ostringstream msg;
|
|
||||||
msg << "Sfx config file '" << sfx_config_name
|
|
||||||
<< "' does not exist - aborting.\n";
|
|
||||||
throw std::runtime_error(msg.str());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const lisp::Lisp* lisp = root->getLisp("sfx-config");
|
const int amount = root->getNumNodes();
|
||||||
if(!lisp)
|
for (int i=0; i<amount; i++)
|
||||||
{
|
{
|
||||||
std::string msg="No sfx-config node";
|
const XMLNode* node = root->getNode(i);
|
||||||
throw std::runtime_error(msg);
|
|
||||||
}
|
|
||||||
loadSingleSfx(lisp, "ugh", SOUND_UGH );
|
|
||||||
loadSingleSfx(lisp, "skid", SOUND_SKID );
|
|
||||||
loadSingleSfx(lisp, "locked", SOUND_LOCKED );
|
|
||||||
loadSingleSfx(lisp, "bowling_roll", SOUND_BOWLING_ROLL );
|
|
||||||
loadSingleSfx(lisp, "bowling_strike",SOUND_BOWLING_STRIKE );
|
|
||||||
loadSingleSfx(lisp, "winner", SOUND_WINNER );
|
|
||||||
loadSingleSfx(lisp, "crash", SOUND_CRASH );
|
|
||||||
loadSingleSfx(lisp, "grab", SOUND_GRAB );
|
|
||||||
loadSingleSfx(lisp, "goo", SOUND_GOO );
|
|
||||||
loadSingleSfx(lisp, "shot", SOUND_SHOT );
|
|
||||||
loadSingleSfx(lisp, "wee", SOUND_WEE );
|
|
||||||
loadSingleSfx(lisp, "explosion", SOUND_EXPLOSION );
|
|
||||||
loadSingleSfx(lisp, "bzzt", SOUND_BZZT );
|
|
||||||
loadSingleSfx(lisp, "beep", SOUND_BEEP );
|
|
||||||
loadSingleSfx(lisp, "back_menu", SOUND_BACK_MENU );
|
|
||||||
loadSingleSfx(lisp, "use_anvil", SOUND_USE_ANVIL );
|
|
||||||
loadSingleSfx(lisp, "use_parachute", SOUND_USE_PARACHUTE );
|
|
||||||
loadSingleSfx(lisp, "select_menu", SOUND_SELECT_MENU );
|
|
||||||
loadSingleSfx(lisp, "move_menu", SOUND_MOVE_MENU );
|
|
||||||
loadSingleSfx(lisp, "full", SOUND_FULL );
|
|
||||||
loadSingleSfx(lisp, "prestart", SOUND_PRESTART );
|
|
||||||
loadSingleSfx(lisp, "start", SOUND_START );
|
|
||||||
loadSingleSfx(lisp, "swap", SOUND_SWAP );
|
|
||||||
|
|
||||||
loadSingleSfx(lisp, "engine_small", SOUND_ENGINE_SMALL );
|
if (node->getName() == "sfx-config")
|
||||||
loadSingleSfx(lisp, "engine_large", SOUND_ENGINE_LARGE );
|
{
|
||||||
} // loadSfx
|
// outer node, ignore
|
||||||
|
}
|
||||||
|
else if (node->getName() == "sfx")
|
||||||
|
{
|
||||||
|
loadSingleSfx(node);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
std::cerr << "Unknown node in sfx XML file : " << node->getName().c_str() << std::endl;
|
||||||
|
throw std::runtime_error("Unknown node in sfx XML file");
|
||||||
|
}
|
||||||
|
}// nend for
|
||||||
|
|
||||||
|
delete root;
|
||||||
|
} // loadSfx
|
||||||
//----------------------------------------------------------------------------
|
//----------------------------------------------------------------------------
|
||||||
/** Load a vorbis file into an OpenAL buffer
|
/** Load a vorbis file into an OpenAL buffer
|
||||||
based on a routine by Peter Mulholland, used with permission (quote : "Feel free to use")
|
based on a routine by Peter Mulholland, used with permission (quote : "Feel free to use")
|
||||||
@ -226,7 +216,7 @@ getCustomTagName(int id)
|
|||||||
I'm just too stupid with C++ to figure it out. The switch code is
|
I'm just too stupid with C++ to figure it out. The switch code is
|
||||||
less then ideal.
|
less then ideal.
|
||||||
*/
|
*/
|
||||||
|
/*
|
||||||
const char *SFXManager::getCustomTagName(int id)
|
const char *SFXManager::getCustomTagName(int id)
|
||||||
{
|
{
|
||||||
switch (id)
|
switch (id)
|
||||||
@ -244,7 +234,7 @@ const char *SFXManager::getCustomTagName(int id)
|
|||||||
};
|
};
|
||||||
return "";
|
return "";
|
||||||
} // getCustomTagName
|
} // getCustomTagName
|
||||||
|
*/
|
||||||
/*
|
/*
|
||||||
|
|
||||||
addSingleSfx()
|
addSingleSfx()
|
||||||
@ -254,100 +244,153 @@ addSingleSfx()
|
|||||||
individual karts (character voices) so that we can avoid creating an
|
individual karts (character voices) so that we can avoid creating an
|
||||||
enumeration for each effect, for each kart.
|
enumeration for each effect, for each kart.
|
||||||
|
|
||||||
sfxFile must be an absolute pathname, so get that straight first.
|
\param sfxFile must be an absolute pathname
|
||||||
|
\return whether loading this sound effect was successful
|
||||||
|
|
||||||
*/
|
*/
|
||||||
int SFXManager::addSingleSfx(std::string sfxFile,
|
bool SFXManager::addSingleSfx(const char* sfx_name,
|
||||||
int positional,
|
std::string sfxFile,
|
||||||
float rolloff,
|
bool positional,
|
||||||
float gain)
|
float rolloff,
|
||||||
/* Returns sfx ID or -1 on error*/
|
float gain)
|
||||||
{
|
{
|
||||||
int sfxID;
|
std::string filename;
|
||||||
|
|
||||||
m_sfx_buffers.push_back(0);
|
SFXBufferInfo sfxInfo;
|
||||||
sfxID = m_sfx_buffers.size() - 1;
|
|
||||||
|
|
||||||
/* FIXME: Check for existance of file before resizing vectors */
|
|
||||||
|
|
||||||
m_sfx_rolloff.push_back(rolloff);
|
sfxInfo.m_sfx_rolloff = rolloff;
|
||||||
m_sfx_positional.push_back(positional);
|
sfxInfo.m_sfx_positional = positional;
|
||||||
m_sfx_gain.push_back(gain);
|
sfxInfo.m_sfx_gain = gain;
|
||||||
|
|
||||||
alGenBuffers(1, &(m_sfx_buffers[sfxID]));
|
printf("Loading SFX %s\n", sfxFile.c_str());
|
||||||
if (!checkError("generating a buffer")) return -1;
|
|
||||||
|
|
||||||
if (!loadVorbisBuffer(sfxFile.c_str(), m_sfx_buffers[sfxID]))
|
alGetError(); // clear errors from previously
|
||||||
|
|
||||||
|
alGenBuffers(1, &sfxInfo.m_sfx_buffer);
|
||||||
|
if (!checkError("generating a buffer"))
|
||||||
{
|
{
|
||||||
printf("Failed to load sound effect %s\n", sfxFile.c_str());
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// debugging
|
if (!loadVorbisBuffer(sfx_name, sfxInfo.m_sfx_buffer))
|
||||||
/*printf("addSingleSfx() id:%d sfxFile:%s\n", sfxID, sfxFile.c_str());*/
|
{
|
||||||
|
fprintf(stderr, "Could not load sound effect %s\n", sfx_name);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
return sfxID;
|
m_all_sfx_types[sfx_name] = sfxInfo;
|
||||||
|
|
||||||
|
return true;
|
||||||
} // addSingleSFX
|
} // addSingleSFX
|
||||||
|
|
||||||
void SFXManager::loadSingleSfx(const lisp::Lisp* lisp,
|
//----------------------------------------------------------------------------
|
||||||
const char *name, int item)
|
|
||||||
|
void SFXManager::loadSingleSfx(const XMLNode* node)
|
||||||
{
|
{
|
||||||
if (item < 0 || item >= (int)m_sfx_gain.size())
|
std::string filename;
|
||||||
|
std::string sfx_name;
|
||||||
|
|
||||||
|
SFXBufferInfo sfxInfo;
|
||||||
|
|
||||||
|
if (node->get("filename", &filename) == 0)
|
||||||
{
|
{
|
||||||
printf("loadSingleSfx: Invalid SFX ID.\n");
|
fprintf(stderr, "/!\\ The 'filename' attribute is mandatory in the SFX XML file!\n");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const lisp::Lisp* sfxLisp = lisp->getLisp(name);
|
if (node->get("name", &sfx_name) == 0)
|
||||||
std::string wav; float rolloff = 0.1f; float gain = 1.0f; int positional = 0;
|
{
|
||||||
|
fprintf(stderr, "/!\\ The 'name' attribute is mandatory in the SFX XML file!\n");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
sfxLisp->get("filename", wav );
|
node->get("rolloff", &sfxInfo.m_sfx_rolloff );
|
||||||
sfxLisp->get("roll-off", rolloff );
|
node->get("positional", &sfxInfo.m_sfx_positional );
|
||||||
sfxLisp->get("positional", positional );
|
node->get("volume", &sfxInfo.m_sfx_gain );
|
||||||
sfxLisp->get("volume", gain );
|
|
||||||
|
|
||||||
m_sfx_rolloff[item] = rolloff;
|
std::string path = file_manager->getSFXFile(filename);
|
||||||
m_sfx_positional[item] = positional;
|
|
||||||
m_sfx_gain[item] = gain;
|
|
||||||
|
|
||||||
std::string path = file_manager->getSFXFile(wav);
|
|
||||||
printf("Loading SFX %s\n", path.c_str());
|
printf("Loading SFX %s\n", path.c_str());
|
||||||
|
|
||||||
alGenBuffers(1, &(m_sfx_buffers[item]));
|
alGenBuffers(1, &sfxInfo.m_sfx_buffer);
|
||||||
if (!checkError("generating a buffer")) return;
|
if (!checkError("generating a buffer")) return;
|
||||||
|
|
||||||
if(!loadVorbisBuffer(path.c_str(), m_sfx_buffers[item]))
|
assert( alIsBuffer(sfxInfo.m_sfx_buffer) );
|
||||||
|
|
||||||
|
if (!loadVorbisBuffer(path.c_str(), sfxInfo.m_sfx_buffer))
|
||||||
{
|
{
|
||||||
printf("Could not load sound effect %s\n", name);
|
fprintf(stderr, "Could not load sound effect %s\n", path.c_str());
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//printf(">>>>>> Addind sound effect '%s' to the map\n", sfx_name.c_str());
|
||||||
|
|
||||||
|
m_all_sfx_types[sfx_name.c_str()] = sfxInfo;
|
||||||
|
|
||||||
|
assert( alIsBuffer(m_all_sfx_types[sfx_name.c_str()].m_sfx_buffer) );
|
||||||
|
|
||||||
|
/*
|
||||||
|
std::map<std::string, SFXBufferInfo>::iterator i = m_all_sfx_types.begin();
|
||||||
|
for (; i != m_all_sfx_types.end(); i++ )
|
||||||
|
{
|
||||||
|
printf(" got '%s', buffer is %i\n", i->first.c_str(), i->second.m_sfx_buffer);
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
} // loadSingleSfx
|
} // loadSingleSfx
|
||||||
|
|
||||||
//----------------------------------------------------------------------------
|
//----------------------------------------------------------------------------
|
||||||
/** Creates a new SFX object. The memory for this object is managed completely
|
/** Creates a new SFX object. The memory for this object is managed completely
|
||||||
* by the SFXManager. This makes it easy to use different implementations of
|
* by the SFXManager. This makes it easy to use different implementations of
|
||||||
* SFX - since newSFX can return whatever type is used. To free the memory,
|
* SFX - since createSoundSource can return whatever type is used. To free the memory,
|
||||||
* call deleteSFX().
|
* call deleteSFX().
|
||||||
* \param id Identifier of the sound effect to create.
|
* \param id Identifier of the sound effect to create.
|
||||||
*/
|
*/
|
||||||
SFXBase *SFXManager::newSFX(int id)
|
SFXBase* SFXManager::createSoundSource(const SFXBufferInfo& info, const bool addToSFXList)
|
||||||
{
|
{
|
||||||
bool positional = false;
|
bool positional = false;
|
||||||
|
|
||||||
if (id < 0 || id >= (int)m_sfx_gain.size())
|
if (race_manager->getNumLocalPlayers() < 2)
|
||||||
{
|
{
|
||||||
printf("newSFX: Invalid SFX ID %d.\n", id);
|
positional = info.m_sfx_positional;
|
||||||
|
}
|
||||||
|
|
||||||
|
assert( alIsBuffer(info.m_sfx_buffer) );
|
||||||
|
|
||||||
|
SFXBase* sfx = new SFXOpenAL(info.m_sfx_buffer, positional, info.m_sfx_rolloff, info.m_sfx_gain);
|
||||||
|
|
||||||
|
// debugging
|
||||||
|
/*printf("newSfx(): id:%d buffer:%p, rolloff:%f, gain:%f %p\n", id, m_sfx_buffers[id], m_sfx_rolloff[id], m_sfx_gain[id], p);*/
|
||||||
|
|
||||||
|
sfx->volume(m_masterGain);
|
||||||
|
|
||||||
|
if (addToSFXList) m_all_sfx.push_back(sfx);
|
||||||
|
|
||||||
|
return sfx;
|
||||||
|
} // createSoundSource
|
||||||
|
|
||||||
|
//----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
SFXBase* SFXManager::createSoundSource(const char* name, const bool addToSFXList)
|
||||||
|
{
|
||||||
|
std::map<std::string, SFXBufferInfo>::iterator i = m_all_sfx_types.find(name);
|
||||||
|
if ( i == m_all_sfx_types.end() )
|
||||||
|
{
|
||||||
|
fprintf( stderr, "SFXManager::createSoundSource could not find the requested sound effect : '%s'\n", name);
|
||||||
|
|
||||||
|
/*
|
||||||
|
std::map<std::string, SFXBufferInfo>::iterator it = m_all_sfx_types.begin();
|
||||||
|
for (; it != m_all_sfx_types.end(); it++ )
|
||||||
|
{
|
||||||
|
printf(" got '%s'\n", it->first.c_str());
|
||||||
|
}*/
|
||||||
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(race_manager->getNumLocalPlayers() < 2)
|
return createSoundSource( i->second, addToSFXList );
|
||||||
positional = m_sfx_positional[id]!=0;
|
}
|
||||||
|
|
||||||
SFXBase *p = new SFXOpenAL(m_sfx_buffers[id], positional, m_sfx_rolloff[id], m_sfx_gain[id]);
|
|
||||||
// debugging
|
|
||||||
/*printf("newSfx(): id:%d buffer:%p, rolloff:%f, gain:%f %p\n", id, m_sfx_buffers[id], m_sfx_rolloff[id], m_sfx_gain[id], p);*/
|
|
||||||
p->volume(m_masterGain);
|
|
||||||
m_all_sfx.push_back(p);
|
|
||||||
return p;
|
|
||||||
} // newSFX
|
|
||||||
|
|
||||||
//----------------------------------------------------------------------------
|
//----------------------------------------------------------------------------
|
||||||
/** Delete a sound effect object, and removes it from the internal list of
|
/** Delete a sound effect object, and removes it from the internal list of
|
||||||
@ -379,7 +422,7 @@ void SFXManager::deleteSFX(SFXBase *sfx)
|
|||||||
*/
|
*/
|
||||||
void SFXManager::pauseAll()
|
void SFXManager::pauseAll()
|
||||||
{
|
{
|
||||||
for(std::vector<SFXBase*>::iterator i=m_all_sfx.begin();
|
for (std::vector<SFXBase*>::iterator i=m_all_sfx.begin();
|
||||||
i!=m_all_sfx.end(); i++)
|
i!=m_all_sfx.end(); i++)
|
||||||
{
|
{
|
||||||
(*i)->pause();
|
(*i)->pause();
|
||||||
@ -390,13 +433,12 @@ void SFXManager::pauseAll()
|
|||||||
*/
|
*/
|
||||||
void SFXManager::resumeAll()
|
void SFXManager::resumeAll()
|
||||||
{
|
{
|
||||||
for(std::vector<SFXBase*>::iterator i=m_all_sfx.begin();
|
for (std::vector<SFXBase*>::iterator i=m_all_sfx.begin();
|
||||||
i!=m_all_sfx.end(); i++)
|
i!=m_all_sfx.end(); i++)
|
||||||
{
|
{
|
||||||
SFXStatus status = (*i)->getStatus();
|
SFXStatus status = (*i)->getStatus();
|
||||||
// Initial happens when
|
// Initial happens when
|
||||||
if(status==SFX_PAUSED)
|
if (status==SFX_PAUSED) (*i)->resume();
|
||||||
(*i)->resume();
|
|
||||||
} // for i in m_all_sfx
|
} // for i in m_all_sfx
|
||||||
} // resumeAll
|
} // resumeAll
|
||||||
|
|
||||||
@ -418,18 +460,28 @@ bool SFXManager::checkError(const std::string &context)
|
|||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
void SFXManager::setMasterSFXVolume(float gain)
|
void SFXManager::setMasterSFXVolume(float gain)
|
||||||
{
|
{
|
||||||
if(gain > 1.0)
|
if (gain > 1.0) gain = 1.0f;
|
||||||
gain = 1.0f;
|
if (gain < 0.0f) gain = 0.0f;
|
||||||
if(gain < 0.0f)
|
|
||||||
gain = 0.0f;
|
|
||||||
|
|
||||||
m_masterGain = gain;
|
m_masterGain = gain;
|
||||||
|
|
||||||
for(std::vector<SFXBase*>::iterator i=m_all_sfx.begin();
|
// regular SFX
|
||||||
i!=m_all_sfx.end(); i++)
|
|
||||||
{
|
{
|
||||||
(*i)->volume(m_masterGain);
|
for (std::vector<SFXBase*>::iterator i=m_all_sfx.begin();
|
||||||
} // for i in m_all_sfx
|
i!=m_all_sfx.end(); i++)
|
||||||
|
{
|
||||||
|
(*i)->volume(m_masterGain);
|
||||||
|
} // for i in m_all_sfx
|
||||||
|
}
|
||||||
|
|
||||||
|
// quick SFX
|
||||||
|
{
|
||||||
|
std::map<std::string, SFXBase*>::iterator i = m_quick_sounds.begin();
|
||||||
|
for (; i != m_quick_sounds.end(); i++)
|
||||||
|
{
|
||||||
|
(*i).second->volume(m_masterGain);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
} // setMasterSFXVolume
|
} // setMasterSFXVolume
|
||||||
|
|
||||||
@ -449,18 +501,19 @@ const std::string SFXManager::getErrorString(int err)
|
|||||||
} // getErrorString
|
} // getErrorString
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
void SFXManager::quickSound(SFXType soundType)
|
|
||||||
|
std::map<std::string, SFXBase*> SFXManager::m_quick_sounds;
|
||||||
|
|
||||||
|
void SFXManager::quickSound(const char* soundType)
|
||||||
{
|
{
|
||||||
static std::map<SFXType, SFXBase*> allSounds;
|
std::map<std::string, SFXBase*>::iterator sound = m_quick_sounds.find(soundType);
|
||||||
|
|
||||||
std::map<SFXType, SFXBase*>::iterator sound = allSounds.find(soundType);
|
if (sound == m_quick_sounds.end())
|
||||||
|
|
||||||
if (sound == allSounds.end())
|
|
||||||
{
|
{
|
||||||
// sound not yet in our list
|
// sound not yet in our local list of quick sounds
|
||||||
SFXBase* newSound = sfx_manager->newSFX(soundType);
|
SFXBase* newSound = sfx_manager->createSoundSource(soundType, false);
|
||||||
newSound->play();
|
newSound->play();
|
||||||
allSounds[soundType] = newSound;
|
m_quick_sounds[soundType] = newSound;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -21,6 +21,7 @@
|
|||||||
#define HEADER_SFX_MANAGER_HPP
|
#define HEADER_SFX_MANAGER_HPP
|
||||||
|
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
#include <map>
|
||||||
#ifdef __APPLE__
|
#ifdef __APPLE__
|
||||||
# include <OpenAL/al.h>
|
# include <OpenAL/al.h>
|
||||||
#else
|
#else
|
||||||
@ -31,7 +32,7 @@
|
|||||||
#include "utils/vec3.hpp"
|
#include "utils/vec3.hpp"
|
||||||
|
|
||||||
class SFXBase;
|
class SFXBase;
|
||||||
|
class XMLNode;
|
||||||
|
|
||||||
/** Manager of all sound effects. The manager reads all sound effects and
|
/** Manager of all sound effects. The manager reads all sound effects and
|
||||||
* maintains the corresponding buffers. Each sound effect objects uses
|
* maintains the corresponding buffers. Each sound effect objects uses
|
||||||
@ -40,21 +41,11 @@ class SFXBase;
|
|||||||
class SFXManager
|
class SFXManager
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
/** The different type of sound effects. */
|
|
||||||
enum SFXType
|
|
||||||
{
|
|
||||||
SOUND_UGH, SOUND_SKID, SOUND_BOWLING_ROLL, SOUND_BOWLING_STRIKE, SOUND_WINNER, SOUND_CRASH, SOUND_GRAB,
|
|
||||||
SOUND_SHOT, SOUND_GOO, SOUND_WEE, SOUND_EXPLOSION, SOUND_BZZT, SOUND_BEEP, SOUND_BACK_MENU, SOUND_USE_ANVIL,
|
|
||||||
SOUND_USE_PARACHUTE, SOUND_SELECT_MENU, SOUND_MOVE_MENU, SOUND_FULL, SOUND_LOCKED,
|
|
||||||
SOUND_PRESTART, SOUND_START, SOUND_ENGINE_SMALL, SOUND_ENGINE_LARGE, SOUND_SWAP,
|
|
||||||
NUM_SOUNDS
|
|
||||||
};
|
|
||||||
|
|
||||||
|
/**
|
||||||
/*
|
* Entries for custom SFX sounds. These are unique for each kart.
|
||||||
Entries for custom SFX sounds. These are unique for each kart.
|
* eg. kart->playCustomSFX(SFX_MANAGER::CUSTOM_HORN)
|
||||||
eg. kart->playCustomSFX(SFX_MANAGER::CUSTOM_HORN)
|
*/
|
||||||
*/
|
|
||||||
enum CustomSFX
|
enum CustomSFX
|
||||||
{
|
{
|
||||||
CUSTOM_HORN, // Replaces default horn
|
CUSTOM_HORN, // Replaces default horn
|
||||||
@ -70,10 +61,6 @@ public:
|
|||||||
NUM_CUSTOMS
|
NUM_CUSTOMS
|
||||||
};
|
};
|
||||||
|
|
||||||
// LISP (or in the future xml) tag for each custom sound
|
|
||||||
const char *getCustomTagName(int id);
|
|
||||||
|
|
||||||
|
|
||||||
/** Status of a sound effect. */
|
/** Status of a sound effect. */
|
||||||
enum SFXStatus
|
enum SFXStatus
|
||||||
{
|
{
|
||||||
@ -82,32 +69,67 @@ public:
|
|||||||
};
|
};
|
||||||
|
|
||||||
private:
|
private:
|
||||||
/** The buffers for all sound effects. These are shared among all
|
|
||||||
|
class SFXBufferInfo
|
||||||
|
{
|
||||||
|
private:
|
||||||
|
public:
|
||||||
|
ALuint m_sfx_buffer;
|
||||||
|
bool m_sfx_positional;
|
||||||
|
float m_sfx_rolloff;
|
||||||
|
float m_sfx_gain;
|
||||||
|
|
||||||
|
SFXBufferInfo()
|
||||||
|
{
|
||||||
|
m_sfx_buffer = 0;
|
||||||
|
m_sfx_gain = 1.0f;
|
||||||
|
m_sfx_rolloff = 0.1f;
|
||||||
|
m_sfx_positional = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/** Cannot appear in destructor because copy-constructors may be used,
|
||||||
|
* and the OpenAL source must not be deleted on a copy */
|
||||||
|
void freeBuffer()
|
||||||
|
{
|
||||||
|
alDeleteBuffers(1, &m_sfx_buffer);
|
||||||
|
m_sfx_buffer = 0;
|
||||||
|
}
|
||||||
|
~SFXBufferInfo()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
/** The buffers and info for all sound effects. These are shared among all
|
||||||
* instances of SFXOpenal. */
|
* instances of SFXOpenal. */
|
||||||
std::vector<ALuint> m_sfx_buffers;
|
std::map<std::string, SFXBufferInfo> m_all_sfx_types;
|
||||||
std::vector<int> m_sfx_positional;
|
|
||||||
std::vector<float> m_sfx_rolloff;
|
/** The actual instances (sound sources) */
|
||||||
std::vector<float> m_sfx_gain;
|
std::vector<SFXBase*> m_all_sfx;
|
||||||
std::vector<SFXBase*> m_all_sfx;
|
|
||||||
|
/** To play non-positional sounds without having to create a new object for each */
|
||||||
|
static std::map<std::string, SFXBase*> m_quick_sounds;
|
||||||
|
|
||||||
bool m_initialized;
|
bool m_initialized;
|
||||||
float m_masterGain;
|
float m_masterGain;
|
||||||
|
|
||||||
void loadSfx();
|
void loadSfx();
|
||||||
|
|
||||||
void loadSingleSfx(const lisp::Lisp *lisp,
|
void loadSingleSfx(const XMLNode* node);
|
||||||
const char *name,
|
|
||||||
int type);
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
SFXManager();
|
SFXManager();
|
||||||
virtual ~SFXManager();
|
virtual ~SFXManager();
|
||||||
bool sfxAllowed();
|
bool sfxAllowed();
|
||||||
int addSingleSfx( std::string filename,
|
bool addSingleSfx( const char* sfx_name,
|
||||||
int positional,
|
std::string filename,
|
||||||
|
bool positional,
|
||||||
float rolloff,
|
float rolloff,
|
||||||
float gain);
|
float gain);
|
||||||
|
|
||||||
SFXBase *newSFX(int id);
|
SFXBase* createSoundSource(const SFXBufferInfo& info, const bool addToSFXList=true);
|
||||||
|
SFXBase* createSoundSource(const char* name, const bool addToSFXList=true);
|
||||||
|
|
||||||
void deleteSFX(SFXBase *sfx);
|
void deleteSFX(SFXBase *sfx);
|
||||||
void pauseAll();
|
void pauseAll();
|
||||||
void resumeAll();
|
void resumeAll();
|
||||||
@ -120,7 +142,7 @@ public:
|
|||||||
|
|
||||||
/** Positional sound is cool, but creating a new object just to play a simple
|
/** Positional sound is cool, but creating a new object just to play a simple
|
||||||
menu sound is not. This function allows for 'quick sounds' in a single call.*/
|
menu sound is not. This function allows for 'quick sounds' in a single call.*/
|
||||||
static void quickSound(SFXType soundType);
|
static void quickSound(const char* soundName);
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -43,18 +43,27 @@ SFXOpenAL::SFXOpenAL(ALuint buffer, bool positional, float rolloff, float gain)
|
|||||||
m_defaultGain = gain;
|
m_defaultGain = gain;
|
||||||
|
|
||||||
alGenSources(1, &m_soundSource );
|
alGenSources(1, &m_soundSource );
|
||||||
if(!SFXManager::checkError("generating a source")) return;
|
if (!SFXManager::checkError("generating a source")) return;
|
||||||
|
|
||||||
|
assert( alIsBuffer(m_soundBuffer) );
|
||||||
|
assert( alIsSource(m_soundSource) );
|
||||||
|
|
||||||
|
//std::cout << "Setting a source with buffer " << m_soundBuffer << ", rolloff " << rolloff
|
||||||
|
// << ", gain=" << m_defaultGain << ", positional=" << (positional ? "true" : "false") << std::endl;
|
||||||
|
|
||||||
alSourcei (m_soundSource, AL_BUFFER, m_soundBuffer);
|
alSourcei (m_soundSource, AL_BUFFER, m_soundBuffer);
|
||||||
|
|
||||||
|
if (!SFXManager::checkError("attaching the buffer to the source")) return;
|
||||||
|
|
||||||
alSource3f(m_soundSource, AL_POSITION, 0.0, 0.0, 0.0);
|
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_VELOCITY, 0.0, 0.0, 0.0);
|
||||||
alSource3f(m_soundSource, AL_DIRECTION, 0.0, 0.0, 0.0);
|
alSource3f(m_soundSource, AL_DIRECTION, 0.0, 0.0, 0.0);
|
||||||
alSourcef (m_soundSource, AL_ROLLOFF_FACTOR, rolloff );
|
alSourcef (m_soundSource, AL_ROLLOFF_FACTOR, rolloff );
|
||||||
alSourcef (m_soundSource, AL_GAIN, m_defaultGain);
|
alSourcef (m_soundSource, AL_GAIN, m_defaultGain);
|
||||||
if(positional)
|
|
||||||
alSourcei (m_soundSource, AL_SOURCE_RELATIVE, AL_FALSE);
|
|
||||||
else
|
if (positional) alSourcei (m_soundSource, AL_SOURCE_RELATIVE, AL_FALSE);
|
||||||
alSourcei (m_soundSource, AL_SOURCE_RELATIVE, AL_TRUE);
|
else alSourcei (m_soundSource, AL_SOURCE_RELATIVE, AL_TRUE);
|
||||||
|
|
||||||
m_positional = positional;
|
m_positional = positional;
|
||||||
m_ok = SFXManager::checkError("setting up the source");
|
m_ok = SFXManager::checkError("setting up the source");
|
||||||
|
@ -44,7 +44,7 @@ UnlockManager::UnlockManager()
|
|||||||
// in main).
|
// in main).
|
||||||
unlock_manager=this;
|
unlock_manager=this;
|
||||||
|
|
||||||
m_locked_sound = sfx_manager->newSFX(SFXManager::SOUND_LOCKED);
|
m_locked_sound = sfx_manager->createSoundSource("locked");
|
||||||
|
|
||||||
// Read challenges from .../data
|
// Read challenges from .../data
|
||||||
// -----------------------------
|
// -----------------------------
|
||||||
|
@ -30,7 +30,7 @@
|
|||||||
const float explosion_time = 1.5f;
|
const float explosion_time = 1.5f;
|
||||||
const float burst_time = 0.1f;
|
const float burst_time = 0.1f;
|
||||||
|
|
||||||
Explosion::Explosion(const Vec3& coord, const int explosion_sound)
|
Explosion::Explosion(const Vec3& coord, const char* explosion_sound)
|
||||||
{
|
{
|
||||||
m_remaining_time = burst_time; // short emision time, explosion, not constant flame
|
m_remaining_time = burst_time; // short emision time, explosion, not constant flame
|
||||||
m_node = irr_driver->addParticleNode();
|
m_node = irr_driver->addParticleNode();
|
||||||
@ -69,7 +69,7 @@ Explosion::Explosion(const Vec3& coord, const int explosion_sound)
|
|||||||
//paf->drop();
|
//paf->drop();
|
||||||
|
|
||||||
|
|
||||||
m_explode_sound = sfx_manager->newSFX( (SFXManager::SFXType)explosion_sound );
|
m_explode_sound = sfx_manager->createSoundSource( explosion_sound );
|
||||||
init(coord);
|
init(coord);
|
||||||
} // Explosion
|
} // Explosion
|
||||||
|
|
||||||
|
@ -34,7 +34,7 @@ private:
|
|||||||
scene::IParticleSystemSceneNode *m_node;
|
scene::IParticleSystemSceneNode *m_node;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
Explosion(const Vec3& coord, const int explosion_sound);
|
Explosion(const Vec3& coord, const char* explosion_sound);
|
||||||
~Explosion();
|
~Explosion();
|
||||||
void init (const Vec3& coord);
|
void init (const Vec3& coord);
|
||||||
void update (float delta_t);
|
void update (float delta_t);
|
||||||
|
@ -39,7 +39,7 @@ public:
|
|||||||
static void init(const XMLNode &node, scene::IMesh *bowling);
|
static void init(const XMLNode &node, scene::IMesh *bowling);
|
||||||
virtual void update(float dt);
|
virtual void update(float dt);
|
||||||
|
|
||||||
int getExplosionSound() const { return SFXManager::SOUND_BOWLING_STRIKE; }
|
const char* getExplosionSound() const { return "bowling_strike"; }
|
||||||
|
|
||||||
}; // Bowling
|
}; // Bowling
|
||||||
|
|
||||||
|
@ -128,7 +128,7 @@ public:
|
|||||||
void setHasHit () { m_has_hit_something = true; }
|
void setHasHit () { m_has_hit_something = true; }
|
||||||
void reset () { Moveable::reset(); }
|
void reset () { Moveable::reset(); }
|
||||||
bool isOwnerImmunity(const Kart *kart_hit) const;
|
bool isOwnerImmunity(const Kart *kart_hit) const;
|
||||||
virtual int getExplosionSound() const { return SFXManager::SOUND_EXPLOSION; }
|
virtual const char* getExplosionSound() const { return "explosion"; }
|
||||||
/** Indicates if an explosion needs to be added if this flyable
|
/** Indicates if an explosion needs to be added if this flyable
|
||||||
* is removed. */
|
* is removed. */
|
||||||
virtual bool needsExplosion() const {return true;}
|
virtual bool needsExplosion() const {return true;}
|
||||||
|
@ -81,30 +81,30 @@ void Powerup::set(PowerupType type, int n)
|
|||||||
break ;
|
break ;
|
||||||
|
|
||||||
case POWERUP_BOWLING:
|
case POWERUP_BOWLING:
|
||||||
m_sound_use = sfx_manager->newSFX(SFXManager::SOUND_BOWLING_ROLL);
|
m_sound_use = sfx_manager->createSoundSource("bowling_roll");
|
||||||
break ;
|
break ;
|
||||||
|
|
||||||
case POWERUP_ANVIL:
|
case POWERUP_ANVIL:
|
||||||
m_sound_use = sfx_manager->newSFX(SFXManager::SOUND_USE_ANVIL);
|
m_sound_use = sfx_manager->createSoundSource("use_anvil");
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case POWERUP_PARACHUTE:
|
case POWERUP_PARACHUTE:
|
||||||
m_sound_use = sfx_manager->newSFX(SFXManager::SOUND_USE_PARACHUTE);
|
m_sound_use = sfx_manager->createSoundSource("use_parachute");
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case POWERUP_BUBBLEGUM:
|
case POWERUP_BUBBLEGUM:
|
||||||
m_sound_use = sfx_manager->newSFX(SFXManager::SOUND_GOO);
|
m_sound_use = sfx_manager->createSoundSource("goo");
|
||||||
break ;
|
break ;
|
||||||
|
|
||||||
case POWERUP_SWITCH:
|
case POWERUP_SWITCH:
|
||||||
m_sound_use = sfx_manager->newSFX(SFXManager::SOUND_SWAP);
|
m_sound_use = sfx_manager->createSoundSource("swap");
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case POWERUP_NOTHING:
|
case POWERUP_NOTHING:
|
||||||
case POWERUP_CAKE:
|
case POWERUP_CAKE:
|
||||||
case POWERUP_PLUNGER:
|
case POWERUP_PLUNGER:
|
||||||
default :
|
default :
|
||||||
m_sound_use = sfx_manager->newSFX(SFXManager::SOUND_SHOT);
|
m_sound_use = sfx_manager->createSoundSource("shot");
|
||||||
break ;
|
break ;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -129,7 +129,7 @@ void Powerup::use()
|
|||||||
{
|
{
|
||||||
//if (m_type == POWERUP_SWITCH) m_sound_use = sfx_manager->newSFX(SFXManager::SOUND_SWAP);
|
//if (m_type == POWERUP_SWITCH) m_sound_use = sfx_manager->newSFX(SFXManager::SOUND_SWAP);
|
||||||
//else
|
//else
|
||||||
m_sound_use = sfx_manager->newSFX(SFXManager::SOUND_SHOT);
|
m_sound_use = sfx_manager->createSoundSource("shot");
|
||||||
}
|
}
|
||||||
|
|
||||||
m_number--;
|
m_number--;
|
||||||
|
@ -186,7 +186,7 @@ Flyable *ProjectileManager::newProjectile(Kart *kart, PowerupType type)
|
|||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
/** See if there is an old, unused explosion object available. If so,
|
/** See if there is an old, unused explosion object available. If so,
|
||||||
* reuse this object, otherwise create a new one. */
|
* reuse this object, otherwise create a new one. */
|
||||||
Explosion* ProjectileManager::newExplosion(const Vec3& coord, const int explosion_sound)
|
Explosion* ProjectileManager::newExplosion(const Vec3& coord, const char* explosion_sound)
|
||||||
{
|
{
|
||||||
Explosion *e = new Explosion(coord, explosion_sound);
|
Explosion *e = new Explosion(coord, explosion_sound);
|
||||||
m_active_explosions.push_back(e);
|
m_active_explosions.push_back(e);
|
||||||
|
@ -66,7 +66,7 @@ public:
|
|||||||
void cleanup ();
|
void cleanup ();
|
||||||
void update (float dt);
|
void update (float dt);
|
||||||
Flyable* newProjectile (Kart *kart, PowerupType type);
|
Flyable* newProjectile (Kart *kart, PowerupType type);
|
||||||
Explosion* newExplosion (const Vec3& coord, const int explosion_sound=(SFXManager::SFXType)SFXManager::SOUND_EXPLOSION);
|
Explosion* newExplosion (const Vec3& coord, const char* explosion_sound="explosion");
|
||||||
void Deactivate (Flyable *p) {}
|
void Deactivate (Flyable *p) {}
|
||||||
void removeTextures ();
|
void removeTextures ();
|
||||||
};
|
};
|
||||||
|
@ -50,11 +50,11 @@ PlayerController::PlayerController(Kart *kart, ActivePlayer *player,
|
|||||||
kart->setCamera(new Camera(player_index, kart));
|
kart->setCamera(new Camera(player_index, kart));
|
||||||
kart->getCamera()->setMode(Camera::CM_NORMAL);
|
kart->getCamera()->setMode(Camera::CM_NORMAL);
|
||||||
|
|
||||||
m_bzzt_sound = sfx_manager->newSFX(SFXManager::SOUND_BZZT );
|
m_bzzt_sound = sfx_manager->createSoundSource( "bzzt" );
|
||||||
m_wee_sound = sfx_manager->newSFX(SFXManager::SOUND_WEE );
|
m_wee_sound = sfx_manager->createSoundSource( "wee" );
|
||||||
m_ugh_sound = sfx_manager->newSFX(SFXManager::SOUND_UGH );
|
m_ugh_sound = sfx_manager->createSoundSource( "ugh" );
|
||||||
m_grab_sound = sfx_manager->newSFX(SFXManager::SOUND_GRAB );
|
m_grab_sound = sfx_manager->createSoundSource( "grab" );
|
||||||
m_full_sound = sfx_manager->newSFX(SFXManager::SOUND_FULL );
|
m_full_sound = sfx_manager->createSoundSource( "full" );
|
||||||
|
|
||||||
reset();
|
reset();
|
||||||
} // PlayerController
|
} // PlayerController
|
||||||
|
@ -88,8 +88,8 @@ Kart::Kart (const std::string& ident, int position,
|
|||||||
|
|
||||||
m_view_blocked_by_plunger = 0;
|
m_view_blocked_by_plunger = 0;
|
||||||
|
|
||||||
// Initialize custom sound vector
|
// Initialize custom sound vector (TODO: add back when properly done)
|
||||||
m_custom_sounds.resize(SFXManager::NUM_CUSTOMS);
|
// m_custom_sounds.resize(SFXManager::NUM_CUSTOMS);
|
||||||
|
|
||||||
// Set position and heading:
|
// Set position and heading:
|
||||||
m_reset_transform = init_transform;
|
m_reset_transform = init_transform;
|
||||||
@ -109,21 +109,24 @@ Kart::Kart (const std::string& ident, int position,
|
|||||||
m_kart_mode = KM_RACE;
|
m_kart_mode = KM_RACE;
|
||||||
m_wheel_rotation = 0;
|
m_wheel_rotation = 0;
|
||||||
|
|
||||||
// Create SFXBase for each custom sound
|
// Create SFXBase for each custom sound (TODO: add back when properly done)
|
||||||
|
/*
|
||||||
for (int n = 0; n < SFXManager::NUM_CUSTOMS; n++)
|
for (int n = 0; n < SFXManager::NUM_CUSTOMS; n++)
|
||||||
{
|
{
|
||||||
int id = m_kart_properties->getCustomSfxId((SFXManager::CustomSFX)n);
|
int id = m_kart_properties->getCustomSfxId((SFXManager::CustomSFX)n);
|
||||||
|
|
||||||
// If id == -1 the custom sound was not defined in the .irrkart config file
|
// If id == -1 the custom sound was not defined in the .irrkart config file
|
||||||
if (id != -1)
|
if (id != -1)
|
||||||
|
{
|
||||||
m_custom_sounds[n] = sfx_manager->newSFX(id);
|
m_custom_sounds[n] = sfx_manager->newSFX(id);
|
||||||
}
|
}
|
||||||
|
}*/
|
||||||
|
|
||||||
m_engine_sound = sfx_manager->newSFX(m_kart_properties->getEngineSfxType());
|
m_engine_sound = sfx_manager->createSoundSource(m_kart_properties->getEngineSfxType());
|
||||||
m_beep_sound = sfx_manager->newSFX( SFXManager::SOUND_BEEP );
|
m_beep_sound = sfx_manager->createSoundSource( "beep" );
|
||||||
m_crash_sound = sfx_manager->newSFX( SFXManager::SOUND_CRASH );
|
m_crash_sound = sfx_manager->createSoundSource( "crash" );
|
||||||
m_goo_sound = sfx_manager->newSFX( SFXManager::SOUND_GOO );
|
m_goo_sound = sfx_manager->createSoundSource( "goo" );
|
||||||
m_skid_sound = sfx_manager->newSFX( SFXManager::SOUND_SKID );
|
m_skid_sound = sfx_manager->createSoundSource( "skid" );
|
||||||
|
|
||||||
if(!m_engine_sound)
|
if(!m_engine_sound)
|
||||||
{
|
{
|
||||||
@ -280,12 +283,13 @@ Kart::~Kart()
|
|||||||
m_engine_sound->stop();
|
m_engine_sound->stop();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Delete all custom sounds
|
// Delete all custom sounds (TODO: add back when properly done)
|
||||||
|
/*
|
||||||
for (int n = 0; n < SFXManager::NUM_CUSTOMS; n++)
|
for (int n = 0; n < SFXManager::NUM_CUSTOMS; n++)
|
||||||
{
|
{
|
||||||
if (m_custom_sounds[n] != NULL)
|
if (m_custom_sounds[n] != NULL)
|
||||||
sfx_manager->deleteSFX(m_custom_sounds[n]);
|
sfx_manager->deleteSFX(m_custom_sounds[n]);
|
||||||
}
|
}*/
|
||||||
|
|
||||||
sfx_manager->deleteSFX(m_engine_sound );
|
sfx_manager->deleteSFX(m_engine_sound );
|
||||||
sfx_manager->deleteSFX(m_crash_sound );
|
sfx_manager->deleteSFX(m_crash_sound );
|
||||||
@ -669,10 +673,12 @@ void Kart::update(float dt)
|
|||||||
|
|
||||||
Moveable::update(dt);
|
Moveable::update(dt);
|
||||||
|
|
||||||
|
/* (TODO: add back when properly done)
|
||||||
for (int n = 0; n < SFXManager::NUM_CUSTOMS; n++)
|
for (int n = 0; n < SFXManager::NUM_CUSTOMS; n++)
|
||||||
{
|
{
|
||||||
if (m_custom_sounds[n] != NULL) m_custom_sounds[n]->position ( getXYZ() );
|
if (m_custom_sounds[n] != NULL) m_custom_sounds[n]->position ( getXYZ() );
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
m_beep_sound->position ( getXYZ() );
|
m_beep_sound->position ( getXYZ() );
|
||||||
m_engine_sound->position ( getXYZ() );
|
m_engine_sound->position ( getXYZ() );
|
||||||
@ -993,6 +999,10 @@ void Kart::beep()
|
|||||||
|
|
||||||
bool Kart::playCustomSFX(unsigned int type)
|
bool Kart::playCustomSFX(unsigned int type)
|
||||||
{
|
{
|
||||||
|
// (TODO: add back when properly done)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
/*
|
||||||
bool ret = false;
|
bool ret = false;
|
||||||
|
|
||||||
// Stop all other character voices for this kart before playing a new one
|
// Stop all other character voices for this kart before playing a new one
|
||||||
@ -1012,13 +1022,16 @@ bool Kart::playCustomSFX(unsigned int type)
|
|||||||
if (m_custom_sounds[type] != NULL)
|
if (m_custom_sounds[type] != NULL)
|
||||||
{
|
{
|
||||||
ret = true;
|
ret = true;
|
||||||
printf("Kart SFX: playing %s for %s.\n", sfx_manager->getCustomTagName(type), m_kart_properties->getIdent().c_str());
|
//printf("Kart SFX: playing %s for %s.\n", sfx_manager->getCustomTagName(type), m_kart_properties->getIdent().c_str());
|
||||||
// If it's already playing, let it finish
|
// If it's already playing, let it finish
|
||||||
if (m_custom_sounds[type]->getStatus() != SFXManager::SFX_PLAYING)
|
if (m_custom_sounds[type]->getStatus() != SFXManager::SFX_PLAYING)
|
||||||
|
{
|
||||||
m_custom_sounds[type]->play();
|
m_custom_sounds[type]->play();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return ret;
|
return ret;
|
||||||
|
*/
|
||||||
}
|
}
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
void Kart::updatePhysics (float dt)
|
void Kart::updatePhysics (float dt)
|
||||||
|
@ -80,10 +80,10 @@ KartProperties::KartProperties(const std::string &filename) : m_icon_material(0)
|
|||||||
m_version = 0;
|
m_version = 0;
|
||||||
m_color = video::SColor(255, 0, 0, 0);
|
m_color = video::SColor(255, 0, 0, 0);
|
||||||
m_shape = 32; // close enough to a circle.
|
m_shape = 32; // close enough to a circle.
|
||||||
m_engine_sfx_type = SFXManager::SOUND_ENGINE_SMALL;
|
m_engine_sfx_type = "engine_small";
|
||||||
|
|
||||||
// The default constructor for stk_config uses filename=""
|
// The default constructor for stk_config uses filename=""
|
||||||
if(filename!="")
|
if (filename != "") load(filename);
|
||||||
load(filename);
|
|
||||||
} // KartProperties
|
} // KartProperties
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
@ -222,13 +222,13 @@ void KartProperties::getAllData(const XMLNode * root)
|
|||||||
std::string sfx_type_string;
|
std::string sfx_type_string;
|
||||||
root->get("engine-sound", &sfx_type_string);
|
root->get("engine-sound", &sfx_type_string);
|
||||||
|
|
||||||
if(sfx_type_string == "large")
|
if (sfx_type_string == "large")
|
||||||
{
|
{
|
||||||
m_engine_sfx_type = SFXManager::SOUND_ENGINE_LARGE;
|
m_engine_sfx_type = "engine_large";
|
||||||
}
|
}
|
||||||
else if(sfx_type_string == "small")
|
else if (sfx_type_string == "small")
|
||||||
{
|
{
|
||||||
m_engine_sfx_type = SFXManager::SOUND_ENGINE_SMALL;
|
m_engine_sfx_type = "engine_small";
|
||||||
}
|
}
|
||||||
|
|
||||||
root->get("has-skidmarks", &m_has_skidmarks);
|
root->get("has-skidmarks", &m_has_skidmarks);
|
||||||
@ -362,7 +362,8 @@ void KartProperties::getAllData(const lisp::Lisp* lisp)
|
|||||||
lisp->get("brake-factor", m_brake_factor);
|
lisp->get("brake-factor", m_brake_factor);
|
||||||
lisp->get("mass", m_mass);
|
lisp->get("mass", m_mass);
|
||||||
|
|
||||||
// Load custom kart SFX files
|
/*
|
||||||
|
// Load custom kart SFX files (TODO: enable back when it's implemented properly)
|
||||||
for (int i = 0; i < SFXManager::NUM_CUSTOMS; i++)
|
for (int i = 0; i < SFXManager::NUM_CUSTOMS; i++)
|
||||||
{
|
{
|
||||||
std::string tempFile;
|
std::string tempFile;
|
||||||
@ -385,24 +386,26 @@ void KartProperties::getAllData(const lisp::Lisp* lisp)
|
|||||||
m_custom_sfx_id[i] = -1;
|
m_custom_sfx_id[i] = -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
std::string sfx_type_string;
|
std::string sfx_type_string;
|
||||||
lisp->get("engine-sound", sfx_type_string);
|
lisp->get("engine-sound", sfx_type_string);
|
||||||
if(sfx_type_string == "large")
|
if(sfx_type_string == "large")
|
||||||
{
|
{
|
||||||
m_engine_sfx_type = SFXManager::SOUND_ENGINE_LARGE;
|
m_engine_sfx_type = "engine_large";
|
||||||
}
|
}
|
||||||
else if(sfx_type_string == "small")
|
else if(sfx_type_string == "small")
|
||||||
{
|
{
|
||||||
m_engine_sfx_type = SFXManager::SOUND_ENGINE_SMALL;
|
m_engine_sfx_type = "engine_small";
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<float> v;
|
std::vector<float> v;
|
||||||
if(lisp->getVector("max-speed-radius", v))
|
if(lisp->getVector("max-speed-radius", v))
|
||||||
{
|
{
|
||||||
if(v.size()!=2)
|
if (v.size()!=2)
|
||||||
|
{
|
||||||
printf("Incorrect max-speed-angle specifications for kart '%s'\n",
|
printf("Incorrect max-speed-angle specifications for kart '%s'\n",
|
||||||
getIdent().c_str());
|
getIdent().c_str());
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
m_max_speed_turn = v[0];
|
m_max_speed_turn = v[0];
|
||||||
|
@ -107,8 +107,7 @@ private:
|
|||||||
float m_rubber_band_duration;/**< Duration a rubber band works. */
|
float m_rubber_band_duration;/**< Duration a rubber band works. */
|
||||||
float m_wheel_base; /**< Wheel base of the kart. */
|
float m_wheel_base; /**< Wheel base of the kart. */
|
||||||
float m_nitro_power_boost; /**< Nitro power boost. */
|
float m_nitro_power_boost; /**< Nitro power boost. */
|
||||||
SFXManager::SFXType
|
std::string m_engine_sfx_type; /**< Engine sound effect. */
|
||||||
m_engine_sfx_type; /**< Engine sound effect. */
|
|
||||||
|
|
||||||
// bullet physics data
|
// bullet physics data
|
||||||
// -------------------
|
// -------------------
|
||||||
@ -207,8 +206,7 @@ public:
|
|||||||
float getTimeFullSteerAI () const {return m_time_full_steer_ai; }
|
float getTimeFullSteerAI () const {return m_time_full_steer_ai; }
|
||||||
float getBrakeFactor () const {return m_brake_factor; }
|
float getBrakeFactor () const {return m_brake_factor; }
|
||||||
float getMaxSpeedReverseRatio () const {return m_max_speed_reverse_ratio; }
|
float getMaxSpeedReverseRatio () const {return m_max_speed_reverse_ratio; }
|
||||||
SFXManager::SFXType getEngineSfxType()
|
const char* getEngineSfxType () const {return m_engine_sfx_type.c_str(); }
|
||||||
const {return m_engine_sfx_type; }
|
|
||||||
|
|
||||||
//bullet physics get functions
|
//bullet physics get functions
|
||||||
float getSuspensionStiffness () const {return m_suspension_stiffness; }
|
float getSuspensionStiffness () const {return m_suspension_stiffness; }
|
||||||
|
@ -34,8 +34,8 @@ WorldStatus::WorldStatus()
|
|||||||
m_phase = SETUP_PHASE;
|
m_phase = SETUP_PHASE;
|
||||||
|
|
||||||
// FIXME - is it a really good idea to reload and delete the sound every race??
|
// FIXME - is it a really good idea to reload and delete the sound every race??
|
||||||
m_prestart_sound = sfx_manager->newSFX(SFXManager::SOUND_PRESTART);
|
m_prestart_sound = sfx_manager->createSoundSource("prestart");
|
||||||
m_start_sound = sfx_manager->newSFX(SFXManager::SOUND_START);
|
m_start_sound = sfx_manager->createSoundSource("start");
|
||||||
} // WorldStatus
|
} // WorldStatus
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
|
@ -423,7 +423,7 @@ FocusDispatcher* g_dispatcher = NULL;
|
|||||||
playerName->elementRemoved();
|
playerName->elementRemoved();
|
||||||
playerName = NULL;
|
playerName = NULL;
|
||||||
|
|
||||||
SFXManager::quickSound( SFXManager::SOUND_WEE );
|
SFXManager::quickSound( "wee" );
|
||||||
|
|
||||||
modelView->setRotateTo(30.0f, 150.0f);
|
modelView->setRotateTo(30.0f, 150.0f);
|
||||||
|
|
||||||
@ -834,7 +834,7 @@ bool KartSelectionScreen::playerQuit(ActivePlayer* player)
|
|||||||
// Check that this player has not already confirmed, then they can't back out
|
// Check that this player has not already confirmed, then they can't back out
|
||||||
if (m_kart_widgets[n].isReady())
|
if (m_kart_widgets[n].isReady())
|
||||||
{
|
{
|
||||||
sfx_manager->quickSound( SFXManager::SOUND_USE_ANVIL );
|
sfx_manager->quickSound( "use_anvil" );
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1311,7 +1311,7 @@ void KartSelectionScreen::eventCallback(Widget* widget, const std::string& name,
|
|||||||
|
|
||||||
//SFXType sound;
|
//SFXType sound;
|
||||||
//SOUND_UGH SOUND_CRASH SOUND_USE_ANVIL SOUND_EXPLOSION SOUND_MOVE_MENU SOUND_SELECT_MENU
|
//SOUND_UGH SOUND_CRASH SOUND_USE_ANVIL SOUND_EXPLOSION SOUND_MOVE_MENU SOUND_SELECT_MENU
|
||||||
sfx_manager->quickSound( SFXManager::SOUND_USE_ANVIL );
|
sfx_manager->quickSound( "use_anvil" );
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -160,8 +160,7 @@ void OptionsScreenAV::eventCallback(Widget* widget, const std::string& name, con
|
|||||||
SpinnerWidget* w = dynamic_cast<SpinnerWidget*>(widget);
|
SpinnerWidget* w = dynamic_cast<SpinnerWidget*>(widget);
|
||||||
assert(w != NULL);
|
assert(w != NULL);
|
||||||
|
|
||||||
if(sample_sound == NULL)
|
if (sample_sound == NULL) sample_sound = sfx_manager->createSoundSource( "skid" );
|
||||||
sample_sound = sfx_manager->newSFX( SFXManager::SOUND_SKID );
|
|
||||||
sample_sound->volume(1);
|
sample_sound->volume(1);
|
||||||
|
|
||||||
sfx_manager->setMasterSFXVolume( w->getValue()/10.0f );
|
sfx_manager->setMasterSFXVolume( w->getValue()/10.0f );
|
||||||
|
Loading…
Reference in New Issue
Block a user