Currently, I'm looking for a decent timer library for a 2D RTS engine that I'm making. I've looked around the internet but haven't found anything. I could use an API specific timer, such as those in DX, OpenGL, or something lesser known such as Grim. But I'd prefer to have seperate libraries for everything, allowing the maximum amount of flexibility when it comes to porting the engine to different APIs for performance comparison. If anyone could recommend a decent timer library for my game, I'd really appreciate it. Thanks for the time.

I'll probably do what you said, max. Wrap a timer library from DX. I would presume it has a high-resolution timer. The reason why I don't use the standard clock in Time.h is I've heard that is has some issues with accuracy.

void CTime::Initialize() // Initialize Our Timer (Get It Ready){// Check To See If A Performance Counter Is Available// If One Is Available The Timer Frequency Will Be Updatedif (!QueryPerformanceFrequency((LARGE_INTEGER *) &frequency)) {// No Performace Counter Available performance_timer = FALSE; // Set Performance Timer To FALSE mm_timer_start = timeGetTime(); // Use timeGetTime() To Get Current Time resolution = 1.0f/1000.0f; // Set Our Timer Resolution To .001f frequency = 1000; // Set Our Timer Frequency To 1000 mm_timer_elapsed = mm_timer_start; // Set The Elapsed Time To The Current Time }else {// Performance Counter Is Available, Use It Instead Of The Multimedia Timer// Get The Current Time And Store It In performance_timer_start QueryPerformanceCounter((LARGE_INTEGER *) &performance_timer_start); performance_timer = TRUE; // Set Performance Timer To TRUE// Calculate The Timer Resolution Using The Timer Frequency resolution = (float) (((double)1.0f)/((double)frequency));// Set The Elapsed Time To The Current Time performance_timer_elapsed = performance_timer_start; }}

float CTime::Get_dt() const{ return dt; }

float CTime::GetTime() const// Get Time In Milliseconds{ __int64 time; // time Will Hold A 64 Bit Integerif (performance_timer) // Are We Using The Performance Timer? { QueryPerformanceCounter((LARGE_INTEGER *) &time); // Grab The Current Performance Time// Return The Current Time Minus The Start Time Multiplied By The Resolution And 1000 (To Get MS)return ( (float) ( time - performance_timer_start) * resolution)*1000.0f; }else {// Return The Current Time Minus The Start Time Multiplied By The Resolution And 1000 (To Get MS)return( (float) ( timeGetTime() - mm_timer_start) * resolution)*1000.0f; }}

To use it, it's very easy:CTime timer;

in your init code:timer.Initialize();

in your update function:timer.Update();

whenever you want to get the elapsed time:timer.GetTime();

whenever you want to get the frame difference timetimer.Get_dt();

It should be bug free - I've had no problems with it [smile]. I just take credit for wrapping it up [lol] - the code is not my original ideas. I believe I had used some ideas from Cone3D, NeHe, and GameTutorials sometime ago.

- Drew

[edit] Also take a look at this page for info on the avaliable timers and why I use the one I did.[/edit]