- sound system is now threaded by default (hopefully this fixes buffer underruns errors from openal)
- background music now plays when game is loading
This commit is contained in:
parent
9ba8668751
commit
d16f6a93bc
|
@ -611,7 +611,10 @@ void Game::init(bool initForPreviewOnly)
|
||||||
|
|
||||||
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||||
//sounds
|
//sounds
|
||||||
|
|
||||||
SoundRenderer &soundRenderer= SoundRenderer::getInstance();
|
SoundRenderer &soundRenderer= SoundRenderer::getInstance();
|
||||||
|
soundRenderer.stopAllSounds();
|
||||||
|
soundRenderer= SoundRenderer::getInstance();
|
||||||
|
|
||||||
Tileset *tileset= world.getTileset();
|
Tileset *tileset= world.getTileset();
|
||||||
AmbientSounds *ambientSounds= tileset->getAmbientSounds();
|
AmbientSounds *ambientSounds= tileset->getAmbientSounds();
|
||||||
|
|
|
@ -301,7 +301,7 @@ void Program::loopWorker() {
|
||||||
if(prevState == this->programState) {
|
if(prevState == this->programState) {
|
||||||
//SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
//SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||||
|
|
||||||
if(soundThreadManager == NULL) {
|
if(soundThreadManager == NULL || soundThreadManager->isThreadExecutionLagging()) {
|
||||||
SoundRenderer::getInstance().update();
|
SoundRenderer::getInstance().update();
|
||||||
if(chronoUpdateLoop.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s Line: %d] SoundRenderer::getInstance().update() took msecs: %lld, updateCount = %d\n",__FILE__,__FUNCTION__,__LINE__,chronoUpdateLoop.getMillis(),updateCount);
|
if(chronoUpdateLoop.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s Line: %d] SoundRenderer::getInstance().update() took msecs: %lld, updateCount = %d\n",__FILE__,__FUNCTION__,__LINE__,chronoUpdateLoop.getMillis(),updateCount);
|
||||||
if(chronoUpdateLoop.getMillis() > 0) chronoUpdateLoop.start();
|
if(chronoUpdateLoop.getMillis() > 0) chronoUpdateLoop.start();
|
||||||
|
@ -553,10 +553,11 @@ void Program::init(WindowGl *window, bool initSound, bool toggleFullScreen){
|
||||||
}
|
}
|
||||||
|
|
||||||
// Run sound streaming in a background thread if enabled
|
// Run sound streaming in a background thread if enabled
|
||||||
if(config.getBool("ThreadedSoundStream","false") == true) {
|
if(SoundRenderer::getInstance().runningThreaded() == true) {
|
||||||
BaseThread::shutdownAndWait(soundThreadManager);
|
if(BaseThread::shutdownAndWait(soundThreadManager) == true) {
|
||||||
delete soundThreadManager;
|
delete soundThreadManager;
|
||||||
soundThreadManager = new SimpleTaskThread(&SoundRenderer::getInstance(),0,50);
|
}
|
||||||
|
soundThreadManager = new SimpleTaskThread(&SoundRenderer::getInstance(),0,10);
|
||||||
soundThreadManager->setUniqueID(__FILE__);
|
soundThreadManager->setUniqueID(__FILE__);
|
||||||
soundThreadManager->start();
|
soundThreadManager->start();
|
||||||
}
|
}
|
||||||
|
|
|
@ -76,8 +76,8 @@ MainMenu::~MainMenu() {
|
||||||
|
|
||||||
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||||
|
|
||||||
SoundRenderer &soundRenderer= SoundRenderer::getInstance();
|
//SoundRenderer &soundRenderer= SoundRenderer::getInstance();
|
||||||
soundRenderer.stopAllSounds();
|
//soundRenderer.stopAllSounds();
|
||||||
|
|
||||||
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1361,6 +1361,10 @@ void MenuStateCustomGame::update() {
|
||||||
Chrono chrono;
|
Chrono chrono;
|
||||||
chrono.start();
|
chrono.start();
|
||||||
|
|
||||||
|
// Test openal buffer underrun issue
|
||||||
|
//sleep(200);
|
||||||
|
// END
|
||||||
|
|
||||||
MutexSafeWrapper safeMutex((publishToMasterserverThread != NULL ? publishToMasterserverThread->getMutexThreadObjectAccessor() : NULL));
|
MutexSafeWrapper safeMutex((publishToMasterserverThread != NULL ? publishToMasterserverThread->getMutexThreadObjectAccessor() : NULL));
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|
|
@ -37,8 +37,10 @@ SoundRenderer::SoundRenderer() {
|
||||||
soundPlayer = NULL;
|
soundPlayer = NULL;
|
||||||
loadConfig();
|
loadConfig();
|
||||||
|
|
||||||
runThreadSafe = false;
|
Config &config= Config::getInstance();
|
||||||
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
runThreadSafe = config.getBool("ThreadedSoundStream","true");
|
||||||
|
|
||||||
|
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] runThreadSafe = %d\n",__FILE__,__FUNCTION__,__LINE__,runThreadSafe);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool SoundRenderer::init(Window *window) {
|
bool SoundRenderer::init(Window *window) {
|
||||||
|
@ -46,14 +48,18 @@ bool SoundRenderer::init(Window *window) {
|
||||||
|
|
||||||
SoundInterface &si= SoundInterface::getInstance();
|
SoundInterface &si= SoundInterface::getInstance();
|
||||||
FactoryRepository &fr= FactoryRepository::getInstance();
|
FactoryRepository &fr= FactoryRepository::getInstance();
|
||||||
Config &config= Config::getInstance();
|
|
||||||
runThreadSafe = config.getBool("ThreadedSoundStream","false");
|
|
||||||
|
|
||||||
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||||
|
Config &config= Config::getInstance();
|
||||||
si.setFactory(fr.getSoundFactory(config.getString("FactorySound")));
|
si.setFactory(fr.getSoundFactory(config.getString("FactorySound")));
|
||||||
|
|
||||||
stopAllSounds();
|
stopAllSounds();
|
||||||
|
|
||||||
|
MutexSafeWrapper safeMutex(NULL);
|
||||||
|
if(runThreadSafe == true) {
|
||||||
|
safeMutex.setMutex(&mutex);
|
||||||
|
}
|
||||||
|
|
||||||
soundPlayer= si.newSoundPlayer();
|
soundPlayer= si.newSoundPlayer();
|
||||||
if(soundPlayer != NULL) {
|
if(soundPlayer != NULL) {
|
||||||
SoundPlayerParams soundPlayerParams;
|
SoundPlayerParams soundPlayerParams;
|
||||||
|
@ -61,6 +67,7 @@ bool SoundRenderer::init(Window *window) {
|
||||||
soundPlayerParams.strBufferCount= config.getInt("SoundStreamingBuffers");
|
soundPlayerParams.strBufferCount= config.getInt("SoundStreamingBuffers");
|
||||||
soundPlayer->init(&soundPlayerParams);
|
soundPlayer->init(&soundPlayerParams);
|
||||||
}
|
}
|
||||||
|
safeMutex.ReleaseLock();
|
||||||
|
|
||||||
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||||
|
|
||||||
|
@ -89,6 +96,10 @@ SoundRenderer::~SoundRenderer() {
|
||||||
|
|
||||||
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||||
|
|
||||||
|
MutexSafeWrapper safeMutex(NULL);
|
||||||
|
if(runThreadSafe == true) {
|
||||||
|
safeMutex.setMutex(&mutex);
|
||||||
|
}
|
||||||
delete soundPlayer;
|
delete soundPlayer;
|
||||||
soundPlayer = NULL;
|
soundPlayer = NULL;
|
||||||
|
|
||||||
|
|
|
@ -79,6 +79,8 @@ public:
|
||||||
void loadConfig();
|
void loadConfig();
|
||||||
|
|
||||||
bool wasInitOk() const;
|
bool wasInitOk() const;
|
||||||
|
|
||||||
|
bool runningThreaded() const { return runThreadSafe; }
|
||||||
};
|
};
|
||||||
|
|
||||||
}}//end namespace
|
}}//end namespace
|
||||||
|
|
|
@ -63,6 +63,9 @@ protected:
|
||||||
bool taskSignalled;
|
bool taskSignalled;
|
||||||
bool needTaskSignal;
|
bool needTaskSignal;
|
||||||
|
|
||||||
|
Mutex mutexLastExecuteTimestamp;
|
||||||
|
time_t lastExecuteTimestamp;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
SimpleTaskThread();
|
SimpleTaskThread();
|
||||||
SimpleTaskThread(SimpleTaskCallbackInterface *simpleTaskInterface,
|
SimpleTaskThread(SimpleTaskCallbackInterface *simpleTaskInterface,
|
||||||
|
@ -74,6 +77,8 @@ public:
|
||||||
|
|
||||||
void setTaskSignalled(bool value);
|
void setTaskSignalled(bool value);
|
||||||
bool getTaskSignalled();
|
bool getTaskSignalled();
|
||||||
|
|
||||||
|
bool isThreadExecutionLagging();
|
||||||
};
|
};
|
||||||
|
|
||||||
// =====================================================
|
// =====================================================
|
||||||
|
|
|
@ -85,6 +85,18 @@ SimpleTaskThread::SimpleTaskThread( SimpleTaskCallbackInterface *simpleTaskInter
|
||||||
this->millisecsBetweenExecutions = millisecsBetweenExecutions;
|
this->millisecsBetweenExecutions = millisecsBetweenExecutions;
|
||||||
this->needTaskSignal = needTaskSignal;
|
this->needTaskSignal = needTaskSignal;
|
||||||
setTaskSignalled(false);
|
setTaskSignalled(false);
|
||||||
|
|
||||||
|
MutexSafeWrapper safeMutex(&mutexLastExecuteTimestamp);
|
||||||
|
lastExecuteTimestamp = time(NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool SimpleTaskThread::isThreadExecutionLagging() {
|
||||||
|
bool result = false;
|
||||||
|
MutexSafeWrapper safeMutex(&mutexLastExecuteTimestamp);
|
||||||
|
result = (difftime(time(NULL),lastExecuteTimestamp) >= 5.0);
|
||||||
|
safeMutex.ReleaseLock();
|
||||||
|
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool SimpleTaskThread::canShutdown(bool deleteSelfIfShutdownDelayed) {
|
bool SimpleTaskThread::canShutdown(bool deleteSelfIfShutdownDelayed) {
|
||||||
|
@ -124,8 +136,12 @@ void SimpleTaskThread::execute() {
|
||||||
else if(runTask == true) {
|
else if(runTask == true) {
|
||||||
//SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] uniqueID [%s]\n",__FILE__,__FUNCTION__,__LINE__,this->getUniqueID().c_str());
|
//SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] uniqueID [%s]\n",__FILE__,__FUNCTION__,__LINE__,this->getUniqueID().c_str());
|
||||||
if(getQuitStatus() == false) {
|
if(getQuitStatus() == false) {
|
||||||
ExecutingTaskSafeWrapper safeExecutingTaskMutex(this);
|
ExecutingTaskSafeWrapper safeExecutingTaskMutex(this);
|
||||||
this->simpleTaskInterface->simpleTask(this);
|
this->simpleTaskInterface->simpleTask(this);
|
||||||
|
|
||||||
|
MutexSafeWrapper safeMutex(&mutexLastExecuteTimestamp);
|
||||||
|
lastExecuteTimestamp = time(NULL);
|
||||||
|
safeMutex.ReleaseLock();
|
||||||
}
|
}
|
||||||
//SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] uniqueID [%s]\n",__FILE__,__FUNCTION__,__LINE__,this->getUniqueID().c_str());
|
//SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] uniqueID [%s]\n",__FILE__,__FUNCTION__,__LINE__,this->getUniqueID().c_str());
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue