annotate pytouhou/game/sprite.py @ 91:f7525fa66bb0

Fix ECL instruction 3
author Thibaut Girka <thib@sitedethib.com>
date Sun, 04 Sep 2011 10:19:42 +0200
parents 630e9045e851
children 85f3b8ba3f24
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
90
630e9045e851 Minor refactoring
Thibaut Girka <thib@sitedethib.com>
parents: 85
diff changeset
15 from math import pi
52
ab826bc29aa2 Add some documentation, GPLv3 headers, README and COPYING file.
Thibaut Girka <thib@sitedethib.com>
parents: 41
diff changeset
16
15
07fba4e1da65 Refactor
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
17 from pytouhou.utils.matrix import Matrix
71
a03d7a94b997 Add support for a few ANM instructions
Thibaut Girka <thib@sitedethib.com>
parents: 69
diff changeset
18 from pytouhou.utils.interpolator import Interpolator
15
07fba4e1da65 Refactor
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
19
21
bf225780973f Small refactoring, and Rumia \o/
Thibaut Girka <thib@sitedethib.com>
parents: 17
diff changeset
20
bf225780973f Small refactoring, and Rumia \o/
Thibaut Girka <thib@sitedethib.com>
parents: 17
diff changeset
21 class AnmWrapper(object):
bf225780973f Small refactoring, and Rumia \o/
Thibaut Girka <thib@sitedethib.com>
parents: 17
diff changeset
22 def __init__(self, anm_files):
bf225780973f Small refactoring, and Rumia \o/
Thibaut Girka <thib@sitedethib.com>
parents: 17
diff changeset
23 self.anm_files = list(anm_files)
bf225780973f Small refactoring, and Rumia \o/
Thibaut Girka <thib@sitedethib.com>
parents: 17
diff changeset
24
69
a142e57218a0 Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents: 61
diff changeset
25
a142e57218a0 Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents: 61
diff changeset
26 def get_sprite(self, sprite_index):
a142e57218a0 Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents: 61
diff changeset
27 for anm in self.anm_files:
a142e57218a0 Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents: 61
diff changeset
28 if sprite_index in anm.sprites:
a142e57218a0 Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents: 61
diff changeset
29 return anm, anm.sprites[sprite_index]
a142e57218a0 Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents: 61
diff changeset
30 raise IndexError
a142e57218a0 Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents: 61
diff changeset
31
a142e57218a0 Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents: 61
diff changeset
32
a142e57218a0 Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents: 61
diff changeset
33 def get_script(self, script_index):
21
bf225780973f Small refactoring, and Rumia \o/
Thibaut Girka <thib@sitedethib.com>
parents: 17
diff changeset
34 for anm in self.anm_files:
bf225780973f Small refactoring, and Rumia \o/
Thibaut Girka <thib@sitedethib.com>
parents: 17
diff changeset
35 if script_index in anm.scripts:
69
a142e57218a0 Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents: 61
diff changeset
36 return anm, anm.scripts[script_index]
a142e57218a0 Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents: 61
diff changeset
37 raise IndexError
21
bf225780973f Small refactoring, and Rumia \o/
Thibaut Girka <thib@sitedethib.com>
parents: 17
diff changeset
38
bf225780973f Small refactoring, and Rumia \o/
Thibaut Girka <thib@sitedethib.com>
parents: 17
diff changeset
39
bf225780973f Small refactoring, and Rumia \o/
Thibaut Girka <thib@sitedethib.com>
parents: 17
diff changeset
40
15
07fba4e1da65 Refactor
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
41 class Sprite(object):
69
a142e57218a0 Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents: 61
diff changeset
42 def __init__(self):
a142e57218a0 Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents: 61
diff changeset
43 self.anm = None
a142e57218a0 Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents: 61
diff changeset
44 self._removed = False
a142e57218a0 Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents: 61
diff changeset
45 self._changed = False
a142e57218a0 Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents: 61
diff changeset
46
90
630e9045e851 Minor refactoring
Thibaut Girka <thib@sitedethib.com>
parents: 85
diff changeset
47 self.width_override = 0
630e9045e851 Minor refactoring
Thibaut Girka <thib@sitedethib.com>
parents: 85
diff changeset
48 self.height_override = 0
630e9045e851 Minor refactoring
Thibaut Girka <thib@sitedethib.com>
parents: 85
diff changeset
49 self.angle = 0
630e9045e851 Minor refactoring
Thibaut Girka <thib@sitedethib.com>
parents: 85
diff changeset
50 self.force_rotation = False
630e9045e851 Minor refactoring
Thibaut Girka <thib@sitedethib.com>
parents: 85
diff changeset
51
71
a03d7a94b997 Add support for a few ANM instructions
Thibaut Girka <thib@sitedethib.com>
parents: 69
diff changeset
52 self.scale_interpolator = None
a03d7a94b997 Add support for a few ANM instructions
Thibaut Girka <thib@sitedethib.com>
parents: 69
diff changeset
53 self.fade_interpolator = None
a03d7a94b997 Add support for a few ANM instructions
Thibaut Girka <thib@sitedethib.com>
parents: 69
diff changeset
54 self.offset_interpolator = None
a03d7a94b997 Add support for a few ANM instructions
Thibaut Girka <thib@sitedethib.com>
parents: 69
diff changeset
55
81
f5f9b5eb69a3 Handle one more ANM instruction, and handle sprite indexes offsets
Thibaut Girka <thib@sitedethib.com>
parents: 75
diff changeset
56 self.automatic_orientation = False
f5f9b5eb69a3 Handle one more ANM instruction, and handle sprite indexes offsets
Thibaut Girka <thib@sitedethib.com>
parents: 75
diff changeset
57
72
6a08f44fa01b Handle a few more ANM instructions. pytouhou.game.background needs some serious refactoring.
Thibaut Girka <thib@sitedethib.com>
parents: 71
diff changeset
58 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
59
15
07fba4e1da65 Refactor
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
60 self.texcoords = (0, 0, 0, 0) # x, y, width, height
71
a03d7a94b997 Add support for a few ANM instructions
Thibaut Girka <thib@sitedethib.com>
parents: 69
diff changeset
61 self.dest_offset = (0., 0., 0.)
a03d7a94b997 Add support for a few ANM instructions
Thibaut Girka <thib@sitedethib.com>
parents: 69
diff changeset
62 self.allow_dest_offset = False
41
93c8dc2de923 Add (hopefully) "texture shifting" in animations
Thibaut Girka <thib@sitedethib.com>
parents: 38
diff changeset
63 self.texoffsets = (0., 0.)
15
07fba4e1da65 Refactor
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
64 self.mirrored = False
07fba4e1da65 Refactor
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
65 self.rescale = (1., 1.)
57
694f25881d0f Fix move_to interpolation, add support for a few ANM and ECL instructions
Thibaut Girka <thib@sitedethib.com>
parents: 54
diff changeset
66 self.scale_speed = (0., 0.)
15
07fba4e1da65 Refactor
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
67 self.rotations_3d = (0., 0., 0.)
27
b65d6bc55793 Add rotating sprite support
Thibaut Girka <thib@sitedethib.com>
parents: 26
diff changeset
68 self.rotations_speed_3d = (0., 0., 0.)
15
07fba4e1da65 Refactor
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
69 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
70 self.frame = 0
57
694f25881d0f Fix move_to interpolation, add support for a few ANM and ECL instructions
Thibaut Girka <thib@sitedethib.com>
parents: 54
diff changeset
71 self.color = (255, 255, 255)
37
a10e3f44a883 Add alpha (anm0 instruction 3) support
Thibaut Girka <thib@sitedethib.com>
parents: 34
diff changeset
72 self.alpha = 255
15
07fba4e1da65 Refactor
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
73 self._uvs = []
07fba4e1da65 Refactor
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
74 self._vertices = []
37
a10e3f44a883 Add alpha (anm0 instruction 3) support
Thibaut Girka <thib@sitedethib.com>
parents: 34
diff changeset
75 self._colors = []
15
07fba4e1da65 Refactor
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
76
07fba4e1da65 Refactor
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
77
71
a03d7a94b997 Add support for a few ANM instructions
Thibaut Girka <thib@sitedethib.com>
parents: 69
diff changeset
78 def fade(self, duration, alpha, formula):
a03d7a94b997 Add support for a few ANM instructions
Thibaut Girka <thib@sitedethib.com>
parents: 69
diff changeset
79 if not self.fade_interpolator:
a03d7a94b997 Add support for a few ANM instructions
Thibaut Girka <thib@sitedethib.com>
parents: 69
diff changeset
80 self.fade_interpolator = Interpolator((self.alpha,), formula)
a03d7a94b997 Add support for a few ANM instructions
Thibaut Girka <thib@sitedethib.com>
parents: 69
diff changeset
81 self.fade_interpolator.set_interpolation_start(self.frame, (self.alpha,))
a03d7a94b997 Add support for a few ANM instructions
Thibaut Girka <thib@sitedethib.com>
parents: 69
diff changeset
82 self.fade_interpolator.set_interpolation_end(self.frame + duration - 1, (alpha,))
a03d7a94b997 Add support for a few ANM instructions
Thibaut Girka <thib@sitedethib.com>
parents: 69
diff changeset
83
a03d7a94b997 Add support for a few ANM instructions
Thibaut Girka <thib@sitedethib.com>
parents: 69
diff changeset
84
a03d7a94b997 Add support for a few ANM instructions
Thibaut Girka <thib@sitedethib.com>
parents: 69
diff changeset
85 def scale_in(self, duration, sx, sy, formula):
a03d7a94b997 Add support for a few ANM instructions
Thibaut Girka <thib@sitedethib.com>
parents: 69
diff changeset
86 if not self.scale_interpolator:
a03d7a94b997 Add support for a few ANM instructions
Thibaut Girka <thib@sitedethib.com>
parents: 69
diff changeset
87 self.scale_interpolator = Interpolator(self.rescale, formula)
a03d7a94b997 Add support for a few ANM instructions
Thibaut Girka <thib@sitedethib.com>
parents: 69
diff changeset
88 self.scale_interpolator.set_interpolation_start(self.frame, self.rescale)
a03d7a94b997 Add support for a few ANM instructions
Thibaut Girka <thib@sitedethib.com>
parents: 69
diff changeset
89 self.scale_interpolator.set_interpolation_end(self.frame + duration - 1, (sx, sy))
a03d7a94b997 Add support for a few ANM instructions
Thibaut Girka <thib@sitedethib.com>
parents: 69
diff changeset
90
a03d7a94b997 Add support for a few ANM instructions
Thibaut Girka <thib@sitedethib.com>
parents: 69
diff changeset
91
a03d7a94b997 Add support for a few ANM instructions
Thibaut Girka <thib@sitedethib.com>
parents: 69
diff changeset
92 def move_in(self, duration, x, y, z, formula):
a03d7a94b997 Add support for a few ANM instructions
Thibaut Girka <thib@sitedethib.com>
parents: 69
diff changeset
93 if not self.offset_interpolator:
a03d7a94b997 Add support for a few ANM instructions
Thibaut Girka <thib@sitedethib.com>
parents: 69
diff changeset
94 self.offset_interpolator = Interpolator(self.dest_offset, formula)
a03d7a94b997 Add support for a few ANM instructions
Thibaut Girka <thib@sitedethib.com>
parents: 69
diff changeset
95 self.offset_interpolator.set_interpolation_start(self.frame, self.dest_offset)
a03d7a94b997 Add support for a few ANM instructions
Thibaut Girka <thib@sitedethib.com>
parents: 69
diff changeset
96 self.offset_interpolator.set_interpolation_end(self.frame + duration - 1, (x, y, z))
a03d7a94b997 Add support for a few ANM instructions
Thibaut Girka <thib@sitedethib.com>
parents: 69
diff changeset
97
a03d7a94b997 Add support for a few ANM instructions
Thibaut Girka <thib@sitedethib.com>
parents: 69
diff changeset
98
90
630e9045e851 Minor refactoring
Thibaut Girka <thib@sitedethib.com>
parents: 85
diff changeset
99 def update_vertices_uvs_colors(self):
630e9045e851 Minor refactoring
Thibaut Girka <thib@sitedethib.com>
parents: 85
diff changeset
100 if not self._changed:
630e9045e851 Minor refactoring
Thibaut Girka <thib@sitedethib.com>
parents: 85
diff changeset
101 return
630e9045e851 Minor refactoring
Thibaut Girka <thib@sitedethib.com>
parents: 85
diff changeset
102
71
a03d7a94b997 Add support for a few ANM instructions
Thibaut Girka <thib@sitedethib.com>
parents: 69
diff changeset
103 if self.fade_interpolator:
a03d7a94b997 Add support for a few ANM instructions
Thibaut Girka <thib@sitedethib.com>
parents: 69
diff changeset
104 self.fade_interpolator.update(self.frame)
a03d7a94b997 Add support for a few ANM instructions
Thibaut Girka <thib@sitedethib.com>
parents: 69
diff changeset
105 self.alpha = int(self.fade_interpolator.values[0])
a03d7a94b997 Add support for a few ANM instructions
Thibaut Girka <thib@sitedethib.com>
parents: 69
diff changeset
106
a03d7a94b997 Add support for a few ANM instructions
Thibaut Girka <thib@sitedethib.com>
parents: 69
diff changeset
107 if self.scale_interpolator:
a03d7a94b997 Add support for a few ANM instructions
Thibaut Girka <thib@sitedethib.com>
parents: 69
diff changeset
108 self.scale_interpolator.update(self.frame)
a03d7a94b997 Add support for a few ANM instructions
Thibaut Girka <thib@sitedethib.com>
parents: 69
diff changeset
109 self.rescale = self.scale_interpolator.values
a03d7a94b997 Add support for a few ANM instructions
Thibaut Girka <thib@sitedethib.com>
parents: 69
diff changeset
110
a03d7a94b997 Add support for a few ANM instructions
Thibaut Girka <thib@sitedethib.com>
parents: 69
diff changeset
111 if self.offset_interpolator:
a03d7a94b997 Add support for a few ANM instructions
Thibaut Girka <thib@sitedethib.com>
parents: 69
diff changeset
112 self.offset_interpolator.update(self.frame)
a03d7a94b997 Add support for a few ANM instructions
Thibaut Girka <thib@sitedethib.com>
parents: 69
diff changeset
113 self.dest_offset = self.offset_interpolator.values
a03d7a94b997 Add support for a few ANM instructions
Thibaut Girka <thib@sitedethib.com>
parents: 69
diff changeset
114
28
f405b947624d Massive sprite updating/matrix handling optimizations
Thibaut Girka <thib@sitedethib.com>
parents: 27
diff changeset
115 vertmat = Matrix([[-.5, .5, .5, -.5],
f405b947624d Massive sprite updating/matrix handling optimizations
Thibaut Girka <thib@sitedethib.com>
parents: 27
diff changeset
116 [-.5, -.5, .5, .5],
f405b947624d Massive sprite updating/matrix handling optimizations
Thibaut Girka <thib@sitedethib.com>
parents: 27
diff changeset
117 [ .0, .0, .0, .0],
f405b947624d Massive sprite updating/matrix handling optimizations
Thibaut Girka <thib@sitedethib.com>
parents: 27
diff changeset
118 [ 1., 1., 1., 1.]])
15
07fba4e1da65 Refactor
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
119
07fba4e1da65 Refactor
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
120 tx, ty, tw, th = self.texcoords
07fba4e1da65 Refactor
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
121 sx, sy = self.rescale
90
630e9045e851 Minor refactoring
Thibaut Girka <thib@sitedethib.com>
parents: 85
diff changeset
122 width = self.width_override or (tw * sx)
630e9045e851 Minor refactoring
Thibaut Girka <thib@sitedethib.com>
parents: 85
diff changeset
123 height = self.height_override or (th * sy)
15
07fba4e1da65 Refactor
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
124
31
55973a3f1222 Some more optimization!
Thibaut Girka <thib@sitedethib.com>
parents: 30
diff changeset
125 vertmat.scale2d(width, height)
15
07fba4e1da65 Refactor
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
126 if self.mirrored:
28
f405b947624d Massive sprite updating/matrix handling optimizations
Thibaut Girka <thib@sitedethib.com>
parents: 27
diff changeset
127 vertmat.flip()
75
b3bd421bb895 Handle a few more ECL instructions
Thibaut Girka <thib@sitedethib.com>
parents: 72
diff changeset
128
b3bd421bb895 Handle a few more ECL instructions
Thibaut Girka <thib@sitedethib.com>
parents: 72
diff changeset
129 rx, ry, rz = self.rotations_3d
90
630e9045e851 Minor refactoring
Thibaut Girka <thib@sitedethib.com>
parents: 85
diff changeset
130 if self.automatic_orientation:
630e9045e851 Minor refactoring
Thibaut Girka <thib@sitedethib.com>
parents: 85
diff changeset
131 rz += pi/2. - self.angle
630e9045e851 Minor refactoring
Thibaut Girka <thib@sitedethib.com>
parents: 85
diff changeset
132 elif self.force_rotation:
630e9045e851 Minor refactoring
Thibaut Girka <thib@sitedethib.com>
parents: 85
diff changeset
133 rz += self.angle
75
b3bd421bb895 Handle a few more ECL instructions
Thibaut Girka <thib@sitedethib.com>
parents: 72
diff changeset
134
b3bd421bb895 Handle a few more ECL instructions
Thibaut Girka <thib@sitedethib.com>
parents: 72
diff changeset
135 if (rx, ry, rz) != (0., 0., 0.):
28
f405b947624d Massive sprite updating/matrix handling optimizations
Thibaut Girka <thib@sitedethib.com>
parents: 27
diff changeset
136 if rx:
f405b947624d Massive sprite updating/matrix handling optimizations
Thibaut Girka <thib@sitedethib.com>
parents: 27
diff changeset
137 vertmat.rotate_x(-rx)
f405b947624d Massive sprite updating/matrix handling optimizations
Thibaut Girka <thib@sitedethib.com>
parents: 27
diff changeset
138 if ry:
f405b947624d Massive sprite updating/matrix handling optimizations
Thibaut Girka <thib@sitedethib.com>
parents: 27
diff changeset
139 vertmat.rotate_y(ry)
f405b947624d Massive sprite updating/matrix handling optimizations
Thibaut Girka <thib@sitedethib.com>
parents: 27
diff changeset
140 if rz:
f405b947624d Massive sprite updating/matrix handling optimizations
Thibaut Girka <thib@sitedethib.com>
parents: 27
diff changeset
141 vertmat.rotate_z(-rz) #TODO: minus, really?
15
07fba4e1da65 Refactor
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
142 if self.corner_relative_placement: # Reposition
28
f405b947624d Massive sprite updating/matrix handling optimizations
Thibaut Girka <thib@sitedethib.com>
parents: 27
diff changeset
143 vertmat.translate(width / 2., height / 2., 0.)
71
a03d7a94b997 Add support for a few ANM instructions
Thibaut Girka <thib@sitedethib.com>
parents: 69
diff changeset
144 if self.allow_dest_offset:
a03d7a94b997 Add support for a few ANM instructions
Thibaut Girka <thib@sitedethib.com>
parents: 69
diff changeset
145 vertmat.translate(*self.dest_offset)
15
07fba4e1da65 Refactor
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
146
30
e3ba2fa966f6 Various optimizations
Thibaut Girka <thib@sitedethib.com>
parents: 29
diff changeset
147 x_1 = 1. / self.anm.size[0]
e3ba2fa966f6 Various optimizations
Thibaut Girka <thib@sitedethib.com>
parents: 29
diff changeset
148 y_1 = 1. / self.anm.size[1]
41
93c8dc2de923 Add (hopefully) "texture shifting" in animations
Thibaut Girka <thib@sitedethib.com>
parents: 38
diff changeset
149 tox, toy = self.texoffsets
93c8dc2de923 Add (hopefully) "texture shifting" in animations
Thibaut Girka <thib@sitedethib.com>
parents: 38
diff changeset
150 uvs = [(tx * x_1 + tox, 1. - (ty * y_1) + toy),
93c8dc2de923 Add (hopefully) "texture shifting" in animations
Thibaut Girka <thib@sitedethib.com>
parents: 38
diff changeset
151 ((tx + tw) * x_1 + tox, 1. - (ty * y_1) + toy),
93c8dc2de923 Add (hopefully) "texture shifting" in animations
Thibaut Girka <thib@sitedethib.com>
parents: 38
diff changeset
152 ((tx + tw) * x_1 + tox, 1. - ((ty + th) * y_1 + toy)),
93c8dc2de923 Add (hopefully) "texture shifting" in animations
Thibaut Girka <thib@sitedethib.com>
parents: 38
diff changeset
153 (tx * x_1 + tox, 1. - ((ty + th) * y_1 + toy))]
15
07fba4e1da65 Refactor
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
154
30
e3ba2fa966f6 Various optimizations
Thibaut Girka <thib@sitedethib.com>
parents: 29
diff changeset
155 d = vertmat.data
e3ba2fa966f6 Various optimizations
Thibaut Girka <thib@sitedethib.com>
parents: 29
diff changeset
156 assert (d[3][0], d[3][1], d[3][2], d[3][3]) == (1., 1., 1., 1.)
57
694f25881d0f Fix move_to interpolation, add support for a few ANM and ECL instructions
Thibaut Girka <thib@sitedethib.com>
parents: 54
diff changeset
157 self._colors = [(self.color[0], self.color[1], self.color[2], self.alpha)] * 4
30
e3ba2fa966f6 Various optimizations
Thibaut Girka <thib@sitedethib.com>
parents: 29
diff changeset
158 self._uvs, self._vertices = uvs, zip(d[0], d[1], d[2])
90
630e9045e851 Minor refactoring
Thibaut Girka <thib@sitedethib.com>
parents: 85
diff changeset
159 self._changed = False
85
3804f07d3b0e Various optimizations
Thibaut Girka <thib@sitedethib.com>
parents: 81
diff changeset
160
15
07fba4e1da65 Refactor
Thibaut Girka <thib@sitedethib.com>
parents:
diff changeset
161
90
630e9045e851 Minor refactoring
Thibaut Girka <thib@sitedethib.com>
parents: 85
diff changeset
162 def update(self, override_width=0, override_height=0, angle_base=0., force_rotation=False):
630e9045e851 Minor refactoring
Thibaut Girka <thib@sitedethib.com>
parents: 85
diff changeset
163 self._changed = (self._changed
630e9045e851 Minor refactoring
Thibaut Girka <thib@sitedethib.com>
parents: 85
diff changeset
164 or override_width != self.width_override
630e9045e851 Minor refactoring
Thibaut Girka <thib@sitedethib.com>
parents: 85
diff changeset
165 or override_height != self.height_override
630e9045e851 Minor refactoring
Thibaut Girka <thib@sitedethib.com>
parents: 85
diff changeset
166 or self.angle != angle_base
630e9045e851 Minor refactoring
Thibaut Girka <thib@sitedethib.com>
parents: 85
diff changeset
167 or self.force_rotation != force_rotation
630e9045e851 Minor refactoring
Thibaut Girka <thib@sitedethib.com>
parents: 85
diff changeset
168 or self.scale_interpolator
630e9045e851 Minor refactoring
Thibaut Girka <thib@sitedethib.com>
parents: 85
diff changeset
169 or self.fade_interpolator
630e9045e851 Minor refactoring
Thibaut Girka <thib@sitedethib.com>
parents: 85
diff changeset
170 or self.offset_interpolator)
630e9045e851 Minor refactoring
Thibaut Girka <thib@sitedethib.com>
parents: 85
diff changeset
171
630e9045e851 Minor refactoring
Thibaut Girka <thib@sitedethib.com>
parents: 85
diff changeset
172 self.width_override = override_width
630e9045e851 Minor refactoring
Thibaut Girka <thib@sitedethib.com>
parents: 85
diff changeset
173 self.height_override = override_height
630e9045e851 Minor refactoring
Thibaut Girka <thib@sitedethib.com>
parents: 85
diff changeset
174 self.angle = angle_base
630e9045e851 Minor refactoring
Thibaut Girka <thib@sitedethib.com>
parents: 85
diff changeset
175 self.force_rotation = force_rotation
630e9045e851 Minor refactoring
Thibaut Girka <thib@sitedethib.com>
parents: 85
diff changeset
176
69
a142e57218a0 Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents: 61
diff changeset
177 if self.rotations_speed_3d != (0., 0., 0.) or self.scale_speed != (0., 0.):
a142e57218a0 Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents: 61
diff changeset
178 ax, ay, az = self.rotations_3d
a142e57218a0 Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents: 61
diff changeset
179 sax, say, saz = self.rotations_speed_3d
a142e57218a0 Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents: 61
diff changeset
180 self.rotations_3d = ax + sax, ay + say, az + saz
a142e57218a0 Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents: 61
diff changeset
181 self.rescale = self.rescale[0] + self.scale_speed[0], self.rescale[1] + self.scale_speed[1]
a142e57218a0 Refactor. Move VMs to pytouhou.vm.
Thibaut Girka <thib@sitedethib.com>
parents: 61
diff changeset
182 self._changed = True
71
a03d7a94b997 Add support for a few ANM instructions
Thibaut Girka <thib@sitedethib.com>
parents: 69
diff changeset
183 self.frame += 1
54
b383b09bc735 Fix anim cycling
Thibaut Girka <thib@sitedethib.com>
parents: 52
diff changeset
184