Просмотр исходного кода

PC tiles now have correct UV's, depth is hardcoded to 999 as its not clear how this value should be scaled down

Paul 11 лет назад
Родитель
Сommit
1c7b7f085c

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

@@ -85,6 +85,7 @@ namespace QGears
 
 
         typedef std::vector<SpriteData> SpriteList;
+        typedef std::vector<SpriteData*> SpritePtrList;
 
         struct Layer
         {
@@ -118,9 +119,9 @@ namespace QGears
         std::array<uint8, PALETTE_ENTRY_COUNT>& getPalette(void) { return m_palette; }
         std::array<Page, PAGE_COUNT>&  getPages(void) { return m_pages; }
 
-        virtual Ogre::Image*        createImage     ( const PaletteFilePtr &palette ) const;
+        Ogre::Image*        createImage     ( const PaletteFilePtr &palette );
 
-        virtual void addAllSprites( SpriteList& sprites ) const;
+        void addAllSprites( SpritePtrList& sprites ) ;
 
     protected:
         virtual void loadImpl();

+ 35 - 24
QGearsMain/src/data/QGearsBackgroundFile.cpp

@@ -126,23 +126,27 @@ namespace QGears
 
     //---------------------------------------------------------------------
     void
-    BackgroundFile::addAllSprites( SpriteList& sprites ) const
+        BackgroundFile::addAllSprites(SpritePtrList& sprites)
     {
         for( size_t i(0); i < LAYER_COUNT; ++i )
         {
             if( m_layers[i].enabled )
             {
-                sprites.insert( sprites.end(), m_layers[i].sprites.begin(), m_layers[i].sprites.end() );
+                for (auto& it : m_layers[i].sprites)
+                {
+                    SpriteData* ptr = &it;
+                    sprites.push_back(ptr);
+                }
             }
         }
     }
 
     //---------------------------------------------------------------------
     Ogre::Image*
-    BackgroundFile::createImage( const PaletteFilePtr &palette ) const
+    BackgroundFile::createImage( const PaletteFilePtr &palette )
     {
         assert( !palette.isNull() );
-        SpriteList sprites;
+        SpritePtrList sprites;
         addAllSprites( sprites );
 
         size_t sprite_count( sprites.size() );
@@ -160,16 +164,19 @@ namespace QGears
         Ogre::LogManager::getSingleton().stream()
             << "Image Size: " << width << " x " << height
             << " sprite_count " << sprite_count;
-        size_t dst_x(0), dst_y(0),
+        int dst_x(0), dst_y(0),
                 dst_x_16(0), dst_y_16(0),
                 dst_x_32(0), dst_y_32(0);
-        size_t dst_n_16(0);
-        for( SpriteList::const_iterator it( sprites.begin() )
-            ;it != sprites.end()
+        int dst_n_16(0);
+
+        for (auto it(sprites.begin())
+            ; it != sprites.end()
             ;++it)
         {
-            const Page& data_page( m_pages[it->data_page] );
-            const Pixel& src(it->src);
+            SpriteData& sprite = **it;
+
+            const Page& data_page(m_pages[sprite.data_page]);
+            const Pixel& src(sprite.src);
             if (!data_page.enabled)
             {
                 Ogre::LogManager::getSingleton().stream()
@@ -177,7 +184,7 @@ namespace QGears
             }
 
             // Position sprites in 32x32 blocks
-            if (it->width == 32)
+            if (sprite.width == 32)
             {
                 dst_x = dst_x_32;
                 dst_y = dst_y_32;
@@ -189,7 +196,7 @@ namespace QGears
                     dst_x_32 = 0;
                 }
             }
-            else if (it->width == 16)
+            else if (sprite.width == 16)
             {
                 // if we start new 16x16*4 block
                 if (dst_n_16 == 0)
@@ -231,9 +238,9 @@ namespace QGears
 
             if (data_page.value_size == 2)
             {
-                for (uint16 y(it->height); y--;)
+                for (uint16 y((*it)->height); y--;)
                 {
-                    for (uint16 x(it->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())
@@ -256,26 +263,24 @@ namespace QGears
             }
             else if (data_page.value_size == 1)
             {
-                if (it->palette_page >= palette->getPages().size())
+                if (sprite.palette_page >= palette->getPages().size())
                 {
-                    Ogre::LogManager::getSingleton().stream()
-                        << "Error: palette page Index out of Bounds " << it->palette_page;
+                    Ogre::LogManager::getSingleton().stream() << "Error: palette page Index out of Bounds " << sprite.palette_page;
                 }
-                const PaletteFile::Page& palette_page(palette->getPage(it->palette_page));
+                const PaletteFile::Page& palette_page(palette->getPage(sprite.palette_page));
                 bool firstColorHidden(false);
-                if (it->palette_page < PALETTE_ENTRY_COUNT) 
+                if (sprite.palette_page < PALETTE_ENTRY_COUNT)
                 {
-                    firstColorHidden = m_palette[it->palette_page] > 0;
+                    firstColorHidden = m_palette[sprite.palette_page] > 0;
                 }
-                for (uint16 y(it->height); y--;)
+                for (uint16 y(sprite.height); y--;)
                 {
-                    for (uint16 x(it->width); x--;)
+                    for (uint16 x(sprite.width); x--;)
                     {
                         size_t data_index((src.y + y) * PAGE_DATA_WIDTH + src.x + x);
                         if (data_index >= data_page.data.size())
                         {
-                            Ogre::LogManager::getSingleton().stream()
-                                << "Error: data page Index out of Bounds " << data_index;
+                            Ogre::LogManager::getSingleton().stream() << "Error: data page Index out of Bounds " << data_index;
                         }
                         uint8 index(data_page.data.at(data_index));
                         if (index >= palette_page.size())
@@ -308,7 +313,13 @@ namespace QGears
                         color[data_index] = colour.getAsARGB();
                     }
                 }
+                
             }
+
+            // Source in the texture atlas is where we just copied it to
+            sprite.src.x = dst_x;
+            sprite.src.y = dst_y;
+
         }
 
         Ogre::DataStreamPtr stream( buffer );

+ 4 - 4
QGearsMain/src/data/QGearsFLevelBackground2DLoader.cpp

@@ -67,18 +67,18 @@ namespace QGears
 
         TileList& tiles( background_2d->getTiles() );
         BackgroundFilePtr background( m_flevel_file.getBackground() );
-        SpriteList sprites;
+        BackgroundFile::SpritePtrList sprites;
         background->addAllSprites( sprites );
 
-        SpriteList::const_iterator it    ( sprites.begin() );
-        SpriteList::const_iterator it_end( sprites.end() );
+        auto it    ( sprites.begin() );
+        auto it_end( sprites.end() );
         Ogre::Real step( BackgroundFile::SPRITE_WIDTH / 1024.0 );
         Ogre::Vector4   uv( 0, 0, step, step );
         Ogre::Vector4   col( step, 0, step, 0 );
         Ogre::Vector4   row( 0, step, 0, step );
         while( it != it_end )
         {
-            const SpriteData& sprite( *it );
+            const SpriteData& sprite( **it );
             Tile tile;
             tile.width  = BackgroundFile::SPRITE_WIDTH;
             tile.height = BackgroundFile::SPRITE_HEIGHT;

+ 11 - 13
utilities/q-gears-launcher/src/ff7DataInstaller.cpp

@@ -179,15 +179,14 @@ static void FF7PcFieldToQGearsField(QGears::FLevelFilePtr& field, const std::str
         TiXmlDocument doc;
         std::unique_ptr<TiXmlElement> element(new TiXmlElement("background2d"));
 
-
-
+        // TODO: Write out the required attributes: image, position, orientation, fov, range and clip
         auto& layers = bg->getLayers();
         const QGears::CameraMatrixFilePtr& camMatrix = field->getCameraMatrix();
 
-
-        // TODO: Write out the *_BG.XML data
+        // Write out the *_BG.XML data
         for (auto& layer : layers)
         {
+            // TODO: Should we only output tiles to construct enabled layers?
           //  if (layer.enabled)
             {
                
@@ -203,22 +202,22 @@ static void FF7PcFieldToQGearsField(QGears::FLevelFilePtr& field, const std::str
                     xmlElement->SetAttribute("width", Ogre::StringConverter::toString(sprite.width * 3));
                     xmlElement->SetAttribute("height", Ogre::StringConverter::toString(sprite.height * 3));
 
-                    // Each tile is added to a big texture atlas with hard coded size of 1024x1024
-                    const float u0 = static_cast<float>(sprite.dst.x) / bgImage->getWidth();
-                    const float v0 = static_cast<float>(sprite.dst.y) / bgImage->getHeight();
+                    // Each tile is added to a big texture atlas with hard coded size of 1024x1024, convert UV's to the 0.0f to 1.0f range
+                    const float u0 = static_cast<float>(sprite.src.x) / bgImage->getWidth();
+                    const float v0 = static_cast<float>(sprite.src.y) / bgImage->getHeight();
 
-                    const float u1 = static_cast<float>(sprite.dst.x + sprite.width) / bgImage->getWidth();
-                    const float v1 = static_cast<float>(sprite.dst.y + sprite.height) / bgImage->getHeight();
+                    const float u1 = static_cast<float>(sprite.src.x + sprite.width) / bgImage->getWidth();
+                    const float v1 = static_cast<float>(sprite.src.y + sprite.height) / bgImage->getHeight();
 
                     xmlElement->SetAttribute("uv", 
                         Ogre::StringConverter::toString(u0) + " " + Ogre::StringConverter::toString(v0) + " " +
                         Ogre::StringConverter::toString(u1) + " " + Ogre::StringConverter::toString(v1)
                         );
 
-                    // TODO: Needs converting somehow
-                    xmlElement->SetAttribute("depth", "999"/* Ogre::StringConverter::toString(sprite.depth)*/);
+                    // TODO: Figure out how to scale this value correctly
+                    xmlElement->SetAttribute("depth", "999" /* Ogre::StringConverter::toString(static_cast<float>(sprite.depth) / (4096.0f/10.0f))*/);
 
-                    // TODO: Copied from DatFile::AddTile
+                    // TODO: Copied from DatFile::AddTile - add to common method
                     Ogre::String blending_str = "";
                     if (sprite.blending == 0)
                     {
@@ -240,7 +239,6 @@ static void FF7PcFieldToQGearsField(QGears::FLevelFilePtr& field, const std::str
                     
                     element->LinkEndChild(xmlElement.release());
                 }
-               
             }
         }
         doc.LinkEndChild(element.release());