10 #include "../stdafx.h"
15 #include "../linkgraph/linkgraph.h"
16 #include "../linkgraph/linkgraphjob.h"
17 #include "../linkgraph/linkgraphschedule.h"
18 #include "../network/network.h"
19 #include "../settings_internal.h"
20 #include "../settings_table.h"
22 #include "../safeguards.h"
27 static uint16_t _num_nodes;
33 inline static const SaveLoad description[] = {
44 void Save(
Node *bn)
const override
52 void Load(
Node *bn)
const override
56 std::vector<Edge> edges(max_size);
60 for (NodeID to = 0; to < max_size; ++to) {
67 for (NodeID to =
_linkgraph_from; to != INVALID_NODE; to = edges[to].dest_node) {
68 if (used_size == 0)
SlErrorCorrupt(
"Link graph structure overflow");
71 if (to >= max_size)
SlErrorCorrupt(
"Link graph structure overflow");
79 for (NodeID to = edges[
_linkgraph_from].dest_node; to != INVALID_NODE; to = edges[to].dest_node) {
80 auto &edge = bn->
edges.emplace_back(edges[to]);
88 for (
size_t i = 0; i < size; i++) {
89 bn->
edges.emplace_back();
98 inline static const SaveLoad description[] = {
113 for (NodeID from = 0; from < lg->
Size(); ++from) {
125 for (NodeID from = 0; from < length; ++from) {
138 static const SaveLoad link_graph_desc[] = {
144 return link_graph_desc;
156 inline static const SaveLoad description[] = {{}};
182 static std::vector<SaveLoad> saveloads;
184 static const SaveLoad job_desc[] = {
192 static_assert(std::is_standard_layout<LinkGraphSettings>::value,
"LinkGraphSettings needs to be a standard layout type");
197 static SaveLoadAddrProc *
const proc = [](
void *b,
size_t extra) ->
void * {
return const_cast<void *
>(
static_cast<const void *
>(
reinterpret_cast<const char *
>(std::addressof(
static_cast<LinkGraphJob *
>(b)->
settings)) + extra)); };
200 if (saveloads.empty()) {
203 for (
auto &sl : saveloads) {
204 sl.address_proc = proc;
207 for (
auto &sld : job_desc) {
208 saveloads.push_back(sld);
221 static const SaveLoad schedule_desc[] = {
225 return schedule_desc;
236 for (NodeID node_id = 0; node_id < lg->Size(); ++node_id) {
238 if (st !=
nullptr) (*lg)[node_id].UpdateLocation(st->
xy);
244 for (NodeID node_id = 0; node_id < lg->
Size(); ++node_id) {
246 if (st !=
nullptr) (*lg)[node_id].UpdateLocation(st->
xy);
269 SlSetArrayIndex(lg->index);
297 SlSetArrayIndex(lgj->
index);
352 extern const ChunkHandlerTable _linkgraph_chunk_handlers(linkgraph_chunk_handlers);
Default handler for saving/loading an object to/from disk.
SaveLoadTable GetDescription() const override
Class for calculation jobs to be run on link graphs.
const LinkGraph & Graph() const
Get a reference to the underlying link graph.
static LinkGraphSchedule instance
Static instance of LinkGraphSchedule.
void SpawnAll()
Start all threads in the running list.
A connected component of a link graph.
void Init(uint size)
Resize the component and fill it with empty nodes and edges.
NodeVector nodes
Nodes in the component.
NodeID Size() const
Get the current size of the component.
SaveLoadTable GetLoadDescription() const
Get the description for how to load the chunk.
Proxy to reuse LinkGraph to save/load a LinkGraphJob.
SaveLoadTable GetDescription() const override
Get the description of the fields in the savegame.
fluid_settings_t * settings
FluidSynth settings handle.
SaveLoadTable GetLinkGraphDesc()
Get a SaveLoad array for a link graph.
SaveLoadTable GetLinkGraphScheduleDesc()
Get a SaveLoad array for the link graph schedule.
static LinkGraph * _linkgraph
Contains the current linkgraph being saved/loaded.
void AfterLoadLinkGraphs()
Spawn the threads for running link graph calculations.
SaveLoadTable GetLinkGraphJobDesc()
Get a SaveLoad array for a link graph job.
static NodeID _linkgraph_from
Contains the current "from" node being saved/loaded.
Loading of linkgraph chunks before table headers were added.
const SaveLoadCompat _linkgraph_node_sl_compat[]
Original field order for SlLinkgraphNode.
const SaveLoadCompat _linkgraph_edge_sl_compat[]
Original field order for SlLinkgraphEdge.
const SaveLoadCompat _linkgraph_schedule_sl_compat[]
Original field order for schedule_desc.
const SaveLoadCompat _linkgraph_job_sl_compat[]
Original field order for job_desc.
const SaveLoadCompat _linkgraph_sl_compat[]
Original field order for link_graph_desc.
void AfterLoad_LinkGraphPauseControl()
Pause the game on load if we would do a join with the next link graph job, but it is still running,...
bool _networking
are we in networking mode?
bool _network_server
network-server is active
size_t SlGetStructListLength(size_t limit)
Get the length of this list; if it exceeds the limit, error out.
int SlIterateArray()
Iterate through the elements of an array and read the whole thing.
void SlErrorCorrupt(const std::string &msg)
Error handler for corrupt savegames.
std::vector< SaveLoad > SlCompatTableHeader(const SaveLoadTable &slt, const SaveLoadCompatTable &slct)
Load a table header in a savegame compatible way.
std::vector< SaveLoad > SlTableHeader(const SaveLoadTable &slt)
Save or Load a table header.
void SlObject(void *object, const SaveLoadTable &slt)
Main SaveLoad function.
void SlSetStructListLength(size_t length)
Set the length of this list.
Functions/types related to saving and loading games.
#define SLEG_STRUCTLIST(name, handler)
Storage of a list of structs in every savegame version.
#define SLEG_CONDVAR(name, variable, type, from, to)
Storage of a global variable in some savegame versions.
std::reference_wrapper< const ChunkHandler > ChunkHandlerRef
A reference to ChunkHandler.
std::span< const ChunkHandlerRef > ChunkHandlerTable
A table of ChunkHandler entries.
#define SLE_REFLIST(base, variable, type)
Storage of a list of SL_REF elements in every savegame version.
std::span< const struct SaveLoadCompat > SaveLoadCompatTable
A table of SaveLoadCompat entries.
#define SLEG_STRUCT(name, handler)
Storage of a structs in every savegame version.
#define SLE_CONDVAR(base, variable, type, from, to)
Storage of a variable in some savegame versions.
bool IsSavegameVersionBefore(SaveLoadVersion major, uint8_t minor=0)
Checks whether the savegame is below major.
@ SLV_SAVELOAD_LIST_LENGTH
293 PR#9374 Consistency in list length with SL_STRUCT / SL_STRUCTLIST / SL_DEQUE / SL_REFLIST.
@ SLV_191
191 26636 FS#6026 Fix disaster vehicle storage (No bump) 191 26646 FS#6041 Linkgraph - store location...
@ SLV_RIFF_TO_ARRAY
294 PR#9375 Changed many CH_RIFF chunks to CH_ARRAY chunks.
@ SLV_LINKGRAPH_EDGES
304 PR#10314 Explicitly store link graph edges destination, PR#10471 int64_t instead of uint64_t leag...
@ SL_MAX_VERSION
Highest possible saveload version.
@ SL_MIN_VERSION
First savegame version.
@ SLV_187
187 25899 Linkgraph - restricted flows
@ SLV_LINKGRAPH_TRAVEL_TIME
297 PR#9457 v12.0-RC1 Store travel time in the linkgraph.
@ REF_LINK_GRAPH_JOB
Load/save a reference to a link graph job.
@ REF_LINK_GRAPH
Load/save a reference to a link graph.
std::span< const struct SaveLoad > SaveLoadTable
A table of SaveLoad entries.
#define SLE_VAR(base, variable, type)
Storage of a variable in every version of a savegame.
#define SLE_CONDVARNAME(base, variable, name, type, from, to)
Storage of a variable in some savegame versions.
void GetSaveLoadFromSettingTable(SettingTable settings, std::vector< SaveLoad > &saveloads)
Get the SaveLoad for all settings in the settings table.
TileIndex xy
Base tile of the station.
Handlers and description of chunk.
void Save() const override
Save the chunk.
void Load() const override
Load the chunk.
void Load() const override
Load the chunk.
void Save() const override
Save the chunk.
void FixPointers() const override
Fix the pointers.
void Load() const override
Load the chunk.
void Save() const override
Save the chunk.
An edge in the link graph.
std::vector< BaseEdge > edges
Sorted list of outgoing edges from this node.
Tindex index
Index of this pool item.
static Pool::IterateWrapper< Titem > Iterate(size_t from=0)
Returns an iterable ensemble of all valid Titem.
static Station * GetIfValid(size_t index)
Returns station if the index is a valid index for this station type.