Codechange: let NewGRF make use of SpriteFile instead of most of the FIO slot functions

(cherry picked from commit 10e35ca8e4)
This commit is contained in:
Rubidium
2021-04-14 17:41:45 +02:00
committed by Jonathan G Rennison
parent 6bd12e24d7
commit eecf7c8525
4 changed files with 154 additions and 150 deletions

View File

@@ -51,16 +51,15 @@ int _progsig_grf_file_index;
* 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.
* @param needs_palette_remap Whether the colours in the GRF file need a palette remap.
* @return The number of loaded sprites.
*/
static uint LoadGrfFile(const char *filename, uint load_index, int file_index, bool needs_palette_remap)
static uint LoadGrfFile(const char *filename, uint load_index, bool needs_palette_remap)
{
uint load_index_org = load_index;
uint sprite_id = 0;
SpriteFile &file = FioOpenFile(file_index, filename, BASESET_DIR, needs_palette_remap);
SpriteFile &file = OpenCachedSpriteFile(filename, BASESET_DIR, needs_palette_remap);
DEBUG(sprite, 2, "Reading grf-file '%s'", filename);
@@ -89,16 +88,15 @@ static uint LoadGrfFile(const char *filename, uint load_index, int file_index, b
* Load an old fashioned GRF file to replace already loaded sprites.
* @param filename The name of the file to open.
* @param index_tbl The offsets of each of the sprites.
* @param file_index The Fio offset to load the file in.
* @param needs_palette_remap Whether the colours in the GRF file need a palette remap.
* @return The number of loaded sprites.
*/
static void LoadGrfFileIndexed(const char *filename, const SpriteID *index_tbl, int file_index, bool needs_palette_remap)
static void LoadGrfFileIndexed(const char *filename, const SpriteID *index_tbl, bool needs_palette_remap)
{
uint start;
uint sprite_id = 0;
SpriteFile &file = FioOpenFile(file_index, filename, BASESET_DIR, needs_palette_remap);
SpriteFile &file = OpenCachedSpriteFile(filename, BASESET_DIR, needs_palette_remap);
DEBUG(sprite, 2, "Reading indexed grf-file '%s'", filename);
@@ -173,14 +171,13 @@ void CheckExternalFiles()
/** Actually load the sprite tables. */
static void LoadSpriteTables()
{
uint i = FIRST_GRF_SLOT;
const GraphicsSet *used_set = BaseGraphics::GetUsedSet();
LoadGrfFile(used_set->files[GFT_BASE].filename, 0, i++, (PAL_DOS != used_set->palette));
LoadGrfFile(used_set->files[GFT_BASE].filename, 0, PAL_DOS != used_set->palette);
/* Progsignal sprites. */
_progsig_grf_file_index = i;
LoadGrfFile("progsignals.grf", SPR_PROGSIGNAL_BASE, i++, false);
//_progsig_grf_file_index = i;
LoadGrfFile("progsignals.grf", SPR_PROGSIGNAL_BASE, false);
/* Fill duplicate programmable pre-signal graphics sprite block */
for (uint i = 0; i < PROGSIGNAL_SPRITE_COUNT; i++) {
@@ -188,7 +185,7 @@ static void LoadSpriteTables()
}
/* Tracerestrict sprites. */
LoadGrfFile("tracerestrict.grf", SPR_TRACERESTRICT_BASE, i++, false);
LoadGrfFile("tracerestrict.grf", SPR_TRACERESTRICT_BASE, false);
/* Fill duplicate original signal graphics sprite block */
for (uint i = 0; i < DUP_ORIGINAL_SIGNALS_SPRITE_COUNT; i++) {
@@ -201,7 +198,7 @@ static void LoadSpriteTables()
* has a few sprites less. However, we do not care about those missing
* sprites as they are not shown anyway (logos in intro game).
*/
LoadGrfFile(used_set->files[GFT_LOGOS].filename, 4793, i++, (PAL_DOS != used_set->palette));
LoadGrfFile(used_set->files[GFT_LOGOS].filename, 4793, PAL_DOS != used_set->palette);
/*
* Load additional sprites for climates other than temperate.
@@ -212,15 +209,14 @@ static void LoadSpriteTables()
LoadGrfFileIndexed(
used_set->files[GFT_ARCTIC + _settings_game.game_creation.landscape - 1].filename,
_landscape_spriteindexes[_settings_game.game_creation.landscape - 1],
i++,
(PAL_DOS != used_set->palette)
PAL_DOS != used_set->palette
);
}
LoadGrfFile("innerhighlight.grf", SPR_ZONING_INNER_HIGHLIGHT_BASE, i++, false);
LoadGrfFile("innerhighlight.grf", SPR_ZONING_INNER_HIGHLIGHT_BASE, false);
/* Load route step graphics */
LoadGrfFile("route_step.grf", SPR_ROUTE_STEP_BASE, i++, false);
LoadGrfFile("route_step.grf", SPR_ROUTE_STEP_BASE, false);
/* Initialize the unicode to sprite mapping table */
InitializeUnicodeGlyphMap();
@@ -257,7 +253,7 @@ static void LoadSpriteTables()
master->next = extra;
_grfconfig = master;
LoadNewGRF(SPR_NEWGRFS_BASE, i, 2);
LoadNewGRF(SPR_NEWGRFS_BASE, 2);
uint total_extra_graphics = SPR_NEWGRFS_BASE - SPR_OPENTTD_BASE;
_missing_extra_graphics = GetSpriteCountForFile(used_set->files[GFT_EXTRA].filename, SPR_OPENTTD_BASE, SPR_NEWGRFS_BASE);
@@ -267,14 +263,13 @@ static void LoadSpriteTables()
* Let's say everything which provides less than 500 sprites misses the rest intentionally. */
if (500 + _missing_extra_graphics > total_extra_graphics) _missing_extra_graphics = 0;
_first_user_grf_file_index = i + 1;
_opengfx_grf_file_index = -1;
uint index = i;
for (GRFConfig *c = master; c != nullptr; c = c->next, index++) {
//_first_user_grf_file_index = i + 1;
//_opengfx_grf_file_index = -1;
for (GRFConfig *c = master; c != nullptr; c = c->next) {
if (c->status == GCS_DISABLED || c->status == GCS_NOT_FOUND || HasBit(c->flags, GCF_INIT_ONLY)) continue;
if (c->ident.grfid == BSWAP32(0xFF4F4701)) {
/* Detect OpenGFX GRF ID */
_opengfx_grf_file_index = index;
//_opengfx_grf_file_index = index;
break;
}
}