There's been some talk elsewhere of how the default timer resolution in 
Windows isn't precise enough to handle 60 FPS, whether in Pyglet or other 
places. I've rolled my own solution and thought I would share it.

The idea is simple. You create a couple of functions that raise and lower 
the timer resolution in Windows as needed:

import ctypes
try:
    _winmm = ctypes.windll.winmm
except:
    time_start = lambda: None
    time_stop = lambda: None
    set_priority = lambda: None
else:
    time_start = lambda: _winmm.timeBeginPeriod(ctypes.c_uint(2))
    time_stop = lambda: _winmm.timeEndPeriod(ctypes.c_uint(2))
    set_priority = lambda: (
        ctypes.windll.kernel32.SetPriorityClass(-1, 0x8000))

(The reason we perform the try/except test is to allow this code to run 
cross-platform.)

Run time_start when you want to raise the timer resolution to allow 60 FPS 
behaviors; run time_stop when you want to toggle it back off.

In my own applications, I toggle on at app start, then toggle off whenever 
the application is paused, or when it's in a mode where 60FPS resolution is 
not required.

set_priority is optional, but useful. Run that and the priority for the 
application is raised to Above Normal, making it slightly more responsive 
if you have other things running in the background.

-- 
You received this message because you are subscribed to the Google Groups 
"pyglet-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/pyglet-users.
For more options, visit https://groups.google.com/d/optout.

Reply via email to