PDA

View Full Version : Do Carbon Idle Event Timers work?


Dardan
2004.08.11, 03:43 AM
Hello everyone,

I'd first like to say that I have long used this forum as a valuable resource, and I just now got around to registering, so this is my first post! YaY! :)

Anyway, I am trying to set up a Carbon event loop that uses an idle event timer to drive the game loop. My problem is this: Xcode will not compile the callback function that my timer calls.

This is the error I get:
Prototypes.h:36: error: parse error before "EventIdleAction"

That error refers to the third line in this prototype:

pascal void NextFrame( EventLoopTimerRef timer,
void *userData,
EventIdleAction action );

I have no problem compiling a regular event timer callback, so it seems that EventIdleAction is the only thing giving me grief. I have read the Apple online docs, but the very code they supply does not compile. I have searched and searched for an example that uses idle event loop timers, and I have found nothing.

I set my timer up like this (almost exactly like the example in the Apple docs):

EventLoopRef mainLoop;
EventLoopIdleTimerUPP idleTimerUPP;
EventLoopTimerRef theTimer;

mainLoop = GetMainEventLoop();
idleTimerUPP = NewEventLoopTimerUPP( NextFrame );
InstallEventLoopIdleTimer( mainLoop,
0,
kEventDurationNoWait,
idleTimerUPP,
NULL,
&theTimer );

RunApplicationEventLoop();

Has anyone had this problem? If not, can someone please post a working example (or a summary of one anyway)?

Thanks a lot!


---
Dard.

ThemsAllTook
2004.08.11, 08:16 AM
Looking in CarbonEventsCore.h, I'm not seeing a typedef for EventIdleAction. What I did find was this:

typedef CALLBACK_API( void , EventLoopIdleTimerProcPtr )(EventLoopTimerRef inTimer, EventLoopIdleTimerMessage inState, void *inUserData);

Those are probably the function parameters you actually want. I have no idea why the Apple docs would have gotten it wrong, though...

Alex Diener

radiance
2004.08.11, 08:48 AM
According the the CarbonEventsCore.h file:

* Idle timers are
* only called when there is no user activity occuring in the
* application. This means that the user is not actively
* clicking/typing, and is also not in the middle of tracking a
* control, menu, or window

I think what you want is:

EventLoopTimerUPP myFrameUPP = NewEventLoopTimerUPP (NextFrame),
EventLoopTimerRef nextFrameTimer;


InstallEventLoopTimer(
GetCurrentEventLoop(),
kEventDurationNoWait,
kEventDurationMillisecond,
myFrameUPP,
NULL,
&nextFrameTimer);

RunApplicationEventLoop();


I use timers a lot to drive my game and it works very well.

Good luck,

::ken::
www.angelfroggames.com (http://www.angelfroggames.com)

FCCovett
2004.08.11, 12:25 PM
There's a fully working example here - with some other goodies: http://webpages.charter.net/utopiaplanetia/BasicCarbonStruct.dmg

Dardan
2004.08.11, 02:24 PM
Thanks a lot for the help, everyone...

Just so you all don't think I'm crazy, here is a link to the docs that this code came from.

Goto:
http://developer.apple.com/documentation/Carbon/Conceptual/Carbon_Event_Manager/index.html

Then click "Carbon Event Manager Tasks," in the navigation bar, and then click "Installing Timers."

Thanks for the example and the tip... I'll be using a regular event timer now. :)