diff --git a/src/gfxinit.cpp b/src/gfxinit.cpp index 46fbd3f7b7..d023f55546 100644 --- a/src/gfxinit.cpp +++ b/src/gfxinit.cpp @@ -43,10 +43,10 @@ static const SpriteID * const _landscape_spriteindexes[] = { * @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 std::string &filename, uint load_index, bool needs_palette_remap) +static uint LoadGrfFile(const std::string &filename, SpriteID load_index, bool needs_palette_remap) { - uint load_index_org = load_index; - uint sprite_id = 0; + SpriteID load_index_org = load_index; + SpriteID sprite_id = 0; SpriteFile &file = OpenCachedSpriteFile(filename, BASESET_DIR, needs_palette_remap); diff --git a/src/newgrf.cpp b/src/newgrf.cpp index 7ffb998885..7795f20c73 100644 --- a/src/newgrf.cpp +++ b/src/newgrf.cpp @@ -6469,7 +6469,7 @@ static void GraphicsNew(ByteReader &buf) for (; num > 0; num--) { _cur.nfo_line++; - int load_index = (replace == 0 ? _cur.spriteid++ : replace++); + SpriteID load_index = (replace == 0 ? _cur.spriteid++ : replace++); LoadNextSprite(load_index, *_cur.file, _cur.nfo_line); if (dup_oneway_sprites) { DupSprite(load_index, load_index + SPR_ONEWAY_SLOPE_N_OFFSET); @@ -7084,7 +7084,7 @@ static void SpriteReplace(ByteReader &buf) } for (uint j = 0; j < num_sprites; j++) { - int load_index = first_sprite + j; + SpriteID load_index = first_sprite + j; _cur.nfo_line++; LoadNextSprite(load_index, *_cur.file, _cur.nfo_line); // XXX @@ -10014,7 +10014,7 @@ static void AfterLoadGRFs() * @param load_index The offset for the first sprite to add. * @param num_baseset Number of NewGRFs at the front of the list to look up in the baseset dir instead of the newgrf dir. */ -void LoadNewGRF(uint load_index, uint num_baseset) +void LoadNewGRF(SpriteID load_index, uint num_baseset) { /* In case of networking we need to "sync" the start values * so all NewGRFs are loaded equally. For this we use the diff --git a/src/newgrf.h b/src/newgrf.h index b08376dc57..5a4d661721 100644 --- a/src/newgrf.h +++ b/src/newgrf.h @@ -196,7 +196,7 @@ inline bool HasGrfMiscBit(GrfMiscBit bit) extern GRFLoadedFeatures _loaded_newgrf_features; void LoadNewGRFFile(struct GRFConfig *config, GrfLoadingStage stage, Subdirectory subdir, bool temporary); -void LoadNewGRF(uint load_index, uint num_baseset); +void LoadNewGRF(SpriteID load_index, uint num_baseset); void ReloadNewGRFData(); // in saveload/afterload.cpp void ResetNewGRFData(); void ResetPersistentNewGRFData(); diff --git a/src/spritecache.cpp b/src/spritecache.cpp index 9bcd98c1d0..35242178d5 100644 --- a/src/spritecache.cpp +++ b/src/spritecache.cpp @@ -573,7 +573,7 @@ void ReadGRFSpriteOffsets(SpriteFile &file) /* Loop over all sprite section entries and store the file * offset for each newly encountered ID. */ - uint32_t id, prev_id = 0; + SpriteID id, prev_id = 0; while ((id = file.ReadDword()) != 0) { if (id != prev_id) { _grf_sprite_offsets[prev_id] = offset; @@ -615,7 +615,7 @@ void ReadGRFSpriteOffsets(SpriteFile &file) * @param container_version Container version of the GRF. * @return True if a valid sprite was loaded, false on any error. */ -bool LoadNextSprite(int load_index, SpriteFile &file, uint file_sprite_id) +bool LoadNextSprite(SpriteID load_index, SpriteFile &file, uint file_sprite_id) { size_t file_pos = file.GetPos(); @@ -661,7 +661,7 @@ bool LoadNextSprite(int load_index, SpriteFile &file, uint file_sprite_id) if (type == SpriteType::Invalid) return false; - if (static_cast(load_index) >= MAX_SPRITES) { + if (load_index >= MAX_SPRITES) { UserError("Tried to load too many sprites (#{}; max {})", load_index, MAX_SPRITES); } diff --git a/src/spritecache.h b/src/spritecache.h index 7aa01765d4..d6ba077a1e 100644 --- a/src/spritecache.h +++ b/src/spritecache.h @@ -77,7 +77,7 @@ std::span> GetCachedSpriteFiles(); void ReadGRFSpriteOffsets(SpriteFile &file); size_t GetGRFSpriteOffset(uint32_t id); -bool LoadNextSprite(int load_index, SpriteFile &file, uint file_sprite_id); +bool LoadNextSprite(SpriteID load_index, SpriteFile &file, uint file_sprite_id); bool SkipSpriteData(SpriteFile &file, uint8_t type, uint16_t num); void DupSprite(SpriteID old_spr, SpriteID new_spr); diff --git a/src/tests/mock_spritecache.cpp b/src/tests/mock_spritecache.cpp index 38bb6804cd..222d49043f 100644 --- a/src/tests/mock_spritecache.cpp +++ b/src/tests/mock_spritecache.cpp @@ -15,7 +15,7 @@ #include "../spritecache_internal.h" #include "../table/sprites.h" -static bool MockLoadNextSprite(int load_index) +static bool MockLoadNextSprite(SpriteID load_index) { SimpleSpriteAllocator allocator; static Sprite *sprite = allocator.Allocate(sizeof(*sprite)); @@ -33,7 +33,7 @@ static bool MockLoadNextSprite(int load_index) sc->control_flags = 0; /* Fill with empty sprites up until the default sprite count. */ - return (uint)load_index < SPR_OPENTTD_BASE + OPENTTD_SPRITE_COUNT; + return load_index < SPR_OPENTTD_BASE + OPENTTD_SPRITE_COUNT; } void MockGfxLoadSprites() @@ -43,7 +43,7 @@ void MockGfxLoadSprites() GfxInitSpriteMem(); - int load_index = 0; + SpriteID load_index = 0; while (MockLoadNextSprite(load_index)) { load_index++; }