Mercurial > touhou
comparison scripts/pytouhou @ 553:8f51e34d911c
Refactor graphics backend selection, to make them fallbackable and optional.
author | Emmanuel Gil Peyrot <linkmauve@linkmauve.fr> |
---|---|
date | Thu, 29 May 2014 12:31:55 +0200 |
parents | 56bca8ce4b68 |
children | 653a9f087673 |
comparison
equal
deleted
inserted
replaced
552:aad758aef26d | 553:8f51e34d911c |
---|---|
50 netplay_group.add_argument('--port', metavar='PORT', type=int, default=0, help='Local port to use.') | 50 netplay_group.add_argument('--port', metavar='PORT', type=int, default=0, help='Local port to use.') |
51 netplay_group.add_argument('--remote', metavar='REMOTE', default=None, help='Remote address.') | 51 netplay_group.add_argument('--remote', metavar='REMOTE', default=None, help='Remote address.') |
52 netplay_group.add_argument('--friendly-fire', action='store_true', help='Allow friendly-fire during netplay.') | 52 netplay_group.add_argument('--friendly-fire', action='store_true', help='Allow friendly-fire during netplay.') |
53 | 53 |
54 graphics_group = parser.add_argument_group('Graphics options') | 54 graphics_group = parser.add_argument_group('Graphics options') |
55 graphics_group.add_argument('--backend', metavar='BACKEND', choices=['opengl', 'sdl'], default='opengl', help='Which backend to use (opengl or sdl for now).') | 55 graphics_group.add_argument('--backend', metavar='BACKEND', choices=['opengl', 'sdl'], default=['opengl', 'sdl'], nargs='*', help='Which backend to use (opengl or sdl).') |
56 graphics_group.add_argument('--fixed-pipeline', action='store_true', help='Use the fixed pipeline instead of the new programmable one.') | |
57 graphics_group.add_argument('--single-buffer', action='store_true', help='Disable double buffering.') | |
58 graphics_group.add_argument('--fps-limit', metavar='FPS', default=-1, type=int, help='Set fps limit. A value of 0 disables fps limiting, while a negative value limits to 60 fps if and only if vsync doesn’t work.') | 56 graphics_group.add_argument('--fps-limit', metavar='FPS', default=-1, type=int, help='Set fps limit. A value of 0 disables fps limiting, while a negative value limits to 60 fps if and only if vsync doesn’t work.') |
59 graphics_group.add_argument('--no-background', action='store_false', help='Disable background display (huge performance boost on slow systems).') | 57 graphics_group.add_argument('--no-background', action='store_false', help='Disable background display (huge performance boost on slow systems).') |
60 graphics_group.add_argument('--no-particles', action='store_false', help='Disable particles handling (huge performance boost on slow systems).') | 58 graphics_group.add_argument('--no-particles', action='store_false', help='Disable particles handling (huge performance boost on slow systems).') |
61 graphics_group.add_argument('--no-sound', action='store_false', help='Disable music and sound effects.') | 59 graphics_group.add_argument('--no-sound', action='store_false', help='Disable music and sound effects.') |
60 | |
61 opengl_group = parser.add_argument_group('OpenGL backend options') | |
62 opengl_group.add_argument('--single-buffer', action='store_true', help='Disable double buffering.') | |
63 opengl_group.add_argument('--gl-flavor', choices=['core', 'es', 'compatibility', 'legacy'], default='compatibility', help='OpenGL profile to use.') | |
64 opengl_group.add_argument('--gl-version', default=2.1, type=float, help='OpenGL version to use.') | |
62 | 65 |
63 args = parser.parse_args() | 66 args = parser.parse_args() |
64 | 67 |
65 | 68 |
66 import sys | 69 import sys |
86 from pytouhou.vm.msgrunner import NextStage | 89 from pytouhou.vm.msgrunner import NextStage |
87 from pytouhou.formats.hint import Hint | 90 from pytouhou.formats.hint import Hint |
88 from pytouhou.network import Network | 91 from pytouhou.network import Network |
89 | 92 |
90 | 93 |
91 if args.backend == 'opengl': | 94 from importlib import import_module |
95 for backend in args.backend: | |
96 if backend == 'opengl': | |
97 options = { | |
98 'double-buffer': not args.single_buffer, | |
99 'flavor': args.gl_flavor, | |
100 'version': args.gl_version | |
101 } | |
102 else: | |
103 options = {} | |
104 | |
92 try: | 105 try: |
93 from pytouhou.ui.opengl.gamerenderer import GameRenderer | 106 backend = import_module('pytouhou.ui.%s.backend' % backend) |
94 opengl = True | 107 except ImportError as e: |
95 except ImportError: | 108 continue |
96 args.backend = 'sdl' | 109 |
97 | 110 try: |
98 if args.backend == 'sdl': | 111 backend.init(options) |
99 from pytouhou.ui.sdl.gamerenderer import GameRenderer | 112 except Exception as e: |
100 opengl = False | 113 print('Backend', backend, 'failed to initialize:', e) |
114 pass | |
115 else: | |
116 GameRenderer = backend.GameRenderer | |
117 break | |
118 else: | |
119 show_simple_message_box(u'No graphical backend could be used, continuing with a windowless game.') | |
120 backend = None | |
121 GameRenderer = None | |
101 | 122 |
102 | 123 |
103 class GameBossRush(Game): | 124 class GameBossRush(Game): |
104 def run_iter(self, keystates): | 125 def run_iter(self, keystates): |
105 for i in range(20): | 126 for i in range(20): |
194 game_class = GameBossRush if boss_rush else Game | 215 game_class = GameBossRush if boss_rush else Game |
195 | 216 |
196 common = Common(resource_loader, characters, continues, stage_num - 1) | 217 common = Common(resource_loader, characters, continues, stage_num - 1) |
197 interface = Interface(resource_loader, common.players[0]) #XXX | 218 interface = Interface(resource_loader, common.players[0]) #XXX |
198 common.interface = interface #XXX | 219 common.interface = interface #XXX |
199 renderer = GameRenderer(resource_loader, window) | 220 renderer = GameRenderer(resource_loader, window) if GameRenderer is not None else None |
200 runner = GameRunner(window, renderer, common, resource_loader, skip_replay, con) | 221 runner = GameRunner(window, renderer, common, resource_loader, skip_replay, con) |
201 window.set_runner(runner) | 222 window.set_runner(runner) |
202 | 223 |
203 while True: | 224 while True: |
204 first_player = common.players[0] | 225 first_player = common.players[0] |
274 with open(save_filename, 'wb+') as file: | 295 with open(save_filename, 'wb+') as file: |
275 save_replay.write(file) | 296 save_replay.write(file) |
276 | 297 |
277 | 298 |
278 with SDL(sound=args.no_sound): | 299 with SDL(sound=args.no_sound): |
279 window = Window(double_buffer=(not args.single_buffer), | 300 window = Window(backend, fps_limit=args.fps_limit) |
280 fps_limit=args.fps_limit, | |
281 fixed_pipeline=args.fixed_pipeline, opengl=opengl) | |
282 | 301 |
283 main(window, args.path, tuple(args.data), args.stage, args.rank, | 302 main(window, args.path, tuple(args.data), args.stage, args.rank, |
284 args.character, args.replay, args.save_replay, args.skip_replay, | 303 args.character, args.replay, args.save_replay, args.skip_replay, |
285 args.boss_rush, args.debug, args.no_background, args.no_particles, | 304 args.boss_rush, args.debug, args.no_background, args.no_particles, |
286 args.hints, args.verbosity, args.port, args.remote, | 305 args.hints, args.verbosity, args.port, args.remote, |