changeset 111:340fcda8e64a

Fix a few, minor things
author Thibaut Girka <thib@sitedethib.com>
date Tue, 06 Sep 2011 21:28:44 +0200
parents 3ac41b966fed
children e544f9a7966d
files pytouhou/formats/anm0.py pytouhou/formats/std.py pytouhou/game/background.py pytouhou/opengl/gamerenderer.py
diffstat 4 files changed, 13 insertions(+), 13 deletions(-) [+]
line wrap: on
line diff
--- a/pytouhou/formats/anm0.py
+++ b/pytouhou/formats/anm0.py
@@ -105,8 +105,8 @@ class Animations(object):
             while True:
                 #TODO
                 instruction_offsets.append(file.tell() - offset)
-                time, opcode, length = unpack('<HBB', file.read(4))
-                data = file.read(length)
+                time, opcode, size = unpack('<HBB', file.read(4))
+                data = file.read(size)
                 if opcode in cls._instructions:
                     args = unpack('<%s' % cls._instructions[opcode][0], data)
                 else:
--- a/pytouhou/formats/std.py
+++ b/pytouhou/formats/std.py
@@ -20,24 +20,24 @@ logger = get_logger(__name__)
 
 
 class Model(object):
-    def __init__(self):
+    def __init__(self, unknown=0, bounding_box=None, quads=None):
         self.unknown = 0
-        self.bounding_box = (0., 0., 0.,
-                             0., 0., 0.)
-        self.quads = []
+        self.bounding_box = bounding_box or (0., 0., 0.,
+                                             0., 0., 0.)
+        self.quads = quads or []
 
 
 
 class Stage(object):
     _instructions = {0: ('fff', 'set_viewpos'),
-                     1: ('BBBBff', 'set_fog'),
+                     1: ('BBBxff', 'set_fog'),
                      2: ('fff', 'set_viewpos2'),
                      3: ('III', 'start_interpolating_viewpos2'),
                      4: ('III', 'start_interpolating_fog')}
 
     def __init__(self):
         self.name = ''
-        self.bgms = (('', ''), ('', ''), ('', ''))
+        self.bgms = (('', ''), ('', ''), ('', ''), ('', ''))
         self.models = []
         self.object_instances = []
         self.script = []
@@ -70,6 +70,7 @@ class Stage(object):
         offsets = unpack('<%s' % ('I' * nb_models), file.read(4 * nb_models))
         for offset in offsets:
             model = Model()
+            file.seek(offset)
             id_, unknown, x, y, z, width, height, depth = unpack('<HHffffff', file.read(28))
             model.unknown = unknown
             model.bounding_box = x, y, z, width, height, depth #TODO: check
--- a/pytouhou/game/background.py
+++ b/pytouhou/game/background.py
@@ -39,10 +39,10 @@ class Background(object):
         self.object_instances = []
         for model_id, ox, oy, oz in self.stage.object_instances:
             self.object_instances.append((ox, oy, oz, model_id, self.models[model_id]))
-        # Z-sorting
+        # Z-sorting:
+        # TODO z-sorting may be needed at each iteration
         def keyfunc(obj):
-            bounding_box = self.stage.models[obj[3]].bounding_box
-            return obj[2] + min(bounding_box[2], bounding_box[5])
+            return obj[2] + self.stage.models[obj[3]].bounding_box[2]
         self.object_instances.sort(key=keyfunc, reverse=True)
 
 
@@ -51,7 +51,6 @@ class Background(object):
         for obj in self.stage.models:
             quads = []
             for script_index, ox, oy, oz, width_override, height_override in obj.quads:
-                #TODO: per-texture rendering
                 sprite = Sprite()
                 anm_runner = ANMRunner(self.anm_wrapper, script_index, sprite)
                 anm_runner.run_frame()
--- a/pytouhou/opengl/gamerenderer.py
+++ b/pytouhou/opengl/gamerenderer.py
@@ -92,7 +92,7 @@ class GameRenderer(object):
         texture_manager = self.texture_manager
 
         if back is not None:
-            fog_b, fog_g, fog_r, _, fog_start, fog_end = back.fog_interpolator.values
+            fog_b, fog_g, fog_r, fog_start, fog_end = back.fog_interpolator.values
             x, y, z = back.position_interpolator.values
             dx, dy, dz = back.position2_interpolator.values