diff --git a/include/openspace/interaction/actionmanager.h b/include/openspace/interaction/actionmanager.h index 9054b3fc09..610bdbf1e9 100644 --- a/include/openspace/interaction/actionmanager.h +++ b/include/openspace/interaction/actionmanager.h @@ -35,14 +35,16 @@ namespace openspace::interaction { class ActionManager { public: + BooleanType(ShouldBeSynchronized); + bool hasAction(const std::string& identifier) const; void registerAction(Action action); void removeAction(const std::string& identifier); const Action& action(const std::string& identifier) const; std::vector actions() const; - void triggerAction(const std::string& identifier, - const ghoul::Dictionary& arguments) const; + void triggerAction(const std::string& identifier, const ghoul::Dictionary& arguments, + ShouldBeSynchronized shouldBeSynchronized) const; static scripting::LuaLibrary luaLibrary(); private: diff --git a/include/openspace/rendering/luaconsole.h b/include/openspace/rendering/luaconsole.h index f7a828fb97..cd875a2b4a 100644 --- a/include/openspace/rendering/luaconsole.h +++ b/include/openspace/rendering/luaconsole.h @@ -66,7 +66,8 @@ private: void addToCommand(std::string c); properties::BoolProperty _isVisible; - properties::BoolProperty _remoteScripting; + properties::BoolProperty _shouldBeSynchronized; + properties::BoolProperty _shouldSendToRemote; properties::Vec4Property _backgroundColor; properties::Vec4Property _entryTextColor; diff --git a/include/openspace/scripting/scriptengine.h b/include/openspace/scripting/scriptengine.h index 8221fee70a..65e6703fe9 100644 --- a/include/openspace/scripting/scriptengine.h +++ b/include/openspace/scripting/scriptengine.h @@ -51,11 +51,13 @@ namespace openspace::scripting { class ScriptEngine : public Syncable { public: using ScriptCallback = std::function; - BooleanType(RemoteScripting); + BooleanType(ShouldBeSynchronized); + BooleanType(ShouldSendToRemote); struct QueueItem { std::string script; - RemoteScripting remoteScripting; + ShouldBeSynchronized shouldBeSynchronized; + ShouldSendToRemote shouldSendToRemote; ScriptCallback callback; }; @@ -89,8 +91,8 @@ public: virtual void decode(SyncBuffer* syncBuffer) override; virtual void postSync(bool isMaster) override; - void queueScript(std::string script, RemoteScripting remoteScripting, - ScriptCallback cb = ScriptCallback()); + void queueScript(std::string script, ShouldBeSynchronized shouldBeSynchronized, + ShouldSendToRemote shouldSendToRemote, ScriptCallback cb = ScriptCallback()); std::vector allLuaFunctions() const; diff --git a/modules/debugging/debuggingmodule_lua.inl b/modules/debugging/debuggingmodule_lua.inl index c8951ae0fb..de69a6deb5 100644 --- a/modules/debugging/debuggingmodule_lua.inl +++ b/modules/debugging/debuggingmodule_lua.inl @@ -66,7 +66,8 @@ constexpr glm::vec3 OrientationLineColor = glm::vec3(0.0, 1.0, 1.0); global::scriptEngine->queueScript( addParentScript, - scripting::ScriptEngine::RemoteScripting::Yes + scripting::ScriptEngine::ShouldBeSynchronized::Yes, + scripting::ScriptEngine::ShouldSendToRemote::Yes ); // Get the poses along the path @@ -98,7 +99,8 @@ constexpr glm::vec3 OrientationLineColor = glm::vec3(0.0, 1.0, 1.0); global::scriptEngine->queueScript( fmt::format("openspace.addSceneGraphNode({})", pointNode), - scripting::ScriptEngine::RemoteScripting::Yes + scripting::ScriptEngine::ShouldBeSynchronized::Yes, + scripting::ScriptEngine::ShouldSendToRemote::Yes ); }; @@ -120,7 +122,8 @@ constexpr glm::vec3 OrientationLineColor = glm::vec3(0.0, 1.0, 1.0); global::scriptEngine->queueScript( fmt::format("openspace.addSceneGraphNode({})", lineNode), - scripting::ScriptEngine::RemoteScripting::Yes + scripting::ScriptEngine::ShouldBeSynchronized::Yes, + scripting::ScriptEngine::ShouldSendToRemote::Yes ); }; @@ -157,7 +160,8 @@ constexpr glm::vec3 OrientationLineColor = glm::vec3(0.0, 1.0, 1.0); using namespace openspace; global::scriptEngine->queueScript( fmt::format("openspace.removeSceneGraphNode('{}');", RenderedPathIdentifier), - scripting::ScriptEngine::RemoteScripting::Yes + scripting::ScriptEngine::ShouldBeSynchronized::Yes, + scripting::ScriptEngine::ShouldSendToRemote::Yes ); } @@ -189,7 +193,8 @@ constexpr glm::vec3 OrientationLineColor = glm::vec3(0.0, 1.0, 1.0); global::scriptEngine->queueScript( addParentScript, - scripting::ScriptEngine::RemoteScripting::Yes + scripting::ScriptEngine::ShouldBeSynchronized::Yes, + scripting::ScriptEngine::ShouldSendToRemote::Yes ); const std::vector points = currentPath->controlPoints(); @@ -226,7 +231,8 @@ constexpr glm::vec3 OrientationLineColor = glm::vec3(0.0, 1.0, 1.0); global::scriptEngine->queueScript( fmt::format("openspace.addSceneGraphNode({})", node), - scripting::ScriptEngine::RemoteScripting::Yes + scripting::ScriptEngine::ShouldBeSynchronized::Yes, + scripting::ScriptEngine::ShouldSendToRemote::Yes ); } } @@ -236,7 +242,8 @@ constexpr glm::vec3 OrientationLineColor = glm::vec3(0.0, 1.0, 1.0); using namespace openspace; global::scriptEngine->queueScript( fmt::format("openspace.removeSceneGraphNode('{}');", RenderedPointsIdentifier), - scripting::ScriptEngine::RemoteScripting::Yes + scripting::ScriptEngine::ShouldBeSynchronized::Yes, + scripting::ScriptEngine::ShouldSendToRemote::Yes ); } @@ -291,7 +298,8 @@ constexpr glm::vec3 OrientationLineColor = glm::vec3(0.0, 1.0, 1.0); global::scriptEngine->queueScript( fmt::format("openspace.addSceneGraphNode({});", axes), - scripting::ScriptEngine::RemoteScripting::Yes + scripting::ScriptEngine::ShouldBeSynchronized::Yes, + scripting::ScriptEngine::ShouldSendToRemote::Yes ); } diff --git a/modules/exoplanets/exoplanetsmodule_lua.inl b/modules/exoplanets/exoplanetsmodule_lua.inl index bdd98a510a..a7aa2d4f15 100644 --- a/modules/exoplanets/exoplanetsmodule_lua.inl +++ b/modules/exoplanets/exoplanetsmodule_lua.inl @@ -211,9 +211,12 @@ void createExoplanetSystem(const std::string& starName, "}" "}"; + // No sync or send because this is already inside a Lua script, therefor it has + // already been synced and sent to the connected nodes and peers global::scriptEngine->queueScript( "openspace.addSceneGraphNode(" + starParent + ");", - scripting::ScriptEngine::RemoteScripting::Yes + scripting::ScriptEngine::ShouldBeSynchronized::No, + scripting::ScriptEngine::ShouldSendToRemote::No ); // Planets @@ -327,10 +330,13 @@ void createExoplanetSystem(const std::string& starName, "}" "}"; + // No sync or send because this is already inside a Lua script, therefor it has + // already been synced and sent to the connected nodes and peers global::scriptEngine->queueScript( "openspace.addSceneGraphNode(" + planetTrailNode + ");" "openspace.addSceneGraphNode(" + planetNode + ");", - scripting::ScriptEngine::RemoteScripting::Yes + scripting::ScriptEngine::ShouldBeSynchronized::No, + scripting::ScriptEngine::ShouldSendToRemote::No ); bool hasUpperAUncertainty = !std::isnan(planet.aUpper); @@ -377,9 +383,12 @@ void createExoplanetSystem(const std::string& starName, "}" "}"; + // No sync or send because this is already inside a Lua script, therefor it + // has already been synced and sent to the connected nodes and peers global::scriptEngine->queueScript( "openspace.addSceneGraphNode(" + discNode + ");", - scripting::ScriptEngine::RemoteScripting::Yes + scripting::ScriptEngine::ShouldBeSynchronized::No, + scripting::ScriptEngine::ShouldSendToRemote::No ); } } @@ -422,9 +431,12 @@ void createExoplanetSystem(const std::string& starName, "}" "}"; + // No sync or send because this is already inside a Lua script, therefor it has + // already been synced and sent to the connected nodes and peers global::scriptEngine->queueScript( "openspace.addSceneGraphNode(" + circle + ");", - scripting::ScriptEngine::RemoteScripting::Yes + scripting::ScriptEngine::ShouldBeSynchronized::No, + scripting::ScriptEngine::ShouldSendToRemote::No ); // Habitable Zone @@ -477,9 +489,12 @@ void createExoplanetSystem(const std::string& starName, "}" "}"; + // No sync or send because this is already inside a Lua script, therefor it has + // already been synced and sent to the connected nodes and peers global::scriptEngine->queueScript( "openspace.addSceneGraphNode(" + zoneDiscNode + ");", - scripting::ScriptEngine::RemoteScripting::Yes + scripting::ScriptEngine::ShouldBeSynchronized::No, + scripting::ScriptEngine::ShouldSendToRemote::No ); // Star glare @@ -518,9 +533,12 @@ void createExoplanetSystem(const std::string& starName, "}" "}"; + // No sync or send because this is already inside a Lua script, therefor it + // has already been synced and sent to the connected nodes and peers global::scriptEngine->queueScript( "openspace.addSceneGraphNode(" + starGlare + ");", - scripting::ScriptEngine::RemoteScripting::Yes + scripting::ScriptEngine::ShouldBeSynchronized::No, + scripting::ScriptEngine::ShouldSendToRemote::No ); } } @@ -627,9 +645,13 @@ std::vector hostStarsWithSufficientData() { using namespace openspace; using namespace exoplanets; const std::string starIdentifier = makeIdentifier(std::move(starName)); + + // No sync or send because this is already inside a Lua script, therefor it has + // already been synced and sent to the connected nodes and peers global::scriptEngine->queueScript( "openspace.removeSceneGraphNode('" + starIdentifier + "');", - scripting::ScriptEngine::RemoteScripting::Yes + scripting::ScriptEngine::ShouldBeSynchronized::No, + scripting::ScriptEngine::ShouldSendToRemote::No ); } diff --git a/modules/globebrowsing/src/geojson/geojsoncomponent.cpp b/modules/globebrowsing/src/geojson/geojsoncomponent.cpp index ca3dbf5423..1d876df11b 100644 --- a/modules/globebrowsing/src/geojson/geojsoncomponent.cpp +++ b/modules/globebrowsing/src/geojson/geojsoncomponent.cpp @@ -840,7 +840,8 @@ void GeoJsonComponent::flyToFeature(std::optional index) const { "openspace.globebrowsing.flyToGeo(\"{}\", {}, {}, {})", _globeNode.owner()->identifier(), lat, lon, d ), - scripting::ScriptEngine::RemoteScripting::Yes + scripting::ScriptEngine::ShouldBeSynchronized::Yes, + scripting::ScriptEngine::ShouldSendToRemote::Yes ); } @@ -850,7 +851,8 @@ void GeoJsonComponent::triggerDeletion() const { "openspace.globebrowsing.deleteGeoJson(\"{}\", \"{}\")", _globeNode.owner()->identifier(), _identifier ), - scripting::ScriptEngine::RemoteScripting::Yes + scripting::ScriptEngine::ShouldBeSynchronized::Yes, + scripting::ScriptEngine::ShouldSendToRemote::Yes ); } diff --git a/modules/imgui/src/guiactioncomponent.cpp b/modules/imgui/src/guiactioncomponent.cpp index a9bb377201..1c7ea37b7c 100644 --- a/modules/imgui/src/guiactioncomponent.cpp +++ b/modules/imgui/src/guiactioncomponent.cpp @@ -55,7 +55,11 @@ void GuiActionComponent::render() { for (const std::pair& p : binds) { boundActions.insert(p.second); if (ImGui::Button(ghoul::to_string(p.first).c_str())) { - global::actionManager->triggerAction(p.second, ghoul::Dictionary()); + global::actionManager->triggerAction( + p.second, + ghoul::Dictionary(), + interaction::ActionManager::ShouldBeSynchronized::Yes + ); } ImGui::SameLine(); @@ -78,7 +82,11 @@ void GuiActionComponent::render() { } if (ImGui::Button(action.identifier.c_str())) { - global::actionManager->triggerAction(action.command, ghoul::Dictionary()); + global::actionManager->triggerAction( + action.command, + ghoul::Dictionary(), + interaction::ActionManager::ShouldBeSynchronized::Yes + ); } ImGui::SameLine(); diff --git a/modules/imgui/src/guigibscomponent.cpp b/modules/imgui/src/guigibscomponent.cpp index e544e01241..a9c2c71a1c 100644 --- a/modules/imgui/src/guigibscomponent.cpp +++ b/modules/imgui/src/guigibscomponent.cpp @@ -147,7 +147,8 @@ void GuiGIBSComponent::render() { ); global::scriptEngine->queueScript( script, - scripting::ScriptEngine::RemoteScripting::Yes + scripting::ScriptEngine::ShouldBeSynchronized::Yes, + scripting::ScriptEngine::ShouldSendToRemote::Yes ); } diff --git a/modules/imgui/src/guiglobebrowsingcomponent.cpp b/modules/imgui/src/guiglobebrowsingcomponent.cpp index 3e3848a830..af6c52d820 100644 --- a/modules/imgui/src/guiglobebrowsingcomponent.cpp +++ b/modules/imgui/src/guiglobebrowsingcomponent.cpp @@ -344,7 +344,8 @@ void GuiGlobeBrowsingComponent::render() { l.name, l.url ), - scripting::ScriptEngine::RemoteScripting::Yes + scripting::ScriptEngine::ShouldBeSynchronized::Yes, + scripting::ScriptEngine::ShouldSendToRemote::Yes ); }; diff --git a/modules/imgui/src/guispacetimecomponent.cpp b/modules/imgui/src/guispacetimecomponent.cpp index 7c00f3d155..0a7bf9dbc7 100644 --- a/modules/imgui/src/guispacetimecomponent.cpp +++ b/modules/imgui/src/guispacetimecomponent.cpp @@ -109,12 +109,14 @@ void GuiSpaceTimeComponent::render() { "openspace.setPropertyValue('" + std::string(AnchorProperty) + "', '" + n->identifier() + "');", - scripting::ScriptEngine::RemoteScripting::Yes + scripting::ScriptEngine::ShouldBeSynchronized::Yes, + scripting::ScriptEngine::ShouldSendToRemote::Yes ); global::scriptEngine->queueScript( "openspace.setPropertyValue('" + std::string(RetargetAnchorProperty) + "', nil);", - scripting::ScriptEngine::RemoteScripting::Yes + scripting::ScriptEngine::ShouldBeSynchronized::Yes, + scripting::ScriptEngine::ShouldSendToRemote::Yes ); } } @@ -144,12 +146,14 @@ void GuiSpaceTimeComponent::render() { global::scriptEngine->queueScript( "openspace.setPropertyValue('" + std::string(AnchorProperty) + "', '" + nodes[currentPosition]->identifier() + "');", - scripting::ScriptEngine::RemoteScripting::Yes + scripting::ScriptEngine::ShouldBeSynchronized::Yes, + scripting::ScriptEngine::ShouldSendToRemote::Yes ); global::scriptEngine->queueScript( "openspace.setPropertyValue('" + std::string(RetargetAnchorProperty) + "', nil);", - scripting::ScriptEngine::RemoteScripting::Yes + scripting::ScriptEngine::ShouldBeSynchronized::Yes, + scripting::ScriptEngine::ShouldSendToRemote::Yes ); } @@ -159,7 +163,8 @@ void GuiSpaceTimeComponent::render() { global::scriptEngine->queueScript( "openspace.setPropertyValue('" + std::string(RetargetAnchorProperty) + "', nil);", - scripting::ScriptEngine::RemoteScripting::Yes + scripting::ScriptEngine::ShouldBeSynchronized::Yes, + scripting::ScriptEngine::ShouldSendToRemote::Yes ); } @@ -195,9 +200,13 @@ void GuiSpaceTimeComponent::render() { for (size_t i = 0; i < interestingTimes.size(); ++i) { const Scene::InterestingTime& t = interestingTimes[i]; if (ImGui::Button(t.name.c_str())) { + + // No sync or send because time settings are always synced and sent + // to the connected nodes and peers global::scriptEngine->queueScript( "openspace.time.setTime(\"" + t.time + "\")", - scripting::ScriptEngine::RemoteScripting::No + scripting::ScriptEngine::ShouldBeSynchronized::No, + scripting::ScriptEngine::ShouldSendToRemote::No ); } @@ -223,9 +232,12 @@ void GuiSpaceTimeComponent::render() { ImGuiInputTextFlags_EnterReturnsTrue ); if (dateChanged) { + // No sync or send because time settings are always synced and sent to the + // connected nodes and peers global::scriptEngine->queueScript( "openspace.time.setTime(\"" + std::string(Buffer) + "\")", - scripting::ScriptEngine::RemoteScripting::No + scripting::ScriptEngine::ShouldBeSynchronized::No, + scripting::ScriptEngine::ShouldSendToRemote::No ); } @@ -255,17 +267,23 @@ void GuiSpaceTimeComponent::render() { j2000 + seconds; if (shift) { - // If any shift key is pressed we want to always jump to the time + // If any shift key is pressed we want to always jump to the time. + // No sync or send because time settings are always synced and sent + // to the connected nodes and peers global::scriptEngine->queueScript( "openspace.time.setTime(" + std::to_string(newTime) + ")", - scripting::ScriptEngine::RemoteScripting::No + scripting::ScriptEngine::ShouldBeSynchronized::No, + scripting::ScriptEngine::ShouldSendToRemote::No ); } else { + // No sync or send because time settings are always synced and sent + // to the connected nodes and peers global::scriptEngine->queueScript( "openspace.time.interpolateTime(" + std::to_string(newTime) + ", " + std::to_string(duration) + ")", - scripting::ScriptEngine::RemoteScripting::No + scripting::ScriptEngine::ShouldBeSynchronized::No, + scripting::ScriptEngine::ShouldSendToRemote::No ); } }; @@ -302,9 +320,12 @@ void GuiSpaceTimeComponent::render() { // setTime doesn't like the T in it and wants a space instead nowTime[11] = ' '; + // No sync or send because time settings are always synced and sent + // to the connected nodes and peers global::scriptEngine->queueScript( "openspace.time.setTime(\"" + nowTime + "\")", - scripting::ScriptEngine::RemoteScripting::No + scripting::ScriptEngine::ShouldBeSynchronized::No, + scripting::ScriptEngine::ShouldSendToRemote::No ); } @@ -382,9 +403,13 @@ void GuiSpaceTimeComponent::render() { // If the value changed, we want to change the delta time to the new value double newDt = convertTime(_deltaTime, _deltaTimeUnit, TimeUnit::Second); + + // No sync or send because time settings are always synced and sent + // to the connected nodes and peers global::scriptEngine->queueScript( "openspace.time.interpolateDeltaTime(" + std::to_string(newDt) + ")", - scripting::ScriptEngine::RemoteScripting::No + scripting::ScriptEngine::ShouldBeSynchronized::No, + scripting::ScriptEngine::ShouldSendToRemote::No ); } if (unitChanged) { @@ -430,16 +455,22 @@ void GuiSpaceTimeComponent::render() { TimeUnit::Second ); + // No sync or send because time settings are always synced and sent + // to the connected nodes and peers global::scriptEngine->queueScript( "openspace.time.setDeltaTime(" + std::to_string(newDeltaTime) + ")", - scripting::ScriptEngine::RemoteScripting::No + scripting::ScriptEngine::ShouldBeSynchronized::No, + scripting::ScriptEngine::ShouldSendToRemote::No ); } if (!ImGui::IsItemActive() && !ImGui::IsItemClicked()) { if (_slidingDelta != 0.f) { + // No sync or send because time settings are always synced and sent + // to the connected nodes and peers global::scriptEngine->queueScript( "openspace.time.setDeltaTime(" + std::to_string(_oldDeltaTime) + ")", - scripting::ScriptEngine::RemoteScripting::No + scripting::ScriptEngine::ShouldBeSynchronized::No, + scripting::ScriptEngine::ShouldSendToRemote::No ); } @@ -464,9 +495,12 @@ void GuiSpaceTimeComponent::render() { TimeUnit::Second ); + // No sync or send because time settings are always synced and sent + // to the connected nodes and peers global::scriptEngine->queueScript( "openspace.time.setDeltaTime(" + std::to_string(newDeltaTime) + ")", - scripting::ScriptEngine::RemoteScripting::No + scripting::ScriptEngine::ShouldBeSynchronized::No, + scripting::ScriptEngine::ShouldSendToRemote::No ); } else { @@ -484,7 +518,8 @@ void GuiSpaceTimeComponent::render() { if (pauseChanged) { global::scriptEngine->queueScript( "openspace.time.interpolateTogglePause()", - scripting::ScriptEngine::RemoteScripting::No + scripting::ScriptEngine::ShouldBeSynchronized::Yes, + scripting::ScriptEngine::ShouldSendToRemote::Yes ); } ImGui::SameLine(); @@ -493,53 +528,71 @@ void GuiSpaceTimeComponent::render() { { ImGui::GetWindowWidth() / 2 - 7.5f, 0.f } ); if (invert) { + // No sync or send because time settings are always synced and sent + // to the connected nodes and peers global::scriptEngine->queueScript( "openspace.time.interpolateDeltaTime(-1 * openspace.time.deltaTime());", - scripting::ScriptEngine::RemoteScripting::No + scripting::ScriptEngine::ShouldBeSynchronized::No, + scripting::ScriptEngine::ShouldSendToRemote::No ); } const bool minusDs = ImGui::Button("-1d/s"); if (minusDs) { + // No sync or send because time settings are always synced and sent + // to the connected nodes and peers global::scriptEngine->queueScript( "openspace.time.interpolateDeltaTime(" + std::to_string(-24 * 60 * 60) + ")", - scripting::ScriptEngine::RemoteScripting::No + scripting::ScriptEngine::ShouldBeSynchronized::No, + scripting::ScriptEngine::ShouldSendToRemote::No ); } ImGui::SameLine(); const bool minusHs = ImGui::Button("-1h/s"); if (minusHs) { + // No sync or send because time settings are always synced and sent + // to the connected nodes and peers global::scriptEngine->queueScript( "openspace.time.interpolateDeltaTime(" + std::to_string(-60 * 60) + ")", - scripting::ScriptEngine::RemoteScripting::No + scripting::ScriptEngine::ShouldBeSynchronized::No, + scripting::ScriptEngine::ShouldSendToRemote::No ); } ImGui::SameLine(); const bool minusMs = ImGui::Button("-1min/s"); if (minusMs) { + // No sync or send because time settings are always synced and sent + // to the connected nodes and peers global::scriptEngine->queueScript( "openspace.time.interpolateDeltaTime(" + std::to_string(-60) + ")", - scripting::ScriptEngine::RemoteScripting::No + scripting::ScriptEngine::ShouldBeSynchronized::No, + scripting::ScriptEngine::ShouldSendToRemote::No ); } ImGui::SameLine(); const bool minusSs = ImGui::Button("-1s/s"); if (minusSs) { + // No sync or send because time settings are always synced and sent + // to the connected nodes and peers global::scriptEngine->queueScript( "openspace.time.interpolateDeltaTime(" + std::to_string(-1) + ")", - scripting::ScriptEngine::RemoteScripting::No + scripting::ScriptEngine::ShouldBeSynchronized::No, + scripting::ScriptEngine::ShouldSendToRemote::No ); } ImGui::SameLine(); const bool zero = ImGui::Button("0"); if (zero) { + // No sync or send because time settings are always synced and sent + // to the connected nodes and peers global::scriptEngine->queueScript( "openspace.time.interpolateDeltaTime(" + std::to_string(0) + ")", - scripting::ScriptEngine::RemoteScripting::No + scripting::ScriptEngine::ShouldBeSynchronized::No, + scripting::ScriptEngine::ShouldSendToRemote::No ); } ImGui::SameLine(); @@ -547,36 +600,48 @@ void GuiSpaceTimeComponent::render() { const bool plusSs = ImGui::Button("+1s/s"); if (plusSs) { + // No sync or send because time settings are always synced and sent + // to the connected nodes and peers global::scriptEngine->queueScript( "openspace.time.interpolateDeltaTime(" + std::to_string(1) + ")", - scripting::ScriptEngine::RemoteScripting::No + scripting::ScriptEngine::ShouldBeSynchronized::No, + scripting::ScriptEngine::ShouldSendToRemote::No ); } ImGui::SameLine(); const bool plusMs = ImGui::Button("1min/s"); if (plusMs) { + // No sync or send because time settings are always synced and sent + // to the connected nodes and peers global::scriptEngine->queueScript( "openspace.time.interpolateDeltaTime(" + std::to_string(60) + ")", - scripting::ScriptEngine::RemoteScripting::No + scripting::ScriptEngine::ShouldBeSynchronized::No, + scripting::ScriptEngine::ShouldSendToRemote::No ); } ImGui::SameLine(); const bool plusHs = ImGui::Button("1h/s"); if (plusHs) { + // No sync or send because time settings are always synced and sent + // to the connected nodes and peers global::scriptEngine->queueScript( "openspace.time.interpolateDeltaTime(" + std::to_string(60 * 60) + ")", - scripting::ScriptEngine::RemoteScripting::No + scripting::ScriptEngine::ShouldBeSynchronized::No, + scripting::ScriptEngine::ShouldSendToRemote::No ); } ImGui::SameLine(); const bool plusDs = ImGui::Button("1d/s"); if (plusDs) { + // No sync or send because time settings are always synced and sent + // to the connected nodes and peers global::scriptEngine->queueScript( "openspace.time.interpolateDeltaTime(" + std::to_string(24 * 60 * 60) + ")", - scripting::ScriptEngine::RemoteScripting::No + scripting::ScriptEngine::ShouldBeSynchronized::No, + scripting::ScriptEngine::ShouldSendToRemote::No ); } diff --git a/modules/imgui/src/renderproperties.cpp b/modules/imgui/src/renderproperties.cpp index 2fa228cf55..6e49500b36 100644 --- a/modules/imgui/src/renderproperties.cpp +++ b/modules/imgui/src/renderproperties.cpp @@ -74,7 +74,8 @@ void renderTooltip(Property* prop, double delay) { void executeSetPropertyScript(const std::string& id, const std::string& value) { global::scriptEngine->queueScript( fmt::format("openspace.setPropertyValueSingle('{}', {});", id, value), - scripting::ScriptEngine::RemoteScripting::Yes + scripting::ScriptEngine::ShouldBeSynchronized::Yes, + scripting::ScriptEngine::ShouldSendToRemote::Yes ); } diff --git a/modules/iswa/rendering/iswacygnet.cpp b/modules/iswa/rendering/iswacygnet.cpp index b8e0f12120..48b935cf20 100644 --- a/modules/iswa/rendering/iswacygnet.cpp +++ b/modules/iswa/rendering/iswacygnet.cpp @@ -139,7 +139,8 @@ void IswaCygnet::initializeGL() { deinitialize(); global::scriptEngine->queueScript( "openspace.removeSceneGraphNode('" + identifier() + "')", - scripting::ScriptEngine::RemoteScripting::Yes + scripting::ScriptEngine::ShouldBeSynchronized::Yes, + scripting::ScriptEngine::ShouldSendToRemote::Yes ); }); } @@ -306,7 +307,8 @@ void IswaCygnet::initializeGroup() { LDEBUG(identifier() + " Event clearGroup"); global::scriptEngine->queueScript( "openspace.removeSceneGraphNode('" + identifier() + "')", - scripting::ScriptEngine::RemoteScripting::Yes + scripting::ScriptEngine::ShouldBeSynchronized::Yes, + scripting::ScriptEngine::ShouldSendToRemote::Yes ); } ); diff --git a/modules/iswa/rendering/iswakameleongroup.cpp b/modules/iswa/rendering/iswakameleongroup.cpp index 5eb84733fb..3840f5f74b 100644 --- a/modules/iswa/rendering/iswakameleongroup.cpp +++ b/modules/iswa/rendering/iswakameleongroup.cpp @@ -153,7 +153,8 @@ void IswaKameleonGroup::updateFieldlineSeeds() { global::scriptEngine->queueScript( "openspace.removeSceneGraphNode('" + std::get<0>(seedPath.second) + "')", - scripting::ScriptEngine::RemoteScripting::Yes + scripting::ScriptEngine::ShouldBeSynchronized::Yes, + scripting::ScriptEngine::ShouldSendToRemote::Yes ); std::get<2>(seedPath.second) = false; // if this option was turned on @@ -180,7 +181,8 @@ void IswaKameleonGroup::clearFieldlines() { global::scriptEngine->queueScript( "openspace.removeSceneGraphNode('" + std::get<0>(seedPath.second) + "')", - scripting::ScriptEngine::RemoteScripting::Yes + scripting::ScriptEngine::ShouldBeSynchronized::Yes, + scripting::ScriptEngine::ShouldSendToRemote::Yes ); std::get<2>(seedPath.second) = false; } diff --git a/modules/iswa/rendering/kameleonplane.cpp b/modules/iswa/rendering/kameleonplane.cpp index 51cbf6286f..5ca5a57c78 100644 --- a/modules/iswa/rendering/kameleonplane.cpp +++ b/modules/iswa/rendering/kameleonplane.cpp @@ -292,7 +292,8 @@ void KameleonPlane::updateFieldlineSeeds() { LDEBUG("Removed fieldlines: " + std::get<0>(seedPath.second)); global::scriptEngine->queueScript( "openspace.removeSceneGraphNode('" + std::get<0>(seedPath.second) + "')", - scripting::ScriptEngine::RemoteScripting::Yes + scripting::ScriptEngine::ShouldBeSynchronized::Yes, + scripting::ScriptEngine::ShouldSendToRemote::Yes ); std::get<2>(seedPath.second) = false; // if this option was turned on diff --git a/modules/iswa/rendering/screenspacecygnet.cpp b/modules/iswa/rendering/screenspacecygnet.cpp index e0b7dcf613..ae31fc066e 100644 --- a/modules/iswa/rendering/screenspacecygnet.cpp +++ b/modules/iswa/rendering/screenspacecygnet.cpp @@ -55,7 +55,8 @@ ScreenSpaceCygnet::ScreenSpaceCygnet(const ghoul::Dictionary& dictionary) _delete.onChange([this]() { global::scriptEngine->queueScript( "openspace.iswa.removeScreenSpaceCygnet("+std::to_string(_cygnetId)+");", - scripting::ScriptEngine::RemoteScripting::Yes + scripting::ScriptEngine::ShouldBeSynchronized::Yes, + scripting::ScriptEngine::ShouldSendToRemote::Yes ); }); } diff --git a/modules/iswa/util/iswamanager.cpp b/modules/iswa/util/iswamanager.cpp index d0532ac2f5..09489ed78d 100644 --- a/modules/iswa/util/iswamanager.cpp +++ b/modules/iswa/util/iswamanager.cpp @@ -87,7 +87,8 @@ namespace { std::string idStr = std::to_string(id); openspace::global::scriptEngine->queueScript( "openspace.iswa.addScreenSpaceCygnet({CygnetId =" + idStr + "});", - openspace::scripting::ScriptEngine::RemoteScripting::Yes + openspace::scripting::ScriptEngine::ShouldBeSynchronized::Yes, + openspace::scripting::ScriptEngine::ShouldSendToRemote::Yes ); } } // namespace @@ -546,7 +547,8 @@ void IswaManager::createPlane(MetadataFuture& data) { std::string script = "openspace.addSceneGraphNode(" + luaTable + ");"; global::scriptEngine->queueScript( script, - scripting::ScriptEngine::RemoteScripting::Yes + scripting::ScriptEngine::ShouldBeSynchronized::Yes, + scripting::ScriptEngine::ShouldSendToRemote::Yes ); } } @@ -579,7 +581,8 @@ void IswaManager::createSphere(MetadataFuture& data) { std::string script = "openspace.addSceneGraphNode(" + luaTable + ");"; global::scriptEngine->queueScript( script, - scripting::ScriptEngine::RemoteScripting::Yes + scripting::ScriptEngine::ShouldBeSynchronized::Yes, + scripting::ScriptEngine::ShouldSendToRemote::Yes ); } } @@ -612,7 +615,8 @@ void IswaManager::createKameleonPlane(CdfInfo info, std::string cut) { std::string script = "openspace.addSceneGraphNode(" + luaTable + ");"; global::scriptEngine->queueScript( script, - scripting::ScriptEngine::RemoteScripting::Yes + scripting::ScriptEngine::ShouldBeSynchronized::Yes, + scripting::ScriptEngine::ShouldSendToRemote::Yes ); } } @@ -653,7 +657,8 @@ void IswaManager::createFieldline(std::string name, std::string cdfPath, std::string script = "openspace.addSceneGraphNode(" + luaTable + ");"; global::scriptEngine->queueScript( script, - scripting::ScriptEngine::RemoteScripting::Yes + scripting::ScriptEngine::ShouldBeSynchronized::Yes, + scripting::ScriptEngine::ShouldSendToRemote::Yes ); } } diff --git a/modules/iswa/util/iswamanager_lua.inl b/modules/iswa/util/iswamanager_lua.inl index ddb7e3a20b..ab7d16a935 100644 --- a/modules/iswa/util/iswamanager_lua.inl +++ b/modules/iswa/util/iswamanager_lua.inl @@ -71,7 +71,8 @@ namespace { using namespace openspace; global::scriptEngine->queueScript( "openspace.removeSceneGraphNode('" + name + "')", - scripting::ScriptEngine::RemoteScripting::Yes + scripting::ScriptEngine::ShouldBeSynchronized::Yes, + scripting::ScriptEngine::ShouldSendToRemote::Yes ); } @@ -96,7 +97,8 @@ namespace { global::scriptEngine->queueScript( script, - scripting::ScriptEngine::RemoteScripting::Yes + scripting::ScriptEngine::ShouldBeSynchronized::Yes, + scripting::ScriptEngine::ShouldSendToRemote::Yes ); } diff --git a/modules/server/include/topics/luascripttopic.h b/modules/server/include/topics/luascripttopic.h index 3a8db5f313..b0ed050eeb 100644 --- a/modules/server/include/topics/luascripttopic.h +++ b/modules/server/include/topics/luascripttopic.h @@ -35,7 +35,7 @@ public: bool isDone() const override; private: - void runScript(std::string script, bool returnValue); + void runScript(std::string script, bool returnValue, bool shouldBeSynchronized); bool _waitingForReturnValue = true; }; diff --git a/modules/server/src/topics/flightcontrollertopic.cpp b/modules/server/src/topics/flightcontrollertopic.cpp index 65c9a42922..ec1b172e0e 100644 --- a/modules/server/src/topics/flightcontrollertopic.cpp +++ b/modules/server/src/topics/flightcontrollertopic.cpp @@ -467,7 +467,8 @@ void FlightControllerTopic::processLua(const nlohmann::json &json) { const std::string script = json[LuaScript]; global::scriptEngine->queueScript( script, - openspace::scripting::ScriptEngine::RemoteScripting::Yes + scripting::ScriptEngine::ShouldBeSynchronized::Yes, + scripting::ScriptEngine::ShouldSendToRemote::Yes ); } diff --git a/modules/server/src/topics/luascripttopic.cpp b/modules/server/src/topics/luascripttopic.cpp index 26b2957abc..b75d863681 100644 --- a/modules/server/src/topics/luascripttopic.cpp +++ b/modules/server/src/topics/luascripttopic.cpp @@ -37,6 +37,7 @@ namespace { constexpr std::string_view KeyFunction = "function"; constexpr std::string_view KeyArguments = "arguments"; constexpr std::string_view KeyReturn = "return"; + constexpr std::string_view KeyShouldBeSynchronized = "shouldBeSynchronized"; constexpr std::string_view _loggerCat = "LuaScriptTopic"; std::string formatLua(const nlohmann::json::const_iterator& it); @@ -146,7 +147,13 @@ void LuaScriptTopic::handleJson(const nlohmann::json& json) { ret->is_boolean() && ret->get(); - runScript(luaScript, shouldReturn); + nlohmann::json::const_iterator sync = json.find(KeyShouldBeSynchronized); + bool shouldBeSynchronized = true; + if (sync != json.end() && sync->is_boolean()) { + shouldBeSynchronized = sync->get(); + } + + runScript(luaScript, shouldReturn, shouldBeSynchronized); } else if (function != json.end() && function->is_string()) { std::string luaFunction = function->get(); @@ -155,6 +162,12 @@ void LuaScriptTopic::handleJson(const nlohmann::json& json) { ret->is_boolean() && ret->get(); + nlohmann::json::const_iterator sync = json.find(KeyShouldBeSynchronized); + bool shouldBeSynchronized = true; + if (sync != json.end() && sync->is_boolean()) { + shouldBeSynchronized = sync->get(); + } + nlohmann::json::const_iterator args = json.find(KeyArguments); if (!args->is_array()) { return; @@ -167,7 +180,7 @@ void LuaScriptTopic::handleJson(const nlohmann::json& json) { } std::string luaScript = generateScript(luaFunction, formattedArgs); - runScript(luaScript, shouldReturn); + runScript(luaScript, shouldReturn, shouldBeSynchronized); } } catch (const std::out_of_range& e) { @@ -176,7 +189,9 @@ void LuaScriptTopic::handleJson(const nlohmann::json& json) { } } -void LuaScriptTopic::runScript(std::string script, bool shouldReturn) { +void LuaScriptTopic::runScript(std::string script, bool shouldReturn, + bool shouldBeSynchronized) +{ scripting::ScriptEngine::ScriptCallback callback; if (shouldReturn) { callback = [this](ghoul::Dictionary data) { @@ -195,7 +210,8 @@ void LuaScriptTopic::runScript(std::string script, bool shouldReturn) { global::scriptEngine->queueScript( std::move(script), - scripting::ScriptEngine::RemoteScripting::No, + scripting::ScriptEngine::ShouldBeSynchronized(shouldBeSynchronized), + scripting::ScriptEngine::ShouldSendToRemote(shouldBeSynchronized), callback ); } diff --git a/modules/server/src/topics/setpropertytopic.cpp b/modules/server/src/topics/setpropertytopic.cpp index 559adc6b6d..3a6ca50f67 100644 --- a/modules/server/src/topics/setpropertytopic.cpp +++ b/modules/server/src/topics/setpropertytopic.cpp @@ -126,7 +126,8 @@ void SetPropertyTopic::handleJson(const nlohmann::json& json) { fmt::format( "openspace.setPropertyValueSingle(\"{}\", {})", propertyKey, literal ), - scripting::ScriptEngine::RemoteScripting::Yes + scripting::ScriptEngine::ShouldBeSynchronized::Yes, + scripting::ScriptEngine::ShouldSendToRemote::Yes ); } } diff --git a/modules/server/src/topics/triggerpropertytopic.cpp b/modules/server/src/topics/triggerpropertytopic.cpp index bb5f3ad143..6ba2e78d05 100644 --- a/modules/server/src/topics/triggerpropertytopic.cpp +++ b/modules/server/src/topics/triggerpropertytopic.cpp @@ -44,7 +44,8 @@ void TriggerPropertyTopic::handleJson(const nlohmann::json& json) { fmt::format( "openspace.setPropertyValueSingle(\"{}\", nil)", propertyKey ), - scripting::ScriptEngine::RemoteScripting::Yes + scripting::ScriptEngine::ShouldBeSynchronized::Yes, + scripting::ScriptEngine::ShouldSendToRemote::Yes ); } catch (const std::out_of_range& e) { diff --git a/modules/skybrowser/skybrowsermodule.cpp b/modules/skybrowser/skybrowsermodule.cpp index 837365b6b5..188fec73db 100644 --- a/modules/skybrowser/skybrowsermodule.cpp +++ b/modules/skybrowser/skybrowsermodule.cpp @@ -356,7 +356,8 @@ void SkyBrowserModule::moveHoverCircle(const std::string& imageUrl, bool useScri ); global::scriptEngine->queueScript( script, - scripting::ScriptEngine::RemoteScripting::Yes + scripting::ScriptEngine::ShouldBeSynchronized::Yes, + scripting::ScriptEngine::ShouldSendToRemote::Yes ); } else { @@ -379,7 +380,8 @@ void SkyBrowserModule::moveHoverCircle(const std::string& imageUrl, bool useScri ); global::scriptEngine->queueScript( script, - scripting::ScriptEngine::RemoteScripting::Yes + scripting::ScriptEngine::ShouldBeSynchronized::Yes, + scripting::ScriptEngine::ShouldSendToRemote::Yes ); } @@ -392,7 +394,8 @@ void SkyBrowserModule::disableHoverCircle(bool useScript) { ); global::scriptEngine->queueScript( script, - scripting::ScriptEngine::RemoteScripting::Yes + scripting::ScriptEngine::ShouldBeSynchronized::Yes, + scripting::ScriptEngine::ShouldSendToRemote::Yes ); } else { diff --git a/modules/skybrowser/skybrowsermodule_lua.inl b/modules/skybrowser/skybrowsermodule_lua.inl index a23865c18a..66b1a628e2 100644 --- a/modules/skybrowser/skybrowsermodule_lua.inl +++ b/modules/skybrowser/skybrowsermodule_lua.inl @@ -228,7 +228,7 @@ std::string prunedIdentifier(std::string identifier) { } /** - * Starts the setup process of the sky browers. This function calls the lua function + * Starts the setup process of the sky browers. This function calls the Lua function * 'sendOutIdsToBrowsers' in all nodes in the cluster. */ [[codegen::luawrap]] void startSetup() { @@ -246,17 +246,23 @@ std::string prunedIdentifier(std::string identifier) { "openspace.skybrowser.setBorderColor('{}', {}, {}, {})", id, color.r, color.g, color.b ); + + // No sync or send because this is already inside a Lua script, therefor it + // has already been synced and sent to the connected nodes and peers global::scriptEngine->queueScript( script, - scripting::ScriptEngine::RemoteScripting::Yes + scripting::ScriptEngine::ShouldBeSynchronized::No, + scripting::ScriptEngine::ShouldSendToRemote::No ); } } // To ensure each node in a cluster calls its own instance of the wwt application - // Do not send this script to the other nodes + // Do not send this script to the other nodes. (Note malej 2023-AUG-23: Due to this + // already being inside a Lua function that have already been synced out) global::scriptEngine->queueScript( "openspace.skybrowser.sendOutIdsToBrowsers()", - scripting::ScriptEngine::RemoteScripting::Yes + scripting::ScriptEngine::ShouldBeSynchronized::No, + scripting::ScriptEngine::ShouldSendToRemote::No ); } @@ -599,25 +605,31 @@ ghoul::Dictionary wwtImageCollectionUrlDeprecated() "}" "}"; + // No sync or send because this is already inside a Lua script, therefor it has + // already been synced and sent to the connected nodes and peers global::scriptEngine->queueScript( "openspace.addScreenSpaceRenderable(" + browser + ");", - scripting::ScriptEngine::RemoteScripting::Yes + scripting::ScriptEngine::ShouldBeSynchronized::No, + scripting::ScriptEngine::ShouldSendToRemote::No ); global::scriptEngine->queueScript( "openspace.addSceneGraphNode(" + target + ");", - scripting::ScriptEngine::RemoteScripting::Yes + scripting::ScriptEngine::ShouldBeSynchronized::No, + scripting::ScriptEngine::ShouldSendToRemote::No ); global::scriptEngine->queueScript( "openspace.skybrowser.addPairToSkyBrowserModule('" + idTarget + "','" + idBrowser + "');", - scripting::ScriptEngine::RemoteScripting::Yes + scripting::ScriptEngine::ShouldBeSynchronized::No, + scripting::ScriptEngine::ShouldSendToRemote::No ); global::scriptEngine->queueScript( "openspace.skybrowser.setSelectedBrowser('" + idBrowser + "');", - scripting::ScriptEngine::RemoteScripting::Yes + scripting::ScriptEngine::ShouldBeSynchronized::No, + scripting::ScriptEngine::ShouldSendToRemote::No ); } @@ -635,15 +647,19 @@ ghoul::Dictionary wwtImageCollectionUrlDeprecated() module->removeTargetBrowserPair(identifier); - // Remove from engine + // Remove from engine. + // No sync or send because this is already inside a Lua script, therefor it has + // already been synced and sent to the connected nodes and peers global::scriptEngine->queueScript( "openspace.removeScreenSpaceRenderable('" + browser + "');", - scripting::ScriptEngine::RemoteScripting::Yes + scripting::ScriptEngine::ShouldBeSynchronized::No, + scripting::ScriptEngine::ShouldSendToRemote::No ); global::scriptEngine->queueScript( "openspace.removeSceneGraphNode('" + target + "');", - scripting::ScriptEngine::RemoteScripting::Yes + scripting::ScriptEngine::ShouldBeSynchronized::No, + scripting::ScriptEngine::ShouldSendToRemote::No ); } } diff --git a/modules/skybrowser/src/targetbrowserpair.cpp b/modules/skybrowser/src/targetbrowserpair.cpp index 57e4e86d48..8683264840 100644 --- a/modules/skybrowser/src/targetbrowserpair.cpp +++ b/modules/skybrowser/src/targetbrowserpair.cpp @@ -51,7 +51,8 @@ namespace { ); openspace::global::scriptEngine->queueScript( script, - openspace::scripting::ScriptEngine::RemoteScripting::Yes + openspace::scripting::ScriptEngine::ShouldBeSynchronized::Yes, + openspace::scripting::ScriptEngine::ShouldSendToRemote::Yes ); } } // namespace @@ -327,7 +328,8 @@ void TargetBrowserPair::startFading(float goal, float fadeTime) { global::scriptEngine->queueScript( script, - scripting::ScriptEngine::RemoteScripting::Yes + scripting::ScriptEngine::ShouldBeSynchronized::Yes, + scripting::ScriptEngine::ShouldSendToRemote::Yes ); } diff --git a/modules/statemachine/src/state.cpp b/modules/statemachine/src/state.cpp index 019646f4cc..6a09ee24e7 100644 --- a/modules/statemachine/src/state.cpp +++ b/modules/statemachine/src/state.cpp @@ -62,14 +62,16 @@ State::State(const ghoul::Dictionary& dictionary) { void State::enter() const { global::scriptEngine->queueScript( _enter, - scripting::ScriptEngine::RemoteScripting::Yes + scripting::ScriptEngine::ShouldBeSynchronized::Yes, + scripting::ScriptEngine::ShouldSendToRemote::Yes ); } void State::exit() const { global::scriptEngine->queueScript( _exit, - scripting::ScriptEngine::RemoteScripting::Yes + scripting::ScriptEngine::ShouldBeSynchronized::Yes, + scripting::ScriptEngine::ShouldSendToRemote::Yes ); } diff --git a/modules/statemachine/src/transition.cpp b/modules/statemachine/src/transition.cpp index 247529a6fe..55873a398b 100644 --- a/modules/statemachine/src/transition.cpp +++ b/modules/statemachine/src/transition.cpp @@ -71,7 +71,8 @@ void Transition::performAction() const { } global::scriptEngine->queueScript( _action, - scripting::ScriptEngine::RemoteScripting::Yes + scripting::ScriptEngine::ShouldBeSynchronized::Yes, + scripting::ScriptEngine::ShouldSendToRemote::Yes ); } diff --git a/src/engine/openspaceengine.cpp b/src/engine/openspaceengine.cpp index 894790e077..b6eb9c8103 100644 --- a/src/engine/openspaceengine.cpp +++ b/src/engine/openspaceengine.cpp @@ -1124,7 +1124,8 @@ void OpenSpaceEngine::preSynchronization() { for (const std::string& script : scheduledScripts) { global::scriptEngine->queueScript( script, - scripting::ScriptEngine::RemoteScripting::Yes + scripting::ScriptEngine::ShouldBeSynchronized::Yes, + scripting::ScriptEngine::ShouldSendToRemote::Yes ); } @@ -1577,7 +1578,8 @@ void OpenSpaceEngine::handleDragDrop(std::filesystem::path file) { std::string script = ghoul::lua::value(s); global::scriptEngine->queueScript( script, - scripting::ScriptEngine::RemoteScripting::Yes + scripting::ScriptEngine::ShouldBeSynchronized::Yes, + scripting::ScriptEngine::ShouldSendToRemote::Yes ); } @@ -1769,7 +1771,8 @@ void setCameraFromProfile(const Profile& p) { geoScript += ")"; global::scriptEngine->queueScript( geoScript, - scripting::ScriptEngine::RemoteScripting::Yes + scripting::ScriptEngine::ShouldBeSynchronized::Yes, + scripting::ScriptEngine::ShouldSendToRemote::Yes ); }, [&checkNodeExists](const Profile::CameraGoToNode& node) { @@ -1800,7 +1803,8 @@ void setModulesFromProfile(const Profile& p) { if (mod.loadedInstruction.has_value()) { global::scriptEngine->queueScript( mod.loadedInstruction.value(), - scripting::ScriptEngine::RemoteScripting::Yes + scripting::ScriptEngine::ShouldBeSynchronized::Yes, + scripting::ScriptEngine::ShouldSendToRemote::Yes ); } } @@ -1808,7 +1812,8 @@ void setModulesFromProfile(const Profile& p) { if (mod.notLoadedInstruction.has_value()) { global::scriptEngine->queueScript( mod.notLoadedInstruction.value(), - scripting::ScriptEngine::RemoteScripting::Yes + scripting::ScriptEngine::ShouldBeSynchronized::Yes, + scripting::ScriptEngine::ShouldSendToRemote::Yes ); } } @@ -1872,7 +1877,8 @@ void setAdditionalScriptsFromProfile(const Profile& p) { for (const std::string& a : p.additionalScripts) { global::scriptEngine->queueScript( a, - scripting::ScriptEngine::RemoteScripting::Yes + scripting::ScriptEngine::ShouldBeSynchronized::Yes, + scripting::ScriptEngine::ShouldSendToRemote::Yes ); } } diff --git a/src/events/eventengine.cpp b/src/events/eventengine.cpp index 01b41f1e52..c777bdfe7a 100644 --- a/src/events/eventengine.cpp +++ b/src/events/eventengine.cpp @@ -164,7 +164,13 @@ void EventEngine::triggerActions() const { if (ai.isEnabled && (!ai.filter.has_value() || params.isSubset(*ai.filter))) { - global::actionManager->triggerAction(ai.action, params); + // No sync because events are always synced and sent to the connected + // nodes and peers + global::actionManager->triggerAction( + ai.action, + params, + interaction::ActionManager::ShouldBeSynchronized::No + ); } } } diff --git a/src/interaction/actionmanager.cpp b/src/interaction/actionmanager.cpp index fb8e4fe904..c52f00f42f 100644 --- a/src/interaction/actionmanager.cpp +++ b/src/interaction/actionmanager.cpp @@ -80,7 +80,8 @@ std::vector ActionManager::actions() const { } void ActionManager::triggerAction(const std::string& identifier, - const ghoul::Dictionary& arguments) const + const ghoul::Dictionary& arguments, + ActionManager::ShouldBeSynchronized shouldBeSynchronized) const { ghoul_assert(!identifier.empty(), "Identifier must not be empty"); @@ -93,18 +94,21 @@ void ActionManager::triggerAction(const std::string& identifier, } const Action& a = action(identifier); - if (arguments.isEmpty()) { - global::scriptEngine->queueScript( - a.command, - scripting::ScriptEngine::RemoteScripting(!a.isLocal) - ); - } - else { - global::scriptEngine->queueScript( - fmt::format("args = {}\n{}", ghoul::formatLua(arguments), a.command), - scripting::ScriptEngine::RemoteScripting(!a.isLocal) - ); + std::string script = + arguments.isEmpty() ? + a.command : + fmt::format("args = {}\n{}", ghoul::formatLua(arguments), a.command); + + using ShouldBeSynchronized = scripting::ScriptEngine::ShouldBeSynchronized; + using ShouldSendToRemote = scripting::ScriptEngine::ShouldSendToRemote; + ShouldBeSynchronized sync = ShouldBeSynchronized::Yes; + ShouldSendToRemote send = ShouldSendToRemote::Yes; + if (!shouldBeSynchronized || a.isLocal) { + sync = ShouldBeSynchronized::No; + send = ShouldSendToRemote::No; } + + global::scriptEngine->queueScript(script, sync, send); } scripting::LuaLibrary ActionManager::luaLibrary() { diff --git a/src/interaction/actionmanager_lua.inl b/src/interaction/actionmanager_lua.inl index 819251d303..1c7bede99e 100644 --- a/src/interaction/actionmanager_lua.inl +++ b/src/interaction/actionmanager_lua.inl @@ -36,7 +36,7 @@ namespace { } /** - * Removes an existing action from the list of possible actions.The action is identifies + * Removes an existing action from the list of possible actions. The action is identifies * either by the passed name, or if it is a table, the value behind the 'Identifier' key * is extract and used instead. */ @@ -192,7 +192,13 @@ struct [[codegen::Dictionary(Action)]] Action { throw ghoul::lua::LuaError(fmt::format("Action '{}' not found", id)); } - global::actionManager->triggerAction(id, arg); + // No sync because this is already inside a Lua script, therefor it has + // already been synced and sent to the connected nodes and peers + global::actionManager->triggerAction( + id, + arg, + interaction::ActionManager::ShouldBeSynchronized::No + ); } #include "actionmanager_lua_codegen.cpp" diff --git a/src/interaction/joystickcamerastates.cpp b/src/interaction/joystickcamerastates.cpp index b53d1c76aa..e5bb3c1be3 100644 --- a/src/interaction/joystickcamerastates.cpp +++ b/src/interaction/joystickcamerastates.cpp @@ -169,7 +169,8 @@ void JoystickCameraStates::updateStateFromInput( global::scriptEngine->queueScript( script, - scripting::ScriptEngine::RemoteScripting(t.isRemote) + scripting::ScriptEngine::ShouldBeSynchronized(t.isRemote), + scripting::ScriptEngine::ShouldSendToRemote(t.isRemote) ); break; } @@ -188,7 +189,10 @@ void JoystickCameraStates::updateStateFromInput( if (active) { global::scriptEngine->queueScript( it->second.command, - scripting::ScriptEngine::RemoteScripting( + scripting::ScriptEngine::ShouldBeSynchronized( + it->second.synchronization + ), + scripting::ScriptEngine::ShouldSendToRemote( it->second.synchronization ) ); diff --git a/src/interaction/keybindingmanager.cpp b/src/interaction/keybindingmanager.cpp index b086e3f524..46d3663a76 100644 --- a/src/interaction/keybindingmanager.cpp +++ b/src/interaction/keybindingmanager.cpp @@ -52,7 +52,11 @@ void KeybindingManager::keyboardCallback(Key key, KeyModifier modifier, KeyActio // bind a key to multiple actions, only one of which could be defined continue; } - global::actionManager->triggerAction(it->second, ghoul::Dictionary()); + global::actionManager->triggerAction( + it->second, + ghoul::Dictionary(), + interaction::ActionManager::ShouldBeSynchronized::Yes + ); } } } diff --git a/src/interaction/sessionrecording.cpp b/src/interaction/sessionrecording.cpp index 6ca8d1d952..f7e6c9f63c 100644 --- a/src/interaction/sessionrecording.cpp +++ b/src/interaction/sessionrecording.cpp @@ -2088,7 +2088,8 @@ bool SessionRecording::processScriptKeyframe() { ); global::scriptEngine->queueScript( nextScript, - scripting::ScriptEngine::RemoteScripting::Yes + scripting::ScriptEngine::ShouldBeSynchronized::Yes, + scripting::ScriptEngine::ShouldSendToRemote::Yes ); } diff --git a/src/navigation/navigationhandler.cpp b/src/navigation/navigationhandler.cpp index 637bdba6cd..5c0de14a84 100644 --- a/src/navigation/navigationhandler.cpp +++ b/src/navigation/navigationhandler.cpp @@ -279,7 +279,13 @@ void NavigationHandler::updateCameraTransitions() { dict.setValue("Node", anchorNode()->identifier()); dict.setValue("Transition", "Exiting"s); for (const std::string& action : anchorNode()->onExitAction()) { - global::actionManager->triggerAction(action, dict); + // No sync because events are always synced and sent to the connected + // nodes and peers + global::actionManager->triggerAction( + action, + dict, + interaction::ActionManager::ShouldBeSynchronized::No + ); } } @@ -299,7 +305,13 @@ void NavigationHandler::updateCameraTransitions() { dict.setValue("Node", anchorNode()->identifier()); dict.setValue("Transition", "Reaching"s); for (const std::string& action : anchorNode()->onReachAction()) { - global::actionManager->triggerAction(action, dict); + // No sync because events are always synced and sent to the connected + // nodes and peers + global::actionManager->triggerAction( + action, + dict, + interaction::ActionManager::ShouldBeSynchronized::No + ); } } @@ -320,7 +332,13 @@ void NavigationHandler::updateCameraTransitions() { dict.setValue("Node", anchorNode()->identifier()); dict.setValue("Transition", "Receding"s); for (const std::string& action : anchorNode()->onRecedeAction()) { - global::actionManager->triggerAction(action, dict); + // No sync because events are always synced and sent to the connected + // nodes and peers + global::actionManager->triggerAction( + action, + dict, + interaction::ActionManager::ShouldBeSynchronized::No + ); } } @@ -341,7 +359,13 @@ void NavigationHandler::updateCameraTransitions() { dict.setValue("Node", anchorNode()->identifier()); dict.setValue("Transition", "Approaching"s); for (const std::string& action : anchorNode()->onApproachAction()) { - global::actionManager->triggerAction(action, dict); + // No sync because events are always synced and sent to the connected + // nodes and peers + global::actionManager->triggerAction( + action, + dict, + interaction::ActionManager::ShouldBeSynchronized::No + ); } } diff --git a/src/navigation/pathnavigator.cpp b/src/navigation/pathnavigator.cpp index f2c5418192..838df0eebb 100644 --- a/src/navigation/pathnavigator.cpp +++ b/src/navigation/pathnavigator.cpp @@ -322,7 +322,8 @@ void PathNavigator::startPath() { if (!global::timeManager->isPaused()) { openspace::global::scriptEngine->queueScript( "openspace.time.setPause(true)", - scripting::ScriptEngine::RemoteScripting::Yes + scripting::ScriptEngine::ShouldBeSynchronized::Yes, + scripting::ScriptEngine::ShouldSendToRemote::Yes ); _startSimulationTimeOnFinish = true; @@ -437,7 +438,8 @@ void PathNavigator::handlePathEnd() { if (_startSimulationTimeOnFinish) { openspace::global::scriptEngine->queueScript( "openspace.time.setPause(false)", - scripting::ScriptEngine::RemoteScripting::Yes + scripting::ScriptEngine::ShouldBeSynchronized::Yes, + scripting::ScriptEngine::ShouldSendToRemote::Yes ); _startSimulationTimeOnFinish = false; } @@ -448,7 +450,8 @@ void PathNavigator::handlePathEnd() { "'NavigationHandler.OrbitalNavigator.IdleBehavior.ApplyIdleBehavior'," "true" ");", - openspace::scripting::ScriptEngine::RemoteScripting::Yes + openspace::scripting::ScriptEngine::ShouldBeSynchronized::Yes, + openspace::scripting::ScriptEngine::ShouldSendToRemote::Yes ); } diff --git a/src/network/parallelpeer.cpp b/src/network/parallelpeer.cpp index 28a1f12c0a..5f5e5727ba 100644 --- a/src/network/parallelpeer.cpp +++ b/src/network/parallelpeer.cpp @@ -392,9 +392,12 @@ void ParallelPeer::dataMessageReceived(const std::vector& message) { datamessagestructures::ScriptMessage sm; sm.deserialize(buffer); + // No sync or send because this has already been recived by a peer, + // don't send it back again global::scriptEngine->queueScript( sm._script, - scripting::ScriptEngine::RemoteScripting::No + scripting::ScriptEngine::ShouldBeSynchronized::No, + scripting::ScriptEngine::ShouldSendToRemote::No ); break; } diff --git a/src/rendering/luaconsole.cpp b/src/rendering/luaconsole.cpp index d87833ea29..19ff81c7c9 100644 --- a/src/rendering/luaconsole.cpp +++ b/src/rendering/luaconsole.cpp @@ -76,11 +76,21 @@ namespace { openspace::properties::Property::Visibility::AdvancedUser }; - constexpr openspace::properties::Property::PropertyInfo RemoveScriptingInfo = { - "RemoteScripting", - "Remote scripting", + constexpr openspace::properties::Property::PropertyInfo ShouldBeSynchronizedInfo = { + "ShouldBeSynchronized", + "Should Be Synchronized", + "Determines whether the entered commands will only be executed locally (if this " + "is disabled), or whether they will be send to other connected nodes, for " + "example in a cluster environment", + openspace::properties::Property::Visibility::AdvancedUser + }; + + constexpr openspace::properties::Property::PropertyInfo ShouldSendToRemoteInfo = { + "ShouldSendToRemote", + "Should Send To Remote", "Determines whether the entered commands will only be executed locally (if this " - "is disabled), or whether they will be send to connected remove instances", + "is disabled), or whether they will be send to connected remote instances (other " + "peers through a parallel connection)", openspace::properties::Property::Visibility::AdvancedUser }; @@ -134,7 +144,8 @@ namespace openspace { LuaConsole::LuaConsole() : properties::PropertyOwner({ "LuaConsole", "Lua Console" }) , _isVisible(VisibleInfo, false) - , _remoteScripting(RemoveScriptingInfo, false) + , _shouldSendToRemote(ShouldSendToRemoteInfo, false) + , _shouldBeSynchronized(ShouldBeSynchronizedInfo, true) , _backgroundColor( BackgroundColorInfo, glm::vec4(21.f / 255.f, 23.f / 255.f, 28.f / 255.f, 0.8f), @@ -157,7 +168,8 @@ LuaConsole::LuaConsole() , _autoCompleteInfo({NoAutoComplete, false, ""}) { addProperty(_isVisible); - addProperty(_remoteScripting); + addProperty(_shouldBeSynchronized); + addProperty(_shouldSendToRemote); addProperty(_historyLength); _backgroundColor.setViewOption(properties::Property::ViewOptions::Color); @@ -278,12 +290,25 @@ bool LuaConsole::keyboardCallback(Key key, KeyModifier modifier, KeyAction actio return false; } + const bool modifierShift = (modifier == KeyModifier::Shift); + const bool modifierControl = (modifier == KeyModifier::Control); + + // Button left of 1 and above TAB (default) + // Can be changed to any other key with the setCommandInputButton funciton if (key == _commandInputButton) { - // Button left of 1 and above TAB - // How to deal with different keyboard languages? ---abock if (_isVisible) { - if (_remoteScripting) { - _remoteScripting = false; + if (modifierShift) { + // Toggle ShouldBeSynchronized property for all scripts + _shouldBeSynchronized = !_shouldBeSynchronized; + } + else if (modifierControl) { + // Only allow this toggle if a ParallelConnection exists + if (_shouldSendToRemote) { + _shouldSendToRemote = false; + } + else if (global::parallelPeer->status() == ParallelConnection::Status::Host) { + _shouldSendToRemote = true; + } } else { _isVisible = false; @@ -293,9 +318,6 @@ bool LuaConsole::keyboardCallback(Key key, KeyModifier modifier, KeyAction actio } else { _isVisible = true; - if (global::parallelPeer->status() == ParallelConnection::Status::Host) { - _remoteScripting = true; - } } return true; @@ -310,10 +332,6 @@ bool LuaConsole::keyboardCallback(Key key, KeyModifier modifier, KeyAction actio return true; } - - const bool modifierControl = (modifier == KeyModifier::Control); - const bool modifierShift = (modifier == KeyModifier::Shift); - // Paste from clipboard if (modifierControl && (key == Key::V || key == Key::Y)) { addToCommand(sanitizeInput(ghoul::clipboardText())); @@ -432,8 +450,11 @@ bool LuaConsole::keyboardCallback(Key key, KeyModifier modifier, KeyAction actio if (key == Key::Enter || key == Key::KeypadEnter) { std::string cmd = _commands.at(_activeCommand); if (!cmd.empty()) { - using RemoteScripting = scripting::ScriptEngine::RemoteScripting; - global::scriptEngine->queueScript(cmd, RemoteScripting(_remoteScripting)); + global::scriptEngine->queueScript( + cmd, + scripting::ScriptEngine::ShouldBeSynchronized(_shouldBeSynchronized), + scripting::ScriptEngine::ShouldSendToRemote(_shouldSendToRemote) + ); // Only add the current command to the history if it hasn't been // executed before. We don't want two of the same commands in a row @@ -799,14 +820,22 @@ void LuaConsole::render() { const glm::vec2 loc = glm::vec2( EntryFontSize * dpi / 2.f, - res.y - _currentHeight + EntryFontSize * dpi + res.y - EntryFontSize * dpi ); const glm::vec2 bbox = _font->boundingBox(text); return glm::vec2(loc.x + res.x - bbox.x - 10.f, loc.y); }; - if (_remoteScripting) { + if (!_shouldBeSynchronized) { + const glm::vec4 Yellow(1.0f, 1.0f, 0.f, 1.f); + + const std::string masterOnlyExecutionText = + "Master only script execution (Nodes and Peers will not recieve scripts)"; + const glm::vec2 loc = locationForRightJustifiedText(masterOnlyExecutionText); + RenderFont(*_font, loc, masterOnlyExecutionText, Yellow); + } + else if (_shouldSendToRemote) { const glm::vec4 Red(1.f, 0.f, 0.f, 1.f); ParallelConnection::Status status = global::parallelPeer->status(); @@ -826,7 +855,8 @@ void LuaConsole::render() { else if (global::parallelPeer->isHost()) { const glm::vec4 LightBlue(0.4f, 0.4f, 1.f, 1.f); - const std::string localExecutionText = "Local script execution"; + const std::string localExecutionText = + "Local script execution (Peers will not recieve scripts)"; const glm::vec2 loc = locationForRightJustifiedText(localExecutionText); RenderFont(*_font, loc, localExecutionText, LightBlue); } @@ -847,7 +877,7 @@ void LuaConsole::addToCommand(std::string c) { } void LuaConsole::parallelConnectionChanged(const ParallelConnection::Status& status) { - _remoteScripting = (status == ParallelConnection::Status::Host); + _shouldSendToRemote = (status == ParallelConnection::Status::Host); } } // namespace openspace diff --git a/src/rendering/renderengine.cpp b/src/rendering/renderengine.cpp index 7adc3ddbc4..e8d3ecbade 100644 --- a/src/rendering/renderengine.cpp +++ b/src/rendering/renderengine.cpp @@ -776,7 +776,8 @@ bool RenderEngine::mouseActivationCallback(const glm::dvec2& mousePosition) cons global::scriptEngine->queueScript( ToggleRotationFrictionScript, - scripting::ScriptEngine::RemoteScripting::Yes + scripting::ScriptEngine::ShouldBeSynchronized::Yes, + scripting::ScriptEngine::ShouldSendToRemote::Yes ); return true; } @@ -788,7 +789,8 @@ bool RenderEngine::mouseActivationCallback(const glm::dvec2& mousePosition) cons global::scriptEngine->queueScript( ToggleZoomFrictionScript, - scripting::ScriptEngine::RemoteScripting::Yes + scripting::ScriptEngine::ShouldBeSynchronized::Yes, + scripting::ScriptEngine::ShouldSendToRemote::Yes ); return true; } @@ -800,7 +802,8 @@ bool RenderEngine::mouseActivationCallback(const glm::dvec2& mousePosition) cons global::scriptEngine->queueScript( ToggleRollFrictionScript, - scripting::ScriptEngine::RemoteScripting::Yes + scripting::ScriptEngine::ShouldBeSynchronized::Yes, + scripting::ScriptEngine::ShouldSendToRemote::Yes ); return true; } diff --git a/src/rendering/screenspacerenderable.cpp b/src/rendering/screenspacerenderable.cpp index f3535aec34..2ddfcacca8 100644 --- a/src/rendering/screenspacerenderable.cpp +++ b/src/rendering/screenspacerenderable.cpp @@ -420,9 +420,13 @@ ScreenSpaceRenderable::ScreenSpaceRenderable(const ghoul::Dictionary& dictionary _delete.onChange([this](){ std::string script = "openspace.removeScreenSpaceRenderable('" + identifier() + "');"; + // No sync or send because this is already inside a Lua script that was triggered + // when this triggerProperty was pressed in the gui, therefor it has already been + // synced and sent to the connected nodes and peers global::scriptEngine->queueScript( script, - scripting::ScriptEngine::RemoteScripting::No + scripting::ScriptEngine::ShouldBeSynchronized::No, + scripting::ScriptEngine::ShouldSendToRemote::No ); }); addProperty(_delete); diff --git a/src/scene/scene.cpp b/src/scene/scene.cpp index cbd7203a50..1fd7efcdc6 100644 --- a/src/scene/scene.cpp +++ b/src/scene/scene.cpp @@ -548,9 +548,13 @@ void Scene::updateInterpolations() { if (i.isExpired) { if (!i.postScript.empty()) { + // No sync or send because this is already inside a Lua script that was triggered + // when the interpolation of the property was triggered, therefor it has already been + // synced and sent to the connected nodes and peers global::scriptEngine->queueScript( std::move(i.postScript), - scripting::ScriptEngine::RemoteScripting::No + scripting::ScriptEngine::ShouldBeSynchronized::No, + scripting::ScriptEngine::ShouldSendToRemote::No ); } diff --git a/src/scripting/scriptengine.cpp b/src/scripting/scriptengine.cpp index c3f6eeb81a..1663b3b133 100644 --- a/src/scripting/scriptengine.cpp +++ b/src/scripting/scriptengine.cpp @@ -533,18 +533,24 @@ void ScriptEngine::preSync(bool isMaster) { QueueItem item = std::move(_incomingScripts.front()); _incomingScripts.pop(); - _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); - if (global::parallelPeer->isHost() && remoteScripting) { - global::parallelPeer->sendScript(item.script); - } if (global::sessionRecording->isRecording()) { global::sessionRecording->saveScriptKeyframeToTimeline(item.script); } + + // Sync out to other nodes (cluster) + if (!item.shouldBeSynchronized) { + continue; + } + _scriptsToSync.push_back(item.script); + + // Send to other peers (parallel connection) + const bool shouldSendToRemote = item.shouldSendToRemote; + if (global::parallelPeer->isHost() && shouldSendToRemote) { + global::parallelPeer->sendScript(item.script); + } } } else { @@ -613,7 +619,8 @@ void ScriptEngine::postSync(bool isMaster) { } void ScriptEngine::queueScript(std::string script, - ScriptEngine::RemoteScripting remoteScripting, + ScriptEngine::ShouldBeSynchronized shouldBeSynchronized, + ScriptEngine::ShouldSendToRemote shouldSendToRemote, ScriptCallback callback) { ZoneScoped; @@ -621,7 +628,12 @@ void ScriptEngine::queueScript(std::string script, if (script.empty()) { return; } - _incomingScripts.push({ std::move(script), remoteScripting, std::move(callback) }); + _incomingScripts.push({ + std::move(script), + shouldBeSynchronized, + shouldSendToRemote, + std::move(callback) + }); } diff --git a/src/scripting/scriptscheduler.cpp b/src/scripting/scriptscheduler.cpp index bbc5cdd451..3a1d8244e4 100644 --- a/src/scripting/scriptscheduler.cpp +++ b/src/scripting/scriptscheduler.cpp @@ -262,7 +262,8 @@ void ScriptScheduler::setCurrentTime(double time) { for (const std::string& script : scheduledScripts) { global::scriptEngine->queueScript( script, - scripting::ScriptEngine::RemoteScripting::Yes + scripting::ScriptEngine::ShouldBeSynchronized::Yes, + scripting::ScriptEngine::ShouldSendToRemote::Yes ); } }