On Tue, Jan 19, 2010 at 1:16 PM, Jens Alfke <j...@mooseyard.com> wrote:
>
> On Jan 19, 2010, at 6:10 AM, Per Bull Holmen wrote:
>
>> I have made one class called GameController, which is overridden by
>> subclasses to control one specific type of game (PS: I will soon rename the
>> class "Controller" to "MainController", and instance variable "controller"
>> to "mainController"). The GameController base class also mediates between
>> input from the main thread, and the game thread, with help from the class
>> InputBuffer:
>
> You've basically implemented coroutines, actually a simple form of an actor,
> using multiple threads. Each coroutine is running an event loop, and the
> game one blocks waiting for incoming events from the UI one.
>
> (Ideally it's possible to implement this without using multiple threads; I
> tried to do that about two years ago using the low-level ucontext library,
> but it turns out that the stack manipulation it does is incompatible with
> Objective-C's exception handling system.)

You might be interested in my MAGenerator code:

http://www.mikeash.com/svn/MAGenerator/

While generators aren't exactly coroutines, they're equivalently
capable (you just need to create a dispatcher to switch between
different active generators). Of course it's a hack, but I'd say much
less of one than low-level stack manipulation, and all the hack is at
the level of syntax.

For this particular case, MAGenerator would allow you to write the
game code in straightforward top-to-bottom code, while still yielding
control to the event loop. Your event responders would invoke the
generator with whatever the user action was, and control would resume
in the generator where it left off. The HTTPParser example in
GeneratorTests.m illustrates this approach, albeit for a very
different purpose.

Mike
_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to