/****************************/
/*      MISC ROUTINES       */
/* (c)2004 Pangea Software  */
/* By Brian Greenstone      */
/****************************/


/**********************/
/*     CONSTANTS      */
/**********************/

#define		MIN_FPS		10.0			// minimum fps that our physics can handle
#define		MAX_FPS		4000.0			// max fps that our physics can handle (we set this high here just for demo purposes - in a real game limit this to like 120)



/**********************/
/*     VARIABLES      */
/**********************/

Boolean			gAltiVec;
float			gFramesPerSecond;
float			gOneOverFramesPerSecond;


/*********************** DO FATAL ALERT *******************/
//
// Show an alert dialog with the input string, and then quit the app.
//

void DoFatalAlert(Str255 s)
{
SInt16      alertItemHit;

	Enter2D();					// make sure we can see this
	
	StandardAlert(kAlertNoteAlert, s, NULL, NULL, &alertItemHit);

	ExitToShell();
}


/*********************** DO ALERT *******************/
//
// Show an alert dialog with the input string, and then continue on
//

void DoAlert(Str255 s)
{
SInt16      alertItemHit;

	Enter2D();					// make sure we can see this
	
	StandardAlert(kAlertNoteAlert, s, NULL, NULL, &alertItemHit);

	Exit2D();
}

/**************** CALC FRAMES PER SECOND **********************/
//
// Called once per frame to calculate our FPS values.
//

void CalcFramesPerSecond(void)
{
	AbsoluteTime 			currTime,deltaTime;
	static AbsoluteTime 	time = {0,0};
	Nanoseconds			nano;

loop:
			/* GET CURRENT TIMER */

	currTime = UpTime();


		/* GET DELTA FROM PREVIOUS TIME */

	deltaTime 	= SubAbsoluteFromAbsolute(currTime, time);
	nano 		= AbsoluteToNanoseconds(deltaTime);


		/* CONVERT NANOSECONDS TO SECONDS */

	gFramesPerSecond = (float)kSecondScale / (float)nano.lo;


		/* MAKE SURE WE DONŐT GO UNDER THE MINIMUM */

	if (gFramesPerSecond < MIN_FPS)			
		gFramesPerSecond = MIN_FPS;


		/* MAKE SURE WE DONŐT GO OVER THE MAXIMUM */

	if (gFramesPerSecond > MAX_FPS)			
		goto loop;
		

			/* CALC 1.0 / FPS */

	gOneOverFramesPerSecond = 1.0f/gFramesPerSecond;		

	time 		= currTime;			// reset for next time interval
}
