This is my first post! Sorry if I did anything wrong!
I am making a game using WinApi and DirectX. I have made pretty decent progress and I like where the project is going, however I have stumbled upon something. I was wondering how to accurately time the events in a game. Not the FPS, but the actual calculations and such. I wonder about this since some computers run faster than others, wouldn't the game calculate faster on different computers? If I wanted a universal experience, wouldn't I want all of the users computers to do the calculations at the same speed?
I have already tried time.h, but it isn't accurate/fast enough. Any thoughts? Or am I just being a noob!
int main ()
int i_ticks = 0;
f_secc = clock(), /* used to hold the first millisecond*/
f_secn = clock() + CLOCKS_PER_SEC, /* used to hold the next second */
f_milc = clock(), /* used to hold the current millisecond */
f_miln = clock() + (CLOCKS_PER_SEC/250); /* used to determine the next tick */
f_milc = clock(); /* get the current millisecond */
if (f_milc >= f_miln) /* if 250th of a second passed */
i_ticks++; /* increase the tick counter */
f_miln = clock() + (CLOCKS_PER_SEC/250); /* assign when the next tick occurs */
} while (f_milc <= f_secn); /* break when a second passed */
std::cout << i_ticks << std::endl; /* output the amount of ticks registered */
This is really rough and isn't part of my project. I just needed something to test with. Also this code is assuming that CLOCKS_PER_SEC is 1000.
I know I am doing something wrong then. Anyone have any suggestions?
You're welcome! I'm glad they helped. Yes, QueryPerformanceFrequency() returns the amount of counts per second. This function should be called when your timer is initialized, since the value it returns cannot be changed for the duration that the system is running. QueryPerformanceCounter() returns the current performance-counter value, measured again in counts.
Referring to the Luna example for his DirectX 10 book, he does: