> >  So any advice on the competing event loops?
> >
>
> That's great to hear. :)
>
> David's PausingRector seems interesting - and might be especially
> relevant in turn-based games.  There are also other easy ways to
> integrate with the default reactor on your platform.  One such way is
> to use a Coiterator.  For example:

Thanks for the positive words.   The implementation is not slow,
though, as your 'turn-based' comment might suggest.  In any reactor,
the reactor gives up control for the duration of a callback.  The same
code you can put into a reactor callback using selectReactor, you can
put between the reactor runs in PausingReactor.  Same code, same time
consumption, same reactor delay.

PausingReactor just allows you to write code in a different style than
with selectReactor; for some of us, that is an easier style.

>  from twisted.internet import reactor, task
>  from twisted.python import log
>  import sys
>
>  class Runtime:
>     ...
>     def run(self):
>         while not win.has_exit:
>             ...
>             yield 1
>     def shutdown(self, result):
>          print 'bye'
>          reactor.stop()
>     def bailout(self, reason):
>         reason.printTraceback()
>         reactor.stop()
>
>  log.startLogging(sys.stdout)
>  runspot = Runtime()
>  
> task.coiterate(runspot.run()).addCallback(runspot.shutdown).addErrback(runspot.bailout)
>  reactor.run()

I looked into this approach, and while it is better than chained
non-generator callbacks, it is still limited.  If your run() method
calls subroutines that need significant runtime, and therefore have
their own internal yields, you have to use a syntax like  "while ... :
yield 1":

def subcall():
        # do stuff
        yield 1
        # do other stuff
        yield 1

def run(self):
      while not_done:
           # do stuff
           while subcall(): yield 1


With PausingReactor, you can do:

def subcall():
     # do stuff
     reactor.resume()
     # do more stuff
     reactor.resume()

def run():
     while not_done:
          # do stuff
          reactor.resume()
          subcall()

reactor.callLater(0,reactor.release())
reactor.run()
run()

The code can nest subroutines calls arbitrarily deep, and the reactor
can be resumed from anywhere, whenever the game is ready for user
interaction.  Presumably, the intervals between resumes would be
brief.

This is a bit off-topic for a pyglet list, so I will stop here.
Thanks for the opportunity to make these points.

David

---
[EMAIL PROTECTED]
Pitcher's Duel -> pitchersduel.python-hosting.com

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"pyglet-users" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/pyglet-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to