comparison pytouhou/ui/gamerunner.pyx @ 458:1b56d62250ab

Make pytouhou.ui.{window,shader,game{runner,renderer}} extension types.
author Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
date Thu, 05 Sep 2013 23:11:54 +0200
parents cae1ae9de430
children 6e733ed817bd
comparison
equal deleted inserted replaced
457:4ccc47828002 458:1b56d62250ab
19 glLoadMatrixf, glGenBuffers, glDeleteBuffers, GL_MODELVIEW, 19 glLoadMatrixf, glGenBuffers, glDeleteBuffers, GL_MODELVIEW,
20 GL_FOG, GL_SCISSOR_TEST, glClear, GL_DEPTH_BUFFER_BIT) 20 GL_FOG, GL_SCISSOR_TEST, glClear, GL_DEPTH_BUFFER_BIT)
21 21
22 from pytouhou.utils.helpers import get_logger 22 from pytouhou.utils.helpers import get_logger
23 from pytouhou.utils.maths cimport perspective, setup_camera, ortho_2d 23 from pytouhou.utils.maths cimport perspective, setup_camera, ortho_2d
24 from pytouhou.utils.matrix cimport Matrix 24
25 25 from .window cimport Window
26 from .gamerenderer import GameRenderer 26 from .gamerenderer cimport GameRenderer
27 from .background import BackgroundRenderer 27 from .background import BackgroundRenderer
28 from .music import MusicPlayer, SFXPlayer, NullPlayer 28 from .music import MusicPlayer, SFXPlayer, NullPlayer
29 from .shaders.eosd import GameShader, BackgroundShader 29 from .shaders.eosd import GameShader, BackgroundShader
30 30
31 from collections import namedtuple 31 from collections import namedtuple
33 Color = namedtuple('Color', 'r g b a') 33 Color = namedtuple('Color', 'r g b a')
34 34
35 logger = get_logger(__name__) 35 logger = get_logger(__name__)
36 36
37 37
38 class GameRunner(GameRenderer): 38 cdef class GameRunner(GameRenderer):
39 def __init__(self, window, resource_loader, replay=None, skip=False): 39 cdef Window window
40 cdef object replay_level, save_keystates
41 cdef long width, height, keystate
42 cdef bint skip
43
44 def __init__(self, window, resource_loader, bint skip=False):
40 self.use_fixed_pipeline = window.use_fixed_pipeline #XXX 45 self.use_fixed_pipeline = window.use_fixed_pipeline #XXX
41 46
42 GameRenderer.__init__(self, resource_loader) 47 GameRenderer.__init__(self, resource_loader)
43 48
44 self.window = window 49 self.window = window
112 # glDeleteBuffers(2, vbo_array) 117 # glDeleteBuffers(2, vbo_array)
113 pass 118 pass
114 119
115 120
116 def update(self): 121 def update(self):
122 cdef long keystate
123
117 if self.background: 124 if self.background:
118 self.background.update(self.game.frame) 125 self.background.update(self.game.frame)
119 for event in sdl.poll_events(): 126 for event in sdl.poll_events():
120 type_ = event[0] 127 type_ = event[0]
121 if type_ == sdl.KEYDOWN: 128 if type_ == sdl.KEYDOWN:
123 if scancode == sdl.SCANCODE_ESCAPE: 130 if scancode == sdl.SCANCODE_ESCAPE:
124 return False #TODO: implement the pause. 131 return False #TODO: implement the pause.
125 elif type_ == sdl.QUIT: 132 elif type_ == sdl.QUIT:
126 return False 133 return False
127 if self.game: 134 if self.game:
128 if not self.replay_level: 135 if self.replay_level is None:
129 #TODO: allow user settings 136 #TODO: allow user settings
130 keys = sdl.get_keyboard_state() 137 keys = sdl.get_keyboard_state()
131 keystate = 0 138 keystate = 0
132 if keys[sdl.SCANCODE_Z]: 139 if keys[sdl.SCANCODE_Z]:
133 keystate |= 1 140 keystate |= 1
215 interface = self.game.interface 222 interface = self.game.interface
216 interface.labels['framerate'].set_text('%.2ffps' % self.window.get_fps()) 223 interface.labels['framerate'].set_text('%.2ffps' % self.window.get_fps())
217 224
218 if self.use_fixed_pipeline: 225 if self.use_fixed_pipeline:
219 glMatrixMode(GL_MODELVIEW) 226 glMatrixMode(GL_MODELVIEW)
220 glLoadMatrixf((<Matrix>self.interface_mvp).data) 227 glLoadMatrixf(self.interface_mvp.data)
221 glDisable(GL_FOG) 228 glDisable(GL_FOG)
222 else: 229 else:
223 self.interface_shader.bind() 230 self.interface_shader.bind()
224 self.interface_shader.uniform_matrix('mvp', self.interface_mvp) 231 self.interface_shader.uniform_matrix('mvp', self.interface_mvp)
225 glViewport(0, 0, self.width, self.height) 232 glViewport(0, 0, self.width, self.height)