[Kde-games-devel] A timer class for games

Parker Coates parker.coates at gmail.com
Wed Jul 8 14:11:21 CEST 2009


On Fri, Jun 12, 2009 at 3:15 AM, Ian Wadham wrote:
> During the re-write of KGoldrunner I have developed a timer
> class that gives greater reliability to animation-timing and a
> smoother overall animation effect.  I am wondering if it is worth
> generalizing it into a KDE Games Library class for KDE 4.4,
> i.e. whether other games could find it useful.
>
> Although its accuracy cannot be better than QTimer's, which
> is to say QObject's accuracy, it checks its performance against
> real time (wall-clock time) and compensates for "beats" that
> QTimer misses, i.e. if you ask for a beat every 20 msec, you
> get 50 beats/second, no matter what the Qt library decides to
> do, although not all beats are exactly on time and some are
> rapidly-executed catch-ups.
>
> Other bonuses are that it implements pause(), resume() and
> step() methods, to accuracy within one beat, so if you are running
> a game off a single timer, it gives you instant pause/resume.
> And the step() method is very handy for debugging animation.
>
> There is also a setScale() method which is useful for speeding
> up or slowing down the whole game.  The tick() signal emitted
> by the timer has parameters that tell you whether a beat has been
> missed (by QObject) and what the scaled time of the tick is.
>
> In KGoldrunner, I use the "missed" parameter to skip an animation
> frame in the graphics, while keeping the internal model and the
> overall motion (distance travelled per second) on time.  That
> should relieve the load on the CPU and graphics and, at worst, it
> causes an occasional flickering, which is not as bad as it already
> was (all the time) in KDE 3 and KDE 4.0 to 4.2.
>
> The code is in kgoldrunner/src/kgrtimer.h and
> kgoldrunner/src/kgrtimer.cpp, but it needs polishing.

Hello Ian,

You might want to take a look at whether your new timer makes senses
for KBreakout, particularly the keyboard controls. The current
keyboard control system is pretty primitive, and as a result it's not
very smooth at all. Seems like this might be an ideal opportunity for
your new class. The code in question is also quite simple so you
should be able to tell whether it's a good fit or not without too much
effort.

Parker


More information about the kde-games-devel mailing list