Mercurial > touhou
comparison pytouhou/ui/window.pyx @ 452:1f5156093785
By default, only enable fps limiting if vsync doesn't do the job.
author | Thibaut Girka <thib@sitedethib.com> |
---|---|
date | Fri, 30 Aug 2013 20:38:02 +0200 |
parents | 2a352118c55a |
children | 6864a38b2413 |
comparison
equal
deleted
inserted
replaced
451:c034570ac785 | 452:1f5156093785 |
---|---|
22 | 22 |
23 IF USE_GLEW: | 23 IF USE_GLEW: |
24 from pytouhou.lib.opengl cimport glewInit | 24 from pytouhou.lib.opengl cimport glewInit |
25 | 25 |
26 | 26 |
27 class Clock(object): | 27 class Clock: |
28 def __init__(self, fps=None): | 28 def __init__(self, fps=None): |
29 self._target_fps = 0 | 29 self._target_fps = 0 |
30 self._ref_tick = 0 | 30 self._ref_tick = 0 |
31 self._ref_frame = 0 | 31 self._ref_frame = 0 |
32 self._fps_tick = 0 | 32 self._fps_tick = 0 |
50 | 50 |
51 if not self._ref_tick: | 51 if not self._ref_tick: |
52 self._ref_tick = current | 52 self._ref_tick = current |
53 self._ref_frame = 0 | 53 self._ref_frame = 0 |
54 | 54 |
55 if self._fps_frame >= (self._target_fps or 60): | 55 if self._fps_frame >= (self._target_fps if self._target_fps > 0 else 60): |
56 self._rate = self._fps_frame * 1000. / (current - self._fps_tick) | 56 self._rate = self._fps_frame * 1000. / (current - self._fps_tick) |
57 self._fps_tick = current | 57 self._fps_tick = current |
58 self._fps_frame = 0 | 58 self._fps_frame = 0 |
59 # If we are relying on vsync, but vsync doesn't work or is higher | |
60 # than 60 fps, limit ourselves to 60 fps. | |
61 if self._target_fps < 0 and self._rate > 64.: | |
62 self._target_fps = 60 | |
59 | 63 |
60 self._ref_frame += 1 | 64 self._ref_frame += 1 |
61 self._fps_frame += 1 | 65 self._fps_frame += 1 |
62 | 66 |
63 target_tick = self._ref_tick | 67 target_tick = self._ref_tick |