Fixed synchronization bug when master runs at a different FPS than slaves.

Scripts are now queued when received and then executed,
This commit is contained in:
Joakim Kilby
2015-02-19 10:02:07 +01:00
parent 3d04af03a3
commit 417f5c8f6c
2 changed files with 15 additions and 3 deletions

View File

@@ -612,13 +612,21 @@ void ScriptEngine::serialize(SyncBuffer* syncBuffer){
void ScriptEngine::deserialize(SyncBuffer* syncBuffer){
syncBuffer->decode(_currentSyncedScript);
if (!_currentSyncedScript.empty()){
_mutex.lock();
_receivedScripts.push_back(_currentSyncedScript);
_mutex.unlock();
}
}
void ScriptEngine::postSynchronizationPreDraw(){
if (!_currentSyncedScript.empty()){
runScript(_currentSyncedScript);
_currentSyncedScript.clear();
_mutex.lock();
if (!_receivedScripts.empty()){
runScript(_receivedScripts.back());
_receivedScripts.pop_back();
}
_mutex.unlock();
}
void ScriptEngine::preSynchronization(){
@@ -628,6 +636,9 @@ void ScriptEngine::preSynchronization(){
if (!_queuedScripts.empty()){
_currentSyncedScript = _queuedScripts.back();
_queuedScripts.pop_back();
//Not really a received script but the master also needs to run the script...
_receivedScripts.push_back(_currentSyncedScript);
}
_mutex.unlock();