12 #ifndef NEWGRF_STORAGE_H 13 #define NEWGRF_STORAGE_H 67 template <
typename TYPE, u
int SIZE>
75 memset(this->storage, 0,
sizeof(this->storage));
81 free(this->prev_storage);
87 memset(this->storage, 0,
sizeof(this->storage));
100 if (pos >= SIZE)
return;
104 if (this->storage[pos] == value)
return;
108 assert(this->prev_storage == NULL);
109 }
else if (this->prev_storage == NULL) {
110 this->prev_storage = MallocT<TYPE>(SIZE);
111 memcpy(this->prev_storage, this->storage,
sizeof(this->storage));
118 this->storage[pos] = value;
129 if (pos >= SIZE)
return 0;
131 return this->storage[pos];
136 if (this->prev_storage != NULL) {
137 memcpy(this->storage, this->prev_storage,
sizeof(this->storage));
138 free(this->prev_storage);
139 this->prev_storage = NULL;
151 template <
typename TYPE, u
int SIZE>
160 memset(this->storage, 0,
sizeof(this->storage));
161 memset(this->init, 0,
sizeof(this->init));
173 if (pos >= SIZE)
return;
175 this->storage[pos] = value;
176 this->init[pos] = this->init_key;
187 if (pos >= SIZE)
return 0;
189 if (this->init[pos] != this->init_key) {
194 return this->storage[pos];
201 if (this->init_key == 0) {
203 memset(this->init, 0,
sizeof(this->init));
213 typedef uint32 PersistentStorageID;
227 this->
grfid = new_grfid;
235 #define FOR_ALL_STORAGES_FROM(var, start) FOR_ALL_ITEMS_FROM(PersistentStorage, storage_index, var, start) 236 #define FOR_ALL_STORAGES(var) FOR_ALL_STORAGES_FROM(var, 0) TileIndex tile
NOSAVE: Used to identify in the owner of the array in debug output.
TemporaryStorageArray()
Simply construct the array.
TYPE * prev_storage
Memory to store "old" states so we can revert them on the performance of test cases for commands etc...
Leave command test mode, revert to previous mode.
Enter command test mode, changes will be tempoary.
Class for temporary storage of data.
~PersistentStorageArray()
And free all data related to it.
byte feature
NOSAVE: Used to identify in the owner of the array in debug output.
Defintion of Pool, structure used to access PoolItems, and PoolItem, base structure for Vehicle...
Class for persistent storage of data.
TYPE GetValue(uint pos) const
Gets the value from a given position.
void StoreValue(uint pos, int32 value)
Stores some value at a given position.
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...
PersistentStorageMode
Mode switches to the behaviour of persistent storage array.
Enter the gameloop, changes will be permanent.
uint32 grfid
GRFID associated to this persistent storage. A value of zero means "default".
PersistentStorage(const uint32 new_grfid, byte feature, TileIndex tile)
We don't want GCC to zero our struct! It already is zeroed and has an index!
virtual void ClearChanges()=0
Discard temporary changes.
void StoreValue(uint pos, int32 value)
Stores some value at a given position.
Class for pooled persistent storage of data.
void AddChangedPersistentStorage(BasePersistentStorageArray *storage)
Add the changed storage array to the list of changed arrays.
static bool AreChangesPersistent()
Check whether currently changes to the storage shall be persistent or temporary till the next call to...
Base class for all persistent NewGRF storage arrays.
Enter command scope, changes will be permanent.
Base class for all PoolItems.
Leave command scope, revert to previous mode.
Base class for all pools.
Leave the gameloop, changes will be temporary.
uint32 TileIndex
The index/ID of a Tile.
#define cpp_lengthof(base, variable)
Gets the length of an array variable within a class.
void ClearChanges()
Discard temporary changes.
uint16 init_key
Magic key to 'init'.
static void free(const void *ptr)
Version of the standard free that accepts const pointers.
PersistentStorageArray()
Simply construct the array.
TYPE GetValue(uint pos) const
Gets the value from a given position.
void ResetToZero()
Resets all values to zero.
virtual ~BasePersistentStorageArray()
Remove references to use.