diff options
author | terkhen <terkhen@openttd.org> | 2011-06-12 20:47:45 +0000 |
---|---|---|
committer | terkhen <terkhen@openttd.org> | 2011-06-12 20:47:45 +0000 |
commit | 00e5c1df18449992cc974b99c61a44d1385bf4a7 (patch) | |
tree | 7433db92049848236fe05f18b99d6f80c99442c6 /src/newgrf_storage.h | |
parent | 9f55abf51aac0f408e60d905fb2ac1b8a1405bb9 (diff) | |
download | openttd-00e5c1df18449992cc974b99c61a44d1385bf4a7.tar.xz |
(svn r22567) -Codechange: Store persistent storages inside a pool.
Diffstat (limited to 'src/newgrf_storage.h')
-rw-r--r-- | src/newgrf_storage.h | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/src/newgrf_storage.h b/src/newgrf_storage.h index dc8f86799..2ea3e3d8e 100644 --- a/src/newgrf_storage.h +++ b/src/newgrf_storage.h @@ -13,6 +13,7 @@ #define NEWGRF_STORAGE_H #include "core/alloc_func.hpp" +#include "core/pool_type.hpp" /** * Base class for all NewGRF storage arrays. Nothing fancy, only here @@ -178,4 +179,40 @@ struct TemporaryStorageArray : BaseStorageArray { void AddChangedStorage(BaseStorageArray *storage); void ClearStorageChanges(bool keep_changes); + +typedef PersistentStorageArray<int32, 16> OldPersistentStorage; + +typedef uint32 PersistentStorageID; + +struct PersistentStorage; +typedef Pool<PersistentStorage, PersistentStorageID, 1, 0xFF000> PersistentStoragePool; + +extern PersistentStoragePool _persistent_storage_pool; + +/** + * Class for pooled persistent storage of data. + * On ClearChanges that data is always zero-ed. + */ +struct PersistentStorage : PersistentStorageArray<int32, 16>, PersistentStoragePool::PoolItem<&_persistent_storage_pool> { + uint32 grfid; ///< GRFID associated to this persistent storage. A value of zero means "default". + + /** We don't want GCC to zero our struct! It already is zeroed and has an index! */ + PersistentStorage(const uint32 new_grfid) : grfid(new_grfid) + { + this->prev_storage = NULL; + memset(this->storage, 0, sizeof(this->storage)); + } + + /** Free the memory used by the persistent storage. */ + ~PersistentStorage() + { + free(this->prev_storage); + } +}; + +assert_compile(cpp_lengthof(OldPersistentStorage, storage) == cpp_lengthof(PersistentStorage, storage)); + +#define FOR_ALL_STORAGES_FROM(var, start) FOR_ALL_ITEMS_FROM(PersistentStorage, storage_index, var, start) +#define FOR_ALL_STORAGES(var) FOR_ALL_STORAGES_FROM(var, 0) + #endif /* NEWGRF_STORAGE_H */ |