YoggieEngine/BarinkEngine/Scene.cpp

67 lines
908 B
C++
Raw Normal View History

#include "Scene.h"
#include "Scene/Node.h"
void DeleteSubGraph(Node* tree);
Scene::Scene(std::string sceneName)
{
// Create a root node
root = new Group(sceneName);
root->name = sceneName;
}
Scene::~Scene()
{
// Delete all nodes in the graph.
DeleteSubGraph(root);
}
Node* SearchInChildren(Node* root, std::string name ) {
if (root->name == name)
return root;
Node* found = nullptr;
for (auto child : root->children) {
found = SearchInChildren(child, name);
}
return found;
}
Node& Scene::GetSceneNode(std::string name)
{
return *SearchInChildren(root, name);
}
Node& Scene::GetRoot()
{
return *root;
}
void Node::addChild(Node& node)
{
children.push_back(&node);
}
void DeleteSubGraph(Node* tree)
{
if (tree->children.size() == 0) {
delete tree;
return;
}
for (auto child : tree->children) {
if (child->children.size() > 0) {
DeleteSubGraph(child);
}
}
}