Changeset - r18009:875021ab0452
[Not reviewed]
master
0 2 0
rubidium - 13 years ago 2011-08-24 14:31:18
rubidium@openttd.org
(svn r22828) -Codechange: give some variables a better name and clean up the code of loading old style GRFs
2 files changed with 32 insertions and 23 deletions:
0 comments (0 inline, 0 general)
src/gfxinit.cpp
Show inline comments
 
@@ -27,18 +27,26 @@ bool _palette_remap_grf[MAX_FILE_SLOTS];
 

	
 
#include "table/landscape_sprite.h"
 

	
 
/** Offsets for loading the different "replacement" sprites in the files. */
 
static const SpriteID * const _landscape_spriteindexes[] = {
 
	_landscape_spriteindexes_1,
 
	_landscape_spriteindexes_2,
 
	_landscape_spriteindexes_3,
 
	_landscape_spriteindexes_arctic,
 
	_landscape_spriteindexes_tropic,
 
	_landscape_spriteindexes_toyland,
 
};
 

	
 
/**
 
 * Load an old fashioned GRF file.
 
 * @param filename   The name of the file to open.
 
 * @param load_index The offset of the first sprite.
 
 * @param file_index The Fio offset to load the file in.
 
 * @return The number of loaded sprites.
 
 */
 
static uint LoadGrfFile(const char *filename, uint load_index, int file_index)
 
{
 
	uint load_index_org = load_index;
 
	uint sprite_id = 0;
 

	
 
	FioOpenFile(file_index, filename, NEWGRF_DIR);
 
	FioOpenFile(file_index, filename, BASESET_DIR);
 

	
 
	DEBUG(sprite, 2, "Reading grf-file '%s'", filename);
 

	
 
@@ -54,32 +62,33 @@ static uint LoadGrfFile(const char *file
 
	return load_index - load_index_org;
 
}
 

	
 

	
 
static void LoadSpritesIndexed(int file_index, uint *sprite_id, const SpriteID *index_tbl)
 
/**
 
 * Load an old fashioned GRF file to replace already loaded sprites.
 
 * @param filename   The name of the file to open.
 
 * @param index_tlb  The offsets of each of the sprites.
 
 * @param file_index The Fio offset to load the file in.
 
 * @return The number of loaded sprites.
 
 */
 
static void LoadGrfFileIndexed(const char *filename, const SpriteID *index_tbl, int file_index)
 
{
 
	uint start;
 
	uint sprite_id = 0;
 

	
 
	FioOpenFile(file_index, filename, BASESET_DIR);
 

	
 
	DEBUG(sprite, 2, "Reading indexed grf-file '%s'", filename);
 

	
 
	while ((start = *index_tbl++) != END) {
 
		uint end = *index_tbl++;
 

	
 
		do {
 
			bool b = LoadNextSprite(start, file_index, *sprite_id);
 
			bool b = LoadNextSprite(start, file_index, sprite_id);
 
			assert(b);
 
			(*sprite_id)++;
 
			sprite_id++;
 
		} while (++start <= end);
 
	}
 
}
 

	
 
static void LoadGrfIndexed(const char *filename, const SpriteID *index_tbl, int file_index)
 
{
 
	uint sprite_id = 0;
 

	
 
	FioOpenFile(file_index, filename, NEWGRF_DIR);
 

	
 
	DEBUG(sprite, 2, "Reading indexed grf-file '%s'", filename);
 

	
 
	LoadSpritesIndexed(file_index, &sprite_id, index_tbl);
 
}
 

	
 
/**
 
 * Checks whether the MD5 checksums of the files are correct.
 
 *
 
@@ -153,7 +162,7 @@ static void LoadSpriteTables()
 
	 */
 
	if (_settings_game.game_creation.landscape != LT_TEMPERATE) {
 
		_palette_remap_grf[i] = (PAL_DOS != used_set->palette);
 
		LoadGrfIndexed(
 
		LoadGrfFileIndexed(
 
			used_set->files[GFT_ARCTIC + _settings_game.game_creation.landscape - 1].filename,
 
			_landscape_spriteindexes[_settings_game.game_creation.landscape - 1],
 
			i++
src/table/landscape_sprite.h
Show inline comments
 
@@ -11,7 +11,7 @@
 

	
 
static const SpriteID END = 0xFFFF;
 

	
 
static const SpriteID _landscape_spriteindexes_1[] = {
 
static const SpriteID _landscape_spriteindexes_arctic[] = {
 
 0xF67,  0xF9F,
 
 0xAAD,  0xAB0,
 
 0x83A,  0x845,
 
@@ -37,7 +37,7 @@ 0x1212, 0x1212,
 
END
 
};
 

	
 
static const SpriteID _landscape_spriteindexes_2[] = {
 
static const SpriteID _landscape_spriteindexes_tropic[] = {
 
 0xF67,  0xF9F,
 
 0xAAD,  0xAB0,
 
 0xFA0,  0xFC9,
 
@@ -74,7 +74,7 @@ 0x1212, 0x1212,
 
END
 
};
 

	
 
static const SpriteID _landscape_spriteindexes_3[] = {
 
static const SpriteID _landscape_spriteindexes_toyland[] = {
 
 0xF54,  0xF9F,
 
 0xFDD,  0xFE5,
 
 0xFEC,  0xFEC,
0 comments (0 inline, 0 general)