PDA

View Full Version : IdleTimers and NewEventLoopTimerUPP



02-27-2003, 08:27 AM
For some reason, I keep getting this error when my IdleTimer is inside my Application class:
function call '[Aspire].NewEventLoopTimerUPP(void)' does not match NewEventLoopTimerUPP(pascal void(*)(OpaqueEventLoopTimerRef *, void*))'

Now basically it's telling me that the IdleTimer I'm supplying to NewEventLoopTimerUPP is wrong... but I see nothing wrong with it. It is declared in my class Aspire(the application class) as:
class Aspire
{
public:
.....
pascal void GameIdleTimer(EventLoopTimerRef inTimer, void* userData);
..........
};

It is used in the function Aspire::Setup like this:
EventLoopTimerUPP sTimerUPP = NewEventLoopTimerUPP (GameIdleTimer);

ANy idea what is going on?

OneSadCookie
02-27-2003, 09:35 AM
It's a member function. It needs to be static.

Member functions have an implicit first parameter -- "this".

In order to work this, you're going to need to make your function static, and pass the this pointer in the userData.

02-27-2003, 09:53 AM
Thanks.

Since my IdleTimer contains a member function : DoUpdate(), will I need to make DoUpdate static as well? Or how would I write my IdleTimer then, since userData->DoUpdate(); doesn't work

OneSadCookie
02-27-2003, 12:10 PM
If you want the timer to call an instance method, you can do something like this, passing the address of an object of type Foo as the userData parameter to InstallEventLoopTimer.

If you want it to call a static function, that's fine too.




class Foo
{
public:
static pascal void IdleTimer(EventLoopTimerRef timer, void* userData)
{
((Foo*)userData)->DoTimer(timer);
}

void DoTimer(EventLoopTimerRef timer)
{
...
}
}