comparison pytouhou/ui/sdl/sprite.pyx @ 527:db28538cd399

Use Sprite C arrays instead of their tuple representation where it makes sense.
author Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
date Wed, 18 Dec 2013 18:19:08 +0100
parents 43ecf0f98f4d
children dacdcca59b66
comparison
equal deleted inserted replaced
526:0b2a92a25245 527:db28538cd399
15 15
16 from libc.math cimport M_PI as pi 16 from libc.math cimport M_PI as pi
17 17
18 18
19 cpdef tuple get_sprite_rendering_data(Sprite sprite): 19 cpdef tuple get_sprite_rendering_data(Sprite sprite):
20 cdef double x, y, tx, ty, tw, th, sx, sy, rz, tox, toy
21
22 if not sprite.changed: 20 if not sprite.changed:
23 return sprite._rendering_data 21 return sprite._rendering_data
24 22
25 x = 0 23 x = 0
26 y = 0 24 y = 0
27 25
28 tx, ty, tw, th = sprite.texcoords 26 tx, ty, tw, th = sprite._texcoords[0], sprite._texcoords[1], sprite._texcoords[2], sprite._texcoords[3]
29 sx, sy = sprite.rescale 27 sx, sy = sprite._rescale[0], sprite._rescale[1]
30 width = sprite.width_override or (tw * sx) 28 width = sprite.width_override or (tw * sx)
31 height = sprite.height_override or (th * sy) 29 height = sprite.height_override or (th * sy)
32 30
33 rz = sprite.rotations_3d[2] 31 rz = sprite._rotations_3d[2]
34 if sprite.automatic_orientation: 32 if sprite.automatic_orientation:
35 rz += pi/2. - sprite.angle 33 rz += pi/2. - sprite.angle
36 elif sprite.force_rotation: 34 elif sprite.force_rotation:
37 rz += sprite.angle 35 rz += sprite.angle
38 36
39 if sprite.allow_dest_offset: 37 if sprite.allow_dest_offset:
40 x += sprite.dest_offset[0] 38 x += sprite._dest_offset[0]
41 y += sprite.dest_offset[1] 39 y += sprite._dest_offset[1]
42 if not sprite.corner_relative_placement: # Reposition 40 if not sprite.corner_relative_placement: # Reposition
43 x -= width / 2 41 x -= width / 2
44 y -= height / 2 42 y -= height / 2
45 43
46 x_1 = sprite.anm.size_inv[0] 44 x_1 = sprite.anm.size_inv[0]
47 y_1 = sprite.anm.size_inv[1] 45 y_1 = sprite.anm.size_inv[1]
48 tox, toy = sprite.texoffsets 46 tox, toy = sprite._texoffsets[0], sprite._texoffsets[1]
49 uvs = (tx * x_1 + tox, 47 uvs = (tx * x_1 + tox,
50 (tx + tw) * x_1 + tox, 48 (tx + tw) * x_1 + tox,
51 ty * y_1 + toy, 49 ty * y_1 + toy,
52 (ty + th) * y_1 + toy) 50 (ty + th) * y_1 + toy)
53 51
52 r, g, b, a = sprite._color[0], sprite._color[1], sprite._color[2], sprite._color[3]
53
54 key = sprite.blendfunc 54 key = sprite.blendfunc
55 r, g, b = sprite.color 55 values = (x, y, width, height), uvs, (r, g, b, a), -rz * 180 / pi, sprite.mirrored
56 values = (x, y, width, height), uvs, (r, g, b, sprite.alpha), -rz * 180 / pi, sprite.mirrored
57 sprite._rendering_data = key, values 56 sprite._rendering_data = key, values
58 sprite.changed = False 57 sprite.changed = False
59 58
60 return sprite._rendering_data 59 return sprite._rendering_data