From 51f6c9d45bdde2cf3a5e46e24fe1af05ab4469f4 Mon Sep 17 00:00:00 2001 From: GPayne Date: Sun, 12 Sep 2021 21:05:00 -0600 Subject: [PATCH] Rearranged profile initializations and verified that all init correctly --- include/openspace/engine/moduleengine.h | 9 - include/openspace/engine/openspaceengine.h | 56 ++++ include/openspace/interaction/actionmanager.h | 7 - .../openspace/interaction/keybindingmanager.h | 8 - .../openspace/navigation/navigationhandler.h | 8 - include/openspace/scene/profile.h | 146 ---------- include/openspace/scene/scene.h | 18 -- include/openspace/util/timemanager.h | 7 - src/engine/moduleengine.cpp | 23 -- src/engine/openspaceengine.cpp | 201 +++++++++++--- src/interaction/actionmanager.cpp | 32 --- src/interaction/keybindingmanager.cpp | 17 -- src/navigation/navigationhandler.cpp | 42 --- src/scene/profile.cpp | 262 ------------------ src/scene/scene.cpp | 53 ---- src/scene/scenelicensewriter.cpp | 21 +- src/util/timemanager.cpp | 4 - 17 files changed, 231 insertions(+), 683 deletions(-) diff --git a/include/openspace/engine/moduleengine.h b/include/openspace/engine/moduleengine.h index b34e08eeda..cc23589a4c 100644 --- a/include/openspace/engine/moduleengine.h +++ b/include/openspace/engine/moduleengine.h @@ -26,7 +26,6 @@ #define __OPENSPACE_CORE___MODULEENGINE___H__ #include -#include #include #include @@ -117,14 +116,6 @@ 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/engine/openspaceengine.h b/include/openspace/engine/openspaceengine.h index 9cc276248f..03c87cfd9b 100644 --- a/include/openspace/engine/openspaceengine.h +++ b/include/openspace/engine/openspaceengine.h @@ -26,6 +26,7 @@ #define __OPENSPACE_CORE___OPENSPACEENGINE___H__ #include +#include #include #include #include @@ -101,6 +102,61 @@ public: void writeStaticDocumentation(); void createUserDirectoriesIfNecessary(); + /** + * Sets the camera position using the time contents of a profile. The function will + * set an absolute position or a go-to-geolocation command using the globebrowsing + * module. + * \param p The Profile to be read. + */ + void setFromProfile_camera(const Profile& p); + + /** + * Sets the delta times using the delta time array from a profile. + * + * \param p The Profile to be read. + */ + void setFromProfile_deltaTimes(const Profile& p); + + /** + * 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); + + /** + * Registers actions from the contents of a profile. + * + * \param p The Profile to be read. + */ + void setFromProfile_actions(const Profile& p); + + /** + * Registers keybindings from the contents of a profile. + * + * \param p The Profile to be read. + */ + void setFromProfile_keybindings(const Profile& p); + + /** + * 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); + + /** + * Reads list of "additional scripts" that are added to the profile to be run + * at the end of the initialization. Any openspace lua commands are allowed, + * and will be added to the script queue. + * + * \param p The Profile to be read. + */ + void setFromProfile_additionalScripts(const Profile& p); + /** * Returns the Lua library that contains all Lua functions available to affect the * application. diff --git a/include/openspace/interaction/actionmanager.h b/include/openspace/interaction/actionmanager.h index d5e86565fd..79a07aa77c 100644 --- a/include/openspace/interaction/actionmanager.h +++ b/include/openspace/interaction/actionmanager.h @@ -26,7 +26,6 @@ #define __OPENSPACE_CORE___ACTIONMANAGER___H__ #include -#include #include namespace ghoul { class Dictionary; } @@ -44,12 +43,6 @@ public: void triggerAction(const std::string& identifier, const ghoul::Dictionary& arguments) const; - /** - * Registers actions from the contents of a profile. - * - * \param p The Profile to be read. - */ - void setFromProfile_actions(const Profile& p); static scripting::LuaLibrary luaLibrary(); private: diff --git a/include/openspace/interaction/keybindingmanager.h b/include/openspace/interaction/keybindingmanager.h index e843b16020..196848a939 100644 --- a/include/openspace/interaction/keybindingmanager.h +++ b/include/openspace/interaction/keybindingmanager.h @@ -27,7 +27,6 @@ #include -#include #include namespace openspace { @@ -52,13 +51,6 @@ public: std::vector> keyBinding( const KeyWithModifier& key) const; - /** - * Registers keybindings from the contents of a profile. - * - * \param p The Profile to be read. - */ - void setFromProfile_keybindings(const Profile& p); - static scripting::LuaLibrary luaLibrary(); void keyboardCallback(Key key, KeyModifier modifier, KeyAction action); diff --git a/include/openspace/navigation/navigationhandler.h b/include/openspace/navigation/navigationhandler.h index d2b525e3fa..b25a14dfe5 100644 --- a/include/openspace/navigation/navigationhandler.h +++ b/include/openspace/navigation/navigationhandler.h @@ -132,14 +132,6 @@ public: void setNavigationStateNextFrame(NavigationState state); - /** - * Sets the camera position using the time contents of a profile. The function will - * set an absolute position or a go-to-geolocation command using the globebrowsing - * module. - * \param p The Profile to be read. - */ - void setFromProfile_camera(const Profile& p); - /** * \return The Lua library that contains all Lua functions available to affect the * interaction diff --git a/include/openspace/scene/profile.h b/include/openspace/scene/profile.h index 63c2e3de90..86631e45ff 100644 --- a/include/openspace/scene/profile.h +++ b/include/openspace/scene/profile.h @@ -168,152 +168,6 @@ public: std::string assetFileExtension = ".asset"; }; -/** - * Function to convert a profile into separate files with converted asset contents - * from each section - * - * \param filePre The prefix name for the asset section to be applied to the output - * filename. The pattern is "_.asset" - * \param p The profile that should be processed - */ -void convertToSeparatedAssets(const std::string filePre, const Profile& p); - -/** - * Function to convert a specific section of a profile into an asset file, which allows - * that section to be individually loaded. - * - * \param profilePrefix The name for the asset section to be applied to the output - * filename. The pattern is "_.asset" - * \param p The profile that should be processed - * \param profileSectionName The name of the profile subsection used for output filename - * \param func a std::function that takes a reference to a const Profile as arg, and - * returns the asset-ified contents as a std::string object - */ -void convertSectionToAssetFile(const std::string profilePrefix, const Profile& p, - const std::string profileSectionName, - std::function func); - -/** - * convertToAsset_* functions extract a section (* as section name) and returns its - * asset-ified version as a string. This allows the profile section to be processed - * by the asset loader. Having individual sections allows for controlling the order of - * processing/loading the profile. It also makes it possible for changing the way - * sections are processed. - */ -/** - * Function to process the meta information included in the profile - * - * \param p The profile that should be processed - * - * \return The string representation of the provided profile's meta section, ready - * to be loaded as an asset - */ -std::string convertToAsset_meta(const Profile& p); - -/** - * Function to process the assets that are included in the profile - * - * \param p The profile that should be processed - * - * \return The string representation of the provided profile's asset section, ready - * to be loaded as an asset - */ -std::string convertToAsset_addedAssets(const Profile& p); - -/** - * Function to process the modules that may be included in the profile, and the commands - * to execute if they are/aren't loaded - * - * \param p The profile that should be processed - * - * \return The string representation of the provided profile's modules section, ready - * to be loaded as an asset - */ -std::string convertToAsset_modules(const Profile& p); - -/** - * Function to process the actions that are included in the profile. - * This is separate from, but closely-related to, the keybindings section - * - * \param p The profile that should be processed - * - * \return The string representation of the provided profile's actions section, - * ready to be loaded as an asset - */ -std::string convertToAsset_actions(const Profile& p); - -/** - * Function to process the keybindings that are included in the profile. - * This is separate from, but closely-related to, the actions section - * - * \param p The profile that should be processed - * - * \return The string representation of the provided profile's keybindings - * section, ready to be loaded as an asset - */ -std::string convertToAsset_keybinds(const Profile& p); - -/** - * Function to process the time setting that is included in the profile - * - * \param p The profile that should be processed - * - * \return The string representation of the provided profile's time section, ready - * to be loaded as an asset - */ -std::string convertToAsset_time(const Profile& p); - -/** - * Function to process the delta time settings that are included in the profile - * - * \param p The profile that should be processed - * - * \return The string representation of the provided profile's delta times section, ready - * to be loaded as an asset - */ -std::string convertToAsset_deltaTimes(const Profile& p); - -/** - * Function to process the mark-interesting-nodes that are included in the profile - * - * \param p The profile that should be processed - * - * \return The string representation of the provided profile's mark-interesting-nodes - * section, ready to be loaded as an asset - */ -std::string convertToAsset_markNodes(const Profile& p); - -/** - * Function to process the properties that are included in the profile - * - * \param p The profile that should be processed - * - * \return The string representation of the provided profile's properties section, ready - * to be loaded as an asset - */ -std::string convertToAsset_properties(const Profile& p); - -/** - * Function to process the initial camera orientation that is included in the profile - * - * \param p The profile that should be processed - * - * \return The string representation of the provided profile's camera section, ready - * to be loaded as an asset - */ -std::string convertToAsset_camera(const Profile& p); - -/** - * Function to process the additional scripts command section that is included in the - * profile - * - * \param p The profile that should be processed - * - * \return The string representation of the provided profile's additional scripts - * section, ready to be loaded as an asset - */ -std::string convertToAsset_addedScripts(const Profile& p); - /** * Function to retrieve the individual additional script lines included in the profile * diff --git a/include/openspace/scene/scene.h b/include/openspace/scene/scene.h index d883d868aa..8eed3fd26c 100644 --- a/include/openspace/scene/scene.h +++ b/include/openspace/scene/scene.h @@ -235,15 +235,6 @@ public: */ static scripting::LuaLibrary luaLibrary(); - /** - * Creates an initial asset file to load, which contains: - * 1. Meta information - * 2. Assets to include - * - * \param p The Profile to be read. - */ - void createInitialAssetToLoad(const Profile& p, const std::string& assetFilename); - /** * Sets a property using the 'properties' contents of a profile. The function will * loop through each setProperty command. A property may be set to a bool, float, @@ -264,15 +255,6 @@ 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/include/openspace/util/timemanager.h b/include/openspace/util/timemanager.h index 9de240dd84..9ecd2f1f4c 100644 --- a/include/openspace/util/timemanager.h +++ b/include/openspace/util/timemanager.h @@ -87,13 +87,6 @@ public: */ void setFromProfile_time(const Profile& p); - /** - * Sets the delta times using the delta time array from a profile. - * - * \param p The Profile to be read. - */ - void setFromProfile_deltaTimes(const Profile& p); - bool isPaused() const; std::vector deltaTimeSteps() const; diff --git a/src/engine/moduleengine.cpp b/src/engine/moduleengine.cpp index c481370117..235003d400 100644 --- a/src/engine/moduleengine.cpp +++ b/src/engine/moduleengine.cpp @@ -164,29 +164,6 @@ 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 55da0b7286..7a04e3ea61 100644 --- a/src/engine/openspaceengine.cpp +++ b/src/engine/openspaceengine.cpp @@ -96,6 +96,10 @@ #include "openspaceengine_lua.inl" namespace { + // Helper structs for the visitor pattern of the std::variant + template struct overloaded : Ts... { using Ts::operator()...; }; + template overloaded(Ts...)->overloaded; + constexpr const char* _loggerCat = "OpenSpaceEngine"; } // namespace @@ -293,7 +297,7 @@ void OpenSpaceEngine::initialize() { LDEBUG("Registering Lua libraries"); registerCoreClasses(*global::scriptEngine); - // Convert profile to scene file (if was provided in configuration file) + // Process profile file (must be provided in configuration file) if (!global::configuration->profile.empty()) { std::string inputProfilePath = absPath("${PROFILES}").string(); std::string outputScenePath = absPath("${TEMPORARY}").string(); @@ -332,10 +336,6 @@ void OpenSpaceEngine::initialize() { ); *global::profile = Profile(content); - // Then save the profile to a scene so that we can load it with the - // existing infrastructure - //convertToSeparatedAssets(outputProfilePrefix, *global::profile); - global::configuration->profileOutPrefixName = outputProfilePrefix; global::configuration->usingProfile = true; } @@ -701,9 +701,6 @@ void OpenSpaceEngine::loadAsset_init(const std::string assetName) { global::windowDelegate->setBarrier(true); }; - if (assetName.empty()) { - return; - } if (_scene) { ZoneScopedN("Reset scene") @@ -752,6 +749,9 @@ void OpenSpaceEngine::loadAsset_init(const std::string assetName) { } _assetManager->removeAll(); + if (!assetName.empty()) { + _assetManager->add(assetName); + } for (auto a : global::profile->assets) { _assetManager->add(a); } @@ -872,7 +872,7 @@ void OpenSpaceEngine::loadAsset_init(const std::string assetName) { void OpenSpaceEngine::loadAsset_postInit(const std::string assetName) { ZoneScoped - LTRACE("OpenSpaceEngine::loadAsset_init(begin)"); + LTRACE("OpenSpaceEngine::loadAsset_postInit(begin)"); _assetManager->add(assetName); _assetManager->update(); LTRACE("OpenSpaceEngine::loadAsset_postInit(end)"); @@ -1117,24 +1117,17 @@ void OpenSpaceEngine::preSynchronization() { _scheduledAssetPathToLoad.clear(); } else if (!_hasInitializedProfile) { - std::string outputScenePath = absPath("${TEMPORARY}/initAsset.asset").string(); global::profile->ignoreUpdates = true; - global::renderEngine->scene()->createInitialAssetToLoad(*global::profile, - outputScenePath); - loadAsset_init(outputScenePath); + loadAsset_init(""); global::renderEngine->scene()->setFromProfile_properties(*global::profile); global::timeManager->setFromProfile_time(*global::profile); - global::timeManager->setFromProfile_deltaTimes(*global::profile); - 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); + setFromProfile_deltaTimes(*global::profile); + setFromProfile_actions(*global::profile); + setFromProfile_keybindings(*global::profile); + setFromProfile_modules(*global::profile); + setFromProfile_markInterestingNodes(*global::profile); global::profile->ignoreUpdates = false; resetPropertyChangeFlagsOfSubowners(global::rootPropertyOwner); - - _hasInitializedProfile = true; } if (_isFirstRenderingFirstFrame) { @@ -1183,30 +1176,8 @@ void OpenSpaceEngine::preSynchronization() { } if (!_hasInitializedProfile) { - std::string output; - for (const std::string& a : global::profile->additionalScripts) { - global::scriptEngine->queueScript( - a, - scripting::ScriptEngine::RemoteScripting::Yes - ); - } - -/* std::string outputScenePath - = absPath("${TEMPORARY}/combinePostInit.asset").string(); - std::ofstream combinedPostInitAsset(outputScenePath); - std::string profilePostInitAsset = "asset.onInitialize(function()\n"; - profilePostInitAsset += fmt::format( - "{}_{}{}", - global::configuration->profileOutPrefixName, - "_addedScripts", - global::profile->assetFileExtension - ); - profilePostInitAsset += "end)\n"; - combinedPostInitAsset << profilePostInitAsset; - - loadAsset_postInit(outputScenePath); -*/ - + setFromProfile_camera(*global::profile); + setFromProfile_additionalScripts(*global::profile); _hasInitializedProfile = true; } LTRACE("OpenSpaceEngine::preSynchronization(end)"); @@ -1613,6 +1584,144 @@ void OpenSpaceEngine::toggleShutdownMode() { } } +void OpenSpaceEngine::setFromProfile_camera(const Profile& p) { + std::visit( + overloaded{ + [](const Profile::CameraNavState& navStateProfile) { + interaction::NavigationState nav; + nav.anchor = navStateProfile.anchor; + if (navStateProfile.aim.has_value()) { + nav.aim = navStateProfile.aim.value(); + } + if (nav.referenceFrame.empty()) { + nav.referenceFrame = "Root"; + } + nav.position = navStateProfile.position; + if (navStateProfile.up.has_value()) { + nav.up = navStateProfile.up; + } + if (navStateProfile.yaw.has_value()) { + nav.yaw = navStateProfile.yaw.value(); + } + if (navStateProfile.pitch.has_value()) { + nav.pitch = navStateProfile.pitch.value(); + } + global::navigationHandler->setNavigationStateNextFrame(nav); + }, + [](const Profile::CameraGoToGeo& geo) { + std::string geoScript = fmt::format("openspace.globebrowsing.goToGeo" + "([[{}]], {}, {}", geo.anchor, geo.latitude, geo.longitude); + if (geo.altitude.has_value()) { + geoScript += fmt::format(", {}", geo.altitude.value()); + } + geoScript += ")"; + global::scriptEngine->queueScript( + geoScript, + scripting::ScriptEngine::RemoteScripting::Yes + ); + } + }, + p.camera.value() + ); +} + +void OpenSpaceEngine::setFromProfile_deltaTimes(const Profile& p) { + global::timeManager->setDeltaTimeSteps(p.deltaTimes); +} + +void OpenSpaceEngine::setFromProfile_modules(const Profile& p) +{ + for (Profile::Module mod : p.modules) { + const std::vector& m = global::moduleEngine->modules(); + const auto it = std::find_if(m.begin(), m.end(), + [&mod](const OpenSpaceModule* moduleSearch) { + return (moduleSearch->identifier().compare(mod.name) == 0); + }); + if (it != 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 + ); + } + } + } +} + +void OpenSpaceEngine::setFromProfile_actions(const Profile& p) +{ + for (Profile::Action a : p.actions) { + if (a.identifier.empty()) { + LERROR("Identifier must to provided to register action"); + } + if (global::actionManager->hasAction(a.identifier)) { + LERROR(fmt::format("Action for identifier '{}' already existed & registered", + a.identifier)); + } + if (a.script.empty()) { + LERROR(fmt::format("Identifier '{}' doesn't provide a Lua command to execute", + a.identifier)); + } + interaction::Action action; + action.identifier = a.identifier; + action.command = a.script; + if (!a.name.empty()) { + action.name = a.name; + } + if (!a.documentation.empty()) { + action.documentation = a.documentation; + } + if (!a.guiPath.empty()) { + action.guiPath = a.guiPath; + } + action.synchronization = interaction::Action::IsSynchronized(a.isLocal); + global::actionManager->registerAction(std::move(action)); + } +} + +void OpenSpaceEngine::setFromProfile_keybindings(const Profile& p) +{ + for (Profile::Keybinding k : p.keybindings) { + if (k.action.empty()) { + LERROR("Action must not be empty"); + } + if (!global::actionManager->hasAction(k.action)) { + LERROR(fmt::format("Action '{}' does not exist", k.action)); + } + if (k.key.key == openspace::Key::Unknown) { + LERROR(fmt::format("Could not find key '{}'", + std::to_string(static_cast(k.key.key)))); + } + global::keybindingManager->bindKey(k.key.key, k.key.modifier, k.action); + } +} + +void OpenSpaceEngine::setFromProfile_markInterestingNodes(const Profile& p) { + for (std::string nodeName : p.markNodes) { + SceneGraphNode* node = global::renderEngine->scene()->sceneGraphNode(nodeName); + if (node) { + node->addTag("GUI.Interesting"); + } + } +} + +void OpenSpaceEngine::setFromProfile_additionalScripts(const Profile& p) { + for (const std::string& a : p.additionalScripts) { + global::scriptEngine->queueScript( + a, + scripting::ScriptEngine::RemoteScripting::Yes + ); + } +} + scripting::LuaLibrary OpenSpaceEngine::luaLibrary() { return { "", diff --git a/src/interaction/actionmanager.cpp b/src/interaction/actionmanager.cpp index 2b0ef58f09..89a112b0d5 100644 --- a/src/interaction/actionmanager.cpp +++ b/src/interaction/actionmanager.cpp @@ -24,7 +24,6 @@ #include -#include #include #include #include @@ -104,37 +103,6 @@ void ActionManager::triggerAction(const std::string& identifier, } } -void ActionManager::setFromProfile_actions(const Profile& p) -{ - for (Profile::Action a : p.actions) { - if (a.identifier.empty()) { - LERROR("Identifier must to provided to register action"); - } - if (hasAction(a.identifier)) { - LERROR(fmt::format("Action for identifier '{}' already existed & registered", - a.identifier)); - } - if (a.script.empty()) { - LERROR(fmt::format("Identifier '{}' doesn't provide a Lua command to execute", - a.identifier)); - } - interaction::Action action; - action.identifier = a.identifier; - action.command = a.script; - if (!a.name.empty()) { - action.name = a.name; - } - if (!a.documentation.empty()) { - action.documentation = a.documentation; - } - if (!a.guiPath.empty()) { - action.guiPath = a.guiPath; - } - action.synchronization = interaction::Action::IsSynchronized(a.isLocal); - registerAction(std::move(action)); - } -} - scripting::LuaLibrary ActionManager::luaLibrary() { return { "action", diff --git a/src/interaction/keybindingmanager.cpp b/src/interaction/keybindingmanager.cpp index 4299b1180b..29b3418c64 100644 --- a/src/interaction/keybindingmanager.cpp +++ b/src/interaction/keybindingmanager.cpp @@ -142,23 +142,6 @@ std::string KeybindingManager::generateJson() const { return json.str(); } -void KeybindingManager::setFromProfile_keybindings(const Profile& p) -{ - for (Profile::Keybinding k : p.keybindings) { - if (k.action.empty()) { - LERROR("Action must not be empty"); - } - if (!global::actionManager->hasAction(k.action)) { - LERROR(fmt::format("Action '{}' does not exist", k.action)); - } - if (k.key.key == openspace::Key::Unknown) { - LERROR(fmt::format("Could not find key '{}'", - std::to_string(static_cast(k.key.key)))); - } - bindKey(k.key.key, k.key.modifier, k.action); - } -} - scripting::LuaLibrary KeybindingManager::luaLibrary() { return { "", diff --git a/src/navigation/navigationhandler.cpp b/src/navigation/navigationhandler.cpp index 2105021d9e..73d74d4c66 100644 --- a/src/navigation/navigationhandler.cpp +++ b/src/navigation/navigationhandler.cpp @@ -440,48 +440,6 @@ std::vector NavigationHandler::joystickButtonCommand(int button) co return _orbitalNavigator.joystickStates().buttonCommand(button); } -void NavigationHandler::setFromProfile_camera(const Profile& p) { - std::visit( - overloaded { - [this](const Profile::CameraNavState& navStateProfile) { - NavigationState nav; - nav.anchor = navStateProfile.anchor; - if (navStateProfile.aim.has_value()) { - nav.aim = navStateProfile.aim.value(); - } - if (nav.referenceFrame.empty()) { - nav.referenceFrame = "Root"; - } - nav.position = navStateProfile.position; - if (navStateProfile.up.has_value()) { - nav.up = navStateProfile.up; - } - if (navStateProfile.yaw.has_value()) { - nav.yaw = navStateProfile.yaw.value(); - } - if (navStateProfile.pitch.has_value()) { - nav.pitch = navStateProfile.pitch.value(); - } - _pendingNavigationState.reset(); - _pendingNavigationState = std::move(nav); - }, - [this](const Profile::CameraGoToGeo& geo) { - std::string geoScript = fmt::format("openspace.globebrowsing.goToGeo" - "([[{}]], {}, {}", geo.anchor, geo.latitude, geo.longitude); - if (geo.altitude.has_value()) { - geoScript += fmt::format(", {}", geo.altitude.value()); - } - geoScript += ")"; - global::scriptEngine->queueScript( - geoScript, - scripting::ScriptEngine::RemoteScripting::Yes - ); - } - }, - p.camera.value() - ); -} - scripting::LuaLibrary NavigationHandler::luaLibrary() { return { "navigation", diff --git a/src/scene/profile.cpp b/src/scene/profile.cpp index ea2c94cc11..6f6b6c5dd2 100644 --- a/src/scene/profile.cpp +++ b/src/scene/profile.cpp @@ -742,268 +742,6 @@ scripting::LuaLibrary Profile::luaLibrary() { }; } -void convertToSeparatedAssets(const std::string filePre, const Profile& p) { - convertSectionToAssetFile(filePre, p, "meta", convertToAsset_meta); - convertSectionToAssetFile(filePre, p, "addedAssets", convertToAsset_addedAssets); - convertSectionToAssetFile(filePre, p, "modules", convertToAsset_modules); - convertSectionToAssetFile(filePre, p, "actions", convertToAsset_actions); - convertSectionToAssetFile(filePre, p, "keybinds", convertToAsset_keybinds); - convertSectionToAssetFile(filePre, p, "time", convertToAsset_time); - convertSectionToAssetFile(filePre, p, "deltaTimes", convertToAsset_deltaTimes); - convertSectionToAssetFile(filePre, p, "markNodes", convertToAsset_markNodes); - convertSectionToAssetFile(filePre, p, "properties", convertToAsset_properties); - convertSectionToAssetFile(filePre, p, "camera", convertToAsset_camera); - convertSectionToAssetFile(filePre, p, "addedScripts", convertToAsset_addedScripts); -} - -void convertSectionToAssetFile(const std::string profilePrefix, const Profile& p, - const std::string profileSectionName, - std::function func) -{ - std::ofstream converted(fmt::format("{}_{}{}", profilePrefix, - profileSectionName, p.assetFileExtension)); - converted << func(p); -} - -std::string convertToAsset_meta(const Profile& p) { - ZoneScoped - - std::string output; - - if (p.meta.has_value()) { - output += "asset.meta = {\n"; - - if (p.meta->name.has_value()) { - output += fmt::format(" Name = [[{}]],\n", *p.meta->name); - } - if (p.meta->version.has_value()) { - output += fmt::format(" Version = [[{}]],\n", *p.meta->version); - } - if (p.meta->description.has_value()) { - output += fmt::format(" Description = [[{}]],\n", *p.meta->description); - } - if (p.meta->author.has_value()) { - output += fmt::format(" Author = [[{}]],\n", *p.meta->author); - } - if (p.meta->url.has_value()) { - output += fmt::format(" URL = [[{}]],\n", *p.meta->url); - } - if (p.meta->license.has_value()) { - output += fmt::format(" License = [[{}]]\n", *p.meta->license); - } - - output += "}\n\n"; - } - - return output; -} - -std::string convertToAsset_addedAssets(const Profile& p) { - ZoneScoped - - std::string output; - - // Assets - for (const std::string& asset : p.assets) { - output += fmt::format("asset.require(\"{}\");\n", asset); - } - - return output; -} - -std::string convertToAsset_modules(const Profile& p) { - ZoneScoped - - std::string output; - for (const Profile::Module& m : p.modules) { - output += fmt::format( - "if openspace.modules.isLoaded(\"{}\") then {} else {} end\n", - m.name, *m.loadedInstruction, *m.notLoadedInstruction - ); - } - - return output; -} - -std::string convertToAsset_actions(const Profile& p) { - ZoneScoped - - std::string output; - for (const Profile::Action& action : p.actions) { - const std::string name = action.name.empty() ? action.identifier : action.name; - output += fmt::format( - "openspace.action.registerAction({{" - "Identifier=[[{}]], Command=[[{}]], Name=[[{}]], Documentation=[[{}]], " - "GuiPath=[[{}]], IsLocal={}" - "}})\n", - action.identifier, action.script, name, action.documentation, action.guiPath, - action.isLocal ? "true" : "false" - ); - } - - return output; -} - -std::string convertToAsset_keybinds(const Profile& p) { - ZoneScoped - - std::string output; - for (size_t i = 0; i < p.keybindings.size(); ++i) { - const Profile::Keybinding& k = p.keybindings[i]; - const std::string key = keyToString(k.key); - output += fmt::format("openspace.bindKey([[{}]], [[{}]])\n", key, k.action); - } - - return output; -} - -std::string convertToAsset_time(const Profile& p) { - ZoneScoped - - std::string output; - switch (p.time->type) { - case Profile::Time::Type::Absolute: - output += fmt::format("openspace.time.setTime(\"{}\")\n", p.time->value); - break; - case Profile::Time::Type::Relative: - output += "local now = openspace.time.currentWallTime();\n"; - output += fmt::format( - "local prev = openspace.time.advancedTime(now, \"{}\");\n", p.time->value - ); - output += "openspace.time.setTime(prev);\n"; - break; - default: - throw ghoul::MissingCaseException(); - } - - return output; -} - -std::string convertToAsset_deltaTimes(const Profile& p) { - ZoneScoped - - std::string output; - { - std::string times; - for (double d : p.deltaTimes) { - times += fmt::format("{}, ", d); - } - output += fmt::format("openspace.time.setDeltaTimeSteps({{ {} }});\n", times); - } - - return output; -} - -std::string convertToAsset_markNodes(const Profile& p) { - ZoneScoped - - std::string output; - { - std::string nodes; - for (const std::string& n : p.markNodes) { - nodes += fmt::format("[[{}]],", n); - } - output += fmt::format("openspace.markInterestingNodes({{ {} }});\n", nodes); - } - - return output; -} - -std::string convertToAsset_properties(const Profile& p) { - ZoneScoped - - std::string output; - for (const Profile::Property& prop : p.properties) { - switch (prop.setType) { - case Profile::Property::SetType::SetPropertyValue: - output += fmt::format( - "openspace.setPropertyValue(\"{}\", {});\n", prop.name, prop.value - ); - break; - case Profile::Property::SetType::SetPropertyValueSingle: - output += fmt::format( - "openspace.setPropertyValueSingle(\"{}\", {});\n", - prop.name, prop.value - ); - break; - default: - throw ghoul::MissingCaseException(); - } - } - - return output; -} - -std::string convertToAsset_camera(const Profile& p) { - ZoneScoped - - std::string output; - if (p.camera.has_value()) { - output += std::visit( - overloaded { - [](const Profile::CameraNavState& c) { - std::string result; - result += "openspace.navigation.setNavigationState({"; - result += fmt::format("Anchor = [[{}]], ", c.anchor); - if (c.aim.has_value()) { - result += fmt::format("Aim = [[{}]], ", *c.aim); - } - if (!c.referenceFrame.empty()) { - result += fmt::format( - "ReferenceFrame = [[{}]], ", c.referenceFrame - ); - } - result += fmt::format( - "Position = {{ {}, {}, {} }}, ", - c.position.x, c.position.y, c.position.z - ); - if (c.up.has_value()) { - result += fmt::format( - "Up = {{ {}, {}, {} }}, ", c.up->x, c.up->y, c.up->z - ); - } - if (c.yaw.has_value()) { - result += fmt::format("Yaw = {}, ", *c.yaw); - } - if (c.pitch.has_value()) { - result += fmt::format("Pitch = {} ", *c.pitch); - } - result += "})\n"; - return result; - }, - [](const Profile::CameraGoToGeo& c) { - if (c.altitude.has_value()) { - return fmt::format( - "openspace.globebrowsing.goToGeo([[{}]], {}, {}, {});\n", - c.anchor, c.latitude, c.longitude, *c.altitude - ); - } - else { - return fmt::format( - "openspace.globebrowsing.goToGeo([[{}]], {}, {});\n", - c.anchor, c.latitude, c.longitude - ); - } - } - }, - *p.camera - ); - } - - return output; -} - -std::string convertToAsset_addedScripts(const Profile& p) { - ZoneScoped - - std::string output; - for (const std::string& a : p.additionalScripts) { - output += fmt::format("{}\n", a); - } - - return output; -} - std::vector& additionalScripts(Profile& p) { return p.additionalScripts; } diff --git a/src/scene/scene.cpp b/src/scene/scene.cpp index 951d4bf97f..b4503b2ede 100644 --- a/src/scene/scene.cpp +++ b/src/scene/scene.cpp @@ -603,44 +603,6 @@ const std::vector& Scene::interestingTimes() const { return _interestingTimes; } -void Scene::createInitialAssetToLoad(const Profile& p, const std::string& assetFilename) -{ - std::ofstream converted(assetFilename); - std::string output; - //Meta - if (p.meta.has_value()) { - output += "asset.meta = {\n"; - - if (p.meta->name.has_value()) { - output += fmt::format(" Name = [[{}]],\n", *p.meta->name); - } - if (p.meta->version.has_value()) { - output += fmt::format(" Version = [[{}]],\n", *p.meta->version); - } - if (p.meta->description.has_value()) { - output += fmt::format(" Description = [[{}]],\n", *p.meta->description); - } - if (p.meta->author.has_value()) { - output += fmt::format(" Author = [[{}]],\n", *p.meta->author); - } - if (p.meta->url.has_value()) { - output += fmt::format(" URL = [[{}]],\n", *p.meta->url); - } - if (p.meta->license.has_value()) { - output += fmt::format(" License = [[{}]]\n", *p.meta->license); - } - - output += "}\n\n"; - } - - // Assets - for (const std::string& asset : p.assets) { - output += fmt::format("asset.require(\"{}\");\n", asset); - } - - converted << output; -} - void Scene::setFromProfile_properties(const Profile& p) { ghoul::lua::LuaState L(ghoul::lua::LuaState::IncludeStandardLibrary::Yes); @@ -683,21 +645,6 @@ 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 { "", diff --git a/src/scene/scenelicensewriter.cpp b/src/scene/scenelicensewriter.cpp index ef7f4841b9..5067175dac 100644 --- a/src/scene/scenelicensewriter.cpp +++ b/src/scene/scenelicensewriter.cpp @@ -28,6 +28,7 @@ #include #include #include +#include #include #include #include @@ -55,6 +56,7 @@ std::string SceneLicenseWriter::generateJson() const { global::openSpaceEngine->assetManager().rootAsset().subTreeAssets(); int metaTotal = 0; + int metaCount = 0; for (const Asset* asset : assets) { std::optional meta = asset->metaInformation(); if (!meta.has_value()) { @@ -63,7 +65,24 @@ std::string SceneLicenseWriter::generateJson() const { metaTotal++; } - int metaCount = 0; + if (global::profile->meta.has_value()) { + metaTotal++; + constexpr const char* replStr = R"("{}": "{}", )"; + constexpr const char* replStr2 = R"("{}": "{}")"; + json << "{"; + json << fmt::format(replStr, "name", escapedJson(global::profile->meta->name.value())); + json << fmt::format(replStr, "version", escapedJson(global::profile->meta->version.value())); + json << fmt::format(replStr, "description", escapedJson(global::profile->meta->description.value())); + json << fmt::format(replStr, "author", escapedJson(global::profile->meta->author.value())); + json << fmt::format(replStr, "url", escapedJson(global::profile->meta->url.value())); + json << fmt::format(replStr, "license", escapedJson(global::profile->meta->license.value())); + json << "}"; + + if (++metaCount != metaTotal) { + json << ","; + } + } + for (const Asset* asset : assets) { std::optional meta = asset->metaInformation(); diff --git a/src/util/timemanager.cpp b/src/util/timemanager.cpp index bee80c4db2..8fbe3ae004 100644 --- a/src/util/timemanager.cpp +++ b/src/util/timemanager.cpp @@ -879,8 +879,4 @@ void TimeManager::setFromProfile_time(const Profile& p) { } } -void TimeManager::setFromProfile_deltaTimes(const Profile& p) { - global::timeManager->setDeltaTimeSteps(p.deltaTimes); -} - } // namespace openspace