annotate pytouhou/vm/anmrunner.py @ 430:c9433188ffdb

Remove AnmWrapper, since ANMs are lists of entries now.
author Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
date Sat, 03 Aug 2013 15:49:04 +0200
parents 40d5f3083ebc
children d4874ebaa06e
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
69
a142e57218a0 Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
1 # -*- encoding: utf-8 -*-
a142e57218a0 Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
2 ##
a142e57218a0 Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
3 ## Copyright (C) 2011 Thibaut Girka <thib@sitedethib.com>
a142e57218a0 Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
4 ##
a142e57218a0 Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
5 ## This program is free software; you can redistribute it and/or modify
a142e57218a0 Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
6 ## it under the terms of the GNU General Public License as published
a142e57218a0 Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
7 ## by the Free Software Foundation; version 3 only.
a142e57218a0 Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
8 ##
a142e57218a0 Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
9 ## This program is distributed in the hope that it will be useful,
a142e57218a0 Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
10 ## but WITHOUT ANY WARRANTY; without even the implied warranty of
a142e57218a0 Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
11 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
a142e57218a0 Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
12 ## GNU General Public License for more details.
a142e57218a0 Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
13 ##
a142e57218a0 Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
14
a142e57218a0 Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
15
429
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 376
diff changeset
16 from random import randrange, random
69
a142e57218a0 Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
17
a142e57218a0 Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
18 from pytouhou.utils.helpers import get_logger
a142e57218a0 Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
19 from pytouhou.vm.common import MetaRegistry, instruction
a142e57218a0 Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
20
a142e57218a0 Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
21 logger = get_logger(__name__)
a142e57218a0 Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
22
a142e57218a0 Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
23
a142e57218a0 Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
24 class ANMRunner(object):
a142e57218a0 Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
25 __metaclass__ = MetaRegistry
430
c9433188ffdb Remove AnmWrapper, since ANMs are lists of entries now.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 429
diff changeset
26 __slots__ = ('_anm', '_sprite', 'running', 'sprite_index_offset', 'script',
c9433188ffdb Remove AnmWrapper, since ANMs are lists of entries now.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 429
diff changeset
27 'instruction_pointer', 'frame', 'waiting', 'handlers',
c9433188ffdb Remove AnmWrapper, since ANMs are lists of entries now.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 429
diff changeset
28 'variables', 'version', 'timeout')
69
a142e57218a0 Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
29
429
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 376
diff changeset
30 #TODO: check!
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 376
diff changeset
31 formulae = {0: lambda x: x,
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 376
diff changeset
32 1: lambda x: x ** 2,
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 376
diff changeset
33 2: lambda x: x ** 3,
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 376
diff changeset
34 3: lambda x: x ** 4,
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 376
diff changeset
35 4: lambda x: 2 * x - x ** 2,
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 376
diff changeset
36 5: lambda x: 2 * x - x ** 3,
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 376
diff changeset
37 6: lambda x: 2 * x - x ** 4,
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 376
diff changeset
38 7: lambda x: x,
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 376
diff changeset
39 255: lambda x: x} #XXX
69
a142e57218a0 Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
40
430
c9433188ffdb Remove AnmWrapper, since ANMs are lists of entries now.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 429
diff changeset
41 def __init__(self, anm, script_id, sprite, sprite_index_offset=0):
c9433188ffdb Remove AnmWrapper, since ANMs are lists of entries now.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 429
diff changeset
42 self._anm = anm
69
a142e57218a0 Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
43 self._sprite = sprite
304
f3099ebf4f61 Update attribute names to reflect the actual interface.
Thibaut Girka <thib@sitedethib.com>
parents: 294
diff changeset
44 self.running = True
236
741860192b56 Implement ANM0 interrupts
Thibaut Girka <thib@sitedethib.com>
parents: 170
diff changeset
45 self.waiting = False
69
a142e57218a0 Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
46
430
c9433188ffdb Remove AnmWrapper, since ANMs are lists of entries now.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 429
diff changeset
47 self.script = anm.scripts[script_id]
429
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 376
diff changeset
48 self.version = anm.version
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 376
diff changeset
49 self.handlers = self._handlers[{0: 6, 2: 7}[anm.version]]
69
a142e57218a0 Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
50 self.frame = 0
429
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 376
diff changeset
51 self.timeout = -1
69
a142e57218a0 Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
52 self.instruction_pointer = 0
429
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 376
diff changeset
53 self.variables = [0, 0, 0, 0,
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 376
diff changeset
54 0., 0., 0., 0.,
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 376
diff changeset
55 0, 0, 0, 0]
81
f5f9b5eb69a3 Handle one more ANM instruction, and handle sprite indexes offsets
Thibaut Girka <thib@sitedethib.com>
parents: 72
diff changeset
56
f5f9b5eb69a3 Handle one more ANM instruction, and handle sprite indexes offsets
Thibaut Girka <thib@sitedethib.com>
parents: 72
diff changeset
57 self.sprite_index_offset = sprite_index_offset
69
a142e57218a0 Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
58
a142e57218a0 Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
59
236
741860192b56 Implement ANM0 interrupts
Thibaut Girka <thib@sitedethib.com>
parents: 170
diff changeset
60 def interrupt(self, interrupt):
741860192b56 Implement ANM0 interrupts
Thibaut Girka <thib@sitedethib.com>
parents: 170
diff changeset
61 new_ip = self.script.interrupts.get(interrupt, None)
741860192b56 Implement ANM0 interrupts
Thibaut Girka <thib@sitedethib.com>
parents: 170
diff changeset
62 if new_ip is None:
741860192b56 Implement ANM0 interrupts
Thibaut Girka <thib@sitedethib.com>
parents: 170
diff changeset
63 new_ip = self.script.interrupts.get(-1, None)
741860192b56 Implement ANM0 interrupts
Thibaut Girka <thib@sitedethib.com>
parents: 170
diff changeset
64 if new_ip is None:
741860192b56 Implement ANM0 interrupts
Thibaut Girka <thib@sitedethib.com>
parents: 170
diff changeset
65 return False
239
901489c21d19 Fix a few crashes in the anmrunner, disable fullscreen switch, change alt+Fx to shift+Fx
Thibaut Girka <thib@sitedethib.com>
parents: 238
diff changeset
66 self.instruction_pointer = new_ip
901489c21d19 Fix a few crashes in the anmrunner, disable fullscreen switch, change alt+Fx to shift+Fx
Thibaut Girka <thib@sitedethib.com>
parents: 238
diff changeset
67 self.frame, opcode, args = self.script[self.instruction_pointer]
901489c21d19 Fix a few crashes in the anmrunner, disable fullscreen switch, change alt+Fx to shift+Fx
Thibaut Girka <thib@sitedethib.com>
parents: 238
diff changeset
68 self.waiting = False
245
d3ba32a9096e Implement ANM0 instruction 29 and fix 24
Thibaut Girka <thib@sitedethib.com>
parents: 243
diff changeset
69 self._sprite.visible = True
239
901489c21d19 Fix a few crashes in the anmrunner, disable fullscreen switch, change alt+Fx to shift+Fx
Thibaut Girka <thib@sitedethib.com>
parents: 238
diff changeset
70 return True
236
741860192b56 Implement ANM0 interrupts
Thibaut Girka <thib@sitedethib.com>
parents: 170
diff changeset
71
741860192b56 Implement ANM0 interrupts
Thibaut Girka <thib@sitedethib.com>
parents: 170
diff changeset
72
69
a142e57218a0 Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
73 def run_frame(self):
304
f3099ebf4f61 Update attribute names to reflect the actual interface.
Thibaut Girka <thib@sitedethib.com>
parents: 294
diff changeset
74 if not self.running:
69
a142e57218a0 Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
75 return False
a142e57218a0 Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
76
122
174324a4da51 Add support for launch animations! (Warning: slow :()
Thibaut Girka <thib@sitedethib.com>
parents: 120
diff changeset
77 sprite = self._sprite
174324a4da51 Add support for launch animations! (Warning: slow :()
Thibaut Girka <thib@sitedethib.com>
parents: 120
diff changeset
78
304
f3099ebf4f61 Update attribute names to reflect the actual interface.
Thibaut Girka <thib@sitedethib.com>
parents: 294
diff changeset
79 while self.running and not self.waiting:
122
174324a4da51 Add support for launch animations! (Warning: slow :()
Thibaut Girka <thib@sitedethib.com>
parents: 120
diff changeset
80 frame, opcode, args = self.script[self.instruction_pointer]
69
a142e57218a0 Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
81
a142e57218a0 Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
82 if frame > self.frame:
a142e57218a0 Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
83 break
a142e57218a0 Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
84 else:
a142e57218a0 Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
85 self.instruction_pointer += 1
a142e57218a0 Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
86
a142e57218a0 Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
87 if frame == self.frame:
a142e57218a0 Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
88 try:
376
69ec72b990a4 Support more than one version of a vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 304
diff changeset
89 callback = self.handlers[opcode]
69
a142e57218a0 Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
90 except KeyError:
129
284ac8f97a96 Fix potential crash
Thibaut Girka <thib@sitedethib.com>
parents: 122
diff changeset
91 logger.warn('unhandled opcode %d (args: %r)', opcode, args)
69
a142e57218a0 Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
92 else:
429
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 376
diff changeset
93 logger.debug('[%d - %04d] anm_%d%r', id(self),
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 376
diff changeset
94 self.frame, opcode, args)
69
a142e57218a0 Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
95 callback(self, *args)
304
f3099ebf4f61 Update attribute names to reflect the actual interface.
Thibaut Girka <thib@sitedethib.com>
parents: 294
diff changeset
96 sprite.changed = True
240
02de1563fa18 Fix ANM wait, translation/rotation order, and partially implement ANM0 instruction 24
Thibaut Girka <thib@sitedethib.com>
parents: 239
diff changeset
97
243
3893a6fc66f1 Update sprite's property even while waiting
Thibaut Girka <thib@sitedethib.com>
parents: 240
diff changeset
98 if not self.waiting:
3893a6fc66f1 Update sprite's property even while waiting
Thibaut Girka <thib@sitedethib.com>
parents: 240
diff changeset
99 self.frame += 1
429
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 376
diff changeset
100 elif self.timeout == sprite.frame: #TODO: check if it’s happening at the correct frame.
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 376
diff changeset
101 self.waiting = False
120
4300a832f033 Small refactoring and massive performance improvement
Thibaut Girka <thib@sitedethib.com>
parents: 81
diff changeset
102
4300a832f033 Small refactoring and massive performance improvement
Thibaut Girka <thib@sitedethib.com>
parents: 81
diff changeset
103 # Update sprite
4300a832f033 Small refactoring and massive performance improvement
Thibaut Girka <thib@sitedethib.com>
parents: 81
diff changeset
104 sprite.frame += 1
4300a832f033 Small refactoring and massive performance improvement
Thibaut Girka <thib@sitedethib.com>
parents: 81
diff changeset
105
4300a832f033 Small refactoring and massive performance improvement
Thibaut Girka <thib@sitedethib.com>
parents: 81
diff changeset
106 if sprite.rotations_speed_3d != (0., 0., 0.):
4300a832f033 Small refactoring and massive performance improvement
Thibaut Girka <thib@sitedethib.com>
parents: 81
diff changeset
107 ax, ay, az = sprite.rotations_3d
4300a832f033 Small refactoring and massive performance improvement
Thibaut Girka <thib@sitedethib.com>
parents: 81
diff changeset
108 sax, say, saz = sprite.rotations_speed_3d
4300a832f033 Small refactoring and massive performance improvement
Thibaut Girka <thib@sitedethib.com>
parents: 81
diff changeset
109 sprite.rotations_3d = ax + sax, ay + say, az + saz
304
f3099ebf4f61 Update attribute names to reflect the actual interface.
Thibaut Girka <thib@sitedethib.com>
parents: 294
diff changeset
110 sprite.changed = True
429
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 376
diff changeset
111 elif sprite.rotation_interpolator:
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 376
diff changeset
112 sprite.rotation_interpolator.update(sprite.frame)
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 376
diff changeset
113 sprite.rotations_3d = sprite.rotation_interpolator.values
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 376
diff changeset
114 sprite.changed = True
120
4300a832f033 Small refactoring and massive performance improvement
Thibaut Girka <thib@sitedethib.com>
parents: 81
diff changeset
115
4300a832f033 Small refactoring and massive performance improvement
Thibaut Girka <thib@sitedethib.com>
parents: 81
diff changeset
116 if sprite.scale_speed != (0., 0.):
4300a832f033 Small refactoring and massive performance improvement
Thibaut Girka <thib@sitedethib.com>
parents: 81
diff changeset
117 rx, ry = sprite.rescale
4300a832f033 Small refactoring and massive performance improvement
Thibaut Girka <thib@sitedethib.com>
parents: 81
diff changeset
118 rsx, rsy = sprite.scale_speed
4300a832f033 Small refactoring and massive performance improvement
Thibaut Girka <thib@sitedethib.com>
parents: 81
diff changeset
119 sprite.rescale = rx + rsx, ry + rsy
304
f3099ebf4f61 Update attribute names to reflect the actual interface.
Thibaut Girka <thib@sitedethib.com>
parents: 294
diff changeset
120 sprite.changed = True
120
4300a832f033 Small refactoring and massive performance improvement
Thibaut Girka <thib@sitedethib.com>
parents: 81
diff changeset
121
4300a832f033 Small refactoring and massive performance improvement
Thibaut Girka <thib@sitedethib.com>
parents: 81
diff changeset
122 if sprite.fade_interpolator:
4300a832f033 Small refactoring and massive performance improvement
Thibaut Girka <thib@sitedethib.com>
parents: 81
diff changeset
123 sprite.fade_interpolator.update(sprite.frame)
4300a832f033 Small refactoring and massive performance improvement
Thibaut Girka <thib@sitedethib.com>
parents: 81
diff changeset
124 sprite.alpha = int(sprite.fade_interpolator.values[0])
304
f3099ebf4f61 Update attribute names to reflect the actual interface.
Thibaut Girka <thib@sitedethib.com>
parents: 294
diff changeset
125 sprite.changed = True
120
4300a832f033 Small refactoring and massive performance improvement
Thibaut Girka <thib@sitedethib.com>
parents: 81
diff changeset
126
4300a832f033 Small refactoring and massive performance improvement
Thibaut Girka <thib@sitedethib.com>
parents: 81
diff changeset
127 if sprite.scale_interpolator:
4300a832f033 Small refactoring and massive performance improvement
Thibaut Girka <thib@sitedethib.com>
parents: 81
diff changeset
128 sprite.scale_interpolator.update(sprite.frame)
4300a832f033 Small refactoring and massive performance improvement
Thibaut Girka <thib@sitedethib.com>
parents: 81
diff changeset
129 sprite.rescale = sprite.scale_interpolator.values
304
f3099ebf4f61 Update attribute names to reflect the actual interface.
Thibaut Girka <thib@sitedethib.com>
parents: 294
diff changeset
130 sprite.changed = True
120
4300a832f033 Small refactoring and massive performance improvement
Thibaut Girka <thib@sitedethib.com>
parents: 81
diff changeset
131
4300a832f033 Small refactoring and massive performance improvement
Thibaut Girka <thib@sitedethib.com>
parents: 81
diff changeset
132 if sprite.offset_interpolator:
4300a832f033 Small refactoring and massive performance improvement
Thibaut Girka <thib@sitedethib.com>
parents: 81
diff changeset
133 sprite.offset_interpolator.update(sprite.frame)
4300a832f033 Small refactoring and massive performance improvement
Thibaut Girka <thib@sitedethib.com>
parents: 81
diff changeset
134 sprite.dest_offset = sprite.offset_interpolator.values
304
f3099ebf4f61 Update attribute names to reflect the actual interface.
Thibaut Girka <thib@sitedethib.com>
parents: 294
diff changeset
135 sprite.changed = True
120
4300a832f033 Small refactoring and massive performance improvement
Thibaut Girka <thib@sitedethib.com>
parents: 81
diff changeset
136
429
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 376
diff changeset
137 if sprite.color_interpolator:
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 376
diff changeset
138 sprite.color_interpolator.update(sprite.frame)
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 376
diff changeset
139 sprite.color = sprite.color_interpolator.values
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 376
diff changeset
140 sprite.changed = True
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 376
diff changeset
141
304
f3099ebf4f61 Update attribute names to reflect the actual interface.
Thibaut Girka <thib@sitedethib.com>
parents: 294
diff changeset
142 return self.running
69
a142e57218a0 Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
143
a142e57218a0 Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
144
429
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 376
diff changeset
145 def _setval(self, variable_id, value):
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 376
diff changeset
146 if self.version == 2:
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 376
diff changeset
147 if 10000 <= variable_id <= 10011:
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 376
diff changeset
148 self.variables[int(variable_id-10000)] = value
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 376
diff changeset
149
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 376
diff changeset
150
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 376
diff changeset
151 def _getval(self, value):
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 376
diff changeset
152 if self.version == 2:
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 376
diff changeset
153 if 10000 <= value <= 10011:
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 376
diff changeset
154 return self.variables[int(value-10000)]
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 376
diff changeset
155 return value
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 376
diff changeset
156
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 376
diff changeset
157
69
a142e57218a0 Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
158 @instruction(0)
429
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 376
diff changeset
159 @instruction(1, 7)
69
a142e57218a0 Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
160 def remove(self):
304
f3099ebf4f61 Update attribute names to reflect the actual interface.
Thibaut Girka <thib@sitedethib.com>
parents: 294
diff changeset
161 self._sprite.removed = True
f3099ebf4f61 Update attribute names to reflect the actual interface.
Thibaut Girka <thib@sitedethib.com>
parents: 294
diff changeset
162 self.running = False
69
a142e57218a0 Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
163
a142e57218a0 Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
164
a142e57218a0 Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
165 @instruction(1)
429
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 376
diff changeset
166 @instruction(3, 7)
69
a142e57218a0 Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
167 def load_sprite(self, sprite_index):
429
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 376
diff changeset
168 #TODO: version 2 only: do not crash when assigning a non-existant sprite.
430
c9433188ffdb Remove AnmWrapper, since ANMs are lists of entries now.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 429
diff changeset
169 self._sprite.anm, self._sprite.texcoords = self._anm, self._anm.sprites[sprite_index + self.sprite_index_offset]
69
a142e57218a0 Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
170
a142e57218a0 Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
171
a142e57218a0 Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
172 @instruction(2)
429
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 376
diff changeset
173 @instruction(7, 7)
69
a142e57218a0 Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
174 def set_scale(self, sx, sy):
429
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 376
diff changeset
175 self._sprite.rescale = self._getval(sx), self._getval(sy)
69
a142e57218a0 Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
176
a142e57218a0 Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
177
a142e57218a0 Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
178 @instruction(3)
429
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 376
diff changeset
179 @instruction(8, 7)
69
a142e57218a0 Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
180 def set_alpha(self, alpha):
a142e57218a0 Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
181 self._sprite.alpha = alpha % 256 #TODO
a142e57218a0 Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
182
a142e57218a0 Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
183
a142e57218a0 Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
184 @instruction(4)
429
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 376
diff changeset
185 @instruction(9, 7)
69
a142e57218a0 Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
186 def set_color(self, b, g, r):
294
94c636f8f863 Add player lasers for MarisaB.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 245
diff changeset
187 if not self._sprite.fade_interpolator:
94c636f8f863 Add player lasers for MarisaB.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 245
diff changeset
188 self._sprite.color = (r, g, b)
69
a142e57218a0 Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
189
a142e57218a0 Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
190
a142e57218a0 Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
191 @instruction(5)
a142e57218a0 Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
192 def jump(self, instruction_pointer):
a142e57218a0 Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
193 #TODO: is that really how it works?
a142e57218a0 Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
194 self.instruction_pointer = instruction_pointer
a142e57218a0 Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
195 self.frame = self.script[self.instruction_pointer][0]
a142e57218a0 Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
196
a142e57218a0 Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
197
a142e57218a0 Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
198 @instruction(7)
429
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 376
diff changeset
199 @instruction(10, 7)
69
a142e57218a0 Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
200 def toggle_mirrored(self):
a142e57218a0 Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
201 self._sprite.mirrored = not self._sprite.mirrored
a142e57218a0 Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
202
a142e57218a0 Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
203
a142e57218a0 Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
204 @instruction(9)
429
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 376
diff changeset
205 @instruction(12, 7)
69
a142e57218a0 Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
206 def set_rotations_3d(self, rx, ry, rz):
429
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 376
diff changeset
207 self._sprite.rotations_3d = self._getval(rx), self._getval(ry), self._getval(rz)
69
a142e57218a0 Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
208
a142e57218a0 Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
209
a142e57218a0 Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
210 @instruction(10)
429
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 376
diff changeset
211 @instruction(13, 7)
69
a142e57218a0 Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
212 def set_rotations_speed_3d(self, srx, sry, srz):
429
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 376
diff changeset
213 self._sprite.rotations_speed_3d = self._getval(srx), self._getval(sry), self._getval(srz)
69
a142e57218a0 Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
214
a142e57218a0 Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
215
a142e57218a0 Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
216 @instruction(11)
429
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 376
diff changeset
217 @instruction(14, 7)
69
a142e57218a0 Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
218 def set_scale_speed(self, ssx, ssy):
a142e57218a0 Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
219 self._sprite.scale_speed = ssx, ssy
a142e57218a0 Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
220
a142e57218a0 Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
221
71
a03d7a94b997 Add support for a few ANM instructions
Thibaut Girka <thib@sitedethib.com>
parents: 69
diff changeset
222 @instruction(12)
429
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 376
diff changeset
223 @instruction(15, 7)
71
a03d7a94b997 Add support for a few ANM instructions
Thibaut Girka <thib@sitedethib.com>
parents: 69
diff changeset
224 def fade(self, new_alpha, duration):
a03d7a94b997 Add support for a few ANM instructions
Thibaut Girka <thib@sitedethib.com>
parents: 69
diff changeset
225 self._sprite.fade(duration, new_alpha, lambda x: x) #TODO: formula
a03d7a94b997 Add support for a few ANM instructions
Thibaut Girka <thib@sitedethib.com>
parents: 69
diff changeset
226
72
6a08f44fa01b Handle a few more ANM instructions. pytouhou.game.background needs some serious refactoring.
Thibaut Girka <thib@sitedethib.com>
parents: 71
diff changeset
227
6a08f44fa01b Handle a few more ANM instructions. pytouhou.game.background needs some serious refactoring.
Thibaut Girka <thib@sitedethib.com>
parents: 71
diff changeset
228 @instruction(13)
6a08f44fa01b Handle a few more ANM instructions. pytouhou.game.background needs some serious refactoring.
Thibaut Girka <thib@sitedethib.com>
parents: 71
diff changeset
229 def set_blendfunc_alphablend(self):
6a08f44fa01b Handle a few more ANM instructions. pytouhou.game.background needs some serious refactoring.
Thibaut Girka <thib@sitedethib.com>
parents: 71
diff changeset
230 self._sprite.blendfunc = 1
6a08f44fa01b Handle a few more ANM instructions. pytouhou.game.background needs some serious refactoring.
Thibaut Girka <thib@sitedethib.com>
parents: 71
diff changeset
231
6a08f44fa01b Handle a few more ANM instructions. pytouhou.game.background needs some serious refactoring.
Thibaut Girka <thib@sitedethib.com>
parents: 71
diff changeset
232
6a08f44fa01b Handle a few more ANM instructions. pytouhou.game.background needs some serious refactoring.
Thibaut Girka <thib@sitedethib.com>
parents: 71
diff changeset
233 @instruction(14)
6a08f44fa01b Handle a few more ANM instructions. pytouhou.game.background needs some serious refactoring.
Thibaut Girka <thib@sitedethib.com>
parents: 71
diff changeset
234 def set_blendfunc_add(self):
6a08f44fa01b Handle a few more ANM instructions. pytouhou.game.background needs some serious refactoring.
Thibaut Girka <thib@sitedethib.com>
parents: 71
diff changeset
235 self._sprite.blendfunc = 0 #TODO
6a08f44fa01b Handle a few more ANM instructions. pytouhou.game.background needs some serious refactoring.
Thibaut Girka <thib@sitedethib.com>
parents: 71
diff changeset
236
6a08f44fa01b Handle a few more ANM instructions. pytouhou.game.background needs some serious refactoring.
Thibaut Girka <thib@sitedethib.com>
parents: 71
diff changeset
237
71
a03d7a94b997 Add support for a few ANM instructions
Thibaut Girka <thib@sitedethib.com>
parents: 69
diff changeset
238 @instruction(15)
429
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 376
diff changeset
239 @instruction(2, 7)
71
a03d7a94b997 Add support for a few ANM instructions
Thibaut Girka <thib@sitedethib.com>
parents: 69
diff changeset
240 def keep_still(self):
304
f3099ebf4f61 Update attribute names to reflect the actual interface.
Thibaut Girka <thib@sitedethib.com>
parents: 294
diff changeset
241 self.running = False
71
a03d7a94b997 Add support for a few ANM instructions
Thibaut Girka <thib@sitedethib.com>
parents: 69
diff changeset
242
69
a142e57218a0 Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
243 @instruction(16)
a142e57218a0 Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
244 def load_random_sprite(self, min_idx, amp):
a142e57218a0 Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
245 #TODO: use the game's PRNG?
a142e57218a0 Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
246 self.load_sprite(min_idx + randrange(amp))
a142e57218a0 Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
247
a142e57218a0 Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
248
170
e7902309305c Implement move anm instructions.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 129
diff changeset
249 @instruction(17)
429
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 376
diff changeset
250 @instruction(6, 7)
170
e7902309305c Implement move anm instructions.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 129
diff changeset
251 def move(self, x, y, z):
e7902309305c Implement move anm instructions.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 129
diff changeset
252 self._sprite.dest_offset = (x, y, z)
e7902309305c Implement move anm instructions.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 129
diff changeset
253
e7902309305c Implement move anm instructions.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 129
diff changeset
254
e7902309305c Implement move anm instructions.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 129
diff changeset
255 @instruction(18)
429
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 376
diff changeset
256 @instruction(17, 7)
170
e7902309305c Implement move anm instructions.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 129
diff changeset
257 def move_in_linear(self, x, y, z, duration):
e7902309305c Implement move anm instructions.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 129
diff changeset
258 self._sprite.move_in(duration, x, y, z, lambda x: x)
e7902309305c Implement move anm instructions.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 129
diff changeset
259
e7902309305c Implement move anm instructions.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 129
diff changeset
260
71
a03d7a94b997 Add support for a few ANM instructions
Thibaut Girka <thib@sitedethib.com>
parents: 69
diff changeset
261 @instruction(19)
429
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 376
diff changeset
262 @instruction(18, 7)
170
e7902309305c Implement move anm instructions.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 129
diff changeset
263 def move_in_decel(self, x, y, z, duration):
e7902309305c Implement move anm instructions.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 129
diff changeset
264 self._sprite.move_in(duration, x, y, z, lambda x: 2. * x - x ** 2)
e7902309305c Implement move anm instructions.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 129
diff changeset
265
e7902309305c Implement move anm instructions.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 129
diff changeset
266
e7902309305c Implement move anm instructions.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 129
diff changeset
267 @instruction(20)
429
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 376
diff changeset
268 @instruction(19, 7)
170
e7902309305c Implement move anm instructions.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 129
diff changeset
269 def move_in_accel(self, x, y, z, duration):
e7902309305c Implement move anm instructions.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 129
diff changeset
270 self._sprite.move_in(duration, x, y, z, lambda x: x ** 2)
71
a03d7a94b997 Add support for a few ANM instructions
Thibaut Girka <thib@sitedethib.com>
parents: 69
diff changeset
271
a03d7a94b997 Add support for a few ANM instructions
Thibaut Girka <thib@sitedethib.com>
parents: 69
diff changeset
272
236
741860192b56 Implement ANM0 interrupts
Thibaut Girka <thib@sitedethib.com>
parents: 170
diff changeset
273 @instruction(21)
429
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 376
diff changeset
274 @instruction(20, 7)
236
741860192b56 Implement ANM0 interrupts
Thibaut Girka <thib@sitedethib.com>
parents: 170
diff changeset
275 def wait(self):
741860192b56 Implement ANM0 interrupts
Thibaut Girka <thib@sitedethib.com>
parents: 170
diff changeset
276 """Wait for an interrupt.
741860192b56 Implement ANM0 interrupts
Thibaut Girka <thib@sitedethib.com>
parents: 170
diff changeset
277 """
741860192b56 Implement ANM0 interrupts
Thibaut Girka <thib@sitedethib.com>
parents: 170
diff changeset
278 self.waiting = True
741860192b56 Implement ANM0 interrupts
Thibaut Girka <thib@sitedethib.com>
parents: 170
diff changeset
279
741860192b56 Implement ANM0 interrupts
Thibaut Girka <thib@sitedethib.com>
parents: 170
diff changeset
280
741860192b56 Implement ANM0 interrupts
Thibaut Girka <thib@sitedethib.com>
parents: 170
diff changeset
281 @instruction(22)
429
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 376
diff changeset
282 @instruction(21, 7)
236
741860192b56 Implement ANM0 interrupts
Thibaut Girka <thib@sitedethib.com>
parents: 170
diff changeset
283 def interrupt_label(self, interrupt):
741860192b56 Implement ANM0 interrupts
Thibaut Girka <thib@sitedethib.com>
parents: 170
diff changeset
284 """Noop"""
741860192b56 Implement ANM0 interrupts
Thibaut Girka <thib@sitedethib.com>
parents: 170
diff changeset
285 pass
741860192b56 Implement ANM0 interrupts
Thibaut Girka <thib@sitedethib.com>
parents: 170
diff changeset
286
741860192b56 Implement ANM0 interrupts
Thibaut Girka <thib@sitedethib.com>
parents: 170
diff changeset
287
69
a142e57218a0 Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
288 @instruction(23)
429
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 376
diff changeset
289 @instruction(22, 7)
69
a142e57218a0 Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
290 def set_corner_relative_placement(self):
a142e57218a0 Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
291 self._sprite.corner_relative_placement = True #TODO
a142e57218a0 Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
292
a142e57218a0 Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
293
240
02de1563fa18 Fix ANM wait, translation/rotation order, and partially implement ANM0 instruction 24
Thibaut Girka <thib@sitedethib.com>
parents: 239
diff changeset
294 @instruction(24)
429
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 376
diff changeset
295 @instruction(23, 7)
240
02de1563fa18 Fix ANM wait, translation/rotation order, and partially implement ANM0 instruction 24
Thibaut Girka <thib@sitedethib.com>
parents: 239
diff changeset
296 def wait_ex(self):
245
d3ba32a9096e Implement ANM0 instruction 29 and fix 24
Thibaut Girka <thib@sitedethib.com>
parents: 243
diff changeset
297 """Hide the sprite and wait for an interrupt.
240
02de1563fa18 Fix ANM wait, translation/rotation order, and partially implement ANM0 instruction 24
Thibaut Girka <thib@sitedethib.com>
parents: 239
diff changeset
298 """
245
d3ba32a9096e Implement ANM0 instruction 29 and fix 24
Thibaut Girka <thib@sitedethib.com>
parents: 243
diff changeset
299 self._sprite.visible = False
240
02de1563fa18 Fix ANM wait, translation/rotation order, and partially implement ANM0 instruction 24
Thibaut Girka <thib@sitedethib.com>
parents: 239
diff changeset
300 self.waiting = True
02de1563fa18 Fix ANM wait, translation/rotation order, and partially implement ANM0 instruction 24
Thibaut Girka <thib@sitedethib.com>
parents: 239
diff changeset
301
02de1563fa18 Fix ANM wait, translation/rotation order, and partially implement ANM0 instruction 24
Thibaut Girka <thib@sitedethib.com>
parents: 239
diff changeset
302
71
a03d7a94b997 Add support for a few ANM instructions
Thibaut Girka <thib@sitedethib.com>
parents: 69
diff changeset
303 @instruction(25)
429
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 376
diff changeset
304 @instruction(24, 7)
71
a03d7a94b997 Add support for a few ANM instructions
Thibaut Girka <thib@sitedethib.com>
parents: 69
diff changeset
305 def set_allow_dest_offset(self, value):
a03d7a94b997 Add support for a few ANM instructions
Thibaut Girka <thib@sitedethib.com>
parents: 69
diff changeset
306 self._sprite.allow_dest_offset = bool(value)
a03d7a94b997 Add support for a few ANM instructions
Thibaut Girka <thib@sitedethib.com>
parents: 69
diff changeset
307
a03d7a94b997 Add support for a few ANM instructions
Thibaut Girka <thib@sitedethib.com>
parents: 69
diff changeset
308
81
f5f9b5eb69a3 Handle one more ANM instruction, and handle sprite indexes offsets
Thibaut Girka <thib@sitedethib.com>
parents: 72
diff changeset
309 @instruction(26)
429
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 376
diff changeset
310 @instruction(25, 7)
81
f5f9b5eb69a3 Handle one more ANM instruction, and handle sprite indexes offsets
Thibaut Girka <thib@sitedethib.com>
parents: 72
diff changeset
311 def set_automatic_orientation(self, value):
f5f9b5eb69a3 Handle one more ANM instruction, and handle sprite indexes offsets
Thibaut Girka <thib@sitedethib.com>
parents: 72
diff changeset
312 """If true, rotate by pi-angle around the z axis.
f5f9b5eb69a3 Handle one more ANM instruction, and handle sprite indexes offsets
Thibaut Girka <thib@sitedethib.com>
parents: 72
diff changeset
313 """
f5f9b5eb69a3 Handle one more ANM instruction, and handle sprite indexes offsets
Thibaut Girka <thib@sitedethib.com>
parents: 72
diff changeset
314 self._sprite.automatic_orientation = bool(value)
f5f9b5eb69a3 Handle one more ANM instruction, and handle sprite indexes offsets
Thibaut Girka <thib@sitedethib.com>
parents: 72
diff changeset
315
f5f9b5eb69a3 Handle one more ANM instruction, and handle sprite indexes offsets
Thibaut Girka <thib@sitedethib.com>
parents: 72
diff changeset
316
69
a142e57218a0 Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
317 @instruction(27)
429
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 376
diff changeset
318 @instruction(26, 7)
69
a142e57218a0 Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
319 def shift_texture_x(self, dx):
a142e57218a0 Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
320 tox, toy = self._sprite.texoffsets
a142e57218a0 Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
321 self._sprite.texoffsets = tox + dx, toy
a142e57218a0 Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
322
a142e57218a0 Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
323
a142e57218a0 Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
324 @instruction(28)
429
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 376
diff changeset
325 @instruction(27, 7)
69
a142e57218a0 Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
326 def shift_texture_y(self, dy):
a142e57218a0 Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
327 tox, toy = self._sprite.texoffsets
a142e57218a0 Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
328 self._sprite.texoffsets = tox, toy + dy
a142e57218a0 Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
329
a142e57218a0 Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
330
245
d3ba32a9096e Implement ANM0 instruction 29 and fix 24
Thibaut Girka <thib@sitedethib.com>
parents: 243
diff changeset
331 @instruction(29)
429
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 376
diff changeset
332 @instruction(28, 7)
245
d3ba32a9096e Implement ANM0 instruction 29 and fix 24
Thibaut Girka <thib@sitedethib.com>
parents: 243
diff changeset
333 def set_visible(self, visible):
d3ba32a9096e Implement ANM0 instruction 29 and fix 24
Thibaut Girka <thib@sitedethib.com>
parents: 243
diff changeset
334 self._sprite.visible = bool(visible & 1)
d3ba32a9096e Implement ANM0 instruction 29 and fix 24
Thibaut Girka <thib@sitedethib.com>
parents: 243
diff changeset
335
d3ba32a9096e Implement ANM0 instruction 29 and fix 24
Thibaut Girka <thib@sitedethib.com>
parents: 243
diff changeset
336
71
a03d7a94b997 Add support for a few ANM instructions
Thibaut Girka <thib@sitedethib.com>
parents: 69
diff changeset
337 @instruction(30)
429
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 376
diff changeset
338 @instruction(29, 7)
71
a03d7a94b997 Add support for a few ANM instructions
Thibaut Girka <thib@sitedethib.com>
parents: 69
diff changeset
339 def scale_in(self, sx, sy, duration):
a03d7a94b997 Add support for a few ANM instructions
Thibaut Girka <thib@sitedethib.com>
parents: 69
diff changeset
340 self._sprite.scale_in(duration, sx, sy, lambda x: x) #TODO: formula
69
a142e57218a0 Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
341
429
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 376
diff changeset
342
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 376
diff changeset
343 # Now are the instructions new to anm2.
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 376
diff changeset
344
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 376
diff changeset
345
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 376
diff changeset
346 @instruction(0, 7)
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 376
diff changeset
347 def noop(self):
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 376
diff changeset
348 pass
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 376
diff changeset
349
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 376
diff changeset
350
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 376
diff changeset
351 @instruction(4, 7)
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 376
diff changeset
352 def jump_bis(self, instruction_pointer, frame):
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 376
diff changeset
353 self.instruction_pointer = instruction_pointer
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 376
diff changeset
354 self.frame = frame
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 376
diff changeset
355
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 376
diff changeset
356
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 376
diff changeset
357 @instruction(5, 7)
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 376
diff changeset
358 def jump_ex(self, variable_id, instruction_pointer, frame):
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 376
diff changeset
359 """If the given variable is non-zero, decrease it by 1 and jump to a
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 376
diff changeset
360 relative offset in the same subroutine.
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 376
diff changeset
361 """
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 376
diff changeset
362 counter_value = self._getval(variable_id) - 1
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 376
diff changeset
363 if counter_value > 0:
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 376
diff changeset
364 self._setval(variable_id, counter_value)
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 376
diff changeset
365 self.instruction_pointer = instruction_pointer
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 376
diff changeset
366 self.frame = frame
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 376
diff changeset
367
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 376
diff changeset
368
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 376
diff changeset
369 @instruction(16, 7)
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 376
diff changeset
370 def set_blendfunc(self, value):
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 376
diff changeset
371 self._sprite.blendfunc = bool(value & 1)
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 376
diff changeset
372
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 376
diff changeset
373
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 376
diff changeset
374 @instruction(32, 7)
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 376
diff changeset
375 def move_in_bis(self, duration, formula, x, y, z):
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 376
diff changeset
376 self._sprite.move_in(duration, x, y, z, self.formulae[formula])
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 376
diff changeset
377
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 376
diff changeset
378
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 376
diff changeset
379 @instruction(33, 7)
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 376
diff changeset
380 def change_color_in(self, duration, formula, r, g, b):
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 376
diff changeset
381 self._sprite.change_color_in(duration, r, g, b, self.formulae[formula])
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 376
diff changeset
382
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 376
diff changeset
383
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 376
diff changeset
384 @instruction(34, 7)
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 376
diff changeset
385 def fade_bis(self, duration, formula, new_alpha):
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 376
diff changeset
386 self._sprite.fade(duration, new_alpha, self.formulae[formula])
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 376
diff changeset
387
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 376
diff changeset
388
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 376
diff changeset
389 @instruction(35, 7)
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 376
diff changeset
390 def rotate_in_bis(self, duration, formula, rx, ry, rz):
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 376
diff changeset
391 self._sprite.rotate_in(duration, rx, ry, rz, self.formulae[formula])
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 376
diff changeset
392
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 376
diff changeset
393
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 376
diff changeset
394 @instruction(36, 7)
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 376
diff changeset
395 def scale_in_bis(self, duration, formula, sx, sy):
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 376
diff changeset
396 self._sprite.scale_in(duration, sx, sy, self.formulae[formula])
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 376
diff changeset
397
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 376
diff changeset
398
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 376
diff changeset
399 @instruction(37, 7)
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 376
diff changeset
400 @instruction(38, 7)
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 376
diff changeset
401 def set_variable(self, variable_id, value):
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 376
diff changeset
402 self._setval(variable_id, value)
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 376
diff changeset
403
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 376
diff changeset
404
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 376
diff changeset
405 @instruction(42, 7)
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 376
diff changeset
406 def decrement(self, variable_id, value):
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 376
diff changeset
407 self._setval(variable_id, self._getval(variable_id) - self._getval(value))
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 376
diff changeset
408
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 376
diff changeset
409
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 376
diff changeset
410 @instruction(50, 7)
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 376
diff changeset
411 def add(self, variable_id, a, b):
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 376
diff changeset
412 self._setval(variable_id, self._getval(a) + self._getval(b))
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 376
diff changeset
413
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 376
diff changeset
414
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 376
diff changeset
415 @instruction(52, 7)
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 376
diff changeset
416 def substract(self, variable_id, a, b):
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 376
diff changeset
417 self._setval(variable_id, self._getval(a) - self._getval(b))
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 376
diff changeset
418
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 376
diff changeset
419
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 376
diff changeset
420 @instruction(55, 7)
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 376
diff changeset
421 def divide_int(self, variable_id, a, b):
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 376
diff changeset
422 self._setval(variable_id, self._getval(a) // self._getval(b))
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 376
diff changeset
423
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 376
diff changeset
424
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 376
diff changeset
425 @instruction(59, 7)
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 376
diff changeset
426 def set_random_int(self, variable_id, amp):
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 376
diff changeset
427 #TODO: use the game's PRNG?
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 376
diff changeset
428 self._setval(variable_id, randrange(amp))
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 376
diff changeset
429
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 376
diff changeset
430
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 376
diff changeset
431 @instruction(60, 7)
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 376
diff changeset
432 def set_random_float(self, variable_id, amp):
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 376
diff changeset
433 #TODO: use the game's PRNG?
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 376
diff changeset
434 self._setval(variable_id, amp * random())
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 376
diff changeset
435
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 376
diff changeset
436
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 376
diff changeset
437 @instruction(69, 7)
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 376
diff changeset
438 def branch_if_not_equal(self, variable_id, value, instruction_pointer, frame):
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 376
diff changeset
439 if self._getval(variable_id) != value:
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 376
diff changeset
440 self.instruction_pointer = instruction_pointer
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 376
diff changeset
441 self.frame = frame
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 376
diff changeset
442 assert self.frame == self.script[self.instruction_pointer][0]
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 376
diff changeset
443
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 376
diff changeset
444
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 376
diff changeset
445 @instruction(79, 7)
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 376
diff changeset
446 def wait_duration(self, duration):
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 376
diff changeset
447 self.timeout = self._sprite.frame + duration
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 376
diff changeset
448 self.waiting = True