OpenTTD Source 20260711-master-g3fb3006dff
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 <https://www.gnu.org/licenses/old-licenses/gpl-2.0>.
6 */
7
9
10#include "../stdafx.h"
11
12#include "saveload.h"
14
15#include "../newgrf_storage.h"
16
17#include "../safeguards.h"
18
25
27struct PSACChunkHandler : ChunkHandler {
28 PSACChunkHandler() : ChunkHandler('PSAC', ChunkType::Table) {}
29
30 void Load() const override
31 {
32 const std::vector<SaveLoad> slt = SlCompatTableHeader(_storage_desc, _storage_sl_compat);
33
34 int index;
35
36 while ((index = SlIterateArray()) != -1) {
39 SlObject(ps, slt);
40 }
41 }
42
43 void Save() const override
44 {
46
47 /* Write the industries */
49 ps->ClearChanges();
50 SlSetArrayIndex(ps->index);
52 }
53 }
54};
55
56static const PSACChunkHandler PSAC;
57static const ChunkHandlerRef persistent_storage_chunk_handlers[] = {
58 PSAC,
59};
60
61extern const ChunkHandlerTable _persistent_storage_chunk_handlers(persistent_storage_chunk_handlers);
@ Invalid
An invalid spec feature.
Definition newgrf.h:109
Functionality related to the temporary and persistent storage arrays for NewGRFs.
A number of safeguards to prevent using unsafe methods.
std::vector< SaveLoad > SlCompatTableHeader(const SaveLoadTable &slt, const SaveLoadCompatTable &slct)
Load a table header in a savegame compatible way.
int SlIterateArray()
Iterate through the elements of an array and read the whole thing.
Definition saveload.cpp:734
void SlObject(void *object, const SaveLoadTable &slt)
Main SaveLoad function.
std::vector< SaveLoad > SlTableHeader(const SaveLoadTable &slt)
Save or Load a table header.
Functions/types related to saving and loading games.
std::reference_wrapper< const ChunkHandler > ChunkHandlerRef
A reference to ChunkHandler.
Definition saveload.h:530
std::span< const ChunkHandlerRef > ChunkHandlerTable
A table of ChunkHandler entries.
Definition saveload.h:533
#define SLE_CONDARR(base, variable, type, length, from, to)
Storage of a fixed-size array of SaveLoadType::Variable elements in some savegame versions.
Definition saveload.h:936
#define SLE_CONDVAR(base, variable, type, from, to)
Storage of a variable in some savegame versions.
Definition saveload.h:904
@ MultipleRoadStops
Saveload version: 6.0, SVN revision: 1721 Multi tile road stops, and some map size related fixes.
Definition saveload.h:47
@ MaxVersion
Highest possible saveload version.
Definition saveload.h:421
@ PersistentStoragePool
Saveload version: 161, SVN revision: 22567 Store persistent storage in a pool.
Definition saveload.h:237
@ ExtendPersistentStorage
Saveload version: 201, GitHub pull request: 6885 Extend NewGRF persistent storages.
Definition saveload.h:285
@ Table
An Array with a header describing the elements.
Definition saveload.h:475
Definition of base types and functions in a cross-platform compatible way.
static const SaveLoad _storage_desc[]
Description of the data to save and load in PersistentStorage.
Loading of storage chunks before table headers were added.
const SaveLoadCompat _storage_sl_compat[]
Original field order for _storage_desc.
Persistent storage data.
void Save() const override
Save the chunk.
void Load() const override
Load the chunk.
Class for pooled persistent storage of data.
static Pool::IterateWrapper< PersistentStorage > Iterate(size_t from=0)
static T * CreateAtIndex(PersistentStorageID index, Targs &&... args)
SaveLoad type struct.
Definition saveload.h:787
static constexpr VarType U32
Store a 32 bits unsigned int.
Definition saveload.h:756
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.
Definition tile_type.h:92