changeset 463:11708a1d0a1a

Make GameRunner inherit from a Runner base class, to bypass Python calls in Window.
author Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
date Wed, 11 Sep 2013 00:36:52 +0200
parents a71b912b45b7
children 36bc577b2392
files pytouhou/ui/gamerunner.pyx pytouhou/ui/window.pxd pytouhou/ui/window.pyx
diffstat 3 files changed, 30 insertions(+), 18 deletions(-) [+]
line wrap: on
line diff
--- a/pytouhou/ui/gamerunner.pyx
+++ b/pytouhou/ui/gamerunner.pyx
@@ -14,17 +14,17 @@
 
 from pytouhou.lib cimport sdl
 
-from .window cimport Window
+from .window cimport Window, Runner
 from .gamerenderer cimport GameRenderer
 from .music import MusicPlayer, SFXPlayer, NullPlayer
 
 
-cdef class GameRunner:
+cdef class GameRunner(Runner):
     cdef object game, background
     cdef GameRenderer renderer
     cdef Window window
     cdef object replay_level, save_keystates
-    cdef long width, height, keystate
+    cdef long keystate
     cdef bint skip, use_fixed_pipeline
 
     def __init__(self, window, resource_loader, bint skip=False):
@@ -75,7 +75,7 @@ cdef class GameRunner:
             self.keys = self.replay_level.iter_keystates()
 
 
-    def start(self):
+    cdef void start(self) except *:
         cdef long width, height
         width = self.game.interface.width if self.game is not None else 640
         height = self.game.interface.height if self.game is not None else 480
@@ -85,15 +85,7 @@ cdef class GameRunner:
         self.renderer.start(self.game)
 
 
-    def finish(self):
-        #TODO: actually clean after buffers are not needed anymore.
-        #if not self.use_fixed_pipeline:
-        #    vbo_array = (c_uint * 2)(self.vbo, self.back_vbo)
-        #    glDeleteBuffers(2, vbo_array)
-        pass
-
-
-    def update(self):
+    cdef bint update(self) except *:
         cdef long keystate
 
         if self.background:
--- a/pytouhou/ui/window.pxd
+++ b/pytouhou/ui/window.pxd
@@ -10,16 +10,24 @@ cdef class Clock:
     cdef void tick(self) nogil except *
 
 
+cdef class Runner:
+    cdef long width, height
+
+    cdef void start(self) except *
+    cdef void finish(self) except *
+    cdef bint update(self) except *
+
+
 cdef class Window:
     cdef sdl.Window win
     cdef long fps_limit
     cdef public long width, height
     cdef public bint use_fixed_pipeline
-    cdef object runner
+    cdef Runner runner
     cdef Clock clock
 
     cdef void set_size(self, int width, int height) nogil
-    cpdef set_runner(self, runner=*)
+    cpdef set_runner(self, Runner runner=*)
     cpdef run(self)
     cdef bint run_frame(self) except? False
-    cpdef double get_fps(self)
+    cdef double get_fps(self) nogil
--- a/pytouhou/ui/window.pyx
+++ b/pytouhou/ui/window.pyx
@@ -74,6 +74,18 @@ cdef class Clock:
 
 
 
+cdef class Runner:
+    cdef void start(self) except *:
+        pass
+
+    cdef void finish(self) except *:
+        pass
+
+    cdef bint update(self) except *:
+        return False
+
+
+
 cdef class Window:
     def __init__(self, tuple size=None, bint double_buffer=True, long fps_limit=-1,
                  bint fixed_pipeline=False, bint sound=True):
@@ -115,7 +127,7 @@ cdef class Window:
         self.win.set_window_size(width, height)
 
 
-    cpdef set_runner(self, runner=None):
+    cpdef set_runner(self, Runner runner=None):
         self.runner = runner
         if runner is not None:
             runner.start()
@@ -138,5 +150,5 @@ cdef class Window:
         return running
 
 
-    cpdef double get_fps(self):
+    cdef double get_fps(self) nogil:
         return self.clock.get_fps()