Codechange: Remove SpriteGroupType from SpriteGroup. (#14511)

This commit is contained in:
2025-08-11 23:14:44 +01:00
committed by GitHub
parent f596498a28
commit b4ebb26c55
2 changed files with 34 additions and 41 deletions

View File

@@ -74,11 +74,17 @@ void NewGRFProfiler::EndResolve(const ResolverResult &result)
{ {
return cb_result; return cb_result;
} }
uint32_t operator()(const SpriteGroup *group) uint32_t operator()(const ResultSpriteGroup *group)
{ {
if (group == nullptr) return 0; return group == nullptr ? 0 : GetSpriteLocalID(group->sprite);
if (group->type != SGT_RESULT) return group->nfo_line; }
return GetSpriteLocalID(static_cast<const ResultSpriteGroup *>(group)->sprite); uint32_t operator()(const TileLayoutSpriteGroup *group)
{
return group == nullptr ? 0 : group->nfo_line;
}
uint32_t operator()(const IndustryProductionSpriteGroup *group)
{
return group == nullptr ? 0 : group->nfo_line;
} }
}; };
this->cur_call.result = std::visit(visitor{}, result); this->cur_call.result = std::visit(visitor{}, result);

View File

@@ -21,18 +21,10 @@
#include "newgrf_storage.h" #include "newgrf_storage.h"
#include "newgrf_commons.h" #include "newgrf_commons.h"
/* List of different sprite group types */
enum SpriteGroupType : uint8_t {
SGT_REAL,
SGT_DETERMINISTIC,
SGT_RANDOMIZED,
SGT_CALLBACK,
SGT_RESULT,
SGT_TILELAYOUT,
SGT_INDUSTRY_PRODUCTION,
};
struct SpriteGroup; struct SpriteGroup;
struct ResultSpriteGroup;
struct TileLayoutSpriteGroup;
struct IndustryProductionSpriteGroup;
struct ResolverObject; struct ResolverObject;
using CallbackResult = uint16_t; using CallbackResult = uint16_t;
@@ -42,7 +34,7 @@ using CallbackResult = uint16_t;
* - CallbackResult: Callback result. * - CallbackResult: Callback result.
* - SpriteGroup: ResultSpriteGroup, TileLayoutSpriteGroup, IndustryProductionSpriteGroup * - SpriteGroup: ResultSpriteGroup, TileLayoutSpriteGroup, IndustryProductionSpriteGroup
*/ */
using ResolverResult = std::variant<std::monostate, CallbackResult, const SpriteGroup *>; using ResolverResult = std::variant<std::monostate, CallbackResult, const ResultSpriteGroup *, const TileLayoutSpriteGroup *, const IndustryProductionSpriteGroup *>;
/* SPRITE_WIDTH is 24. ECS has roughly 30 sprite groups per real sprite. /* SPRITE_WIDTH is 24. ECS has roughly 30 sprite groups per real sprite.
* Adding an 'extra' margin would be assuming 64 sprite groups per real * Adding an 'extra' margin would be assuming 64 sprite groups per real
@@ -54,15 +46,14 @@ extern SpriteGroupPool _spritegroup_pool;
/* Common wrapper for all the different sprite group types */ /* Common wrapper for all the different sprite group types */
struct SpriteGroup : SpriteGroupPool::PoolItem<&_spritegroup_pool> { struct SpriteGroup : SpriteGroupPool::PoolItem<&_spritegroup_pool> {
protected: protected:
SpriteGroup(SpriteGroupType type) : type(type) {} SpriteGroup() {} // Not `= default` as that resets PoolItem->index.
/** Base sprite group resolver */ /** Base sprite group resolver */
virtual ResolverResult Resolve([[maybe_unused]] ResolverObject &object) const { return this; }; virtual ResolverResult Resolve(ResolverObject &object) const = 0;
public: public:
virtual ~SpriteGroup() = default; virtual ~SpriteGroup() = default;
uint32_t nfo_line = 0; uint32_t nfo_line = 0;
SpriteGroupType type{};
static ResolverResult Resolve(const SpriteGroup *group, ResolverObject &object, bool top_level = true); static ResolverResult Resolve(const SpriteGroup *group, ResolverObject &object, bool top_level = true);
}; };
@@ -71,7 +62,7 @@ public:
/* 'Real' sprite groups contain a list of other result or callback sprite /* 'Real' sprite groups contain a list of other result or callback sprite
* groups. */ * groups. */
struct RealSpriteGroup : SpriteGroup { struct RealSpriteGroup : SpriteGroup {
RealSpriteGroup() : SpriteGroup(SGT_REAL) {} RealSpriteGroup() : SpriteGroup() {}
/* Loaded = in motion, loading = not moving /* Loaded = in motion, loading = not moving
* Each group contains several spritesets, for various loading stages */ * Each group contains several spritesets, for various loading stages */
@@ -166,7 +157,7 @@ struct DeterministicSpriteGroupRange {
struct DeterministicSpriteGroup : SpriteGroup { struct DeterministicSpriteGroup : SpriteGroup {
DeterministicSpriteGroup() : SpriteGroup(SGT_DETERMINISTIC) {} DeterministicSpriteGroup() : SpriteGroup() {}
VarSpriteGroupScope var_scope{}; VarSpriteGroupScope var_scope{};
DeterministicSpriteGroupSize size{}; DeterministicSpriteGroupSize size{};
@@ -188,7 +179,7 @@ enum RandomizedSpriteGroupCompareMode : uint8_t {
}; };
struct RandomizedSpriteGroup : SpriteGroup { struct RandomizedSpriteGroup : SpriteGroup {
RandomizedSpriteGroup() : SpriteGroup(SGT_RANDOMIZED) {} RandomizedSpriteGroup() : SpriteGroup() {}
VarSpriteGroupScope var_scope{}; ///< Take this object: VarSpriteGroupScope var_scope{}; ///< Take this object:
@@ -212,7 +203,7 @@ struct CallbackResultSpriteGroup : SpriteGroup {
* Creates a spritegroup representing a callback result * Creates a spritegroup representing a callback result
* @param value The value that was used to represent this callback result * @param value The value that was used to represent this callback result
*/ */
explicit CallbackResultSpriteGroup(CallbackResult value) : SpriteGroup(SGT_CALLBACK), result(value) {} explicit CallbackResultSpriteGroup(CallbackResult value) : SpriteGroup(), result(value) {}
CallbackResult result = 0; CallbackResult result = 0;
@@ -224,43 +215,37 @@ protected:
/* A result sprite group returns the first SpriteID and the number of /* A result sprite group returns the first SpriteID and the number of
* sprites in the set */ * sprites in the set */
struct ResultSpriteGroup : SpriteGroup { struct ResultSpriteGroup : SpriteGroup {
static constexpr SpriteGroupType TYPE = SGT_RESULT;
/** /**
* Creates a spritegroup representing a sprite number result. * Creates a spritegroup representing a sprite number result.
* @param sprite The sprite number. * @param sprite The sprite number.
* @param num_sprites The number of sprites per set. * @param num_sprites The number of sprites per set.
* @return A spritegroup representing the sprite number result. * @return A spritegroup representing the sprite number result.
*/ */
ResultSpriteGroup(SpriteID sprite, uint8_t num_sprites) : ResultSpriteGroup(SpriteID sprite, uint8_t num_sprites) : SpriteGroup(), num_sprites(num_sprites), sprite(sprite) {}
SpriteGroup(TYPE),
num_sprites(num_sprites),
sprite(sprite)
{
}
uint8_t num_sprites = 0; uint8_t num_sprites = 0;
SpriteID sprite = 0; SpriteID sprite = 0;
protected:
ResolverResult Resolve(ResolverObject &) const override { return this; }
}; };
/** /**
* Action 2 sprite layout for houses, industry tiles, objects and airport tiles. * Action 2 sprite layout for houses, industry tiles, objects and airport tiles.
*/ */
struct TileLayoutSpriteGroup : SpriteGroup { struct TileLayoutSpriteGroup : SpriteGroup {
static constexpr SpriteGroupType TYPE = SGT_TILELAYOUT; TileLayoutSpriteGroup() : SpriteGroup() {}
TileLayoutSpriteGroup() : SpriteGroup(TYPE) {}
~TileLayoutSpriteGroup() {}
NewGRFSpriteLayout dts{}; NewGRFSpriteLayout dts{};
SpriteLayoutProcessor ProcessRegisters(const ResolverObject &object, uint8_t *stage) const; SpriteLayoutProcessor ProcessRegisters(const ResolverObject &object, uint8_t *stage) const;
protected:
ResolverResult Resolve(ResolverObject &) const override { return this; }
}; };
struct IndustryProductionSpriteGroup : SpriteGroup { struct IndustryProductionSpriteGroup : SpriteGroup {
static constexpr SpriteGroupType TYPE = SGT_INDUSTRY_PRODUCTION; IndustryProductionSpriteGroup() : SpriteGroup() {}
IndustryProductionSpriteGroup() : SpriteGroup(TYPE) {}
uint8_t version = 0; ///< Production callback version used, or 0xFF if marked invalid uint8_t version = 0; ///< Production callback version used, or 0xFF if marked invalid
uint8_t num_input = 0; ///< How many subtract_input values are valid uint8_t num_input = 0; ///< How many subtract_input values are valid
@@ -271,6 +256,8 @@ struct IndustryProductionSpriteGroup : SpriteGroup {
std::array<CargoType, INDUSTRY_NUM_OUTPUTS> cargo_output{}; ///< Which output cargoes to add to (only cb version 2) std::array<CargoType, INDUSTRY_NUM_OUTPUTS> cargo_output{}; ///< Which output cargoes to add to (only cb version 2)
uint8_t again = 0; uint8_t again = 0;
protected:
ResolverResult Resolve(ResolverObject &) const override { return this; }
}; };
/** /**
@@ -374,9 +361,9 @@ public:
inline const TSpriteGroup *Resolve() inline const TSpriteGroup *Resolve()
{ {
auto result = this->DoResolve(); auto result = this->DoResolve();
const auto *group = std::get_if<const SpriteGroup *>(&result); const auto *group = std::get_if<const TSpriteGroup *>(&result);
if (group == nullptr || *group == nullptr || (*group)->type != TSpriteGroup::TYPE) return nullptr; if (group == nullptr) return nullptr;
return static_cast<const TSpriteGroup *>(*group); return *group;
} }
/** /**