Archived

This topic is now archived and is closed to further replies.

Paralax

My WM_TIMER message dies -> animations crappy :-(

Recommended Posts

Hi there! Me, being rather a beginner, got a problem with my Visual C++ DirectX 7.0aSDK -main-menu code. I wanted the buttons to be animated, when they''re activated and so I set up a little loop with peek message, all the drawing stuff and some calls to DirectInput like GetDeviceState(...). Now, I wrote a linked list for my surfaces and finally all worked fine with my animations. But my problem is, that the animation gets interrupted, if I press any key. If I hold it and press another key, the whole thing just goes on fine. I have no idea, what I could do about it. I could use clocks, but I hope anyone of you helpful guyz out there has a clue and can help me with my problem. Thanx so much!

Share this post


Link to post
Share on other sites
I take it from your subject that you are using WM_TIMER... this is probably the cause of the problem. I''d use something like GetTickCount() instead.

- Daniel

Share this post


Link to post
Share on other sites
If you''re using WM_TIMER, then when you''re pressing a key, then the message processing loop go to the WM_ of the key and go over WM_TIMER. So during that time, your animations stop.

So like deakin said, you should use GetTickCount()

Darkening

Share this post


Link to post
Share on other sites
The problem with relying on WM_TIMER messages is that it is a low priority message. When messages (events) are added to the message loop they are inserted into the queue before any other messages with a lower priority. In other words the queue is actually a sorted list.

WM_TIMER has a VERY low priority, WM_KEYxxx has a higher priority.

Use a Message Dispatch loop with PeekMessage and use GetTickCount() inside the loop for timing.

The down side to this approach is that if there a lot of messages in the queue that are result in a lengthy event process (i.e. saving/loading) your animation will grind to a halt.

The ideal approach would to create a separate thread. Make your thread sleep() for a specified time, when it wakes up it will be serviced at the next opportunity (usually within a few hundred clock cycles).

Share this post


Link to post
Share on other sites