/******************************************************************************************
	AM2 PS   (c) 1999-2001 ISL

	timer.h:		Debug timing functions
******************************************************************************************/

#ifndef _TIMER_H_
#define _TIMER_H_

enum {
	TIMER_TOTAL,
	TIMER_TIMERS,

	TIMER_CYCLE,
	TIMER_ALLDRAW,
	TIMER_ALLOTHER,

//	TIMER_SKYREND,
	TIMER_MAPREND,
	TIMER_PSIREND,
//	TIMER_PSI_CWM,
//	TIMER_PSI_SEK,

	TIMER_ROUTE,
	TIMER_SHADOW,

	TIMER_NME,
	TIMER_CAM,

	TIMER_TEMPTEST,
	TIMER_DUMMY,

	TIMER_DRAWSYNC,
	TIMER_NUMTIMERS
};

//	TIMER_DOG,
//	TIMER_MRT,

#define TIMER_PSI_CWM		TIMER_DUMMY
#define TIMER_PSI_SEK		TIMER_DUMMY
#define TIMER_MRT			TIMER_DUMMY
#define TIMER_DOG			TIMER_DUMMY
#define TIMER_SKYREND		TIMER_DUMMY

#define TIMER_NAMES	   	"TOTAL", \
					   	"TIMERS", \
						"ALL Cycle", \
						"ALL Draw", \
						"ALL Other", \
						"Map_REN", \
						"Psi_REN", \
						"Route", \
						"Shadow(s)", \
						"NME Cyc\n", \
						"Camera\n", \
						"Temp Test\n",\
						"(Dummy)\n", \
					   	"DrawSync"


//						"NME MrT\n", \
//						"NME Dog\n", \

extern char	timerActive;
extern char	*timerName[TIMER_NUMTIMERS];
extern int	globalTimer[TIMER_NUMTIMERS];
extern int 	activeTimer[TIMER_NUMTIMERS];
extern int	prevTimer[TIMER_NUMTIMERS];

/**************************************************************************
	FUNCTION:	TIMER_START()
	PURPOSE:	Start timing
	PARAMETERS:	Timer number
	RETURNS:	
**************************************************************************/

// timers now support multiple start/stops per frame

#define TIMER_START(n)		{activeTimer[n] = VSync(1);}


/**************************************************************************
	FUNCTION:	TIMER_STOP()
	PURPOSE:	Stop timing
	PARAMETERS:	Timer number
	RETURNS:	
**************************************************************************/

#define TIMER_STOP(n)		{globalTimer[n] += VSync(1)-activeTimer[n]; activeTimer[n] = 0; }


/**************************************************************************
	FUNCTION:	TIMER_ENDFRAME()
	PURPOSE:	Start timing
	PARAMETERS:	Timer number
	RETURNS:	
**************************************************************************/

//#define TIMER_ENDFRAME		memcpy(prevTimer, globalTimer, sizeof(globalTimer))
#define TIMER_ENDFRAME		{	memcpy(prevTimer, globalTimer, sizeof(globalTimer)); \
								memset(globalTimer, 0, sizeof(globalTimer)); \
								memset(activeTimer, 0, sizeof(activeTimer)); \
							}


/**************************************************************************
	FUNCTION:	timerDisplay()
	PURPOSE:	Display timer readings if enabled
	PARAMETERS:	
	RETURNS:	
**************************************************************************/

void timerDisplay();


#endif
