Simulating "system idle" events in Carbon applications - Printable Version
+- iDevGames Forums (http://www.idevgames.com/forums)
+-- Forum: Development Zone (/forum-3.html)
+--- Forum: Game Programming Fundamentals (/forum-7.html)
+--- Thread: Simulating "system idle" events in Carbon applications (/thread-4303.html)
Simulating "system idle" events in Carbon applications - ascotti - Apr 30, 2006 05:51 PM
thanks to some great posts in this forum and to OneSadCookie's sample code for AGL, I've got a first working port of my emulator Tickle (http://www.ascotti.org/programming/tickle/tickle.htm) as a Carbon application for Mac OS X, although with no audio yet.
Now, the very simple architecture I already use on Windows and Linux is based on receiving "idle" events from the system, and I would like to reuse that on the Mac too.
Apparently, the system does not provide such events "out of the box", so they have to be produced manually. Here's what I'm doing. Before calling RunApplicationEventLoop(), I create an 'IDLE' event and post it to the main queue. This event is handled by the application event handler, which immediately reposts it on the same queue thus generating an endless stream of 'IDLE' events.
From what I can see, this method works very well, and gives me several thousands events per second... more than I need actually! :-)
Ok, now I have a couple of questions:
1) is there something wrong with the above approach? Some solutions I found on the net are considerably more complicated and I wonder if I'm missing something (being still a beginner for Mac programming);
2) is it ok to call CreateEvent just once or do I have to create a separate event for each post?
Thanks for your help and BTW this is really an amazing place for Mac knowledge!
Simulating "system idle" events in Carbon applications - OneSadCookie - Apr 30, 2006 06:27 PM
Personally, I'd be doing this with a timer... but if your approach is working, there's probably nothing wrong with it
Simulating "system idle" events in Carbon applications - ascotti - May 2, 2006 03:12 PM
Hey good advice... I just switched to a fast timer and it seems to work better actually!
One problem of the method I posted is idle messages do not get dispatched when the system is busy in some "internal" operation, e.g. when you drag the window around. Timers do not suffer from this.
There is one piece of information I would like to know though: what is the "guaranteed" resolution of those timers?
Simulating "system idle" events in Carbon applications - DoG - May 2, 2006 03:19 PM
There isn't any guaranteed resolution. If the system hangs on VM paging, for example, you're SOL. If you want guaranteed resolution, you need to use a real-time OS, or look into what OS X has to offer in that regard.
Simulating "system idle" events in Carbon applications - OneSadCookie - May 2, 2006 03:22 PM
There is no guaranteed resolution. They will fire as often as possible, up to the requested rate.