Move upstream saveload to src/saveload/, move jgrpp saveload to src/sl/
Leave afterload in src/saveload/
This commit is contained in:
@@ -8,21 +8,115 @@
|
||||
/** @file linkgraph_sl.cpp Code handling saving and loading of link graphs */
|
||||
|
||||
#include "../stdafx.h"
|
||||
|
||||
#include "saveload.h"
|
||||
#include "compat/linkgraph_sl_compat.h"
|
||||
|
||||
#include "../linkgraph/linkgraph.h"
|
||||
#include "../linkgraph/linkgraphjob.h"
|
||||
#include "../linkgraph/linkgraphschedule.h"
|
||||
#include "../network/network.h"
|
||||
#include "../settings_internal.h"
|
||||
#include "saveload.h"
|
||||
|
||||
#include "../safeguards.h"
|
||||
|
||||
namespace upstream_sl {
|
||||
|
||||
typedef LinkGraph::BaseNode Node;
|
||||
typedef LinkGraph::BaseEdge Edge;
|
||||
|
||||
const SettingDesc *GetSettingDescription(uint index);
|
||||
|
||||
static uint16 _num_nodes;
|
||||
static LinkGraph *_linkgraph; ///< Contains the current linkgraph being saved/loaded.
|
||||
static NodeID _linkgraph_from; ///< Contains the current "from" node being saved/loaded.
|
||||
static NodeID _edge_dest_node;
|
||||
static NodeID _edge_next_edge;
|
||||
|
||||
class SlLinkgraphEdge : public DefaultSaveLoadHandler<SlLinkgraphEdge, Node> {
|
||||
public:
|
||||
inline static const SaveLoad description[] = {
|
||||
SLE_VAR(Edge, capacity, SLE_UINT32),
|
||||
SLE_VAR(Edge, usage, SLE_UINT32),
|
||||
SLE_CONDVAR(Edge, travel_time_sum, SLE_UINT64, SLV_LINKGRAPH_TRAVEL_TIME, SL_MAX_VERSION),
|
||||
SLE_VAR(Edge, last_unrestricted_update, SLE_INT32),
|
||||
SLE_CONDVAR(Edge, last_restricted_update, SLE_INT32, SLV_187, SL_MAX_VERSION),
|
||||
SLEG_VAR("dest_node", _edge_dest_node, SLE_UINT16),
|
||||
SLEG_CONDVAR("next_edge", _edge_next_edge, SLE_UINT16, SL_MIN_VERSION, SLV_LINKGRAPH_EDGES),
|
||||
};
|
||||
inline const static SaveLoadCompatTable compat_description = _linkgraph_edge_sl_compat;
|
||||
|
||||
void Save(Node *bn) const override
|
||||
{
|
||||
NOT_REACHED();
|
||||
}
|
||||
|
||||
void Load(Node *bn) const override
|
||||
{
|
||||
uint16 max_size = _linkgraph->Size();
|
||||
|
||||
if (IsSavegameVersionBefore(SLV_191)) {
|
||||
NOT_REACHED();
|
||||
}
|
||||
|
||||
if (IsSavegameVersionBefore(SLV_LINKGRAPH_EDGES)) {
|
||||
size_t used_size = IsSavegameVersionBefore(SLV_SAVELOAD_LIST_LENGTH) ? max_size : SlGetStructListLength(UINT16_MAX);
|
||||
|
||||
/* ... but as that wasted a lot of space we save a sparse matrix now. */
|
||||
for (NodeID to = _linkgraph_from; to != INVALID_NODE; to = _edge_next_edge) {
|
||||
if (used_size == 0) SlErrorCorrupt("Link graph structure overflow");
|
||||
used_size--;
|
||||
|
||||
if (to >= max_size) SlErrorCorrupt("Link graph structure overflow");
|
||||
SlObject(&_linkgraph->edges[std::make_pair(_linkgraph_from, to)], this->GetLoadDescription());
|
||||
}
|
||||
|
||||
if (!IsSavegameVersionBefore(SLV_SAVELOAD_LIST_LENGTH) && used_size > 0) SlErrorCorrupt("Corrupted link graph");
|
||||
} else {
|
||||
/* Edge data is now a simple vector and not any kind of matrix. */
|
||||
size_t size = SlGetStructListLength(UINT16_MAX);
|
||||
for (size_t i = 0; i < size; i++) {
|
||||
Edge edge;
|
||||
SlObject(&edge, this->GetLoadDescription());
|
||||
if (_edge_dest_node >= max_size) SlErrorCorrupt("Link graph structure overflow");
|
||||
_linkgraph->edges[std::make_pair(_linkgraph_from, _edge_dest_node)] = edge;
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
class SlLinkgraphNode : public DefaultSaveLoadHandler<SlLinkgraphNode, LinkGraph> {
|
||||
public:
|
||||
inline static const SaveLoad description[] = {
|
||||
SLE_CONDVAR(Node, xy, SLE_UINT32, SLV_191, SL_MAX_VERSION),
|
||||
SLE_VAR(Node, supply, SLE_UINT32),
|
||||
SLE_VAR(Node, demand, SLE_UINT32),
|
||||
SLE_VAR(Node, station, SLE_UINT16),
|
||||
SLE_VAR(Node, last_update, SLE_INT32),
|
||||
SLEG_STRUCTLIST("edges", SlLinkgraphEdge),
|
||||
};
|
||||
inline const static SaveLoadCompatTable compat_description = _linkgraph_node_sl_compat;
|
||||
|
||||
void Save(LinkGraph *lg) const override
|
||||
{
|
||||
_linkgraph = lg;
|
||||
|
||||
SlSetStructListLength(lg->Size());
|
||||
for (NodeID from = 0; from < lg->Size(); ++from) {
|
||||
_linkgraph_from = from;
|
||||
SlObject(&lg->nodes[from], this->GetDescription());
|
||||
}
|
||||
}
|
||||
|
||||
void Load(LinkGraph *lg) const override
|
||||
{
|
||||
_linkgraph = lg;
|
||||
|
||||
uint16 length = IsSavegameVersionBefore(SLV_SAVELOAD_LIST_LENGTH) ? _num_nodes : (uint16)SlGetStructListLength(UINT16_MAX);
|
||||
lg->Init(length);
|
||||
for (NodeID from = 0; from < length; ++from) {
|
||||
_linkgraph_from = from;
|
||||
SlObject(&lg->nodes[from], this->GetLoadDescription());
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Get a SaveLoad array for a link graph.
|
||||
@@ -32,18 +126,36 @@ SaveLoadTable GetLinkGraphDesc()
|
||||
{
|
||||
static const SaveLoad link_graph_desc[] = {
|
||||
SLE_VAR(LinkGraph, last_compression, SLE_INT32),
|
||||
SLEG_VAR(_num_nodes, SLE_UINT16),
|
||||
SLEG_CONDVAR("num_nodes", _num_nodes, SLE_UINT16, SL_MIN_VERSION, SLV_SAVELOAD_LIST_LENGTH),
|
||||
SLE_VAR(LinkGraph, cargo, SLE_UINT8),
|
||||
SLEG_STRUCTLIST("nodes", SlLinkgraphNode),
|
||||
};
|
||||
return link_graph_desc;
|
||||
}
|
||||
|
||||
void GetLinkGraphJobDayLengthScaleAfterLoad(LinkGraphJob *lgj)
|
||||
{
|
||||
lgj->join_date_ticks *= DAY_TICKS;
|
||||
lgj->join_date_ticks += LinkGraphSchedule::SPAWN_JOIN_TICK;
|
||||
lgj->start_date_ticks = lgj->join_date_ticks - (lgj->Settings().recalc_time * DAY_TICKS);
|
||||
}
|
||||
/**
|
||||
* Proxy to reuse LinkGraph to save/load a LinkGraphJob.
|
||||
* One of the members of a LinkGraphJob is a LinkGraph, but SLEG_STRUCT()
|
||||
* doesn't allow us to select a member. So instead, we add a bit of glue to
|
||||
* accept a LinkGraphJob, get the LinkGraph, and use that to call the
|
||||
* save/load routines for a regular LinkGraph.
|
||||
*/
|
||||
class SlLinkgraphJobProxy : public DefaultSaveLoadHandler<SlLinkgraphJobProxy, LinkGraphJob> {
|
||||
public:
|
||||
inline static const SaveLoad description[] = {{}}; // Needed to keep DefaultSaveLoadHandler happy.
|
||||
SaveLoadTable GetDescription() const override { return GetLinkGraphDesc(); }
|
||||
inline const static SaveLoadCompatTable compat_description = _linkgraph_sl_compat;
|
||||
|
||||
void Save(LinkGraphJob *lgj) const override
|
||||
{
|
||||
SlObject(const_cast<LinkGraph *>(&lgj->Graph()), this->GetDescription());
|
||||
}
|
||||
|
||||
void Load(LinkGraphJob *lgj) const override
|
||||
{
|
||||
SlObject(const_cast<LinkGraph *>(&lgj->Graph()), this->GetLoadDescription());
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Get a SaveLoad array for a link graph job. The settings struct is derived from
|
||||
@@ -56,43 +168,24 @@ void GetLinkGraphJobDayLengthScaleAfterLoad(LinkGraphJob *lgj)
|
||||
*/
|
||||
SaveLoadTable GetLinkGraphJobDesc()
|
||||
{
|
||||
static std::vector<SaveLoad> saveloads;
|
||||
static const char *prefix = "linkgraph.";
|
||||
static const SaveLoad job_desc[] = {
|
||||
SLE_VAR2(LinkGraphJob, "linkgraph.recalc_interval", settings.recalc_interval, SLE_UINT16),
|
||||
SLE_VAR2(LinkGraphJob, "linkgraph.recalc_time", settings.recalc_time, SLE_UINT16),
|
||||
SLE_VAR2(LinkGraphJob, "linkgraph.distribution_pax", settings.distribution_pax, SLE_UINT8),
|
||||
SLE_VAR2(LinkGraphJob, "linkgraph.distribution_mail", settings.distribution_mail, SLE_UINT8),
|
||||
SLE_VAR2(LinkGraphJob, "linkgraph.distribution_armoured", settings.distribution_armoured, SLE_UINT8),
|
||||
SLE_VAR2(LinkGraphJob, "linkgraph.distribution_default", settings.distribution_default, SLE_UINT8),
|
||||
SLE_VAR2(LinkGraphJob, "linkgraph.accuracy", settings.accuracy, SLE_UINT8),
|
||||
SLE_VAR2(LinkGraphJob, "linkgraph.demand_distance", settings.demand_distance, SLE_UINT8),
|
||||
SLE_VAR2(LinkGraphJob, "linkgraph.demand_size", settings.demand_size, SLE_UINT8),
|
||||
SLE_VAR2(LinkGraphJob, "linkgraph.short_path_saturation", settings.short_path_saturation, SLE_UINT8),
|
||||
|
||||
/* Build the SaveLoad array on first call and don't touch it later on */
|
||||
if (saveloads.size() == 0) {
|
||||
size_t offset_gamesettings = cpp_offsetof(GameSettings, linkgraph);
|
||||
size_t offset_component = cpp_offsetof(LinkGraphJob, settings);
|
||||
SLE_VAR2(LinkGraphJob, "join_date", join_date_ticks, SLE_INT32),
|
||||
SLE_VAR(LinkGraphJob, link_graph.index, SLE_UINT16),
|
||||
SLEG_STRUCT("linkgraph", SlLinkgraphJobProxy),
|
||||
};
|
||||
|
||||
size_t prefixlen = strlen(prefix);
|
||||
|
||||
int setting = 0;
|
||||
const SettingDesc *desc = GetSettingDescription(setting);
|
||||
while (desc != nullptr) {
|
||||
if (desc->name != nullptr && strncmp(desc->name, prefix, prefixlen) == 0) {
|
||||
SaveLoad sl = desc->save;
|
||||
if (GetVarMemType(sl.conv) != SLE_VAR_NULL) {
|
||||
char *&address = reinterpret_cast<char *&>(sl.address);
|
||||
address -= offset_gamesettings;
|
||||
address += offset_component;
|
||||
}
|
||||
saveloads.push_back(sl);
|
||||
}
|
||||
desc = GetSettingDescription(++setting);
|
||||
}
|
||||
|
||||
const SaveLoad job_desc[] = {
|
||||
SLE_VAR(LinkGraphJob, join_date_ticks, SLE_INT32),
|
||||
SLE_CONDVAR_X(LinkGraphJob, start_date_ticks, SLE_INT32, SL_MIN_VERSION, SL_MAX_VERSION, SlXvFeatureTest(XSLFTO_AND, XSLFI_LINKGRAPH_DAY_SCALE)),
|
||||
SLE_VAR(LinkGraphJob, link_graph.index, SLE_UINT16),
|
||||
};
|
||||
|
||||
for (auto &sld : job_desc) {
|
||||
saveloads.push_back(sld);
|
||||
}
|
||||
}
|
||||
|
||||
return saveloads;
|
||||
return job_desc;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -108,190 +201,6 @@ SaveLoadTable GetLinkGraphScheduleDesc()
|
||||
return schedule_desc;
|
||||
}
|
||||
|
||||
/* Edges and nodes are saved in the correct order, so we don't need to save their IDs. */
|
||||
|
||||
/**
|
||||
* SaveLoad desc for a link graph node.
|
||||
*/
|
||||
static const SaveLoad _node_desc[] = {
|
||||
SLE_CONDVAR(Node, xy, SLE_UINT32, SLV_191, SL_MAX_VERSION),
|
||||
SLE_VAR(Node, supply, SLE_UINT32),
|
||||
SLE_VAR(Node, demand, SLE_UINT32),
|
||||
SLE_VAR(Node, station, SLE_UINT16),
|
||||
SLE_VAR(Node, last_update, SLE_INT32),
|
||||
};
|
||||
|
||||
/**
|
||||
* SaveLoad desc for a link graph edge.
|
||||
*/
|
||||
static const SaveLoad _edge_desc[] = {
|
||||
SLE_CONDNULL(4, SL_MIN_VERSION, SLV_191), // distance
|
||||
SLE_VAR(Edge, capacity, SLE_UINT32),
|
||||
SLE_VAR(Edge, usage, SLE_UINT32),
|
||||
SLE_CONDVAR_X(Edge, travel_time_sum, SLE_UINT64, SL_MIN_VERSION, SL_MAX_VERSION, SlXvFeatureTest(XSLFTO_AND, XSLFI_LINKGRAPH_TRAVEL_TIME)),
|
||||
SLE_VAR(Edge, last_unrestricted_update, SLE_INT32),
|
||||
SLE_CONDVAR(Edge, last_restricted_update, SLE_INT32, SLV_187, SL_MAX_VERSION),
|
||||
SLE_CONDVAR_X(Edge, last_aircraft_update, SLE_INT32, SL_MIN_VERSION, SL_MAX_VERSION, SlXvFeatureTest(XSLFTO_AND, XSLFI_LINKGRAPH_AIRCRAFT)),
|
||||
// SLE_VAR(Edge, next_edge, SLE_UINT16), // Removed since XSLFI_LINKGRAPH_SPARSE_EDGES
|
||||
};
|
||||
|
||||
std::vector<SaveLoad> _filtered_node_desc;
|
||||
std::vector<SaveLoad> _filtered_edge_desc;
|
||||
std::vector<SaveLoad> _filtered_job_desc;
|
||||
|
||||
static void FilterDescs()
|
||||
{
|
||||
_filtered_node_desc = SlFilterObject(_node_desc);
|
||||
_filtered_edge_desc = SlFilterObject(_edge_desc);
|
||||
_filtered_job_desc = SlFilterObject(GetLinkGraphJobDesc());
|
||||
}
|
||||
|
||||
/**
|
||||
* Save a link graph.
|
||||
* @param lg Link graph to be saved or loaded.
|
||||
*/
|
||||
void Save_LinkGraph(LinkGraph &lg)
|
||||
{
|
||||
uint16 size = lg.Size();
|
||||
auto edge_iter = lg.edges.begin();
|
||||
auto edge_end = lg.edges.end();
|
||||
for (NodeID from = 0; from < size; ++from) {
|
||||
Node *node = &lg.nodes[from];
|
||||
SlObjectSaveFiltered(node, _filtered_node_desc);
|
||||
|
||||
while (edge_iter != edge_end && edge_iter->first.first == from) {
|
||||
SlWriteUint16(edge_iter->first.second);
|
||||
Edge *edge = &edge_iter->second;
|
||||
SlObjectSaveFiltered(edge, _filtered_edge_desc);
|
||||
++edge_iter;
|
||||
}
|
||||
SlWriteUint16(INVALID_NODE);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Load a link graph.
|
||||
* @param lg Link graph to be saved or loaded.
|
||||
*/
|
||||
void Load_LinkGraph(LinkGraph &lg)
|
||||
{
|
||||
uint size = lg.Size();
|
||||
if (SlXvIsFeaturePresent(XSLFI_LINKGRAPH_SPARSE_EDGES)) {
|
||||
for (NodeID from = 0; from < size; ++from) {
|
||||
Node *node = &lg.nodes[from];
|
||||
SlObjectLoadFiltered(node, _filtered_node_desc);
|
||||
while (true) {
|
||||
NodeID to = SlReadUint16();
|
||||
if (to == INVALID_NODE) break;
|
||||
SlObjectLoadFiltered(&lg.edges[std::make_pair(from, to)], _filtered_edge_desc);
|
||||
}
|
||||
}
|
||||
} else if (IsSavegameVersionBefore(SLV_191)) {
|
||||
std::vector<Edge> temp_edges;
|
||||
std::vector<NodeID> temp_next_edges;
|
||||
temp_edges.resize(size);
|
||||
temp_next_edges.resize(size);
|
||||
for (NodeID from = 0; from < size; ++from) {
|
||||
Node *node = &lg.nodes[from];
|
||||
SlObjectLoadFiltered(node, _filtered_node_desc);
|
||||
/* We used to save the full matrix ... */
|
||||
for (NodeID to = 0; to < size; ++to) {
|
||||
SlObjectLoadFiltered(&temp_edges[to], _filtered_edge_desc);
|
||||
temp_next_edges[to] = SlReadUint16();
|
||||
}
|
||||
for (NodeID to = from; to != INVALID_NODE; to = temp_next_edges[to]) {
|
||||
lg.edges[std::make_pair(from, to)] = temp_edges[to];
|
||||
}
|
||||
}
|
||||
} else {
|
||||
for (NodeID from = 0; from < size; ++from) {
|
||||
Node *node = &lg.nodes[from];
|
||||
SlObjectLoadFiltered(node, _filtered_node_desc);
|
||||
/* ... but as that wasted a lot of space we save a sparse matrix now. */
|
||||
for (NodeID to = from; to != INVALID_NODE;) {
|
||||
if (to >= size) SlErrorCorrupt("Link graph structure overflow");
|
||||
SlObjectLoadFiltered(&lg.edges[std::make_pair(from, to)], _filtered_edge_desc);
|
||||
to = SlReadUint16();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Save a link graph job.
|
||||
* @param lgj LinkGraphJob to be saved.
|
||||
*/
|
||||
static void DoSave_LGRJ(LinkGraphJob *lgj)
|
||||
{
|
||||
SlObjectSaveFiltered(lgj, _filtered_job_desc);
|
||||
_num_nodes = lgj->Size();
|
||||
SlObjectSaveFiltered(const_cast<LinkGraph *>(&lgj->Graph()), GetLinkGraphDesc()); // GetLinkGraphDesc has no conditionals
|
||||
Save_LinkGraph(const_cast<LinkGraph &>(lgj->Graph()));
|
||||
}
|
||||
|
||||
/**
|
||||
* Save a link graph.
|
||||
* @param lg LinkGraph to be saved.
|
||||
*/
|
||||
static void DoSave_LGRP(LinkGraph *lg)
|
||||
{
|
||||
_num_nodes = lg->Size();
|
||||
SlObjectSaveFiltered(lg, GetLinkGraphDesc()); // GetLinkGraphDesc has no conditionals
|
||||
Save_LinkGraph(*lg);
|
||||
}
|
||||
|
||||
/**
|
||||
* Load all link graphs.
|
||||
*/
|
||||
static void Load_LGRP()
|
||||
{
|
||||
FilterDescs();
|
||||
int index;
|
||||
while ((index = SlIterateArray()) != -1) {
|
||||
if (!LinkGraph::CanAllocateItem()) {
|
||||
/* Impossible as they have been present in previous game. */
|
||||
NOT_REACHED();
|
||||
}
|
||||
LinkGraph *lg = new (index) LinkGraph();
|
||||
SlObjectLoadFiltered(lg, GetLinkGraphDesc()); // GetLinkGraphDesc has no conditionals
|
||||
lg->Init(_num_nodes);
|
||||
Load_LinkGraph(*lg);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Load all link graph jobs.
|
||||
*/
|
||||
static void Load_LGRJ()
|
||||
{
|
||||
FilterDescs();
|
||||
int index;
|
||||
while ((index = SlIterateArray()) != -1) {
|
||||
if (!LinkGraphJob::CanAllocateItem()) {
|
||||
/* Impossible as they have been present in previous game. */
|
||||
NOT_REACHED();
|
||||
}
|
||||
LinkGraphJob *lgj = new (index) LinkGraphJob();
|
||||
SlObjectLoadFiltered(lgj, _filtered_job_desc);
|
||||
if (SlXvIsFeatureMissing(XSLFI_LINKGRAPH_DAY_SCALE)) {
|
||||
extern void GetLinkGraphJobDayLengthScaleAfterLoad(LinkGraphJob *lgj);
|
||||
GetLinkGraphJobDayLengthScaleAfterLoad(lgj);
|
||||
}
|
||||
LinkGraph &lg = const_cast<LinkGraph &>(lgj->Graph());
|
||||
SlObjectLoadFiltered(&lg, GetLinkGraphDesc()); // GetLinkGraphDesc has no conditionals
|
||||
lg.Init(_num_nodes);
|
||||
Load_LinkGraph(lg);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Load the link graph schedule.
|
||||
*/
|
||||
static void Load_LGRS()
|
||||
{
|
||||
SlObject(&LinkGraphSchedule::instance, GetLinkGraphScheduleDesc());
|
||||
}
|
||||
|
||||
/**
|
||||
* Spawn the threads for running link graph calculations.
|
||||
* Has to be done after loading as the cargo classes might have changed.
|
||||
@@ -314,6 +223,9 @@ void AfterLoadLinkGraphs()
|
||||
}
|
||||
}
|
||||
}
|
||||
for (LinkGraphJob *lgj : LinkGraphJob::Iterate()) {
|
||||
GetLinkGraphJobDayLengthScaleAfterLoad(lgj);
|
||||
}
|
||||
|
||||
LinkGraphSchedule::instance.SpawnAll();
|
||||
|
||||
@@ -323,49 +235,99 @@ void AfterLoadLinkGraphs()
|
||||
}
|
||||
|
||||
/**
|
||||
* Save all link graphs.
|
||||
* All link graphs.
|
||||
*/
|
||||
static void Save_LGRP()
|
||||
{
|
||||
FilterDescs();
|
||||
for (LinkGraph *lg : LinkGraph::Iterate()) {
|
||||
SlSetArrayIndex(lg->index);
|
||||
SlAutolength((AutolengthProc*)DoSave_LGRP, lg);
|
||||
struct LGRPChunkHandler : ChunkHandler {
|
||||
LGRPChunkHandler() : ChunkHandler('LGRP', CH_TABLE) {}
|
||||
|
||||
void Save() const override
|
||||
{
|
||||
SlTableHeader(GetLinkGraphDesc());
|
||||
|
||||
for (LinkGraph *lg : LinkGraph::Iterate()) {
|
||||
SlSetArrayIndex(lg->index);
|
||||
SlObject(lg, GetLinkGraphDesc());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Save all link graph jobs.
|
||||
*/
|
||||
static void Save_LGRJ()
|
||||
{
|
||||
FilterDescs();
|
||||
for (LinkGraphJob *lgj : LinkGraphJob::Iterate()) {
|
||||
SlSetArrayIndex(lgj->index);
|
||||
SlAutolength((AutolengthProc*)DoSave_LGRJ, lgj);
|
||||
void Load() const override
|
||||
{
|
||||
const std::vector<SaveLoad> slt = SlCompatTableHeader(GetLinkGraphDesc(), _linkgraph_sl_compat);
|
||||
|
||||
int index;
|
||||
while ((index = SlIterateArray()) != -1) {
|
||||
LinkGraph *lg = new (index) LinkGraph();
|
||||
SlObject(lg, slt);
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Save the link graph schedule.
|
||||
* All link graph jobs.
|
||||
*/
|
||||
static void Save_LGRS()
|
||||
{
|
||||
SlObject(&LinkGraphSchedule::instance, GetLinkGraphScheduleDesc());
|
||||
}
|
||||
struct LGRJChunkHandler : ChunkHandler {
|
||||
LGRJChunkHandler() : ChunkHandler('LGRJ', CH_TABLE) {}
|
||||
|
||||
void Save() const override
|
||||
{
|
||||
SlTableHeader(GetLinkGraphJobDesc());
|
||||
|
||||
for (LinkGraphJob *lgj : LinkGraphJob::Iterate()) {
|
||||
SlSetArrayIndex(lgj->index);
|
||||
SlObject(lgj, GetLinkGraphJobDesc());
|
||||
}
|
||||
}
|
||||
|
||||
void Load() const override
|
||||
{
|
||||
const std::vector<SaveLoad> slt = SlCompatTableHeader(GetLinkGraphJobDesc(), _linkgraph_job_sl_compat);
|
||||
|
||||
int index;
|
||||
while ((index = SlIterateArray()) != -1) {
|
||||
LinkGraphJob *lgj = new (index) LinkGraphJob();
|
||||
SlObject(lgj, slt);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Substitute pointers in link graph schedule.
|
||||
* Link graph schedule.
|
||||
*/
|
||||
static void Ptrs_LGRS()
|
||||
{
|
||||
SlObject(&LinkGraphSchedule::instance, GetLinkGraphScheduleDesc());
|
||||
}
|
||||
struct LGRSChunkHandler : ChunkHandler {
|
||||
LGRSChunkHandler() : ChunkHandler('LGRS', CH_TABLE) {}
|
||||
|
||||
static const ChunkHandler linkgraph_chunk_handlers[] = {
|
||||
{ 'LGRP', Save_LGRP, Load_LGRP, nullptr, nullptr, CH_ARRAY },
|
||||
{ 'LGRJ', Save_LGRJ, Load_LGRJ, nullptr, nullptr, CH_ARRAY },
|
||||
{ 'LGRS', Save_LGRS, Load_LGRS, Ptrs_LGRS, nullptr, CH_RIFF }
|
||||
void Save() const override
|
||||
{
|
||||
SlTableHeader(GetLinkGraphScheduleDesc());
|
||||
|
||||
SlSetArrayIndex(0);
|
||||
SlObject(&LinkGraphSchedule::instance, GetLinkGraphScheduleDesc());
|
||||
}
|
||||
|
||||
void Load() const override
|
||||
{
|
||||
const std::vector<SaveLoad> slt = SlCompatTableHeader(GetLinkGraphScheduleDesc(), _linkgraph_schedule_sl_compat);
|
||||
|
||||
if (!IsSavegameVersionBefore(SLV_RIFF_TO_ARRAY) && SlIterateArray() == -1) return;
|
||||
SlObject(&LinkGraphSchedule::instance, slt);
|
||||
if (!IsSavegameVersionBefore(SLV_RIFF_TO_ARRAY) && SlIterateArray() != -1) SlErrorCorrupt("Too many LGRS entries");
|
||||
}
|
||||
|
||||
void FixPointers() const override
|
||||
{
|
||||
SlObject(&LinkGraphSchedule::instance, GetLinkGraphScheduleDesc());
|
||||
}
|
||||
};
|
||||
|
||||
static const LGRPChunkHandler LGRP;
|
||||
static const LGRJChunkHandler LGRJ;
|
||||
static const LGRSChunkHandler LGRS;
|
||||
static const ChunkHandlerRef linkgraph_chunk_handlers[] = {
|
||||
LGRP,
|
||||
LGRJ,
|
||||
LGRS,
|
||||
};
|
||||
|
||||
extern const ChunkHandlerTable _linkgraph_chunk_handlers(linkgraph_chunk_handlers);
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user