1
0
Fork 0

Codechange: De-template PersistentStorage and TemporaryStorageArray.

NewGRF storage is always int32_t with no exceptions, so allowing the type to be configurable is unnecessary complexity.

Removes unnecessary template parameter from PersistentStorage and TemporaryStorageArray.
pull/10670/head
Peter Nelson 2024-11-13 16:43:03 +00:00
parent 184621e64a
commit c502c4479e
No known key found for this signature in database
GPG Key ID: 8EF8F0A467DF75ED
5 changed files with 15 additions and 17 deletions

View File

@ -421,7 +421,7 @@ uint32_t CommandCost::textref_stack[16];
*/ */
void CommandCost::UseTextRefStack(const GRFFile *grffile, uint num_registers) void CommandCost::UseTextRefStack(const GRFFile *grffile, uint num_registers)
{ {
extern TemporaryStorageArray<int32_t, 0x110> _temp_store; extern TemporaryStorageArray _temp_store;
assert(num_registers < lengthof(textref_stack)); assert(num_registers < lengthof(textref_stack));
this->textref_stack_grffile = grffile; this->textref_stack_grffile = grffile;

View File

@ -18,7 +18,7 @@
SpriteGroupPool _spritegroup_pool("SpriteGroup"); SpriteGroupPool _spritegroup_pool("SpriteGroup");
INSTANTIATE_POOL_METHODS(SpriteGroup) INSTANTIATE_POOL_METHODS(SpriteGroup)
TemporaryStorageArray<int32_t, 0x110> _temp_store; TemporaryStorageArray _temp_store;
/** /**

View File

@ -28,7 +28,7 @@
*/ */
inline uint32_t GetRegister(uint i) inline uint32_t GetRegister(uint i)
{ {
extern TemporaryStorageArray<int32_t, 0x110> _temp_store; extern TemporaryStorageArray _temp_store;
return _temp_store.GetValue(i); return _temp_store.GetValue(i);
} }

View File

@ -60,12 +60,11 @@ private:
/** /**
* Class for persistent storage of data. * Class for persistent storage of data.
* On #ClearChanges that data is either reverted or saved. * On #ClearChanges that data is either reverted or saved.
* @tparam TYPE the type of variable to store.
* @tparam SIZE the size of the array. * @tparam SIZE the size of the array.
*/ */
template <typename TYPE, uint SIZE> template <uint SIZE>
struct PersistentStorageArray : BasePersistentStorageArray { struct PersistentStorageArray : BasePersistentStorageArray {
using StorageType = std::array<TYPE, SIZE>; using StorageType = std::array<int32_t, SIZE>;
StorageType storage{}; ///< Memory for the storage array StorageType storage{}; ///< Memory for the storage array
std::unique_ptr<StorageType> prev_storage{}; ///< Temporary memory to store previous state so it can be reverted, e.g. for command tests. std::unique_ptr<StorageType> prev_storage{}; ///< Temporary memory to store previous state so it can be reverted, e.g. for command tests.
@ -105,7 +104,7 @@ struct PersistentStorageArray : BasePersistentStorageArray {
* @param pos the position to get the data from * @param pos the position to get the data from
* @return the data from that position * @return the data from that position
*/ */
TYPE GetValue(uint pos) const int32_t GetValue(uint pos) const
{ {
/* Out of the scope of the array */ /* Out of the scope of the array */
if (pos >= SIZE) return 0; if (pos >= SIZE) return 0;
@ -126,12 +125,11 @@ struct PersistentStorageArray : BasePersistentStorageArray {
/** /**
* Class for temporary storage of data. * Class for temporary storage of data.
* On #ClearChanges that data is always zero-ed. * On #ClearChanges that data is always zero-ed.
* @tparam TYPE the type of variable to store.
* @tparam SIZE the size of the array.
*/ */
template <typename TYPE, uint SIZE>
struct TemporaryStorageArray { struct TemporaryStorageArray {
using StorageType = std::array<TYPE, SIZE>; static constexpr size_t SIZE = 0x110;
using StorageType = std::array<int32_t, SIZE>;
using StorageInitType = std::array<uint16_t, SIZE>; using StorageInitType = std::array<uint16_t, SIZE>;
StorageType storage{}; ///< Memory for the storage array StorageType storage{}; ///< Memory for the storage array
@ -143,7 +141,7 @@ struct TemporaryStorageArray {
* @param pos the position to write at * @param pos the position to write at
* @param value the value to write * @param value the value to write
*/ */
void StoreValue(uint pos, int32_t value) inline void StoreValue(uint pos, int32_t value)
{ {
/* Out of the scope of the array */ /* Out of the scope of the array */
if (pos >= SIZE) return; if (pos >= SIZE) return;
@ -157,7 +155,7 @@ struct TemporaryStorageArray {
* @param pos the position to get the data from * @param pos the position to get the data from
* @return the data from that position * @return the data from that position
*/ */
TYPE GetValue(uint pos) const inline int32_t GetValue(uint pos) const
{ {
/* Out of the scope of the array */ /* Out of the scope of the array */
if (pos >= SIZE) return 0; if (pos >= SIZE) return 0;
@ -170,7 +168,7 @@ struct TemporaryStorageArray {
return this->storage[pos]; return this->storage[pos];
} }
void ClearChanges() inline void ClearChanges()
{ {
/* Increment init_key to invalidate all storage */ /* Increment init_key to invalidate all storage */
this->init_key++; this->init_key++;
@ -184,7 +182,7 @@ struct TemporaryStorageArray {
void AddChangedPersistentStorage(BasePersistentStorageArray *storage); void AddChangedPersistentStorage(BasePersistentStorageArray *storage);
typedef PersistentStorageArray<int32_t, 16> OldPersistentStorage; typedef PersistentStorageArray<16> OldPersistentStorage;
typedef uint32_t PersistentStorageID; typedef uint32_t PersistentStorageID;
@ -196,7 +194,7 @@ extern PersistentStoragePool _persistent_storage_pool;
/** /**
* Class for pooled persistent storage of data. * Class for pooled persistent storage of data.
*/ */
struct PersistentStorage : PersistentStorageArray<int32_t, 256>, PersistentStoragePool::PoolItem<&_persistent_storage_pool> { struct PersistentStorage : PersistentStorageArray<256>, PersistentStoragePool::PoolItem<&_persistent_storage_pool> {
/** We don't want GCC to zero our struct! It already is zeroed and has an index! */ /** We don't want GCC to zero our struct! It already is zeroed and has an index! */
PersistentStorage(const uint32_t new_grfid, uint8_t feature, TileIndex tile) PersistentStorage(const uint32_t new_grfid, uint8_t feature, TileIndex tile)
{ {

View File

@ -797,7 +797,7 @@ void RestoreTextRefStackBackup(struct TextRefStack *backup)
*/ */
void StartTextRefStackUsage(const GRFFile *grffile, uint8_t numEntries, const uint32_t *values) void StartTextRefStackUsage(const GRFFile *grffile, uint8_t numEntries, const uint32_t *values)
{ {
extern TemporaryStorageArray<int32_t, 0x110> _temp_store; extern TemporaryStorageArray _temp_store;
_newgrf_textrefstack.ResetStack(grffile); _newgrf_textrefstack.ResetStack(grffile);