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

Albert Astals Cid aacid at kde.org
Mon Jun 15 22:37:57 CEST 2009


A Divendres, 12 de juny de 2009, Ian Wadham va escriure:
> 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.

Doesn't that mean jerky animation?

>
> 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.

Hmmm, so you mean now you get jerky animation but game still "runs fast" while 
previously it was running jerky and slow?

Albert

>
> The code is in kgoldrunner/src/kgrtimer.h and
> kgoldrunner/src/kgrtimer.cpp, but it needs polishing.
>
> All the best, Ian W.
> _______________________________________________
> kde-games-devel mailing list
> kde-games-devel at kde.org
> https://mail.kde.org/mailman/listinfo/kde-games-devel




More information about the kde-games-devel mailing list