27static uint16_t _num_nodes;
33 static inline const SaveLoad description[] = {
44 void Save(Node *bn)
const override
47 for (Edge &e : bn->
edges) {
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 auto &edge = bn->
edges.emplace_back();
98 static inline 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;
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);
261struct LGRPChunkHandler : ChunkHandler {
269 SlSetArrayIndex(lg->index);
289struct LGRJChunkHandler : ChunkHandler {
297 SlSetArrayIndex(lgj->index);
317struct LGRSChunkHandler : ChunkHandler {
352extern 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.
LinkGraphSchedule()
Create a link graph schedule and initialize its handlers.
GraphList schedule
Queue for new jobs.
static LinkGraphSchedule instance
Static instance of LinkGraphSchedule.
JobList running
Currently running jobs.
A connected component of a link graph.
void Init(uint size)
Resize the component and fill it with empty nodes and edges.
CargoType cargo
Cargo of this component's link graph.
NodeVector nodes
Nodes in the component.
NodeID Size() const
Get the current size of the component.
LinkGraph(LinkGraphID index, CargoType cargo=INVALID_CARGO)
Real constructor.
TimerGameEconomy::Date last_compression
Last time the capacities and supplies were compressed.
SaveLoadTable GetLoadDescription() const
Get the description for how to load the chunk.
void Save(Node *bn) const override
Save the object to disk.
void Load(Node *bn) const override
Load the object from disk.
Proxy to reuse LinkGraph to save/load a LinkGraphJob.
SaveLoadTable GetDescription() const override
Get the description of the fields in the savegame.
void Save(LinkGraphJob *lgj) const override
Save the object to disk.
void Load(LinkGraphJob *lgj) const override
Load the object from disk.
static const SaveLoad description[]
Needed to keep DefaultSaveLoadHandler happy.
void Save(LinkGraph *lg) const override
Save the object to disk.
void Load(LinkGraph *lg) const override
Load the object from disk.
fluid_settings_t * settings
FluidSynth settings handle.
Declaration of link graph classes used for cargo distribution.
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.
Declaration of link graph job classes used for cargo distribution.
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,...
Declaration of link graph schedule used for cargo distribution.
bool _networking
are we in networking mode?
bool _network_server
network-server is active
Basic functions/variables used all over the place.
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.
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.
void SlObject(void *object, const SaveLoadTable &slt)
Main SaveLoad function.
std::vector< SaveLoad > SlTableHeader(const SaveLoadTable &slt)
Save or Load a table header.
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.
@ LinkGraph
Load/save a reference to a link graph.
@ LinkGraphJob
Load/save a reference to a link graph job.
std::span< const ChunkHandlerRef > ChunkHandlerTable
A table of ChunkHandler entries.
#define SLE_REFLIST(base, variable, type)
Storage of a list of SaveLoadType::Reference 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.
@ LinkgraphRestrictedFlow
Saveload version: 187, SVN revision: 25899 Linkgraph - restricted flows.
@ LinkgraphEdges
Saveload version: 304, GitHub pull request: 10314 Explicitly store link graph edges destination,...
@ LinkgraphLocationDisasterStore
Saveload version: 191, SVN revision: 26636, 26646 Fix disaster vehicle storage, Linkgraph - store lo...
@ LinkgraphTravelTime
Saveload version: 297, GitHub pull request: 9457, release: 12.0-RC1 Store travel time in the linkgra...
@ MinVersion
First savegame version.
@ SaveloadListLength
Saveload version: 293, GitHub pull request: 9374 Consistency in list length with SaveLoadType::Struc...
@ MaxVersion
Highest possible saveload version.
@ RiffToArray
Saveload version: 294, GitHub pull request: 9375 Changed many ChunkType::Riff chunks to ChunkType::A...
std::span< const struct SaveLoad > SaveLoadTable
A table of SaveLoad entries.
@ Table
An Array with a header describing the elements.
#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.
Functions and types used internally for the settings configurations.
Definition of the configuration tables of the settings.
Definition of base types and functions in a cross-platform compatible way.
TileIndex xy
Base tile of the station.
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.
static Pool::IterateWrapper< LinkGraph > Iterate(size_t from=0)
static T * CreateAtIndex(LinkGraphID index, Targs &&... args)
static Station * GetIfValid(auto index)
static constexpr VarType U16
Store a 16 bits unsigned int.
static constexpr VarType U8
Store a 8 bits unsigned int.
static constexpr VarType U64
Store a 64 bits unsigned int.
static constexpr VarType U32
Store a 32 bits unsigned int.
static constexpr VarType I32
Store a 32 bits signed int.