changeset 18019:17be4c7991db draft

(svn r22828) -Codechange: give some variables a better name and clean up the code of loading old style GRFs
author rubidium <rubidium@openttd.org>
date Wed, 24 Aug 2011 14:31:18 +0000
parents 873018a3a54e
children fd8f44f55f2a
files src/gfxinit.cpp src/table/landscape_sprite.h
diffstat 2 files changed, 32 insertions(+), 23 deletions(-) [+]
line wrap: on
line diff
--- a/src/gfxinit.cpp
+++ b/src/gfxinit.cpp
@@ -27,18 +27,26 @@
 
 #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 @@
 	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 @@
 	 */
 	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++
--- a/src/table/landscape_sprite.h
+++ b/src/table/landscape_sprite.h
@@ -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 @@
 END
 };
 
-static const SpriteID _landscape_spriteindexes_2[] = {
+static const SpriteID _landscape_spriteindexes_tropic[] = {
  0xF67,  0xF9F,
  0xAAD,  0xAB0,
  0xFA0,  0xFC9,
@@ -74,7 +74,7 @@
 END
 };
 
-static const SpriteID _landscape_spriteindexes_3[] = {
+static const SpriteID _landscape_spriteindexes_toyland[] = {
  0xF54,  0xF9F,
  0xFDD,  0xFE5,
  0xFEC,  0xFEC,