#include "tpApi.H"
#include <Nindows.h>
#define NUM 4

#include "shinobi.h"
#include "sg_gd.h"


NJS_TEXMEMLIST	tex[100];

NJS_VIEW	view;
NJS_LIGHT	light;

/* setting textures */
NJS_TEXINFO	info;
NJS_TEXNAME texname[NUM];
NJS_TEXLIST texlist = {texname,1};

MovieStruct movie1;

void Counter(void)
{
	sdSysServer();

	tpVSyncHandler(&movie1);
}


void njUserInit(void)
{
	sbInitSystem( NJD_RESOLUTION_640x480_NTSCNI, NJD_FRAMEBUFFER_MODE_RGB555, 1 );
	/*sbInitSystem( NJD_RESOLUTION_VGA, NJD_FRAMEBUFFER_MODE_RGB555, 1 );*/

		/* get a list of movie names */
	if (!getMovieList(".")) /* try current directory */
		getMovieList("MOVIE"); /* try directory named "MOVIE" */

	njInitVertexBuffer( 200000, 0, 10000, 0, 10000 );
	njInitTexture( tex,100);

	SoundInitialize( "MANATEE.DRV", "STREAM.MLT" ); /* located in sbinit.c */

	njSetBackColor(0x000000FF,0x000000FF,0x00000000);
	njSetVSyncFunction(Counter);

	njInitView( &view );
	njCreateLight( &light, NJD_PHONG_DIR );
	njSetLightIntensity( &light, 1.5f, 1.0f, 0.7f );
	njSetLightAngle( &light, NJM_RAD_ANG(NJD_PI / 30.f), NJM_RAD_ANG(NJD_PI / 4.f) );
	njSetLightDirection( &light, 0, 0.707f, -0.707f );
	njSetView( &view );

	/* setting memory textures */
	njSetTextureInfo(&info,(void *)NULL,NJD_TEXFMT_YUV_422|NJD_TEXFMT_STRIDE,1024,512);	
	njSetTextureName(&texname[0],&info,0,NJD_TEXATTR_TYPE_MEMORY|NJD_TEXATTR_GLOBALINDEX);

	njLoadTexture( &texlist );
	njSetTexture( &texlist );


}

Sint32 njUserMain(void)
{
	extern PLAYER_STATUS_CODE tp_setupDisplay(MovieHandle movie);
	extern PLAYER_STATUS_CODE tp_setupAudioDriver(MovieHandle movie);

	char *nextMovie(void);

	pdExecPeripheralServer();

	tp_MovieStructInit(&movie1, tp_setupDisplay,tp_setupAudioDriver);

	strcpy(movie1.fileName,nextMovie());
	movie1.HFB_bufferSize = 512*1024;

	tp_MovieInitAndPlay(&movie1);


	return NJD_USER_CONTINUE;

}

void njUserExit(void)
{
	sbExitSystem();

#if 0
    njExitTexture();
	njExitSystem();
#endif
}

