comparison pytouhou/game/background.py @ 21:bf225780973f

Small refactoring, and Rumia \o/
author Thibaut Girka <thib@sitedethib.com>
date Thu, 11 Aug 2011 12:39:12 +0200
parents d940d004b840
children f17122405121
comparison
equal deleted inserted replaced
20:6ebf9539c077 21:bf225780973f
6 from pytouhou.utils.interpolator import Interpolator 6 from pytouhou.utils.interpolator import Interpolator
7 from pytouhou.game.sprite import Sprite 7 from pytouhou.game.sprite import Sprite
8 8
9 9
10 class Background(object): 10 class Background(object):
11 def __init__(self, stage, anim): 11 def __init__(self, stage, anm_wrapper):
12 self.stage = stage 12 self.stage = stage
13 self.anim = anim 13 self.anm_wrapper = anm_wrapper
14 self.objects = [] 14 self.objects = []
15 self.object_instances = [] 15 self.object_instances = []
16 self.objects_by_texture = {} 16 self.objects_by_texture = {}
17 17
18 self.build_objects() 18 self.build_objects()
47 def build_objects(self): 47 def build_objects(self):
48 self.objects = [] 48 self.objects = []
49 for i, obj in enumerate(self.stage.objects): 49 for i, obj in enumerate(self.stage.objects):
50 faces = [] 50 faces = []
51 for script_index, ox, oy, oz, width_override, height_override in obj.quads: 51 for script_index, ox, oy, oz, width_override, height_override in obj.quads:
52 sprite = Sprite(self.anim, script_index) 52 #TODO: per-texture rendering
53 anm, sprite = self.anm_wrapper.get_sprite(script_index)
53 sprite.update(width_override, height_override) 54 sprite.update(width_override, height_override)
54 uvs, vertices = sprite._uvs, tuple((x + ox, y + oy, z + oz) for x, y, z in sprite._vertices) 55 uvs, vertices = sprite._uvs, tuple((x + ox, y + oy, z + oz) for x, y, z in sprite._vertices)
55 faces.append((vertices, uvs)) 56 faces.append((vertices, uvs))
56 self.objects.append(faces) 57 self.objects.append(faces)
57 58
62 nb_vertices = len(vertices) 63 nb_vertices = len(vertices)
63 vertices_format = 'f' * (3 * nb_vertices) 64 vertices_format = 'f' * (3 * nb_vertices)
64 uvs_format = 'f' * (2 * nb_vertices) 65 uvs_format = 'f' * (2 * nb_vertices)
65 vertices = struct.pack(vertices_format, *chain(*vertices)) 66 vertices = struct.pack(vertices_format, *chain(*vertices))
66 uvs = struct.pack(uvs_format, *chain(*uvs)) 67 uvs = struct.pack(uvs_format, *chain(*uvs))
67 self.objects_by_texture = {(self.anim.first_name, self.anim.secondary_name): (nb_vertices, vertices, uvs)} 68 assert len(self.anm_wrapper.anm_files) == 1 #TODO
69 anm = self.anm_wrapper.anm_files[0]
70 self.objects_by_texture = {(anm.first_name, anm.secondary_name): (nb_vertices, vertices, uvs)}
68 71
69 self.position_interpolator = Interpolator((0, 0, 0)) 72 self.position_interpolator = Interpolator((0, 0, 0))
70 self.fog_interpolator = Interpolator((0, 0, 0, 0, 0)) 73 self.fog_interpolator = Interpolator((0, 0, 0, 0, 0))
71 self.position2_interpolator = Interpolator((0, 0, 0)) 74 self.position2_interpolator = Interpolator((0, 0, 0))
72 75