Parallelize SFX loading, 7% speedup in load time

Vorbis and AL are thread-safe.


git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/main/trunk@13549 178a84e3-b1eb-0310-8ba1-8eac791a3b58
This commit is contained in:
curaga
2013-08-22 15:43:24 +00:00
parent 138d61554c
commit 5d7e846969
2 changed files with 36 additions and 9 deletions

View File

@@ -154,14 +154,16 @@ void SFXManager::loadSfx()
std::cerr << "Could not read sounf effects XML file " << sfx_config_name.c_str() << std::endl;
}
int i;
const int amount = root->getNumNodes();
for (int i=0; i<amount; i++)
for (i=0; i<amount; i++)
{
const XMLNode* node = root->getNode(i);
if (node->getName() == "sfx")
{
loadSingleSfx(node);
loadSingleSfx(node, "", false);
}
else
{
@@ -171,7 +173,27 @@ void SFXManager::loadSfx()
}// nend for
delete root;
} // loadSfx
// Now load them in parallel
const int max = m_all_sfx_types.size();
SFXBuffer **array = new SFXBuffer *[max];
i = 0;
for (std::map<std::string, SFXBuffer*>::iterator it = m_all_sfx_types.begin();
it != m_all_sfx_types.end(); it++)
{
SFXBuffer* const buffer = (*it).second;
array[i++] = buffer;
}
#pragma omp parallel for private(i)
for (i = 0; i < max; i++)
{
array[i]->load();
}
delete [] array;
} // loadSfx
// -----------------------------------------------------------------------------
/** Introduces a mechanism by which one can load sound effects beyond the basic
@@ -188,7 +210,8 @@ SFXBuffer* SFXManager::addSingleSfx(const std::string &sfx_name,
bool positional,
float rolloff,
float max_width,
float gain)
float gain,
const bool load)
{
SFXBuffer* buffer = new SFXBuffer(sfx_file, positional, rolloff, max_width, gain);
@@ -205,7 +228,7 @@ SFXBuffer* SFXManager::addSingleSfx(const std::string &sfx_name,
if (UserConfigParams::logMisc())
Log::debug("SFXManager", "Loading SFX %s\n", sfx_file.c_str());
if (buffer->load()) return buffer;
if (load && buffer->load()) return buffer;
return NULL;
} // addSingleSFX
@@ -215,7 +238,8 @@ SFXBuffer* SFXManager::addSingleSfx(const std::string &sfx_name,
* \param node The XML node with the data for this sfx.
*/
SFXBuffer* SFXManager::loadSingleSfx(const XMLNode* node,
const std::string &path)
const std::string &path,
const bool load)
{
std::string filename;
@@ -254,7 +278,8 @@ SFXBuffer* SFXManager::loadSingleSfx(const XMLNode* node,
tmpbuffer.isPositional(),
tmpbuffer.getRolloff(),
tmpbuffer.getMaxDist(),
tmpbuffer.getGain());
tmpbuffer.getGain(),
load);
} // loadSingleSfx

View File

@@ -106,13 +106,15 @@ public:
virtual ~SFXManager();
bool sfxAllowed();
SFXBuffer* loadSingleSfx(const XMLNode* node,
const std::string &path=std::string(""));
const std::string &path=std::string(""),
const bool load = true);
SFXBuffer* addSingleSfx(const std::string &sfx_name,
const std::string &filename,
bool positional,
float rolloff,
float max_width,
float gain);
float gain,
const bool load = true);
SFXBase* createSoundSource(SFXBuffer* info,
const bool addToSFXList=true,