win32priority.py edited online with Bitbucket
-"""
+'''
win32priority.py
A set of utilies to patch Pyglet to provide more precise event timing on Windows.
@@ -27,11 +27,10 @@ The following options are provided:
patch_event_loop: Replaces the default event loop with one that is more amenable
to an application where you're firing the main event loop by way of the
- scheduler. If you use this, you'll need to manually call window.flip() in your
- draw routine.
-
-"""
+ scheduler. If you use this, you'll need to manually call window.switch_to() and
+ window.flip() in your draw routine.
+'''
def priority_patch(
pin_thread = True,
@@ -44,6 +43,7 @@ def priority_patch(
pin_process = False,
patch_event_loop=False,
):
+
import ctypes
try:
_winmm = ctypes.windll.winmm
@@ -72,20 +72,18 @@ def priority_patch(
k32.SetProcessAffinityMask(k32.GetCurrentProcess(), 1)
if patch_event_loop:
- class Loop(pyglet.app.EventLoop):
def idle(self):
self.clock.call_scheduled_functions(self.clock.update_time())
return self.clock.get_sleep_time(True)
- loop = Loop()
- pyglet.app.event_loop = loop
+ pyglet.app.EventLoop.idle = idle
if patch_timer:
- old_step = pyglet.app.base.EventLoop._run_estimated
+ old_step = pyglet.clock.Clock.sleep
def new_step(*a, **ka):
time_start(_1)
old_step(*a,**ka)
time_stop(_1)
- pyglet.app.base.EventLoop._run_estimated = new_step
\ No newline at end of file
+ pyglet.clock.Clock.sleep=new_step
\ No newline at end of file
