First incomplete implementation of garbage collector in Scene

This commit is contained in:
brunoherbelin
2020-05-05 17:17:29 +02:00
parent 4e2e3bc739
commit 451c793cdd
11 changed files with 202 additions and 101 deletions

View File

@@ -17,6 +17,8 @@
#include <algorithm>
Group *Scene::limbo = new Group;
glm::mat4 transform(glm::vec3 translation, glm::vec3 rotation, glm::vec3 scale)
{
glm::mat4 View = glm::translate(glm::identity<glm::mat4>(), translation);
@@ -179,13 +181,13 @@ void Primitive::deleteGLBuffers_()
// Group
Group::~Group()
{
for(auto it = children_.begin(); it != children_.end(); ) {
for(NodeSet::iterator it = children_.begin(); it != children_.end(); ) {
// this group is not parent of that node anymore
(*it)->parents_.remove(this);
// if this group was the only remaining parent
if ( (*it)->parents_.size() < 1 )
// delete the child
delete (*it);
// put the child in limbo
Scene::limbo->addChild( *it );
// erase this iterator from the list
it = children_.erase(it);
}
@@ -197,6 +199,7 @@ void Group::addChild(Node *child)
child->parents_.push_back(this);
}
void Group::detatchChild(Node *child)
{
NodeSet::iterator it = std::find_if(children_.begin(), children_.end(), hasId(child->id()));
@@ -375,14 +378,31 @@ void Animation::accept(Visitor& v)
v.visit(*this);
}
Scene::Scene()
Scene::Scene(): root_(nullptr)
{
root_ = new Group;
}
Scene::~Scene()
{
delete root_;
deleteNode(root_);
}
void Scene::deleteNode(Node *node)
{
for(auto it = node->parents_.begin(); it != node->parents_.end();){
(*it)->detatchChild(node);
}
limbo->addChild(node);
}
void Scene::update(float dt)
{
root_->update( dt );
// remove nodes from limbo
}
void Scene::accept(Visitor& v)