[haiku-3rdparty-dev] Creating a fast (60 fps or so) periodic timer

  • From: Joseph Adams <joeyadams3.14159@xxxxxxxxx>
  • To: haiku-3rdparty-dev@xxxxxxxxxxxxx
  • Date: Fri, 18 Sep 2009 01:48:46 +0000

I'm porting a game of mine to Haiku, and I'm trying to have it update
quickly (e.g. 60 times per second) so as to produce a smooth
framerate.  On the game's original platform (Ecere SDK), I created a
Timer object that would fire a handler function every 0.015 seconds.

The closest analogue I have found to this is the Pulse() handler.
Unfortunately, its granularity isn't sufficient, producing roughly 10
frames per second.  I also tried a BMessageRunner:

game_timer = new BMessageRunner(this, new BMessage(GAME_TIMER), 15000, -1);

but the framerate is still the same.  Note that the CPU usage stays low.

Ways that come to mind for me are:

1.  Using the Media kit and BTimeSource
2.  Creating a thread with a for loop to send the periodic messages
3.  Having the update handler recursively invoke itself
4.  Using an Application kit feature I overlooked

How can I get my update handler to trigger faster than the Pulse()
cutoff point (preferably without hogging all the CPU power unless the
computer is too slow)?  Thanks!

Other related posts: