changeset 428:f41a26971a19

Remove all Loader uses from outside pytouhou.games, and add a --no-music option to disable bgm.
author Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
date Tue, 16 Jul 2013 21:17:22 +0200
parents 0604f4fbbe3c
children 40d5f3083ebc
files eosd pytouhou/game/game.py pytouhou/games/eosd.py pytouhou/ui/gamerunner.pyx
diffstat 4 files changed, 43 insertions(+), 39 deletions(-) [+]
line wrap: on
line diff
--- a/eosd
+++ b/eosd
@@ -42,6 +42,7 @@ parser.add_argument('--debug', action='s
 parser.add_argument('--fixed-pipeline', action='store_true', help='Use the fixed pipeline instead of the new programmable one.')
 parser.add_argument('--no-background', action='store_false', help='Disable background display (huge performance boost on slow systems).')
 parser.add_argument('--no-particles', action='store_false', help='Disable particles handling (huge performance boost on slow systems).')
+parser.add_argument('--no-music', action='store_false', help='Disable background music.')
 parser.add_argument('--hints', metavar='HINTS', default=None, help='Hints file, to display text while playing.')
 parser.add_argument('--verbosity', metavar='VERBOSITY', choices=['DEBUG', 'INFO', 'WARNING', 'ERROR', 'CRITICAL'], help='Select the wanted logging level.')
 
@@ -56,7 +57,6 @@ pyximport.install()
 
 from pytouhou.ui.window import Window
 from pytouhou.resource.loader import Loader
-from pytouhou.game.background import Background
 from pytouhou.ui.gamerunner import GameRunner
 from pytouhou.games.eosd import EoSDGame
 from pytouhou.game.game import GameOver
@@ -97,8 +97,8 @@ class EoSDGameBossRush(EoSDGame):
 
 def main(path, data, stage_num, rank, character, replay, save_filename,
          skip_replay, boss_rush, fps_limit, single_buffer, debug,
-         fixed_pipeline, display_background, display_particles, hints,
-         verbosity):
+         fixed_pipeline, enable_background, enable_particles, enable_music,
+         hints, verbosity):
 
     resource_loader = Loader(path)
 
@@ -185,24 +185,18 @@ def main(path, data, stage_num, rank, ch
 
         hints_stage = hints.stages[stage_num - 1] if hints else None
 
-        # Load stage data
-        stage = resource_loader.get_stage('stage%d.std' % stage_num)
-
         game = game_class(resource_loader, states, stage_num, rank, difficulty, prng=prng, continues=continues, hints=hints_stage)
 
-        if not display_particles:
+        if not enable_particles:
             def new_particle(pos, anim, amp, number=1, reverse=False, duration=24):
                 pass
             game.new_particle = new_particle
 
-        if display_background:
-            background_anm_wrapper = resource_loader.get_anm_wrapper(('stg%dbg.anm' % stage_num,))
-            background = Background(stage, background_anm_wrapper)
-        else:
-            background = None
+        background = game.background if enable_background else None
+        bgms = game.std.bgms if enable_music else None
 
         # Main loop
-        runner.load_game(game, background, stage.bgms, replay, save_keystates)
+        runner.load_game(game, background, bgms, replay, save_keystates)
         window.set_runner(runner)
         try:
             window.run()
@@ -231,4 +225,5 @@ def main(path, data, stage_num, rank, ch
 main(args.path, tuple(args.data), args.stage, args.rank, args.character,
      args.replay, args.save_replay, args.skip_replay, args.boss_rush,
      args.fps_limit, args.single_buffer, args.debug, args.fixed_pipeline,
-     args.no_background, args.no_particles, args.hints, args.verbosity)
+     args.no_background, args.no_particles, args.no_music, args.hints,
+     args.verbosity)
--- a/pytouhou/game/game.py
+++ b/pytouhou/game/game.py
@@ -14,7 +14,6 @@
 
 from itertools import chain
 
-from pytouhou.vm.eclrunner import ECLMainRunner
 from pytouhou.vm.msgrunner import MSGRunner
 
 from pytouhou.game.bullet import LAUNCHED, CANCELLED
@@ -31,12 +30,10 @@ class GameOver(Exception):
 
 
 class Game(object):
-    def __init__(self, resource_loader, players, stage, rank, difficulty,
-                 bullet_types, laser_types, item_types,
-                 nb_bullets_max=None, width=384, height=448, prng=None,
-                 interface=None, continues=0, hints=None):
-        self.resource_loader = resource_loader
-
+    def __init__(self, players, stage, rank, difficulty, bullet_types,
+                 laser_types, item_types, nb_bullets_max=None, width=384,
+                 height=448, prng=None, interface=None, continues=0,
+                 hints=None):
         self.width, self.height = width, height
 
         self.nb_bullets_max = nb_bullets_max
@@ -75,13 +72,6 @@ class Game(object):
         self.prng = prng
         self.frame = 0
 
-        self.enm_anm_wrapper = resource_loader.get_anm_wrapper2(('stg%denm.anm' % stage,
-                                                                 'stg%denm2.anm' % stage))
-        self.etama4 = resource_loader.get_anm_wrapper(('etama4.anm',))
-        ecl = resource_loader.get_ecl('ecldata%d.ecl' % stage)
-        self.ecl_runners = [ECLMainRunner(main, ecl.subs, self) for main in ecl.mains]
-
-        self.spellcard_effect_anm_wrapper = resource_loader.get_anm_wrapper(('eff0%d.anm' % stage,))
         self.spellcard_effect = None
 
         # See 102h.exe@0x413220 if you think you're brave enough.
@@ -187,13 +177,13 @@ class Game(object):
     def new_effect(self, pos, anim, anm_wrapper=None, number=1):
         number = min(number, self.nb_bullets_max - len(self.effects))
         for i in xrange(number):
-            self.effects.append(Effect(pos, anim, anm_wrapper or self.etama4))
+            self.effects.append(Effect(pos, anim, anm_wrapper or self.etama))
 
 
     def new_particle(self, pos, anim, amp, number=1, reverse=False, duration=24):
         number = min(number, self.nb_bullets_max - len(self.effects))
         for i in xrange(number):
-            self.effects.append(Particle(pos, anim, self.etama4, amp, self, reverse=reverse, duration=duration))
+            self.effects.append(Particle(pos, anim, self.etama, amp, self, reverse=reverse, duration=duration))
 
 
     def new_enemy(self, pos, life, instr_type, bonus_dropped, die_score):
--- a/pytouhou/games/eosd.py
+++ b/pytouhou/games/eosd.py
@@ -22,9 +22,9 @@ from pytouhou.game.player import Player
 from pytouhou.game.orb import Orb
 from pytouhou.game.effect import Effect
 from pytouhou.game.text import Text, Counter, Gauge
-
+from pytouhou.game.background import Background
 
-SQ2 = 2. ** 0.5 / 2.
+from pytouhou.vm.eclrunner import ECLMainRunner
 
 
 class EoSDGame(Game):
@@ -35,7 +35,7 @@ class EoSDGame(Game):
 
         if not bullet_types:
             etama3 = resource_loader.get_anm_wrapper(('etama3.anm',))
-            etama4 = resource_loader.get_anm_wrapper(('etama4.anm',))
+            self.etama = resource_loader.get_anm_wrapper(('etama4.anm',))
             bullet_types = [BulletType(etama3, 0, 11, 14, 15, 16, hitbox_size=2,
                                        type_id=0),
                             BulletType(etama3, 1, 12, 17, 18, 19, hitbox_size=3,
@@ -57,7 +57,7 @@ class EoSDGame(Game):
                             BulletType(etama3, 8, 13, 20, 20, 20, hitbox_size=4.5,
                                        launch_anim_offsets=(0, 1, 1, 2, 2, 3, 4, 0),
                                        type_id=8),
-                            BulletType(etama4, 0, 1, 2, 2, 2, hitbox_size=16,
+                            BulletType(self.etama, 0, 1, 2, 2, 2, hitbox_size=16,
                                        launch_anim_offsets=(0, 1, 2, 3, 4, 5, 6, 7, 8),
                                        type_id=9)]
 
@@ -74,6 +74,13 @@ class EoSDGame(Game):
                           ItemType(etama3, 5, 12), #1up
                           ItemType(etama3, 6, 13)] #Star
 
+        self.enm_anm_wrapper = resource_loader.get_anm_wrapper2(('stg%denm.anm' % stage,
+                                                                 'stg%denm2.anm' % stage))
+        ecl = resource_loader.get_ecl('ecldata%d.ecl' % stage)
+        self.ecl_runners = [ECLMainRunner(main, ecl.subs, self) for main in ecl.mains]
+
+        self.spellcard_effect_anm_wrapper = resource_loader.get_anm_wrapper(('eff0%d.anm' % stage,))
+
         player_face = player_states[0].character // 2
         enemy_face = [('face03a.anm', 'face03b.anm'),
                       ('face05a.anm',),
@@ -95,7 +102,15 @@ class EoSDGame(Game):
         self.stage = stage #XXX
         interface = EoSDInterface(self, resource_loader)
 
-        Game.__init__(self, resource_loader, players, stage, rank, difficulty,
+        # Load stage data
+        self.std = resource_loader.get_stage('stage%d.std' % stage)
+
+        background_anm_wrapper = resource_loader.get_anm_wrapper(('stg%dbg.anm' % stage,))
+        self.background = Background(self.std, background_anm_wrapper)
+
+        self.resource_loader = resource_loader #XXX: currently used for texture preload in pytouhou.ui.gamerunner. Wipe it!
+
+        Game.__init__(self, players, stage, rank, difficulty,
                       bullet_types, laser_types, item_types, nb_bullets_max,
                       width, height, prng, interface, continues, hints)
 
@@ -277,4 +292,3 @@ class EoSDPlayer(Player):
 
         for orb in self.orbs:
             orb.update()
-
--- a/pytouhou/ui/gamerunner.pyx
+++ b/pytouhou/ui/gamerunner.pyx
@@ -71,9 +71,14 @@ class GameRunner(GameRenderer):
 
         self.save_keystates = save_keystates
 
-        game.music = MusicPlayer(game.resource_loader, bgms)
-        game.music.play(0)
-        game.sfx_player = SFXPlayer(game.resource_loader) if not self.skip else NullPlayer()
+        null_player = NullPlayer()
+        if bgms:
+            game.music = MusicPlayer(game.resource_loader, bgms)
+            game.music.play(0)
+        else:
+            game.music = null_player
+
+        game.sfx_player = SFXPlayer(game.resource_loader) if not self.skip else null_player
 
 
     def set_input(self, replay=None):