# HG changeset patch # User Thibaut Girka # Date 1324239831 -3600 # Node ID 98c64ffcbdffc13bebff2fb38e7fffa9b40e68eb # Parent 5cac48b328ad2ab519cebcc10777c30df05d3f0d Make pytouhou.ui.{background,texture} Cython modules as they are only used by Cython modules. diff --git a/pytouhou/ui/background.pxd b/pytouhou/ui/background.pxd new file mode 100644 --- /dev/null +++ b/pytouhou/ui/background.pxd @@ -0,0 +1,1 @@ +cpdef object get_background_rendering_data(object background) diff --git a/pytouhou/ui/background.py b/pytouhou/ui/background.pyx rename from pytouhou/ui/background.py rename to pytouhou/ui/background.pyx --- a/pytouhou/ui/background.py +++ b/pytouhou/ui/background.pyx @@ -17,10 +17,13 @@ from struct import pack from itertools import chain -from .sprite import get_sprite_rendering_data +from .sprite cimport get_sprite_rendering_data -def get_background_rendering_data(background): - #TODO +cpdef object get_background_rendering_data(object background): + cdef float x, y, z, ox, oy, oz, ox2, oy2, oz2 + cdef list vertices, uvs, colors + + #TODO: do not cache the results, and use view frustum culling try: return background._rendering_data except AttributeError: @@ -29,18 +32,22 @@ def get_background_rendering_data(backgr vertices = [] uvs = [] colors = [] + for ox, oy, oz, model_id, model in background.object_instances: for ox2, oy2, oz2, width_override, height_override, sprite in model: + #TODO: view frustum culling key, (vertices2, uvs2, colors2) = get_sprite_rendering_data(sprite) - vertices.extend((x + ox + ox2, y + oy + oy2, z + oz + oz2) for x, y, z in vertices2) + vertices.extend([(x + ox + ox2, y + oy + oy2, z + oz + oz2) + for x, y, z in vertices2]) uvs.extend(uvs2) colors.extend(colors2) nb_vertices = len(vertices) - vertices = pack(str(3 * nb_vertices) + 'f', *chain(*vertices)) - uvs = pack(str(2 * nb_vertices) + 'f', *uvs) - colors = pack(str(4 * nb_vertices) + 'B', *colors) + vertices_s = pack(str(3 * nb_vertices) + 'f', *chain(*vertices)) + uvs_s = pack(str(2 * nb_vertices) + 'f', *uvs) + colors_s = pack(str(4 * nb_vertices) + 'B', *colors) - background._rendering_data = [(key, (nb_vertices, vertices, uvs, colors))] + background._rendering_data = [(key, (nb_vertices, vertices_s, uvs_s, colors_s))] return background._rendering_data + diff --git a/pytouhou/ui/gamerenderer.pyx b/pytouhou/ui/gamerenderer.pyx --- a/pytouhou/ui/gamerenderer.pyx +++ b/pytouhou/ui/gamerenderer.pyx @@ -18,7 +18,7 @@ from itertools import chain from pyglet.gl import * from .renderer cimport Renderer -from .background import get_background_rendering_data +from .background cimport get_background_rendering_data diff --git a/pytouhou/ui/renderer.pyx b/pytouhou/ui/renderer.pyx --- a/pytouhou/ui/renderer.pyx +++ b/pytouhou/ui/renderer.pyx @@ -21,7 +21,7 @@ from struct import pack from pyglet.gl import * from .sprite cimport get_sprite_rendering_data -from .texture import TextureManager +from .texture cimport TextureManager MAX_ELEMENTS = 10000 diff --git a/pytouhou/ui/texture.pxd b/pytouhou/ui/texture.pxd new file mode 100644 --- /dev/null +++ b/pytouhou/ui/texture.pxd @@ -0,0 +1,3 @@ +cdef class TextureManager: + cdef public object loader + cdef public dict textures diff --git a/pytouhou/ui/texture.py b/pytouhou/ui/texture.pyx rename from pytouhou/ui/texture.py rename to pytouhou/ui/texture.pyx --- a/pytouhou/ui/texture.py +++ b/pytouhou/ui/texture.pyx @@ -18,7 +18,7 @@ from pyglet.gl import (glTexParameteri, import os -class TextureManager(object): +cdef class TextureManager: def __init__(self, loader=None): self.loader = loader self.textures = {} @@ -54,7 +54,7 @@ class TextureManager(object): alpha_data = alpha_file.get_data('RGB', image_file.width * 3) image_file = pyglet.image.ImageData(image_file.width, image_file.height, 'RGBA', b''.join(data[i*3:i*3+3] + alpha_data[i*3] for i in range(image_file.width * image_file.height))) - #TODO + #TODO: improve perfs somehow texture = image_file.get_texture() diff --git a/pytouhou/utils/matrix.pxd b/pytouhou/utils/matrix.pxd --- a/pytouhou/utils/matrix.pxd +++ b/pytouhou/utils/matrix.pxd @@ -1,5 +1,5 @@ cdef class Matrix: - cdef public data + cdef public list data cpdef flip(Matrix self) cpdef scale(Matrix self, x, y, z)