I've been trying to make an environment and want to run it as fast as possible (1000+ FPS if possible). I tried experimenting with pyglet, and it seems as though I cannot go beyond 60fps.
I used the following setting to call my update function
pyglet.clock.schedule_interval(update, 1.0/120.0)
The environment currently has just 1 sprite, and there is no expensive computation that is happening. Running just the update method for 1000 iterations takes 2ms.
It seems to work okay if I reduce the FPS, but always gets capped at 60FPS. Is there any way around this?
From Migrating from pyglet 1.5:
Application Event Loop
^^^^^^^^^^^^^^^
In previous releases, the Window was redrawn (and theWindow.on_draw()event dispatched) whenever any scheduled function was called, or event dispatched. This often lead to unpredictability and potentially unstable frame rates. In pyglet 2.0, a newintervalargument has been added topyglet.app.run. Windows will now always be redrawn at this interval. It defaults to 60fps > (1/60), but can be set as desired:
@mywindow.event
def on_draw():
# always called at 120fps
pyglet.app.run(interval=1/120)
Other things to keep in mind:
https://pyglet.readthedocs.io/en/latest/programming_guide/time.html
Periodic Events
You can schedule updates on an interval. This is for ideal for animation, physics simulation, and game state updates.
pyglet.clock.schedule_interval(update, 1 / 60.0)
Or, if you want to call the function as frequently as possible:
pyglet.clock.schedule(benchmark)
Vsync
Pyglet window buffer swaps are synchronized to the display refresh rate, so you may want to disable vsync. This can specified at window creation time or set with window.set_vsync(False)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With