Mercurial > touhou
annotate pytouhou/vm/anmrunner.py @ 589:0768122da817
Add a frameskip option, and use swap interval to implement it.
author | Emmanuel Gil Peyrot <linkmauve@linkmauve.fr> |
---|---|
date | Fri, 10 Oct 2014 15:59:11 +0200 |
parents | e4c9eafab6d0 |
children | e15672733c93 |
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! |
489
59bd29568753
Remove identity lambda for interpolators, improves performances slightly.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
470
diff
changeset
|
31 formulae = {0: None, |
429
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, |
489
59bd29568753
Remove identity lambda for interpolators, improves performances slightly.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
470
diff
changeset
|
38 7: None, |
59bd29568753
Remove identity lambda for interpolators, improves performances slightly.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
470
diff
changeset
|
39 255: None} #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 |
433
1222341ea22c
Always run the first frame of an ANMRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
432
diff
changeset
|
58 self.run_frame() |
470
98995d8ac744
Reset ANMRunner.sprite_index_offset after the first frame, fixes bullettype 7; also forbid glitch bullet types.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
433
diff
changeset
|
59 self.sprite_index_offset = 0 |
433
1222341ea22c
Always run the first frame of an ANMRunner.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
432
diff
changeset
|
60 |
69
a142e57218a0
Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
61 |
236
741860192b56
Implement ANM0 interrupts
Thibaut Girka <thib@sitedethib.com>
parents:
170
diff
changeset
|
62 def interrupt(self, interrupt): |
741860192b56
Implement ANM0 interrupts
Thibaut Girka <thib@sitedethib.com>
parents:
170
diff
changeset
|
63 new_ip = self.script.interrupts.get(interrupt, 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 new_ip = self.script.interrupts.get(-1, None) |
741860192b56
Implement ANM0 interrupts
Thibaut Girka <thib@sitedethib.com>
parents:
170
diff
changeset
|
66 if new_ip is None: |
741860192b56
Implement ANM0 interrupts
Thibaut Girka <thib@sitedethib.com>
parents:
170
diff
changeset
|
67 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
|
68 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
|
69 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
|
70 self.waiting = False |
245
d3ba32a9096e
Implement ANM0 instruction 29 and fix 24
Thibaut Girka <thib@sitedethib.com>
parents:
243
diff
changeset
|
71 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
|
72 return True |
236
741860192b56
Implement ANM0 interrupts
Thibaut Girka <thib@sitedethib.com>
parents:
170
diff
changeset
|
73 |
741860192b56
Implement ANM0 interrupts
Thibaut Girka <thib@sitedethib.com>
parents:
170
diff
changeset
|
74 |
69
a142e57218a0
Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
75 def run_frame(self): |
304
f3099ebf4f61
Update attribute names to reflect the actual interface.
Thibaut Girka <thib@sitedethib.com>
parents:
294
diff
changeset
|
76 if not self.running: |
69
a142e57218a0
Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
77 return False |
a142e57218a0
Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
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: |
575
e4c9eafab6d0
Don’t log every instruction executed, nobody is interested in that, and demote unhandled opcodes to debug.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
489
diff
changeset
|
91 logger.debug('[%d - %04d] unhandled opcode %d (args: %r)', |
e4c9eafab6d0
Don’t log every instruction executed, nobody is interested in that, and demote unhandled opcodes to debug.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
489
diff
changeset
|
92 id(self), self.frame, opcode, args) |
69
a142e57218a0
Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
93 else: |
a142e57218a0
Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
94 callback(self, *args) |
432
d4874ebaa06e
Split ANMRunner.run_frame into Sprite.update.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
430
diff
changeset
|
95 self._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
|
96 |
243
3893a6fc66f1
Update sprite's property even while waiting
Thibaut Girka <thib@sitedethib.com>
parents:
240
diff
changeset
|
97 if not self.waiting: |
3893a6fc66f1
Update sprite's property even while waiting
Thibaut Girka <thib@sitedethib.com>
parents:
240
diff
changeset
|
98 self.frame += 1 |
432
d4874ebaa06e
Split ANMRunner.run_frame into Sprite.update.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
430
diff
changeset
|
99 elif self.timeout == self._sprite.frame: #TODO: check if it’s happening at the correct frame. |
429
40d5f3083ebc
Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
376
diff
changeset
|
100 self.waiting = False |
120
4300a832f033
Small refactoring and massive performance improvement
Thibaut Girka <thib@sitedethib.com>
parents:
81
diff
changeset
|
101 |
432
d4874ebaa06e
Split ANMRunner.run_frame into Sprite.update.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
430
diff
changeset
|
102 self._sprite.update() |
429
40d5f3083ebc
Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
376
diff
changeset
|
103 |
304
f3099ebf4f61
Update attribute names to reflect the actual interface.
Thibaut Girka <thib@sitedethib.com>
parents:
294
diff
changeset
|
104 return self.running |
69
a142e57218a0
Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
105 |
a142e57218a0
Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
106 |
429
40d5f3083ebc
Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
376
diff
changeset
|
107 def _setval(self, variable_id, value): |
40d5f3083ebc
Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
376
diff
changeset
|
108 if self.version == 2: |
40d5f3083ebc
Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
376
diff
changeset
|
109 if 10000 <= variable_id <= 10011: |
40d5f3083ebc
Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
376
diff
changeset
|
110 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
|
111 |
40d5f3083ebc
Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
376
diff
changeset
|
112 |
40d5f3083ebc
Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
376
diff
changeset
|
113 def _getval(self, value): |
40d5f3083ebc
Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
376
diff
changeset
|
114 if self.version == 2: |
40d5f3083ebc
Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
376
diff
changeset
|
115 if 10000 <= value <= 10011: |
40d5f3083ebc
Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
376
diff
changeset
|
116 return self.variables[int(value-10000)] |
40d5f3083ebc
Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
376
diff
changeset
|
117 return value |
40d5f3083ebc
Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
376
diff
changeset
|
118 |
40d5f3083ebc
Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
376
diff
changeset
|
119 |
69
a142e57218a0
Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
120 @instruction(0) |
429
40d5f3083ebc
Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
376
diff
changeset
|
121 @instruction(1, 7) |
69
a142e57218a0
Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
122 def remove(self): |
304
f3099ebf4f61
Update attribute names to reflect the actual interface.
Thibaut Girka <thib@sitedethib.com>
parents:
294
diff
changeset
|
123 self._sprite.removed = True |
f3099ebf4f61
Update attribute names to reflect the actual interface.
Thibaut Girka <thib@sitedethib.com>
parents:
294
diff
changeset
|
124 self.running = False |
69
a142e57218a0
Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
125 |
a142e57218a0
Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
126 |
a142e57218a0
Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
127 @instruction(1) |
429
40d5f3083ebc
Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
376
diff
changeset
|
128 @instruction(3, 7) |
69
a142e57218a0
Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
129 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
|
130 #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
|
131 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
|
132 |
a142e57218a0
Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
133 |
a142e57218a0
Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
134 @instruction(2) |
429
40d5f3083ebc
Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
376
diff
changeset
|
135 @instruction(7, 7) |
69
a142e57218a0
Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
136 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
|
137 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
|
138 |
a142e57218a0
Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
139 |
a142e57218a0
Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
140 @instruction(3) |
429
40d5f3083ebc
Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
376
diff
changeset
|
141 @instruction(8, 7) |
69
a142e57218a0
Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
142 def set_alpha(self, alpha): |
a142e57218a0
Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
143 self._sprite.alpha = alpha % 256 #TODO |
a142e57218a0
Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
144 |
a142e57218a0
Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
145 |
a142e57218a0
Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
146 @instruction(4) |
429
40d5f3083ebc
Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
376
diff
changeset
|
147 @instruction(9, 7) |
69
a142e57218a0
Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
148 def set_color(self, b, g, r): |
294
94c636f8f863
Add player lasers for MarisaB.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
245
diff
changeset
|
149 if not self._sprite.fade_interpolator: |
94c636f8f863
Add player lasers for MarisaB.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
245
diff
changeset
|
150 self._sprite.color = (r, g, b) |
69
a142e57218a0
Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
151 |
a142e57218a0
Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
152 |
a142e57218a0
Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
153 @instruction(5) |
a142e57218a0
Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
154 def jump(self, instruction_pointer): |
a142e57218a0
Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
155 #TODO: is that really how it works? |
a142e57218a0
Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
156 self.instruction_pointer = instruction_pointer |
a142e57218a0
Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
157 self.frame = self.script[self.instruction_pointer][0] |
a142e57218a0
Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
158 |
a142e57218a0
Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
159 |
a142e57218a0
Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
160 @instruction(7) |
429
40d5f3083ebc
Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
376
diff
changeset
|
161 @instruction(10, 7) |
69
a142e57218a0
Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
162 def toggle_mirrored(self): |
a142e57218a0
Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
163 self._sprite.mirrored = not self._sprite.mirrored |
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 |
a142e57218a0
Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
166 @instruction(9) |
429
40d5f3083ebc
Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
376
diff
changeset
|
167 @instruction(12, 7) |
69
a142e57218a0
Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
168 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
|
169 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
|
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(10) |
429
40d5f3083ebc
Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
376
diff
changeset
|
173 @instruction(13, 7) |
69
a142e57218a0
Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
174 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
|
175 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
|
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(11) |
429
40d5f3083ebc
Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
376
diff
changeset
|
179 @instruction(14, 7) |
69
a142e57218a0
Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
180 def set_scale_speed(self, ssx, ssy): |
a142e57218a0
Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
181 self._sprite.scale_speed = ssx, ssy |
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 |
71
a03d7a94b997
Add support for a few ANM instructions
Thibaut Girka <thib@sitedethib.com>
parents:
69
diff
changeset
|
184 @instruction(12) |
429
40d5f3083ebc
Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
376
diff
changeset
|
185 @instruction(15, 7) |
71
a03d7a94b997
Add support for a few ANM instructions
Thibaut Girka <thib@sitedethib.com>
parents:
69
diff
changeset
|
186 def fade(self, new_alpha, duration): |
489
59bd29568753
Remove identity lambda for interpolators, improves performances slightly.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
470
diff
changeset
|
187 self._sprite.fade(duration, new_alpha) |
71
a03d7a94b997
Add support for a few ANM instructions
Thibaut Girka <thib@sitedethib.com>
parents:
69
diff
changeset
|
188 |
72
6a08f44fa01b
Handle a few more ANM instructions. pytouhou.game.background needs some serious refactoring.
Thibaut Girka <thib@sitedethib.com>
parents:
71
diff
changeset
|
189 |
6a08f44fa01b
Handle a few more ANM instructions. pytouhou.game.background needs some serious refactoring.
Thibaut Girka <thib@sitedethib.com>
parents:
71
diff
changeset
|
190 @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
|
191 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
|
192 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
|
193 |
6a08f44fa01b
Handle a few more ANM instructions. pytouhou.game.background needs some serious refactoring.
Thibaut Girka <thib@sitedethib.com>
parents:
71
diff
changeset
|
194 |
6a08f44fa01b
Handle a few more ANM instructions. pytouhou.game.background needs some serious refactoring.
Thibaut Girka <thib@sitedethib.com>
parents:
71
diff
changeset
|
195 @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
|
196 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
|
197 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
|
198 |
6a08f44fa01b
Handle a few more ANM instructions. pytouhou.game.background needs some serious refactoring.
Thibaut Girka <thib@sitedethib.com>
parents:
71
diff
changeset
|
199 |
71
a03d7a94b997
Add support for a few ANM instructions
Thibaut Girka <thib@sitedethib.com>
parents:
69
diff
changeset
|
200 @instruction(15) |
429
40d5f3083ebc
Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
376
diff
changeset
|
201 @instruction(2, 7) |
71
a03d7a94b997
Add support for a few ANM instructions
Thibaut Girka <thib@sitedethib.com>
parents:
69
diff
changeset
|
202 def keep_still(self): |
304
f3099ebf4f61
Update attribute names to reflect the actual interface.
Thibaut Girka <thib@sitedethib.com>
parents:
294
diff
changeset
|
203 self.running = False |
71
a03d7a94b997
Add support for a few ANM instructions
Thibaut Girka <thib@sitedethib.com>
parents:
69
diff
changeset
|
204 |
69
a142e57218a0
Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
205 @instruction(16) |
a142e57218a0
Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
206 def load_random_sprite(self, min_idx, amp): |
a142e57218a0
Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
207 #TODO: use the game's PRNG? |
a142e57218a0
Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
208 self.load_sprite(min_idx + randrange(amp)) |
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 |
170
e7902309305c
Implement move anm instructions.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
129
diff
changeset
|
211 @instruction(17) |
429
40d5f3083ebc
Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
376
diff
changeset
|
212 @instruction(6, 7) |
170
e7902309305c
Implement move anm instructions.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
129
diff
changeset
|
213 def move(self, x, y, z): |
e7902309305c
Implement move anm instructions.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
129
diff
changeset
|
214 self._sprite.dest_offset = (x, y, z) |
e7902309305c
Implement move anm instructions.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
129
diff
changeset
|
215 |
e7902309305c
Implement move anm instructions.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
129
diff
changeset
|
216 |
e7902309305c
Implement move anm instructions.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
129
diff
changeset
|
217 @instruction(18) |
429
40d5f3083ebc
Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
376
diff
changeset
|
218 @instruction(17, 7) |
170
e7902309305c
Implement move anm instructions.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
129
diff
changeset
|
219 def move_in_linear(self, x, y, z, duration): |
489
59bd29568753
Remove identity lambda for interpolators, improves performances slightly.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
470
diff
changeset
|
220 self._sprite.move_in(duration, x, y, z) |
170
e7902309305c
Implement move anm instructions.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
129
diff
changeset
|
221 |
e7902309305c
Implement move anm instructions.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
129
diff
changeset
|
222 |
71
a03d7a94b997
Add support for a few ANM instructions
Thibaut Girka <thib@sitedethib.com>
parents:
69
diff
changeset
|
223 @instruction(19) |
429
40d5f3083ebc
Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
376
diff
changeset
|
224 @instruction(18, 7) |
170
e7902309305c
Implement move anm instructions.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
129
diff
changeset
|
225 def move_in_decel(self, x, y, z, duration): |
e7902309305c
Implement move anm instructions.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
129
diff
changeset
|
226 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
|
227 |
e7902309305c
Implement move anm instructions.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
129
diff
changeset
|
228 |
e7902309305c
Implement move anm instructions.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
129
diff
changeset
|
229 @instruction(20) |
429
40d5f3083ebc
Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
376
diff
changeset
|
230 @instruction(19, 7) |
170
e7902309305c
Implement move anm instructions.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
129
diff
changeset
|
231 def move_in_accel(self, x, y, z, duration): |
e7902309305c
Implement move anm instructions.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
129
diff
changeset
|
232 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
|
233 |
a03d7a94b997
Add support for a few ANM instructions
Thibaut Girka <thib@sitedethib.com>
parents:
69
diff
changeset
|
234 |
236
741860192b56
Implement ANM0 interrupts
Thibaut Girka <thib@sitedethib.com>
parents:
170
diff
changeset
|
235 @instruction(21) |
429
40d5f3083ebc
Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
376
diff
changeset
|
236 @instruction(20, 7) |
236
741860192b56
Implement ANM0 interrupts
Thibaut Girka <thib@sitedethib.com>
parents:
170
diff
changeset
|
237 def wait(self): |
741860192b56
Implement ANM0 interrupts
Thibaut Girka <thib@sitedethib.com>
parents:
170
diff
changeset
|
238 """Wait for an interrupt. |
741860192b56
Implement ANM0 interrupts
Thibaut Girka <thib@sitedethib.com>
parents:
170
diff
changeset
|
239 """ |
741860192b56
Implement ANM0 interrupts
Thibaut Girka <thib@sitedethib.com>
parents:
170
diff
changeset
|
240 self.waiting = True |
741860192b56
Implement ANM0 interrupts
Thibaut Girka <thib@sitedethib.com>
parents:
170
diff
changeset
|
241 |
741860192b56
Implement ANM0 interrupts
Thibaut Girka <thib@sitedethib.com>
parents:
170
diff
changeset
|
242 |
741860192b56
Implement ANM0 interrupts
Thibaut Girka <thib@sitedethib.com>
parents:
170
diff
changeset
|
243 @instruction(22) |
429
40d5f3083ebc
Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
376
diff
changeset
|
244 @instruction(21, 7) |
236
741860192b56
Implement ANM0 interrupts
Thibaut Girka <thib@sitedethib.com>
parents:
170
diff
changeset
|
245 def interrupt_label(self, interrupt): |
741860192b56
Implement ANM0 interrupts
Thibaut Girka <thib@sitedethib.com>
parents:
170
diff
changeset
|
246 """Noop""" |
741860192b56
Implement ANM0 interrupts
Thibaut Girka <thib@sitedethib.com>
parents:
170
diff
changeset
|
247 pass |
741860192b56
Implement ANM0 interrupts
Thibaut Girka <thib@sitedethib.com>
parents:
170
diff
changeset
|
248 |
741860192b56
Implement ANM0 interrupts
Thibaut Girka <thib@sitedethib.com>
parents:
170
diff
changeset
|
249 |
69
a142e57218a0
Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
250 @instruction(23) |
429
40d5f3083ebc
Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
376
diff
changeset
|
251 @instruction(22, 7) |
69
a142e57218a0
Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
252 def set_corner_relative_placement(self): |
a142e57218a0
Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
253 self._sprite.corner_relative_placement = True #TODO |
a142e57218a0
Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
254 |
a142e57218a0
Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
255 |
240
02de1563fa18
Fix ANM wait, translation/rotation order, and partially implement ANM0 instruction 24
Thibaut Girka <thib@sitedethib.com>
parents:
239
diff
changeset
|
256 @instruction(24) |
429
40d5f3083ebc
Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
376
diff
changeset
|
257 @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
|
258 def wait_ex(self): |
245
d3ba32a9096e
Implement ANM0 instruction 29 and fix 24
Thibaut Girka <thib@sitedethib.com>
parents:
243
diff
changeset
|
259 """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
|
260 """ |
245
d3ba32a9096e
Implement ANM0 instruction 29 and fix 24
Thibaut Girka <thib@sitedethib.com>
parents:
243
diff
changeset
|
261 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
|
262 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
|
263 |
02de1563fa18
Fix ANM wait, translation/rotation order, and partially implement ANM0 instruction 24
Thibaut Girka <thib@sitedethib.com>
parents:
239
diff
changeset
|
264 |
71
a03d7a94b997
Add support for a few ANM instructions
Thibaut Girka <thib@sitedethib.com>
parents:
69
diff
changeset
|
265 @instruction(25) |
429
40d5f3083ebc
Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
376
diff
changeset
|
266 @instruction(24, 7) |
71
a03d7a94b997
Add support for a few ANM instructions
Thibaut Girka <thib@sitedethib.com>
parents:
69
diff
changeset
|
267 def set_allow_dest_offset(self, value): |
a03d7a94b997
Add support for a few ANM instructions
Thibaut Girka <thib@sitedethib.com>
parents:
69
diff
changeset
|
268 self._sprite.allow_dest_offset = bool(value) |
a03d7a94b997
Add support for a few ANM instructions
Thibaut Girka <thib@sitedethib.com>
parents:
69
diff
changeset
|
269 |
a03d7a94b997
Add support for a few ANM instructions
Thibaut Girka <thib@sitedethib.com>
parents:
69
diff
changeset
|
270 |
81
f5f9b5eb69a3
Handle one more ANM instruction, and handle sprite indexes offsets
Thibaut Girka <thib@sitedethib.com>
parents:
72
diff
changeset
|
271 @instruction(26) |
429
40d5f3083ebc
Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
376
diff
changeset
|
272 @instruction(25, 7) |
81
f5f9b5eb69a3
Handle one more ANM instruction, and handle sprite indexes offsets
Thibaut Girka <thib@sitedethib.com>
parents:
72
diff
changeset
|
273 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
|
274 """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
|
275 """ |
f5f9b5eb69a3
Handle one more ANM instruction, and handle sprite indexes offsets
Thibaut Girka <thib@sitedethib.com>
parents:
72
diff
changeset
|
276 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
|
277 |
f5f9b5eb69a3
Handle one more ANM instruction, and handle sprite indexes offsets
Thibaut Girka <thib@sitedethib.com>
parents:
72
diff
changeset
|
278 |
69
a142e57218a0
Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
279 @instruction(27) |
429
40d5f3083ebc
Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
376
diff
changeset
|
280 @instruction(26, 7) |
69
a142e57218a0
Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
281 def shift_texture_x(self, dx): |
a142e57218a0
Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
282 tox, toy = self._sprite.texoffsets |
a142e57218a0
Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
283 self._sprite.texoffsets = tox + dx, toy |
a142e57218a0
Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
284 |
a142e57218a0
Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
285 |
a142e57218a0
Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
286 @instruction(28) |
429
40d5f3083ebc
Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
376
diff
changeset
|
287 @instruction(27, 7) |
69
a142e57218a0
Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
288 def shift_texture_y(self, dy): |
a142e57218a0
Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
289 tox, toy = self._sprite.texoffsets |
a142e57218a0
Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
290 self._sprite.texoffsets = tox, toy + dy |
a142e57218a0
Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
291 |
a142e57218a0
Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
292 |
245
d3ba32a9096e
Implement ANM0 instruction 29 and fix 24
Thibaut Girka <thib@sitedethib.com>
parents:
243
diff
changeset
|
293 @instruction(29) |
429
40d5f3083ebc
Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
376
diff
changeset
|
294 @instruction(28, 7) |
245
d3ba32a9096e
Implement ANM0 instruction 29 and fix 24
Thibaut Girka <thib@sitedethib.com>
parents:
243
diff
changeset
|
295 def set_visible(self, visible): |
d3ba32a9096e
Implement ANM0 instruction 29 and fix 24
Thibaut Girka <thib@sitedethib.com>
parents:
243
diff
changeset
|
296 self._sprite.visible = bool(visible & 1) |
d3ba32a9096e
Implement ANM0 instruction 29 and fix 24
Thibaut Girka <thib@sitedethib.com>
parents:
243
diff
changeset
|
297 |
d3ba32a9096e
Implement ANM0 instruction 29 and fix 24
Thibaut Girka <thib@sitedethib.com>
parents:
243
diff
changeset
|
298 |
71
a03d7a94b997
Add support for a few ANM instructions
Thibaut Girka <thib@sitedethib.com>
parents:
69
diff
changeset
|
299 @instruction(30) |
429
40d5f3083ebc
Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
376
diff
changeset
|
300 @instruction(29, 7) |
71
a03d7a94b997
Add support for a few ANM instructions
Thibaut Girka <thib@sitedethib.com>
parents:
69
diff
changeset
|
301 def scale_in(self, sx, sy, duration): |
489
59bd29568753
Remove identity lambda for interpolators, improves performances slightly.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
470
diff
changeset
|
302 self._sprite.scale_in(duration, sx, sy) |
69
a142e57218a0
Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
303 |
429
40d5f3083ebc
Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
376
diff
changeset
|
304 |
40d5f3083ebc
Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
376
diff
changeset
|
305 # 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
|
306 |
40d5f3083ebc
Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
376
diff
changeset
|
307 |
40d5f3083ebc
Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
376
diff
changeset
|
308 @instruction(0, 7) |
40d5f3083ebc
Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
376
diff
changeset
|
309 def noop(self): |
40d5f3083ebc
Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
376
diff
changeset
|
310 pass |
40d5f3083ebc
Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
376
diff
changeset
|
311 |
40d5f3083ebc
Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
376
diff
changeset
|
312 |
40d5f3083ebc
Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
376
diff
changeset
|
313 @instruction(4, 7) |
40d5f3083ebc
Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
376
diff
changeset
|
314 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
|
315 self.instruction_pointer = instruction_pointer |
40d5f3083ebc
Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
376
diff
changeset
|
316 self.frame = frame |
40d5f3083ebc
Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
376
diff
changeset
|
317 |
40d5f3083ebc
Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
376
diff
changeset
|
318 |
40d5f3083ebc
Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
376
diff
changeset
|
319 @instruction(5, 7) |
40d5f3083ebc
Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
376
diff
changeset
|
320 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
|
321 """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
|
322 relative offset in the same subroutine. |
40d5f3083ebc
Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
376
diff
changeset
|
323 """ |
40d5f3083ebc
Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
376
diff
changeset
|
324 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
|
325 if counter_value > 0: |
40d5f3083ebc
Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
376
diff
changeset
|
326 self._setval(variable_id, counter_value) |
40d5f3083ebc
Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
376
diff
changeset
|
327 self.instruction_pointer = instruction_pointer |
40d5f3083ebc
Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
376
diff
changeset
|
328 self.frame = frame |
40d5f3083ebc
Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
376
diff
changeset
|
329 |
40d5f3083ebc
Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
376
diff
changeset
|
330 |
40d5f3083ebc
Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
376
diff
changeset
|
331 @instruction(16, 7) |
40d5f3083ebc
Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
376
diff
changeset
|
332 def set_blendfunc(self, value): |
40d5f3083ebc
Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
376
diff
changeset
|
333 self._sprite.blendfunc = bool(value & 1) |
40d5f3083ebc
Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
376
diff
changeset
|
334 |
40d5f3083ebc
Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
376
diff
changeset
|
335 |
40d5f3083ebc
Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
376
diff
changeset
|
336 @instruction(32, 7) |
40d5f3083ebc
Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
376
diff
changeset
|
337 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
|
338 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
|
339 |
40d5f3083ebc
Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
376
diff
changeset
|
340 |
40d5f3083ebc
Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
376
diff
changeset
|
341 @instruction(33, 7) |
40d5f3083ebc
Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
376
diff
changeset
|
342 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
|
343 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
|
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(34, 7) |
40d5f3083ebc
Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
376
diff
changeset
|
347 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
|
348 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
|
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(35, 7) |
40d5f3083ebc
Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
376
diff
changeset
|
352 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
|
353 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
|
354 |
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 @instruction(36, 7) |
40d5f3083ebc
Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
376
diff
changeset
|
357 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
|
358 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
|
359 |
40d5f3083ebc
Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
376
diff
changeset
|
360 |
40d5f3083ebc
Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
376
diff
changeset
|
361 @instruction(37, 7) |
40d5f3083ebc
Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
376
diff
changeset
|
362 @instruction(38, 7) |
40d5f3083ebc
Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
376
diff
changeset
|
363 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
|
364 self._setval(variable_id, value) |
40d5f3083ebc
Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
376
diff
changeset
|
365 |
40d5f3083ebc
Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
376
diff
changeset
|
366 |
40d5f3083ebc
Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
376
diff
changeset
|
367 @instruction(42, 7) |
40d5f3083ebc
Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
376
diff
changeset
|
368 def decrement(self, variable_id, value): |
40d5f3083ebc
Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
376
diff
changeset
|
369 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
|
370 |
40d5f3083ebc
Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
376
diff
changeset
|
371 |
40d5f3083ebc
Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
376
diff
changeset
|
372 @instruction(50, 7) |
40d5f3083ebc
Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
376
diff
changeset
|
373 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
|
374 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
|
375 |
40d5f3083ebc
Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
376
diff
changeset
|
376 |
40d5f3083ebc
Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
376
diff
changeset
|
377 @instruction(52, 7) |
40d5f3083ebc
Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
376
diff
changeset
|
378 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
|
379 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
|
380 |
40d5f3083ebc
Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
376
diff
changeset
|
381 |
40d5f3083ebc
Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
376
diff
changeset
|
382 @instruction(55, 7) |
40d5f3083ebc
Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
376
diff
changeset
|
383 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
|
384 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
|
385 |
40d5f3083ebc
Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
376
diff
changeset
|
386 |
40d5f3083ebc
Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
376
diff
changeset
|
387 @instruction(59, 7) |
40d5f3083ebc
Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
376
diff
changeset
|
388 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
|
389 #TODO: use the game's PRNG? |
40d5f3083ebc
Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
376
diff
changeset
|
390 self._setval(variable_id, randrange(amp)) |
40d5f3083ebc
Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
376
diff
changeset
|
391 |
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 @instruction(60, 7) |
40d5f3083ebc
Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
376
diff
changeset
|
394 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
|
395 #TODO: use the game's PRNG? |
40d5f3083ebc
Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
376
diff
changeset
|
396 self._setval(variable_id, amp * random()) |
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(69, 7) |
40d5f3083ebc
Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
376
diff
changeset
|
400 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
|
401 if self._getval(variable_id) != value: |
40d5f3083ebc
Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
376
diff
changeset
|
402 self.instruction_pointer = instruction_pointer |
40d5f3083ebc
Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
376
diff
changeset
|
403 self.frame = frame |
40d5f3083ebc
Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
376
diff
changeset
|
404 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
|
405 |
40d5f3083ebc
Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
376
diff
changeset
|
406 |
40d5f3083ebc
Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
376
diff
changeset
|
407 @instruction(79, 7) |
40d5f3083ebc
Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
376
diff
changeset
|
408 def wait_duration(self, duration): |
40d5f3083ebc
Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
376
diff
changeset
|
409 self.timeout = self._sprite.frame + duration |
40d5f3083ebc
Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
376
diff
changeset
|
410 self.waiting = True |