10#ifndef NEWGRF_STORAGE_H
11#define NEWGRF_STORAGE_H
67template <
typename TYPE, u
int SIZE>
69 using StorageType = std::array<TYPE, SIZE>;
84 if (pos >= SIZE)
return;
88 if (this->storage[pos] == value)
return;
92 assert(!this->prev_storage);
93 }
else if (!this->prev_storage) {
94 this->prev_storage = std::make_unique<StorageType>(this->storage);
101 this->storage[pos] = value;
112 if (pos >= SIZE)
return 0;
114 return this->storage[pos];
119 if (this->prev_storage) {
120 this->storage = *this->prev_storage;
121 this->prev_storage.reset();
133template <
typename TYPE, u
int SIZE>
135 using StorageType = std::array<TYPE, SIZE>;
136 using StorageInitType = std::array<uint16_t, SIZE>;
150 if (pos >= SIZE)
return;
152 this->storage[pos] = value;
153 this->init[pos] = this->init_key;
164 if (pos >= SIZE)
return 0;
166 if (this->init[pos] != this->init_key) {
171 return this->storage[pos];
178 if (this->init_key == 0) {
195extern PersistentStoragePool _persistent_storage_pool;
200struct PersistentStorage :
PersistentStorageArray<int32_t, 256>, PersistentStoragePool::PoolItem<&_persistent_storage_pool> {
203 this->
grfid = new_grfid;
Base for the NewGRF implementation.
@ GSF_INVALID
An invalid spec feature.
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.
GrfSpecFeature 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 us.
Class for persistent storage of data.
void ClearChanges() override
Discard temporary changes.
std::unique_ptr< StorageType > prev_storage
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.
Templated helper to make a PoolID a single POD value.
const PersistentStorageID index
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.
StrongType::Typedef< uint32_t, struct TileIndexTag, StrongType::Compare, StrongType::Integer, StrongType::Compatible< int32_t >, StrongType::Compatible< int64_t > > TileIndex
The index/ID of a Tile.
constexpr TileIndex INVALID_TILE
The very nice invalid tile marker.