From d3d34d2aac83bb6a3d53c5e05eb34f7057c6e0d1 Mon Sep 17 00:00:00 2001 From: rubidium Date: Sat, 30 Aug 2008 09:46:52 +0000 Subject: (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. --- src/spritecache.cpp | 48 ++++++++++++++++++++++++++++++------------------ 1 file changed, 30 insertions(+), 18 deletions(-) (limited to 'src/spritecache.cpp') 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; } -- cgit v1.2.3-54-g00ecf