From 14900d3e5367e8ee0460b7780a840fa8705f3130 Mon Sep 17 00:00:00 2001 From: tron Date: Thu, 11 Aug 2005 13:09:12 +0000 Subject: [PATCH] (svn r2855) Make ReadSpriteHeaderSkipData() responsible for detecting the end of a grf file instead of its callers - this simplifies the code a bit --- spritecache.c | 27 +++++++++++---------------- 1 file changed, 11 insertions(+), 16 deletions(-) diff --git a/spritecache.c b/spritecache.c index c246a89c19..e30a5e1955 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; } }