Framerate issues
How can i calculate the framerate ? I mean, I know the way NeHe does, but I use the framerate for other things (like calculating the speed of an entity) and I need it very precise and refreshed every frame. I used GetTickCount, but the framerate is incorrect (I get bad movement from entities, console etc). What should I do ???
PS: The way I do it:
tm2 := gettickcount;
fps_count := 1000 / (tm2 - tm1);
tm1 := tm2;
in the main message loop, before scene is drawn.
-------------------------
Neo Software Group Pitesti 2004
Vasi Vîlvoiu
-------------------------Neo Software Group Pitesti 2004Vasi Vîlvoiu
I dont know the language you''re using but if it is possible convert the integers to doubles (or floats). You might want to do something like this:
tm2 := gettickcount;
double tmp=tm2-tm1; // A double precision floating point variable
tmp=1000/tmp; // Calculate framerate in double precision float (more precise)
fps_count := tmp; // If you make fps_count a double too, this will make your calculations more precise
tm1 := tm2;
Actually if it is about physics, movement and effects (and all other time based techniques) you should use floating point or double.
If it is impossible in that language ignore this post :].
tm2 := gettickcount;
double tmp=tm2-tm1; // A double precision floating point variable
tmp=1000/tmp; // Calculate framerate in double precision float (more precise)
fps_count := tmp; // If you make fps_count a double too, this will make your calculations more precise
tm1 := tm2;
Actually if it is about physics, movement and effects (and all other time based techniques) you should use floating point or double.
If it is impossible in that language ignore this post :].
GetTickCount() sucks.
(Assuming Win32...) Look at { timeBeginPeriod(1), timeGetTime(), timeEndPeriod(1) }, and { QueryPerformanceFrequency(), QueryPerformanceCounter() }. They''re typically much more accurate. There are probably other timers as well, but these are the ones I see the most often, and have performed well for me.
int Agony() { return *((int*)0); } Mwahaha... >8)
(Assuming Win32...) Look at { timeBeginPeriod(1), timeGetTime(), timeEndPeriod(1) }, and { QueryPerformanceFrequency(), QueryPerformanceCounter() }. They''re typically much more accurate. There are probably other timers as well, but these are the ones I see the most often, and have performed well for me.
int Agony() { return *((int*)0); } Mwahaha... >8)
"We should have a great fewer disputes in the world if words were taken for what they are, the signs of our ideas only, and not for things themselves." - John Locke
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement