Преглед изворни кода

Forces width and height SpriteData structure.

myst6re пре 11 година
родитељ
комит
fcce3e9a64

+ 2 - 2
QGearsMain/include/data/QGearsBackgroundFile.h

@@ -68,8 +68,8 @@ namespace QGears
             uint16 unknown_04[2]; // Unused
             Pixel src;
             Pixel src2; // used for special effects pages, when data_page2 != 0, it must be used instead of src
-            uint16 width; // Do not use
-            uint16 height; // Do not use
+            uint16 width;
+            uint16 height;
 
             uint16 palette_page;
             uint16 depth; // <=> Z

+ 1 - 0
QGearsMain/include/data/QGearsBackgroundFileSerializer.h

@@ -99,6 +99,7 @@ namespace QGears
 
     private:
         Header  m_header;
+        size_t m_layer_index;
     };
 }
 

+ 6 - 6
QGearsMain/src/data/QGearsBackgroundFile.cpp

@@ -174,9 +174,9 @@ namespace QGears
             }
             if (data_page.value_size == 2)
             {
-                for (uint16 y(SPRITE_HEIGHT); y--;)
+                for (uint16 y(it->height); y--;)
                 {
-                    for (uint16 x(SPRITE_WIDTH); x--;)
+                    for (uint16 x(it->width); x--;)
                     {
                         size_t data_index((src.y + y) * PAGE_DATA_WIDTH + src.x + x);
                         if (data_index >= data_page.colors.size())
@@ -210,9 +210,9 @@ namespace QGears
                 {
                     firstColorHidden = m_palette[it->palette_page] > 0;
                 }
-                for (uint16 y(SPRITE_HEIGHT); y--;)
+                for (uint16 y(it->height); y--;)
                 {
-                    for (uint16 x(SPRITE_WIDTH); x--;)
+                    for (uint16 x(it->width); x--;)
                     {
                         size_t data_index((src.y + y) * PAGE_DATA_WIDTH + src.x + x);
                         if (data_index >= data_page.data.size())
@@ -253,11 +253,11 @@ namespace QGears
                 }
             }
 
-            dst_x += SPRITE_WIDTH;
+            dst_x += it->width;
             if (dst_x >= width)
             {
                 dst_x = 0;
-                dst_y += SPRITE_HEIGHT;
+                dst_y += it->height;
             }
         }
 

+ 15 - 1
QGearsMain/src/data/QGearsBackgroundFileSerializer.cpp

@@ -41,7 +41,7 @@ namespace QGears
 
     //---------------------------------------------------------------------
     BackgroundFileSerializer::BackgroundFileSerializer() :
-        Serializer()
+        Serializer(), m_layer_index(BackgroundFile::LAYER_COUNT)
     {
     }
 
@@ -150,6 +150,7 @@ namespace QGears
             readShorts( stream, pDest->unknown_0E, 4 );
         }
         stream->skip( 2 * 2 ); // 2 * uint16 unused;
+        m_layer_index = layer_index;
         readVector( stream, pDest->sprites, sprite_count );
     }
 
@@ -164,6 +165,19 @@ namespace QGears
         readShort( stream, pDest.width );
         readShort( stream, pDest.height );
 
+        uint16 size;
+        // width and height are sometimes incorrect in the file
+        if ( m_layer_index < 2 ) {
+            size = 16;
+        } else if ( m_layer_index < BackgroundFile::LAYER_COUNT) {
+            size = 32;
+        } else {
+            OGRE_EXCEPT(Ogre::Exception::ERR_INVALIDPARAMS
+                ,"m_layer_index not set correctly"
+                ,"BackgroundFileSerializer::readObject" );
+        }
+        pDest.width = pDest.height = size;
+
         readShort( stream, pDest.palette_page );
         readShort( stream, pDest.depth );