Re: "Nested" runloops
Re: "Nested" runloops
- Subject: Re: "Nested" runloops
- From: Eric Matecki <email@hidden>
- Date: Fri, 22 Jul 2011 09:42:38 +0200
Ken Thomases wrote:
On Jul 20, 2011, at 8:01 AM, Eric Matecki wrote:
I have to port a software to take advantage of 64 bits adressing.
The software was originally written for Windows...
So there isn't any real runloop, but there are GetMsg() function calls
spread all around the source code (in about 200 files out of the 1000+ !!).
My condolences. :)
I create a NSWindow and put a subclass of NSOpenGLView as contentView:
In that view I override all event processing methods, "decode" the event
into our own event structure, and append it to our event queue.
In this 'append to queue' method, after appending the event, if it is the first time it is called,
I call the working function of the software, which will call GetMsg() from everywhere.
You should probably call the working function from -applicationDidFinishLaunching: or the like. Or maybe an override of -[NSApplication run] (see below).
GetMsg(), if our event queue is empty, tries to get new 'native' events and decodes and append them to the queue.
Thats where my problems really start.
I tried all of these :
NSRunLoop* runloop = [NSRunLoop currentRunLoop];
assert(runloop);
[runloop acceptInputForMode: NSModalPanelRunLoopMode beforeDate: [NSDate dateWithTimeIntervalSinceNow: 1];
// [runloop acceptInputForMode: NSDefaultRunLoopMode beforeDate: [NSDate dateWithTimeIntervalSinceNow: 1]];
// [runloop runMode: NSDefaultRunLoopMode beforeDate: [NSDate dateWithTimeIntervalSinceNow: 1]];
// [runloop runUntilDate: [NSDate dateWithTimeIntervalSinceNow: 1]];
The 'timeout' of 1 second is so I have time to read the traces in the console.
What happens is:
- when I do nothing with the window, the timeout 'fires' and GetMsg() returns nil after one second.
- when I 'draw' with the mouse (down,drag,up), the method I call on runloop returns
(almost) instantly, thus the event has been processed somehow, but the event methods
in my view AREN'T called !!
Anything I'm doing wrong ? (beside the fact I really should be using the runloop
as it was meant to, but can't ...)
The connection to the window server for receiving events is a run loop source, but that source's handler merely queues the event internally. It doesn't dispatch the event. The event is dequeued by -[NSApplication nextEventMatchingMask:untilDate:inMode:dequeue:] and dispatched via -[NSApplication sendEvent:]. It is -[NSApplication run] which normally does this. Review the class overview for NSApplication. Also, see the GLUT sample code linked to from the documentation for -[NSApplication run]. That sample re-implements -run, which will give you some idea of how to do the same.
http://developer.apple.com/library/mac/#samplecode/glut/Listings/GLUTApplication_m.html
You'll need to turn that run method inside out for your GetMsg() implementation.
Good luck,
Ken
Thanks !
That's a great sample I overlooked somehow.
Now I have to take it appart to understand all the details of its inner working.
Eric M.
--
Keep intel OUTSIDE my Mac !
Hiii !!! I can see Intel chips creeping around my G5 !
Eric M.
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden