summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorPatric Stout <truebrain@openttd.org>2021-06-14 14:03:03 +0200
committerPatric Stout <github@truebrain.nl>2021-06-14 21:58:05 +0200
commit5cd0c65787a4c04bbb2294cf2e676eb5649e49fe (patch)
treec918eb2e5723d782891510a571da15533647907c /src
parentaf3aba7a8830ad19fbb32819cd74ff4d5d7f51c5 (diff)
downloadopenttd-5cd0c65787a4c04bbb2294cf2e676eb5649e49fe.tar.xz
Codechange: move Save/Load functions of same chunk next to each other
Diffstat (limited to 'src')
-rw-r--r--src/saveload/linkgraph_sl.cpp126
1 files changed, 63 insertions, 63 deletions
diff --git a/src/saveload/linkgraph_sl.cpp b/src/saveload/linkgraph_sl.cpp
index 0640dba19..4fcc36e96 100644
--- a/src/saveload/linkgraph_sl.cpp
+++ b/src/saveload/linkgraph_sl.cpp
@@ -144,15 +144,33 @@ void SaveLoad_LinkGraph(LinkGraph &lg)
}
/**
- * Save a link graph job.
- * @param lgj LinkGraphJob to be saved.
+ * Spawn the threads for running link graph calculations.
+ * Has to be done after loading as the cargo classes might have changed.
*/
-static void DoSave_LGRJ(LinkGraphJob *lgj)
+void AfterLoadLinkGraphs()
{
- SlObject(lgj, GetLinkGraphJobDesc());
- _num_nodes = lgj->Size();
- SlObject(const_cast<LinkGraph *>(&lgj->Graph()), GetLinkGraphDesc());
- SaveLoad_LinkGraph(const_cast<LinkGraph &>(lgj->Graph()));
+ if (IsSavegameVersionBefore(SLV_191)) {
+ for (LinkGraph *lg : LinkGraph::Iterate()) {
+ for (NodeID node_id = 0; node_id < lg->Size(); ++node_id) {
+ const Station *st = Station::GetIfValid((*lg)[node_id].Station());
+ if (st != nullptr) (*lg)[node_id].UpdateLocation(st->xy);
+ }
+ }
+
+ for (LinkGraphJob *lgj : LinkGraphJob::Iterate()) {
+ LinkGraph *lg = &(const_cast<LinkGraph &>(lgj->Graph()));
+ for (NodeID node_id = 0; node_id < lg->Size(); ++node_id) {
+ const Station *st = Station::GetIfValid((*lg)[node_id].Station());
+ if (st != nullptr) (*lg)[node_id].UpdateLocation(st->xy);
+ }
+ }
+ }
+
+ LinkGraphSchedule::instance.SpawnAll();
+
+ if (!_networking || _network_server) {
+ AfterLoad_LinkGraphPauseControl();
+ }
}
/**
@@ -167,6 +185,17 @@ static void DoSave_LGRP(LinkGraph *lg)
}
/**
+ * Save all link graphs.
+ */
+static void Save_LGRP()
+{
+ for (LinkGraph *lg : LinkGraph::Iterate()) {
+ SlSetArrayIndex(lg->index);
+ SlAutolength((AutolengthProc*)DoSave_LGRP, lg);
+ }
+}
+
+/**
* Load all link graphs.
*/
static void Load_LGRP()
@@ -185,6 +214,29 @@ static void Load_LGRP()
}
/**
+ * Save a link graph job.
+ * @param lgj LinkGraphJob to be saved.
+ */
+static void DoSave_LGRJ(LinkGraphJob *lgj)
+{
+ SlObject(lgj, GetLinkGraphJobDesc());
+ _num_nodes = lgj->Size();
+ SlObject(const_cast<LinkGraph *>(&lgj->Graph()), GetLinkGraphDesc());
+ SaveLoad_LinkGraph(const_cast<LinkGraph &>(lgj->Graph()));
+}
+
+/**
+ * Save all link graph jobs.
+ */
+static void Save_LGRJ()
+{
+ for (LinkGraphJob *lgj : LinkGraphJob::Iterate()) {
+ SlSetArrayIndex(lgj->index);
+ SlAutolength((AutolengthProc*)DoSave_LGRJ, lgj);
+ }
+}
+
+/**
* Load all link graph jobs.
*/
static void Load_LGRJ()
@@ -205,69 +257,17 @@ static void Load_LGRJ()
}
/**
- * Load the link graph schedule.
+ * Save the link graph schedule.
*/
-static void Load_LGRS()
+static void Save_LGRS()
{
SlObject(&LinkGraphSchedule::instance, GetLinkGraphScheduleDesc());
}
/**
- * Spawn the threads for running link graph calculations.
- * Has to be done after loading as the cargo classes might have changed.
- */
-void AfterLoadLinkGraphs()
-{
- if (IsSavegameVersionBefore(SLV_191)) {
- for (LinkGraph *lg : LinkGraph::Iterate()) {
- for (NodeID node_id = 0; node_id < lg->Size(); ++node_id) {
- const Station *st = Station::GetIfValid((*lg)[node_id].Station());
- if (st != nullptr) (*lg)[node_id].UpdateLocation(st->xy);
- }
- }
-
- for (LinkGraphJob *lgj : LinkGraphJob::Iterate()) {
- LinkGraph *lg = &(const_cast<LinkGraph &>(lgj->Graph()));
- for (NodeID node_id = 0; node_id < lg->Size(); ++node_id) {
- const Station *st = Station::GetIfValid((*lg)[node_id].Station());
- if (st != nullptr) (*lg)[node_id].UpdateLocation(st->xy);
- }
- }
- }
-
- LinkGraphSchedule::instance.SpawnAll();
-
- if (!_networking || _network_server) {
- AfterLoad_LinkGraphPauseControl();
- }
-}
-
-/**
- * Save all link graphs.
- */
-static void Save_LGRP()
-{
- for (LinkGraph *lg : LinkGraph::Iterate()) {
- SlSetArrayIndex(lg->index);
- SlAutolength((AutolengthProc*)DoSave_LGRP, lg);
- }
-}
-
-/**
- * Save all link graph jobs.
- */
-static void Save_LGRJ()
-{
- for (LinkGraphJob *lgj : LinkGraphJob::Iterate()) {
- SlSetArrayIndex(lgj->index);
- SlAutolength((AutolengthProc*)DoSave_LGRJ, lgj);
- }
-}
-
-/**
- * Save the link graph schedule.
+ * Load the link graph schedule.
*/
-static void Save_LGRS()
+static void Load_LGRS()
{
SlObject(&LinkGraphSchedule::instance, GetLinkGraphScheduleDesc());
}