| 50 | } |
| 51 | |
| 52 | void Load(Node *bn) const override |
| 53 | { |
| 54 | if (IsSavegameVersionBefore(SLV_LINKGRAPH_EDGES)) { |
| 55 | uint16_t max_size = _linkgraph->Size(); |
| 56 | std::vector<Edge> edges(max_size); |
| 57 | |
| 58 | if (IsSavegameVersionBefore(SLV_191)) { |
| 59 | /* We used to save the full matrix ... */ |
| 60 | for (NodeID to = 0; to < max_size; ++to) { |
| 61 | SlObject(&edges[to], this->GetLoadDescription()); |
| 62 | } |
| 63 | } else { |
| 64 | size_t used_size = IsSavegameVersionBefore(SLV_SAVELOAD_LIST_LENGTH) ? max_size : SlGetStructListLength(UINT16_MAX); |
| 65 | |
| 66 | /* ... but as that wasted a lot of space we save a sparse matrix now. */ |
| 67 | for (NodeID to = _linkgraph_from; to != INVALID_NODE; to = edges[to].dest_node) { |
| 68 | if (used_size == 0) SlErrorCorrupt("Link graph structure overflow"); |
| 69 | used_size--; |
| 70 | |
| 71 | if (to >= max_size) SlErrorCorrupt("Link graph structure overflow"); |
| 72 | SlObject(&edges[to], this->GetLoadDescription()); |
| 73 | } |
| 74 | |
| 75 | if (!IsSavegameVersionBefore(SLV_SAVELOAD_LIST_LENGTH) && used_size > 0) SlErrorCorrupt("Corrupted link graph"); |
| 76 | } |
| 77 | |
| 78 | /* Build edge list from edge matrix. */ |
| 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]); |
| 81 | edge.dest_node = to; |
| 82 | } |
| 83 | /* Sort by destination. */ |
| 84 | std::sort(bn->edges.begin(), bn->edges.end()); |
| 85 | } else { |
| 86 | /* Edge data is now a simple vector and not any kind of matrix. */ |
| 87 | size_t size = SlGetStructListLength(UINT16_MAX); |
| 88 | for (size_t i = 0; i < size; i++) { |
| 89 | auto &edge = bn->edges.emplace_back(); |
| 90 | SlObject(&edge, this->GetLoadDescription()); |
| 91 | } |
| 92 | } |
| 93 | } |
| 94 | }; |
| 95 | |
| 96 | class SlLinkgraphNode : public DefaultSaveLoadHandler<SlLinkgraphNode, LinkGraph> { |
nothing calls this directly
no test coverage detected