Mercurial > touhou
annotate pytouhou/vm/anmrunner.py @ 649:967627181a76
Use the merged name of RGB in AnmRenderer.
See https://github.com/phaazon/luminance-rs/pull/150 for reasoning.
author | Emmanuel Gil Peyrot <linkmauve@linkmauve.fr> |
---|---|
date | Thu, 08 Aug 2019 13:39:28 +0200 |
parents | e15672733c93 |
children |
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 |
590
e15672733c93
Switch to Python 3.x instead of 2.7.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
575
diff
changeset
|
24 class ANMRunner(metaclass=MetaRegistry): |
430
c9433188ffdb
Remove AnmWrapper, since ANMs are lists of entries now.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
429
diff
changeset
|
25 __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
|
26 '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
|
27 'variables', 'version', 'timeout') |
69
a142e57218a0
Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
28 |
429
40d5f3083ebc
Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
376
diff
changeset
|
29 #TODO: check! |
489
59bd29568753
Remove identity lambda for interpolators, improves performances slightly.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
470
diff
changeset
|
30 formulae = {0: None, |
429
40d5f3083ebc
Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
376
diff
changeset
|
31 1: lambda x: x ** 2, |
40d5f3083ebc
Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
376
diff
changeset
|
32 2: lambda x: x ** 3, |
40d5f3083ebc
Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
376
diff
changeset
|
33 3: lambda x: x ** 4, |
40d5f3083ebc
Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
376
diff
changeset
|
34 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
|
35 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
|
36 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
|
37 7: None, |
59bd29568753
Remove identity lambda for interpolators, improves performances slightly.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
470
diff
changeset
|
38 255: None} #XXX |
69
a142e57218a0
Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
39 |
430
c9433188ffdb
Remove AnmWrapper, since ANMs are lists of entries now.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
429
diff
changeset
|
40 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
|
41 self._anm = anm |
69
a142e57218a0
Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
42 self._sprite = sprite |
304
f3099ebf4f61
Update attribute names to reflect the actual interface.
Thibaut Girka <thib@sitedethib.com>
parents:
294
diff
changeset
|
43 self.running = True |
236
741860192b56
Implement ANM0 interrupts
Thibaut Girka <thib@sitedethib.com>
parents:
170
diff
changeset
|
44 self.waiting = False |
69
a142e57218a0
Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
45 |
430
c9433188ffdb
Remove AnmWrapper, since ANMs are lists of entries now.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
429
diff
changeset
|
46 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
|
47 self.version = anm.version |
40d5f3083ebc
Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
376
diff
changeset
|
48 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
|
49 self.frame = 0 |
429
40d5f3083ebc
Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
376
diff
changeset
|
50 self.timeout = -1 |
69
a142e57218a0
Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
51 self.instruction_pointer = 0 |
429
40d5f3083ebc
Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
376
diff
changeset
|
52 self.variables = [0, 0, 0, 0, |
40d5f3083ebc
Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
376
diff
changeset
|
53 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] |
81
f5f9b5eb69a3
Handle one more ANM instruction, and handle sprite indexes offsets
Thibaut Girka <thib@sitedethib.com>
parents:
72
diff
changeset
|
55 |
f5f9b5eb69a3
Handle one more ANM instruction, and handle sprite indexes offsets
Thibaut Girka <thib@sitedethib.com>
parents:
72
diff
changeset
|
56 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
|
57 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
|
58 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
|
59 |
69
a142e57218a0
Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
60 |
236
741860192b56
Implement ANM0 interrupts
Thibaut Girka <thib@sitedethib.com>
parents:
170
diff
changeset
|
61 def interrupt(self, interrupt): |
741860192b56
Implement ANM0 interrupts
Thibaut Girka <thib@sitedethib.com>
parents:
170
diff
changeset
|
62 new_ip = self.script.interrupts.get(interrupt, None) |
741860192b56
Implement ANM0 interrupts
Thibaut Girka <thib@sitedethib.com>
parents:
170
diff
changeset
|
63 if new_ip is None: |
741860192b56
Implement ANM0 interrupts
Thibaut Girka <thib@sitedethib.com>
parents:
170
diff
changeset
|
64 new_ip = self.script.interrupts.get(-1, None) |
741860192b56
Implement ANM0 interrupts
Thibaut Girka <thib@sitedethib.com>
parents:
170
diff
changeset
|
65 if new_ip is None: |
741860192b56
Implement ANM0 interrupts
Thibaut Girka <thib@sitedethib.com>
parents:
170
diff
changeset
|
66 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
|
67 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
|
68 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
|
69 self.waiting = False |
245
d3ba32a9096e
Implement ANM0 instruction 29 and fix 24
Thibaut Girka <thib@sitedethib.com>
parents:
243
diff
changeset
|
70 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
|
71 return True |
236
741860192b56
Implement ANM0 interrupts
Thibaut Girka <thib@sitedethib.com>
parents:
170
diff
changeset
|
72 |
741860192b56
Implement ANM0 interrupts
Thibaut Girka <thib@sitedethib.com>
parents:
170
diff
changeset
|
73 |
69
a142e57218a0
Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
74 def run_frame(self): |
304
f3099ebf4f61
Update attribute names to reflect the actual interface.
Thibaut Girka <thib@sitedethib.com>
parents:
294
diff
changeset
|
75 if not self.running: |
69
a142e57218a0
Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
76 return False |
a142e57218a0
Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
77 |
304
f3099ebf4f61
Update attribute names to reflect the actual interface.
Thibaut Girka <thib@sitedethib.com>
parents:
294
diff
changeset
|
78 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
|
79 frame, opcode, args = self.script[self.instruction_pointer] |
69
a142e57218a0
Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
80 |
a142e57218a0
Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
81 if frame > self.frame: |
a142e57218a0
Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
82 break |
a142e57218a0
Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
83 else: |
a142e57218a0
Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
84 self.instruction_pointer += 1 |
a142e57218a0
Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
85 |
a142e57218a0
Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
86 if frame == self.frame: |
a142e57218a0
Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
87 try: |
376
69ec72b990a4
Support more than one version of a vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
304
diff
changeset
|
88 callback = self.handlers[opcode] |
69
a142e57218a0
Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
89 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
|
90 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
|
91 id(self), self.frame, opcode, args) |
69
a142e57218a0
Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
92 else: |
a142e57218a0
Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
93 callback(self, *args) |
432
d4874ebaa06e
Split ANMRunner.run_frame into Sprite.update.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
430
diff
changeset
|
94 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
|
95 |
243
3893a6fc66f1
Update sprite's property even while waiting
Thibaut Girka <thib@sitedethib.com>
parents:
240
diff
changeset
|
96 if not self.waiting: |
3893a6fc66f1
Update sprite's property even while waiting
Thibaut Girka <thib@sitedethib.com>
parents:
240
diff
changeset
|
97 self.frame += 1 |
432
d4874ebaa06e
Split ANMRunner.run_frame into Sprite.update.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
430
diff
changeset
|
98 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
|
99 self.waiting = False |
120
4300a832f033
Small refactoring and massive performance improvement
Thibaut Girka <thib@sitedethib.com>
parents:
81
diff
changeset
|
100 |
432
d4874ebaa06e
Split ANMRunner.run_frame into Sprite.update.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
430
diff
changeset
|
101 self._sprite.update() |
429
40d5f3083ebc
Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
376
diff
changeset
|
102 |
304
f3099ebf4f61
Update attribute names to reflect the actual interface.
Thibaut Girka <thib@sitedethib.com>
parents:
294
diff
changeset
|
103 return self.running |
69
a142e57218a0
Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
104 |
a142e57218a0
Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
105 |
429
40d5f3083ebc
Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
376
diff
changeset
|
106 def _setval(self, variable_id, value): |
40d5f3083ebc
Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
376
diff
changeset
|
107 if self.version == 2: |
40d5f3083ebc
Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
376
diff
changeset
|
108 if 10000 <= variable_id <= 10011: |
40d5f3083ebc
Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
376
diff
changeset
|
109 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
|
110 |
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 def _getval(self, value): |
40d5f3083ebc
Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
376
diff
changeset
|
113 if self.version == 2: |
40d5f3083ebc
Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
376
diff
changeset
|
114 if 10000 <= value <= 10011: |
40d5f3083ebc
Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
376
diff
changeset
|
115 return self.variables[int(value-10000)] |
40d5f3083ebc
Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
376
diff
changeset
|
116 return value |
40d5f3083ebc
Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
376
diff
changeset
|
117 |
40d5f3083ebc
Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
376
diff
changeset
|
118 |
69
a142e57218a0
Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
119 @instruction(0) |
429
40d5f3083ebc
Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
376
diff
changeset
|
120 @instruction(1, 7) |
69
a142e57218a0
Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
121 def remove(self): |
304
f3099ebf4f61
Update attribute names to reflect the actual interface.
Thibaut Girka <thib@sitedethib.com>
parents:
294
diff
changeset
|
122 self._sprite.removed = True |
f3099ebf4f61
Update attribute names to reflect the actual interface.
Thibaut Girka <thib@sitedethib.com>
parents:
294
diff
changeset
|
123 self.running = False |
69
a142e57218a0
Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
124 |
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 @instruction(1) |
429
40d5f3083ebc
Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
376
diff
changeset
|
127 @instruction(3, 7) |
69
a142e57218a0
Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
128 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
|
129 #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
|
130 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
|
131 |
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 @instruction(2) |
429
40d5f3083ebc
Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
376
diff
changeset
|
134 @instruction(7, 7) |
69
a142e57218a0
Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
135 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
|
136 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
|
137 |
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 @instruction(3) |
429
40d5f3083ebc
Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
376
diff
changeset
|
140 @instruction(8, 7) |
69
a142e57218a0
Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
141 def set_alpha(self, alpha): |
a142e57218a0
Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
142 self._sprite.alpha = alpha % 256 #TODO |
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 |
a142e57218a0
Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
145 @instruction(4) |
429
40d5f3083ebc
Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
376
diff
changeset
|
146 @instruction(9, 7) |
69
a142e57218a0
Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
147 def set_color(self, b, g, r): |
294
94c636f8f863
Add player lasers for MarisaB.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
245
diff
changeset
|
148 if not self._sprite.fade_interpolator: |
94c636f8f863
Add player lasers for MarisaB.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
245
diff
changeset
|
149 self._sprite.color = (r, g, b) |
69
a142e57218a0
Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
150 |
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 @instruction(5) |
a142e57218a0
Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
153 def jump(self, instruction_pointer): |
a142e57218a0
Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
154 #TODO: is that really how it works? |
a142e57218a0
Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
155 self.instruction_pointer = instruction_pointer |
a142e57218a0
Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
156 self.frame = self.script[self.instruction_pointer][0] |
a142e57218a0
Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
157 |
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 @instruction(7) |
429
40d5f3083ebc
Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
376
diff
changeset
|
160 @instruction(10, 7) |
69
a142e57218a0
Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
161 def toggle_mirrored(self): |
a142e57218a0
Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
162 self._sprite.mirrored = not self._sprite.mirrored |
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(9) |
429
40d5f3083ebc
Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
376
diff
changeset
|
166 @instruction(12, 7) |
69
a142e57218a0
Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
167 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
|
168 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
|
169 |
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 @instruction(10) |
429
40d5f3083ebc
Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
376
diff
changeset
|
172 @instruction(13, 7) |
69
a142e57218a0
Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
173 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
|
174 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
|
175 |
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 @instruction(11) |
429
40d5f3083ebc
Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
376
diff
changeset
|
178 @instruction(14, 7) |
69
a142e57218a0
Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
179 def set_scale_speed(self, ssx, ssy): |
a142e57218a0
Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
180 self._sprite.scale_speed = ssx, ssy |
a142e57218a0
Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
181 |
a142e57218a0
Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
182 |
71
a03d7a94b997
Add support for a few ANM instructions
Thibaut Girka <thib@sitedethib.com>
parents:
69
diff
changeset
|
183 @instruction(12) |
429
40d5f3083ebc
Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
376
diff
changeset
|
184 @instruction(15, 7) |
71
a03d7a94b997
Add support for a few ANM instructions
Thibaut Girka <thib@sitedethib.com>
parents:
69
diff
changeset
|
185 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
|
186 self._sprite.fade(duration, new_alpha) |
71
a03d7a94b997
Add support for a few ANM instructions
Thibaut Girka <thib@sitedethib.com>
parents:
69
diff
changeset
|
187 |
72
6a08f44fa01b
Handle a few more ANM instructions. pytouhou.game.background needs some serious refactoring.
Thibaut Girka <thib@sitedethib.com>
parents:
71
diff
changeset
|
188 |
6a08f44fa01b
Handle a few more ANM instructions. pytouhou.game.background needs some serious refactoring.
Thibaut Girka <thib@sitedethib.com>
parents:
71
diff
changeset
|
189 @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
|
190 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
|
191 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
|
192 |
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 @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
|
195 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
|
196 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
|
197 |
6a08f44fa01b
Handle a few more ANM instructions. pytouhou.game.background needs some serious refactoring.
Thibaut Girka <thib@sitedethib.com>
parents:
71
diff
changeset
|
198 |
71
a03d7a94b997
Add support for a few ANM instructions
Thibaut Girka <thib@sitedethib.com>
parents:
69
diff
changeset
|
199 @instruction(15) |
429
40d5f3083ebc
Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
376
diff
changeset
|
200 @instruction(2, 7) |
71
a03d7a94b997
Add support for a few ANM instructions
Thibaut Girka <thib@sitedethib.com>
parents:
69
diff
changeset
|
201 def keep_still(self): |
304
f3099ebf4f61
Update attribute names to reflect the actual interface.
Thibaut Girka <thib@sitedethib.com>
parents:
294
diff
changeset
|
202 self.running = False |
71
a03d7a94b997
Add support for a few ANM instructions
Thibaut Girka <thib@sitedethib.com>
parents:
69
diff
changeset
|
203 |
69
a142e57218a0
Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
204 @instruction(16) |
a142e57218a0
Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
205 def load_random_sprite(self, min_idx, amp): |
a142e57218a0
Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
206 #TODO: use the game's PRNG? |
a142e57218a0
Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
207 self.load_sprite(min_idx + randrange(amp)) |
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 |
170
e7902309305c
Implement move anm instructions.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
129
diff
changeset
|
210 @instruction(17) |
429
40d5f3083ebc
Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
376
diff
changeset
|
211 @instruction(6, 7) |
170
e7902309305c
Implement move anm instructions.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
129
diff
changeset
|
212 def move(self, x, y, z): |
e7902309305c
Implement move anm instructions.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
129
diff
changeset
|
213 self._sprite.dest_offset = (x, y, z) |
e7902309305c
Implement move anm instructions.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
129
diff
changeset
|
214 |
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 @instruction(18) |
429
40d5f3083ebc
Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
376
diff
changeset
|
217 @instruction(17, 7) |
170
e7902309305c
Implement move anm instructions.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
129
diff
changeset
|
218 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
|
219 self._sprite.move_in(duration, x, y, z) |
170
e7902309305c
Implement move anm instructions.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
129
diff
changeset
|
220 |
e7902309305c
Implement move anm instructions.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
129
diff
changeset
|
221 |
71
a03d7a94b997
Add support for a few ANM instructions
Thibaut Girka <thib@sitedethib.com>
parents:
69
diff
changeset
|
222 @instruction(19) |
429
40d5f3083ebc
Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
376
diff
changeset
|
223 @instruction(18, 7) |
170
e7902309305c
Implement move anm instructions.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
129
diff
changeset
|
224 def move_in_decel(self, x, y, z, duration): |
e7902309305c
Implement move anm instructions.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
129
diff
changeset
|
225 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
|
226 |
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 @instruction(20) |
429
40d5f3083ebc
Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
376
diff
changeset
|
229 @instruction(19, 7) |
170
e7902309305c
Implement move anm instructions.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
129
diff
changeset
|
230 def move_in_accel(self, x, y, z, duration): |
e7902309305c
Implement move anm instructions.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
129
diff
changeset
|
231 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
|
232 |
a03d7a94b997
Add support for a few ANM instructions
Thibaut Girka <thib@sitedethib.com>
parents:
69
diff
changeset
|
233 |
236
741860192b56
Implement ANM0 interrupts
Thibaut Girka <thib@sitedethib.com>
parents:
170
diff
changeset
|
234 @instruction(21) |
429
40d5f3083ebc
Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
376
diff
changeset
|
235 @instruction(20, 7) |
236
741860192b56
Implement ANM0 interrupts
Thibaut Girka <thib@sitedethib.com>
parents:
170
diff
changeset
|
236 def wait(self): |
741860192b56
Implement ANM0 interrupts
Thibaut Girka <thib@sitedethib.com>
parents:
170
diff
changeset
|
237 """Wait for an interrupt. |
741860192b56
Implement ANM0 interrupts
Thibaut Girka <thib@sitedethib.com>
parents:
170
diff
changeset
|
238 """ |
741860192b56
Implement ANM0 interrupts
Thibaut Girka <thib@sitedethib.com>
parents:
170
diff
changeset
|
239 self.waiting = True |
741860192b56
Implement ANM0 interrupts
Thibaut Girka <thib@sitedethib.com>
parents:
170
diff
changeset
|
240 |
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 @instruction(22) |
429
40d5f3083ebc
Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
376
diff
changeset
|
243 @instruction(21, 7) |
236
741860192b56
Implement ANM0 interrupts
Thibaut Girka <thib@sitedethib.com>
parents:
170
diff
changeset
|
244 def interrupt_label(self, interrupt): |
741860192b56
Implement ANM0 interrupts
Thibaut Girka <thib@sitedethib.com>
parents:
170
diff
changeset
|
245 """Noop""" |
741860192b56
Implement ANM0 interrupts
Thibaut Girka <thib@sitedethib.com>
parents:
170
diff
changeset
|
246 pass |
741860192b56
Implement ANM0 interrupts
Thibaut Girka <thib@sitedethib.com>
parents:
170
diff
changeset
|
247 |
741860192b56
Implement ANM0 interrupts
Thibaut Girka <thib@sitedethib.com>
parents:
170
diff
changeset
|
248 |
69
a142e57218a0
Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
249 @instruction(23) |
429
40d5f3083ebc
Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
376
diff
changeset
|
250 @instruction(22, 7) |
69
a142e57218a0
Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
251 def set_corner_relative_placement(self): |
a142e57218a0
Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
252 self._sprite.corner_relative_placement = True #TODO |
a142e57218a0
Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
253 |
a142e57218a0
Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
254 |
240
02de1563fa18
Fix ANM wait, translation/rotation order, and partially implement ANM0 instruction 24
Thibaut Girka <thib@sitedethib.com>
parents:
239
diff
changeset
|
255 @instruction(24) |
429
40d5f3083ebc
Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
376
diff
changeset
|
256 @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
|
257 def wait_ex(self): |
245
d3ba32a9096e
Implement ANM0 instruction 29 and fix 24
Thibaut Girka <thib@sitedethib.com>
parents:
243
diff
changeset
|
258 """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
|
259 """ |
245
d3ba32a9096e
Implement ANM0 instruction 29 and fix 24
Thibaut Girka <thib@sitedethib.com>
parents:
243
diff
changeset
|
260 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
|
261 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
|
262 |
02de1563fa18
Fix ANM wait, translation/rotation order, and partially implement ANM0 instruction 24
Thibaut Girka <thib@sitedethib.com>
parents:
239
diff
changeset
|
263 |
71
a03d7a94b997
Add support for a few ANM instructions
Thibaut Girka <thib@sitedethib.com>
parents:
69
diff
changeset
|
264 @instruction(25) |
429
40d5f3083ebc
Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
376
diff
changeset
|
265 @instruction(24, 7) |
71
a03d7a94b997
Add support for a few ANM instructions
Thibaut Girka <thib@sitedethib.com>
parents:
69
diff
changeset
|
266 def set_allow_dest_offset(self, value): |
a03d7a94b997
Add support for a few ANM instructions
Thibaut Girka <thib@sitedethib.com>
parents:
69
diff
changeset
|
267 self._sprite.allow_dest_offset = bool(value) |
a03d7a94b997
Add support for a few ANM instructions
Thibaut Girka <thib@sitedethib.com>
parents:
69
diff
changeset
|
268 |
a03d7a94b997
Add support for a few ANM instructions
Thibaut Girka <thib@sitedethib.com>
parents:
69
diff
changeset
|
269 |
81
f5f9b5eb69a3
Handle one more ANM instruction, and handle sprite indexes offsets
Thibaut Girka <thib@sitedethib.com>
parents:
72
diff
changeset
|
270 @instruction(26) |
429
40d5f3083ebc
Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
376
diff
changeset
|
271 @instruction(25, 7) |
81
f5f9b5eb69a3
Handle one more ANM instruction, and handle sprite indexes offsets
Thibaut Girka <thib@sitedethib.com>
parents:
72
diff
changeset
|
272 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
|
273 """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
|
274 """ |
f5f9b5eb69a3
Handle one more ANM instruction, and handle sprite indexes offsets
Thibaut Girka <thib@sitedethib.com>
parents:
72
diff
changeset
|
275 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
|
276 |
f5f9b5eb69a3
Handle one more ANM instruction, and handle sprite indexes offsets
Thibaut Girka <thib@sitedethib.com>
parents:
72
diff
changeset
|
277 |
69
a142e57218a0
Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
278 @instruction(27) |
429
40d5f3083ebc
Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
376
diff
changeset
|
279 @instruction(26, 7) |
69
a142e57218a0
Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
280 def shift_texture_x(self, dx): |
a142e57218a0
Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
281 tox, toy = self._sprite.texoffsets |
a142e57218a0
Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
282 self._sprite.texoffsets = tox + dx, toy |
a142e57218a0
Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
283 |
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 @instruction(28) |
429
40d5f3083ebc
Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
376
diff
changeset
|
286 @instruction(27, 7) |
69
a142e57218a0
Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
287 def shift_texture_y(self, dy): |
a142e57218a0
Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
288 tox, toy = self._sprite.texoffsets |
a142e57218a0
Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
289 self._sprite.texoffsets = tox, toy + dy |
a142e57218a0
Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
290 |
a142e57218a0
Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
291 |
245
d3ba32a9096e
Implement ANM0 instruction 29 and fix 24
Thibaut Girka <thib@sitedethib.com>
parents:
243
diff
changeset
|
292 @instruction(29) |
429
40d5f3083ebc
Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
376
diff
changeset
|
293 @instruction(28, 7) |
245
d3ba32a9096e
Implement ANM0 instruction 29 and fix 24
Thibaut Girka <thib@sitedethib.com>
parents:
243
diff
changeset
|
294 def set_visible(self, visible): |
d3ba32a9096e
Implement ANM0 instruction 29 and fix 24
Thibaut Girka <thib@sitedethib.com>
parents:
243
diff
changeset
|
295 self._sprite.visible = bool(visible & 1) |
d3ba32a9096e
Implement ANM0 instruction 29 and fix 24
Thibaut Girka <thib@sitedethib.com>
parents:
243
diff
changeset
|
296 |
d3ba32a9096e
Implement ANM0 instruction 29 and fix 24
Thibaut Girka <thib@sitedethib.com>
parents:
243
diff
changeset
|
297 |
71
a03d7a94b997
Add support for a few ANM instructions
Thibaut Girka <thib@sitedethib.com>
parents:
69
diff
changeset
|
298 @instruction(30) |
429
40d5f3083ebc
Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
376
diff
changeset
|
299 @instruction(29, 7) |
71
a03d7a94b997
Add support for a few ANM instructions
Thibaut Girka <thib@sitedethib.com>
parents:
69
diff
changeset
|
300 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
|
301 self._sprite.scale_in(duration, sx, sy) |
69
a142e57218a0
Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
302 |
429
40d5f3083ebc
Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
376
diff
changeset
|
303 |
40d5f3083ebc
Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
376
diff
changeset
|
304 # 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
|
305 |
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 @instruction(0, 7) |
40d5f3083ebc
Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
376
diff
changeset
|
308 def noop(self): |
40d5f3083ebc
Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
376
diff
changeset
|
309 pass |
40d5f3083ebc
Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
376
diff
changeset
|
310 |
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 @instruction(4, 7) |
40d5f3083ebc
Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
376
diff
changeset
|
313 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
|
314 self.instruction_pointer = instruction_pointer |
40d5f3083ebc
Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
376
diff
changeset
|
315 self.frame = frame |
40d5f3083ebc
Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
376
diff
changeset
|
316 |
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 @instruction(5, 7) |
40d5f3083ebc
Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
376
diff
changeset
|
319 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
|
320 """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
|
321 relative offset in the same subroutine. |
40d5f3083ebc
Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
376
diff
changeset
|
322 """ |
40d5f3083ebc
Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
376
diff
changeset
|
323 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
|
324 if counter_value > 0: |
40d5f3083ebc
Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
376
diff
changeset
|
325 self._setval(variable_id, counter_value) |
40d5f3083ebc
Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
376
diff
changeset
|
326 self.instruction_pointer = instruction_pointer |
40d5f3083ebc
Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
376
diff
changeset
|
327 self.frame = frame |
40d5f3083ebc
Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
376
diff
changeset
|
328 |
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 @instruction(16, 7) |
40d5f3083ebc
Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
376
diff
changeset
|
331 def set_blendfunc(self, value): |
40d5f3083ebc
Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
376
diff
changeset
|
332 self._sprite.blendfunc = bool(value & 1) |
40d5f3083ebc
Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
376
diff
changeset
|
333 |
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 @instruction(32, 7) |
40d5f3083ebc
Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
376
diff
changeset
|
336 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
|
337 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
|
338 |
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 @instruction(33, 7) |
40d5f3083ebc
Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
376
diff
changeset
|
341 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
|
342 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
|
343 |
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 @instruction(34, 7) |
40d5f3083ebc
Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
376
diff
changeset
|
346 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
|
347 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
|
348 |
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 @instruction(35, 7) |
40d5f3083ebc
Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
376
diff
changeset
|
351 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
|
352 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
|
353 |
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 @instruction(36, 7) |
40d5f3083ebc
Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
376
diff
changeset
|
356 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
|
357 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
|
358 |
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 @instruction(37, 7) |
40d5f3083ebc
Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
376
diff
changeset
|
361 @instruction(38, 7) |
40d5f3083ebc
Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
376
diff
changeset
|
362 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
|
363 self._setval(variable_id, value) |
40d5f3083ebc
Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
376
diff
changeset
|
364 |
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 @instruction(42, 7) |
40d5f3083ebc
Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
376
diff
changeset
|
367 def decrement(self, variable_id, value): |
40d5f3083ebc
Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
376
diff
changeset
|
368 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
|
369 |
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 @instruction(50, 7) |
40d5f3083ebc
Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
376
diff
changeset
|
372 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
|
373 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
|
374 |
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 @instruction(52, 7) |
40d5f3083ebc
Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
376
diff
changeset
|
377 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
|
378 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
|
379 |
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 @instruction(55, 7) |
40d5f3083ebc
Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
376
diff
changeset
|
382 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
|
383 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
|
384 |
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 @instruction(59, 7) |
40d5f3083ebc
Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
376
diff
changeset
|
387 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
|
388 #TODO: use the game's PRNG? |
40d5f3083ebc
Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
376
diff
changeset
|
389 self._setval(variable_id, randrange(amp)) |
40d5f3083ebc
Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
376
diff
changeset
|
390 |
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 @instruction(60, 7) |
40d5f3083ebc
Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
376
diff
changeset
|
393 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
|
394 #TODO: use the game's PRNG? |
40d5f3083ebc
Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
376
diff
changeset
|
395 self._setval(variable_id, amp * random()) |
40d5f3083ebc
Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
376
diff
changeset
|
396 |
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 @instruction(69, 7) |
40d5f3083ebc
Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
376
diff
changeset
|
399 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
|
400 if self._getval(variable_id) != value: |
40d5f3083ebc
Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
376
diff
changeset
|
401 self.instruction_pointer = instruction_pointer |
40d5f3083ebc
Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
376
diff
changeset
|
402 self.frame = frame |
40d5f3083ebc
Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
376
diff
changeset
|
403 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
|
404 |
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 @instruction(79, 7) |
40d5f3083ebc
Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
376
diff
changeset
|
407 def wait_duration(self, duration): |
40d5f3083ebc
Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
376
diff
changeset
|
408 self.timeout = self._sprite.frame + duration |
40d5f3083ebc
Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
376
diff
changeset
|
409 self.waiting = True |