#ifndef FPS_H
#define FPS_H

/******************************************************************************
 * How to use this : call fps_init() once to feed in reasonable values.
 * Call fps_oneframe() before (or after, it does not matter) each frame.
 * fps_oneframe() will eventually call usleep(sleepstep) to give up CPU
 * time if framerate is above fpslimit.
 *****************************************************************************/

typedef struct fps_s
{
  double fpslimit ; /* maximal framerate (frames per second) */
  int timelimit ; /* minimal time between frames (milliseconds) */
  int lastframetime ; /* date of last drawn frame (milliseconds) */
  int possibleframetime ; /* time alloted to draw last frame (milliseconds) */
  int realframetime ; /* real time between two last frames (milliseconds) */
  int sleepstep ;/* nanoseconds */
} fps_t ;

void fps_init (fps_t*) ;
void fps_oneframe (fps_t*) ;

double fps_getlimit (fps_t* fps) ;
void fps_setlimit (fps_t* fps, double limit) ;
int fps_getsleepstep (fps_t* fps) ;
void fps_setsleepstep (fps_t* fps, int sleepstep) ;

#endif
