mirror of
https://github.com/OpenSpace/OpenSpace.git
synced 2026-02-25 14:29:03 -06:00
added serialize, deserialize, post sync and pre sync functions for script engine
This commit is contained in:
@@ -34,6 +34,8 @@
|
||||
*/
|
||||
|
||||
namespace openspace {
|
||||
class SyncBuffer;
|
||||
|
||||
namespace scripting {
|
||||
|
||||
class ScriptEngine {
|
||||
@@ -67,6 +69,16 @@ public:
|
||||
|
||||
bool writeDocumentation(const std::string& filename, const std::string& type) const;
|
||||
|
||||
void serialize(SyncBuffer* syncBuffer);
|
||||
|
||||
void deserialize(SyncBuffer* syncBuffer);
|
||||
|
||||
void postSynchronizationPreDraw();
|
||||
|
||||
void preSynchronization();
|
||||
|
||||
void queueScript(const std::string &script);
|
||||
|
||||
std::vector<std::string> allLuaFunctions() const;
|
||||
|
||||
private:
|
||||
@@ -80,6 +92,11 @@ private:
|
||||
|
||||
lua_State* _state;
|
||||
std::set<LuaLibrary> _registeredLibraries;
|
||||
|
||||
//sync variables
|
||||
std::mutex _mutex;
|
||||
std::vector<std::string> _queuedScripts;
|
||||
std::string _currentSyncedScript;
|
||||
};
|
||||
|
||||
} // namespace scripting
|
||||
|
||||
@@ -26,6 +26,7 @@
|
||||
|
||||
#include <ghoul/logging/logmanager.h>
|
||||
#include <ghoul/filesystem/filesystem.h>
|
||||
#include <openspace/util/syncbuffer.h>
|
||||
|
||||
#include <ghoul/lua/lua_helper.h>
|
||||
#include <fstream>
|
||||
@@ -605,6 +606,45 @@ bool ScriptEngine::writeDocumentation(const std::string& filename, const std::st
|
||||
}
|
||||
}
|
||||
|
||||
void ScriptEngine::serialize(SyncBuffer* syncBuffer){
|
||||
syncBuffer->encode(_currentSyncedScript);
|
||||
}
|
||||
|
||||
void ScriptEngine::deserialize(SyncBuffer* syncBuffer){
|
||||
syncBuffer->decode(_currentSyncedScript);
|
||||
}
|
||||
|
||||
void ScriptEngine::postSynchronizationPreDraw(){
|
||||
|
||||
}
|
||||
|
||||
void ScriptEngine::preSynchronization(){
|
||||
if (!_currentSyncedScript.empty()){
|
||||
runScript(_currentSyncedScript);
|
||||
_currentSyncedScript.clear();
|
||||
}
|
||||
|
||||
_mutex.lock();
|
||||
|
||||
if (!_queuedScripts.empty()){
|
||||
_currentSyncedScript = _queuedScripts.back();
|
||||
_queuedScripts.pop_back();
|
||||
}
|
||||
|
||||
_mutex.unlock();
|
||||
}
|
||||
|
||||
void ScriptEngine::queueScript(const std::string &script){
|
||||
if (script.empty())
|
||||
return;
|
||||
|
||||
_mutex.lock();
|
||||
|
||||
_queuedScripts.insert(_queuedScripts.begin(), script);
|
||||
|
||||
_mutex.unlock();
|
||||
}
|
||||
|
||||
|
||||
} // namespace scripting
|
||||
} // namespace openspace
|
||||
|
||||
Reference in New Issue
Block a user