# HG changeset patch # User Thibaut Girka # Date 1313185654 -7200 # Node ID e3ba2fa966f65760f597e0bb375924a9d244edf1 # Parent afa91be769ae2b674aa22a3708a57514af8b8b18 Various optimizations diff --git a/pytouhou/game/eclrunner.py b/pytouhou/game/eclrunner.py --- a/pytouhou/game/eclrunner.py +++ b/pytouhou/game/eclrunner.py @@ -38,21 +38,21 @@ class ECLRunner(object): def update(self): frame = self.frame - while frame <= self.frame: - try: + try: + while frame <= self.frame: frame, instr_type, rank_mask, param_mask, args = self.ecl.subs[self.sub][self.instruction_pointer] - except IndexError: - break #TODO: script ended, destroy enemy - if frame == self.frame: - try: - format, callback = self.implementation[instr_type] - except KeyError: - print('Warning: unhandled opcode %d!' % instr_type) #TODO - else: - callback(*unpack('<' + format, args)) - if frame <= self.frame: - self.instruction_pointer += 1 + if frame == self.frame: + try: + format, callback = self.implementation[instr_type] + except KeyError: + print('Warning: unhandled opcode %d!' % instr_type) #TODO + else: + callback(*unpack('<' + format, args)) + if frame <= self.frame: + self.instruction_pointer += 1 + except IndexError: + pass #TODO: script ended, destroy enemy self.frame += 1 diff --git a/pytouhou/game/sprite.py b/pytouhou/game/sprite.py --- a/pytouhou/game/sprite.py +++ b/pytouhou/game/sprite.py @@ -24,6 +24,7 @@ class Sprite(object): self.rotations_3d = (0., 0., 0.) self.rotations_speed_3d = (0., 0., 0.) self.corner_relative_placement = False + self.instruction_pointer = 0 self.frame = 0 self._uvs = [] self._vertices = [] @@ -54,60 +55,60 @@ class Sprite(object): if self.corner_relative_placement: # Reposition vertmat.translate(width / 2., height / 2., 0.) - uvs = [(tx / self.anm.size[0], 1. - (ty / self.anm.size[1])), - ((tx + tw) / self.anm.size[0], 1. - (ty / self.anm.size[1])), - ((tx + tw) / self.anm.size[0], 1. - ((ty + th) / self.anm.size[1])), - (tx / self.anm.size[0], 1. - ((ty + th) / self.anm.size[1]))] + x_1 = 1. / self.anm.size[0] + y_1 = 1. / self.anm.size[1] + uvs = [(tx * x_1, 1. - (ty * y_1)), + ((tx + tw) * x_1, 1. - (ty * y_1)), + ((tx + tw) * x_1, 1. - ((ty + th) * y_1)), + (tx * x_1, 1. - ((ty + th) * y_1))] - vertices = [] - for i in xrange(4): - w = vertmat.data[3][i] - vertices.append((vertmat.data[0][i] / w, - vertmat.data[1][i] / w, - vertmat.data[2][i] / w)) - - self._uvs, self._vertices = uvs, vertices + d = vertmat.data + assert (d[3][0], d[3][1], d[3][2], d[3][3]) == (1., 1., 1., 1.) + self._uvs, self._vertices = uvs, zip(d[0], d[1], d[2]) def update(self): - properties = {} - for time, instr_type, data in self.anm.scripts[self.script_index]: - if time == self.frame: - if instr_type == 15: #Return - break - else: - properties[instr_type] = data + changed = False + frame = self.frame + script = self.anm.scripts[self.script_index] + try: + while frame <= self.frame: + frame, instr_type, data = script[self.instruction_pointer] + if frame == self.frame: + changed = True + if instr_type == 1: + self.texcoords = self.anm.sprites[unpack('