comparison pytouhou/vm/anmrunner.py @ 432:d4874ebaa06e

Split ANMRunner.run_frame into Sprite.update.
author Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
date Sat, 10 Aug 2013 15:18:44 +0200
parents c9433188ffdb
children 1222341ea22c
comparison
equal deleted inserted replaced
431:77c0e9a53795 432:d4874ebaa06e
72 72
73 def run_frame(self): 73 def run_frame(self):
74 if not self.running: 74 if not self.running:
75 return False 75 return False
76 76
77 sprite = self._sprite
78
79 while self.running and not self.waiting: 77 while self.running and not self.waiting:
80 frame, opcode, args = self.script[self.instruction_pointer] 78 frame, opcode, args = self.script[self.instruction_pointer]
81 79
82 if frame > self.frame: 80 if frame > self.frame:
83 break 81 break
91 logger.warn('unhandled opcode %d (args: %r)', opcode, args) 89 logger.warn('unhandled opcode %d (args: %r)', opcode, args)
92 else: 90 else:
93 logger.debug('[%d - %04d] anm_%d%r', id(self), 91 logger.debug('[%d - %04d] anm_%d%r', id(self),
94 self.frame, opcode, args) 92 self.frame, opcode, args)
95 callback(self, *args) 93 callback(self, *args)
96 sprite.changed = True 94 self._sprite.changed = True
97 95
98 if not self.waiting: 96 if not self.waiting:
99 self.frame += 1 97 self.frame += 1
100 elif self.timeout == sprite.frame: #TODO: check if it’s happening at the correct frame. 98 elif self.timeout == self._sprite.frame: #TODO: check if it’s happening at the correct frame.
101 self.waiting = False 99 self.waiting = False
102 100
103 # Update sprite 101 self._sprite.update()
104 sprite.frame += 1
105
106 if sprite.rotations_speed_3d != (0., 0., 0.):
107 ax, ay, az = sprite.rotations_3d
108 sax, say, saz = sprite.rotations_speed_3d
109 sprite.rotations_3d = ax + sax, ay + say, az + saz
110 sprite.changed = True
111 elif sprite.rotation_interpolator:
112 sprite.rotation_interpolator.update(sprite.frame)
113 sprite.rotations_3d = sprite.rotation_interpolator.values
114 sprite.changed = True
115
116 if sprite.scale_speed != (0., 0.):
117 rx, ry = sprite.rescale
118 rsx, rsy = sprite.scale_speed
119 sprite.rescale = rx + rsx, ry + rsy
120 sprite.changed = True
121
122 if sprite.fade_interpolator:
123 sprite.fade_interpolator.update(sprite.frame)
124 sprite.alpha = int(sprite.fade_interpolator.values[0])
125 sprite.changed = True
126
127 if sprite.scale_interpolator:
128 sprite.scale_interpolator.update(sprite.frame)
129 sprite.rescale = sprite.scale_interpolator.values
130 sprite.changed = True
131
132 if sprite.offset_interpolator:
133 sprite.offset_interpolator.update(sprite.frame)
134 sprite.dest_offset = sprite.offset_interpolator.values
135 sprite.changed = True
136
137 if sprite.color_interpolator:
138 sprite.color_interpolator.update(sprite.frame)
139 sprite.color = sprite.color_interpolator.values
140 sprite.changed = True
141 102
142 return self.running 103 return self.running
143 104
144 105
145 def _setval(self, variable_id, value): 106 def _setval(self, variable_id, value):