Mercurial > touhou
comparison pytouhou/vm/msgrunner.py @ 376:69ec72b990a4
Support more than one version of a vm.
author | Emmanuel Gil Peyrot <linkmauve@linkmauve.fr> |
---|---|
date | Mon, 06 Aug 2012 23:10:09 +0200 |
parents | 61caded6b4f5 |
children | 9589a01e6edf |
comparison
equal
deleted
inserted
replaced
375:8f2f3053906a | 376:69ec72b990a4 |
---|---|
26 | 26 |
27 | 27 |
28 class MSGRunner(object): | 28 class MSGRunner(object): |
29 __metaclass__ = MetaRegistry | 29 __metaclass__ = MetaRegistry |
30 __slots__ = ('_msg', '_game', 'frame', 'sleep_time', 'allow_skip', | 30 __slots__ = ('_msg', '_game', 'frame', 'sleep_time', 'allow_skip', |
31 'skipping', 'frozen', 'faces', 'ended', 'instruction_pointer') | 31 'skipping', 'frozen', 'faces', 'ended', 'instruction_pointer', |
32 'handlers') | |
32 | 33 |
33 def __init__(self, msg, script, game): | 34 def __init__(self, msg, script, game): |
34 self._msg = msg.msgs[script + 10 * (game.players[0].state.character // 2)] | 35 self._msg = msg.msgs[script + 10 * (game.players[0].state.character // 2)] |
35 self._game = game | 36 self._game = game |
37 self.handlers = self._handlers[6] | |
36 self.frame = 0 | 38 self.frame = 0 |
37 self.sleep_time = 0 | 39 self.sleep_time = 0 |
38 self.allow_skip = True | 40 self.allow_skip = True |
39 self.skipping = False | 41 self.skipping = False |
40 self.frozen = False | 42 self.frozen = False |
66 else: | 68 else: |
67 self.instruction_pointer += 1 | 69 self.instruction_pointer += 1 |
68 | 70 |
69 if frame == self.frame: | 71 if frame == self.frame: |
70 try: | 72 try: |
71 callback = self._handlers[instr_type] | 73 callback = self.handlers[instr_type] |
72 except KeyError: | 74 except KeyError: |
73 logger.warn('unhandled msg opcode %d (args: %r)', instr_type, args) | 75 logger.warn('unhandled msg opcode %d (args: %r)', instr_type, args) |
74 else: | 76 else: |
75 callback(self, *args) | 77 callback(self, *args) |
76 | 78 |