summaryrefslogtreecommitdiff
path: root/src/saveload
diff options
context:
space:
mode:
authorfonsinchen <fonsinchen@openttd.org>2014-06-14 13:35:39 +0000
committerfonsinchen <fonsinchen@openttd.org>2014-06-14 13:35:39 +0000
commit957f5ca11758d556763881d04ced39cd34c470c1 (patch)
tree03a1c5061a2d4466526f39b637a0967333a5591f /src/saveload
parente8e5cdde034dcf5c3874790b5a9cd67ad300ee9d (diff)
downloadopenttd-957f5ca11758d556763881d04ced39cd34c470c1.tar.xz
(svn r26646) -Fix [FS#6041]: Save locations instead of distances in link graphs to reduce size.
Diffstat (limited to 'src/saveload')
-rw-r--r--src/saveload/linkgraph_sl.cpp54
-rw-r--r--src/saveload/saveload.cpp3
2 files changed, 42 insertions, 15 deletions
diff --git a/src/saveload/linkgraph_sl.cpp b/src/saveload/linkgraph_sl.cpp
index 4988eb2ed..20a3f4498 100644
--- a/src/saveload/linkgraph_sl.cpp
+++ b/src/saveload/linkgraph_sl.cpp
@@ -109,24 +109,25 @@ const SaveLoad *GetLinkGraphScheduleDesc()
* SaveLoad desc for a link graph node.
*/
static const SaveLoad _node_desc[] = {
- SLE_VAR(Node, supply, SLE_UINT32),
- SLE_VAR(Node, demand, SLE_UINT32),
- SLE_VAR(Node, station, SLE_UINT16),
- SLE_VAR(Node, last_update, SLE_INT32),
- SLE_END()
+ SLE_CONDVAR(Node, xy, SLE_UINT32, 191, SL_MAX_VERSION),
+ SLE_VAR(Node, supply, SLE_UINT32),
+ SLE_VAR(Node, demand, SLE_UINT32),
+ SLE_VAR(Node, station, SLE_UINT16),
+ SLE_VAR(Node, last_update, SLE_INT32),
+ SLE_END()
};
/**
* SaveLoad desc for a link graph edge.
*/
static const SaveLoad _edge_desc[] = {
- SLE_VAR(Edge, distance, SLE_UINT32),
- SLE_VAR(Edge, capacity, SLE_UINT32),
- SLE_VAR(Edge, usage, SLE_UINT32),
- SLE_VAR(Edge, last_unrestricted_update, SLE_INT32),
- SLE_CONDVAR(Edge, last_restricted_update, SLE_INT32, 187, SL_MAX_VERSION),
- SLE_VAR(Edge, next_edge, SLE_UINT16),
- SLE_END()
+ SLE_CONDNULL(4, 0, 190), // distance
+ SLE_VAR(Edge, capacity, SLE_UINT32),
+ SLE_VAR(Edge, usage, SLE_UINT32),
+ SLE_VAR(Edge, last_unrestricted_update, SLE_INT32),
+ SLE_CONDVAR(Edge, last_restricted_update, SLE_INT32, 187, SL_MAX_VERSION),
+ SLE_VAR(Edge, next_edge, SLE_UINT16),
+ SLE_END()
};
/**
@@ -139,8 +140,16 @@ void SaveLoad_LinkGraph(LinkGraph &lg)
for (NodeID from = 0; from < size; ++from) {
Node *node = &lg.nodes[from];
SlObject(node, _node_desc);
- for (NodeID to = 0; to < size; ++to) {
- SlObject(&lg.edges[from][to], _edge_desc);
+ if (IsSavegameVersionBefore(191)) {
+ /* We used to save the full matrix ... */
+ for (NodeID to = 0; to < size; ++to) {
+ SlObject(&lg.edges[from][to], _edge_desc);
+ }
+ } else {
+ /* ... but as that wasted a lot of space we save a sparse matrix now. */
+ for (NodeID to = from; to != INVALID_NODE; to = lg.edges[from][to].next_edge) {
+ SlObject(&lg.edges[from][to], _edge_desc);
+ }
}
}
}
@@ -220,6 +229,23 @@ static void Load_LGRS()
*/
void AfterLoadLinkGraphs()
{
+ if (IsSavegameVersionBefore(191)) {
+ LinkGraph *lg;
+ FOR_ALL_LINK_GRAPHS(lg) {
+ for (NodeID node_id = 0; node_id < lg->Size(); ++node_id) {
+ (*lg)[node_id].UpdateLocation(Station::Get((*lg)[node_id].Station())->xy);
+ }
+ }
+
+ LinkGraphJob *lgj;
+ FOR_ALL_LINK_GRAPH_JOBS(lgj) {
+ lg = &(const_cast<LinkGraph &>(lgj->Graph()));
+ for (NodeID node_id = 0; node_id < lg->Size(); ++node_id) {
+ (*lg)[node_id].UpdateLocation(Station::Get((*lg)[node_id].Station())->xy);
+ }
+ }
+ }
+
LinkGraphSchedule::Instance()->SpawnAll();
}
diff --git a/src/saveload/saveload.cpp b/src/saveload/saveload.cpp
index f3d2f6205..958ed46ac 100644
--- a/src/saveload/saveload.cpp
+++ b/src/saveload/saveload.cpp
@@ -258,8 +258,9 @@
* 188 26169 1.4.x
* 189 26450
* 190 26547
+ * 191 26646
*/
-extern const uint16 SAVEGAME_VERSION = 190; ///< Current savegame version of OpenTTD.
+extern const uint16 SAVEGAME_VERSION = 191; ///< Current savegame version of OpenTTD.
SavegameType _savegame_type; ///< type of savegame we are loading