OpenTTD Source
1.11.0-beta2
|
Go to the documentation of this file.
10 #include "../stdafx.h"
11 #include "../linkgraph/linkgraph.h"
12 #include "../linkgraph/linkgraphjob.h"
13 #include "../linkgraph/linkgraphschedule.h"
14 #include "../network/network.h"
15 #include "../settings_internal.h"
18 #include "../safeguards.h"
23 const SettingDesc *GetSettingDescription(uint index);
25 static uint16 _num_nodes;
33 static const SaveLoad link_graph_desc[] = {
39 return link_graph_desc;
53 static std::vector<SaveLoad> saveloads;
54 static const char *prefix =
"linkgraph.";
64 static_assert(std::is_standard_layout<LinkGraphSettings>::value,
"LinkGraphSettings needs to be a standard layout type");
69 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)); };
72 if (saveloads.size() == 0) {
73 size_t prefixlen = strlen(prefix);
76 const SettingDesc *desc = GetSettingDescription(setting);
77 while (desc->
save.
cmd != SL_END) {
78 if (desc->
desc.
name !=
nullptr && strncmp(desc->
desc.
name, prefix, prefixlen) == 0) {
81 saveloads.push_back(sl);
83 desc = GetSettingDescription(++setting);
88 saveloads.push_back(job_desc[i++]);
89 }
while (saveloads[saveloads.size() - 1].cmd != SL_END);
101 static const SaveLoad schedule_desc[] = {
106 return schedule_desc;
130 SLE_VAR(
Edge, last_unrestricted_update, SLE_INT32),
142 uint size = lg.
Size();
143 for (NodeID from = 0; from < size; ++from) {
148 for (NodeID to = 0; to < size; ++to) {
153 for (NodeID to = from; to != INVALID_NODE; to = lg.
edges[from][to].next_edge) {
167 _num_nodes = lgj->
Size();
178 _num_nodes = lg->
Size();
196 lg->
Init(_num_nodes);
237 for (NodeID node_id = 0; node_id < lg->Size(); ++node_id) {
239 if (st !=
nullptr) (*lg)[node_id].UpdateLocation(st->
xy);
245 for (NodeID node_id = 0; node_id < lg->
Size(); ++node_id) {
247 if (st !=
nullptr) (*lg)[node_id].UpdateLocation(st->
xy);
265 SlSetArrayIndex(lg->index);
276 SlSetArrayIndex(lgj->index);
297 extern const ChunkHandler _linkgraph_chunk_handlers[] = {
@ SLV_187
187 25899 Linkgraph - restricted flows
static void Save_LGRS()
Save the link graph schedule.
EdgeMatrix edges
Edges in the component.
A connected component of a link graph.
@ SL_MIN_VERSION
First savegame version.
static void Load_LGRS()
Load the link graph schedule.
NodeVector nodes
Nodes in the component.
Class for calculation jobs to be run on link graphs.
bool _network_server
network-server is active
SaveLoad save
Internal structure (going to savegame, parts to config)
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.
@ CH_LAST
Last chunk in this array.
void SaveLoad_LinkGraph(LinkGraph &lg)
Save/load a link graph.
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,...
static void Load_LGRJ()
Load all link graph jobs.
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.
#define SLE_CONDNULL(length, from, to)
Empty space in some savegame versions.
const LinkGraph & Graph() const
Get a reference to the underlying link graph.
const SaveLoad * GetLinkGraphJobDesc()
Get a SaveLoad array for a link graph job.
static void Save_LGRJ()
Save all link graph jobs.
#define SLE_END()
End marker of a struct/class save or load.
An edge in the link graph.
SaveLoadType cmd
the action to take with the saved/loaded type, All types need different action
uint Size() const
Get the current size of the component.
fluid_settings_t * settings
FluidSynth settings handle.
static bool IsSavegameVersionBefore(SaveLoadVersion major, byte minor=0)
Checks whether the savegame is below major.
bool _networking
are we in networking mode?
#define SLE_LST(base, variable, type)
Storage of a list in every savegame version.
void SlObject(void *object, const SaveLoad *sld)
Main SaveLoad function.
static void Save_LGRP()
Save all link graphs.
void SlAutolength(AutolengthProc *proc, void *arg)
Do something of which I have no idea what it is :P.
const SaveLoad * GetLinkGraphScheduleDesc()
Get a SaveLoad array for the link graph schedule.
@ SL_MAX_VERSION
Highest possible saveload version.
@ REF_LINK_GRAPH_JOB
Load/save a reference to a link graph job.
#define SLEG_VAR(variable, type)
Storage of a global variable in every savegame version.
uint Size() const
Get the size of the underlying link graph.
#define SLE_VAR(base, variable, type)
Storage of a variable in every version of a savegame.
static const SaveLoad _edge_desc[]
SaveLoad desc for a link graph edge.
static Pool::IterateWrapper< Titem > Iterate(size_t from=0)
Returns an iterable ensemble of all valid Titem.
void AfterLoadLinkGraphs()
Spawn the threads for running link graph calculations.
static const SaveLoad _node_desc[]
SaveLoad desc for a link graph node.
static bool CanAllocateItem(size_t n=1)
Helper functions so we can use PoolItem::Function() instead of _poolitem_pool.Function()
SettingDescBase desc
Settings structure (going to configuration file)
TileIndex xy
Base tile of the station.
static void Ptrs_LGRS()
Substitute pointers in link graph schedule.
@ REF_LINK_GRAPH
Load/save a reference to a link graph.
static void DoSave_LGRJ(LinkGraphJob *lgj)
Save a link graph job.
static Station * GetIfValid(size_t index)
Returns station if the index is a valid index for this station type.
const char * name
name of the setting. Used in configuration file and for console
@ SLV_191
191 26636 FS#6026 Fix disaster vehicle storage (No bump) 191 26646 FS#6041 Linkgraph - store location...
static void DoSave_LGRP(LinkGraph *lg)
Save a link graph.
SaveLoadAddrProc * address_proc
callback proc the get the actual variable address in memory
const SaveLoad * GetLinkGraphDesc()
Get a SaveLoad array for a link graph.
static void Load_LGRP()
Load all link graphs.
int SlIterateArray()
Iterate through the elements of an array and read the whole thing.