Action, Bullet: Minor optimizations.
authorJoe Wreschnig <joe.wreschnig@gmail.com>
Thu, 22 Apr 2010 03:04:58 +0000 (20:04 -0700)
committerJoe Wreschnig <joe.wreschnig@gmail.com>
Thu, 22 Apr 2010 03:04:58 +0000 (20:04 -0700)
bulletml/impl.py

index ea4893f42dacfaf91cc1b7bcc0693400d2d27d8e..dad560104ac190f58c792ea269b572d5cbca7b98 100644 (file)
@@ -4,7 +4,7 @@ from __future__ import division
 
 from math import atan2, sin, cos
 
-from bulletml import parser
+from bulletml.parser import ActionDef, ActionRef
 
 __all__ = ["Action", "Bullet"]
 
@@ -74,8 +74,6 @@ class Action(object):
 
     def step(self, owner, created):
         """Advance by one frame."""
-        s_params = self.params
-        rank = owner.rank
 
         if self.speed_frames > 0:
             self.speed_frames -= 1
@@ -101,6 +99,9 @@ class Action(object):
             self.wait_frames -= 1
             return
 
+        s_params = self.params
+        rank = owner.rank
+
         while True:
             self.pc += 1
 
@@ -119,7 +120,7 @@ class Action(object):
                     self.pc = 0
                     action = self.actions[self.pc]
 
-            if isinstance(action, (parser.ActionDef, parser.ActionRef)):
+            if isinstance(action, (ActionDef, ActionRef)):
                 child = self.Child(action, s_params, rank)
                 owner.replace(self, child)
                 child.step(owner, created)
@@ -248,9 +249,11 @@ class Bullet(object):
         for action in self.actions:
             action.step(self, created)
 
+        speed = self.speed
+        direction = self.direction
         self.px = self.x
         self.py = self.y
-        self.x += self.mx + sin(self.direction) * self.speed
-        self.y += -self.my + cos(self.direction) * self.speed
+        self.x += self.mx + sin(direction) * speed
+        self.y += -self.my + cos(direction) * speed
 
         return created