Mercurial > touhou
comparison pytouhou/game/sprite.py @ 120:4300a832f033
Small refactoring and massive performance improvement
author | Thibaut Girka <thib@sitedethib.com> |
---|---|
date | Thu, 08 Sep 2011 12:46:05 +0200 |
parents | 2a03940deea3 |
children | 174324a4da51 |
comparison
equal
deleted
inserted
replaced
119:fad7b44cebf2 | 120:4300a832f033 |
---|---|
15 | 15 |
16 from pytouhou.utils.interpolator import Interpolator | 16 from pytouhou.utils.interpolator import Interpolator |
17 | 17 |
18 | 18 |
19 class Sprite(object): | 19 class Sprite(object): |
20 def __init__(self): | 20 __slots__ = ('anm', '_removed', '_changed', 'width_override', 'height_override', |
21 'angle', 'force_rotation', 'scale_interpolator', 'fade_interpolator', | |
22 'offset_interpolator', 'automatic_orientation', 'blendfunc', | |
23 'texcoords', 'dest_offset', 'allow_dest_offset', 'texoffsets', | |
24 'mirrored', 'rescale', 'scale_speed', 'rotations_3d', | |
25 'rotations_speed_3d', 'corner_relative_placement', 'frame', | |
26 'color', 'alpha', '_rendering_data') | |
27 def __init__(self, width_override=0, height_override=0): | |
21 self.anm = None | 28 self.anm = None |
22 self._removed = False | 29 self._removed = False |
23 self._changed = False | 30 self._changed = False |
24 | 31 |
25 self.width_override = 0 | 32 self.width_override = width_override |
26 self.height_override = 0 | 33 self.height_override = height_override |
27 self.angle = 0 | 34 self.angle = 0 |
28 self.force_rotation = False | 35 self.force_rotation = False |
29 | 36 |
30 self.scale_interpolator = None | 37 self.scale_interpolator = None |
31 self.fade_interpolator = None | 38 self.fade_interpolator = None |
71 self.offset_interpolator = Interpolator(self.dest_offset, formula) | 78 self.offset_interpolator = Interpolator(self.dest_offset, formula) |
72 self.offset_interpolator.set_interpolation_start(self.frame, self.dest_offset) | 79 self.offset_interpolator.set_interpolation_start(self.frame, self.dest_offset) |
73 self.offset_interpolator.set_interpolation_end(self.frame + duration - 1, (x, y, z)) | 80 self.offset_interpolator.set_interpolation_end(self.frame + duration - 1, (x, y, z)) |
74 | 81 |
75 | 82 |
76 def update(self, override_width=0, override_height=0, angle_base=0., force_rotation=False): | 83 def update_orientation(self, angle_base=0., force_rotation=False): |
77 if (override_width != self.width_override | 84 if (self.angle != angle_base or self.force_rotation != force_rotation): |
78 or override_height != self.height_override | |
79 or self.angle != angle_base | |
80 or self.force_rotation != force_rotation | |
81 or self.scale_interpolator | |
82 or self.fade_interpolator | |
83 or self.offset_interpolator): | |
84 | |
85 self._changed = True | |
86 self.width_override = override_width | |
87 self.height_override = override_height | |
88 self.angle = angle_base | 85 self.angle = angle_base |
89 self.force_rotation = force_rotation | 86 self.force_rotation = force_rotation |
90 | |
91 if self.rotations_speed_3d != (0., 0., 0.): | |
92 ax, ay, az = self.rotations_3d | |
93 sax, say, saz = self.rotations_speed_3d | |
94 self.rotations_3d = ax + sax, ay + say, az + saz | |
95 self._changed = True | 87 self._changed = True |
96 | 88 |
97 if self.scale_speed != (0., 0.): | |
98 rx, ry = self.rescale | |
99 rsx, rsy = self.scale_speed | |
100 self.rescale = rx + rsx, ry + rsy | |
101 self._changed = True | |
102 | |
103 self.frame += 1 | |
104 |