Re: Of input loops and games
Re: Of input loops and games
- Subject: Re: Of input loops and games
- From: Jack Nutting <email@hidden>
- Date: Thu, 22 Sep 2005 01:16:33 +0200
On 9/22/05, Hari Seldon <email@hidden> wrote:
>
> Sadly, I don't have "control" over the start_move_loop function --
> it's built into the original C code. Is it possible to clear the pool
> on a timer, or would that raise problems?
You could use a timer of some sort, but that would end up creating and
releasing pools continuously, even if your game was just idling, waiting for
input.
Instead, you could use a static pointer in one of your recurring functions,
perhaps modifying get_key_from_user() like this:
int get_key_from_user()
{
static NSAutoreleasePool *pool = nil;
// first time through, this just sends release to nil, which is OK
[pool release];
pool = [[NSAutoreleasePool alloc] init];
// this blocks the thread until the main thread unlocks it
[[c_controller keyLock] lock];
return [c_controller getCurrentKeyAndClear];
}
The very first time get_key_from_user() is called, this will create a pool,
and each subsequent time it will release the old pool and create a new one.
This approach will end up doing a pool cleanup for each keypress, which is
probably a pretty good granularity.
--
// jack
// http://www.nuthole.com
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden