#ifndef DEF_TX_WORLD
 #define DEF_TX_WORLD

//------------------------------------------//
//		TKA4 Main Object Graph classes		//
//				26. 10. 2007				//
//------------------------------------------//


//--- Includes
#include "gl_add.h"

#include "TX_Error.h"
#include "TX_Collision.h"

#include "../GLTools/GLTools.h"
#include "../StrDivider/StrDiv.h"

#include "../LibTexture/libTexture.h"
//=== Includes 


//--- Defines
#define MAX_VIEW_AREA  1000
//=== Defines
	

//--- Collision Map ---//
class txCollisionMap {
public:
	txcSimple *first, *final, *current;

	void AddTXC(txcSimple *new_) {
		new_ -> prev = final;
		final -> next = new_;
		final = new_;
	}

	txCollisionMap() {
		first = new txcSimple(); 
		final = first; 
		current = first;
	};
};


//--- txLight ---//
class txLight {	
public:	
	GLint  number;

	GLfloat  LightPos[4];  // Point source
	GLfloat  Param[4];

	GLfloat  Ambient[4];
	GLfloat  Diffuse[4];
	GLfloat  Specular[4];

public:
	txLight(int num, char* filename) {
		number = num;

		if (filename == STR_NONE || filename == NULL) {
			
			
			LightPos[0]=-100.0f; LightPos[1]=100.0f; LightPos[2]=50.0f; LightPos[3]=1;
			Param[0]=0; Param[1]=0; Param[2]=0; Param[3]=0;
			
			Ambient[0]=0.25f; Ambient[1]=0.25f; Ambient[2]=0.25f; Ambient[3]=1.0f;
			Diffuse[0]=1; Diffuse[1]=1; Diffuse[2]=1; Diffuse[3]=1;
			Specular[0]=1; Specular[1]=1; Specular[2]=1; Specular[3]=1;
		}
	}


	inline void Init() {
		glLightModelfv(GL_LIGHT_MODEL_AMBIENT, Param);

		glLightfv(GL_LIGHT0+number, GL_AMBIENT, Ambient);
		glLightfv(GL_LIGHT0+number, GL_DIFFUSE, Diffuse);
		glLightfv(GL_LIGHT0+number, GL_SPECULAR, Specular);

		glLightfv(GL_LIGHT0, GL_POSITION, LightPos);
	}


	inline void Disable() { glDisable (GL_LIGHT0+number); }
	inline void Enable() { glEnable (GL_LIGHT0+number); }
};



//---  Abstract Class Object TX  ---//
/*	Base for all Graph Objects.	   */
class txWorld {
public: 
	txErrorFile *Log;
	int  Screen_Width, Screen_Height;
	
	long int  World_Time;
	GLTFrame  Camera, CameraOld;

	int  LightCount;
	txLight  *Lights;
	
	GLfloat fog_color[4];

	txCollisionMap Collision;

public:
	txWorld (txErrorFile *log, char *s);
	~txWorld () { delete [] Lights; }

	inline void Init ();
};


//----------------------------------------------------------------

txWorld :: txWorld (txErrorFile *log, char *s)
{ 
	Log = log;
		
	if (GetParamFromStr(s, "CAMERA") == STR_NONE) {
		gltInitFrame(&Camera);
		gltInitFrame(&CameraOld);
		CameraOld.vLocation[1] = 1.5;
		Camera.vLocation[1] = 0.51;

		CameraOld.vLocation[0] = 15.0;
		Camera.vLocation[0] = 15.0;
	}
		
	if (GetParamFromStr(s, "WORLD_TIME") == STR_NONE) {
		World_Time = 0;
	}

	if (GetParamFromStr(s, "FOG") == STR_NONE) {
		
		fog_color[0] = 0.0;
		fog_color[1] = 0.0;
		fog_color[2] = 0.0;
		fog_color[3] = 1;
	}


	LightCount = 1;
	Lights = new txLight(0, GetParamFromStr(s, "LIGHT0"));
};


//--- txWorld Init ---
void txWorld :: Init()
{
	for (int i = 0; i<LightCount; i++) {
		Lights[i].Init();
		Lights[i].Enable();
	}

}


#endif