import pyglet
from pyglet import clock
from pyglet.window import key
from pyglet.gl import *
pyglet.options['debug_gl'] = False
class Test(pyglet.window.Window):
def __init__(self):
super(Test, self).__init__(640, 480, resizable=False, fullscreen=False, caption="Test")
self.clear()
#setup the tick counter and Frames Per Second counter
self.dt_count = clock.tick()
self.fps_display = pyglet.clock.ClockDisplay()
#start main loop
self.update()
def update(self):
while not self.has_exit:
#Make sure events are timed properly
self.dt_count += clock.tick()
#timer rate for updating code
if self.dt_count >= 0.025:
self.dt_count = 0
#render to screen and flip frame buffers
self.draw()
#manually dispatch window events
self.dispatch_events()
def draw(self):
#clear screen
self.clear()
#draw frames per second
self.fps_display.draw()
#flip frame buffer
self.flip()
def on_key_press(self,symbol,modifiers):
if symbol == key.ESCAPE:
self.close()
if __name__ == '__main__':
window = Test()
def update(self):
while not self.has_exit:
#store delta_time for instances
self.tick = clock.tick()Bypassing the event loop may give you other issues, like extreme CPU usage. If you're interested, I rewrote the pyglet scheduler to use a heap queue instead of sorted list and got a nice performance boost with several hundred sprites/scheduled events. I'll clean up my code and post it if you want to try it out.
I never pushed for inclusion in pyglet mostly because I didn't want to back port it and wasn't sure if it was needed. Guess I was wrong. I'll let this issue sit for a few days then consider merging it if I get more response. There needs to be more testing than just my own use though. It has the potential for making odd bugs due and that's scary. Anyway, I'll revisit this next week after some thought.