Advertisement
Guest User

Untitled

a guest
Jul 21st, 2017
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.16 KB | None | 0 0
  1. /* Get actual time of day in sec & msec */
  2. unsigned long getTickCount()
  3. {
  4.   struct timeval tv; // tv.tv_sec == seconds & tv.tv_usec == milliseconds
  5.   if( gettimeofday(&tv, NULL) != 0 )
  6.     return 0;
  7.   return ((tv.tv_sec * 1000) + (tv.tv_usec / 1000));
  8. }
  9.  
  10. /* Do heartbeat*/
  11. int fgcTimer(int* nwNewsock)
  12. {
  13.   const int tps = 25; // Ticks per second
  14.   const int frequency = 1000 / tps;
  15.   const int maxFrameskip = 5;
  16.   bool isRunning = true;
  17.   int loops;
  18.   float delta;
  19.   unsigned long nextTick = getTickCount();
  20.  
  21.   while( isRunning ) {
  22.     loops = 0;
  23.     do {
  24. //      doSomething();
  25.  
  26.     std::system("clear");
  27.     std::cout << "Data: getTickCount(): " << getTickCount() << std::endl;
  28.     std::cout << "Data: nextTick: " << nextTick << std::endl;
  29.     std::cout << "Data: Delta: " << ((getTickCount() + frequency - nextTick) / frequency) << std::endl;
  30.     std::cout << "Data: Loops: " << loops << std::endl;
  31.     nextTick += frequency;
  32.     loops++;
  33.     } else { exit(1); };
  34.   } while( getTickCount() > nextTick && loops < maxFrameskip);
  35.   delta = float(getTickCount() + frequency - nextTick) / float(frequency);
  36. //    showSomething(delta);
  37.   }
  38.   return 0;
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement