12 #include "../stdafx.h" 13 #include "../linkgraph/linkgraph.h" 14 #include "../linkgraph/linkgraphjob.h" 15 #include "../linkgraph/linkgraphschedule.h" 16 #include "../settings_internal.h" 19 #include "../safeguards.h" 24 const SettingDesc *GetSettingDescription(uint index);
26 static uint16 _num_nodes;
34 static const SaveLoad link_graph_desc[] = {
40 return link_graph_desc;
55 static const char *prefix =
"linkgraph.";
58 if (saveloads.
Length() == 0) {
59 size_t offset_gamesettings = cpp_offsetof(
GameSettings, linkgraph);
60 size_t offset_component = cpp_offsetof(
LinkGraphJob, settings);
62 size_t prefixlen = strlen(prefix);
65 const SettingDesc *desc = GetSettingDescription(setting);
66 while (desc->
save.
cmd != SL_END) {
67 if (desc->
desc.
name != NULL && strncmp(desc->
desc.
name, prefix, prefixlen) == 0) {
69 char *&address =
reinterpret_cast<char *&
>(sl.
address);
70 address -= offset_gamesettings;
71 address += offset_component;
72 *(saveloads.
Append()) = sl;
74 desc = GetSettingDescription(++setting);
85 *(saveloads.
Append()) = job_desc[i++];
86 }
while (saveloads[saveloads.
Length() - 1].cmd != SL_END);
98 static const SaveLoad schedule_desc[] = {
103 return schedule_desc;
127 SLE_VAR(
Edge, last_unrestricted_update, SLE_INT32),
139 uint size = lg.
Size();
140 for (NodeID from = 0; from < size; ++from) {
145 for (NodeID to = 0; to < size; ++to) {
150 for (NodeID to = from; to != INVALID_NODE; to = lg.
edges[from][to].next_edge) {
164 _num_nodes = lgj->
Size();
175 _num_nodes = lg->
Size();
193 lg->
Init(_num_nodes);
234 FOR_ALL_LINK_GRAPHS(lg) {
235 for (NodeID node_id = 0; node_id < lg->
Size(); ++node_id) {
241 FOR_ALL_LINK_GRAPH_JOBS(lgj) {
243 for (NodeID node_id = 0; node_id < lg->
Size(); ++node_id) {
258 FOR_ALL_LINK_GRAPHS(lg) {
259 SlSetArrayIndex(lg->
index);
270 FOR_ALL_LINK_GRAPH_JOBS(lgj) {
271 SlSetArrayIndex(lgj->
index);
292 extern const ChunkHandler _linkgraph_chunk_handlers[] = {
#define SLE_CONDNULL(length, from, to)
Empty space in some savegame versions.
static void Load_LGRJ()
Load all link graph jobs.
const SaveLoad * GetLinkGraphDesc()
Get a SaveLoad array for a link graph.
static void DoSave_LGRJ(LinkGraphJob *lgj)
Save a link graph job.
An edge in the link graph.
static void Ptrs_LGRS()
Substitute pointers in link graph schedule.
All settings together for the game.
void SpawnAll()
Start all threads in the running list.
#define SLE_LST(base, variable, type)
Storage of a list in every savegame version.
Load/save a reference to a link graph job.
Tindex index
Index of this pool item.
void * address
address of variable OR offset of variable in the struct (max offset is 65536)
Simple vector template class.
#define SLEG_VAR(variable, type)
Storage of a global variable in every savegame version.
const char * name
name of the setting. Used in configuration file and for console
T * Append(uint to_add=1)
Append an item and return it.
static void Load_LGRS()
Load the link graph schedule.
A connected component of a link graph.
const SaveLoad * GetLinkGraphJobDesc()
Get a SaveLoad array for a link graph job.
SaveLoad save
Internal structure (going to savegame, parts to config)
uint Size() const
Get the current size of the component.
Functions/types related to saving and loading games.
#define SLE_CONDVAR(base, variable, type, from, to)
Storage of a variable in some savegame versions.
static const SaveLoad _node_desc[]
SaveLoad desc for a link graph node.
uint Length() const
Get the number of items in the list.
static void Save_LGRP()
Save all link graphs.
static LinkGraphSchedule instance
Static instance of LinkGraphSchedule.
static const SaveLoad _edge_desc[]
SaveLoad desc for a link graph edge.
static void Save_LGRJ()
Save all link graph jobs.
EdgeMatrix edges
Edges in the component.
const SaveLoad * GetLinkGraphScheduleDesc()
Get a SaveLoad array for the link graph schedule.
void AfterLoadLinkGraphs()
Spawn the threads for running link graph calculations.
#define SL_MAX_VERSION
Highest possible savegame version.
static bool IsSavegameVersionBefore(uint16 major, byte minor=0)
Checks whether the savegame is below major.
int SlIterateArray()
Iterate through the elements of an array and read the whole thing.
Handlers and description of chunk.
#define SLE_END()
End marker of a struct/class save or load.
void Init(uint size)
Resize the component and fill it with empty nodes and edges.
static void Save_LGRS()
Save the link graph schedule.
SaveLoadType cmd
the action to take with the saved/loaded type, All types need different action
void SlObject(void *object, const SaveLoad *sld)
Main SaveLoad function.
uint Size() const
Get the size of the underlying link graph.
const LinkGraph & Graph() const
Get a reference to the underlying link graph.
static bool CanAllocateItem(size_t n=1)
Helper functions so we can use PoolItem::Function() instead of _poolitem_pool.Function() ...
void SlAutolength(AutolengthProc *proc, void *arg)
Do something of which I have no idea what it is :P.
#define SLE_VAR(base, variable, type)
Storage of a variable in every version of a savegame.
static void Load_LGRP()
Load all link graphs.
Load/save a reference to a link graph.
static void DoSave_LGRP(LinkGraph *lg)
Save a link graph.
NodeVector nodes
Nodes in the component.
static Station * Get(size_t index)
Gets station with given index.
SettingDescBase desc
Settings structure (going to configuration file)
Class for calculation jobs to be run on link graphs.
Last chunk in this array.
void SaveLoad_LinkGraph(LinkGraph &lg)
Save/load a link graph.