From 9b5018cadee8ae1f5599b20095f47e4fa8b0bcc0 Mon Sep 17 00:00:00 2001 From: Joe Wreschnig Date: Tue, 16 Mar 2010 03:01:31 -0700 Subject: [PATCH] Evaluation optimizations. --- bulletml/expr.py | 2 +- bulletml/impl.py | 6 +++--- bulletml/parser.py | 9 ++------- 3 files changed, 6 insertions(+), 11 deletions(-) diff --git a/bulletml/expr.py b/bulletml/expr.py index 9ca82ec..33f7d44 100644 --- a/bulletml/expr.py +++ b/bulletml/expr.py @@ -57,7 +57,7 @@ class NumberDef(object): if self.__value is not None: return self.__value rand = random.random() - variables = dict(rand=rand, rank=rank, params=params) + variables = { 'rand': rand, 'rank': rank, 'params': params } return eval(self.__expr, variables) def __repr__(self): diff --git a/bulletml/impl.py b/bulletml/impl.py index 4dde9fb..9139f9c 100644 --- a/bulletml/impl.py +++ b/bulletml/impl.py @@ -238,9 +238,9 @@ class Bullet(object): self.actions = [] if rank is None: rank = parent.rank if parent else 0.5 - for action, params in actions: - # New bullets reset the parent hierarchy. - self.actions.append(Action(self, None, action, params, rank)) + # New bullets reset the parent hierarchy. + self.actions = [Action(self, None, action, params, rank) + for action, params in actions] def __repr__(self): return ("%s(%r, %r, accel=%r, direction=%r, speed=%r, " diff --git a/bulletml/parser.py b/bulletml/parser.py index 187fa86..933be80 100644 --- a/bulletml/parser.py +++ b/bulletml/parser.py @@ -36,10 +36,7 @@ class ParamList(object): self.params.append(NumberDef(subelem.text)) def __call__(self, params, rank): - new_params = [param(params, rank) for param in self.params] - while len(new_params) < len(params): - new_params.append(params[len(new_params)]) - return new_params + return [param(params, rank) for param in self.params] def __repr__(self): return "%s(%r)" % (type(self).__name__, self.params) @@ -210,9 +207,7 @@ class BulletDef(object): self.actions.append(ActionRef(doc, subelem)) def __call__(self, params, rank): - actions = [] - for action in self.actions: - actions.append(action(params, rank)) + actions = [action(params, rank) for action in self.actions] return ( self.direction and self.direction(params, rank), self.speed and self.speed(params, rank), -- 2.20.1