changeset 245:d3ba32a9096e

Implement ANM0 instruction 29 and fix 24
author Thibaut Girka <thib@sitedethib.com>
date Mon, 02 Jan 2012 18:46:55 +0100 (2012-01-02)
parents 2b7f69ad9ccd
children cb329dca4758
files pytouhou/formats/anm0.py pytouhou/game/sprite.py pytouhou/ui/renderer.pyx pytouhou/vm/anmrunner.py
diffstat 4 files changed, 12 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/pytouhou/formats/anm0.py
+++ b/pytouhou/formats/anm0.py
@@ -64,6 +64,7 @@ class Animations(object):
                      26: ('i', 'set_automatic_orientation'),
                      27: ('f', 'shift_texture_x'),
                      28: ('f', 'shift_texture_y'),
+                     29: ('i', 'set_visible'),
                      30: ('ffi', 'scale_in'),
                      31: ('i', None)}
 
--- a/pytouhou/game/sprite.py
+++ b/pytouhou/game/sprite.py
@@ -23,11 +23,12 @@ class Sprite(object):
                  'texcoords', 'dest_offset', 'allow_dest_offset', 'texoffsets',
                  'mirrored', 'rescale', 'scale_speed', 'rotations_3d',
                  'rotations_speed_3d', 'corner_relative_placement', 'frame',
-                 'color', 'alpha', '_rendering_data')
+                 'color', 'alpha', 'visible', '_rendering_data')
     def __init__(self, width_override=0, height_override=0):
         self.anm = None
         self._removed = False
         self._changed = True
+        self.visible = True
 
         self.width_override = width_override
         self.height_override = height_override
--- a/pytouhou/ui/renderer.pyx
+++ b/pytouhou/ui/renderer.pyx
@@ -48,7 +48,7 @@ cdef class Renderer:
 
         for element in elements:
             sprite = element._sprite
-            if sprite:
+            if sprite and sprite.visible:
                 ox, oy = element.x, element.y
                 key, (vertices, uvs, colors) = get_sprite_rendering_data(sprite)
                 rec = indices_by_texture.setdefault(key, [])
--- a/pytouhou/vm/anmrunner.py
+++ b/pytouhou/vm/anmrunner.py
@@ -51,6 +51,7 @@ class ANMRunner(object):
         self.instruction_pointer = new_ip
         self.frame, opcode, args = self.script[self.instruction_pointer]
         self.waiting = False
+        self._sprite.visible = True
         return True
 
 
@@ -231,9 +232,9 @@ class ANMRunner(object):
 
     @instruction(24)
     def wait_ex(self):
-        """Hide/delete the sprite and wait for an interrupt.
+        """Hide the sprite and wait for an interrupt.
         """
-        #TODO: Hide/delete the sprite and figure what happens exactly
+        self._sprite.visible = False
         self.waiting = True
 
 
@@ -261,6 +262,11 @@ class ANMRunner(object):
         self._sprite.texoffsets = tox, toy + dy
 
 
+    @instruction(29)
+    def set_visible(self, visible):
+        self._sprite.visible = bool(visible & 1)
+
+
     @instruction(30)
     def scale_in(self, sx, sy, duration):
         self._sprite.scale_in(duration, sx, sy, lambda x: x) #TODO: formula