Throttle sfx command if the queue should get too long (might need some

tuning). Non-essential sfx (positioning, speed, looping, and play)
are discarded.
This commit is contained in:
hiker 2014-10-17 16:49:14 +11:00
parent 403702d6bb
commit 0a39842b04

View File

@ -101,7 +101,7 @@ SFXManager::SFXManager()
delete m_thread_id.getData(); delete m_thread_id.getData();
m_thread_id.unlock(); m_thread_id.unlock();
m_thread_id.setAtomic(0); m_thread_id.setAtomic(0);
Log::error("HTTP Manager", "Could not create thread, error=%d.", Log::error("SFXManager", "Could not create thread, error=%d.",
errno); errno);
} }
pthread_attr_destroy(&attr); pthread_attr_destroy(&attr);
@ -211,6 +211,23 @@ void SFXManager::queue(SFXCommands command, SFXBase *sfx, const Vec3 &p)
void SFXManager::queueCommand(SFXCommand *command) void SFXManager::queueCommand(SFXCommand *command)
{ {
m_sfx_commands.lock(); m_sfx_commands.lock();
if(m_sfx_commands.getData().size() > 20*race_manager->getNumberOfKarts()+20)
{
if(command->m_command==SFX_POSITION || command->m_command==SFX_LOOP ||
command->m_command==SFX_PLAY || command->m_command==SFX_SPEED )
{
delete command;
static int count_messages = 0;
if(count_messages < 5)
{
Log::warn("SFXManager", "Throttling sfx - queue size %d",
m_sfx_commands.getData().size());
count_messages++;
}
m_sfx_commands.unlock();
return;
} // if throttling
}
m_sfx_commands.getData().push_back(command); m_sfx_commands.getData().push_back(command);
m_sfx_commands.unlock(); m_sfx_commands.unlock();
} // queueCommand } // queueCommand
@ -266,13 +283,12 @@ void* SFXManager::mainLoop(void *obj)
pthread_cond_wait(&me->m_cond_request, me->m_sfx_commands.getMutex()); pthread_cond_wait(&me->m_cond_request, me->m_sfx_commands.getMutex());
empty = me->m_sfx_commands.getData().empty(); empty = me->m_sfx_commands.getData().empty();
} }
SFXCommand *current = me->m_sfx_commands.getData().front(); SFXCommand *current = me->m_sfx_commands.getData().front();
me->m_sfx_commands.getData().erase(me->m_sfx_commands.getData().begin()); me->m_sfx_commands.getData().erase(me->m_sfx_commands.getData().begin());
if (current->m_command == SFX_EXIT) if (current->m_command == SFX_EXIT)
break; break;
Log::verbose("sfx", "%d", me->m_sfx_commands.getData().size());
me->m_sfx_commands.unlock(); me->m_sfx_commands.unlock();
switch(current->m_command) switch(current->m_command)
{ {
@ -443,7 +459,7 @@ SFXBuffer* SFXManager::addSingleSfx(const std::string &sfx_name,
} }
if (UserConfigParams::logMisc()) if (UserConfigParams::logMisc())
Log::debug("SFXManager", "Loading SFX %s\n", sfx_file.c_str()); Log::debug("SFXManager", "Loading SFX %s", sfx_file.c_str());
if (load && buffer->load()) return buffer; if (load && buffer->load()) return buffer;
@ -463,7 +479,7 @@ SFXBuffer* SFXManager::loadSingleSfx(const XMLNode* node,
if (node->get("filename", &filename) == 0) if (node->get("filename", &filename) == 0)
{ {
Log::error("SFXManager", Log::error("SFXManager",
"/!\\ The 'filename' attribute is mandatory in the SFX XML file!\n"); "The 'filename' attribute is mandatory in the SFX XML file!");
return NULL; return NULL;
} }
@ -472,7 +488,7 @@ SFXBuffer* SFXManager::loadSingleSfx(const XMLNode* node,
if(m_all_sfx_types.find(sfx_name)!=m_all_sfx_types.end()) if(m_all_sfx_types.find(sfx_name)!=m_all_sfx_types.end())
{ {
Log::error("SFXManager", Log::error("SFXManager",
"There is already a sfx named '%s' installed - new one is ignored.\n", "There is already a sfx named '%s' installed - new one is ignored.",
sfx_name.c_str()); sfx_name.c_str());
return NULL; return NULL;
} }
@ -540,7 +556,7 @@ SFXBase* SFXManager::createSoundSource(const std::string &name,
{ {
Log::error("SFXManager", Log::error("SFXManager",
"SFXManager::createSoundSource could not find the " "SFXManager::createSoundSource could not find the "
"requested sound effect : '%s'\n", name.c_str()); "requested sound effect : '%s'.", name.c_str());
return NULL; return NULL;
} }