OpenTTD Source
20240919-master-gdf0233f4c2
|
Go to the documentation of this file.
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 bn->
edges.push_back(edges[to]);
81 bn->
edges.back().dest_node = 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.
#define SLE_REFLIST(base, variable, type)
Storage of a list of SL_REF elements in every savegame version.
A connected component of a link graph.
std::span< const struct SaveLoad > SaveLoadTable
A table of SaveLoad entries.
@ SLV_191
191 26636 FS#6026 Fix disaster vehicle storage (No bump) 191 26646 FS#6041 Linkgraph - store location...
NodeVector nodes
Nodes in the component.
std::reference_wrapper< const ChunkHandler > ChunkHandlerRef
A reference to ChunkHandler.
const SaveLoadCompat _linkgraph_node_sl_compat[]
Original field order for SlLinkgraphNode.
#define SLE_CONDVARNAME(base, variable, name, type, from, to)
Storage of a variable in some savegame versions.
Class for calculation jobs to be run on link graphs.
@ SL_MIN_VERSION
First savegame version.
bool _network_server
network-server is active
static LinkGraphSchedule instance
Static instance of LinkGraphSchedule.
Tindex index
Index of this pool item.
#define SLE_CONDVAR(base, variable, type, from, to)
Storage of a variable in some savegame versions.
void SlErrorCorrupt(const std::string &msg)
Error handler for corrupt savegames.
SaveLoadTable GetLoadDescription() const
Get the description for how to load the chunk.
@ SLV_187
187 25899 Linkgraph - restricted flows
std::span< const struct SaveLoadCompat > SaveLoadCompatTable
A table of SaveLoadCompat entries.
const SaveLoadCompat _linkgraph_schedule_sl_compat[]
Original field order for schedule_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,...
NodeID Size() const
Get the current size of the component.
void SpawnAll()
Start all threads in the running list.
Handlers and description of chunk.
void Init(uint size)
Resize the component and fill it with empty nodes and edges.
const LinkGraph & Graph() const
Get a reference to the underlying link graph.
SaveLoadTable GetLinkGraphJobDesc()
Get a SaveLoad array for a link graph job.
SaveLoadTable GetDescription() const override
Get the description of the fields in the savegame.
void Save() const override
Save the chunk.
void FixPointers() const override
Fix the pointers.
@ SLV_LINKGRAPH_TRAVEL_TIME
297 PR#9457 v12.0-RC1 Store travel time in the linkgraph.
An edge in the link graph.
@ SLV_SAVELOAD_LIST_LENGTH
293 PR#9374 Consistency in list length with SL_STRUCT / SL_STRUCTLIST / SL_DEQUE / SL_REFLIST.
fluid_settings_t * settings
FluidSynth settings handle.
void Load() const override
Load the chunk.
bool _networking
are we in networking mode?
@ SLV_RIFF_TO_ARRAY
294 PR#9375 Changed many CH_RIFF chunks to CH_ARRAY chunks.
@ SL_MAX_VERSION
Highest possible saveload version.
std::vector< BaseEdge > edges
Sorted list of outgoing edges from this node.
size_t SlGetStructListLength(size_t limit)
Get the length of this list; if it exceeds the limit, error out.
const SaveLoadCompat _linkgraph_job_sl_compat[]
Original field order for job_desc.
@ REF_LINK_GRAPH_JOB
Load/save a reference to a link graph job.
void Save() const override
Save the chunk.
#define SLE_VAR(base, variable, type)
Storage of a variable in every version of a savegame.
static Pool::IterateWrapper< Titem > Iterate(size_t from=0)
Returns an iterable ensemble of all valid Titem.
#define SLEG_CONDVAR(name, variable, type, from, to)
Storage of a global variable in some savegame versions.
void AfterLoadLinkGraphs()
Spawn the threads for running link graph calculations.
SaveLoadTable GetDescription() const override
void Save() const override
Save the chunk.
std::span< const ChunkHandlerRef > ChunkHandlerTable
A table of ChunkHandler entries.
TileIndex xy
Base tile of the station.
Proxy to reuse LinkGraph to save/load a LinkGraphJob.
const SaveLoadCompat _linkgraph_edge_sl_compat[]
Original field order for SlLinkgraphEdge.
@ REF_LINK_GRAPH
Load/save a reference to a link graph.
static Station * GetIfValid(size_t index)
Returns station if the index is a valid index for this station type.
SaveLoadTable GetLinkGraphScheduleDesc()
Get a SaveLoad array for the link graph schedule.
std::vector< SaveLoad > SlCompatTableHeader(const SaveLoadTable &slt, const SaveLoadCompatTable &slct)
Load a table header in a savegame compatible way.
void Load() const override
Load the chunk.
SaveLoadTable GetLinkGraphDesc()
Get a SaveLoad array for a link graph.
void SlObject(void *object, const SaveLoadTable &slt)
Main SaveLoad function.
bool IsSavegameVersionBefore(SaveLoadVersion major, uint8_t minor=0)
Checks whether the savegame is below major.
std::vector< SaveLoad > SlTableHeader(const SaveLoadTable &slt)
Save or Load a table header.
void Load() const override
Load the chunk.
void SlSetStructListLength(size_t length)
Set the length of this list.
@ SLV_LINKGRAPH_EDGES
304 PR#10314 Explicitly store link graph edges destination, PR#10471 int64_t instead of uint64_t leag...
static LinkGraph * _linkgraph
Contains the current linkgraph being saved/loaded.
void GetSaveLoadFromSettingTable(SettingTable settings, std::vector< SaveLoad > &saveloads)
Get the SaveLoad for all settings in the settings table.
const SaveLoadCompat _linkgraph_sl_compat[]
Original field order for link_graph_desc.
int SlIterateArray()
Iterate through the elements of an array and read the whole thing.
static NodeID _linkgraph_from
Contains the current "from" node being saved/loaded.
#define SLEG_STRUCTLIST(name, handler)
Storage of a list of structs in every savegame version.
#define SLEG_STRUCT(name, handler)
Storage of a structs in every savegame version.