Hi Res Timer for BlitzMax

BlitzMax Forums/BlitzMax Programming/Hi Res Timer for BlitzMax

monotonic(Posted 2008) [#1]
Hi,

Does anybody know if there is a Hi Res Timer for BlitzMax. I have found some C++ code in the NewtonSDK for one but, it uses glutget to query the graphics hardware. I don't know how to do this in BMax.


The C++ code snippet for the timer (Note: this is taken from a class so variables declarations etc are in the header).
	dFloat timeStep;
	unsigned miliseconds;



	
	miliseconds = glutGet (GLUT_ELAPSED_TIME);

	// optimal keep the fps below 70 fps
	#ifdef LOCK_FRAME_RATE
	while ((miliseconds - m_prevTime) < 14) {
		miliseconds = glutGet (GLUT_ELAPSED_TIME);
	}
	#endif

	timeStep = dFloat (miliseconds - m_prevTime) * TICKS2SEC;
	m_prevTime = miliseconds;
	
	if (timeStep > 0.1f) {
		timeStep = 0.1f;
	}
	if (timeStep < 0.005f) {
		timeStep = 0.005f;
	}


#ifdef RECORD_LOG
//	Sleep (100);
	extern FILE * file;
	fwrite (&timeStep, sizeof (float), 1, file);
	fflush (file);
#endif

#ifdef READ_LOG
	extern FILE * file;
	//Sleep (150);
	fread (&timeStep, sizeof (float), 1, file);
#endif

	
	return timeStep;

Any help would be greatly appreciated.


tonyg(Posted 2008) [#2]
There's High Resolution Timer Module in Code Archives. Seems like something that might be useful.


monotonic(Posted 2008) [#3]
Thats perfect, thank you.