comparison pytouhou/game/background.py @ 16:66ce9bb440ac

Refactor in order to support multiple textures
author Thibaut Girka <thib@sitedethib.com>
date Sat, 06 Aug 2011 12:36:25 +0200
parents 07fba4e1da65
children d940d004b840
comparison
equal deleted inserted replaced
15:07fba4e1da65 16:66ce9bb440ac
11 def __init__(self, stage, anim): 11 def __init__(self, stage, anim):
12 self.stage = stage 12 self.stage = stage
13 self.anim = anim 13 self.anim = anim
14 self.objects = [] 14 self.objects = []
15 self.object_instances = [] 15 self.object_instances = []
16 self._uvs = b'' 16 self.objects_by_texture = {}
17 self._vertices = b''
18 self.nb_vertices = 0
19 17
20 self.build_objects() 18 self.build_objects()
21 self.build_object_instances() 19 self.build_object_instances()
22 20
23 21
57 faces.append((vertices, uvs)) 55 faces.append((vertices, uvs))
58 self.objects.append(faces) 56 self.objects.append(faces)
59 57
60 58
61 def update(self, frame): 59 def update(self, frame):
62 if not self._uvs or not self._vertices: 60 if not self.objects_by_texture:
63 vertices, uvs = self.object_instances_to_vertices_uvs() 61 vertices, uvs = self.object_instances_to_vertices_uvs()
64 self.nb_vertices = len(vertices) 62 nb_vertices = len(vertices)
65 vertices_format = 'f' * (3 * self.nb_vertices) 63 vertices_format = 'f' * (3 * nb_vertices)
66 uvs_format = 'f' * (2 * self.nb_vertices) 64 uvs_format = 'f' * (2 * nb_vertices)
67 self._vertices = struct.pack(vertices_format, *chain(*vertices)) 65 vertices = struct.pack(vertices_format, *chain(*vertices))
68 self._uvs = struct.pack(uvs_format, *chain(*uvs)) 66 uvs = struct.pack(uvs_format, *chain(*uvs))
67 self.objects_by_texture = {(self.anim.first_name, self.anim.secondary_name): (nb_vertices, vertices, uvs)}
69 68
70 self.position_interpolator = Interpolator((0, 0, 0)) 69 self.position_interpolator = Interpolator((0, 0, 0))
71 self.fog_interpolator = Interpolator((0, 0, 0, 0, 0)) 70 self.fog_interpolator = Interpolator((0, 0, 0, 0, 0))
72 self.position2_interpolator = Interpolator((0, 0, 0)) 71 self.position2_interpolator = Interpolator((0, 0, 0))
73 72