Explorar o código

Implementing depth=2 backgrounds

myst6re %!s(int64=11) %!d(string=hai) anos
pai
achega
82fc35db83

+ 4 - 3
QGearsMain/include/data/QGearsBackgroundFile.h

@@ -93,8 +93,10 @@ namespace QGears
             SpriteList sprites;
         };
 
+        typedef PaletteFile::Color Color;
 
-        typedef std::vector<uint8>  Buffer;
+        typedef std::vector<uint8> Buffer;
+        typedef std::vector<Color> Colors;
 
         struct Page
         {
@@ -104,10 +106,9 @@ namespace QGears
             // uint8 if value_size == 1, uint16 if value_size == 2
             //uint8 data[PAGE_DATA_WIDTH][PAGE_DATA_HEIGHT];
             Buffer data;
+            Colors colors;
         };
 
-        typedef PaletteFile::Color Color;
-
         virtual Layer* getLayers ( void ) { return m_layers;  }
         virtual uint8* getPalette( void ) { return m_palette; }
         virtual Page*  getPages  ( void ) { return m_pages;   }

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

@@ -41,6 +41,14 @@ namespace QGears
 
         virtual void    importBackgroundFile( Ogre::DataStreamPtr &stream, BackgroundFile *pDest );
 
+        enum {
+            BIT_MASK_RED    = 0xF800
+           ,BIT_MASK_GREEN  = 0x07C0
+           ,BIT_MASK_BLUE   = 0x001F
+           ,BIT_SIZE        = 0x001F
+           ,BIT_MASK_RGB    = BIT_MASK_BLUE | BIT_MASK_GREEN | BIT_MASK_RED
+        };
+
         struct Header
         {
             uint16 unused;

+ 36 - 18
QGearsMain/src/data/QGearsBackgroundFile.cpp

@@ -158,22 +158,40 @@ namespace QGears
             ;++it)
         {
             const Page& data_page( m_pages[it->data_page] );
-            if (data_page.value_size == 2)
+            const Pixel& src(it->src);
+            if (!data_page.enabled)
             {
-                // TODO FIX ME
                 Ogre::LogManager::getSingleton().stream()
-                    << "Error: value_size(RGB16) not implemented";
-                break;
+                    << "Error: referencing an disabled data page";
             }
-            else if (data_page.value_size == 1)
+            if (data_page.value_size == 2)
             {
-                const PaletteFile::Page& palette_page(palette->getPage(it->palette_page));
-                const Pixel& src(it->src);
-                if (!data_page.enabled)
+                for (uint16 y(SPRITE_HEIGHT); y--;)
                 {
-                    Ogre::LogManager::getSingleton().stream()
-                        << "Error: referencing an disabled data page";
+                    for (uint16 x(SPRITE_WIDTH); x--;)
+                    {
+                        size_t data_index((src.y + y) * PAGE_DATA_WIDTH + src.x + x);
+                        if (data_index >= data_page.colors.size())
+                        {
+                            Ogre::LogManager::getSingleton().stream()
+                                << "Error: data page Index out of Bounds " << data_index;
+                        }
+
+                        Color colour(data_page.colors.at(data_index));
+                        data_index = (dst_y + y) * row_pitch + dst_x + x;
+                        if (data_index >= pixel_count)
+                        {
+                            Ogre::LogManager::getSingleton().stream()
+                                << "Error: writing Pixel out of Bounds " << data_index
+                                << " " << (dst_x + x) << " x " << dst_y + y;
+                        }
+                        color[data_index] = colour.getAsARGB();
+                    }
                 }
+            }
+            else if (data_page.value_size == 1)
+            {
+                const PaletteFile::Page& palette_page(palette->getPage(it->palette_page));
                 for (uint16 y(SPRITE_HEIGHT); y--;)
                 {
                     for (uint16 x(SPRITE_WIDTH); x--;)
@@ -198,8 +216,8 @@ namespace QGears
                                 << "Error: writing Pixel out of Bounds " << data_index
                                 << " " << (dst_x + x) << " x " << dst_y + y;
                         }
-                        Ogre::ColourValue colour(palette_page[index]);
-                        if (index == 0 && colour != Ogre::ColourValue::Black)
+                        Color colour(palette_page[index]);
+                        if (index == 0 && colour != Color::Black)
                         {
                             colour.a = 0;
                         }
@@ -210,13 +228,13 @@ namespace QGears
                         color[data_index] = colour.getAsARGB();
                     }
                 }
+            }
 
-                dst_x += SPRITE_WIDTH;
-                if (dst_x >= width)
-                {
-                    dst_x = 0;
-                    dst_y += SPRITE_HEIGHT;
-                }
+            dst_x += SPRITE_WIDTH;
+            if (dst_x >= width)
+            {
+                dst_x = 0;
+                dst_y += SPRITE_HEIGHT;
             }
         }
 

+ 27 - 7
QGearsMain/src/data/QGearsBackgroundFileSerializer.cpp

@@ -24,6 +24,7 @@ THE SOFTWARE.
 -----------------------------------------------------------------------------
 */
 #include "data/QGearsBackgroundFileSerializer.h"
+#include "data/QGearsPaletteFileSerializer.h"
 
 #include <OgreException.h>
 #include <OgreLogManager.h>
@@ -211,14 +212,33 @@ namespace QGears
 
         if( pDest.value_size == 2 )
         {
-            Ogre::LogManager::getSingleton().stream()
-                << "Warning: Page value_size == 2 @" << stream->tell();
+            size_t color_count( BackgroundFile::PAGE_DATA_SIZE );
+            pDest.colors.clear();
+            pDest.colors.reserve( color_count );
+            for( size_t i( color_count ); i--; )
+            {
+                uint16 colour;
+                readShort( stream, colour );
+                BackgroundFile::Color colourDest;
+                colourDest.r = static_cast<float>(( colour & BIT_MASK_RED   ) >> 11);
+                colourDest.g = static_cast<float>(( colour & BIT_MASK_GREEN ) >>  6);
+                colourDest.b = static_cast<float>(colour & BIT_MASK_BLUE);
+                colourDest /= BIT_SIZE;
+                colourDest.a = 0.0f;
+                if ( colour == 0 )
+                {
+                    colourDest.a = 1.0f;
+                }
+                pDest.colors.push_back( colourDest );
+            }
+        }
+        else
+        {
+            size_t data_size( pDest.value_size * BackgroundFile::PAGE_DATA_SIZE );
+            pDest.data.clear();
+            pDest.data.resize( data_size );
+            stream->read( &pDest.data[0], data_size );
         }
-
-        size_t data_size( pDest.value_size * BackgroundFile::PAGE_DATA_SIZE );
-        pDest.data.clear();
-        pDest.data.resize( data_size );
-        stream->read( &pDest.data[0], data_size );
     }
 
     //---------------------------------------------------------------------