mirror of https://github.com/OpenTTD/OpenTTD
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
parent
184621e64a
commit
c502c4479e
|
@ -421,7 +421,7 @@ uint32_t CommandCost::textref_stack[16];
|
|||
*/
|
||||
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));
|
||||
this->textref_stack_grffile = grffile;
|
||||
|
|
|
@ -18,7 +18,7 @@
|
|||
SpriteGroupPool _spritegroup_pool("SpriteGroup");
|
||||
INSTANTIATE_POOL_METHODS(SpriteGroup)
|
||||
|
||||
TemporaryStorageArray<int32_t, 0x110> _temp_store;
|
||||
TemporaryStorageArray _temp_store;
|
||||
|
||||
|
||||
/**
|
||||
|
|
|
@ -28,7 +28,7 @@
|
|||
*/
|
||||
inline uint32_t GetRegister(uint i)
|
||||
{
|
||||
extern TemporaryStorageArray<int32_t, 0x110> _temp_store;
|
||||
extern TemporaryStorageArray _temp_store;
|
||||
return _temp_store.GetValue(i);
|
||||
}
|
||||
|
||||
|
|
|
@ -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 <typename TYPE, uint SIZE>
|
||||
template <uint SIZE>
|
||||
struct PersistentStorageArray : BasePersistentStorageArray {
|
||||
using StorageType = std::array<TYPE, SIZE>;
|
||||
using StorageType = std::array<int32_t, SIZE>;
|
||||
|
||||
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.
|
||||
|
@ -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 <typename TYPE, uint SIZE>
|
||||
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>;
|
||||
|
||||
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<int32_t, 16> 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<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! */
|
||||
PersistentStorage(const uint32_t new_grfid, uint8_t feature, TileIndex tile)
|
||||
{
|
||||
|
|
|
@ -797,7 +797,7 @@ void RestoreTextRefStackBackup(struct TextRefStack *backup)
|
|||
*/
|
||||
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);
|
||||
|
||||
|
|
Loading…
Reference in New Issue