comparison pytouhou/ui/window.pyx @ 589:0768122da817

Add a frameskip option, and use swap interval to implement it.
author Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
date Fri, 10 Oct 2014 15:59:11 +0200
parents 7a82c4b52b16
children 12756994a92c
comparison
equal deleted inserted replaced
588:7a82c4b52b16 589:0768122da817
75 return False 75 return False
76 76
77 77
78 78
79 cdef class Window: 79 cdef class Window:
80 def __init__(self, backend, long fps_limit=-1): 80 def __init__(self, backend, long fps_limit=-1, frameskip=1):
81 if backend is not None: 81 if backend is not None:
82 self.win = backend.create_window( 82 self.win = backend.create_window(
83 'PyTouhou', 83 'PyTouhou',
84 sdl.WINDOWPOS_CENTERED, sdl.WINDOWPOS_CENTERED, 84 sdl.WINDOWPOS_CENTERED, sdl.WINDOWPOS_CENTERED,
85 640, 480) #XXX 85 640, 480, #XXX
86 frameskip)
86 87
87 self.clock = Clock(fps_limit) 88 self.clock = Clock(fps_limit)
89 self.frame = 0
90 self.frameskip = frameskip
88 91
89 92
90 cdef void set_size(self, int width, int height) nogil: 93 cdef void set_size(self, int width, int height) nogil:
91 self.win.set_window_size(width, height) 94 self.win.set_window_size(width, height)
92 95
108 111
109 cdef bint run_frame(self) except? False: 112 cdef bint run_frame(self) except? False:
110 cdef bint running = False 113 cdef bint running = False
111 if self.runner is not None: 114 if self.runner is not None:
112 running = self.runner.update() 115 running = self.runner.update()
113 if self.win is not None: 116 if self.win is not None and (self.frameskip <= 1 or not self.frame % self.frameskip):
114 self.win.present() 117 self.win.present()
115 self.clock.tick() 118 self.clock.tick()
119 self.frame += 1
116 return running 120 return running
117 121
118 122
119 cdef double get_fps(self) nogil: 123 cdef double get_fps(self) nogil:
120 return self.clock.fps 124 return self.clock.fps