Subversion Repositories Kolibri OS

Rev

Blame | Last modification | View Log | Download | RSS feed

  1. #include <sys/ksys.h>
  2.  
  3. /*
  4. Calculate and draw FPS
  5. x,y - window relative coordinates to draw FPS info
  6.  
  7. Returns the number of centiseconds (cs) spent in one drawing cycle
  8. */
  9.  
  10. int time1=0;
  11. int time2=0;
  12. int fps1=0;
  13. int timerend=0;
  14.  
  15. int Fps (long x, long y)
  16. {
  17.     int tr;
  18.  
  19.     time1 = _ksys_get_tick_count(); // time in cs since boot
  20.  
  21.     if (timerend==0)
  22.     {
  23.        time2 = time1;
  24.        timerend = time1;
  25.     }
  26.  
  27.     tr = time1 - timerend;
  28.  
  29.     if ((time1 - time2) < 100)  // if passed less than one second
  30.     {
  31.         fps1++;
  32.     }
  33.     else
  34.     {
  35.         // draw FPS info
  36.         _ksys_draw_bar(x, y, 23, 7, 0x00555555);
  37.         _ksys_draw_number(fps1, x, y, 4, 0xfafafa);
  38.         fps1 = 0;
  39.         time2 = time1;
  40.     }
  41.  
  42.     timerend = time1;
  43.  
  44.     return tr;
  45. }
  46.