10#ifndef NEWGRF_STORAGE_H
11#define NEWGRF_STORAGE_H
65template <
typename TYPE, u
int SIZE>
67 using StorageType = std::array<TYPE, SIZE>;
82 if (pos >= SIZE)
return;
86 if (this->
storage[pos] == value)
return;
110 if (pos >= SIZE)
return 0;
131template <
typename TYPE, u
int SIZE>
133 using StorageType = std::array<TYPE, SIZE>;
134 using StorageInitType = std::array<uint16_t, SIZE>;
148 if (pos >= SIZE)
return;
162 if (pos >= SIZE)
return 0;
164 if (this->
init[pos] != this->init_key) {
176 if (this->init_key == 0) {
202 this->
grfid = new_grfid;
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!
Templated helper to make a PoolID a single POD value.
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.
constexpr TileIndex INVALID_TILE
The very nice invalid tile marker.