annotate pytouhou/ui/gamerunner.py @ 484:699c8e8c7738

Don't stick with the remote user unless the game has started, avoid skipping to prevent desynchro
author Thibaut Girka <thib@sitedethib.com>
date Thu, 29 Dec 2011 10:35:54 +0100
parents e71b1bcf952a
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
fab7ad2f0d8b Use Cython, improve performances!
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
15 import pyglet
146
96c30ffd9b87 Evil workaround to pyglet's X11 backend
Thibaut Girka <thib@sitedethib.com>
parents: 131
diff changeset
16 import traceback
96c30ffd9b87 Evil workaround to pyglet's X11 backend
Thibaut Girka <thib@sitedethib.com>
parents: 131
diff changeset
17
203
df8b2ab54639 Make pylint slightly happier (and code analysis easier)
Thibaut Girka <thib@sitedethib.com>
parents: 188
diff changeset
18 from pyglet.gl import (glMatrixMode, glLoadIdentity, glEnable,
df8b2ab54639 Make pylint slightly happier (and code analysis easier)
Thibaut Girka <thib@sitedethib.com>
parents: 188
diff changeset
19 glHint, glEnableClientState, glViewport,
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
20 gluPerspective, gluOrtho2D,
203
df8b2ab54639 Make pylint slightly happier (and code analysis easier)
Thibaut Girka <thib@sitedethib.com>
parents: 188
diff changeset
21 GL_MODELVIEW, GL_PROJECTION,
df8b2ab54639 Make pylint slightly happier (and code analysis easier)
Thibaut Girka <thib@sitedethib.com>
parents: 188
diff changeset
22 GL_TEXTURE_2D, GL_BLEND, GL_FOG,
df8b2ab54639 Make pylint slightly happier (and code analysis easier)
Thibaut Girka <thib@sitedethib.com>
parents: 188
diff changeset
23 GL_PERSPECTIVE_CORRECTION_HINT, GL_FOG_HINT, GL_NICEST,
df8b2ab54639 Make pylint slightly happier (and code analysis easier)
Thibaut Girka <thib@sitedethib.com>
parents: 188
diff changeset
24 GL_COLOR_ARRAY, GL_VERTEX_ARRAY, GL_TEXTURE_COORD_ARRAY)
131
fab7ad2f0d8b Use Cython, improve performances!
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
25
224
9bb26dbb8438 Remove useless and occasionally problematic (think about non-utf8 terminals) print calls.
Thibaut Girka <thib@sitedethib.com>
parents: 205
diff changeset
26 from pytouhou.utils.helpers import get_logger
9bb26dbb8438 Remove useless and occasionally problematic (think about non-utf8 terminals) print calls.
Thibaut Girka <thib@sitedethib.com>
parents: 205
diff changeset
27
205
ee6dfd14a785 Rename pytouhou.opengl to pytouhou.ui, makes much more sense that way.
Thibaut Girka <thib@sitedethib.com>
parents: 203
diff changeset
28 from .gamerenderer import GameRenderer
131
fab7ad2f0d8b Use Cython, improve performances!
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
29
fab7ad2f0d8b Use Cython, improve performances!
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
30
224
9bb26dbb8438 Remove useless and occasionally problematic (think about non-utf8 terminals) print calls.
Thibaut Girka <thib@sitedethib.com>
parents: 205
diff changeset
31 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
32
9bb26dbb8438 Remove useless and occasionally problematic (think about non-utf8 terminals) print calls.
Thibaut Girka <thib@sitedethib.com>
parents: 205
diff changeset
33
131
fab7ad2f0d8b Use Cython, improve performances!
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
34 class GameRunner(pyglet.window.Window, GameRenderer):
475
9d4d52793eca Experimental netplay! Yay!
Thibaut Girka <thib@sitedethib.com>
parents: 225
diff changeset
35 def __init__(self, resource_loader, game=None, background=None, replay=None,
9d4d52793eca Experimental netplay! Yay!
Thibaut Girka <thib@sitedethib.com>
parents: 225
diff changeset
36 con=None):
131
fab7ad2f0d8b Use Cython, improve performances!
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
37 GameRenderer.__init__(self, resource_loader, game, background)
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
38
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
39 width, height = (game.width, game.height) if game else (None, None)
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
40 pyglet.window.Window.__init__(self, width=width, height=height,
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
41 caption='PyTouhou', resizable=False)
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
42
475
9d4d52793eca Experimental netplay! Yay!
Thibaut Girka <thib@sitedethib.com>
parents: 225
diff changeset
43 self.con = con
187
46793ccfedca Implement replays.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 158
diff changeset
44 self.replay_level = None
46793ccfedca Implement replays.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 158
diff changeset
45 if not replay or not replay.levels[game.stage-1]:
46793ccfedca Implement replays.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 158
diff changeset
46 self.keys = pyglet.window.key.KeyStateHandler()
46793ccfedca Implement replays.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 158
diff changeset
47 self.push_handlers(self.keys)
46793ccfedca Implement replays.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 158
diff changeset
48 else:
46793ccfedca Implement replays.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 158
diff changeset
49 self.keys = 0
46793ccfedca Implement replays.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 158
diff changeset
50 self.replay_level = replay.levels[game.stage-1]
131
fab7ad2f0d8b Use Cython, improve performances!
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
51
fab7ad2f0d8b Use Cython, improve performances!
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
52 self.fps_display = pyglet.clock.ClockDisplay()
fab7ad2f0d8b Use Cython, improve performances!
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
53
fab7ad2f0d8b Use Cython, improve performances!
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
54
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
55 def start(self, width=None, height=None):
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
56 width = width or (self.game.width if self.game else 640)
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
57 height = height or (self.game.height if self.game else 480)
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
58
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
59 if (width, height) != (self.width, self.height):
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
60 self.set_size(width, height)
131
fab7ad2f0d8b Use Cython, improve performances!
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
61
fab7ad2f0d8b Use Cython, improve performances!
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
62 # Initialize OpenGL
fab7ad2f0d8b Use Cython, improve performances!
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
63 glEnable(GL_BLEND)
fab7ad2f0d8b Use Cython, improve performances!
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
64 glEnable(GL_TEXTURE_2D)
fab7ad2f0d8b Use Cython, improve performances!
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
65 glEnable(GL_FOG)
fab7ad2f0d8b Use Cython, improve performances!
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
66 glHint(GL_FOG_HINT, GL_NICEST)
fab7ad2f0d8b Use Cython, improve performances!
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
67 glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST)
fab7ad2f0d8b Use Cython, improve performances!
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
68 glEnableClientState(GL_COLOR_ARRAY)
fab7ad2f0d8b Use Cython, improve performances!
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
69 glEnableClientState(GL_VERTEX_ARRAY)
fab7ad2f0d8b Use Cython, improve performances!
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
70 glEnableClientState(GL_TEXTURE_COORD_ARRAY)
fab7ad2f0d8b Use Cython, improve performances!
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
71
fab7ad2f0d8b Use Cython, improve performances!
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
72 # Use our own loop to ensure 60 (for now, 120) fps
477
e71b1bcf952a Wait a bit for incoming messages...
Thibaut Girka <thib@sitedethib.com>
parents: 475
diff changeset
73 pyglet.clock.set_fps_limit(60)
131
fab7ad2f0d8b Use Cython, improve performances!
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
74 while not self.has_exit:
fab7ad2f0d8b Use Cython, improve performances!
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
75 pyglet.clock.tick()
fab7ad2f0d8b Use Cython, improve performances!
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
76 self.dispatch_events()
fab7ad2f0d8b Use Cython, improve performances!
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
77 self.update()
fab7ad2f0d8b Use Cython, improve performances!
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
78 self.on_draw()
fab7ad2f0d8b Use Cython, improve performances!
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
79 self.flip()
fab7ad2f0d8b Use Cython, improve performances!
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
80
fab7ad2f0d8b Use Cython, improve performances!
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
81
fab7ad2f0d8b Use Cython, improve performances!
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
82 def on_resize(self, width, height):
fab7ad2f0d8b Use Cython, improve performances!
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
83 glViewport(0, 0, width, height)
fab7ad2f0d8b Use Cython, improve performances!
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
84
fab7ad2f0d8b Use Cython, improve performances!
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
85
146
96c30ffd9b87 Evil workaround to pyglet's X11 backend
Thibaut Girka <thib@sitedethib.com>
parents: 131
diff changeset
86 def _event_text_symbol(self, ev):
96c30ffd9b87 Evil workaround to pyglet's X11 backend
Thibaut Girka <thib@sitedethib.com>
parents: 131
diff changeset
87 # XXX: Ugly workaround to a pyglet bug on X11
96c30ffd9b87 Evil workaround to pyglet's X11 backend
Thibaut Girka <thib@sitedethib.com>
parents: 131
diff changeset
88 #TODO: fix that bug in pyglet
96c30ffd9b87 Evil workaround to pyglet's X11 backend
Thibaut Girka <thib@sitedethib.com>
parents: 131
diff changeset
89 try:
96c30ffd9b87 Evil workaround to pyglet's X11 backend
Thibaut Girka <thib@sitedethib.com>
parents: 131
diff changeset
90 return pyglet.window.Window._event_text_symbol(self, ev)
96c30ffd9b87 Evil workaround to pyglet's X11 backend
Thibaut Girka <thib@sitedethib.com>
parents: 131
diff changeset
91 except Exception as exc:
224
9bb26dbb8438 Remove useless and occasionally problematic (think about non-utf8 terminals) print calls.
Thibaut Girka <thib@sitedethib.com>
parents: 205
diff changeset
92 logger.warn('Pyglet error: %s', traceback.format_exc(exc))
146
96c30ffd9b87 Evil workaround to pyglet's X11 backend
Thibaut Girka <thib@sitedethib.com>
parents: 131
diff changeset
93 return None, None
96c30ffd9b87 Evil workaround to pyglet's X11 backend
Thibaut Girka <thib@sitedethib.com>
parents: 131
diff changeset
94
96c30ffd9b87 Evil workaround to pyglet's X11 backend
Thibaut Girka <thib@sitedethib.com>
parents: 131
diff changeset
95
131
fab7ad2f0d8b Use Cython, improve performances!
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
96 def on_key_press(self, symbol, modifiers):
fab7ad2f0d8b Use Cython, improve performances!
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
97 if symbol == pyglet.window.key.ESCAPE:
fab7ad2f0d8b Use Cython, improve performances!
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
98 self.has_exit = True
fab7ad2f0d8b Use Cython, improve performances!
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
99 # XXX: Fullscreen will be enabled the day pyglet stops sucking
fab7ad2f0d8b Use Cython, improve performances!
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
100 elif symbol == pyglet.window.key.F11:
fab7ad2f0d8b Use Cython, improve performances!
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
101 self.set_fullscreen(not self.fullscreen)
fab7ad2f0d8b Use Cython, improve performances!
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
102
fab7ad2f0d8b Use Cython, improve performances!
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
103
fab7ad2f0d8b Use Cython, improve performances!
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
104 def update(self):
fab7ad2f0d8b Use Cython, improve performances!
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
105 if self.background:
151
5cf927cbd9c5 Merge GameState into Game. TODO: Merge PlayerState into Player
Thibaut Girka <thib@sitedethib.com>
parents: 146
diff changeset
106 self.background.update(self.game.frame)
131
fab7ad2f0d8b Use Cython, improve performances!
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
107 if self.game:
187
46793ccfedca Implement replays.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 158
diff changeset
108 if not self.replay_level:
46793ccfedca Implement replays.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 158
diff changeset
109 #TODO: allow user settings
46793ccfedca Implement replays.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 158
diff changeset
110 keystate = 0
46793ccfedca Implement replays.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 158
diff changeset
111 if self.keys[pyglet.window.key.W]:
46793ccfedca Implement replays.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 158
diff changeset
112 keystate |= 1
46793ccfedca Implement replays.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 158
diff changeset
113 if self.keys[pyglet.window.key.X]:
46793ccfedca Implement replays.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 158
diff changeset
114 keystate |= 2
46793ccfedca Implement replays.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 158
diff changeset
115 #TODO: on some configurations, LSHIFT is Shift_L when pressed
46793ccfedca Implement replays.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 158
diff changeset
116 # and ISO_Prev_Group when released, confusing the hell out of pyglet
46793ccfedca Implement replays.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 158
diff changeset
117 # and leading to a always-on LSHIFT...
46793ccfedca Implement replays.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 158
diff changeset
118 if self.keys[pyglet.window.key.LSHIFT]:
46793ccfedca Implement replays.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 158
diff changeset
119 keystate |= 4
46793ccfedca Implement replays.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 158
diff changeset
120 if self.keys[pyglet.window.key.UP]:
46793ccfedca Implement replays.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 158
diff changeset
121 keystate |= 16
46793ccfedca Implement replays.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 158
diff changeset
122 if self.keys[pyglet.window.key.DOWN]:
46793ccfedca Implement replays.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 158
diff changeset
123 keystate |= 32
46793ccfedca Implement replays.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 158
diff changeset
124 if self.keys[pyglet.window.key.LEFT]:
46793ccfedca Implement replays.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 158
diff changeset
125 keystate |= 64
46793ccfedca Implement replays.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 158
diff changeset
126 if self.keys[pyglet.window.key.RIGHT]:
46793ccfedca Implement replays.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 158
diff changeset
127 keystate |= 128
46793ccfedca Implement replays.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 158
diff changeset
128 if self.keys[pyglet.window.key.LCTRL]:
46793ccfedca Implement replays.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 158
diff changeset
129 keystate |= 256
46793ccfedca Implement replays.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 158
diff changeset
130 else:
188
008f90ebfdc0 Fix replay handling and add support for encrypted replays
Thibaut Girka <thib@sitedethib.com>
parents: 187
diff changeset
131 keystate = 0
008f90ebfdc0 Fix replay handling and add support for encrypted replays
Thibaut Girka <thib@sitedethib.com>
parents: 187
diff changeset
132 for frame, _keystate, unknown in self.replay_level.keys:
008f90ebfdc0 Fix replay handling and add support for encrypted replays
Thibaut Girka <thib@sitedethib.com>
parents: 187
diff changeset
133 if self.game.frame < frame:
008f90ebfdc0 Fix replay handling and add support for encrypted replays
Thibaut Girka <thib@sitedethib.com>
parents: 187
diff changeset
134 break
008f90ebfdc0 Fix replay handling and add support for encrypted replays
Thibaut Girka <thib@sitedethib.com>
parents: 187
diff changeset
135 else:
008f90ebfdc0 Fix replay handling and add support for encrypted replays
Thibaut Girka <thib@sitedethib.com>
parents: 187
diff changeset
136 keystate = _keystate
187
46793ccfedca Implement replays.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 158
diff changeset
137
475
9d4d52793eca Experimental netplay! Yay!
Thibaut Girka <thib@sitedethib.com>
parents: 225
diff changeset
138 if self.con:
9d4d52793eca Experimental netplay! Yay!
Thibaut Girka <thib@sitedethib.com>
parents: 225
diff changeset
139 self.con.run_iter(self.game, keystate)
9d4d52793eca Experimental netplay! Yay!
Thibaut Girka <thib@sitedethib.com>
parents: 225
diff changeset
140 else:
9d4d52793eca Experimental netplay! Yay!
Thibaut Girka <thib@sitedethib.com>
parents: 225
diff changeset
141 self.game.run_iter([keystate])
131
fab7ad2f0d8b Use Cython, improve performances!
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
142
fab7ad2f0d8b Use Cython, improve performances!
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
143
fab7ad2f0d8b Use Cython, improve performances!
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
144 def on_draw(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
145 # 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
146 #TODO: move that to GameRenderer?
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
147 glMatrixMode(GL_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
148 glLoadIdentity()
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
149 gluPerspective(30, float(self.width) / float(self.height),
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
150 101010101./2010101., 101010101./10101.)
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
151
131
fab7ad2f0d8b Use Cython, improve performances!
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
152 GameRenderer.render(self)
fab7ad2f0d8b Use Cython, improve performances!
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
153
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
154 # Get back to standard orthographic 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
155 glMatrixMode(GL_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
156 glLoadIdentity()
131
fab7ad2f0d8b Use Cython, improve performances!
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
157 glMatrixMode(GL_MODELVIEW)
fab7ad2f0d8b Use Cython, improve performances!
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
158 glLoadIdentity()
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
159
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
160 #TODO: draw interface
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
161 gluOrtho2D(0., float(self.game.width), 0., float(self.game.height))
131
fab7ad2f0d8b Use Cython, improve performances!
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
162 self.fps_display.draw()
fab7ad2f0d8b Use Cython, improve performances!
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
163