10#ifndef NEWGRF_STORAGE_H
11#define NEWGRF_STORAGE_H
66template <
typename TYPE, u
int SIZE>
68 using StorageType = std::array<TYPE, SIZE>;
83 if (pos >= SIZE)
return;
87 if (this->
storage[pos] == value)
return;
111 if (pos >= SIZE)
return 0;
132template <
typename TYPE, u
int SIZE>
134 using StorageType = std::array<TYPE, SIZE>;
135 using StorageInitType = std::array<uint16_t, SIZE>;
149 if (pos >= SIZE)
return;
163 if (pos >= SIZE)
return 0;
165 if (this->
init[pos] != this->init_key) {
177 if (this->init_key == 0) {
189typedef uint32_t PersistentStorageID;
203 this->
grfid = new_grfid;
Functions related to the allocation of memory.
PersistentStorageMode
Mode switches to the behaviour of persistent storage array.
@ PSM_ENTER_GAMELOOP
Enter the gameloop, changes will be permanent.
@ PSM_LEAVE_TESTMODE
Leave command test mode, revert to previous mode.
@ PSM_LEAVE_COMMAND
Leave command scope, revert to previous mode.
@ PSM_LEAVE_GAMELOOP
Leave the gameloop, changes will be temporary.
@ PSM_ENTER_COMMAND
Enter command scope, changes will be permanent.
@ PSM_ENTER_TESTMODE
Enter command test mode, changes will be temporary.
void AddChangedPersistentStorage(BasePersistentStorageArray *storage)
Add the changed storage array to the list of changed arrays.
SwitchMode
Mode which defines what mode we're switching to.
Definition of Pool, structure used to access PoolItems, and PoolItem, base structure for Vehicle,...
Base class for all persistent NewGRF storage arrays.
static bool AreChangesPersistent()
Check whether currently changes to the storage shall be persistent or temporary till the next call to...
virtual void ClearChanges()=0
Discard temporary changes.
uint8_t feature
NOSAVE: Used to identify in the owner of the array in debug output.
TileIndex tile
NOSAVE: Used to identify in the owner of the array in debug output.
uint32_t grfid
GRFID associated to this persistent storage. A value of zero means "default".
virtual ~BasePersistentStorageArray()
Remove references to use.
Class for persistent storage of data.
StorageType storage
Memory for the storage array.
void ClearChanges() override
Discard temporary changes.
std::unique_ptr< StorageType > prev_storage
Temporary memory to store previous state so it can be reverted, e.g. for command tests.
TYPE GetValue(uint pos) const
Gets the value from a given position.
void StoreValue(uint pos, int32_t value)
Stores some value at a given position.
Class for pooled persistent storage of data.
PersistentStorage(const uint32_t new_grfid, uint8_t feature, TileIndex tile)
We don't want GCC to zero our struct! It already is zeroed and has an index!
Base class for all PoolItems.
Base class for all pools.
Class for temporary storage of data.
uint16_t init_key
Magic key to 'init'.
TYPE GetValue(uint pos) const
Gets the value from a given position.
void StoreValue(uint pos, int32_t value)
Stores some value at a given position.
StorageInitType init
Storage has been assigned, if this equals 'init_key'.
StorageType storage
Memory for the storage array.