diff --git a/modules/server/servermodule.cpp b/modules/server/servermodule.cpp index 3d02d87cc8..86fa11a7f2 100644 --- a/modules/server/servermodule.cpp +++ b/modules/server/servermodule.cpp @@ -113,10 +113,7 @@ void ServerModule::internalInitialize(const ghoul::Dictionary& configuration) { std::unique_ptr serverInterface = ServerInterface::createFromDictionary(interfaceDictionary); - - if (global::windowDelegate->isMaster()) { - serverInterface->initialize(); - } + serverInterface->initialize(); _interfaceOwner.addPropertySubOwner(serverInterface.get()); @@ -132,10 +129,6 @@ void ServerModule::internalInitialize(const ghoul::Dictionary& configuration) { } void ServerModule::preSync() { - if (!global::windowDelegate->isMaster()) { - return; - } - // Set up new connections. for (std::unique_ptr& serverInterface : _interfaces) { if (!serverInterface->isEnabled()) { @@ -204,9 +197,7 @@ void ServerModule::disconnectAll() { ZoneScoped for (std::unique_ptr& serverInterface : _interfaces) { - if (global::windowDelegate->isMaster()) { - serverInterface->deinitialize(); - } + serverInterface->deinitialize(); } for (ConnectionData& connectionData : _connections) { diff --git a/modules/skybrowser/skybrowsermodule_lua.inl b/modules/skybrowser/skybrowsermodule_lua.inl index 745373431c..5387c3a146 100644 --- a/modules/skybrowser/skybrowsermodule_lua.inl +++ b/modules/skybrowser/skybrowsermodule_lua.inl @@ -35,10 +35,34 @@ #include #include #include +#include namespace { - constexpr std::string_view _loggerCat = "SkyBrowserModule"; +constexpr std::string_view _loggerCat = "SkyBrowserModule"; +bool browserBelongsToCurrentNode(std::string identifier) { + size_t found = identifier.find('_'); + std::string errorMessage = "The Sky Browser encountered a problem when it tried to " + "initialize the browser"; + if (found == std::string::npos) { + throw ghoul::RuntimeError(errorMessage); + } + else { + std::string res = identifier.substr(found + 1, identifier.size()); + if (res.empty()) { + throw ghoul::RuntimeError(errorMessage); + } + // Convert the last char to an int + int nodeId = std::stoi(res); + return nodeId == openspace::global::windowDelegate->currentNode(); + } +} + +std::string prunedIdentifier(std::string identifier) { + // Removes the node number at the end of the identifier + std::string res = identifier.substr(0, identifier.find('_')); + return res; +} /** * Reloads the sky browser display copy for the node index that is sent in. @@ -186,13 +210,17 @@ namespace { [[codegen::luawrap]] void loadImagesToWWT(std::string identifier) { using namespace openspace; + if (!browserBelongsToCurrentNode(identifier)) { + return; + } + std::string prunedId = prunedIdentifier(identifier); // Load images from url - LINFO("Connection established to WorldWide Telescope application in " + identifier); - LINFO("Loading image collections to " + identifier); + LINFO("Connection established to WorldWide Telescope application in " + prunedId); + LINFO("Loading image collections to " + prunedId); // Load the collections here because we know that the browser can execute javascript SkyBrowserModule* module = global::moduleEngine->module(); - TargetBrowserPair* pair = module->pair(identifier); + TargetBrowserPair* pair = module->pair(prunedId); if (pair) { pair->hideChromeInterface(); pair->browser()->loadImageCollection(module->wwtImageCollectionUrl()); @@ -224,12 +252,11 @@ namespace { ); } } - // To ensure each node in a cluster calls its own instance of the wwt application // Do not send this script to the other nodes global::scriptEngine->queueScript( "openspace.skybrowser.sendOutIdsToBrowsers()", - scripting::ScriptEngine::RemoteScripting::No + scripting::ScriptEngine::RemoteScripting::Yes ); } @@ -258,9 +285,14 @@ namespace { using namespace openspace; // Initialize browser with ID and its corresponding target - LINFO("Initializing sky browser " + identifier); + if (!browserBelongsToCurrentNode(identifier)) { + return; + } + + std::string prunedId = prunedIdentifier(identifier); + LINFO("Initializing sky browser " + prunedId); SkyBrowserModule* module = global::moduleEngine->module(); - TargetBrowserPair* pair = module->pair(identifier); + TargetBrowserPair* pair = module->pair(prunedId); if (pair) { pair->initialize(); } @@ -479,7 +511,7 @@ namespace { glm::vec3 positionTarget = glm::vec3(0.9f, 0.4f, -2.1f); glm::dvec3 galacticTarget = skybrowser::localCameraToGalactic(positionTarget); if (glm::any(glm::isnan(galacticTarget))) { - galacticTarget = glm::dvec3 (0.0, 0.0, skybrowser::CelestialSphereRadius); + galacticTarget = glm::dvec3(0.0, 0.0, skybrowser::CelestialSphereRadius); } std::string guiPath = "/Sky Browser"; std::string url = "http://wwt.openspaceproject.com/1/openspace/"; @@ -777,10 +809,15 @@ namespace { [[codegen::luawrap]] void loadingImageCollectionComplete(std::string identifier) { using namespace openspace; + if (!browserBelongsToCurrentNode(identifier)) { + return; + } + std::string prunedId = prunedIdentifier(identifier); + SkyBrowserModule* module = global::moduleEngine->module(); - TargetBrowserPair* pair = module->pair(identifier); + TargetBrowserPair* pair = module->pair(prunedId); if (pair) { - LINFO("Image collection is loaded in Screen Space Sky Browser " + identifier); + LINFO("Image collection is loaded in Screen Space Sky Browser " + prunedId); pair->setImageCollectionIsLoaded(true); // Add all selected images to WorldWide Telescope const std::vector& images = pair->selectedImages(); diff --git a/modules/skybrowser/src/screenspaceskybrowser.cpp b/modules/skybrowser/src/screenspaceskybrowser.cpp index d657ce49c5..85cf3c6eab 100644 --- a/modules/skybrowser/src/screenspaceskybrowser.cpp +++ b/modules/skybrowser/src/screenspaceskybrowser.cpp @@ -195,7 +195,8 @@ bool ScreenSpaceSkyBrowser::isPointingSpacecraft() const { } void ScreenSpaceSkyBrowser::setIdInBrowser() const { - WwtCommunicator::setIdInBrowser(identifier()); + int currentNode = global::windowDelegate->currentNode(); + WwtCommunicator::setIdInBrowser(fmt::format("{}_{}", identifier(), currentNode)); } void ScreenSpaceSkyBrowser::setIsInitialized(bool isInitialized) { diff --git a/src/scripting/scriptengine.cpp b/src/scripting/scriptengine.cpp index 03fae5f5ab..06a0d99b48 100644 --- a/src/scripting/scriptengine.cpp +++ b/src/scripting/scriptengine.cpp @@ -576,26 +576,31 @@ void ScriptEngine::writeLog(const std::string& script) { void ScriptEngine::preSync(bool isMaster) { ZoneScoped - if (!isMaster) { - return; - } - std::lock_guard guard(_clientScriptsMutex); - while (!_incomingScripts.empty()) { - QueueItem item = std::move(_incomingScripts.front()); - _incomingScripts.pop(); + if (isMaster) { + while (!_incomingScripts.empty()) { + QueueItem item = std::move(_incomingScripts.front()); + _incomingScripts.pop(); - _scriptsToSync.push_back(item.script); - const bool remoteScripting = item.remoteScripting; + _scriptsToSync.push_back(item.script); + const bool remoteScripting = item.remoteScripting; - // Not really a received script but the master also needs to run the script... - _masterScriptQueue.push(item); + // Not really a received script but the master also needs to run the script... + _masterScriptQueue.push(item); - if (global::parallelPeer->isHost() && remoteScripting) { - global::parallelPeer->sendScript(item.script); + if (global::parallelPeer->isHost() && remoteScripting) { + global::parallelPeer->sendScript(item.script); + } + if (global::sessionRecording->isRecording()) { + global::sessionRecording->saveScriptKeyframeToTimeline(item.script); + } } - if (global::sessionRecording->isRecording()) { - global::sessionRecording->saveScriptKeyframeToTimeline(item.script); + } + else { + while (!_incomingScripts.empty()) { + QueueItem item = std::move(_incomingScripts.front()); + _incomingScripts.pop(); + _clientScriptQueue.push(item.script); } } }