Codechange: Make SpriteType, CargoSortType, SourceType and ScriptType enum classes. (#10663)

This avoids a (soft) namespace conflict between the four ST_* enums.
This commit is contained in:
PeterN
2023-04-16 20:00:55 +01:00
committed by GitHub
parent 32c8e7feb8
commit e97bf271dc
42 changed files with 189 additions and 189 deletions

View File

@@ -162,7 +162,7 @@ bool SpriteExists(SpriteID id)
*/
SpriteType GetSpriteType(SpriteID sprite)
{
if (!SpriteExists(sprite)) return ST_INVALID;
if (!SpriteExists(sprite)) return SpriteType::Invalid;
return GetSpriteCache(sprite)->type;
}
@@ -461,8 +461,8 @@ static void *ReadSprite(const SpriteCache *sc, SpriteID id, SpriteType sprite_ty
SpriteFile &file = *sc->file;
size_t file_pos = sc->file_pos;
assert(sprite_type != ST_RECOLOUR);
assert(IsMapgenSpriteID(id) == (sprite_type == ST_MAPGEN));
assert(sprite_type != SpriteType::Recolour);
assert(IsMapgenSpriteID(id) == (sprite_type == SpriteType::MapGen));
assert(sc->type == sprite_type);
Debug(sprite, 9, "Load sprite {}", id);
@@ -472,7 +472,7 @@ static void *ReadSprite(const SpriteCache *sc, SpriteID id, SpriteType sprite_ty
sprite[ZOOM_LVL_NORMAL].type = sprite_type;
SpriteLoaderGrf sprite_loader(file.GetContainerVersion());
if (sprite_type != ST_MAPGEN && encoder->Is32BppSupported()) {
if (sprite_type != SpriteType::MapGen && encoder->Is32BppSupported()) {
/* Try for 32bpp sprites first. */
sprite_avail = sprite_loader.LoadSprite(sprite, file, file_pos, sprite_type, true, sc->control_flags);
}
@@ -481,12 +481,12 @@ static void *ReadSprite(const SpriteCache *sc, SpriteID id, SpriteType sprite_ty
}
if (sprite_avail == 0) {
if (sprite_type == ST_MAPGEN) return nullptr;
if (sprite_type == SpriteType::MapGen) return nullptr;
if (id == SPR_IMG_QUERY) usererror("Okay... something went horribly wrong. I couldn't load the fallback sprite. What should I do?");
return (void*)GetRawSprite(SPR_IMG_QUERY, ST_NORMAL, allocator, encoder);
return (void*)GetRawSprite(SPR_IMG_QUERY, SpriteType::Normal, allocator, encoder);
}
if (sprite_type == ST_MAPGEN) {
if (sprite_type == SpriteType::MapGen) {
/* Ugly hack to work around the problem that the old landscape
* generator assumes that those sprites are stored uncompressed in
* the memory, and they are only read directly by the code, never
@@ -516,10 +516,10 @@ static void *ReadSprite(const SpriteCache *sc, SpriteID id, SpriteType sprite_ty
if (!ResizeSprites(sprite, sprite_avail, encoder)) {
if (id == SPR_IMG_QUERY) usererror("Okay... something went horribly wrong. I couldn't resize the fallback sprite. What should I do?");
return (void*)GetRawSprite(SPR_IMG_QUERY, ST_NORMAL, allocator, encoder);
return (void*)GetRawSprite(SPR_IMG_QUERY, SpriteType::Normal, allocator, encoder);
}
if (sprite->type == ST_FONT && ZOOM_LVL_GUI != ZOOM_LVL_NORMAL) {
if (sprite->type == SpriteType::Font && ZOOM_LVL_GUI != ZOOM_LVL_NORMAL) {
/* Make ZOOM_LVL_NORMAL be ZOOM_LVL_GUI */
sprite[ZOOM_LVL_NORMAL].width = sprite[ZOOM_LVL_GUI].width;
sprite[ZOOM_LVL_NORMAL].height = sprite[ZOOM_LVL_GUI].height;
@@ -629,7 +629,7 @@ bool LoadNextSprite(int load_index, SpriteFile &file, uint file_sprite_id)
file.ReadByte();
return false;
}
type = ST_RECOLOUR;
type = SpriteType::Recolour;
data = ReadRecolourSprite(file, num);
} else if (file.GetContainerVersion() >= 2 && grf_type == 0xFD) {
if (num != 4) {
@@ -645,15 +645,15 @@ bool LoadNextSprite(int load_index, SpriteFile &file, uint file_sprite_id)
} else {
file_pos = SIZE_MAX;
}
type = ST_NORMAL;
type = SpriteType::Normal;
} else {
file.SkipBytes(7);
type = SkipSpriteData(file, grf_type, num - 8) ? ST_NORMAL : ST_INVALID;
type = SkipSpriteData(file, grf_type, num - 8) ? SpriteType::Normal : SpriteType::Invalid;
/* Inline sprites are not supported for container version >= 2. */
if (file.GetContainerVersion() >= 2) return false;
}
if (type == ST_INVALID) return false;
if (type == SpriteType::Invalid) return false;
if (load_index >= MAX_SPRITES) {
usererror("Tried to load too many sprites (#%d; max %d)", load_index, MAX_SPRITES);
@@ -662,8 +662,8 @@ bool LoadNextSprite(int load_index, SpriteFile &file, uint file_sprite_id)
bool is_mapgen = IsMapgenSpriteID(load_index);
if (is_mapgen) {
if (type != ST_NORMAL) usererror("Uhm, would you be so kind not to load a NewGRF that changes the type of the map generator sprites?");
type = ST_MAPGEN;
if (type != SpriteType::Normal) usererror("Uhm, would you be so kind not to load a NewGRF that changes the type of the map generator sprites?");
type = SpriteType::MapGen;
}
SpriteCache *sc = AllocateSpriteCache(load_index);
@@ -828,7 +828,7 @@ static void DeleteEntryFromSpriteCache()
cur_lru = 0xffff;
for (SpriteID i = 0; i != _spritecache_items; i++) {
SpriteCache *sc = GetSpriteCache(i);
if (sc->type != ST_RECOLOUR && sc->ptr != nullptr && sc->lru < cur_lru) {
if (sc->type != SpriteType::Recolour && sc->ptr != nullptr && sc->lru < cur_lru) {
cur_lru = sc->lru;
best = i;
}
@@ -888,7 +888,7 @@ void *SimpleSpriteAlloc(size_t size)
/**
* Handles the case when a sprite of different type is requested than is present in the SpriteCache.
* For ST_FONT sprites, it is normal. In other cases, default sprite is loaded instead.
* For SpriteType::Font sprites, it is normal. In other cases, default sprite is loaded instead.
* @param sprite ID of loaded sprite
* @param requested requested sprite type
* @param sc the currently known sprite cache for the requested sprite
@@ -898,33 +898,33 @@ void *SimpleSpriteAlloc(size_t size)
static void *HandleInvalidSpriteRequest(SpriteID sprite, SpriteType requested, SpriteCache *sc, AllocatorProc *allocator)
{
static const char * const sprite_types[] = {
"normal", // ST_NORMAL
"map generator", // ST_MAPGEN
"character", // ST_FONT
"recolour", // ST_RECOLOUR
"normal", // SpriteType::Normal
"map generator", // SpriteType::MapGen
"character", // SpriteType::Font
"recolour", // SpriteType::Recolour
};
SpriteType available = sc->type;
if (requested == ST_FONT && available == ST_NORMAL) {
if (sc->ptr == nullptr) sc->type = ST_FONT;
if (requested == SpriteType::Font && available == SpriteType::Normal) {
if (sc->ptr == nullptr) sc->type = SpriteType::Font;
return GetRawSprite(sprite, sc->type, allocator);
}
byte warning_level = sc->warned ? 6 : 0;
sc->warned = true;
Debug(sprite, warning_level, "Tried to load {} sprite #{} as a {} sprite. Probable cause: NewGRF interference", sprite_types[available], sprite, sprite_types[requested]);
Debug(sprite, warning_level, "Tried to load {} sprite #{} as a {} sprite. Probable cause: NewGRF interference", sprite_types[static_cast<byte>(available)], sprite, sprite_types[static_cast<byte>(requested)]);
switch (requested) {
case ST_NORMAL:
case SpriteType::Normal:
if (sprite == SPR_IMG_QUERY) usererror("Uhm, would you be so kind not to load a NewGRF that makes the 'query' sprite a non-normal sprite?");
FALLTHROUGH;
case ST_FONT:
return GetRawSprite(SPR_IMG_QUERY, ST_NORMAL, allocator);
case ST_RECOLOUR:
case SpriteType::Font:
return GetRawSprite(SPR_IMG_QUERY, SpriteType::Normal, allocator);
case SpriteType::Recolour:
if (sprite == PALETTE_TO_DARK_BLUE) usererror("Uhm, would you be so kind not to load a NewGRF that makes the 'PALETTE_TO_DARK_BLUE' sprite a non-remap sprite?");
return GetRawSprite(PALETTE_TO_DARK_BLUE, ST_RECOLOUR, allocator);
case ST_MAPGEN:
/* this shouldn't happen, overriding of ST_MAPGEN sprites is checked in LoadNextSprite()
return GetRawSprite(PALETTE_TO_DARK_BLUE, SpriteType::Recolour, allocator);
case SpriteType::MapGen:
/* this shouldn't happen, overriding of SpriteType::MapGen sprites is checked in LoadNextSprite()
* (the only case the check fails is when these sprites weren't even loaded...) */
default:
NOT_REACHED();
@@ -942,8 +942,8 @@ static void *HandleInvalidSpriteRequest(SpriteID sprite, SpriteType requested, S
*/
void *GetRawSprite(SpriteID sprite, SpriteType type, AllocatorProc *allocator, SpriteEncoder *encoder)
{
assert(type != ST_MAPGEN || IsMapgenSpriteID(sprite));
assert(type < ST_INVALID);
assert(type != SpriteType::MapGen || IsMapgenSpriteID(sprite));
assert(type < SpriteType::Invalid);
if (!SpriteExists(sprite)) {
Debug(sprite, 1, "Tried to load non-existing sprite #{}. Probable cause: Wrong/missing NewGRFs", sprite);
@@ -1042,7 +1042,7 @@ void GfxClearSpriteCache()
/* Clear sprite ptr for all cached items */
for (uint i = 0; i != _spritecache_items; i++) {
SpriteCache *sc = GetSpriteCache(i);
if (sc->type != ST_RECOLOUR && sc->ptr != nullptr) DeleteEntryFromSpriteCache(i);
if (sc->type != SpriteType::Recolour && sc->ptr != nullptr) DeleteEntryFromSpriteCache(i);
}
VideoDriver::GetInstance()->ClearSystemSprites();