diff --git a/include/openspace/engine/openspaceengine.h b/include/openspace/engine/openspaceengine.h index 552b2e895b..6e94d69a3c 100644 --- a/include/openspace/engine/openspaceengine.h +++ b/include/openspace/engine/openspaceengine.h @@ -178,22 +178,22 @@ private: // Components std::unique_ptr _configurationManager; - std::unique_ptr _interactionHandler; - std::unique_ptr _renderEngine; std::unique_ptr _sceneManager; - std::unique_ptr _scriptEngine; - std::unique_ptr _scriptScheduler; - std::unique_ptr _networkEngine; - std::unique_ptr _syncEngine; - std::unique_ptr _commandlineParser; std::unique_ptr _downloadManager; std::unique_ptr _console; std::unique_ptr _moduleEngine; + std::unique_ptr _networkEngine; std::unique_ptr _parallelConnection; + std::unique_ptr _renderEngine; std::unique_ptr _settingsEngine; + std::unique_ptr _syncEngine; std::unique_ptr _timeManager; std::unique_ptr _windowWrapper; + std::unique_ptr _commandlineParser; std::unique_ptr _fontManager; + std::unique_ptr _interactionHandler; + std::unique_ptr _scriptEngine; + std::unique_ptr _scriptScheduler; // Others std::unique_ptr _globalPropertyNamespace; diff --git a/include/openspace/scene/scene.h b/include/openspace/scene/scene.h index b397e921be..a0d53a53a1 100644 --- a/include/openspace/scene/scene.h +++ b/include/openspace/scene/scene.h @@ -68,18 +68,17 @@ public: */ void initialize(); - /* + /** * Load the scenegraph from the provided folder */ - //void scheduleLoadSceneFile(const std::string& sceneDescriptionFilePath); void clear(); - /* + /** * Set the root node of the scene */ void setRoot(std::unique_ptr root); - /* + /** * Set the root node of the scene */ void setCamera(std::unique_ptr camera); @@ -88,45 +87,61 @@ public: * Return the camera */ Camera* camera() const; - - /* + + /** * Updates all SceneGraphNodes relative positions */ void update(const UpdateData& data); - /* - * Evaluates if the SceneGraphNodes are visible to the provided camera + /** + * Evaluate if the SceneGraphNodes are visible to the provided camera. */ void evaluate(Camera* camera); - /* - * Render visible SceneGraphNodes using the provided camera + /** + * Render visible SceneGraphNodes using the provided camera. */ void render(const RenderData& data, RendererTasks& tasks); - /* - * Returns the root SceneGraphNode + /** + * Return the root SceneGraphNode. */ SceneGraphNode* root() const; /** * Return the scenegraph node with the specified name or nullptr if that - * name does not exist + * name does not exist. */ SceneGraphNode* sceneGraphNode(const std::string& name) const; + /** + * Add a node and all its children to the scene. + */ void addNode(SceneGraphNode* node, UpdateDependencies updateDeps = UpdateDependencies::Yes); + /** + * Remove a node and all its children from the scene. + */ void removeNode(SceneGraphNode* node, UpdateDependencies updateDeps = UpdateDependencies::Yes); + /** + * Update dependencies. + */ void updateDependencies(); - void sortTopologically(); - + /** + * Return a vector of all scene graph nodes in the scene. + */ const std::vector& allSceneGraphNodes() const; + /** + * Return a a map from name to scene graph node. + */ const std::map& nodesByName() const; + /** + * Output property documentation to a file. + */ void writePropertyDocumentation(const std::string& filename, const std::string& type, const std::string& sceneFilename); /** @@ -142,6 +157,8 @@ public: static documentation::Documentation Documentation(); private: + void sortTopologically(); + std::unique_ptr _root; std::unique_ptr _camera; std::vector _topologicallySortedNodes; diff --git a/include/openspace/scene/scenegraphnode.h b/include/openspace/scene/scenegraphnode.h index b13a6161e7..58a1c5a99b 100644 --- a/include/openspace/scene/scenegraphnode.h +++ b/include/openspace/scene/scenegraphnode.h @@ -81,7 +81,6 @@ public: std::unique_ptr detachChild(SceneGraphNode& child, UpdateScene updateScene = UpdateScene::Yes); void setParent(SceneGraphNode& parent, UpdateScene updateScene = UpdateScene::Yes); - void addDependency(SceneGraphNode& dependency, UpdateScene updateScene = UpdateScene::Yes); void removeDependency(SceneGraphNode& dependency, UpdateScene updateScene = UpdateScene::Yes); void clearDependencies(UpdateScene updateScene = UpdateScene::Yes); diff --git a/include/openspace/scene/scenemanager.h b/include/openspace/scene/scenemanager.h index 1045994066..426a6cb3ea 100644 --- a/include/openspace/scene/scenemanager.h +++ b/include/openspace/scene/scenemanager.h @@ -38,6 +38,7 @@ public: ~SceneManager() = default; Scene* loadScene(const std::string& path); void unloadScene(Scene& scene); + void unloadAll(); private: std::vector> _scenes; }; diff --git a/src/engine/openspaceengine.cpp b/src/engine/openspaceengine.cpp index 6bb43921cb..43d3389a5d 100644 --- a/src/engine/openspaceengine.cpp +++ b/src/engine/openspaceengine.cpp @@ -381,11 +381,14 @@ void OpenSpaceEngine::destroy() { _engine->_console->deinitialize(); _engine->_scriptEngine->deinitialize(); + _engine->_sceneManager->unloadAll(); + delete _engine; FactoryManager::deinitialize(); Time::deinitialize(); SpiceManager::deinitialize(); + ghoul::fontrendering::FontRenderer::deinitialize(); LogManager::deinitialize(); diff --git a/src/scene/scene.cpp b/src/scene/scene.cpp index d890576195..3f5ea4ddea 100644 --- a/src/scene/scene.cpp +++ b/src/scene/scene.cpp @@ -117,9 +117,12 @@ void Scene::addNode(SceneGraphNode* node, Scene::UpdateDependencies updateDeps) void Scene::removeNode(SceneGraphNode* node, Scene::UpdateDependencies updateDeps) { // Remove the node and all its children. - node->traversePostOrder([this](SceneGraphNode* n) { - _topologicallySortedNodes.erase(std::remove(_topologicallySortedNodes.begin(), _topologicallySortedNodes.end(), n), _topologicallySortedNodes.end()); - _nodesByName.erase(n->name()); + node->traversePostOrder([this](SceneGraphNode* node) { + _topologicallySortedNodes.erase( + std::remove(_topologicallySortedNodes.begin(), _topologicallySortedNodes.end(), node), + _topologicallySortedNodes.end() + ); + _nodesByName.erase(node->name()); }); if (updateDeps) { diff --git a/src/scene/scenegraphnode.cpp b/src/scene/scenegraphnode.cpp index 56fdcacf17..2ea7e44c88 100644 --- a/src/scene/scenegraphnode.cpp +++ b/src/scene/scenegraphnode.cpp @@ -367,15 +367,6 @@ void SceneGraphNode::render(const RenderData& data, RendererTasks& tasks) { // child->render(newData); } - -// not used anymore @AA -//void SceneGraphNode::addNode(SceneGraphNode* child) -//{ -// // add a child node and set this node to be the parent -// child->setParent(this); -// _children.push_back(child); -//} - void SceneGraphNode::setParent(SceneGraphNode& parent, UpdateScene updateScene) { ghoul_assert(_parent != nullptr, "Node must be attached to a parent"); ghoul_assert( diff --git a/src/scene/sceneloader.cpp b/src/scene/sceneloader.cpp index ebda2dba7e..06c2a1fbd6 100644 --- a/src/scene/sceneloader.cpp +++ b/src/scene/sceneloader.cpp @@ -306,7 +306,6 @@ std::vector SceneLoader::addLoadedNodes(Scene& scene, std::vect return static_cast(nullptr); }; - std::vector attachedBranches; std::vector> badNodes; @@ -348,11 +347,6 @@ std::vector SceneLoader::addLoadedNodes(Scene& scene, std::vect } } - // Add the nodes to the scene. - for (auto& node : attachedBranches) { - scene.addNode(node, Scene::UpdateDependencies::No); - } - // Remove all bad nodes (parent or deps missing) and all their children and dependent nodes. // Use unsorted set `visited` to avoid infinite loop in case of circular deps. std::unordered_set visited; @@ -378,14 +372,21 @@ std::vector SceneLoader::addLoadedNodes(Scene& scene, std::vect LWARNING("Node '" << node.first << "' is not connected to the root and will not be added to the scene"); } } + + // Add the nodes to the scene. + for (auto& node : attachedBranches) { + scene.addNode(node, Scene::UpdateDependencies::No); + } + // Update dependencies: sort nodes topologically. scene.updateDependencies(); // Return a vector of all added nodes. std::vector addedNodesVector; - for (auto& it : addedNodes) { - addedNodesVector.push_back(it.second); - } + std::transform(addedNodes.begin(), addedNodes.end(), std::back_inserter(addedNodesVector), [] (auto& pair) { + return pair.second; + }); + return addedNodesVector; } } diff --git a/src/scene/scenemanager.cpp b/src/scene/scenemanager.cpp index 14ff89754c..943f2ae55c 100644 --- a/src/scene/scenemanager.cpp +++ b/src/scene/scenemanager.cpp @@ -45,4 +45,8 @@ void SceneManager::unloadScene(Scene& scene) { return s.get() == &scene; }); } + +void SceneManager::unloadAll() { + _scenes.clear(); +} }