OpenTTD

storage_sl.cpp
Go to the documentation of this file.
1 /* $Id: storage_sl.cpp 26482 2014-04-23 20:13:33Z rubidium $ */
2
3 /*
4 * This file is part of OpenTTD.
5 * OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
6 * OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
7 * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
8 */
9
12 #include "../stdafx.h"
13 #include "../newgrf_storage.h"
14 #include "saveload.h"
15
16 #include "../safeguards.h"
17
19 static const SaveLoad _storage_desc[] = {
20 SLE_CONDVAR(PersistentStorage, grfid, SLE_UINT32, 6, SL_MAX_VERSION),
21 SLE_CONDARR(PersistentStorage, storage, SLE_UINT32, 16, 161, SL_MAX_VERSION),
22 SLE_END()
23 };
24
26 static void Load_PSAC()
27 {
28 int index;
29
30 while ((index = SlIterateArray()) != -1) {
31 assert(PersistentStorage::CanAllocateItem());
32 PersistentStorage *ps = new (index) PersistentStorage(0, 0, 0);
33 SlObject(ps, _storage_desc);
34 }
35 }
36
38 static void Save_PSAC()
39 {
40 PersistentStorage *ps;
41
42 /* Write the industries */
43 FOR_ALL_STORAGES(ps) {
44 ps->ClearChanges();
45 SlSetArrayIndex(ps->index);
46 SlObject(ps, _storage_desc);
47 }
48 }
49
51 extern const ChunkHandler _persistent_storage_chunk_handlers[] = {
52 { 'PSAC', Save_PSAC, Load_PSAC, NULL, NULL, CH_ARRAY | CH_LAST},
53 };
Pool::PoolItem::index
Tindex index
Index of this pool item.
Definition: pool_type.hpp:147
_storage_desc
static const SaveLoad _storage_desc[]
Description of the data to save and load in PersistentStorage.
Definition: storage_sl.cpp:19
saveload.h
Functions/types related to saving and loading games.
SLE_CONDVAR
#define SLE_CONDVAR(base, variable, type, from, to)
Storage of a variable in some savegame versions.
Definition: saveload.h:246
_persistent_storage_chunk_handlers
const ChunkHandler _persistent_storage_chunk_handlers[]
Chunk handler for persistent storages.
PersistentStorage
Class for pooled persistent storage of data.
Definition: newgrf_storage.h:223
SL_MAX_VERSION
#define SL_MAX_VERSION
Highest possible savegame version.
Definition: saveload.h:96
SlIterateArray
int SlIterateArray()
Iterate through the elements of an array and read the whole thing.
Definition: saveload.cpp:828
ChunkHandler
Handlers and description of chunk.
Definition: saveload.h:66
Load_PSAC
static void Load_PSAC()
Load persistent storage data.
Definition: storage_sl.cpp:26
Save_PSAC
static void Save_PSAC()
Save persistent storage data.
Definition: storage_sl.cpp:38
SLE_END
#define SLE_END()
End marker of a struct/class save or load.
Definition: saveload.h:353
SLE_CONDARR
#define SLE_CONDARR(base, variable, type, length, from, to)
Storage of an array in some savegame versions.
Definition: saveload.h:267
PersistentStorageArray::ClearChanges
void ClearChanges()
Discard temporary changes.
Definition: newgrf_storage.h:134
SlObject
void SlObject(void *object, const SaveLoad *sld)
Main SaveLoad function.
Definition: saveload.cpp:1612
Pool::PoolItem<&_persistent_storage_pool >::CanAllocateItem
static bool CanAllocateItem(size_t n=1)
Helper functions so we can use PoolItem::Function() instead of _poolitem_pool.Function() ...
Definition: pool_type.hpp:216
SaveLoad
SaveLoad type struct.
Definition: saveload.h:208
CH_LAST
Last chunk in this array.
Definition: saveload.h:104