
#include <WFX/scene/ListSceneGraph.h>

using namespace WFX;
using namespace WFX::renderer;
using namespace WFX::scene;
using namespace std;

ListSceneGraph::~ListSceneGraph() {
    LOG("ListSceneGraph::destroy()");
    std::list<AbstractNode*>::iterator it;
    for (it = Nodes.begin(); it!=Nodes.end(); it++) {
        if (*(it) != NULL)
            delete *(it);
    }
}

void ListSceneGraph::update() {
    //iterate over all nodes and update them
    list<AbstractNode*>::iterator it;
    for (it=Nodes.begin();it!=Nodes.end();it++) {
        (*it)->updateDown();
    }
}

void ListSceneGraph::render(WFX::renderer::Renderer* r) {
    SceneGraph::render(r);

    //iterate over all nodes and render them
    list<AbstractNode*>::iterator it;
    for (it=Nodes.begin();it!=Nodes.end();it++) {
        (*it)->onDraw(r);
    }

}

void ListSceneGraph::accept(SceneGraphVisitor& v) {
    //iterate over all nodes and call accept
    list<AbstractNode*>::iterator it;
    for (it=Nodes.begin();it!=Nodes.end();it++) {
        (*it)->accept(v);
    }
}

