Procházet zdrojové kódy

Removing sprites with buggy destination

myst6re před 11 roky
rodič
revize
51e30470b2

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

@@ -47,6 +47,7 @@ namespace QGears
            ,BIT_MASK_BLUE   = 0x001F
            ,BIT_SIZE        = 0x001F
            ,BIT_MASK_RGB    = BIT_MASK_BLUE | BIT_MASK_GREEN | BIT_MASK_RED
+           ,SPRITE_DST_MAX      = 1024
         };
 
         struct Header
@@ -98,6 +99,8 @@ namespace QGears
         static const Ogre::Real src_big_SCALE;
 
     private:
+        void removeBuggySprites( SpriteList &sprites );
+
         Header  m_header;
         size_t m_layer_index;
     };

+ 23 - 0
QGearsMain/src/data/QGearsBackgroundFileSerializer.cpp

@@ -152,6 +152,29 @@ namespace QGears
         stream->skip( 2 * 2 ); // 2 * uint16 unused;
         m_layer_index = layer_index;
         readVector( stream, pDest->sprites, sprite_count );
+
+        removeBuggySprites( pDest->sprites );
+    }
+
+    //---------------------------------------------------------------------
+    void
+    BackgroundFileSerializer::removeBuggySprites( SpriteList &sprites )
+    {
+        auto it = sprites.begin();
+        while (it != sprites.end())
+        {
+            const SpriteData &sprite = (*it);
+
+            if (std::abs(sprite.dst.x) > SPRITE_DST_MAX
+                    || std::abs(sprite.dst.y) > SPRITE_DST_MAX)
+            {
+                it = sprites.erase(it);
+            }
+            else
+            {
+                ++it;
+            }
+        }
     }
 
     //---------------------------------------------------------------------