Mercurial > touhou
comparison pytouhou/vm/anmrunner.py @ 304:f3099ebf4f61
Update attribute names to reflect the actual interface.
author | Thibaut Girka <thib@sitedethib.com> |
---|---|
date | Tue, 13 Mar 2012 18:38:14 +0100 |
parents | 94c636f8f863 |
children | 69ec72b990a4 |
comparison
equal
deleted
inserted
replaced
303:647bde10353d | 304:f3099ebf4f61 |
---|---|
21 logger = get_logger(__name__) | 21 logger = get_logger(__name__) |
22 | 22 |
23 | 23 |
24 class ANMRunner(object): | 24 class ANMRunner(object): |
25 __metaclass__ = MetaRegistry | 25 __metaclass__ = MetaRegistry |
26 __slots__ = ('_anm_wrapper', '_sprite', '_running', | 26 __slots__ = ('_anm_wrapper', '_sprite', 'running', |
27 'sprite_index_offset', | 27 'sprite_index_offset', |
28 'script', 'instruction_pointer', 'frame', | 28 'script', 'instruction_pointer', 'frame', |
29 'waiting') | 29 'waiting') |
30 | 30 |
31 | 31 |
32 def __init__(self, anm_wrapper, script_id, sprite, sprite_index_offset=0): | 32 def __init__(self, anm_wrapper, script_id, sprite, sprite_index_offset=0): |
33 self._anm_wrapper = anm_wrapper | 33 self._anm_wrapper = anm_wrapper |
34 self._sprite = sprite | 34 self._sprite = sprite |
35 self._running = True | 35 self.running = True |
36 self.waiting = False | 36 self.waiting = False |
37 | 37 |
38 anm, self.script = anm_wrapper.get_script(script_id) | 38 anm, self.script = anm_wrapper.get_script(script_id) |
39 self.frame = 0 | 39 self.frame = 0 |
40 self.instruction_pointer = 0 | 40 self.instruction_pointer = 0 |
54 self._sprite.visible = True | 54 self._sprite.visible = True |
55 return True | 55 return True |
56 | 56 |
57 | 57 |
58 def run_frame(self): | 58 def run_frame(self): |
59 if not self._running: | 59 if not self.running: |
60 return False | 60 return False |
61 | 61 |
62 sprite = self._sprite | 62 sprite = self._sprite |
63 | 63 |
64 while self._running and not self.waiting: | 64 while self.running and not self.waiting: |
65 frame, opcode, args = self.script[self.instruction_pointer] | 65 frame, opcode, args = self.script[self.instruction_pointer] |
66 | 66 |
67 if frame > self.frame: | 67 if frame > self.frame: |
68 break | 68 break |
69 else: | 69 else: |
74 callback = self._handlers[opcode] | 74 callback = self._handlers[opcode] |
75 except KeyError: | 75 except KeyError: |
76 logger.warn('unhandled opcode %d (args: %r)', opcode, args) | 76 logger.warn('unhandled opcode %d (args: %r)', opcode, args) |
77 else: | 77 else: |
78 callback(self, *args) | 78 callback(self, *args) |
79 sprite._changed = True | 79 sprite.changed = True |
80 | 80 |
81 if not self.waiting: | 81 if not self.waiting: |
82 self.frame += 1 | 82 self.frame += 1 |
83 | 83 |
84 # Update sprite | 84 # Update sprite |
86 | 86 |
87 if sprite.rotations_speed_3d != (0., 0., 0.): | 87 if sprite.rotations_speed_3d != (0., 0., 0.): |
88 ax, ay, az = sprite.rotations_3d | 88 ax, ay, az = sprite.rotations_3d |
89 sax, say, saz = sprite.rotations_speed_3d | 89 sax, say, saz = sprite.rotations_speed_3d |
90 sprite.rotations_3d = ax + sax, ay + say, az + saz | 90 sprite.rotations_3d = ax + sax, ay + say, az + saz |
91 sprite._changed = True | 91 sprite.changed = True |
92 | 92 |
93 if sprite.scale_speed != (0., 0.): | 93 if sprite.scale_speed != (0., 0.): |
94 rx, ry = sprite.rescale | 94 rx, ry = sprite.rescale |
95 rsx, rsy = sprite.scale_speed | 95 rsx, rsy = sprite.scale_speed |
96 sprite.rescale = rx + rsx, ry + rsy | 96 sprite.rescale = rx + rsx, ry + rsy |
97 sprite._changed = True | 97 sprite.changed = True |
98 | 98 |
99 if sprite.fade_interpolator: | 99 if sprite.fade_interpolator: |
100 sprite.fade_interpolator.update(sprite.frame) | 100 sprite.fade_interpolator.update(sprite.frame) |
101 sprite.alpha = int(sprite.fade_interpolator.values[0]) | 101 sprite.alpha = int(sprite.fade_interpolator.values[0]) |
102 sprite._changed = True | 102 sprite.changed = True |
103 | 103 |
104 if sprite.scale_interpolator: | 104 if sprite.scale_interpolator: |
105 sprite.scale_interpolator.update(sprite.frame) | 105 sprite.scale_interpolator.update(sprite.frame) |
106 sprite.rescale = sprite.scale_interpolator.values | 106 sprite.rescale = sprite.scale_interpolator.values |
107 sprite._changed = True | 107 sprite.changed = True |
108 | 108 |
109 if sprite.offset_interpolator: | 109 if sprite.offset_interpolator: |
110 sprite.offset_interpolator.update(sprite.frame) | 110 sprite.offset_interpolator.update(sprite.frame) |
111 sprite.dest_offset = sprite.offset_interpolator.values | 111 sprite.dest_offset = sprite.offset_interpolator.values |
112 sprite._changed = True | 112 sprite.changed = True |
113 | 113 |
114 return self._running | 114 return self.running |
115 | 115 |
116 | 116 |
117 @instruction(0) | 117 @instruction(0) |
118 def remove(self): | 118 def remove(self): |
119 self._sprite._removed = True | 119 self._sprite.removed = True |
120 self._running = False | 120 self.running = False |
121 | 121 |
122 | 122 |
123 @instruction(1) | 123 @instruction(1) |
124 def load_sprite(self, sprite_index): | 124 def load_sprite(self, sprite_index): |
125 self._sprite.anm, self._sprite.texcoords = self._anm_wrapper.get_sprite(sprite_index + self.sprite_index_offset) | 125 self._sprite.anm, self._sprite.texcoords = self._anm_wrapper.get_sprite(sprite_index + self.sprite_index_offset) |
183 self._sprite.blendfunc = 0 #TODO | 183 self._sprite.blendfunc = 0 #TODO |
184 | 184 |
185 | 185 |
186 @instruction(15) | 186 @instruction(15) |
187 def keep_still(self): | 187 def keep_still(self): |
188 self._running = False | 188 self.running = False |
189 | 189 |
190 @instruction(16) | 190 @instruction(16) |
191 def load_random_sprite(self, min_idx, amp): | 191 def load_random_sprite(self, min_idx, amp): |
192 #TODO: use the game's PRNG? | 192 #TODO: use the game's PRNG? |
193 self.load_sprite(min_idx + randrange(amp)) | 193 self.load_sprite(min_idx + randrange(amp)) |