#include "pw/scene/traverser.hpp"
#include "pw/scene/node.hpp"

#include <stack>
#include <iostream>
#include <queue>

namespace pw {

traverser t = traverser();

void traverser::visit(node *node)
{
	// enter node
	on_enter(node);
	// visit
	if (direction::up == _direction)
		this->visit(node->parent());
	else
		for (auto c : node->children()) this->visit(c.get());

	//leave node
	on_leave(node);
}

void traverser::bfs(node::ref root)
{
	std::stack<node::ref> q;
	q.push(root);

	node::ref_array leafs;

	while (!q.empty())
	{
		// get the top
		node::ref n = q.top();
		// remove from stack
		q.pop();

//		std::cout << "d:" << q.size() << " l:" << n->is_leaf() << " n:" << n->name();

		// add all children
		for(auto c : n->children()) q.push(c);

//		std::cout << std::endl;
	}

}

}
