summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorrubidium <rubidium@openttd.org>2008-08-30 09:46:52 +0000
committerrubidium <rubidium@openttd.org>2008-08-30 09:46:52 +0000
commit951ea4ae6d6e62d7f7a24b34bb859d5b6982f89e (patch)
tree0a942538fcf6d959026cc0ef41b03b81feb28867
parent943031bdaf52a66d7b9b59fce694654ce1450ffd (diff)
downloadopenttd-951ea4ae6d6e62d7f7a24b34bb859d5b6982f89e.tar.xz
(svn r14191) -Codechange: unify the code to skip sprite payload (i.e. not the header).
-Fix: sprite payload skipping wouldn't skip enough bytes in a very small subset of compressed sprites.
-rw-r--r--src/newgrf.cpp18
-rw-r--r--src/sprite.h1
-rw-r--r--src/spritecache.cpp48
3 files changed, 32 insertions, 35 deletions
diff --git a/src/newgrf.cpp b/src/newgrf.cpp
index 1ef2fe87c..b49605b22 100644
--- a/src/newgrf.cpp
+++ b/src/newgrf.cpp
@@ -5935,23 +5935,7 @@ void LoadNewGRFFile(GRFConfig *config, uint file_index, GrfLoadingStage stage)
}
FioSkipBytes(7);
- num -= 8;
-
- if (type & 2) {
- FioSkipBytes(num);
- } else {
- while (num > 0) {
- int8 i = FioReadByte();
- if (i >= 0) {
- num -= i;
- FioSkipBytes(i);
- } else {
- i = -(i >> 3);
- num -= i;
- FioReadByte();
- }
- }
- }
+ SkipSpriteData(type, num - 8);
}
if (_skip_sprites > 0) _skip_sprites--;
diff --git a/src/sprite.h b/src/sprite.h
index b996280d8..26bdb0595 100644
--- a/src/sprite.h
+++ b/src/sprite.h
@@ -56,5 +56,6 @@ struct DrawBuildingsTileStruct {
/** Iterate through all DrawTileSeqStructs in DrawTileSprites. */
#define foreach_draw_tile_seq(idx, list) for (idx = list; ((byte) idx->delta_x) != 0x80; idx++)
+void SkipSpriteData(byte type, uint16 num);
#endif /* SPRITE_H */
diff --git a/src/spritecache.cpp b/src/spritecache.cpp
index 296744ab5..ae331e3ed 100644
--- a/src/spritecache.cpp
+++ b/src/spritecache.cpp
@@ -72,31 +72,20 @@ static int _compact_cache_counter;
static void CompactSpriteCache();
-static bool ReadSpriteHeaderSkipData()
+/**
+ * Skip the given amount of sprite graphics data.
+ * @param type the type of sprite (compressed etc)
+ * @param num the amount of sprites to skip
+ */
+void SkipSpriteData(byte type, uint16 num)
{
- uint16 num = FioReadWord();
- byte type;
-
- if (num == 0) return false;
-
- type = FioReadByte();
- if (type == 0xFF) {
- FioSkipBytes(num);
- /* Some NewGRF files have "empty" pseudo-sprites which are 1
- * byte long. Catch these so the sprites won't be displayed. */
- return num != 1;
- }
-
- FioSkipBytes(7);
- num -= 8;
- if (num == 0) return true;
-
if (type & 2) {
FioSkipBytes(num);
} else {
while (num > 0) {
int8 i = FioReadByte();
if (i >= 0) {
+ i = (i == 0) ? 0x80 : i;
num -= i;
FioSkipBytes(i);
} else {
@@ -106,6 +95,29 @@ static bool ReadSpriteHeaderSkipData()
}
}
}
+}
+
+/**
+ * Read the sprite header data and then skip the real payload.
+ * @return true if the sprite is a pseudo sprite.
+ */
+static bool ReadSpriteHeaderSkipData()
+{
+ uint16 num = FioReadWord();
+ byte type;
+
+ if (num == 0) return false;
+
+ type = FioReadByte();
+ if (type == 0xFF) {
+ FioSkipBytes(num);
+ /* Some NewGRF files have "empty" pseudo-sprites which are 1
+ * byte long. Catch these so the sprites won't be displayed. */
+ return num != 1;
+ }
+
+ FioSkipBytes(7);
+ SkipSpriteData(type, num - 8);
return true;
}