Skip to main content
GameDev.net gamedev.net
🔒 Locked

OnIdle handler troubles

Started by Goku705 Jan 7, 2002 at 6:52 PM 3 replies 650+ views
Original Post
Goku705
Goku705
In my game (made using CBuilder 5), I''ve set Application->OnIdle to a function that does my frame rendering. Unfortunately, it seems that the OnIdle handler is only called when I do something like move the mouse over the game window, press a key or click the mouse button. So, the idle handler is being called only when other messages are being handled (IOW, the program''s not idle...). This makes no sense at all and obviously I''d really like to fix it so if someone could please tell me what''s wrong here and how to fix it, it would be greatly appreciated. Thanks in advance. -Goku
Ironside
Ironside
You could try using peekmsg to see if there''s an idle message at the head of the queue instead of waiting for one to get delivered.
Goku705
Goku705
Thanks Ironside, but you appear to be assuming a little too much about my knowledge of VCL here. I know I could use the PeekMsg Win32 function (something I am familiar with if that''s what you mean). The thing is I have no idea how I''d use that without completely defeating the purpose of even using OnIdle. Could you maybe clarify a bit?

-Goku
Goku705
Goku705
Well, I solved my problem. I''ll explain it here for those who might benefit from it in the future. The IdleHandler was only being triggered when a fresh idle message is being sent, something which occurs immediately after each time a non-idle message is sent. Since the Done parameter to the function was set to true (as it is by default), it ignored any repeated idle messages. By adding the line Done = false; to my function, I got it working exactly as I had wanted.


-Goku
SANE Productions Homepage
Sly
Sly
The difference is that when Done is set to True (the default), the message loop in TApplication.Run calls GetMessage which waits for the next message to enter the application''s message queue. If Done is set to False by the OnIdle event handler, then PeekMessage is called which returns immediately, thus triggering the OnIdle event again if there is no message waiting in the queue.

Steve ''Sly'' Williams  Monkey Wrangler  Krome Studios
turbo game development with Borland compilers

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.