Changeset - r2329:ea0e9adbf1e6
[Not reviewed]
master
0 1 0
tron - 19 years ago 2005-08-11 13:09:12
tron@openttd.org
(svn r2855) Make ReadSpriteHeaderSkipData() responsible for detecting the end of a grf file instead of its callers - this simplifies the code a bit
1 file changed with 11 insertions and 16 deletions:
0 comments (0 inline, 0 general)
spritecache.c
Show inline comments
 
@@ -75,17 +75,20 @@ static const SpriteID * const _slopes_sp
 
	_slopes_spriteindexes_2,
 
	_slopes_spriteindexes_3,
 
};
 

	
 
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--;
 
		deaf = 1;
 
	}
 

	
 
@@ -99,19 +102,18 @@ static void ReadSpriteHeaderSkipData(int
 
		 * on their own. */
 
		if (_skip_specials || deaf) {
 
			FioSkipBytes(num);
 
		} 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);
 
	} else {
 
		while (num > 0) {
 
			int8 i = FioReadByte();
 
@@ -122,12 +124,14 @@ static void ReadSpriteHeaderSkipData(int
 
				i = -(i >> 3);
 
				num -= i;
 
				FioReadByte();
 
			}
 
		}
 
	}
 

	
 
	return true;
 
}
 

	
 
static void* AllocSprite(size_t);
 

	
 
static void* ReadSprite(SpriteID id)
 
{
 
@@ -192,17 +196,14 @@ 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];
 
		int offset = _replace_sprites_offset[0];
 

	
 
		_replace_sprites_offset[0]++;
 
@@ -242,20 +243,14 @@ static bool LoadNextSprite(int load_inde
 

	
 
	return true;
 
}
 

	
 
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;
 
	}
 
}
 

	
 
static int LoadGrfFile(const char *filename, int load_index, int file_index)
 
{
 
	int load_index_org = load_index;
0 comments (0 inline, 0 general)