PocketMatrix forums

A read-only archive of the PocketMatrix forums (2001–2014). Posting and accounts are closed.

GapiDraw and Timers(Again!!)

I'm just starting out on my next project for MS Smartphone and have a problem with timers.

I have used GR Moore's sample code to implement a timer. At the moment all I want to do is animate a line moving up and down the screen. From what I've read the whole point of a timer is to isolate the animation speed from the framerate - only I can't seem to be able to achieve this.

In my timer callback I simply update the Y coordinate of the line by a value of 1. To test whether it's isolated from the framerate I set the framerate to a low value (<10). I believe that what I should see when the framerate is low is that the line should move in big steps every time the frame is updated.

For example if the framerate is 10 and my timer is set to 25ms every time the frame is updated I my line should have moved 4 pixels. Unfortunately it doesn't, it just moves by 1 pixel every frame.

I'm using the CGapiApplication framework and I also use the Hekkus Sound system. I realise that GR Moore's code was written for GD 1.04 so I'm wondering whether using GD2.05 or the Hekkus Sound System could be making a difference.

Any advice on why this might be occuring would be great. Many thanks.
The Timer code will work across all of the versions of GapiDraw, so that shouldn't be an issue. I've used it through GD2.04 without problems. I'm not sure what the timer resolution is on the Smartphone, so I can't comment on how accurate it will be there. You may try using GetTickCount( ) as I've been using that method of timing in our SpriteEngine and RaptureEngine.

Without seeing your code, my only guess would be the timer resolution on your device isn't good enough to handle 25ms. You would need to test the timer to see just how accurate it is.
Pejo Software - Per · 14 Jan 2004, 18:07 UTC
I don't recommend using Windows timers to implement sprite movement. They aren't very accurate.
The WM_TIMER message is a low-priority message. The GetMessage and PeekMessage functions retrieve this message only when no other higher-priority messages are in the thread’s message queue.
The best way is to use a performance counter (not available on all devices) and the next best thing is GetTickCount().
Thanks very much for the advice. I have another question which may demonstrate my complete lack of understanding of the way I should be using GetTickCount().

If I call GetTickCount from within processNextFrame I will only ever get a difference of between successive calls of the time it takes to get through processNextFrame i.e. the frame time - which means I might as well just use the built in GapiDraw timer for my animation.

If that is the case should I be using a different thread for my calls to getTickCount() so that I can get a higher resolution than the frame rate? My knowledge of how to use threads in C++ is pretty minimal so I'm hoping, if this is what I should do, it wouldn't be too complicated to start a new thread using the CGapiApplication framework.
GetTickCount provides the number of milliseconds passed since system reset. On the Pocket PC, this count is paused while the applicaiton is minimized (ie phone edition devices). You can measure elapsed time by comparing the value returned by GetTickCount each pass through ProcessNextFrame (or wherever).