#include <GameOS\GameOS.hpp>
#include <GameOS\ToolOS.hpp>
#include <GOSScript\GOSScriptHeaders.hpp>
#include "SampleClass.hpp"

#include <string.h>

mySample * sample[3] = {0,0,0};

char * yourMom = 0;
HGOSSCRIPT hHandle;
int passThis = 0;
char * holo = NULL;

int __stdcall TestCallback(void * instance, int, void *[16]);
												  
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//
void __stdcall InitializeGameEngine()
{
	//
	//---------------------------
	// Start the Script Processor
	//---------------------------
	//
//	char * str = gos_DescribeKey(' ');

	gosScript_InitializeProcessor();

	holo = (char *) gos_Malloc(32);
	strcpy(holo, "holo.avi");

	gosScript_RegisterVariable("holo",&holo,GOSVAR_STRING,0,0);
	gosScript_RegisterVariable("yourMom",&yourMom,GOSVAR_STRING,0,0);
	gosScript_RegisterCallback("TestCallback",TestCallback,GOSVAR_INT,0,0);
	hHandle = gosScript_ExecuteScript("Assets\\Scripts\\TestSuite.script",0x1000,0);


	sample[0] = new mySample(320-48,400-16,0xff0000ff);
	sample[1] = new mySample(320-16,400-16,0x00ff00ff);
	sample[2] = new mySample(320+16,400-16,0x0000ffff);

}

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//
void __stdcall DoGameLogic()
{
	if (passThis > 32) 
		gosScript_Command(hHandle,"O_COLORpicker", gosScript_Cmd_MAILBOX, &passThis);
	passThis++;
}

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//
void __stdcall SkunkworksUpdateDisplay()
{
//
// Just clear the display 
//	
//	NO!!!!
//
//	gos_SetupViewport( 0,1.0,0,Color,0.0,0.0,1.0,1.0 );
}

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//
void __stdcall TerminateGameEngine()
{
	gosScript_UnregisterAll(NULL);
	//
	//--------------------------
	// Stop the Script Processor
	//--------------------------
	//

	gosScript_EndScript(hHandle);

	if (holo)
	{
		gos_Free(holo);
		holo = 0;
	}

	if (yourMom)
	{
		gos_Free(yourMom);
		yourMom = 0;
	}

	if (sample[0])
	{
		delete sample[0];
		sample[0] = 0;
	}
	if (sample[1])
	{
		delete sample[1];
		sample[1] = 0;
	}
	if (sample[2])
	{
		delete sample[2];
		sample[2] = 0;
	}

	gosScript_ShutdownProcessor();

}
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//
void _stdcall GetGameOSEnvironment(char* CommandLine)
{
	CommandLine = CommandLine;
	Environment.applicationName			= "Test Scripts";
	Environment.screenWidth				= 640;
	Environment.screenHeight			= 480;
	Environment.fullScreen				= 0;
	Environment.bitDepth				= 16;
	Environment.debugLog				= "";
	Environment.spew					= "";
	Environment.memoryTraceLevel		= 5;
	Environment.TimeStampSpew			= 0;
	Environment.UpdateRenderers			= SkunkworksUpdateDisplay;
	Environment.DoGameLogic				= DoGameLogic;
	Environment.InitializeGameEngine	= InitializeGameEngine;
	Environment.TerminateGameEngine		= TerminateGameEngine;
	Environment.soundChannels			= 16;

	Environment.FullScreenDevice		= 0;
	Environment.AntiAlias				= 0;			// true/false - Enable full screen antialiasing
	Environment.Renderer				= 0;

	Environment.MinimumTextureMemory	= 5*1024;
	Environment.MegMemoryRequired		= 256;

	//Raid
	Environment.RaidCustomFields		= "AssignedTo=jreicher;Project=gosScript;Client=GameOS;GOSRaid=Yes"; 
	Environment.RaidDataSource			= "GameTech :Raid4";
	Environment.RaidFilePath			= "\\\\aas1\\coretech\\Test\\Raid\\Exceptions";
}

int __stdcall TestCallback(void * ,int ,void *[16])
{
	int poo = 1;
	return poo;
}


