1
0
Fork 0

Codechange: Use span instead of marker terminated array for indexed sprite loading. (#13050)

pull/13054/head
Peter Nelson 2024-11-02 14:47:49 +00:00 committed by GitHub
parent 9193d69e0b
commit a1233ee8a1
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 130 additions and 138 deletions

View File

@ -30,7 +30,7 @@
#include "table/landscape_sprite.h" #include "table/landscape_sprite.h"
/** Offsets for loading the different "replacement" sprites in the files. */ /** Offsets for loading the different "replacement" sprites in the files. */
static const SpriteID * const _landscape_spriteindexes[] = { static constexpr std::span<const std::pair<SpriteID, SpriteID>> _landscape_spriteindexes[] = {
_landscape_spriteindexes_arctic, _landscape_spriteindexes_arctic,
_landscape_spriteindexes_tropic, _landscape_spriteindexes_tropic,
_landscape_spriteindexes_toyland, _landscape_spriteindexes_toyland,
@ -80,9 +80,8 @@ static uint LoadGrfFile(const std::string &filename, SpriteID load_index, bool n
* @param needs_palette_remap Whether the colours in the GRF file need a palette remap. * @param needs_palette_remap Whether the colours in the GRF file need a palette remap.
* @return The number of loaded sprites. * @return The number of loaded sprites.
*/ */
static void LoadGrfFileIndexed(const std::string &filename, const SpriteID *index_tbl, bool needs_palette_remap) static void LoadGrfFileIndexed(const std::string &filename, std::span<const std::pair<SpriteID, SpriteID>> index_tbl, bool needs_palette_remap)
{ {
uint start;
uint sprite_id = 0; uint sprite_id = 0;
SpriteFile &file = OpenCachedSpriteFile(filename, BASESET_DIR, needs_palette_remap); SpriteFile &file = OpenCachedSpriteFile(filename, BASESET_DIR, needs_palette_remap);
@ -98,14 +97,12 @@ static void LoadGrfFileIndexed(const std::string &filename, const SpriteID *inde
if (compression != 0) UserError("Unsupported compression format"); if (compression != 0) UserError("Unsupported compression format");
} }
while ((start = *index_tbl++) != END) { for (const auto &pair : index_tbl) {
uint end = *index_tbl++; for (SpriteID load_index = pair.first; load_index <= pair.second; ++load_index) {
[[maybe_unused]] bool b = LoadNextSprite(load_index, file, sprite_id);
do {
[[maybe_unused]] bool b = LoadNextSprite(start, file, sprite_id);
assert(b); assert(b);
sprite_id++; sprite_id++;
} while (++start <= end); }
} }
} }

View File

@ -7,137 +7,132 @@
/** @file landscape_sprite.h Offsets of sprites to replace for non-temperate landscapes. */ /** @file landscape_sprite.h Offsets of sprites to replace for non-temperate landscapes. */
static const SpriteID END = 0xFFFF; static constexpr std::pair<SpriteID, SpriteID> _landscape_spriteindexes_arctic[] = {
{ 0xF67, 0xF9F},
static const SpriteID _landscape_spriteindexes_arctic[] = { { 0xAAD, 0xAB0},
0xF67, 0xF9F, { 0x83A, 0x845},
0xAAD, 0xAB0, { 0xFA0, 0xFC9},
0x83A, 0x845, { 0x43F, 0x45E},
0xFA0, 0xFC9, { 0x566, 0x56D},
0x43F, 0x45E, { 0x945, 0x94C},
0x566, 0x56D, { 0x3ED, 0x40C},
0x945, 0x94C, { 0x515, 0x51C},
0x3ED, 0x40C, { 0x55A, 0x561},
0x515, 0x51C, { 0x534, 0x546},
0x55A, 0x561, { 0x93D, 0x944},
0x534, 0x546, { 0x955, 0x95C},
0x93D, 0x944, { 0xFDD, 0xFEC},
0x955, 0x95C, { 0x87D, 0x883},
0xFDD, 0xFEC, { 0xA2B, 0xA39},
0x87D, 0x883, { 0x497, 0x4B0},
0xA2B, 0xA39, { 0x572, 0x575},
0x497, 0x4B0, { 0x94D, 0x954},
0x572, 0x575, { 0x818, 0x81D},
0x94D, 0x954, { 0x3DE, 0x3EB},
0x818, 0x81D, {0x1212, 0x1212},
0x3DE, 0x3EB,
0x1212, 0x1212,
END
}; };
static const SpriteID _landscape_spriteindexes_tropic[] = { static constexpr std::pair<SpriteID, SpriteID> _landscape_spriteindexes_tropic[] = {
0xF67, 0xF9F, { 0xF67, 0xF9F},
0xAAD, 0xAB0, { 0xAAD, 0xAB0},
0xFA0, 0xFC9, { 0xFA0, 0xFC9},
0x43F, 0x45E, { 0x43F, 0x45E},
0x566, 0x56D, { 0x566, 0x56D},
0x945, 0x94C, { 0x945, 0x94C},
0x3ED, 0x40C, { 0x3ED, 0x40C},
0x515, 0x51C, { 0x515, 0x51C},
0x55A, 0x561, { 0x55A, 0x561},
0x547, 0x559, { 0x547, 0x559},
0x93D, 0x944, { 0x93D, 0x944},
0x955, 0x95C, { 0x955, 0x95C},
0xFDD, 0xFEC, { 0xFDD, 0xFEC},
0x87D, 0x883, { 0x87D, 0x883},
0xA2B, 0xA39, { 0xA2B, 0xA39},
0x497, 0x4B0, { 0x497, 0x4B0},
0x572, 0x575, { 0x572, 0x575},
0x94D, 0x954, { 0x94D, 0x954},
0x5AE, 0x5AF, { 0x5AE, 0x5AF},
0x118D, 0x11D8, {0x118D, 0x11D8},
0x534, 0x546, { 0x534, 0x546},
0x40D, 0x426, { 0x40D, 0x426},
0x45F, 0x478, { 0x45F, 0x478},
0x4B1, 0x4CA, { 0x4B1, 0x4CA},
0x95D, 0x97C, { 0x95D, 0x97C},
0x3DE, 0x3EB, { 0x3DE, 0x3EB},
0x562, 0x565, { 0x562, 0x565},
0x56E, 0x571, { 0x56E, 0x571},
0x57A, 0x57D, { 0x57A, 0x57D},
0x83A, 0x845, { 0x83A, 0x845},
0xFF5, 0xFF5, { 0xFF5, 0xFF5},
0xFF8, 0xFF8, { 0xFF8, 0xFF8},
0x1212, 0x1212, {0x1212, 0x1212},
END
}; };
static const SpriteID _landscape_spriteindexes_toyland[] = { static constexpr std::pair<SpriteID, SpriteID> _landscape_spriteindexes_toyland[] = {
0xF54, 0xF9F, { 0xF54, 0xF9F},
0xFDD, 0xFE5, { 0xFDD, 0xFE5},
0xFEC, 0xFEC, { 0xFEC, 0xFEC},
0xFA0, 0xFC9, { 0xFA0, 0xFC9},
0x818, 0x81D, { 0x818, 0x81D},
0x521, 0x546, { 0x521, 0x546},
0x57E, 0x57F, { 0x57E, 0x57F},
0x3ED, 0x40C, { 0x3ED, 0x40C},
0x43F, 0x45E, { 0x43F, 0x45E},
0x491, 0x4B0, { 0x491, 0x4B0},
0xA48, 0xA48, { 0xA48, 0xA48},
0x4FB, 0x50A, { 0x4FB, 0x50A},
0x55A, 0x561, { 0x55A, 0x561},
0x566, 0x56D, { 0x566, 0x56D},
0x572, 0x579, { 0x572, 0x579},
0x427, 0x42C, { 0x427, 0x42C},
0x479, 0x47E, { 0x479, 0x47E},
0x4CB, 0x4D0, { 0x4CB, 0x4D0},
0x4EF, 0x4FA, { 0x4EF, 0x4FA},
0xE9D, 0xECC, { 0xE9D, 0xECC},
0xF3D, 0xF40, { 0xF3D, 0xF40},
0xB59, 0xB60, { 0xB59, 0xB60},
0xE5D, 0xE6C, { 0xE5D, 0xE6C},
0xA49, 0xA59, { 0xA49, 0xA59},
0xA63, 0xA68, { 0xA63, 0xA68},
0xA5A, 0xA62, { 0xA5A, 0xA62},
0xA78, 0xA83, { 0xA78, 0xA83},
0xA69, 0xA77, { 0xA69, 0xA77},
0xA84, 0xAA3, { 0xA84, 0xAA3},
0xAA7, 0xAAC, { 0xAA7, 0xAAC},
0xA2B, 0xA47, { 0xA2B, 0xA47},
0x3DE, 0x3EB, { 0x3DE, 0x3EB},
0x47F, 0x488, { 0x47F, 0x488},
0x4D1, 0x4DA, { 0x4D1, 0x4DA},
0x42D, 0x436, { 0x42D, 0x436},
0x515, 0x51C, { 0x515, 0x51C},
0x580, 0x585, { 0x580, 0x585},
0xC14, 0xCB3, { 0xC14, 0xCB3},
0xAAD, 0xAB0, { 0xAAD, 0xAB0},
0xAB5, 0xB00, { 0xAB5, 0xB00},
0xB69, 0xB70, { 0xB69, 0xB70},
0xB61, 0xB68, { 0xB61, 0xB68},
0xBC9, 0xBD0, { 0xBC9, 0xBD0},
0xBD9, 0xBE0, { 0xBD9, 0xBE0},
0xBA9, 0xBB0, { 0xBA9, 0xBB0},
0xBC1, 0xBC4, { 0xBC1, 0xBC4},
0x2D0, 0x2D0, { 0x2D0, 0x2D0},
0xAA5, 0xAA6, { 0xAA5, 0xAA6},
0x50F, 0x50F, { 0x50F, 0x50F},
0x2EA, 0x2EA, { 0x2EA, 0x2EA},
0x2ED, 0x2EE, { 0x2ED, 0x2EE},
0x512, 0x513, { 0x512, 0x513},
0x4EB, 0x4EE, { 0x4EB, 0x4EE},
0x4E7, 0x4EA, { 0x4E7, 0x4EA},
0x985, 0xA28, { 0x985, 0xA28},
0x10E4, 0x1133, {0x10E4, 0x1133},
0x93D, 0x95C, { 0x93D, 0x95C},
0x97D, 0x984, { 0x97D, 0x984},
0x7DA, 0x7DA, { 0x7DA, 0x7DA},
0x2E6, 0x2E6, { 0x2E6, 0x2E6},
0x1, 0x1, { 0x1, 0x1},
0xE54, 0xE54, { 0xE54, 0xE54},
0x51F, 0x520, { 0x51F, 0x520},
0x514, 0x514, { 0x514, 0x514},
0x511, 0x511, { 0x511, 0x511},
0x322, 0x322, { 0x322, 0x322},
END
}; };