#ifndef QUADINDEX_H
#define QUADINDEX_H

//#include "Quad.h"
#include "Vector3i.h"
#include "Vertex.h"
//#include "OgreVector3.h"
#include <deque>

using namespace std;

namespace Ogre {


class QuadIndex{
private:
	int size, depth;
	Vertex*** vertexTree;
	bool** vertexLoaded;
	
	bool isVertexInMemory(int x, int y, int level);
	void setVertexInMemory(int x, int y, int level);
	void setVertexOutMemory(int x, int y, int level);
	void loadVertexFromDisk(int x, int y, int level);
	int getVertexPosition(int x, int y, int level);

	void freemem();
	bool unloadVertex(int x, int y, int level);
	Vertex* readVertex(int x, int y, int level);	
	
	deque <Vector3i*> bufferQueue;
	
	FILE* file;
	
	int levelHeaderSize, vertexSize;
	
public:

	void setClipmapFile(FILE* clipmapFile);
	void setLevelHeaderSize(int levelHeaderSize);
	void setVertexSize(int vertexSize);
	QuadIndex(int size);
	~QuadIndex();
	
//	Vertex* getVertex(int x, int y, int level);
	int getLevelSize(int level);
	int getLevelWidth(int level);
	int getLevelHeight(int level);
	int getDepth();
	int getLevelQuadSize(int level);
	void setVertex(int x, int y, int level, Vertex* quad);
	
	Vertex* getVertexObject(int x, int y, int level);
	Vector3 getVertex(int x, int y, int level);
	Vector3 getNormal(int x, int y, int level);
	//Quad getQuad(int x, int y, int level);
};


}
#endif // QUADINDEX_H

