# HG changeset patch # User Emmanuel Gil Peyrot # Date 1387387148 -3600 # Node ID db28538cd399102cf0202cfc956fb58873893209 # Parent 0b2a92a25245aad9fed3c32fb243df31c960230e Use Sprite C arrays instead of their tuple representation where it makes sense. diff --git a/pytouhou/game/bullet.pyx b/pytouhou/game/bullet.pyx --- a/pytouhou/game/bullet.pyx +++ b/pytouhou/game/bullet.pyx @@ -80,9 +80,7 @@ cdef class Bullet(Element): cdef bint is_visible(self, unsigned int screen_width, unsigned int screen_height): - cdef double tw, th - - tw, th = self.sprite.texcoords[2:] + tw, th = self.sprite._texcoords[2], self.sprite._texcoords[3] x, y = self.x, self.y max_x = tw / 2 diff --git a/pytouhou/game/enemy.pyx b/pytouhou/game/enemy.pyx --- a/pytouhou/game/enemy.pyx +++ b/pytouhou/game/enemy.pyx @@ -310,14 +310,12 @@ cdef class Enemy(Element): cdef bint is_visible(self, long screen_width, long screen_height): - cdef double tw, th - if self.sprite is not None: if self.sprite.corner_relative_placement: raise Exception #TODO - _, _, tw, th = self.sprite.texcoords + tw, th = self.sprite._texcoords[2], self.sprite._texcoords[3] else: - tw, th = 0, 0 + tw, th = 0., 0. x, y = self.x, self.y max_x = tw / 2 diff --git a/pytouhou/game/item.pyx b/pytouhou/game/item.pyx --- a/pytouhou/game/item.pyx +++ b/pytouhou/game/item.pyx @@ -23,7 +23,7 @@ cdef class Indicator(Element): self.sprite = item._item_type.indicator_sprite.copy() self.x = self._item.x - self.y = self.sprite.texcoords[2] / 2. + self.y = self.sprite._texcoords[3] / 2. cdef void update(self) nogil: @@ -185,7 +185,7 @@ cdef class Item(Element): self.x += dx self.y += dy - offscreen = self.y < -(self.sprite.texcoords[2] / 2.) + offscreen = self.y < -self.sprite._texcoords[3] / 2. if offscreen: if self.indicator is None: self.indicator = Indicator(self) diff --git a/pytouhou/game/laser.pyx b/pytouhou/game/laser.pyx --- a/pytouhou/game/laser.pyx +++ b/pytouhou/game/laser.pyx @@ -39,7 +39,7 @@ cdef class LaserLaunchAnim(Element): self.y = laser.base_pos[1] + offset * dy scale = laser.width / 10. - (offset - laser.start_offset) #TODO: check - self.sprite.rescale = (scale, scale) + self.sprite._rescale[:] = [scale, scale] self.sprite.changed = True if laser.removed or scale <= 0.: diff --git a/pytouhou/game/player.pyx b/pytouhou/game/player.pyx --- a/pytouhou/game/player.pyx +++ b/pytouhou/game/player.pyx @@ -208,10 +208,12 @@ cdef class Player(Element): m = self.invulnerable_time % 8 if m == 7 or self.invulnerable_time == 0: - self.sprite.color = (255, 255, 255) + for i in xrange(3): + self.sprite._color[i] = 255 self.sprite.changed = True elif m == 1: - self.sprite.color = (64, 64, 64) + for i in xrange(3): + self.sprite._color[i] = 64 self.sprite.changed = True if keystate & 1 and self.fire_time == 0: @@ -280,7 +282,7 @@ cdef class Player(Element): elif time == 7: self.sprite.mirrored = False self.sprite.blendfunc = 0 - self.sprite.rescale = 0.75, 1.5 + self.sprite._rescale[:] = [0.75, 1.5] self.sprite.fade(26, 96) self.sprite.scale_in(26, 0., 2.5) @@ -295,8 +297,8 @@ cdef class Player(Element): self.sprite = Sprite() self.anmrunner = ANMRunner(self.anm, 0, self.sprite) - self.sprite.alpha = 128 - self.sprite.rescale = 0., 2.5 + self.sprite._color[3] = 128 + self.sprite._rescale[:] = [0., 2.5] self.sprite.fade(30, 255) self.sprite.blendfunc = 1 self.sprite.scale_in(30, 1., 1.) diff --git a/pytouhou/ui/opengl/sprite.pyx b/pytouhou/ui/opengl/sprite.pyx --- a/pytouhou/ui/opengl/sprite.pyx +++ b/pytouhou/ui/opengl/sprite.pyx @@ -20,7 +20,6 @@ from .renderer cimport Texture #XXX cpdef tuple get_sprite_rendering_data(Sprite sprite): - cdef double tx, ty, tw, th, sx, sy, rx, ry, rz, tox, toy cdef Matrix vertmat if not sprite.changed: @@ -31,8 +30,8 @@ cpdef tuple get_sprite_rendering_data(Sp 0, 0, 0, 0, 1, 1, 1, 1) - tx, ty, tw, th = sprite.texcoords - sx, sy = sprite.rescale + tx, ty, tw, th = sprite._texcoords[0], sprite._texcoords[1], sprite._texcoords[2], sprite._texcoords[3] + sx, sy = sprite._rescale[0], sprite._rescale[1] width = sprite.width_override or (tw * sx) height = sprite.height_override or (th * sy) @@ -40,7 +39,7 @@ cpdef tuple get_sprite_rendering_data(Sp if sprite.mirrored: flip(&vertmat) - rx, ry, rz = sprite.rotations_3d + rx, ry, rz = sprite._rotations_3d[0], sprite._rotations_3d[1], sprite._rotations_3d[2] if sprite.automatic_orientation: rz += pi/2. - sprite.angle elif sprite.force_rotation: @@ -53,21 +52,22 @@ cpdef tuple get_sprite_rendering_data(Sp if rz: rotate_z(&vertmat, -rz) #TODO: minus, really? if sprite.allow_dest_offset: - translate(&vertmat, sprite.dest_offset[0], sprite.dest_offset[1], sprite.dest_offset[2]) + translate(&vertmat, sprite._dest_offset) if sprite.corner_relative_placement: # Reposition translate2d(&vertmat, width / 2, height / 2) x_1 = sprite.anm.size_inv[0] y_1 = sprite.anm.size_inv[1] - tox, toy = sprite.texoffsets + tox, toy = sprite._texoffsets[0], sprite._texoffsets[1] uvs = (tx * x_1 + tox, (tx + tw) * x_1 + tox, ty * y_1 + toy, (ty + th) * y_1 + toy) + r, g, b, a = sprite._color[0], sprite._color[1], sprite._color[2], sprite._color[3] + key = ((sprite.anm.texture).key << 1) | sprite.blendfunc - r, g, b = sprite.color - values = tuple([x for x in (&vertmat)[:12]]), uvs, (r, g, b, sprite.alpha) + values = tuple([x for x in (&vertmat)[:12]]), uvs, (r, g, b, a) sprite._rendering_data = key, values sprite.changed = False diff --git a/pytouhou/ui/sdl/sprite.pyx b/pytouhou/ui/sdl/sprite.pyx --- a/pytouhou/ui/sdl/sprite.pyx +++ b/pytouhou/ui/sdl/sprite.pyx @@ -17,43 +17,42 @@ from libc.math cimport M_PI as pi cpdef tuple get_sprite_rendering_data(Sprite sprite): - cdef double x, y, tx, ty, tw, th, sx, sy, rz, tox, toy - if not sprite.changed: return sprite._rendering_data x = 0 y = 0 - tx, ty, tw, th = sprite.texcoords - sx, sy = sprite.rescale + tx, ty, tw, th = sprite._texcoords[0], sprite._texcoords[1], sprite._texcoords[2], sprite._texcoords[3] + sx, sy = sprite._rescale[0], sprite._rescale[1] width = sprite.width_override or (tw * sx) height = sprite.height_override or (th * sy) - rz = sprite.rotations_3d[2] + rz = sprite._rotations_3d[2] if sprite.automatic_orientation: rz += pi/2. - sprite.angle elif sprite.force_rotation: rz += sprite.angle if sprite.allow_dest_offset: - x += sprite.dest_offset[0] - y += sprite.dest_offset[1] + x += sprite._dest_offset[0] + y += sprite._dest_offset[1] if not sprite.corner_relative_placement: # Reposition x -= width / 2 y -= height / 2 x_1 = sprite.anm.size_inv[0] y_1 = sprite.anm.size_inv[1] - tox, toy = sprite.texoffsets + tox, toy = sprite._texoffsets[0], sprite._texoffsets[1] uvs = (tx * x_1 + tox, (tx + tw) * x_1 + tox, ty * y_1 + toy, (ty + th) * y_1 + toy) + r, g, b, a = sprite._color[0], sprite._color[1], sprite._color[2], sprite._color[3] + key = sprite.blendfunc - r, g, b = sprite.color - values = (x, y, width, height), uvs, (r, g, b, sprite.alpha), -rz * 180 / pi, sprite.mirrored + values = (x, y, width, height), uvs, (r, g, b, a), -rz * 180 / pi, sprite.mirrored sprite._rendering_data = key, values sprite.changed = False diff --git a/pytouhou/utils/matrix.pxd b/pytouhou/utils/matrix.pxd --- a/pytouhou/utils/matrix.pxd +++ b/pytouhou/utils/matrix.pxd @@ -11,7 +11,7 @@ cdef void mul(Matrix *mat1, Matrix *mat2 cdef void flip(Matrix *mat) nogil cdef void scale(Matrix *mat, float x, float y, float z) nogil cdef void scale2d(Matrix *mat, float x, float y) nogil -cdef void translate(Matrix *mat, float x, float y, float z) nogil +cdef void translate(Matrix *mat, float[3] offset) nogil cdef void translate2d(Matrix *mat, float x, float y) nogil cdef void rotate_x(Matrix *mat, float angle) nogil cdef void rotate_y(Matrix *mat, float angle) nogil diff --git a/pytouhou/utils/matrix.pyx b/pytouhou/utils/matrix.pyx --- a/pytouhou/utils/matrix.pyx +++ b/pytouhou/utils/matrix.pyx @@ -76,12 +76,8 @@ cdef void scale2d(Matrix *mat, float x, data[4+i] *= y -cdef void translate(Matrix *mat, float x, float y, float z) nogil: - cdef float offset[3], item[3] - - offset[0] = x - offset[1] = y - offset[2] = z +cdef void translate(Matrix *mat, float[3] offset) nogil: + cdef float item[3] data = mat for i in xrange(3): @@ -93,7 +89,13 @@ cdef void translate(Matrix *mat, float x cdef void translate2d(Matrix *mat, float x, float y) nogil: - translate(mat, x, y, 0) + cdef float[3] offset + + offset[0] = x + offset[1] = y + offset[2] = 0 + + translate(mat, offset) cdef void rotate_x(Matrix *mat, float angle) nogil: