comparison pytouhou/game/sprite.pyx @ 532:dacdcca59b66

Don’t put back the rendering data into a tuple, use a specialised struct inside Sprite to pass it to the renderer.
author Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
date Thu, 19 Dec 2013 21:55:26 +0100
parents 0b2a92a25245
children e15672733c93
comparison
equal deleted inserted replaced
531:a7dc55ad9380 532:dacdcca59b66
10 ## but WITHOUT ANY WARRANTY; without even the implied warranty of 10 ## but WITHOUT ANY WARRANTY; without even the implied warranty of
11 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 ## GNU General Public License for more details. 12 ## GNU General Public License for more details.
13 ## 13 ##
14 14
15 from libc.stdlib cimport free
16 from libc.string cimport memcpy
17
18
15 cdef class Sprite: 19 cdef class Sprite:
20 def __dealloc__(self):
21 if self._rendering_data != NULL:
22 free(self._rendering_data)
23
24
16 def __init__(self, width_override=0, height_override=0): 25 def __init__(self, width_override=0, height_override=0):
17 self.anm = None 26 self.anm = None
18 self.removed = False 27 self.removed = False
19 self.changed = True 28 self.changed = True
20 self.visible = True 29 self.visible = True
49 # Cython treats unsigned char* variables as bytes, so we can’t use 58 # Cython treats unsigned char* variables as bytes, so we can’t use
50 # slicing here. 59 # slicing here.
51 for i in xrange(4): 60 for i in xrange(4):
52 self._color[i] = 255 61 self._color[i] = 255
53 62
54 self._rendering_data = None
55
56 63
57 property scale_speed: 64 property scale_speed:
58 def __get__(self): 65 def __get__(self):
59 return (self._scale_speed[0], self._scale_speed[1]) 66 return (self._scale_speed[0], self._scale_speed[1])
60 def __set__(self, value): 67 def __set__(self, value):
179 sprite.rotations_speed_3d = self.rotations_speed_3d 186 sprite.rotations_speed_3d = self.rotations_speed_3d
180 sprite.color = self.color 187 sprite.color = self.color
181 188
182 sprite.alpha = self.alpha 189 sprite.alpha = self.alpha
183 sprite.anm = self.anm 190 sprite.anm = self.anm
184 sprite._rendering_data = self._rendering_data
185 191
186 return sprite 192 return sprite
187 193
188 194
189 cpdef update(self): 195 cpdef update(self):