OpenTTD Source
20240917-master-g9ab0a47812
|
Go to the documentation of this file.
10 #ifndef NEWGRF_STORAGE_H
11 #define NEWGRF_STORAGE_H
66 template <
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;
132 template <
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) {
189 typedef uint32_t PersistentStorageID;
203 this->
grfid = new_grfid;
@ PSM_LEAVE_TESTMODE
Leave command test mode, revert to previous mode.
static bool AreChangesPersistent()
Check whether currently changes to the storage shall be persistent or temporary till the next call to...
StorageType storage
Memory for the storage array.
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!
void ClearChanges() override
Discard temporary changes.
virtual ~BasePersistentStorageArray()
Remove references to use.
TYPE GetValue(uint pos) const
Gets the value from a given position.
Class for pooled persistent storage of data.
@ PSM_LEAVE_COMMAND
Leave command scope, revert to previous mode.
@ PSM_ENTER_GAMELOOP
Enter the gameloop, changes will be permanent.
StorageInitType init
Storage has been assigned, if this equals 'init_key'.
uint8_t feature
NOSAVE: Used to identify in the owner of the array in debug output.
virtual void ClearChanges()=0
Discard temporary changes.
uint32_t grfid
GRFID associated to this persistent storage. A value of zero means "default".
TileIndex tile
NOSAVE: Used to identify in the owner of the array in debug output.
Base class for all persistent NewGRF storage arrays.
Base class for all pools.
StorageType storage
Memory for the storage array.
Class for temporary storage of data.
@ PSM_LEAVE_GAMELOOP
Leave the gameloop, changes will be temporary.
uint16_t init_key
Magic key to 'init'.
static void SwitchMode(PersistentStorageMode mode, bool ignore_prev_mode=false)
Clear temporary changes made since the last call to SwitchMode, and set whether subsequent changes sh...
void StoreValue(uint pos, int32_t value)
Stores some value at a given position.
@ PSM_ENTER_COMMAND
Enter command scope, changes will be permanent.
@ PSM_ENTER_TESTMODE
Enter command test mode, changes will be temporary.
Base class for all PoolItems.
void StoreValue(uint pos, int32_t value)
Stores some value at a given position.
void AddChangedPersistentStorage(BasePersistentStorageArray *storage)
Add the changed storage array to the list of changed arrays.
TYPE GetValue(uint pos) const
Gets the value from a given position.
std::unique_ptr< StorageType > prev_storage
Temporary memory to store previous state so it can be reverted, e.g. for command tests.
Class for persistent storage of data.
PersistentStorageMode
Mode switches to the behaviour of persistent storage array.