Problems:
1. pyglet is difficult to use in an interactive session (runloop needs to
be in a separate thread).
2. {while not w.has_exit: w.dispatch_evets(); update(dt); draw()} is
boilerplate in every program.
3. using multiple windows is error-prone; have to remember to switch_to()
at all the right times.
4. pushing event handlers is way cool, but it doesn't also push
rendering/update methods (in lazy susan, a separate stack is maintained for
same effect).
Proposal:
class ManagedWindow(Window):
def __init__(...):
super(...)
#register self in global windows list
def update(self, dt):
pass
def draw(self):
pass
ManagedWindow.register_event('update')
ManagedWindow.register_event('draw')
def run_loop():
while True:
dt = clock.tick()
for w in windows:
w.switch_to()
w.dispatch_events()
for w in windows:
w.switch_to()
w.dispatch_event('update', dt)
w.dispatch_events()
for w in windows:
w.switch_to()
w.dispatch_event('draw')
w.dispatch_events()
Usage:
from pyglet import window
w = window.ManagedWindow(...)
window.run_loop()
Event handler instances pushed onto event stack can also override update
and draw methods now.
kwargs could be provided for max dt limit, spawning in separate thread
(could detect and default true for interactive anyway?), when to exit (all
windows closed / any window closed, ...).
Prefer better names than ManagedWindow and run_loop. Related to (replaces)
issue 112.
Original issue reported on code.google.com by Alex.Hol...@gmail.com on 10 Sep 2007 at 1:51
Original issue reported on code.google.com by
Alex.Hol...@gmail.com
on 10 Sep 2007 at 1:51