annotate pytouhou/vm/__init__.py @ 669:1bb8b34dbd32

Don’t allocate a Vec while reading a String in ECL.
author Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
date Mon, 12 Aug 2019 15:10:19 +0200
parents d1f0bb0b7a17
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
590
e15672733c93 Switch to Python 3.x instead of 2.7.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 547
diff changeset
1 from .anmrunner import ANMRunner
e15672733c93 Switch to Python 3.x instead of 2.7.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 547
diff changeset
2 from .msgrunner import MSGRunner
e15672733c93 Switch to Python 3.x instead of 2.7.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 547
diff changeset
3 from .eclrunner import ECLMainRunner
599
d471b07ce4fd Add a sample Python ECL.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 590
diff changeset
4
d471b07ce4fd Add a sample Python ECL.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 590
diff changeset
5
615
d1f0bb0b7a17 Don’t inherit explicitely from object, we are not on Python 2.7 anymore. :)
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 599
diff changeset
6 class PythonMainRunner:
599
d471b07ce4fd Add a sample Python ECL.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 590
diff changeset
7 def __init__(self, main, game):
d471b07ce4fd Add a sample Python ECL.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 590
diff changeset
8 self.main = main
d471b07ce4fd Add a sample Python ECL.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 590
diff changeset
9 self.game = game
d471b07ce4fd Add a sample Python ECL.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 590
diff changeset
10
d471b07ce4fd Add a sample Python ECL.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 590
diff changeset
11 def run_iter(self):
d471b07ce4fd Add a sample Python ECL.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 590
diff changeset
12 self.main(self.game)
d471b07ce4fd Add a sample Python ECL.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 590
diff changeset
13
d471b07ce4fd Add a sample Python ECL.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 590
diff changeset
14
615
d1f0bb0b7a17 Don’t inherit explicitely from object, we are not on Python 2.7 anymore. :)
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 599
diff changeset
15 class EnemyRunner:
599
d471b07ce4fd Add a sample Python ECL.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 590
diff changeset
16 def __init__(self, enemy, game, sub):
d471b07ce4fd Add a sample Python ECL.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 590
diff changeset
17 self.enemy = enemy
d471b07ce4fd Add a sample Python ECL.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 590
diff changeset
18 self.game = game
d471b07ce4fd Add a sample Python ECL.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 590
diff changeset
19 self.sub = sub
d471b07ce4fd Add a sample Python ECL.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 590
diff changeset
20
d471b07ce4fd Add a sample Python ECL.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 590
diff changeset
21 def run_iteration(self):
d471b07ce4fd Add a sample Python ECL.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 590
diff changeset
22 self.sub(self.enemy, self.game)
d471b07ce4fd Add a sample Python ECL.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 590
diff changeset
23
d471b07ce4fd Add a sample Python ECL.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 590
diff changeset
24
d471b07ce4fd Add a sample Python ECL.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 590
diff changeset
25 def spawn_enemy(game, sub, x=0., y=0., life=1, item=-1, score=0, mirrored=False, random=False):
d471b07ce4fd Add a sample Python ECL.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 590
diff changeset
26 instr_type = (2 if mirrored else 0) | (4 if random else 0)
d471b07ce4fd Add a sample Python ECL.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 590
diff changeset
27 enemy = game.new_enemy((x, y, 0.), life, instr_type, item, score)
d471b07ce4fd Add a sample Python ECL.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 590
diff changeset
28 enemy.process = EnemyRunner(enemy, game, sub)
d471b07ce4fd Add a sample Python ECL.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 590
diff changeset
29 enemy.process.run_iteration()