OpenTTD Source  1.11.2
storage_sl.cpp
Go to the documentation of this file.
1 /*
2  * This file is part of OpenTTD.
3  * 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.
4  * 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.
5  * 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/>.
6  */
7 
10 #include "../stdafx.h"
11 #include "../newgrf_storage.h"
12 #include "saveload.h"
13 
14 #include "../safeguards.h"
15 
17 static const SaveLoad _storage_desc[] = {
18  SLE_CONDVAR(PersistentStorage, grfid, SLE_UINT32, SLV_6, SL_MAX_VERSION),
21  SLE_END()
22 };
23 
25 static void Load_PSAC()
26 {
27  int index;
28 
29  while ((index = SlIterateArray()) != -1) {
31  PersistentStorage *ps = new (index) PersistentStorage(0, 0, 0);
33  }
34 }
35 
37 static void Save_PSAC()
38 {
39  /* Write the industries */
41  ps->ClearChanges();
42  SlSetArrayIndex(ps->index);
44  }
45 }
46 
49  { 'PSAC', Save_PSAC, Load_PSAC, nullptr, nullptr, CH_ARRAY | CH_LAST},
50 };
SLE_CONDARR
#define SLE_CONDARR(base, variable, type, length, from, to)
Storage of an array in some savegame versions.
Definition: saveload.h:573
SLE_CONDVAR
#define SLE_CONDVAR(base, variable, type, from, to)
Storage of a variable in some savegame versions.
Definition: saveload.h:552
CH_LAST
@ CH_LAST
Last chunk in this array.
Definition: saveload.h:411
saveload.h
ChunkHandler
Handlers and description of chunk.
Definition: saveload.h:380
SLV_EXTEND_PERSISTENT_STORAGE
@ SLV_EXTEND_PERSISTENT_STORAGE
201 PR#6885 Extend NewGRF persistent storages.
Definition: saveload.h:285
SLV_161
@ SLV_161
161 22567
Definition: saveload.h:236
PersistentStorage
Class for pooled persistent storage of data.
Definition: newgrf_storage.h:221
SLE_END
#define SLE_END()
End marker of a struct/class save or load.
Definition: saveload.h:687
_persistent_storage_chunk_handlers
const ChunkHandler _persistent_storage_chunk_handlers[]
Chunk handler for persistent storages.
_storage_desc
static const SaveLoad _storage_desc[]
Description of the data to save and load in PersistentStorage.
Definition: storage_sl.cpp:17
SlObject
void SlObject(void *object, const SaveLoad *sld)
Main SaveLoad function.
Definition: saveload.cpp:1612
Load_PSAC
static void Load_PSAC()
Load persistent storage data.
Definition: storage_sl.cpp:25
SL_MAX_VERSION
@ SL_MAX_VERSION
Highest possible saveload version.
Definition: saveload.h:329
Pool::PoolItem<&_persistent_storage_pool >::Iterate
static Pool::IterateWrapper< Titem > Iterate(size_t from=0)
Returns an iterable ensemble of all valid Titem.
Definition: pool_type.hpp:378
SLV_6
@ SLV_6
6.0 1721 6.1 1768
Definition: saveload.h:46
Save_PSAC
static void Save_PSAC()
Save persistent storage data.
Definition: storage_sl.cpp:37
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:299
SaveLoad
SaveLoad type struct.
Definition: saveload.h:517
SlIterateArray
int SlIterateArray()
Iterate through the elements of an array and read the whole thing.
Definition: saveload.cpp:631