changeset 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 d369a369204a
children 2350147cf043
files eosd pytouhou/ui/gamerunner.py
diffstat 2 files changed, 13 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/eosd
+++ b/eosd
@@ -49,7 +49,7 @@ class EoSDGameBossRush(EoSDGame):
 
 
 
-def main(path, data, stage_num, rank, character, replay, boss_rush):
+def main(path, data, stage_num, rank, character, replay, boss_rush, fps_limit, single_buffer):
     resource_loader = Loader(path)
     resource_loader.scan_archives(data)
 
@@ -71,7 +71,7 @@ def main(path, data, stage_num, rank, ch
 
     game_class = EoSDGameBossRush if boss_rush else EoSDGame
 
-    runner = GameRunner(resource_loader)
+    runner = GameRunner(resource_loader, fps_limit=fps_limit, double_buffer=(not single_buffer))
     while True:
         if replay:
             level = replay.levels[stage_num - 1]
@@ -131,7 +131,10 @@ parser.add_argument('-r', '--rank', meta
 parser.add_argument('-c', '--character', metavar='CHARACTER', type=int, default=0, help='Select the character to use, from 0 (ReimuA, default) to 3 (MarisaB).')
 parser.add_argument('--replay', metavar='REPLAY', help='Select a replay')
 parser.add_argument('-b', '--boss-rush', action='store_true', help='Fight only bosses')
+parser.add_argument('--single-buffer', action='store_true', help='Disable double buffering')
+parser.add_argument('--fps-limit', metavar='FPS', default=60, type=int, help='Set fps limit')
 
 args = parser.parse_args()
 
-main(args.path, tuple(args.data), args.stage, args.rank, args.character, args.replay, args.boss_rush)
+main(args.path, tuple(args.data), args.stage, args.rank, args.character,
+     args.replay, args.boss_rush, args.fps_limit, args.single_buffer)
--- a/pytouhou/ui/gamerunner.py
+++ b/pytouhou/ui/gamerunner.py
@@ -36,13 +36,16 @@ logger = get_logger(__name__)
 
 
 class GameRunner(pyglet.window.Window, GameRenderer):
-    def __init__(self, resource_loader, game=None, background=None, replay=None):
+    def __init__(self, resource_loader, game=None, background=None, replay=None, double_buffer=True, fps_limit=60):
         GameRenderer.__init__(self, resource_loader, game, background)
 
+        config = pyglet.gl.Config(double_buffer=double_buffer)
         width, height = (game.interface.width, game.interface.height) if game else (None, None)
         pyglet.window.Window.__init__(self, width=width, height=height,
-                                      caption='PyTouhou', resizable=False)
+                                      caption='PyTouhou', resizable=False,
+                                      config=config)
 
+        self.fps_limit = fps_limit
         self.replay_level = None
 
         if game:
@@ -89,8 +92,8 @@ class GameRunner(pyglet.window.Window, G
             self.game.music.queue(bgm)
         self.game.music.play()
 
-        # Use our own loop to ensure 60 (for now, 120) fps
-        pyglet.clock.set_fps_limit(120)
+        if self.fps_limit > 0:
+            pyglet.clock.set_fps_limit(self.fps_limit)
         while not self.has_exit:
             pyglet.clock.tick()
             self.dispatch_events()