//------------------------------------------------------------
// Tony Hyun Kim
// Spring 2007
// 18.354 Project: Lattice gas
// NODE MANAGER HEADER
//------------------------------------------------------------

#ifndef NODE_MANAGER_H
#define NODE_MANAGER_H

#include "node.h"
#include <vector>
#include <list>
#include <algorithm>

struct SortByX 
{
	bool operator() (const NODE* n1, const NODE* n2)
	{ return n1->pos.x < n2->pos.x; }
};
struct SortByY
{
	bool operator() (const NODE* n1, const NODE* n2)
	{ return n1->pos.y < n2->pos.y; }
};

class NodeManager
{
private:
	vector<NODE*> np_x;
	vector<NODE*> np_y;
	list<NODE>    node_data;

	float		  fTolerance;

	float Distance(const D3DXVECTOR2& v1,const D3DXVECTOR2& v2);
	bool  CloseEnough(float distance);

public:
	NodeManager();

	void AddNode(NODE& n);
	void DelNode(NODE* np);
	void UpdateNode(NODE* np);

	void Tick();
	void ClearAllParticles();
	void RandomlyFillParticles();

	void ReorderNPx(NODE* target);
	void ReorderNPy(NODE* target);

	const list<NODE>& GetNodeData();
	NODE* GetNodeByPos(const D3DXVECTOR2& target);
	
	void NodeFindNeighbors(NODE* np);
	void ConnectAllNeighbors();
};

extern NodeManager myNodes;

#endif