Mercurial > touhou
changeset 384:690b5faaa0e6
Make rendering of multiple-sprites elements work like single-sprites.
author | Emmanuel Gil Peyrot <linkmauve@linkmauve.fr> |
---|---|
date | Tue, 02 Oct 2012 13:27:05 +0200 |
parents | 0537af9125a7 |
children | d8aab27a2ab2 |
files | pytouhou/game/bullet.pyx pytouhou/game/effect.py pytouhou/game/enemy.py pytouhou/game/face.py pytouhou/game/item.py pytouhou/game/laser.py pytouhou/game/player.py pytouhou/game/text.py pytouhou/games/eosd.py pytouhou/ui/anmrenderer.py pytouhou/ui/gamerenderer.pyx pytouhou/ui/gamerunner.py pytouhou/ui/renderer.pyx |
diffstat | 13 files changed, 37 insertions(+), 20 deletions(-) [+] |
line wrap: on
line diff
--- a/pytouhou/game/bullet.pyx +++ b/pytouhou/game/bullet.pyx @@ -26,7 +26,7 @@ cdef class Bullet(object): cdef public double dx, dy, angle, speed #TODO cdef public object player_bullet, target cdef public object _game, _bullet_type - cdef public object sprite, anmrunner, removed, was_visible + cdef public object sprite, anmrunner, removed, was_visible, objects cdef public object attributes, damage, hitbox_half_size, speed_interpolator, grazed cdef public object x, y #TODO @@ -40,6 +40,7 @@ cdef class Bullet(object): self.anmrunner = None self.removed = False self.was_visible = True + self.objects = [self] if hitbox: self.hitbox_half_size = (hitbox[0] / 2., hitbox[1] / 2.)
--- a/pytouhou/game/effect.py +++ b/pytouhou/game/effect.py @@ -26,6 +26,7 @@ class Effect(object): self.anmrunner = ANMRunner(anm_wrapper, index, self.sprite) self.anmrunner.run_frame() self.removed = False + self.objects = [self] self.x, self.y = pos @@ -48,6 +49,7 @@ class Particle(object): self.sprite = Sprite() self.sprite.anm, self.sprite.texcoords = anm_wrapper.get_sprite(index) self.removed = False + self.objects = [self] self.x, self.y = start_pos self.frame = 0
--- a/pytouhou/game/enemy.py +++ b/pytouhou/game/enemy.py @@ -85,8 +85,9 @@ class Enemy(object): self.aux_anm = 8 * [None] + @property def objects(self): - return [anm for anm in self.aux_anm if anm] + return [self] + [anm for anm in self.aux_anm if anm] def play_sound(self, index):
--- a/pytouhou/game/face.py +++ b/pytouhou/game/face.py @@ -18,7 +18,7 @@ from pytouhou.vm.anmrunner import ANMRun class Face(object): - __slots__ = ('_anm_wrapper', 'sprite', 'anmrunner', 'side', 'x', 'y') + __slots__ = ('_anm_wrapper', 'sprite', 'anmrunner', 'side', 'x', 'y', 'objects') def __init__(self, anm_wrapper, effect, side): self._anm_wrapper = anm_wrapper @@ -27,6 +27,7 @@ class Face(object): self.side = side self.load(0) self.animate(effect) + self.objects = [self] #FIXME: the same as game.effect. self.x = -32
--- a/pytouhou/game/item.py +++ b/pytouhou/game/item.py @@ -154,6 +154,13 @@ class Item(object): self.removed = True + @property + def objects(self): + if self.indicator: + return [self.indicator] + return [self] + + def update(self): if self.frame == 60: self.speed_interpolator = Interpolator((0.,), 60,
--- a/pytouhou/game/laser.py +++ b/pytouhou/game/laser.py @@ -28,6 +28,7 @@ class LaserLaunchAnim(object): self.sprite.anm, self.sprite.texcoords = anm_wrapper.get_sprite(index) self.sprite.blendfunc = 1 self.removed = False + self.objects = [self] self.x, self.y = 0, 0 @@ -65,6 +66,7 @@ class Laser(object): self.sprite = None self.anmrunner = None self.removed = False + self.objects = [self] #TODO: hitbox @@ -201,6 +203,7 @@ class PlayerLaser(object): self.removed = False self._laser_type = laser_type self.origin = origin + self.objects = [self] self.hitbox_half_size = hitbox[0] / 2., hitbox[1] / 2.
--- a/pytouhou/game/player.py +++ b/pytouhou/game/player.py @@ -87,10 +87,6 @@ class Player(object): return self.state.y - def objects(self): - return [] - - def set_anim(self, index): self.sprite = Sprite() self.anmrunner = ANMRunner(self.anm_wrapper, index, self.sprite)
--- a/pytouhou/game/text.py +++ b/pytouhou/game/text.py @@ -66,10 +66,6 @@ class GlyphCollection(Widget): self.ref_sprite.corner_relative_placement = True #TODO: perhaps not right - def objects(self): - return self.glyphes - - def set_length(self, length): current_length = len(self.glyphes) if length > current_length: @@ -99,6 +95,11 @@ class Text(GlyphCollection): self.set_text(text) + @property + def objects(self): + return self.glyphes + [self] + + def set_text(self, text): if text == self.text: return @@ -144,6 +145,11 @@ class Counter(GlyphCollection): self.set_value(value) + @property + def objects(self): + return [self] + self.glyphes + + def set_value(self, value): if value < 0: value = 0 @@ -163,6 +169,7 @@ class Gauge(object): self.anmrunner.run_frame() self.removed = False self.sprite.corner_relative_placement = True #TODO: perhaps not right + self.objects = [self] self.x, self.y = pos self.max_length = max_length
--- a/pytouhou/games/eosd.py +++ b/pytouhou/games/eosd.py @@ -243,8 +243,9 @@ class EoSDPlayer(Player): self.state.focused = False + @property def objects(self): - return self.orbs if self.state.power >= 8 else [] + return [self] + (self.orbs if self.state.power >= 8 else []) def update(self, keystate):
--- a/pytouhou/ui/anmrenderer.py +++ b/pytouhou/ui/anmrenderer.py @@ -49,6 +49,7 @@ class ANMRenderer(pyglet.window.Window, self.force_allow_dest_offset = False self.index_items() self.load(index) + self.objects = [self] self.x = width / 2 self.y = height / 2
--- a/pytouhou/ui/gamerenderer.pyx +++ b/pytouhou/ui/gamerenderer.pyx @@ -122,16 +122,13 @@ cdef class GameRenderer(Renderer): self.game_shader.bind() self.game_shader.uniform_matrixf('mvp', self.game_mvp.get_c_data()) - self.render_elements(chain(*(enemy.objects() for enemy in game.enemies if enemy.visible))) self.render_elements(enemy for enemy in game.enemies if enemy.visible) self.render_elements(game.effects) self.render_elements(chain(game.players_bullets, game.lasers_sprites(), game.players, - game.msg_sprites(), - *(player.objects() for player in game.players))) + game.msg_sprites())) self.render_elements(chain(game.bullets, game.lasers, game.cancelled_bullets, game.items, - (item.indicator for item in game.items if item.indicator), - *(label.objects() for label in game.labels))) + game.labels))
--- a/pytouhou/ui/gamerunner.py +++ b/pytouhou/ui/gamerunner.py @@ -14,7 +14,6 @@ import pyglet import traceback -from itertools import chain from pyglet.gl import (glMatrixMode, glLoadIdentity, glEnable, glDisable, glHint, glEnableClientState, glViewport, glScissor, @@ -223,7 +222,6 @@ class GameRunner(pyglet.window.Window, G self.render_elements(interface.boss_items) self.render_elements(labels) - self.render_elements(chain(*(label.objects() for label in labels))) for label in labels: label.changed = False
--- a/pytouhou/ui/renderer.pyx +++ b/pytouhou/ui/renderer.pyx @@ -15,6 +15,7 @@ from libc.stdlib cimport malloc, free from libc.math cimport tan from math import radians +from itertools import chain import ctypes @@ -54,7 +55,8 @@ cdef class Renderer: indices_by_texture = {} - for element in elements: + objects = chain(*[element.objects for element in elements]) + for element in objects: if nb_vertices >= MAX_ELEMENTS - 4: break