Mercurial > touhou
comparison pytouhou/ui/gamerunner.py @ 334:4eca6130f118
Add options to set FPS limit and disable double buffering
author | Thibaut Girka <thib@sitedethib.com> |
---|---|
date | Sun, 01 Jul 2012 01:07:41 +0200 |
parents | 1b4f04b08729 |
children | 61caded6b4f5 |
comparison
equal
deleted
inserted
replaced
333:d369a369204a | 334:4eca6130f118 |
---|---|
34 | 34 |
35 logger = get_logger(__name__) | 35 logger = get_logger(__name__) |
36 | 36 |
37 | 37 |
38 class GameRunner(pyglet.window.Window, GameRenderer): | 38 class GameRunner(pyglet.window.Window, GameRenderer): |
39 def __init__(self, resource_loader, game=None, background=None, replay=None): | 39 def __init__(self, resource_loader, game=None, background=None, replay=None, double_buffer=True, fps_limit=60): |
40 GameRenderer.__init__(self, resource_loader, game, background) | 40 GameRenderer.__init__(self, resource_loader, game, background) |
41 | 41 |
42 config = pyglet.gl.Config(double_buffer=double_buffer) | |
42 width, height = (game.interface.width, game.interface.height) if game else (None, None) | 43 width, height = (game.interface.width, game.interface.height) if game else (None, None) |
43 pyglet.window.Window.__init__(self, width=width, height=height, | 44 pyglet.window.Window.__init__(self, width=width, height=height, |
44 caption='PyTouhou', resizable=False) | 45 caption='PyTouhou', resizable=False, |
45 | 46 config=config) |
47 | |
48 self.fps_limit = fps_limit | |
46 self.replay_level = None | 49 self.replay_level = None |
47 | 50 |
48 if game: | 51 if game: |
49 self.load_game(game, background, replay) | 52 self.load_game(game, background, replay) |
50 | 53 |
87 bgm = self.game.bgms[0] | 90 bgm = self.game.bgms[0] |
88 if bgm: | 91 if bgm: |
89 self.game.music.queue(bgm) | 92 self.game.music.queue(bgm) |
90 self.game.music.play() | 93 self.game.music.play() |
91 | 94 |
92 # Use our own loop to ensure 60 (for now, 120) fps | 95 if self.fps_limit > 0: |
93 pyglet.clock.set_fps_limit(120) | 96 pyglet.clock.set_fps_limit(self.fps_limit) |
94 while not self.has_exit: | 97 while not self.has_exit: |
95 pyglet.clock.tick() | 98 pyglet.clock.tick() |
96 self.dispatch_events() | 99 self.dispatch_events() |
97 self.update() | 100 self.update() |
98 self.render_game() | 101 self.render_game() |