From 284c68f95288f0835d744ce55c3a8d42c08493a7 Mon Sep 17 00:00:00 2001 From: GPayne Date: Wed, 8 Sep 2021 09:21:56 -0600 Subject: [PATCH] Finished support for modules and markInterestingNodes --- include/openspace/engine/moduleengine.h | 9 +++++++++ include/openspace/scene/scene.h | 9 +++++++++ src/engine/moduleengine.cpp | 24 ++++++++++++++++++++++++ src/engine/openspaceengine.cpp | 3 +++ src/scene/scene.cpp | 16 ++++++++++++++++ 5 files changed, 61 insertions(+) diff --git a/include/openspace/engine/moduleengine.h b/include/openspace/engine/moduleengine.h index cc23589a4c..b34e08eeda 100644 --- a/include/openspace/engine/moduleengine.h +++ b/include/openspace/engine/moduleengine.h @@ -26,6 +26,7 @@ #define __OPENSPACE_CORE___MODULEENGINE___H__ #include +#include #include #include @@ -116,6 +117,14 @@ public: */ ghoul::systemcapabilities::Version requiredOpenGLVersion() const; + /** + * Reads a list of modules from a profile, and executes scripts based on whether or + * not the corresponding module is loaded. + * + * \param p The Profile to be read. + */ + void setFromProfile_modules(const Profile& p); + /** * Returns the Lua library that contains all Lua functions available to affect the * modules. diff --git a/include/openspace/scene/scene.h b/include/openspace/scene/scene.h index 2bf112f4d1..d883d868aa 100644 --- a/include/openspace/scene/scene.h +++ b/include/openspace/scene/scene.h @@ -264,6 +264,15 @@ public: void property_pushValueFromProfileToLuaState(ghoul::lua::LuaState& L, const std::string& value); + /** + * Reads list of nodes from profile to be marked as interesting nodes. + * If any nodes are listed, a script to mark these will be queued with the + * script engine. + * + * \param p The Profile to be read. + */ + void setFromProfile_markInterestingNodes(const Profile& p); + private: /** * Update dependencies. diff --git a/src/engine/moduleengine.cpp b/src/engine/moduleengine.cpp index e2e8836265..c481370117 100644 --- a/src/engine/moduleengine.cpp +++ b/src/engine/moduleengine.cpp @@ -27,6 +27,7 @@ #include #include #include +#include #include #include #include @@ -163,6 +164,29 @@ ghoul::systemcapabilities::Version ModuleEngine::requiredOpenGLVersion() const { return version; } +void ModuleEngine::setFromProfile_modules(const Profile& p) +{ + for (Profile::Module mod : p.modules) { + const std::vector& m = modules(); + if (std::find(m.begin(), m.end(), mod.name) != m.end()) { + if (mod.loadedInstruction.has_value()) { + global::scriptEngine->queueScript( + mod.loadedInstruction.value(), + scripting::ScriptEngine::RemoteScripting::Yes + ); + } + } + else { + if (mod.notLoadedInstruction.has_value()) { + global::scriptEngine->queueScript( + mod.notLoadedInstruction.value(), + scripting::ScriptEngine::RemoteScripting::Yes + ); + } + } + } +} + scripting::LuaLibrary ModuleEngine::luaLibrary() { return { "modules", diff --git a/src/engine/openspaceengine.cpp b/src/engine/openspaceengine.cpp index c07331db27..55da0b7286 100644 --- a/src/engine/openspaceengine.cpp +++ b/src/engine/openspaceengine.cpp @@ -1128,6 +1128,9 @@ void OpenSpaceEngine::preSynchronization() { global::navigationHandler->setFromProfile_camera(*global::profile); global::actionManager->setFromProfile_actions(*global::profile); global::keybindingManager->setFromProfile_keybindings(*global::profile); + global::moduleEngine->setFromProfile_modules(*global::profile); + global::renderEngine->scene()->setFromProfile_markInterestingNodes( + *global::profile); global::profile->ignoreUpdates = false; resetPropertyChangeFlagsOfSubowners(global::rootPropertyOwner); diff --git a/src/scene/scene.cpp b/src/scene/scene.cpp index a21e3d688e..951d4bf97f 100644 --- a/src/scene/scene.cpp +++ b/src/scene/scene.cpp @@ -35,6 +35,7 @@ #include #include #include +#include #include #include #include @@ -682,6 +683,21 @@ void Scene::property_pushValueFromProfileToLuaState(ghoul::lua::LuaState& L, } } +void Scene::setFromProfile_markInterestingNodes(const Profile& p) { + std::string nodesToMark; + for (auto node : p.markNodes) { + nodesToMark += fmt::format("[[{}]],", node); + } + if (!nodesToMark.empty()) { + std::string markCmd = fmt::format("openspace.markInterestingNodes({{ {} }});", + nodesToMark); + global::scriptEngine->queueScript( + markCmd, + scripting::ScriptEngine::RemoteScripting::Yes + ); + } +} + scripting::LuaLibrary Scene::luaLibrary() { return { "",