From 417f5c8f6c2a644b243f97e9e0cc604312a78fe2 Mon Sep 17 00:00:00 2001 From: Joakim Kilby Date: Thu, 19 Feb 2015 10:02:07 +0100 Subject: [PATCH] Fixed synchronization bug when master runs at a different FPS than slaves. Scripts are now queued when received and then executed, --- include/openspace/scripting/scriptengine.h | 1 + src/scripting/scriptengine.cpp | 17 ++++++++++++++--- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/include/openspace/scripting/scriptengine.h b/include/openspace/scripting/scriptengine.h index a28219a8ac..6a9c0c5038 100644 --- a/include/openspace/scripting/scriptengine.h +++ b/include/openspace/scripting/scriptengine.h @@ -96,6 +96,7 @@ private: //sync variables std::mutex _mutex; std::vector _queuedScripts; + std::vector _receivedScripts; std::string _currentSyncedScript; }; diff --git a/src/scripting/scriptengine.cpp b/src/scripting/scriptengine.cpp index fc749696a7..1d2e18833d 100644 --- a/src/scripting/scriptengine.cpp +++ b/src/scripting/scriptengine.cpp @@ -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();