Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* Get actual time of day in sec & msec */
- unsigned long getTickCount()
- {
- struct timeval tv; // tv.tv_sec == seconds & tv.tv_usec == milliseconds
- if( gettimeofday(&tv, NULL) != 0 )
- return 0;
- return ((tv.tv_sec * 1000) + (tv.tv_usec / 1000));
- }
- /* Do heartbeat*/
- int fgcTimer(int* nwNewsock)
- {
- const int tps = 25; // Ticks per second
- const int frequency = 1000 / tps;
- const int maxFrameskip = 5;
- bool isRunning = true;
- int loops;
- float delta;
- unsigned long nextTick = getTickCount();
- while( isRunning ) {
- loops = 0;
- do {
- // doSomething();
- std::system("clear");
- std::cout << "Data: getTickCount(): " << getTickCount() << std::endl;
- std::cout << "Data: nextTick: " << nextTick << std::endl;
- std::cout << "Data: Delta: " << ((getTickCount() + frequency - nextTick) / frequency) << std::endl;
- std::cout << "Data: Loops: " << loops << std::endl;
- nextTick += frequency;
- loops++;
- } else { exit(1); };
- } while( getTickCount() > nextTick && loops < maxFrameskip);
- delta = float(getTickCount() + frequency - nextTick) / float(frequency);
- // showSomething(delta);
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement