Mercurial > touhou
annotate pytouhou/ui/sprite.pyx @ 507:507d446dc6cf
Divide the damages inflicted by the number of players.
author | Emmanuel Gil Peyrot <linkmauve@linkmauve.fr> |
---|---|
date | Sun, 17 Nov 2013 17:36:47 +0100 |
parents | bfea9e9a6845 |
children | b39ad30c6620 |
rev | line source |
---|---|
108
2a03940deea3
Move everything graphical to pytouhou.opengl!
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
1 # -*- encoding: utf-8 -*- |
2a03940deea3
Move everything graphical to pytouhou.opengl!
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
2 ## |
2a03940deea3
Move everything graphical to pytouhou.opengl!
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
3 ## Copyright (C) 2011 Thibaut Girka <thib@sitedethib.com> |
2a03940deea3
Move everything graphical to pytouhou.opengl!
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
4 ## |
2a03940deea3
Move everything graphical to pytouhou.opengl!
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
5 ## This program is free software; you can redistribute it and/or modify |
2a03940deea3
Move everything graphical to pytouhou.opengl!
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
6 ## it under the terms of the GNU General Public License as published |
2a03940deea3
Move everything graphical to pytouhou.opengl!
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
7 ## by the Free Software Foundation; version 3 only. |
2a03940deea3
Move everything graphical to pytouhou.opengl!
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
8 ## |
2a03940deea3
Move everything graphical to pytouhou.opengl!
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
9 ## This program is distributed in the hope that it will be useful, |
2a03940deea3
Move everything graphical to pytouhou.opengl!
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
10 ## but WITHOUT ANY WARRANTY; without even the implied warranty of |
2a03940deea3
Move everything graphical to pytouhou.opengl!
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
11 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
2a03940deea3
Move everything graphical to pytouhou.opengl!
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
12 ## GNU General Public License for more details. |
2a03940deea3
Move everything graphical to pytouhou.opengl!
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
13 ## |
2a03940deea3
Move everything graphical to pytouhou.opengl!
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
14 |
2a03940deea3
Move everything graphical to pytouhou.opengl!
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
15 |
439
723a3e67a223
Make pytouhou.game.sprite an extension type.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
435
diff
changeset
|
16 from libc.math cimport M_PI as pi |
108
2a03940deea3
Move everything graphical to pytouhou.opengl!
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
17 |
131
fab7ad2f0d8b
Use Cython, improve performances!
Thibaut Girka <thib@sitedethib.com>
parents:
125
diff
changeset
|
18 from pytouhou.utils.matrix cimport Matrix |
505
bfea9e9a6845
Manage the texture-specific indices in the Texture, and some more renderer optimisations.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
449
diff
changeset
|
19 from pytouhou.ui.renderer cimport Texture #XXX |
108
2a03940deea3
Move everything graphical to pytouhou.opengl!
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
20 |
2a03940deea3
Move everything graphical to pytouhou.opengl!
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
21 |
439
723a3e67a223
Make pytouhou.game.sprite an extension type.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
435
diff
changeset
|
22 cpdef object get_sprite_rendering_data(Sprite sprite): |
131
fab7ad2f0d8b
Use Cython, improve performances!
Thibaut Girka <thib@sitedethib.com>
parents:
125
diff
changeset
|
23 cdef Matrix vertmat |
439
723a3e67a223
Make pytouhou.game.sprite an extension type.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
435
diff
changeset
|
24 cdef double tx, ty, tw, th, sx, sy, rx, ry, rz, tox, toy |
723a3e67a223
Make pytouhou.game.sprite an extension type.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
435
diff
changeset
|
25 cdef object tmp1, tmp2 |
131
fab7ad2f0d8b
Use Cython, improve performances!
Thibaut Girka <thib@sitedethib.com>
parents:
125
diff
changeset
|
26 |
304
f3099ebf4f61
Update attribute names to reflect the actual interface.
Thibaut Girka <thib@sitedethib.com>
parents:
279
diff
changeset
|
27 if not sprite.changed: |
108
2a03940deea3
Move everything graphical to pytouhou.opengl!
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
28 return sprite._rendering_data |
2a03940deea3
Move everything graphical to pytouhou.opengl!
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
29 |
439
723a3e67a223
Make pytouhou.game.sprite an extension type.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
435
diff
changeset
|
30 tmp1 = .5 |
723a3e67a223
Make pytouhou.game.sprite an extension type.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
435
diff
changeset
|
31 tmp2 = -.5 |
723a3e67a223
Make pytouhou.game.sprite an extension type.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
435
diff
changeset
|
32 vertmat = Matrix([tmp2, tmp1, tmp1, tmp2, |
723a3e67a223
Make pytouhou.game.sprite an extension type.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
435
diff
changeset
|
33 tmp2, tmp2, tmp1, tmp1, |
723a3e67a223
Make pytouhou.game.sprite an extension type.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
435
diff
changeset
|
34 0, 0, 0, 0, |
723a3e67a223
Make pytouhou.game.sprite an extension type.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
435
diff
changeset
|
35 1, 1, 1, 1]) |
108
2a03940deea3
Move everything graphical to pytouhou.opengl!
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
36 |
2a03940deea3
Move everything graphical to pytouhou.opengl!
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
37 tx, ty, tw, th = sprite.texcoords |
2a03940deea3
Move everything graphical to pytouhou.opengl!
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
38 sx, sy = sprite.rescale |
2a03940deea3
Move everything graphical to pytouhou.opengl!
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
39 width = sprite.width_override or (tw * sx) |
2a03940deea3
Move everything graphical to pytouhou.opengl!
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
40 height = sprite.height_override or (th * sy) |
2a03940deea3
Move everything graphical to pytouhou.opengl!
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
41 |
2a03940deea3
Move everything graphical to pytouhou.opengl!
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
42 vertmat.scale2d(width, height) |
2a03940deea3
Move everything graphical to pytouhou.opengl!
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
43 if sprite.mirrored: |
2a03940deea3
Move everything graphical to pytouhou.opengl!
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
44 vertmat.flip() |
2a03940deea3
Move everything graphical to pytouhou.opengl!
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
45 |
2a03940deea3
Move everything graphical to pytouhou.opengl!
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
46 rx, ry, rz = sprite.rotations_3d |
2a03940deea3
Move everything graphical to pytouhou.opengl!
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
47 if sprite.automatic_orientation: |
2a03940deea3
Move everything graphical to pytouhou.opengl!
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
48 rz += pi/2. - sprite.angle |
2a03940deea3
Move everything graphical to pytouhou.opengl!
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
49 elif sprite.force_rotation: |
2a03940deea3
Move everything graphical to pytouhou.opengl!
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
50 rz += sprite.angle |
2a03940deea3
Move everything graphical to pytouhou.opengl!
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
51 |
439
723a3e67a223
Make pytouhou.game.sprite an extension type.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
435
diff
changeset
|
52 if rx: |
723a3e67a223
Make pytouhou.game.sprite an extension type.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
435
diff
changeset
|
53 vertmat.rotate_x(-rx) |
723a3e67a223
Make pytouhou.game.sprite an extension type.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
435
diff
changeset
|
54 if ry: |
723a3e67a223
Make pytouhou.game.sprite an extension type.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
435
diff
changeset
|
55 vertmat.rotate_y(ry) |
723a3e67a223
Make pytouhou.game.sprite an extension type.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
435
diff
changeset
|
56 if rz: |
723a3e67a223
Make pytouhou.game.sprite an extension type.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
435
diff
changeset
|
57 vertmat.rotate_z(-rz) #TODO: minus, really? |
279
3539520fff93
Fix sprite rotation/translation.
Thibaut Girka <thib@sitedethib.com>
parents:
274
diff
changeset
|
58 if sprite.allow_dest_offset: |
3539520fff93
Fix sprite rotation/translation.
Thibaut Girka <thib@sitedethib.com>
parents:
274
diff
changeset
|
59 vertmat.translate(sprite.dest_offset[0], sprite.dest_offset[1], sprite.dest_offset[2]) |
108
2a03940deea3
Move everything graphical to pytouhou.opengl!
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
60 if sprite.corner_relative_placement: # Reposition |
439
723a3e67a223
Make pytouhou.game.sprite an extension type.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
435
diff
changeset
|
61 vertmat.translate(width / 2, height / 2, 0) |
108
2a03940deea3
Move everything graphical to pytouhou.opengl!
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
62 |
439
723a3e67a223
Make pytouhou.game.sprite an extension type.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
435
diff
changeset
|
63 x_1 = 1 / <double>sprite.anm.size[0] |
723a3e67a223
Make pytouhou.game.sprite an extension type.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
435
diff
changeset
|
64 y_1 = 1 / <double>sprite.anm.size[1] |
108
2a03940deea3
Move everything graphical to pytouhou.opengl!
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
65 tox, toy = sprite.texoffsets |
397
c5ba11ede097
Don’t duplicate values in sprite rendering data.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
393
diff
changeset
|
66 uvs = (tx * x_1 + tox, |
c5ba11ede097
Don’t duplicate values in sprite rendering data.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
393
diff
changeset
|
67 (tx + tw) * x_1 + tox, |
420
3a7b36324611
Replace Pyglet’s image loader with our SDL2_image-based one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
397
diff
changeset
|
68 ty * y_1 + toy, |
3a7b36324611
Replace Pyglet’s image loader with our SDL2_image-based one.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
397
diff
changeset
|
69 (ty + th) * y_1 + toy) |
108
2a03940deea3
Move everything graphical to pytouhou.opengl!
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
70 |
505
bfea9e9a6845
Manage the texture-specific indices in the Texture, and some more renderer optimisations.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
449
diff
changeset
|
71 key = ((<Texture>sprite.anm.texture).texture << 1) | sprite.blendfunc |
125
0313ca2c50e9
Small refactoring and massive performance improvements
Thibaut Girka <thib@sitedethib.com>
parents:
120
diff
changeset
|
72 r, g, b = sprite.color |
435
878273a984c4
Improve Matrix representation, using float[16] instead of imbricated python lists.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
420
diff
changeset
|
73 values = tuple([x for x in vertmat.data[:12]]), uvs, (r, g, b, sprite.alpha) |
108
2a03940deea3
Move everything graphical to pytouhou.opengl!
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
74 sprite._rendering_data = key, values |
304
f3099ebf4f61
Update attribute names to reflect the actual interface.
Thibaut Girka <thib@sitedethib.com>
parents:
279
diff
changeset
|
75 sprite.changed = False |
108
2a03940deea3
Move everything graphical to pytouhou.opengl!
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
76 |
2a03940deea3
Move everything graphical to pytouhou.opengl!
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
77 return sprite._rendering_data |