Mercurial > touhou
annotate 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 |
rev | line source |
---|---|
131
fab7ad2f0d8b
Use Cython, improve performances!
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
1 # -*- encoding: utf-8 -*- |
fab7ad2f0d8b
Use Cython, improve performances!
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
2 ## |
fab7ad2f0d8b
Use Cython, improve performances!
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
3 ## Copyright (C) 2011 Thibaut Girka <thib@sitedethib.com> |
fab7ad2f0d8b
Use Cython, improve performances!
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
4 ## |
fab7ad2f0d8b
Use Cython, improve performances!
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
5 ## This program is free software; you can redistribute it and/or modify |
fab7ad2f0d8b
Use Cython, improve performances!
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
6 ## it under the terms of the GNU General Public License as published |
fab7ad2f0d8b
Use Cython, improve performances!
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
7 ## by the Free Software Foundation; version 3 only. |
fab7ad2f0d8b
Use Cython, improve performances!
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
8 ## |
fab7ad2f0d8b
Use Cython, improve performances!
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
9 ## This program is distributed in the hope that it will be useful, |
fab7ad2f0d8b
Use Cython, improve performances!
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
10 ## but WITHOUT ANY WARRANTY; without even the implied warranty of |
fab7ad2f0d8b
Use Cython, improve performances!
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
11 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
fab7ad2f0d8b
Use Cython, improve performances!
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
12 ## GNU General Public License for more details. |
fab7ad2f0d8b
Use Cython, improve performances!
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
13 ## |
fab7ad2f0d8b
Use Cython, improve performances!
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
14 |
455
6864a38b2413
Make pytouhou.lib.sdl cimportable, and convert pytouhou.ui.window.* to extension types.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
438
diff
changeset
|
15 from pytouhou.lib cimport sdl |
146
96c30ffd9b87
Evil workaround to pyglet's X11 backend
Thibaut Girka <thib@sitedethib.com>
parents:
131
diff
changeset
|
16 |
423
d8630c086926
Replace Pyglet with our own Cython OpenGL wrapper.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
422
diff
changeset
|
17 from pytouhou.lib.opengl cimport \ |
d8630c086926
Replace Pyglet with our own Cython OpenGL wrapper.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
422
diff
changeset
|
18 (glMatrixMode, glEnable, glDisable, glViewport, glScissor, |
d8630c086926
Replace Pyglet with our own Cython OpenGL wrapper.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
422
diff
changeset
|
19 glLoadMatrixf, glGenBuffers, glDeleteBuffers, GL_MODELVIEW, |
427
0604f4fbbe3c
Move the depth buffer clear outside of scissor, as per apitrace’s advice.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
426
diff
changeset
|
20 GL_FOG, GL_SCISSOR_TEST, glClear, GL_DEPTH_BUFFER_BIT) |
131
fab7ad2f0d8b
Use Cython, improve performances!
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
21 |
224
9bb26dbb8438
Remove useless and occasionally problematic (think about non-utf8 terminals) print calls.
Thibaut Girka <thib@sitedethib.com>
parents:
205
diff
changeset
|
22 from pytouhou.utils.helpers import get_logger |
423
d8630c086926
Replace Pyglet with our own Cython OpenGL wrapper.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
422
diff
changeset
|
23 from pytouhou.utils.maths cimport perspective, setup_camera, ortho_2d |
224
9bb26dbb8438
Remove useless and occasionally problematic (think about non-utf8 terminals) print calls.
Thibaut Girka <thib@sitedethib.com>
parents:
205
diff
changeset
|
24 |
458
1b56d62250ab
Make pytouhou.ui.{window,shader,game{runner,renderer}} extension types.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
456
diff
changeset
|
25 from .window cimport Window |
1b56d62250ab
Make pytouhou.ui.{window,shader,game{runner,renderer}} extension types.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
456
diff
changeset
|
26 from .gamerenderer cimport GameRenderer |
423
d8630c086926
Replace Pyglet with our own Cython OpenGL wrapper.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
422
diff
changeset
|
27 from .background import BackgroundRenderer |
379
e0e284fcb288
Make a sound when an enemy is hit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
378
diff
changeset
|
28 from .music import MusicPlayer, SFXPlayer, NullPlayer |
370
74471afbac37
Add a programmable pipeline renderer, and a --fixed-pipeline switch to use the old one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
353
diff
changeset
|
29 from .shaders.eosd import GameShader, BackgroundShader |
131
fab7ad2f0d8b
Use Cython, improve performances!
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
30 |
456
cae1ae9de430
Add native text support, MSG instructions 3 and 8, and text at the beginning of a stage.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
455
diff
changeset
|
31 from collections import namedtuple |
cae1ae9de430
Add native text support, MSG instructions 3 and 8, and text at the beginning of a stage.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
455
diff
changeset
|
32 Rect = namedtuple('Rect', 'x y w h') |
cae1ae9de430
Add native text support, MSG instructions 3 and 8, and text at the beginning of a stage.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
455
diff
changeset
|
33 Color = namedtuple('Color', 'r g b a') |
131
fab7ad2f0d8b
Use Cython, improve performances!
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
34 |
224
9bb26dbb8438
Remove useless and occasionally problematic (think about non-utf8 terminals) print calls.
Thibaut Girka <thib@sitedethib.com>
parents:
205
diff
changeset
|
35 logger = get_logger(__name__) |
9bb26dbb8438
Remove useless and occasionally problematic (think about non-utf8 terminals) print calls.
Thibaut Girka <thib@sitedethib.com>
parents:
205
diff
changeset
|
36 |
9bb26dbb8438
Remove useless and occasionally problematic (think about non-utf8 terminals) print calls.
Thibaut Girka <thib@sitedethib.com>
parents:
205
diff
changeset
|
37 |
458
1b56d62250ab
Make pytouhou.ui.{window,shader,game{runner,renderer}} extension types.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
456
diff
changeset
|
38 cdef class GameRunner(GameRenderer): |
1b56d62250ab
Make pytouhou.ui.{window,shader,game{runner,renderer}} extension types.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
456
diff
changeset
|
39 cdef Window window |
1b56d62250ab
Make pytouhou.ui.{window,shader,game{runner,renderer}} extension types.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
456
diff
changeset
|
40 cdef object replay_level, save_keystates |
1b56d62250ab
Make pytouhou.ui.{window,shader,game{runner,renderer}} extension types.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
456
diff
changeset
|
41 cdef long width, height, keystate |
1b56d62250ab
Make pytouhou.ui.{window,shader,game{runner,renderer}} extension types.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
456
diff
changeset
|
42 cdef bint skip |
1b56d62250ab
Make pytouhou.ui.{window,shader,game{runner,renderer}} extension types.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
456
diff
changeset
|
43 |
1b56d62250ab
Make pytouhou.ui.{window,shader,game{runner,renderer}} extension types.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
456
diff
changeset
|
44 def __init__(self, window, resource_loader, bint skip=False): |
423
d8630c086926
Replace Pyglet with our own Cython OpenGL wrapper.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
422
diff
changeset
|
45 self.use_fixed_pipeline = window.use_fixed_pipeline #XXX |
d8630c086926
Replace Pyglet with our own Cython OpenGL wrapper.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
422
diff
changeset
|
46 |
422
52829ebe2561
Refactor window management in its own class.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
421
diff
changeset
|
47 GameRenderer.__init__(self, resource_loader) |
419
1c92721f8e49
Re-implement frame control
Thibaut Girka <thib@sitedethib.com>
parents:
418
diff
changeset
|
48 |
422
52829ebe2561
Refactor window management in its own class.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
421
diff
changeset
|
49 self.window = window |
187
46793ccfedca
Implement replays.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
158
diff
changeset
|
50 self.replay_level = None |
378
11d895b6c0dc
Add the debug feature to start a game at the end of a replay.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
374
diff
changeset
|
51 self.skip = skip |
418
63f59be04a54
Replace Pyglet with SDL2 for window creation and events; disables framerate control/display and sound.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
412
diff
changeset
|
52 self.keystate = 0 |
331
1b4f04b08729
Add the story mode.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
330
diff
changeset
|
53 |
422
52829ebe2561
Refactor window management in its own class.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
421
diff
changeset
|
54 self.width = window.width #XXX |
52829ebe2561
Refactor window management in its own class.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
421
diff
changeset
|
55 self.height = window.height #XXX |
52829ebe2561
Refactor window management in its own class.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
421
diff
changeset
|
56 |
370
74471afbac37
Add a programmable pipeline renderer, and a --fixed-pipeline switch to use the old one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
353
diff
changeset
|
57 if not self.use_fixed_pipeline: |
74471afbac37
Add a programmable pipeline renderer, and a --fixed-pipeline switch to use the old one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
353
diff
changeset
|
58 self.game_shader = GameShader() |
74471afbac37
Add a programmable pipeline renderer, and a --fixed-pipeline switch to use the old one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
353
diff
changeset
|
59 self.background_shader = BackgroundShader() |
74471afbac37
Add a programmable pipeline renderer, and a --fixed-pipeline switch to use the old one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
353
diff
changeset
|
60 self.interface_shader = self.game_shader |
74471afbac37
Add a programmable pipeline renderer, and a --fixed-pipeline switch to use the old one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
353
diff
changeset
|
61 |
330
16ed1ab1e14b
Add a GameRunner.load_game method to allow level changes.
Thibaut Girka <thib@sitedethib.com>
parents:
323
diff
changeset
|
62 |
373
6deab6ad8be8
Add the ability to save a replay.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
370
diff
changeset
|
63 def load_game(self, game=None, background=None, bgms=None, replay=None, save_keystates=None): |
422
52829ebe2561
Refactor window management in its own class.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
421
diff
changeset
|
64 self.game = game |
52829ebe2561
Refactor window management in its own class.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
421
diff
changeset
|
65 self.background = background |
52829ebe2561
Refactor window management in its own class.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
421
diff
changeset
|
66 |
426
5d7bb2fd74f7
Never keep texture on the host when it has been uploaded, and prevent them from being decoded again.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
424
diff
changeset
|
67 self.texture_manager.load(game.resource_loader.instanced_anms.values()) |
422
52829ebe2561
Refactor window management in its own class.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
421
diff
changeset
|
68 |
52829ebe2561
Refactor window management in its own class.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
421
diff
changeset
|
69 if background: |
426
5d7bb2fd74f7
Never keep texture on the host when it has been uploaded, and prevent them from being decoded again.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
424
diff
changeset
|
70 self.background_renderer = BackgroundRenderer(self.use_fixed_pipeline) |
423
d8630c086926
Replace Pyglet with our own Cython OpenGL wrapper.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
422
diff
changeset
|
71 self.background_renderer.prerender(background) |
422
52829ebe2561
Refactor window management in its own class.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
421
diff
changeset
|
72 |
378
11d895b6c0dc
Add the debug feature to start a game at the end of a replay.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
374
diff
changeset
|
73 self.set_input(replay) |
11d895b6c0dc
Add the debug feature to start a game at the end of a replay.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
374
diff
changeset
|
74 if replay and replay.levels[game.stage - 1]: |
341
61caded6b4f5
Clean music playback API a little.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
334
diff
changeset
|
75 game.players[0].state.lives = self.replay_level.lives |
61caded6b4f5
Clean music playback API a little.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
334
diff
changeset
|
76 game.players[0].state.power = self.replay_level.power |
61caded6b4f5
Clean music playback API a little.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
334
diff
changeset
|
77 game.players[0].state.bombs = self.replay_level.bombs |
61caded6b4f5
Clean music playback API a little.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
334
diff
changeset
|
78 game.difficulty = self.replay_level.difficulty |
61caded6b4f5
Clean music playback API a little.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
334
diff
changeset
|
79 |
373
6deab6ad8be8
Add the ability to save a replay.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
370
diff
changeset
|
80 self.save_keystates = save_keystates |
6deab6ad8be8
Add the ability to save a replay.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
370
diff
changeset
|
81 |
428
f41a26971a19
Remove all Loader uses from outside pytouhou.games, and add a --no-music option to disable bgm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
427
diff
changeset
|
82 null_player = NullPlayer() |
f41a26971a19
Remove all Loader uses from outside pytouhou.games, and add a --no-music option to disable bgm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
427
diff
changeset
|
83 if bgms: |
f41a26971a19
Remove all Loader uses from outside pytouhou.games, and add a --no-music option to disable bgm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
427
diff
changeset
|
84 game.music = MusicPlayer(game.resource_loader, bgms) |
f41a26971a19
Remove all Loader uses from outside pytouhou.games, and add a --no-music option to disable bgm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
427
diff
changeset
|
85 game.music.play(0) |
f41a26971a19
Remove all Loader uses from outside pytouhou.games, and add a --no-music option to disable bgm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
427
diff
changeset
|
86 else: |
f41a26971a19
Remove all Loader uses from outside pytouhou.games, and add a --no-music option to disable bgm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
427
diff
changeset
|
87 game.music = null_player |
f41a26971a19
Remove all Loader uses from outside pytouhou.games, and add a --no-music option to disable bgm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
427
diff
changeset
|
88 |
f41a26971a19
Remove all Loader uses from outside pytouhou.games, and add a --no-music option to disable bgm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
427
diff
changeset
|
89 game.sfx_player = SFXPlayer(game.resource_loader) if not self.skip else null_player |
343
94fdb6c782c1
Implement sfx for player and enemies.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
341
diff
changeset
|
90 |
131
fab7ad2f0d8b
Use Cython, improve performances!
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
91 |
378
11d895b6c0dc
Add the debug feature to start a game at the end of a replay.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
374
diff
changeset
|
92 def set_input(self, replay=None): |
11d895b6c0dc
Add the debug feature to start a game at the end of a replay.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
374
diff
changeset
|
93 if not replay or not replay.levels[self.game.stage-1]: |
11d895b6c0dc
Add the debug feature to start a game at the end of a replay.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
374
diff
changeset
|
94 self.replay_level = None |
11d895b6c0dc
Add the debug feature to start a game at the end of a replay.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
374
diff
changeset
|
95 else: |
11d895b6c0dc
Add the debug feature to start a game at the end of a replay.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
374
diff
changeset
|
96 self.replay_level = replay.levels[self.game.stage-1] |
11d895b6c0dc
Add the debug feature to start a game at the end of a replay.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
374
diff
changeset
|
97 self.keys = self.replay_level.iter_keystates() |
11d895b6c0dc
Add the debug feature to start a game at the end of a replay.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
374
diff
changeset
|
98 |
11d895b6c0dc
Add the debug feature to start a game at the end of a replay.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
374
diff
changeset
|
99 |
422
52829ebe2561
Refactor window management in its own class.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
421
diff
changeset
|
100 def start(self): |
52829ebe2561
Refactor window management in its own class.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
421
diff
changeset
|
101 width = self.game.interface.width if self.game else 640 |
52829ebe2561
Refactor window management in its own class.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
421
diff
changeset
|
102 height = self.game.interface.height if self.game else 480 |
225
2d35565b5608
Move game size in the game's definition, and don't keep changing the window's size.
Thibaut Girka <thib@sitedethib.com>
parents:
224
diff
changeset
|
103 if (width, height) != (self.width, self.height): |
422
52829ebe2561
Refactor window management in its own class.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
421
diff
changeset
|
104 self.window.set_size(width, height) |
131
fab7ad2f0d8b
Use Cython, improve performances!
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
105 |
412
5fe6cd6ceb48
Refactor the maths functions out of Renderer.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
399
diff
changeset
|
106 self.proj = perspective(30, float(self.game.width) / float(self.game.height), |
5fe6cd6ceb48
Refactor the maths functions out of Renderer.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
399
diff
changeset
|
107 101010101./2010101., 101010101./10101.) |
5fe6cd6ceb48
Refactor the maths functions out of Renderer.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
399
diff
changeset
|
108 game_view = setup_camera(0, 0, 1) |
370
74471afbac37
Add a programmable pipeline renderer, and a --fixed-pipeline switch to use the old one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
353
diff
changeset
|
109 self.game_mvp = game_view * self.proj |
412
5fe6cd6ceb48
Refactor the maths functions out of Renderer.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
399
diff
changeset
|
110 self.interface_mvp = ortho_2d(0., float(self.width), float(self.height), 0.) |
370
74471afbac37
Add a programmable pipeline renderer, and a --fixed-pipeline switch to use the old one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
353
diff
changeset
|
111 |
131
fab7ad2f0d8b
Use Cython, improve performances!
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
112 |
422
52829ebe2561
Refactor window management in its own class.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
421
diff
changeset
|
113 def finish(self): |
52829ebe2561
Refactor window management in its own class.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
421
diff
changeset
|
114 #TODO: actually clean after buffers are not needed anymore. |
52829ebe2561
Refactor window management in its own class.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
421
diff
changeset
|
115 #if not self.use_fixed_pipeline: |
52829ebe2561
Refactor window management in its own class.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
421
diff
changeset
|
116 # vbo_array = (c_uint * 2)(self.vbo, self.back_vbo) |
52829ebe2561
Refactor window management in its own class.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
421
diff
changeset
|
117 # glDeleteBuffers(2, vbo_array) |
52829ebe2561
Refactor window management in its own class.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
421
diff
changeset
|
118 pass |
131
fab7ad2f0d8b
Use Cython, improve performances!
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
119 |
fab7ad2f0d8b
Use Cython, improve performances!
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
120 |
fab7ad2f0d8b
Use Cython, improve performances!
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
121 def update(self): |
458
1b56d62250ab
Make pytouhou.ui.{window,shader,game{runner,renderer}} extension types.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
456
diff
changeset
|
122 cdef long keystate |
1b56d62250ab
Make pytouhou.ui.{window,shader,game{runner,renderer}} extension types.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
456
diff
changeset
|
123 |
131
fab7ad2f0d8b
Use Cython, improve performances!
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
124 if self.background: |
151
5cf927cbd9c5
Merge GameState into Game. TODO: Merge PlayerState into Player
Thibaut Girka <thib@sitedethib.com>
parents:
146
diff
changeset
|
125 self.background.update(self.game.frame) |
418
63f59be04a54
Replace Pyglet with SDL2 for window creation and events; disables framerate control/display and sound.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
412
diff
changeset
|
126 for event in sdl.poll_events(): |
63f59be04a54
Replace Pyglet with SDL2 for window creation and events; disables framerate control/display and sound.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
412
diff
changeset
|
127 type_ = event[0] |
63f59be04a54
Replace Pyglet with SDL2 for window creation and events; disables framerate control/display and sound.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
412
diff
changeset
|
128 if type_ == sdl.KEYDOWN: |
63f59be04a54
Replace Pyglet with SDL2 for window creation and events; disables framerate control/display and sound.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
412
diff
changeset
|
129 scancode = event[1] |
63f59be04a54
Replace Pyglet with SDL2 for window creation and events; disables framerate control/display and sound.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
412
diff
changeset
|
130 if scancode == sdl.SCANCODE_ESCAPE: |
422
52829ebe2561
Refactor window management in its own class.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
421
diff
changeset
|
131 return False #TODO: implement the pause. |
418
63f59be04a54
Replace Pyglet with SDL2 for window creation and events; disables framerate control/display and sound.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
412
diff
changeset
|
132 elif type_ == sdl.QUIT: |
422
52829ebe2561
Refactor window management in its own class.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
421
diff
changeset
|
133 return False |
131
fab7ad2f0d8b
Use Cython, improve performances!
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
134 if self.game: |
458
1b56d62250ab
Make pytouhou.ui.{window,shader,game{runner,renderer}} extension types.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
456
diff
changeset
|
135 if self.replay_level is None: |
187
46793ccfedca
Implement replays.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
158
diff
changeset
|
136 #TODO: allow user settings |
418
63f59be04a54
Replace Pyglet with SDL2 for window creation and events; disables framerate control/display and sound.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
412
diff
changeset
|
137 keys = sdl.get_keyboard_state() |
187
46793ccfedca
Implement replays.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
158
diff
changeset
|
138 keystate = 0 |
418
63f59be04a54
Replace Pyglet with SDL2 for window creation and events; disables framerate control/display and sound.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
412
diff
changeset
|
139 if keys[sdl.SCANCODE_Z]: |
187
46793ccfedca
Implement replays.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
158
diff
changeset
|
140 keystate |= 1 |
418
63f59be04a54
Replace Pyglet with SDL2 for window creation and events; disables framerate control/display and sound.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
412
diff
changeset
|
141 if keys[sdl.SCANCODE_X]: |
187
46793ccfedca
Implement replays.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
158
diff
changeset
|
142 keystate |= 2 |
418
63f59be04a54
Replace Pyglet with SDL2 for window creation and events; disables framerate control/display and sound.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
412
diff
changeset
|
143 if keys[sdl.SCANCODE_LSHIFT]: |
187
46793ccfedca
Implement replays.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
158
diff
changeset
|
144 keystate |= 4 |
418
63f59be04a54
Replace Pyglet with SDL2 for window creation and events; disables framerate control/display and sound.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
412
diff
changeset
|
145 if keys[sdl.SCANCODE_UP]: |
187
46793ccfedca
Implement replays.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
158
diff
changeset
|
146 keystate |= 16 |
418
63f59be04a54
Replace Pyglet with SDL2 for window creation and events; disables framerate control/display and sound.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
412
diff
changeset
|
147 if keys[sdl.SCANCODE_DOWN]: |
187
46793ccfedca
Implement replays.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
158
diff
changeset
|
148 keystate |= 32 |
418
63f59be04a54
Replace Pyglet with SDL2 for window creation and events; disables framerate control/display and sound.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
412
diff
changeset
|
149 if keys[sdl.SCANCODE_LEFT]: |
187
46793ccfedca
Implement replays.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
158
diff
changeset
|
150 keystate |= 64 |
418
63f59be04a54
Replace Pyglet with SDL2 for window creation and events; disables framerate control/display and sound.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
412
diff
changeset
|
151 if keys[sdl.SCANCODE_RIGHT]: |
187
46793ccfedca
Implement replays.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
158
diff
changeset
|
152 keystate |= 128 |
418
63f59be04a54
Replace Pyglet with SDL2 for window creation and events; disables framerate control/display and sound.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
412
diff
changeset
|
153 if keys[sdl.SCANCODE_LCTRL]: |
187
46793ccfedca
Implement replays.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
158
diff
changeset
|
154 keystate |= 256 |
46793ccfedca
Implement replays.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
158
diff
changeset
|
155 else: |
374
6a63fd3deb76
Use an iterator to get the keystates from a replay.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
373
diff
changeset
|
156 try: |
6a63fd3deb76
Use an iterator to get the keystates from a replay.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
373
diff
changeset
|
157 keystate = self.keys.next() |
6a63fd3deb76
Use an iterator to get the keystates from a replay.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
373
diff
changeset
|
158 except StopIteration: |
6a63fd3deb76
Use an iterator to get the keystates from a replay.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
373
diff
changeset
|
159 keystate = 0 |
378
11d895b6c0dc
Add the debug feature to start a game at the end of a replay.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
374
diff
changeset
|
160 if self.skip: |
11d895b6c0dc
Add the debug feature to start a game at the end of a replay.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
374
diff
changeset
|
161 self.set_input() |
11d895b6c0dc
Add the debug feature to start a game at the end of a replay.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
374
diff
changeset
|
162 self.skip = False |
379
e0e284fcb288
Make a sound when an enemy is hit.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
378
diff
changeset
|
163 self.game.sfx_player = SFXPlayer(self.game.resource_loader) |
187
46793ccfedca
Implement replays.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
158
diff
changeset
|
164 |
373
6deab6ad8be8
Add the ability to save a replay.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
370
diff
changeset
|
165 if self.save_keystates is not None: |
6deab6ad8be8
Add the ability to save a replay.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
370
diff
changeset
|
166 self.save_keystates.append(keystate) |
6deab6ad8be8
Add the ability to save a replay.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
370
diff
changeset
|
167 |
331
1b4f04b08729
Add the story mode.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
330
diff
changeset
|
168 self.game.run_iter(keystate) |
422
52829ebe2561
Refactor window management in its own class.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
421
diff
changeset
|
169 if not self.skip: |
52829ebe2561
Refactor window management in its own class.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
421
diff
changeset
|
170 self.render_game() |
456
cae1ae9de430
Add native text support, MSG instructions 3 and 8, and text at the beginning of a stage.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
455
diff
changeset
|
171 self.render_text() |
422
52829ebe2561
Refactor window management in its own class.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
421
diff
changeset
|
172 self.render_interface() |
52829ebe2561
Refactor window management in its own class.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
421
diff
changeset
|
173 return True |
131
fab7ad2f0d8b
Use Cython, improve performances!
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
174 |
fab7ad2f0d8b
Use Cython, improve performances!
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
175 |
300
da53bc29b94a
Add the game interface.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
233
diff
changeset
|
176 def render_game(self): |
225
2d35565b5608
Move game size in the game's definition, and don't keep changing the window's size.
Thibaut Girka <thib@sitedethib.com>
parents:
224
diff
changeset
|
177 # Switch to game projection |
2d35565b5608
Move game size in the game's definition, and don't keep changing the window's size.
Thibaut Girka <thib@sitedethib.com>
parents:
224
diff
changeset
|
178 #TODO: move that to GameRenderer? |
300
da53bc29b94a
Add the game interface.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
233
diff
changeset
|
179 x, y = self.game.interface.game_pos |
da53bc29b94a
Add the game interface.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
233
diff
changeset
|
180 glViewport(x, y, self.game.width, self.game.height) |
427
0604f4fbbe3c
Move the depth buffer clear outside of scissor, as per apitrace’s advice.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
426
diff
changeset
|
181 glClear(GL_DEPTH_BUFFER_BIT) |
300
da53bc29b94a
Add the game interface.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
233
diff
changeset
|
182 glScissor(x, y, self.game.width, self.game.height) |
da53bc29b94a
Add the game interface.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
233
diff
changeset
|
183 glEnable(GL_SCISSOR_TEST) |
225
2d35565b5608
Move game size in the game's definition, and don't keep changing the window's size.
Thibaut Girka <thib@sitedethib.com>
parents:
224
diff
changeset
|
184 |
131
fab7ad2f0d8b
Use Cython, improve performances!
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
185 GameRenderer.render(self) |
fab7ad2f0d8b
Use Cython, improve performances!
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
186 |
300
da53bc29b94a
Add the game interface.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
233
diff
changeset
|
187 glDisable(GL_SCISSOR_TEST) |
da53bc29b94a
Add the game interface.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
233
diff
changeset
|
188 |
456
cae1ae9de430
Add native text support, MSG instructions 3 and 8, and text at the beginning of a stage.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
455
diff
changeset
|
189 if self.game.msg_runner: |
cae1ae9de430
Add native text support, MSG instructions 3 and 8, and text at the beginning of a stage.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
455
diff
changeset
|
190 rect = Rect(48, 368, 288, 48) |
cae1ae9de430
Add native text support, MSG instructions 3 and 8, and text at the beginning of a stage.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
455
diff
changeset
|
191 color1 = Color(0, 0, 0, 192) |
cae1ae9de430
Add native text support, MSG instructions 3 and 8, and text at the beginning of a stage.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
455
diff
changeset
|
192 color2 = Color(0, 0, 0, 128) |
cae1ae9de430
Add native text support, MSG instructions 3 and 8, and text at the beginning of a stage.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
455
diff
changeset
|
193 self.render_quads([rect], [(color1, color1, color2, color2)], 0) |
cae1ae9de430
Add native text support, MSG instructions 3 and 8, and text at the beginning of a stage.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
455
diff
changeset
|
194 |
cae1ae9de430
Add native text support, MSG instructions 3 and 8, and text at the beginning of a stage.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
455
diff
changeset
|
195 |
cae1ae9de430
Add native text support, MSG instructions 3 and 8, and text at the beginning of a stage.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
455
diff
changeset
|
196 def render_text(self): |
cae1ae9de430
Add native text support, MSG instructions 3 and 8, and text at the beginning of a stage.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
455
diff
changeset
|
197 if self.font_manager is None: |
cae1ae9de430
Add native text support, MSG instructions 3 and 8, and text at the beginning of a stage.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
455
diff
changeset
|
198 return |
cae1ae9de430
Add native text support, MSG instructions 3 and 8, and text at the beginning of a stage.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
455
diff
changeset
|
199 |
cae1ae9de430
Add native text support, MSG instructions 3 and 8, and text at the beginning of a stage.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
455
diff
changeset
|
200 labels = [label for label in self.game.texts + self.game.native_texts if label is not None] |
cae1ae9de430
Add native text support, MSG instructions 3 and 8, and text at the beginning of a stage.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
455
diff
changeset
|
201 self.font_manager.load(labels) |
cae1ae9de430
Add native text support, MSG instructions 3 and 8, and text at the beginning of a stage.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
455
diff
changeset
|
202 |
cae1ae9de430
Add native text support, MSG instructions 3 and 8, and text at the beginning of a stage.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
455
diff
changeset
|
203 black = Color(0, 0, 0, 255) |
cae1ae9de430
Add native text support, MSG instructions 3 and 8, and text at the beginning of a stage.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
455
diff
changeset
|
204 |
cae1ae9de430
Add native text support, MSG instructions 3 and 8, and text at the beginning of a stage.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
455
diff
changeset
|
205 for label in labels: |
cae1ae9de430
Add native text support, MSG instructions 3 and 8, and text at the beginning of a stage.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
455
diff
changeset
|
206 if label is None: |
cae1ae9de430
Add native text support, MSG instructions 3 and 8, and text at the beginning of a stage.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
455
diff
changeset
|
207 continue |
cae1ae9de430
Add native text support, MSG instructions 3 and 8, and text at the beginning of a stage.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
455
diff
changeset
|
208 |
cae1ae9de430
Add native text support, MSG instructions 3 and 8, and text at the beginning of a stage.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
455
diff
changeset
|
209 rect = Rect(label.x, label.y, label.width, label.height) |
cae1ae9de430
Add native text support, MSG instructions 3 and 8, and text at the beginning of a stage.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
455
diff
changeset
|
210 gradient = [Color(*color, a=label.alpha) for color in label.gradient] |
cae1ae9de430
Add native text support, MSG instructions 3 and 8, and text at the beginning of a stage.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
455
diff
changeset
|
211 |
cae1ae9de430
Add native text support, MSG instructions 3 and 8, and text at the beginning of a stage.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
455
diff
changeset
|
212 if label.shadow: |
cae1ae9de430
Add native text support, MSG instructions 3 and 8, and text at the beginning of a stage.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
455
diff
changeset
|
213 shadow_rect = Rect(label.x + 1, label.y + 1, label.width, label.height) |
cae1ae9de430
Add native text support, MSG instructions 3 and 8, and text at the beginning of a stage.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
455
diff
changeset
|
214 shadow = [black._replace(a=label.alpha)] * 4 |
cae1ae9de430
Add native text support, MSG instructions 3 and 8, and text at the beginning of a stage.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
455
diff
changeset
|
215 self.render_quads([shadow_rect, rect], [shadow, gradient], label.texture) |
cae1ae9de430
Add native text support, MSG instructions 3 and 8, and text at the beginning of a stage.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
455
diff
changeset
|
216 else: |
cae1ae9de430
Add native text support, MSG instructions 3 and 8, and text at the beginning of a stage.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
455
diff
changeset
|
217 self.render_quads([rect], [gradient], label.texture) |
cae1ae9de430
Add native text support, MSG instructions 3 and 8, and text at the beginning of a stage.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
455
diff
changeset
|
218 |
300
da53bc29b94a
Add the game interface.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
233
diff
changeset
|
219 |
da53bc29b94a
Add the game interface.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
233
diff
changeset
|
220 def render_interface(self): |
438
43a8fed9a8d8
Make only one call to render_elements during interface rendering.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
435
diff
changeset
|
221 elements = [] |
300
da53bc29b94a
Add the game interface.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
233
diff
changeset
|
222 interface = self.game.interface |
455
6864a38b2413
Make pytouhou.lib.sdl cimportable, and convert pytouhou.ui.window.* to extension types.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
438
diff
changeset
|
223 interface.labels['framerate'].set_text('%.2ffps' % self.window.get_fps()) |
300
da53bc29b94a
Add the game interface.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
233
diff
changeset
|
224 |
370
74471afbac37
Add a programmable pipeline renderer, and a --fixed-pipeline switch to use the old one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
353
diff
changeset
|
225 if self.use_fixed_pipeline: |
74471afbac37
Add a programmable pipeline renderer, and a --fixed-pipeline switch to use the old one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
353
diff
changeset
|
226 glMatrixMode(GL_MODELVIEW) |
458
1b56d62250ab
Make pytouhou.ui.{window,shader,game{runner,renderer}} extension types.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
456
diff
changeset
|
227 glLoadMatrixf(self.interface_mvp.data) |
370
74471afbac37
Add a programmable pipeline renderer, and a --fixed-pipeline switch to use the old one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
353
diff
changeset
|
228 glDisable(GL_FOG) |
74471afbac37
Add a programmable pipeline renderer, and a --fixed-pipeline switch to use the old one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
353
diff
changeset
|
229 else: |
74471afbac37
Add a programmable pipeline renderer, and a --fixed-pipeline switch to use the old one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
353
diff
changeset
|
230 self.interface_shader.bind() |
424
f4d76d3d6f2a
Make the Shader class use cython too.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
423
diff
changeset
|
231 self.interface_shader.uniform_matrix('mvp', self.interface_mvp) |
300
da53bc29b94a
Add the game interface.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
233
diff
changeset
|
232 glViewport(0, 0, self.width, self.height) |
225
2d35565b5608
Move game size in the game's definition, and don't keep changing the window's size.
Thibaut Girka <thib@sitedethib.com>
parents:
224
diff
changeset
|
233 |
304
f3099ebf4f61
Update attribute names to reflect the actual interface.
Thibaut Girka <thib@sitedethib.com>
parents:
300
diff
changeset
|
234 items = [item for item in interface.items if item.anmrunner and item.anmrunner.running] |
323
2fcdb8966957
Display lives and bombs.
Thibaut Girka <thib@sitedethib.com>
parents:
321
diff
changeset
|
235 labels = interface.labels.values() |
2fcdb8966957
Display lives and bombs.
Thibaut Girka <thib@sitedethib.com>
parents:
321
diff
changeset
|
236 |
300
da53bc29b94a
Add the game interface.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
233
diff
changeset
|
237 if items: |
323
2fcdb8966957
Display lives and bombs.
Thibaut Girka <thib@sitedethib.com>
parents:
321
diff
changeset
|
238 # Redraw all the interface |
438
43a8fed9a8d8
Make only one call to render_elements during interface rendering.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
435
diff
changeset
|
239 elements.extend(items) |
300
da53bc29b94a
Add the game interface.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
233
diff
changeset
|
240 else: |
323
2fcdb8966957
Display lives and bombs.
Thibaut Girka <thib@sitedethib.com>
parents:
321
diff
changeset
|
241 # Redraw only changed labels |
2fcdb8966957
Display lives and bombs.
Thibaut Girka <thib@sitedethib.com>
parents:
321
diff
changeset
|
242 labels = [label for label in labels if label.changed] |
2fcdb8966957
Display lives and bombs.
Thibaut Girka <thib@sitedethib.com>
parents:
321
diff
changeset
|
243 |
438
43a8fed9a8d8
Make only one call to render_elements during interface rendering.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
435
diff
changeset
|
244 elements.extend(interface.level_start) |
387
e1f5dcd4b83e
Display something at the start of a stage.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
384
diff
changeset
|
245 |
345
2c4589370cc6
Display a boss remaining lives and timeout.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
343
diff
changeset
|
246 if self.game.boss: |
438
43a8fed9a8d8
Make only one call to render_elements during interface rendering.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
435
diff
changeset
|
247 elements.extend(interface.boss_items) |
345
2c4589370cc6
Display a boss remaining lives and timeout.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
343
diff
changeset
|
248 |
438
43a8fed9a8d8
Make only one call to render_elements during interface rendering.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
435
diff
changeset
|
249 elements.extend(labels) |
43a8fed9a8d8
Make only one call to render_elements during interface rendering.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
435
diff
changeset
|
250 self.render_elements(elements) |
323
2fcdb8966957
Display lives and bombs.
Thibaut Girka <thib@sitedethib.com>
parents:
321
diff
changeset
|
251 for label in labels: |
304
f3099ebf4f61
Update attribute names to reflect the actual interface.
Thibaut Girka <thib@sitedethib.com>
parents:
300
diff
changeset
|
252 label.changed = False |
131
fab7ad2f0d8b
Use Cython, improve performances!
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
253 |