Mercurial > touhou
comparison pytouhou/vm/eclrunner.py @ 372:704bea2e4360
Use a future-proof ECL parser.
author | Emmanuel Gil Peyrot <linkmauve@linkmauve.fr> |
---|---|
date | Mon, 06 Aug 2012 22:52:22 +0200 |
parents | 238d06c6603e |
children | 69ec72b990a4 |
comparison
equal
deleted
inserted
replaced
371:6702bc0215dc | 372:704bea2e4360 |
---|---|
23 | 23 |
24 | 24 |
25 | 25 |
26 class ECLMainRunner(object): | 26 class ECLMainRunner(object): |
27 __metaclass__ = MetaRegistry | 27 __metaclass__ = MetaRegistry |
28 __slots__ = ('_ecl', '_game', 'frame', | 28 __slots__ = ('_main', '_subs', '_game', 'frame', |
29 'instruction_pointer', | 29 'instruction_pointer', |
30 'boss_wait') | 30 'boss_wait') |
31 | 31 |
32 def __init__(self, ecl, game): | 32 def __init__(self, main, subs, game): |
33 self._ecl = ecl | 33 self._main = main |
34 self._subs = subs | |
34 self._game = game | 35 self._game = game |
35 self.frame = 0 | 36 self.frame = 0 |
36 self.boss_wait = False | 37 self.boss_wait = False |
37 | 38 |
38 self.instruction_pointer = 0 | 39 self.instruction_pointer = 0 |
42 if not self._game.boss: | 43 if not self._game.boss: |
43 self.boss_wait = False | 44 self.boss_wait = False |
44 | 45 |
45 while True: | 46 while True: |
46 try: | 47 try: |
47 frame, sub, instr_type, args = self._ecl.main[self.instruction_pointer] | 48 frame, sub, instr_type, args = self._main[self.instruction_pointer] |
48 except IndexError: | 49 except IndexError: |
49 break | 50 break |
50 | 51 |
51 # The msg_wait instruction stops the reading of the ECL, not just the frame incrementation. | 52 # The msg_wait instruction stops the reading of the ECL, not just the frame incrementation. |
52 if frame > self.frame or self._game.msg_wait or self.boss_wait: | 53 if frame > self.frame or self._game.msg_wait or self.boss_wait: |
74 y = self._game.prng.rand_double() * 416 | 75 y = self._game.prng.rand_double() * 416 |
75 if z < -990: #102h.exe@0x411881 | 76 if z < -990: #102h.exe@0x411881 |
76 z = self._game.prng.rand_double() * 800 | 77 z = self._game.prng.rand_double() * 800 |
77 enemy = self._game.new_enemy((x, y, z), life, instr_type, | 78 enemy = self._game.new_enemy((x, y, z), life, instr_type, |
78 bonus_dropped, die_score) | 79 bonus_dropped, die_score) |
79 enemy.process = ECLRunner(self._ecl, sub, enemy, self._game) #TODO | 80 enemy.process = ECLRunner(self._subs, sub, enemy, self._game, self._pop_enemy) #TODO |
80 enemy.process.run_iteration() | 81 enemy.process.run_iteration() |
81 | 82 |
82 | 83 |
83 @instruction(0) | 84 @instruction(0) |
84 @instruction(2) | 85 @instruction(2) |
118 | 119 |
119 | 120 |
120 | 121 |
121 class ECLRunner(object): | 122 class ECLRunner(object): |
122 __metaclass__ = MetaRegistry | 123 __metaclass__ = MetaRegistry |
123 __slots__ = ('_ecl', '_enemy', '_game', 'variables', 'sub', 'frame', | 124 __slots__ = ('_subs', '_enemy', '_game', '_pop_enemy', 'variables', 'sub', 'frame', |
124 'instruction_pointer', 'comparison_reg', 'stack', | 125 'instruction_pointer', 'comparison_reg', 'stack', |
125 'running') | 126 'running') |
126 | 127 |
127 def __init__(self, ecl, sub, enemy, game): | 128 def __init__(self, subs, sub, enemy, game, pop_enemy): |
128 # Things not supposed to change | 129 # Things not supposed to change |
129 self._ecl = ecl | 130 self._subs = subs |
130 self._enemy = enemy | 131 self._enemy = enemy |
131 self._game = game | 132 self._game = game |
133 self._pop_enemy = pop_enemy | |
132 | 134 |
133 self.running = True | 135 self.running = True |
134 | 136 |
135 # Things supposed to change (and be put in the stack) | 137 # Things supposed to change (and be put in the stack) |
136 self.variables = [0, 0, 0, 0, | 138 self.variables = [0, 0, 0, 0, |
153 | 155 |
154 def run_iteration(self): | 156 def run_iteration(self): |
155 # Process script | 157 # Process script |
156 while self.running: | 158 while self.running: |
157 try: | 159 try: |
158 frame, instr_type, rank_mask, param_mask, args = self._ecl.subs[self.sub][self.instruction_pointer] | 160 frame, instr_type, rank_mask, param_mask, args = self._subs[self.sub][self.instruction_pointer] |
159 except IndexError: | 161 except IndexError: |
160 self.running = False | 162 self.running = False |
161 break | 163 break |
162 | 164 |
163 if frame > self.frame: | 165 if frame > self.frame: |
757 self._game.disable_spellcard_effect() | 759 self._game.disable_spellcard_effect() |
758 | 760 |
759 | 761 |
760 @instruction(95) | 762 @instruction(95) |
761 def pop_enemy(self, sub, x, y, z, life, bonus_dropped, die_score): | 763 def pop_enemy(self, sub, x, y, z, life, bonus_dropped, die_score): |
762 self._game.ecl_runner._pop_enemy(sub, 0, self._getval(x), | 764 self._pop_enemy(sub, 0, self._getval(x), |
763 self._getval(y), | 765 self._getval(y), |
764 self._getval(z), | 766 self._getval(z), |
765 life, bonus_dropped, die_score) | 767 life, bonus_dropped, die_score) |
766 | 768 |
767 | 769 |
768 @instruction(96) | 770 @instruction(96) |
769 def kill_enemies(self): | 771 def kill_enemies(self): |
770 self._game.kill_enemies() | 772 self._game.kill_enemies() |