2022-05-28 19:19:16 +00:00
|
|
|
#include "Scene.h"
|
2022-07-09 20:21:56 +00:00
|
|
|
#include "Scene.h"
|
2022-07-09 19:22:50 +00:00
|
|
|
#include "Scene/Node.h"
|
2022-07-08 19:35:14 +00:00
|
|
|
void DeleteSubGraph(Node* tree);
|
2022-05-28 19:19:16 +00:00
|
|
|
|
2022-07-09 20:21:56 +00:00
|
|
|
Scene::Scene(const std::string& sceneName)
|
2022-07-08 19:35:14 +00:00
|
|
|
{
|
|
|
|
// Create a root node
|
2022-07-09 19:22:50 +00:00
|
|
|
root = new Group(sceneName);
|
2022-07-08 19:35:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Scene::~Scene()
|
|
|
|
{
|
|
|
|
// Delete all nodes in the graph.
|
|
|
|
DeleteSubGraph(root);
|
|
|
|
|
|
|
|
}
|
2022-05-28 19:19:16 +00:00
|
|
|
|
2022-07-08 19:35:14 +00:00
|
|
|
|
2022-07-09 20:21:56 +00:00
|
|
|
Node* SearchInChildren(Node* root, const std::string name ) {
|
2022-05-28 19:19:16 +00:00
|
|
|
|
|
|
|
if (root->name == name)
|
|
|
|
return root;
|
|
|
|
|
2022-07-08 19:35:14 +00:00
|
|
|
Node* found = nullptr;
|
2022-05-28 19:19:16 +00:00
|
|
|
for (auto child : root->children) {
|
|
|
|
found = SearchInChildren(child, name);
|
|
|
|
}
|
|
|
|
return found;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-07-08 19:35:14 +00:00
|
|
|
Node& Scene::GetSceneNode(std::string name)
|
2022-05-28 19:19:16 +00:00
|
|
|
{
|
|
|
|
return *SearchInChildren(root, name);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2022-07-08 19:35:14 +00:00
|
|
|
Node& Scene::GetRoot()
|
2022-05-28 19:19:16 +00:00
|
|
|
{
|
|
|
|
return *root;
|
|
|
|
}
|
|
|
|
|
2022-07-09 19:22:50 +00:00
|
|
|
|
|
|
|
|
2022-07-08 19:35:14 +00:00
|
|
|
void Node::addChild(Node& node)
|
2022-05-28 19:19:16 +00:00
|
|
|
{
|
2022-07-08 19:35:14 +00:00
|
|
|
children.push_back(&node);
|
2022-05-28 19:19:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-07-08 19:35:14 +00:00
|
|
|
void DeleteSubGraph(Node* tree)
|
2022-05-28 19:19:16 +00:00
|
|
|
{
|
2022-07-08 19:35:14 +00:00
|
|
|
if (tree->children.size() == 0) {
|
|
|
|
delete tree;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (auto child : tree->children) {
|
|
|
|
if (child->children.size() > 0) {
|
|
|
|
DeleteSubGraph(child);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|