changeset 72:6a08f44fa01b

Handle a few more ANM instructions. pytouhou.game.background needs some serious refactoring.
author Thibaut Girka <thib@sitedethib.com>
date Sun, 28 Aug 2011 01:23:11 +0200
parents a03d7a94b997
children e4af16a019d3
files eclviewer.py pytouhou/formats/anm0.py pytouhou/game/background.py pytouhou/game/enemymanager.py pytouhou/game/sprite.py pytouhou/vm/anmrunner.py
diffstat 6 files changed, 21 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- 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)
--- 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),
--- 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:
--- 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)
--- 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
--- 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):