diff options
author | tron <tron@openttd.org> | 2005-08-11 13:09:12 +0000 |
---|---|---|
committer | tron <tron@openttd.org> | 2005-08-11 13:09:12 +0000 |
commit | 14900d3e5367e8ee0460b7780a840fa8705f3130 (patch) | |
tree | 23c9209985d115fa61a2770bcd6e12237885f6d3 | |
parent | 999f18fac8959c83c7fdfc47f6d9d0ce3eea4fa1 (diff) | |
download | openttd-14900d3e5367e8ee0460b7780a840fa8705f3130.tar.xz |
(svn r2855) Make ReadSpriteHeaderSkipData() responsible for detecting the end of a grf file instead of its callers - this simplifies the code a bit
-rw-r--r-- | spritecache.c | 27 |
1 files changed, 11 insertions, 16 deletions
diff --git a/spritecache.c b/spritecache.c index c246a89c1..e30a5e195 100644 --- a/spritecache.c +++ b/spritecache.c @@ -78,11 +78,14 @@ static const SpriteID * const _slopes_spriteindexes[] = { static void CompactSpriteCache(void); -static void ReadSpriteHeaderSkipData(int num, int load_index) +static bool ReadSpriteHeaderSkipData(int load_index) { + uint16 num = FioReadWord(); byte type; int deaf = 0; + if (num == 0) return false; + if (_skip_sprites) { if (_skip_sprites > 0) _skip_sprites--; @@ -102,13 +105,12 @@ static void ReadSpriteHeaderSkipData(int num, int load_index) } else { DecodeSpecialSprite(_cur_grffile, num, load_index, _loading_stage); } - return; + return true; } FioSkipBytes(7); num -= 8; - if (num == 0) - return; + if (num == 0) return true; if (type & 2) { FioSkipBytes(num); @@ -125,6 +127,8 @@ static void ReadSpriteHeaderSkipData(int num, int load_index) } } } + + return true; } static void* AllocSprite(size_t); @@ -195,11 +199,8 @@ static void* ReadSprite(SpriteID id) static bool LoadNextSprite(int load_index, byte file_index) { uint32 file_pos = FioGetPos() | (file_index << 24); - uint16 size = FioReadWord(); - - if (size == 0) return false; - ReadSpriteHeaderSkipData(size, load_index); + if (!ReadSpriteHeaderSkipData(load_index)) return false; if (_replace_sprites_count[0] > 0 && _cur_sprite.info != 0xFF) { int count = _replace_sprites_count[0]; @@ -245,14 +246,8 @@ static bool LoadNextSprite(int load_index, byte file_index) static void SkipSprites(uint count) { - for (; count > 0; --count) - { - uint16 size = FioReadWord(); - - if (size == 0) - return; - - ReadSpriteHeaderSkipData(size, MAX_SPRITES - 1); + for (; count > 0; --count) { + if (!ReadSpriteHeaderSkipData(MAX_SPRITES - 1)) return; } } |