From d76e18d9ee914698eaabf1c0573098e6d1cda8cb Mon Sep 17 00:00:00 2001 From: Joakim Kilby Date: Sun, 5 Jul 2015 17:21:23 +0200 Subject: [PATCH] more work on scripting synchronization and state saving --- .../openspace/network/parallelconnection.h | 6 +++ src/network/parallelconnection.cpp | 52 +++++++++++++++++++ 2 files changed, 58 insertions(+) diff --git a/include/openspace/network/parallelconnection.h b/include/openspace/network/parallelconnection.h index e20ba4d9c4..84d7c79d63 100644 --- a/include/openspace/network/parallelconnection.h +++ b/include/openspace/network/parallelconnection.h @@ -40,6 +40,7 @@ #include #include #include +#include #ifdef __WIN32__ #ifndef WIN32_LEAN_AND_MEAN @@ -90,6 +91,8 @@ namespace openspace{ void preSynchronization(); + void scriptMessage(const std::string propIdentifier, const std::string propValue); + enum MessageTypes{ Authentication=0, Initialization, @@ -171,6 +174,8 @@ namespace openspace{ void threadManagement(); + std::string scriptFromPropertyAndValue(const std::string property, const std::string value); + uint32_t _passCode; std::string _port; std::string _address; @@ -192,6 +197,7 @@ namespace openspace{ network::datamessagestructures::TimeKeyframe _latestTimeKeyframe; std::mutex _timeKeyframeMutex; std::atomic _latestTimeKeyframeValid; + std::map _currentState; }; } // namespace network diff --git a/src/network/parallelconnection.cpp b/src/network/parallelconnection.cpp index 78edcd7062..2b79b7eead 100644 --- a/src/network/parallelconnection.cpp +++ b/src/network/parallelconnection.cpp @@ -1004,6 +1004,58 @@ namespace openspace { } } + void ParallelConnection::scriptMessage(const std::string propIdentifier, const std::string propValue){ + + //save script as current state + _currentState[propIdentifier] = propValue; + + //construct script + std::string script = scriptFromPropertyAndValue(propIdentifier, propValue); + + //create a script message + network::datamessagestructures::ScriptMessage sm; + sm._script = script; + sm._scriptlen = static_cast(script.length()); + + //create a buffer for the script + std::vector sbuffer; + + //fill the script buffer + sm.serialize(sbuffer); + + //get the size of the keyframebuffer + uint16_t msglen = static_cast(sbuffer.size()); + + //the type of message + uint16_t type = static_cast(network::datamessagestructures::ScriptData); + + //create the full buffer + std::vector buffer; + buffer.reserve(headerSize() + sizeof(type) + sizeof(msglen) + msglen); + + //write header + writeHeader(buffer, MessageTypes::Data); + + //type of message + buffer.insert(buffer.end(), reinterpret_cast(&type), reinterpret_cast(&type) + sizeof(type)); + + //size of message + buffer.insert(buffer.end(), reinterpret_cast(&msglen), reinterpret_cast(&msglen) + sizeof(msglen)); + + //actual message + buffer.insert(buffer.end(), sbuffer.begin(), sbuffer.end()); + + //send message + queMessage(buffer); + + } + + std::string ParallelConnection::scriptFromPropertyAndValue(const std::string property, const std::string value){ + //consruct script + std::string script = "openspace.setPropertyValue(\"" + property + ",\"" + value + "\")"; + return script; + } + void ParallelConnection::broadcast(){ //while we're still connected and we're the host