![]() |
| [[ Home | Forums | 3D Engines Database | Wiki | Articles/Tutorials | Game Dev Jobs | IRC Chat Network | Contact Us ]] |
|
|
#1 |
|
New Member
Join Date: May 2004
Posts: 17
|
The following code is for a cross platform accurate timer. This timer also has the ability to calculate FPS if you so desire. For windows you can use either SDL_GetTicks() for a timer or QueryPerformanceCounter(), this of course requires SDL to be used.
Timer.h Code:
Timer.cpp Code:
Hope you enjoy, I look forward to any questions or comments. |
|
|
|
|
|
#2 |
|
DevMaster Staff
Join Date: Jan 2003
Posts: 1,201
|
Nice piece of code. One comment: since you're already doing a check on platform used, you might as well use the appropriate timer function in each platform in order to remove the dependency on SDL. It's not a big issue though
![]() |
|
|
|
|
|
#3 |
|
DevMaster Staff
Join Date: Jan 2003
Location: Mars
Posts: 1,141
|
maybe I'm missing something, but why not just use SDL on both platforms? that removes a lot of the ugly preprocessor code.
___________________________________________
baldurk He who knows not and knows that he knows not is ignorant. Teach him. He who knows not and knows not that he knows not is a fool. Shun him. |
|
|
|
|
|
#4 |
|
DevMaster Staff
Join Date: Apr 2003
Location: Germany
Posts: 2,328
|
using accurate and QPC in one sentence is kind of... well you know
___________________________________________
If Prolog is the answer, what is the question ? |
|
|
|
|
|
#5 |
|
Member
Join Date: Apr 2004
Posts: 48
|
What about a counter that doesn't use SDL? What does SDL do to time on Linux, etc.?
___________________________________________
- FYHuang "Do, or do not. There is no 'try'." - Yoda "Shoot Pixels not People" - Drakonite [<a href='http://www.hytetech.com/altitude/forums/' target='_blank'>Altitude Forums</a>][<a href='http://www.hytetech.com/altitude/' target='_blank'>Altitude Technologies</a>] |
|
|
|
|
|
#6 | |
|
DevMaster Staff
Join Date: Jan 2003
Location: Mars
Posts: 1,141
|
Quote:
gettimeofday() I'd imagine. As close to microsecond accuracy as a processor clock will allow.
___________________________________________
baldurk He who knows not and knows that he knows not is ignorant. Teach him. He who knows not and knows not that he knows not is a fool. Shun him. |
|
|
|
|
|
|
#7 |
|
New Member
Join Date: Sep 2004
Location: Heidelberg, Old Europe
Posts: 23
|
I hope you know that QueryPerformanceCounter is FAR from accurate ?
It's one of the most unpredictable functions you could have used. I strongly recommend changing that code to use timeGetTime (). timeGetTime () guarantees a 1ms resolution on XP/2000 and 5ms on 98/ME/NT. QueryPerformanceCounter () went as bad as using the 18.2 Hz AT timer on one of my machines. On my current Athlon XP 3000+ it has a resolution of approximately 3.5 MHz (according to QueryPerformanceFrequency) and I heard of a P4 2.2 GHz user who reported something like 1.17 GHz over at flipcode. Strange numbers, those, and he reported other strange effects, too. |
|
|
|
![]() |
| Thread Tools | Search this Thread |
| Display Modes | |
|