changeset 594:12756994a92c

Make frameskip actually skip the rendering part, not just the buffer swap.
author Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
date Sat, 18 Oct 2014 18:04:43 +0200
parents 974decb8df4f
children b7b4a234bf70
files pytouhou/ui/gamerunner.pyx pytouhou/ui/window.pxd pytouhou/ui/window.pyx
diffstat 3 files changed, 13 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/pytouhou/ui/gamerunner.pyx
+++ b/pytouhou/ui/gamerunner.pyx
@@ -114,7 +114,7 @@ cdef class GameRunner(Runner):
             self.renderer.capture(filename, self.width, self.height)
 
 
-    cpdef bint update(self) except? False:
+    cpdef bint update(self, bint render) except? False:
         cdef long keystate
         capture = False
 
@@ -178,7 +178,7 @@ cdef class GameRunner(Runner):
         if self.window is not None and 'framerate' in labels:
             labels['framerate'].set_text('%.2ffps' % self.window.get_fps())
 
-        if not self.skip and self.renderer is not None:
+        if render and not self.skip and self.renderer is not None:
             self.renderer.render(self.game)
 
         if capture:
--- a/pytouhou/ui/window.pxd
+++ b/pytouhou/ui/window.pxd
@@ -15,7 +15,7 @@ cdef class Runner:
 
     cdef void start(self) except *
     cdef void finish(self) except *
-    cpdef bint update(self) except? False
+    cpdef bint update(self, bint render) except? False
 
 
 cdef class Window:
--- a/pytouhou/ui/window.pyx
+++ b/pytouhou/ui/window.pyx
@@ -71,7 +71,7 @@ cdef class Runner:
     cdef void finish(self) except *:
         pass
 
-    cpdef bint update(self) except? False:
+    cpdef bint update(self, bint render) except? False:
         return False
 
 
@@ -109,14 +109,20 @@ cdef class Window:
                 self.runner.finish()
 
 
+    @cython.cdivision(True)
     cdef bint run_frame(self) except? False:
-        cdef bint running = False
+        cdef bint render = (self.win is not None and
+                            (self.frameskip <= 1 or not self.frame % self.frameskip))
+
+        running = False
         if self.runner is not None:
-            running = self.runner.update()
-        if self.win is not None and (self.frameskip <= 1 or not self.frame % self.frameskip):
+            running = self.runner.update(render)
+        if render:
             self.win.present()
+
         self.clock.tick()
         self.frame += 1
+
         return running