Mercurial > touhou
annotate pytouhou/utils/interpolator.pyx @ 290:18e4ed141dd8
Display lasers' “launch anim”.
author | Thibaut Girka <thib@sitedethib.com> |
---|---|
date | Wed, 15 Feb 2012 18:37:52 +0100 |
parents | fab7ad2f0d8b |
children | d778db08190f |
rev | line source |
---|---|
52
ab826bc29aa2
Add some documentation, GPLv3 headers, README and COPYING file.
Thibaut Girka <thib@sitedethib.com>
parents:
50
diff
changeset
|
1 # -*- encoding: utf-8 -*- |
ab826bc29aa2
Add some documentation, GPLv3 headers, README and COPYING file.
Thibaut Girka <thib@sitedethib.com>
parents:
50
diff
changeset
|
2 ## |
ab826bc29aa2
Add some documentation, GPLv3 headers, README and COPYING file.
Thibaut Girka <thib@sitedethib.com>
parents:
50
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:
50
diff
changeset
|
4 ## |
ab826bc29aa2
Add some documentation, GPLv3 headers, README and COPYING file.
Thibaut Girka <thib@sitedethib.com>
parents:
50
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:
50
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:
50
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:
50
diff
changeset
|
8 ## |
ab826bc29aa2
Add some documentation, GPLv3 headers, README and COPYING file.
Thibaut Girka <thib@sitedethib.com>
parents:
50
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:
50
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:
50
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:
50
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:
50
diff
changeset
|
13 ## |
ab826bc29aa2
Add some documentation, GPLv3 headers, README and COPYING file.
Thibaut Girka <thib@sitedethib.com>
parents:
50
diff
changeset
|
14 |
ab826bc29aa2
Add some documentation, GPLv3 headers, README and COPYING file.
Thibaut Girka <thib@sitedethib.com>
parents:
50
diff
changeset
|
15 |
13 | 16 class Interpolator(object): |
122
174324a4da51
Add support for launch animations! (Warning: slow :()
Thibaut Girka <thib@sitedethib.com>
parents:
62
diff
changeset
|
17 __slots__ = ('values', 'start_values', 'end_values', 'start_frame', 'end_frame', '_frame', '_formula') |
174324a4da51
Add support for launch animations! (Warning: slow :()
Thibaut Girka <thib@sitedethib.com>
parents:
62
diff
changeset
|
18 def __init__(self, values=(), start_frame=0, end_values=(), end_frame=0, formula=None): |
13 | 19 self.values = tuple(values) |
20 self.start_values = tuple(values) | |
122
174324a4da51
Add support for launch animations! (Warning: slow :()
Thibaut Girka <thib@sitedethib.com>
parents:
62
diff
changeset
|
21 self.end_values = tuple(end_values) |
174324a4da51
Add support for launch animations! (Warning: slow :()
Thibaut Girka <thib@sitedethib.com>
parents:
62
diff
changeset
|
22 self.start_frame = start_frame |
174324a4da51
Add support for launch animations! (Warning: slow :()
Thibaut Girka <thib@sitedethib.com>
parents:
62
diff
changeset
|
23 self.end_frame = end_frame |
50
811cefefb5c8
Fix a few bugs and add support for a few instructions
Thibaut Girka <thib@sitedethib.com>
parents:
20
diff
changeset
|
24 self._frame = 0 |
60
af7914413b89
Enable interpolators to use different formulas
Thibaut Girka <thib@sitedethib.com>
parents:
57
diff
changeset
|
25 self._formula = formula or (lambda x: x) |
13 | 26 |
27 | |
57
694f25881d0f
Fix move_to interpolation, add support for a few ANM and ECL instructions
Thibaut Girka <thib@sitedethib.com>
parents:
52
diff
changeset
|
28 def __nonzero__(self): |
60
af7914413b89
Enable interpolators to use different formulas
Thibaut Girka <thib@sitedethib.com>
parents:
57
diff
changeset
|
29 return self._frame < self.end_frame |
57
694f25881d0f
Fix move_to interpolation, add support for a few ANM and ECL instructions
Thibaut Girka <thib@sitedethib.com>
parents:
52
diff
changeset
|
30 |
694f25881d0f
Fix move_to interpolation, add support for a few ANM and ECL instructions
Thibaut Girka <thib@sitedethib.com>
parents:
52
diff
changeset
|
31 |
13 | 32 def set_interpolation_start(self, frame, values): |
33 self.start_values = tuple(values) | |
34 self.start_frame = frame | |
35 | |
36 | |
37 def set_interpolation_end(self, frame, values): | |
38 self.end_values = tuple(values) | |
39 self.end_frame = frame | |
40 | |
41 | |
42 def set_interpolation_end_frame(self, end_frame): | |
43 self.end_frame = end_frame | |
44 | |
45 | |
46 def set_interpolation_end_values(self, values): | |
47 self.end_values = tuple(values) | |
48 | |
49 | |
50 def update(self, frame): | |
50
811cefefb5c8
Fix a few bugs and add support for a few instructions
Thibaut Girka <thib@sitedethib.com>
parents:
20
diff
changeset
|
51 self._frame = frame |
62
1f591adcea04
Fix animation determination (ins_98 stuff) and some interpolation functions
Thibaut Girka <thib@sitedethib.com>
parents:
60
diff
changeset
|
52 if frame >= self.end_frame - 1: #XXX: skip the last interpolation step |
1f591adcea04
Fix animation determination (ins_98 stuff) and some interpolation functions
Thibaut Girka <thib@sitedethib.com>
parents:
60
diff
changeset
|
53 # This bug is replicated from the original game |
122
174324a4da51
Add support for launch animations! (Warning: slow :()
Thibaut Girka <thib@sitedethib.com>
parents:
62
diff
changeset
|
54 self.values = self.end_values |
174324a4da51
Add support for launch animations! (Warning: slow :()
Thibaut Girka <thib@sitedethib.com>
parents:
62
diff
changeset
|
55 self.start_values = self.end_values |
13 | 56 self.start_frame = frame |
57 else: | |
60
af7914413b89
Enable interpolators to use different formulas
Thibaut Girka <thib@sitedethib.com>
parents:
57
diff
changeset
|
58 coeff = self._formula(float(frame - self.start_frame) / float(self.end_frame - self.start_frame)) |
131
fab7ad2f0d8b
Use Cython, improve performances!
Thibaut Girka <thib@sitedethib.com>
parents:
122
diff
changeset
|
59 self.values = [start_value + coeff * (end_value - start_value) |
fab7ad2f0d8b
Use Cython, improve performances!
Thibaut Girka <thib@sitedethib.com>
parents:
122
diff
changeset
|
60 for (start_value, end_value) in zip(self.start_values, self.end_values)] |
20
6ebf9539c077
Handle more enemies types and movements
Thibaut Girka <thib@sitedethib.com>
parents:
13
diff
changeset
|
61 |