# HG changeset patch # User Thibaut Girka # Date 1313179414 -7200 # Node ID afa91be769ae2b674aa22a3708a57514af8b8b18 # Parent f405b947624d6025c347afc58824ba2d3051e276 Don't lose time updating off-screen enemies' sprites diff --git a/pytouhou/game/background.py b/pytouhou/game/background.py --- a/pytouhou/game/background.py +++ b/pytouhou/game/background.py @@ -55,7 +55,8 @@ class Background(object): for script_index, ox, oy, oz, width_override, height_override in obj.quads: #TODO: per-texture rendering anm, sprite = self.anm_wrapper.get_sprite(script_index) - sprite.update(width_override, height_override) + if sprite.update(): + sprite.update_uvs_vertices(width_override, height_override) uvs, vertices = sprite._uvs, tuple((x + ox, y + oy, z + oz) for x, y, z in sprite._vertices) faces.append((vertices, uvs)) self.objects.append(faces) diff --git a/pytouhou/game/enemymanager.py b/pytouhou/game/enemymanager.py --- a/pytouhou/game/enemymanager.py +++ b/pytouhou/game/enemymanager.py @@ -95,13 +95,20 @@ class Enemy(object): def is_visible(self, screen_width, screen_height): if not self.sprite: return False - if min(x for x, y, z in self.sprite._vertices) >= screen_width - self.x: - return False - if max(x for x, y, z in self.sprite._vertices) <= -self.x: - return False - if min(y for x, y, z in self.sprite._vertices) >= screen_height - self.y: - return False - if max(y for x, y, z in self.sprite._vertices) <= -self.y: + + tx, ty, tw, th = self.sprite.texcoords + if self.sprite.corner_relative_placement: + raise Exception #TODO + else: + max_x = tw / 2. + max_y = th / 2. + min_x = -max_x + min_y = -max_y + + if any((min_x >= screen_width - self.x, + max_x <= -self.x, + min_y >= screen_height - self.y, + max_y <= -self.y)): return False return True @@ -146,7 +153,8 @@ class Enemy(object): self.x, self.y = x, y if self.sprite: - self.sprite.update() + if self.sprite.update() and self.is_visible(384, 448): #TODO: screen size + self.sprite.update_uvs_vertices() self.frame += 1 return True @@ -179,7 +187,6 @@ class EnemyManager(object): enemy = Enemy((x, y), life, instr_type, ecl_runner, self.anm_wrapper) def _enemy_deleter(unknown): #TOOD: unknown - print('youhou!') self.enemies.remove(enemy) ecl_runner.implementation[1] = ('I', _enemy_deleter) diff --git a/pytouhou/game/sprite.py b/pytouhou/game/sprite.py --- a/pytouhou/game/sprite.py +++ b/pytouhou/game/sprite.py @@ -70,7 +70,7 @@ class Sprite(object): - def update(self, override_width=0, override_height=0): + def update(self): properties = {} for time, instr_type, data in self.anm.scripts[self.script_index]: if time == self.frame: @@ -106,10 +106,8 @@ class Sprite(object): del properties[23] if properties: print('Leftover properties: %r' % properties) #TODO - self.update_uvs_vertices(override_width, override_height) return True if self.rotations_speed_3d != (0., 0., 0.): - self.update_uvs_vertices(override_width, override_height) return True return False