annotate pytouhou/game/sprite.pyx @ 526:0b2a92a25245

Store data in C arrays in Sprite, and add an interface to access them as tuples.
author Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
date Wed, 18 Dec 2013 18:15:45 +0100
parents pytouhou/game/sprite.py@723a3e67a223
children dacdcca59b66
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
52
ab826bc29aa2 Add some documentation, GPLv3 headers, README and COPYING file.
Thibaut Girka <thib@sitedethib.com>
parents: 41
diff changeset
1 # -*- encoding: utf-8 -*-
ab826bc29aa2 Add some documentation, GPLv3 headers, README and COPYING file.
Thibaut Girka <thib@sitedethib.com>
parents: 41
diff changeset
2 ##
ab826bc29aa2 Add some documentation, GPLv3 headers, README and COPYING file.
Thibaut Girka <thib@sitedethib.com>
parents: 41
diff changeset
3 ## Copyright (C) 2011 Thibaut Girka <thib@sitedethib.com>
ab826bc29aa2 Add some documentation, GPLv3 headers, README and COPYING file.
Thibaut Girka <thib@sitedethib.com>
parents: 41
diff changeset
4 ##
ab826bc29aa2 Add some documentation, GPLv3 headers, README and COPYING file.
Thibaut Girka <thib@sitedethib.com>
parents: 41
diff changeset
5 ## This program is free software; you can redistribute it and/or modify
ab826bc29aa2 Add some documentation, GPLv3 headers, README and COPYING file.
Thibaut Girka <thib@sitedethib.com>
parents: 41
diff changeset
6 ## it under the terms of the GNU General Public License as published
ab826bc29aa2 Add some documentation, GPLv3 headers, README and COPYING file.
Thibaut Girka <thib@sitedethib.com>
parents: 41
diff changeset
7 ## by the Free Software Foundation; version 3 only.
ab826bc29aa2 Add some documentation, GPLv3 headers, README and COPYING file.
Thibaut Girka <thib@sitedethib.com>
parents: 41
diff changeset
8 ##
ab826bc29aa2 Add some documentation, GPLv3 headers, README and COPYING file.
Thibaut Girka <thib@sitedethib.com>
parents: 41
diff changeset
9 ## This program is distributed in the hope that it will be useful,
ab826bc29aa2 Add some documentation, GPLv3 headers, README and COPYING file.
Thibaut Girka <thib@sitedethib.com>
parents: 41
diff changeset
10 ## but WITHOUT ANY WARRANTY; without even the implied warranty of
ab826bc29aa2 Add some documentation, GPLv3 headers, README and COPYING file.
Thibaut Girka <thib@sitedethib.com>
parents: 41
diff changeset
11 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
ab826bc29aa2 Add some documentation, GPLv3 headers, README and COPYING file.
Thibaut Girka <thib@sitedethib.com>
parents: 41
diff changeset
12 ## GNU General Public License for more details.
ab826bc29aa2 Add some documentation, GPLv3 headers, README and COPYING file.
Thibaut Girka <thib@sitedethib.com>
parents: 41
diff changeset
13 ##
ab826bc29aa2 Add some documentation, GPLv3 headers, README and COPYING file.
Thibaut Girka <thib@sitedethib.com>
parents: 41
diff changeset
14
526
0b2a92a25245 Store data in C arrays in Sprite, and add an interface to access them as tuples.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 439
diff changeset
15 cdef class Sprite:
120
4300a832f033 Small refactoring and massive performance improvement
Thibaut Girka <thib@sitedethib.com>
parents: 108
diff changeset
16 def __init__(self, width_override=0, height_override=0):
69
a142e57218a0 Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents: 61
diff changeset
17 self.anm = None
304
f3099ebf4f61 Update attribute names to reflect the actual interface.
Thibaut Girka <thib@sitedethib.com>
parents: 280
diff changeset
18 self.removed = False
f3099ebf4f61 Update attribute names to reflect the actual interface.
Thibaut Girka <thib@sitedethib.com>
parents: 280
diff changeset
19 self.changed = True
245
d3ba32a9096e Implement ANM0 instruction 29 and fix 24
Thibaut Girka <thib@sitedethib.com>
parents: 150
diff changeset
20 self.visible = True
69
a142e57218a0 Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents: 61
diff changeset
21
120
4300a832f033 Small refactoring and massive performance improvement
Thibaut Girka <thib@sitedethib.com>
parents: 108
diff changeset
22 self.width_override = width_override
4300a832f033 Small refactoring and massive performance improvement
Thibaut Girka <thib@sitedethib.com>
parents: 108
diff changeset
23 self.height_override = height_override
90
630e9045e851 Minor refactoring
Thibaut Girka <thib@sitedethib.com>
parents: 85
diff changeset
24 self.angle = 0
630e9045e851 Minor refactoring
Thibaut Girka <thib@sitedethib.com>
parents: 85
diff changeset
25 self.force_rotation = False
630e9045e851 Minor refactoring
Thibaut Girka <thib@sitedethib.com>
parents: 85
diff changeset
26
71
a03d7a94b997 Add support for a few ANM instructions
Thibaut Girka <thib@sitedethib.com>
parents: 69
diff changeset
27 self.scale_interpolator = None
a03d7a94b997 Add support for a few ANM instructions
Thibaut Girka <thib@sitedethib.com>
parents: 69
diff changeset
28 self.fade_interpolator = None
a03d7a94b997 Add support for a few ANM instructions
Thibaut Girka <thib@sitedethib.com>
parents: 69
diff changeset
29 self.offset_interpolator = None
429
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 304
diff changeset
30 self.rotation_interpolator = None
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 304
diff changeset
31 self.color_interpolator = None
71
a03d7a94b997 Add support for a few ANM instructions
Thibaut Girka <thib@sitedethib.com>
parents: 69
diff changeset
32
81
f5f9b5eb69a3 Handle one more ANM instruction, and handle sprite indexes offsets
Thibaut Girka <thib@sitedethib.com>
parents: 75
diff changeset
33 self.automatic_orientation = False
f5f9b5eb69a3 Handle one more ANM instruction, and handle sprite indexes offsets
Thibaut Girka <thib@sitedethib.com>
parents: 75
diff changeset
34
72
6a08f44fa01b Handle a few more ANM instructions. pytouhou.game.background needs some serious refactoring.
Thibaut Girka <thib@sitedethib.com>
parents: 71
diff changeset
35 self.blendfunc = 0 # 0 = Normal, 1 = saturate #TODO: proper constants
6a08f44fa01b Handle a few more ANM instructions. pytouhou.game.background needs some serious refactoring.
Thibaut Girka <thib@sitedethib.com>
parents: 71
diff changeset
36
526
0b2a92a25245 Store data in C arrays in Sprite, and add an interface to access them as tuples.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 439
diff changeset
37 self._texcoords[:] = [0, 0, 0, 0] # x, y, width, height
0b2a92a25245 Store data in C arrays in Sprite, and add an interface to access them as tuples.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 439
diff changeset
38 self._dest_offset[:] = [0., 0., 0.]
71
a03d7a94b997 Add support for a few ANM instructions
Thibaut Girka <thib@sitedethib.com>
parents: 69
diff changeset
39 self.allow_dest_offset = False
526
0b2a92a25245 Store data in C arrays in Sprite, and add an interface to access them as tuples.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 439
diff changeset
40 self._texoffsets[:] = [0., 0.]
15
07fba4e1da65 Refactor
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
41 self.mirrored = False
526
0b2a92a25245 Store data in C arrays in Sprite, and add an interface to access them as tuples.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 439
diff changeset
42 self._rescale[:] = [1., 1.]
0b2a92a25245 Store data in C arrays in Sprite, and add an interface to access them as tuples.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 439
diff changeset
43 self._scale_speed[:] = [0., 0.]
0b2a92a25245 Store data in C arrays in Sprite, and add an interface to access them as tuples.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 439
diff changeset
44 self._rotations_3d[:] = [0., 0., 0.]
0b2a92a25245 Store data in C arrays in Sprite, and add an interface to access them as tuples.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 439
diff changeset
45 self._rotations_speed_3d[:] = [0., 0., 0.]
15
07fba4e1da65 Refactor
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
46 self.corner_relative_placement = False
17
d940d004b840 Make game.sprite.Sprite use its own frame counter.
Thibaut Girka <thib@sitedethib.com>
parents: 15
diff changeset
47 self.frame = 0
526
0b2a92a25245 Store data in C arrays in Sprite, and add an interface to access them as tuples.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 439
diff changeset
48
0b2a92a25245 Store data in C arrays in Sprite, and add an interface to access them as tuples.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 439
diff changeset
49 # Cython treats unsigned char* variables as bytes, so we can’t use
0b2a92a25245 Store data in C arrays in Sprite, and add an interface to access them as tuples.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 439
diff changeset
50 # slicing here.
0b2a92a25245 Store data in C arrays in Sprite, and add an interface to access them as tuples.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 439
diff changeset
51 for i in xrange(4):
0b2a92a25245 Store data in C arrays in Sprite, and add an interface to access them as tuples.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 439
diff changeset
52 self._color[i] = 255
108
2a03940deea3 Move everything graphical to pytouhou.opengl!
Thibaut Girka <thib@sitedethib.com>
parents: 97
diff changeset
53
2a03940deea3 Move everything graphical to pytouhou.opengl!
Thibaut Girka <thib@sitedethib.com>
parents: 97
diff changeset
54 self._rendering_data = None
15
07fba4e1da65 Refactor
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
55
07fba4e1da65 Refactor
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
56
526
0b2a92a25245 Store data in C arrays in Sprite, and add an interface to access them as tuples.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 439
diff changeset
57 property scale_speed:
0b2a92a25245 Store data in C arrays in Sprite, and add an interface to access them as tuples.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 439
diff changeset
58 def __get__(self):
0b2a92a25245 Store data in C arrays in Sprite, and add an interface to access them as tuples.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 439
diff changeset
59 return (self._scale_speed[0], self._scale_speed[1])
0b2a92a25245 Store data in C arrays in Sprite, and add an interface to access them as tuples.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 439
diff changeset
60 def __set__(self, value):
0b2a92a25245 Store data in C arrays in Sprite, and add an interface to access them as tuples.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 439
diff changeset
61 self._scale_speed[:] = [value[0], value[1]]
0b2a92a25245 Store data in C arrays in Sprite, and add an interface to access them as tuples.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 439
diff changeset
62
0b2a92a25245 Store data in C arrays in Sprite, and add an interface to access them as tuples.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 439
diff changeset
63 property texoffsets:
0b2a92a25245 Store data in C arrays in Sprite, and add an interface to access them as tuples.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 439
diff changeset
64 def __get__(self):
0b2a92a25245 Store data in C arrays in Sprite, and add an interface to access them as tuples.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 439
diff changeset
65 return (self._texoffsets[0], self._texoffsets[1])
0b2a92a25245 Store data in C arrays in Sprite, and add an interface to access them as tuples.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 439
diff changeset
66 def __set__(self, value):
0b2a92a25245 Store data in C arrays in Sprite, and add an interface to access them as tuples.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 439
diff changeset
67 self._texoffsets[:] = [value[0], value[1]]
0b2a92a25245 Store data in C arrays in Sprite, and add an interface to access them as tuples.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 439
diff changeset
68
0b2a92a25245 Store data in C arrays in Sprite, and add an interface to access them as tuples.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 439
diff changeset
69 property rescale:
0b2a92a25245 Store data in C arrays in Sprite, and add an interface to access them as tuples.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 439
diff changeset
70 def __get__(self):
0b2a92a25245 Store data in C arrays in Sprite, and add an interface to access them as tuples.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 439
diff changeset
71 return (self._rescale[0], self._rescale[1])
0b2a92a25245 Store data in C arrays in Sprite, and add an interface to access them as tuples.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 439
diff changeset
72 def __set__(self, value):
0b2a92a25245 Store data in C arrays in Sprite, and add an interface to access them as tuples.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 439
diff changeset
73 self._rescale[:] = [value[0], value[1]]
0b2a92a25245 Store data in C arrays in Sprite, and add an interface to access them as tuples.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 439
diff changeset
74
0b2a92a25245 Store data in C arrays in Sprite, and add an interface to access them as tuples.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 439
diff changeset
75 property dest_offset:
0b2a92a25245 Store data in C arrays in Sprite, and add an interface to access them as tuples.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 439
diff changeset
76 def __get__(self):
0b2a92a25245 Store data in C arrays in Sprite, and add an interface to access them as tuples.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 439
diff changeset
77 return (self._dest_offset[0], self._dest_offset[1], self._dest_offset[2])
0b2a92a25245 Store data in C arrays in Sprite, and add an interface to access them as tuples.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 439
diff changeset
78 def __set__(self, value):
0b2a92a25245 Store data in C arrays in Sprite, and add an interface to access them as tuples.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 439
diff changeset
79 self._dest_offset[:] = [value[0], value[1], value[2]]
0b2a92a25245 Store data in C arrays in Sprite, and add an interface to access them as tuples.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 439
diff changeset
80
0b2a92a25245 Store data in C arrays in Sprite, and add an interface to access them as tuples.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 439
diff changeset
81 property rotations_speed_3d:
0b2a92a25245 Store data in C arrays in Sprite, and add an interface to access them as tuples.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 439
diff changeset
82 def __get__(self):
0b2a92a25245 Store data in C arrays in Sprite, and add an interface to access them as tuples.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 439
diff changeset
83 return (self._rotations_speed_3d[0], self._rotations_speed_3d[1], self._rotations_speed_3d[2])
0b2a92a25245 Store data in C arrays in Sprite, and add an interface to access them as tuples.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 439
diff changeset
84 def __set__(self, value):
0b2a92a25245 Store data in C arrays in Sprite, and add an interface to access them as tuples.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 439
diff changeset
85 self._rotations_speed_3d[:] = [value[0], value[1], value[2]]
0b2a92a25245 Store data in C arrays in Sprite, and add an interface to access them as tuples.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 439
diff changeset
86
0b2a92a25245 Store data in C arrays in Sprite, and add an interface to access them as tuples.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 439
diff changeset
87 property rotations_3d:
0b2a92a25245 Store data in C arrays in Sprite, and add an interface to access them as tuples.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 439
diff changeset
88 def __get__(self):
0b2a92a25245 Store data in C arrays in Sprite, and add an interface to access them as tuples.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 439
diff changeset
89 return (self._rotations_3d[0], self._rotations_3d[1], self._rotations_3d[2])
0b2a92a25245 Store data in C arrays in Sprite, and add an interface to access them as tuples.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 439
diff changeset
90 def __set__(self, value):
0b2a92a25245 Store data in C arrays in Sprite, and add an interface to access them as tuples.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 439
diff changeset
91 self._rotations_3d[:] = [value[0], value[1], value[2]]
0b2a92a25245 Store data in C arrays in Sprite, and add an interface to access them as tuples.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 439
diff changeset
92
0b2a92a25245 Store data in C arrays in Sprite, and add an interface to access them as tuples.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 439
diff changeset
93 property color:
0b2a92a25245 Store data in C arrays in Sprite, and add an interface to access them as tuples.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 439
diff changeset
94 def __get__(self):
0b2a92a25245 Store data in C arrays in Sprite, and add an interface to access them as tuples.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 439
diff changeset
95 return (self._color[0], self._color[1], self._color[2])
0b2a92a25245 Store data in C arrays in Sprite, and add an interface to access them as tuples.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 439
diff changeset
96 def __set__(self, value):
0b2a92a25245 Store data in C arrays in Sprite, and add an interface to access them as tuples.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 439
diff changeset
97 self._color[0] = value[0]
0b2a92a25245 Store data in C arrays in Sprite, and add an interface to access them as tuples.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 439
diff changeset
98 self._color[1] = value[1]
0b2a92a25245 Store data in C arrays in Sprite, and add an interface to access them as tuples.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 439
diff changeset
99 self._color[2] = value[2]
0b2a92a25245 Store data in C arrays in Sprite, and add an interface to access them as tuples.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 439
diff changeset
100
0b2a92a25245 Store data in C arrays in Sprite, and add an interface to access them as tuples.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 439
diff changeset
101 property alpha:
0b2a92a25245 Store data in C arrays in Sprite, and add an interface to access them as tuples.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 439
diff changeset
102 def __get__(self):
0b2a92a25245 Store data in C arrays in Sprite, and add an interface to access them as tuples.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 439
diff changeset
103 return self._color[3]
0b2a92a25245 Store data in C arrays in Sprite, and add an interface to access them as tuples.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 439
diff changeset
104 def __set__(self, value):
0b2a92a25245 Store data in C arrays in Sprite, and add an interface to access them as tuples.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 439
diff changeset
105 self._color[3] = value
0b2a92a25245 Store data in C arrays in Sprite, and add an interface to access them as tuples.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 439
diff changeset
106
0b2a92a25245 Store data in C arrays in Sprite, and add an interface to access them as tuples.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 439
diff changeset
107 property texcoords:
0b2a92a25245 Store data in C arrays in Sprite, and add an interface to access them as tuples.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 439
diff changeset
108 def __get__(self):
0b2a92a25245 Store data in C arrays in Sprite, and add an interface to access them as tuples.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 439
diff changeset
109 return (self._texcoords[0], self._texcoords[1], self._texcoords[2], self._texcoords[3])
0b2a92a25245 Store data in C arrays in Sprite, and add an interface to access them as tuples.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 439
diff changeset
110 def __set__(self, value):
0b2a92a25245 Store data in C arrays in Sprite, and add an interface to access them as tuples.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 439
diff changeset
111 self._texcoords[:] = [value[0], value[1], value[2], value[3]]
0b2a92a25245 Store data in C arrays in Sprite, and add an interface to access them as tuples.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 439
diff changeset
112
0b2a92a25245 Store data in C arrays in Sprite, and add an interface to access them as tuples.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 439
diff changeset
113
0b2a92a25245 Store data in C arrays in Sprite, and add an interface to access them as tuples.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 439
diff changeset
114 cpdef fade(self, unsigned long duration, alpha, formula=None):
0b2a92a25245 Store data in C arrays in Sprite, and add an interface to access them as tuples.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 439
diff changeset
115 self.fade_interpolator = Interpolator((self._color[3],), self.frame,
280
e04c3e1957c8 Fix ANM interpolators.
Thibaut Girka <thib@sitedethib.com>
parents: 245
diff changeset
116 (alpha,), self.frame + duration,
e04c3e1957c8 Fix ANM interpolators.
Thibaut Girka <thib@sitedethib.com>
parents: 245
diff changeset
117 formula)
71
a03d7a94b997 Add support for a few ANM instructions
Thibaut Girka <thib@sitedethib.com>
parents: 69
diff changeset
118
a03d7a94b997 Add support for a few ANM instructions
Thibaut Girka <thib@sitedethib.com>
parents: 69
diff changeset
119
526
0b2a92a25245 Store data in C arrays in Sprite, and add an interface to access them as tuples.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 439
diff changeset
120 cpdef scale_in(self, unsigned long duration, sx, sy, formula=None):
280
e04c3e1957c8 Fix ANM interpolators.
Thibaut Girka <thib@sitedethib.com>
parents: 245
diff changeset
121 self.scale_interpolator = Interpolator(self.rescale, self.frame,
e04c3e1957c8 Fix ANM interpolators.
Thibaut Girka <thib@sitedethib.com>
parents: 245
diff changeset
122 (sx, sy), self.frame + duration,
e04c3e1957c8 Fix ANM interpolators.
Thibaut Girka <thib@sitedethib.com>
parents: 245
diff changeset
123 formula)
71
a03d7a94b997 Add support for a few ANM instructions
Thibaut Girka <thib@sitedethib.com>
parents: 69
diff changeset
124
a03d7a94b997 Add support for a few ANM instructions
Thibaut Girka <thib@sitedethib.com>
parents: 69
diff changeset
125
526
0b2a92a25245 Store data in C arrays in Sprite, and add an interface to access them as tuples.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 439
diff changeset
126 cpdef move_in(self, unsigned long duration, x, y, z, formula=None):
280
e04c3e1957c8 Fix ANM interpolators.
Thibaut Girka <thib@sitedethib.com>
parents: 245
diff changeset
127 self.offset_interpolator = Interpolator(self.dest_offset, self.frame,
e04c3e1957c8 Fix ANM interpolators.
Thibaut Girka <thib@sitedethib.com>
parents: 245
diff changeset
128 (x, y, z), self.frame + duration,
e04c3e1957c8 Fix ANM interpolators.
Thibaut Girka <thib@sitedethib.com>
parents: 245
diff changeset
129 formula)
71
a03d7a94b997 Add support for a few ANM instructions
Thibaut Girka <thib@sitedethib.com>
parents: 69
diff changeset
130
a03d7a94b997 Add support for a few ANM instructions
Thibaut Girka <thib@sitedethib.com>
parents: 69
diff changeset
131
526
0b2a92a25245 Store data in C arrays in Sprite, and add an interface to access them as tuples.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 439
diff changeset
132 cpdef rotate_in(self, unsigned long duration, rx, ry, rz, formula=None):
429
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 304
diff changeset
133 self.rotation_interpolator = Interpolator(self.rotations_3d, self.frame,
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 304
diff changeset
134 (rx, ry, rz), self.frame + duration,
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 304
diff changeset
135 formula)
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 304
diff changeset
136
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 304
diff changeset
137
526
0b2a92a25245 Store data in C arrays in Sprite, and add an interface to access them as tuples.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 439
diff changeset
138 cpdef change_color_in(self, unsigned long duration, r, g, b, formula=None):
429
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 304
diff changeset
139 self.color_interpolator = Interpolator(self.color, self.frame,
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 304
diff changeset
140 (r, g, b), self.frame + duration,
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 304
diff changeset
141 formula)
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 304
diff changeset
142
40d5f3083ebc Implement PCB’s ANM2 format and vm.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 304
diff changeset
143
526
0b2a92a25245 Store data in C arrays in Sprite, and add an interface to access them as tuples.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 439
diff changeset
144 cpdef update_orientation(self, double angle_base=0., bint force_rotation=False):
120
4300a832f033 Small refactoring and massive performance improvement
Thibaut Girka <thib@sitedethib.com>
parents: 108
diff changeset
145 if (self.angle != angle_base or self.force_rotation != force_rotation):
92
85f3b8ba3f24 Minor refactoring and optimizations. Drop stageviewer.
Thibaut Girka <thib@sitedethib.com>
parents: 90
diff changeset
146 self.angle = angle_base
85f3b8ba3f24 Minor refactoring and optimizations. Drop stageviewer.
Thibaut Girka <thib@sitedethib.com>
parents: 90
diff changeset
147 self.force_rotation = force_rotation
304
f3099ebf4f61 Update attribute names to reflect the actual interface.
Thibaut Girka <thib@sitedethib.com>
parents: 280
diff changeset
148 self.changed = True
94
ca571697ec83 Various minor optimisations and refactoring
Thibaut Girka <thib@sitedethib.com>
parents: 92
diff changeset
149
432
d4874ebaa06e Split ANMRunner.run_frame into Sprite.update.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 429
diff changeset
150
526
0b2a92a25245 Store data in C arrays in Sprite, and add an interface to access them as tuples.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 439
diff changeset
151 cpdef Sprite copy(self):
439
723a3e67a223 Make pytouhou.game.sprite an extension type.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 432
diff changeset
152 sprite = Sprite(self.width_override, self.height_override)
723a3e67a223 Make pytouhou.game.sprite an extension type.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 432
diff changeset
153
723a3e67a223 Make pytouhou.game.sprite an extension type.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 432
diff changeset
154 sprite.blendfunc = self.blendfunc
723a3e67a223 Make pytouhou.game.sprite an extension type.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 432
diff changeset
155 sprite.frame = self.frame
723a3e67a223 Make pytouhou.game.sprite an extension type.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 432
diff changeset
156 sprite.angle = self.angle
723a3e67a223 Make pytouhou.game.sprite an extension type.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 432
diff changeset
157
723a3e67a223 Make pytouhou.game.sprite an extension type.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 432
diff changeset
158 sprite.removed = self.removed
723a3e67a223 Make pytouhou.game.sprite an extension type.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 432
diff changeset
159 sprite.changed = self.changed
723a3e67a223 Make pytouhou.game.sprite an extension type.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 432
diff changeset
160 sprite.visible = self.visible
723a3e67a223 Make pytouhou.game.sprite an extension type.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 432
diff changeset
161 sprite.force_rotation = self.force_rotation
723a3e67a223 Make pytouhou.game.sprite an extension type.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 432
diff changeset
162 sprite.automatic_orientation = self.automatic_orientation
723a3e67a223 Make pytouhou.game.sprite an extension type.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 432
diff changeset
163 sprite.allow_dest_offset = self.allow_dest_offset
723a3e67a223 Make pytouhou.game.sprite an extension type.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 432
diff changeset
164 sprite.mirrored = self.mirrored
723a3e67a223 Make pytouhou.game.sprite an extension type.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 432
diff changeset
165 sprite.corner_relative_placement = self.corner_relative_placement
723a3e67a223 Make pytouhou.game.sprite an extension type.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 432
diff changeset
166
723a3e67a223 Make pytouhou.game.sprite an extension type.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 432
diff changeset
167 sprite.scale_interpolator = self.scale_interpolator
723a3e67a223 Make pytouhou.game.sprite an extension type.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 432
diff changeset
168 sprite.fade_interpolator = self.fade_interpolator
723a3e67a223 Make pytouhou.game.sprite an extension type.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 432
diff changeset
169 sprite.offset_interpolator = self.offset_interpolator
723a3e67a223 Make pytouhou.game.sprite an extension type.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 432
diff changeset
170 sprite.rotation_interpolator = self.rotation_interpolator
723a3e67a223 Make pytouhou.game.sprite an extension type.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 432
diff changeset
171 sprite.color_interpolator = self.color_interpolator
723a3e67a223 Make pytouhou.game.sprite an extension type.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 432
diff changeset
172
723a3e67a223 Make pytouhou.game.sprite an extension type.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 432
diff changeset
173 sprite.texcoords = self.texcoords
723a3e67a223 Make pytouhou.game.sprite an extension type.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 432
diff changeset
174 sprite.dest_offset = self.dest_offset
723a3e67a223 Make pytouhou.game.sprite an extension type.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 432
diff changeset
175 sprite.texoffsets = self.texoffsets
723a3e67a223 Make pytouhou.game.sprite an extension type.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 432
diff changeset
176 sprite.rescale = self.rescale
723a3e67a223 Make pytouhou.game.sprite an extension type.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 432
diff changeset
177 sprite.scale_speed = self.scale_speed
723a3e67a223 Make pytouhou.game.sprite an extension type.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 432
diff changeset
178 sprite.rotations_3d = self.rotations_3d
723a3e67a223 Make pytouhou.game.sprite an extension type.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 432
diff changeset
179 sprite.rotations_speed_3d = self.rotations_speed_3d
723a3e67a223 Make pytouhou.game.sprite an extension type.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 432
diff changeset
180 sprite.color = self.color
723a3e67a223 Make pytouhou.game.sprite an extension type.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 432
diff changeset
181
723a3e67a223 Make pytouhou.game.sprite an extension type.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 432
diff changeset
182 sprite.alpha = self.alpha
723a3e67a223 Make pytouhou.game.sprite an extension type.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 432
diff changeset
183 sprite.anm = self.anm
723a3e67a223 Make pytouhou.game.sprite an extension type.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 432
diff changeset
184 sprite._rendering_data = self._rendering_data
723a3e67a223 Make pytouhou.game.sprite an extension type.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 432
diff changeset
185
723a3e67a223 Make pytouhou.game.sprite an extension type.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 432
diff changeset
186 return sprite
723a3e67a223 Make pytouhou.game.sprite an extension type.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 432
diff changeset
187
723a3e67a223 Make pytouhou.game.sprite an extension type.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 432
diff changeset
188
526
0b2a92a25245 Store data in C arrays in Sprite, and add an interface to access them as tuples.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 439
diff changeset
189 cpdef update(self):
432
d4874ebaa06e Split ANMRunner.run_frame into Sprite.update.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 429
diff changeset
190 self.frame += 1
d4874ebaa06e Split ANMRunner.run_frame into Sprite.update.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 429
diff changeset
191
526
0b2a92a25245 Store data in C arrays in Sprite, and add an interface to access them as tuples.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 439
diff changeset
192 sax, say, saz = self._rotations_speed_3d[0], self._rotations_speed_3d[1], self._rotations_speed_3d[2] #XXX
0b2a92a25245 Store data in C arrays in Sprite, and add an interface to access them as tuples.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 439
diff changeset
193 if sax or say or saz:
0b2a92a25245 Store data in C arrays in Sprite, and add an interface to access them as tuples.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 439
diff changeset
194 ax, ay, az = self._rotations_3d[0], self._rotations_3d[1], self._rotations_3d[2] #XXX
0b2a92a25245 Store data in C arrays in Sprite, and add an interface to access them as tuples.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 439
diff changeset
195 self._rotations_3d[:] = [ax + sax, ay + say, az + saz]
432
d4874ebaa06e Split ANMRunner.run_frame into Sprite.update.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 429
diff changeset
196 self.changed = True
d4874ebaa06e Split ANMRunner.run_frame into Sprite.update.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 429
diff changeset
197 elif self.rotation_interpolator:
d4874ebaa06e Split ANMRunner.run_frame into Sprite.update.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 429
diff changeset
198 self.rotation_interpolator.update(self.frame)
d4874ebaa06e Split ANMRunner.run_frame into Sprite.update.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 429
diff changeset
199 self.rotations_3d = self.rotation_interpolator.values
d4874ebaa06e Split ANMRunner.run_frame into Sprite.update.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 429
diff changeset
200 self.changed = True
d4874ebaa06e Split ANMRunner.run_frame into Sprite.update.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 429
diff changeset
201
526
0b2a92a25245 Store data in C arrays in Sprite, and add an interface to access them as tuples.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 439
diff changeset
202 rsx, rsy = self._scale_speed[0], self._scale_speed[1] #XXX
0b2a92a25245 Store data in C arrays in Sprite, and add an interface to access them as tuples.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 439
diff changeset
203 if rsx or rsy:
0b2a92a25245 Store data in C arrays in Sprite, and add an interface to access them as tuples.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 439
diff changeset
204 rx, ry = self._rescale[0], self._rescale[1] #XXX
0b2a92a25245 Store data in C arrays in Sprite, and add an interface to access them as tuples.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 439
diff changeset
205 self._rescale[:] = [rx + rsx, ry + rsy]
432
d4874ebaa06e Split ANMRunner.run_frame into Sprite.update.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 429
diff changeset
206 self.changed = True
d4874ebaa06e Split ANMRunner.run_frame into Sprite.update.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 429
diff changeset
207
d4874ebaa06e Split ANMRunner.run_frame into Sprite.update.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 429
diff changeset
208 if self.fade_interpolator:
d4874ebaa06e Split ANMRunner.run_frame into Sprite.update.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 429
diff changeset
209 self.fade_interpolator.update(self.frame)
526
0b2a92a25245 Store data in C arrays in Sprite, and add an interface to access them as tuples.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 439
diff changeset
210 self._color[3] = self.fade_interpolator.values[0]
432
d4874ebaa06e Split ANMRunner.run_frame into Sprite.update.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 429
diff changeset
211 self.changed = True
d4874ebaa06e Split ANMRunner.run_frame into Sprite.update.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 429
diff changeset
212
d4874ebaa06e Split ANMRunner.run_frame into Sprite.update.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 429
diff changeset
213 if self.scale_interpolator:
d4874ebaa06e Split ANMRunner.run_frame into Sprite.update.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 429
diff changeset
214 self.scale_interpolator.update(self.frame)
d4874ebaa06e Split ANMRunner.run_frame into Sprite.update.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 429
diff changeset
215 self.rescale = self.scale_interpolator.values
d4874ebaa06e Split ANMRunner.run_frame into Sprite.update.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 429
diff changeset
216 self.changed = True
d4874ebaa06e Split ANMRunner.run_frame into Sprite.update.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 429
diff changeset
217
d4874ebaa06e Split ANMRunner.run_frame into Sprite.update.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 429
diff changeset
218 if self.offset_interpolator:
d4874ebaa06e Split ANMRunner.run_frame into Sprite.update.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 429
diff changeset
219 self.offset_interpolator.update(self.frame)
d4874ebaa06e Split ANMRunner.run_frame into Sprite.update.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 429
diff changeset
220 self.dest_offset = self.offset_interpolator.values
d4874ebaa06e Split ANMRunner.run_frame into Sprite.update.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 429
diff changeset
221 self.changed = True
d4874ebaa06e Split ANMRunner.run_frame into Sprite.update.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 429
diff changeset
222
d4874ebaa06e Split ANMRunner.run_frame into Sprite.update.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 429
diff changeset
223 if self.color_interpolator:
d4874ebaa06e Split ANMRunner.run_frame into Sprite.update.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 429
diff changeset
224 self.color_interpolator.update(self.frame)
d4874ebaa06e Split ANMRunner.run_frame into Sprite.update.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 429
diff changeset
225 self.color = self.color_interpolator.values
d4874ebaa06e Split ANMRunner.run_frame into Sprite.update.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 429
diff changeset
226 self.changed = True