# HG changeset patch # User Thibaut Girka # Date 1314487391 -7200 # Node ID 6a08f44fa01b433f4d02aa4ef6f5aa94b3caade1 # Parent a03d7a94b9974e96f7af599fc083e384a2dc6366 Handle a few more ANM instructions. pytouhou.game.background needs some serious refactoring. diff --git a/eclviewer.py b/eclviewer.py --- a/eclviewer.py +++ b/eclviewer.py @@ -130,7 +130,8 @@ def main(path, stage_num): glTranslatef(-x, -y, -z) glEnable(GL_DEPTH_TEST) - for texture_key, (nb_vertices, vertices, uvs, colors) in background.objects_by_texture.items(): + for (texture_key, blendfunc), (nb_vertices, vertices, uvs, colors) in background.objects_by_texture.items(): + glBlendFunc(GL_SRC_ALPHA, {0: GL_ONE_MINUS_SRC_ALPHA, 1: GL_ONE}[blendfunc]) glBindTexture(GL_TEXTURE_2D, texture_manager[texture_key]) glVertexPointer(3, GL_FLOAT, 0, vertices) glTexCoordPointer(2, GL_FLOAT, 0, uvs) @@ -150,7 +151,8 @@ def main(path, stage_num): 192., 224., 0., 0., -1., 0.) glDisable(GL_FOG) - for texture_key, (nb_vertices, vertices, uvs, colors) in enemy_manager.objects_by_texture.items(): + for (texture_key, blendfunc), (nb_vertices, vertices, uvs, colors) in enemy_manager.objects_by_texture.items(): + glBlendFunc(GL_SRC_ALPHA, {0: GL_ONE_MINUS_SRC_ALPHA, 1: GL_ONE}[blendfunc]) glBindTexture(GL_TEXTURE_2D, texture_manager[texture_key]) glVertexPointer(3, GL_FLOAT, 0, vertices) glTexCoordPointer(2, GL_FLOAT, 0, uvs) diff --git a/pytouhou/formats/anm0.py b/pytouhou/formats/anm0.py --- a/pytouhou/formats/anm0.py +++ b/pytouhou/formats/anm0.py @@ -33,8 +33,8 @@ class Animations(object): 10: ('fff', 'set_3d_rotations_speed'), 11: ('ff', 'set_scale_speed'), 12: ('ii', 'fade'), - 13: ('', None), - 14: ('', None), + 13: ('', 'set_blendmode_add'), + 14: ('', 'set_blendmode_alphablend'), 15: ('', 'keep_still'), 16: ('i', 'set_random_sprite'), 17: ('fff', None), diff --git a/pytouhou/game/background.py b/pytouhou/game/background.py --- a/pytouhou/game/background.py +++ b/pytouhou/game/background.py @@ -97,7 +97,7 @@ class Background(object): colors = struct.pack(colors_format, *chain(*colors)) assert len(self.anm_wrapper.anm_files) == 1 #TODO anm = self.anm_wrapper.anm_files[0] - self.objects_by_texture = {(anm.first_name, anm.secondary_name): (nb_vertices, vertices, uvs, colors)} + self.objects_by_texture = {((anm.first_name, anm.secondary_name), 0): (nb_vertices, vertices, uvs, colors)} #TODO: blendfunc for frame_num, message_type, args in self.stage.script: if frame_num == frame: diff --git a/pytouhou/game/enemymanager.py b/pytouhou/game/enemymanager.py --- a/pytouhou/game/enemymanager.py +++ b/pytouhou/game/enemymanager.py @@ -142,6 +142,7 @@ class Enemy(object): def get_objects_by_texture(self): objects_by_texture = {} key = self._sprite.anm.first_name, self._sprite.anm.secondary_name + key = (key, self._sprite.blendfunc) if not key in objects_by_texture: objects_by_texture[key] = (0, [], [], []) vertices = tuple((x + self.x, y + self.y, z) for x, y, z in self._sprite._vertices) diff --git a/pytouhou/game/sprite.py b/pytouhou/game/sprite.py --- a/pytouhou/game/sprite.py +++ b/pytouhou/game/sprite.py @@ -47,6 +47,8 @@ class Sprite(object): self.fade_interpolator = None self.offset_interpolator = None + self.blendfunc = 0 # 0 = Normal, 1 = saturate #TODO: proper constants + self.texcoords = (0, 0, 0, 0) # x, y, width, height self.dest_offset = (0., 0., 0.) self.allow_dest_offset = False diff --git a/pytouhou/vm/anmrunner.py b/pytouhou/vm/anmrunner.py --- a/pytouhou/vm/anmrunner.py +++ b/pytouhou/vm/anmrunner.py @@ -122,6 +122,17 @@ class ANMRunner(object): def fade(self, new_alpha, duration): self._sprite.fade(duration, new_alpha, lambda x: x) #TODO: formula + + @instruction(13) + def set_blendfunc_alphablend(self): + self._sprite.blendfunc = 1 + + + @instruction(14) + def set_blendfunc_add(self): + self._sprite.blendfunc = 0 #TODO + + @instruction(15) @instruction(21) #TODO def keep_still(self):