comparison pytouhou/game/eclrunner.py @ 30:e3ba2fa966f6

Various optimizations
author Thibaut Girka <thib@sitedethib.com>
date Fri, 12 Aug 2011 23:47:34 +0200
parents 93aa1b55d97c
children 1b0ca2fb89f9
comparison
equal deleted inserted replaced
29:afa91be769ae 30:e3ba2fa966f6
36 self.sub, self.instruction_pointer = sub, instruction_pointer 36 self.sub, self.instruction_pointer = sub, instruction_pointer
37 37
38 38
39 def update(self): 39 def update(self):
40 frame = self.frame 40 frame = self.frame
41 while frame <= self.frame: 41 try:
42 try: 42 while frame <= self.frame:
43 frame, instr_type, rank_mask, param_mask, args = self.ecl.subs[self.sub][self.instruction_pointer] 43 frame, instr_type, rank_mask, param_mask, args = self.ecl.subs[self.sub][self.instruction_pointer]
44 except IndexError:
45 break #TODO: script ended, destroy enemy
46 44
47 if frame == self.frame: 45 if frame == self.frame:
48 try: 46 try:
49 format, callback = self.implementation[instr_type] 47 format, callback = self.implementation[instr_type]
50 except KeyError: 48 except KeyError:
51 print('Warning: unhandled opcode %d!' % instr_type) #TODO 49 print('Warning: unhandled opcode %d!' % instr_type) #TODO
52 else: 50 else:
53 callback(*unpack('<' + format, args)) 51 callback(*unpack('<' + format, args))
54 if frame <= self.frame: 52 if frame <= self.frame:
55 self.instruction_pointer += 1 53 self.instruction_pointer += 1
54 except IndexError:
55 pass #TODO: script ended, destroy enemy
56 56
57 self.frame += 1 57 self.frame += 1
58 58