comparison pytouhou/ui/background.pyx @ 223:98c64ffcbdff

Make pytouhou.ui.{background,texture} Cython modules as they are only used by Cython modules.
author Thibaut Girka <thib@sitedethib.com>
date Sun, 18 Dec 2011 21:23:51 +0100
parents pytouhou/ui/background.py@ee6dfd14a785
children c5ba11ede097
comparison
equal deleted inserted replaced
222:5cac48b328ad 223:98c64ffcbdff
1 # -*- encoding: utf-8 -*-
2 ##
3 ## Copyright (C) 2011 Thibaut Girka <thib@sitedethib.com>
4 ##
5 ## This program is free software; you can redistribute it and/or modify
6 ## it under the terms of the GNU General Public License as published
7 ## by the Free Software Foundation; version 3 only.
8 ##
9 ## This program is distributed in the hope that it will be useful,
10 ## but WITHOUT ANY WARRANTY; without even the implied warranty of
11 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 ## GNU General Public License for more details.
13 ##
14
15 #TODO: lots of things
16
17 from struct import pack
18 from itertools import chain
19
20 from .sprite cimport get_sprite_rendering_data
21
22 cpdef object get_background_rendering_data(object background):
23 cdef float x, y, z, ox, oy, oz, ox2, oy2, oz2
24 cdef list vertices, uvs, colors
25
26 #TODO: do not cache the results, and use view frustum culling
27 try:
28 return background._rendering_data
29 except AttributeError:
30 pass
31
32 vertices = []
33 uvs = []
34 colors = []
35
36 for ox, oy, oz, model_id, model in background.object_instances:
37 for ox2, oy2, oz2, width_override, height_override, sprite in model:
38 #TODO: view frustum culling
39 key, (vertices2, uvs2, colors2) = get_sprite_rendering_data(sprite)
40 vertices.extend([(x + ox + ox2, y + oy + oy2, z + oz + oz2)
41 for x, y, z in vertices2])
42 uvs.extend(uvs2)
43 colors.extend(colors2)
44
45 nb_vertices = len(vertices)
46 vertices_s = pack(str(3 * nb_vertices) + 'f', *chain(*vertices))
47 uvs_s = pack(str(2 * nb_vertices) + 'f', *uvs)
48 colors_s = pack(str(4 * nb_vertices) + 'B', *colors)
49
50 background._rendering_data = [(key, (nb_vertices, vertices_s, uvs_s, colors_s))]
51
52 return background._rendering_data
53