changeset 432:d4874ebaa06e

Split ANMRunner.run_frame into Sprite.update.
author Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
date Sat, 10 Aug 2013 15:18:44 +0200
parents 77c0e9a53795
children 1222341ea22c
files pytouhou/game/sprite.py pytouhou/vm/anmrunner.py
diffstat 2 files changed, 42 insertions(+), 42 deletions(-) [+]
line wrap: on
line diff
--- a/pytouhou/game/sprite.py
+++ b/pytouhou/game/sprite.py
@@ -100,3 +100,42 @@ class Sprite(object):
             self.force_rotation = force_rotation
             self.changed = True
 
+
+    def update(self):
+        self.frame += 1
+
+        if self.rotations_speed_3d != (0., 0., 0.):
+            ax, ay, az = self.rotations_3d
+            sax, say, saz = self.rotations_speed_3d
+            self.rotations_3d = ax + sax, ay + say, az + saz
+            self.changed = True
+        elif self.rotation_interpolator:
+            self.rotation_interpolator.update(self.frame)
+            self.rotations_3d = self.rotation_interpolator.values
+            self.changed = True
+
+        if self.scale_speed != (0., 0.):
+            rx, ry = self.rescale
+            rsx, rsy = self.scale_speed
+            self.rescale = rx + rsx, ry + rsy
+            self.changed = True
+
+        if self.fade_interpolator:
+            self.fade_interpolator.update(self.frame)
+            self.alpha = int(self.fade_interpolator.values[0])
+            self.changed = True
+
+        if self.scale_interpolator:
+            self.scale_interpolator.update(self.frame)
+            self.rescale = self.scale_interpolator.values
+            self.changed = True
+
+        if self.offset_interpolator:
+            self.offset_interpolator.update(self.frame)
+            self.dest_offset = self.offset_interpolator.values
+            self.changed = True
+
+        if self.color_interpolator:
+            self.color_interpolator.update(self.frame)
+            self.color = self.color_interpolator.values
+            self.changed = True
--- a/pytouhou/vm/anmrunner.py
+++ b/pytouhou/vm/anmrunner.py
@@ -74,8 +74,6 @@ class ANMRunner(object):
         if not self.running:
             return False
 
-        sprite = self._sprite
-
         while self.running and not self.waiting:
             frame, opcode, args = self.script[self.instruction_pointer]
 
@@ -93,51 +91,14 @@ class ANMRunner(object):
                     logger.debug('[%d - %04d] anm_%d%r', id(self),
                                  self.frame, opcode, args)
                     callback(self, *args)
-                    sprite.changed = True
+                    self._sprite.changed = True
 
         if not self.waiting:
             self.frame += 1
-        elif self.timeout == sprite.frame: #TODO: check if it’s happening at the correct frame.
+        elif self.timeout == self._sprite.frame: #TODO: check if it’s happening at the correct frame.
             self.waiting = False
 
-        # Update sprite
-        sprite.frame += 1
-
-        if sprite.rotations_speed_3d != (0., 0., 0.):
-            ax, ay, az = sprite.rotations_3d
-            sax, say, saz = sprite.rotations_speed_3d
-            sprite.rotations_3d = ax + sax, ay + say, az + saz
-            sprite.changed = True
-        elif sprite.rotation_interpolator:
-            sprite.rotation_interpolator.update(sprite.frame)
-            sprite.rotations_3d = sprite.rotation_interpolator.values
-            sprite.changed = True
-
-        if sprite.scale_speed != (0., 0.):
-            rx, ry = sprite.rescale
-            rsx, rsy = sprite.scale_speed
-            sprite.rescale = rx + rsx, ry + rsy
-            sprite.changed = True
-
-        if sprite.fade_interpolator:
-            sprite.fade_interpolator.update(sprite.frame)
-            sprite.alpha = int(sprite.fade_interpolator.values[0])
-            sprite.changed = True
-
-        if sprite.scale_interpolator:
-            sprite.scale_interpolator.update(sprite.frame)
-            sprite.rescale = sprite.scale_interpolator.values
-            sprite.changed = True
-
-        if sprite.offset_interpolator:
-            sprite.offset_interpolator.update(sprite.frame)
-            sprite.dest_offset = sprite.offset_interpolator.values
-            sprite.changed = True
-
-        if sprite.color_interpolator:
-            sprite.color_interpolator.update(sprite.frame)
-            sprite.color = sprite.color_interpolator.values
-            sprite.changed = True
+        self._sprite.update()
 
         return self.running