mirror of
https://github.com/OpenSpace/OpenSpace.git
synced 2026-01-05 11:09:37 -06:00
more work on scripting synchronization and state saving
This commit is contained in:
@@ -40,6 +40,7 @@
|
||||
#include <thread>
|
||||
#include <sstream>
|
||||
#include <mutex>
|
||||
#include <map>
|
||||
|
||||
#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<bool> _latestTimeKeyframeValid;
|
||||
std::map<std::string, std::string> _currentState;
|
||||
};
|
||||
} // namespace network
|
||||
|
||||
|
||||
@@ -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<uint16_t>(script.length());
|
||||
|
||||
//create a buffer for the script
|
||||
std::vector<char> sbuffer;
|
||||
|
||||
//fill the script buffer
|
||||
sm.serialize(sbuffer);
|
||||
|
||||
//get the size of the keyframebuffer
|
||||
uint16_t msglen = static_cast<uint16_t>(sbuffer.size());
|
||||
|
||||
//the type of message
|
||||
uint16_t type = static_cast<uint16_t>(network::datamessagestructures::ScriptData);
|
||||
|
||||
//create the full buffer
|
||||
std::vector<char> buffer;
|
||||
buffer.reserve(headerSize() + sizeof(type) + sizeof(msglen) + msglen);
|
||||
|
||||
//write header
|
||||
writeHeader(buffer, MessageTypes::Data);
|
||||
|
||||
//type of message
|
||||
buffer.insert(buffer.end(), reinterpret_cast<char*>(&type), reinterpret_cast<char*>(&type) + sizeof(type));
|
||||
|
||||
//size of message
|
||||
buffer.insert(buffer.end(), reinterpret_cast<char*>(&msglen), reinterpret_cast<char*>(&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
|
||||
|
||||
Reference in New Issue
Block a user