Move upstream saveload to src/saveload/, move jgrpp saveload to src/sl/

Leave afterload in src/saveload/
This commit is contained in:
Jonathan G Rennison
2023-06-07 23:29:52 +01:00
parent 3c9ce6f9a5
commit ac2f9a21e8
181 changed files with 16887 additions and 16888 deletions

View File

@@ -8,63 +8,55 @@
/** @file newgrf_sl.cpp Code handling saving and loading of newgrf config */
#include "../stdafx.h"
#include "../fios.h"
#include "../string_func.h"
#include "saveload.h"
#include "compat/newgrf_sl_compat.h"
#include "newgrf_sl.h"
#include "../fios.h"
#include "../safeguards.h"
namespace upstream_sl {
/** Save and load the mapping between a spec and the NewGRF it came from. */
static const SaveLoad _newgrf_mapping_desc_old[] = {
static const SaveLoad _newgrf_mapping_desc[] = {
SLE_VAR(EntityIDMapping, grfid, SLE_UINT32),
SLE_VAR(EntityIDMapping, entity_id, SLE_FILE_U8 | SLE_VAR_U16),
SLE_VAR(EntityIDMapping, substitute_id, SLE_FILE_U8 | SLE_VAR_U16),
};
static const SaveLoad _newgrf_mapping_desc_new[] = {
SLE_VAR(EntityIDMapping, grfid, SLE_UINT32),
SLE_VAR(EntityIDMapping, entity_id, SLE_UINT16),
SLE_VAR(EntityIDMapping, substitute_id, SLE_UINT16),
SLE_CONDVAR(EntityIDMapping, entity_id, SLE_FILE_U8 | SLE_VAR_U16, SL_MIN_VERSION, SLV_EXTEND_ENTITY_MAPPING),
SLE_CONDVAR(EntityIDMapping, entity_id, SLE_UINT16, SLV_EXTEND_ENTITY_MAPPING, SL_MAX_VERSION),
SLE_CONDVAR(EntityIDMapping, substitute_id, SLE_FILE_U8 | SLE_VAR_U16, SL_MIN_VERSION, SLV_EXTEND_ENTITY_MAPPING),
SLE_CONDVAR(EntityIDMapping, substitute_id, SLE_UINT16, SLV_EXTEND_ENTITY_MAPPING, SL_MAX_VERSION),
};
/**
* Save a GRF ID + local id -> OpenTTD's id mapping.
* @param mapping The mapping to save.
*/
void Save_NewGRFMapping(const OverrideManagerBase &mapping)
void NewGRFMappingChunkHandler::Save() const
{
for (uint i = 0; i < mapping.GetMaxMapping(); i++) {
if (mapping.mappings[i].grfid == 0 &&
mapping.mappings[i].entity_id == 0) continue;
SlSetArrayIndex(i);
SlSetLength(4 + 2 + 2);
SlObjectSaveFiltered(const_cast<EntityIDMapping *>(&mapping.mappings[i]), _newgrf_mapping_desc_new); // _newgrf_mapping_desc_new has no conditionals
}
// removed
NOT_REACHED();
}
/**
* Load a GRF ID + local id -> OpenTTD's id mapping.
* @param mapping The mapping to load.
*/
void Load_NewGRFMapping(OverrideManagerBase &mapping)
void NewGRFMappingChunkHandler::Load() const
{
const std::vector<SaveLoad> slt = SlCompatTableHeader(_newgrf_mapping_desc, _newgrf_mapping_sl_compat);
/* Clear the current mapping stored.
* This will create the manager if ever it is not yet done */
mapping.ResetMapping();
this->mapping.ResetMapping();
uint max_id = mapping.GetMaxMapping();
SaveLoadTable slt = SlXvIsFeaturePresent(XSLFI_NEWGRF_ENTITY_EXTRA) ? SaveLoadTable(_newgrf_mapping_desc_new) : SaveLoadTable(_newgrf_mapping_desc_old);
uint max_id = this->mapping.GetMaxMapping();
int index;
while ((index = SlIterateArray()) != -1) {
if (unlikely((uint)index >= max_id)) SlErrorCorrupt("Too many NewGRF entity mappings");
SlObjectLoadFiltered(&mapping.mappings[index], slt); // _newgrf_mapping_desc_old/_newgrf_mapping_desc_new has no conditionals
if ((uint)index >= max_id) SlErrorCorrupt("Too many NewGRF entity mappings");
SlObject(&this->mapping.mappings[index], slt);
}
}
static std::string _grf_name;
static const SaveLoad _grfconfig_desc[] = {
SLE_SSTR(GRFConfig, filename, SLE_STR),
@@ -74,60 +66,66 @@ static const SaveLoad _grfconfig_desc[] = {
SLE_ARR(GRFConfig, param, SLE_UINT32, 0x80),
SLE_VAR(GRFConfig, num_params, SLE_UINT8),
SLE_CONDVAR(GRFConfig, palette, SLE_UINT8, SLV_101, SL_MAX_VERSION),
SLEG_CONDSSTR_X(_grf_name, 0, SL_MIN_VERSION, SL_MAX_VERSION, SlXvFeatureTest(XSLFTO_AND, XSLFI_NEWGRF_INFO_EXTRA)),
};
static void Save_NGRF()
{
int index = 0;
struct NGRFChunkHandler : ChunkHandler {
NGRFChunkHandler() : ChunkHandler('NGRF', CH_TABLE) {}
for (GRFConfig *c = _grfconfig; c != nullptr; c = c->next) {
if (HasBit(c->flags, GCF_STATIC) || HasBit(c->flags, GCF_INIT_ONLY)) continue;
SlSetArrayIndex(index++);
_grf_name = str_strip_all_scc(GetDefaultLangGRFStringFromGRFText(c->name));
SlObject(c, _grfconfig_desc);
}
}
void Save() const override
{
SlTableHeader(_grfconfig_desc);
int index = 0;
static void Load_NGRF_common(GRFConfig *&grfconfig)
{
ClearGRFConfigList(&grfconfig);
while (SlIterateArray() != -1) {
GRFConfig *c = new GRFConfig();
SlObject(c, _grfconfig_desc);
if (SlXvIsFeaturePresent(XSLFI_NEWGRF_INFO_EXTRA)) {
AddGRFTextToList(c->name, 0x7F, c->ident.grfid, false, _grf_name.c_str());
for (GRFConfig *c = _grfconfig; c != nullptr; c = c->next) {
if (HasBit(c->flags, GCF_STATIC) || HasBit(c->flags, GCF_INIT_ONLY)) continue;
SlSetArrayIndex(index++);
SlObject(c, _grfconfig_desc);
}
if (IsSavegameVersionBefore(SLV_101)) c->SetSuitablePalette();
AppendToGRFConfigList(&grfconfig, c);
}
}
static void Load_NGRF()
{
Load_NGRF_common(_grfconfig);
if (_game_mode == GM_MENU) {
/* Intro game must not have NewGRF. */
if (_grfconfig != nullptr) SlErrorCorrupt("The intro game must not use NewGRF");
void LoadCommon(GRFConfig *&grfconfig) const
{
const std::vector<SaveLoad> slt = SlCompatTableHeader(_grfconfig_desc, _grfconfig_sl_compat);
/* Activate intro NewGRFs (townnames) */
ResetGRFConfig(false);
} else {
/* Append static NewGRF configuration */
AppendStaticGRFConfigs(&_grfconfig);
ClearGRFConfigList(&grfconfig);
while (SlIterateArray() != -1) {
GRFConfig *c = new GRFConfig();
SlObject(c, slt);
if (IsSavegameVersionBefore(SLV_101)) c->SetSuitablePalette();
AppendToGRFConfigList(&grfconfig, c);
}
}
}
static void Check_NGRF()
{
Load_NGRF_common(_load_check_data.grfconfig);
}
void Load() const override
{
this->LoadCommon(_grfconfig);
static const ChunkHandler newgrf_chunk_handlers[] = {
{ 'NGRF', Save_NGRF, Load_NGRF, nullptr, Check_NGRF, CH_ARRAY }
if (_game_mode == GM_MENU) {
/* Intro game must not have NewGRF. */
if (_grfconfig != nullptr) SlErrorCorrupt("The intro game must not use NewGRF");
/* Activate intro NewGRFs (townnames) */
ResetGRFConfig(false);
} else {
/* Append static NewGRF configuration */
AppendStaticGRFConfigs(&_grfconfig);
}
}
void LoadCheck(size_t) const override
{
this->LoadCommon(_load_check_data.grfconfig);
}
};
static const NGRFChunkHandler NGRF;
static const ChunkHandlerRef newgrf_chunk_handlers[] = {
NGRF,
};
extern const ChunkHandlerTable _newgrf_chunk_handlers(newgrf_chunk_handlers);
}