diff --git a/src/command.cpp b/src/command.cpp index b5865ad4ae..ffac3dd45c 100644 --- a/src/command.cpp +++ b/src/command.cpp @@ -421,7 +421,7 @@ uint32_t CommandCost::textref_stack[16]; */ void CommandCost::UseTextRefStack(const GRFFile *grffile, uint num_registers) { - extern TemporaryStorageArray _temp_store; + extern TemporaryStorageArray _temp_store; assert(num_registers < lengthof(textref_stack)); this->textref_stack_grffile = grffile; diff --git a/src/newgrf_spritegroup.cpp b/src/newgrf_spritegroup.cpp index 1b8596659e..ae5bbb34fe 100644 --- a/src/newgrf_spritegroup.cpp +++ b/src/newgrf_spritegroup.cpp @@ -18,7 +18,7 @@ SpriteGroupPool _spritegroup_pool("SpriteGroup"); INSTANTIATE_POOL_METHODS(SpriteGroup) -TemporaryStorageArray _temp_store; +TemporaryStorageArray _temp_store; /** diff --git a/src/newgrf_spritegroup.h b/src/newgrf_spritegroup.h index 2efc98dbdc..36ba56b4fd 100644 --- a/src/newgrf_spritegroup.h +++ b/src/newgrf_spritegroup.h @@ -28,7 +28,7 @@ */ inline uint32_t GetRegister(uint i) { - extern TemporaryStorageArray _temp_store; + extern TemporaryStorageArray _temp_store; return _temp_store.GetValue(i); } diff --git a/src/newgrf_storage.h b/src/newgrf_storage.h index 3d5ab0ac04..13b6ff8f1f 100644 --- a/src/newgrf_storage.h +++ b/src/newgrf_storage.h @@ -60,12 +60,11 @@ private: /** * Class for persistent storage of data. * On #ClearChanges that data is either reverted or saved. - * @tparam TYPE the type of variable to store. * @tparam SIZE the size of the array. */ -template +template struct PersistentStorageArray : BasePersistentStorageArray { - using StorageType = std::array; + using StorageType = std::array; StorageType storage{}; ///< Memory for the storage array std::unique_ptr 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 * @return the data from that position */ - TYPE GetValue(uint pos) const + int32_t GetValue(uint pos) const { /* Out of the scope of the array */ if (pos >= SIZE) return 0; @@ -126,12 +125,11 @@ struct PersistentStorageArray : BasePersistentStorageArray { /** * Class for temporary storage of data. * On #ClearChanges that data is always zero-ed. - * @tparam TYPE the type of variable to store. - * @tparam SIZE the size of the array. */ -template struct TemporaryStorageArray { - using StorageType = std::array; + static constexpr size_t SIZE = 0x110; + + using StorageType = std::array; using StorageInitType = std::array; StorageType storage{}; ///< Memory for the storage array @@ -143,7 +141,7 @@ struct TemporaryStorageArray { * @param pos the position to write at * @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 */ if (pos >= SIZE) return; @@ -157,7 +155,7 @@ struct TemporaryStorageArray { * @param pos the position to get the data from * @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 */ if (pos >= SIZE) return 0; @@ -170,7 +168,7 @@ struct TemporaryStorageArray { return this->storage[pos]; } - void ClearChanges() + inline void ClearChanges() { /* Increment init_key to invalidate all storage */ this->init_key++; @@ -184,7 +182,7 @@ struct TemporaryStorageArray { void AddChangedPersistentStorage(BasePersistentStorageArray *storage); -typedef PersistentStorageArray OldPersistentStorage; +typedef PersistentStorageArray<16> OldPersistentStorage; typedef uint32_t PersistentStorageID; @@ -196,7 +194,7 @@ extern PersistentStoragePool _persistent_storage_pool; /** * Class for pooled persistent storage of data. */ -struct PersistentStorage : PersistentStorageArray, 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! */ PersistentStorage(const uint32_t new_grfid, uint8_t feature, TileIndex tile) { diff --git a/src/newgrf_text.cpp b/src/newgrf_text.cpp index 2383212b5a..c8e4e39784 100644 --- a/src/newgrf_text.cpp +++ b/src/newgrf_text.cpp @@ -797,7 +797,7 @@ void RestoreTextRefStackBackup(struct TextRefStack *backup) */ void StartTextRefStackUsage(const GRFFile *grffile, uint8_t numEntries, const uint32_t *values) { - extern TemporaryStorageArray _temp_store; + extern TemporaryStorageArray _temp_store; _newgrf_textrefstack.ResetStack(grffile);