summaryrefslogtreecommitdiff
path: root/src/saveload/order_sl.cpp
diff options
context:
space:
mode:
authorsmatz <smatz@openttd.org>2009-05-17 16:28:29 +0000
committersmatz <smatz@openttd.org>2009-05-17 16:28:29 +0000
commit570af0ce449b6c94427233d7eae07c40bb789197 (patch)
tree81450baf6a65200503c2871c31e586ac5214d054 /src/saveload/order_sl.cpp
parent83dc6ef6e6064441c9a5ebc22061de313147821a (diff)
downloadopenttd-570af0ce449b6c94427233d7eae07c40bb789197.tar.xz
(svn r16338) -Codechange: split loading of references to two phases
In the first phase, indexes are stored. In the second phase, indexes are checked for validity and converted to pointers
Diffstat (limited to 'src/saveload/order_sl.cpp')
-rw-r--r--src/saveload/order_sl.cpp30
1 files changed, 26 insertions, 4 deletions
diff --git a/src/saveload/order_sl.cpp b/src/saveload/order_sl.cpp
index c7c66e130..6325b3cca 100644
--- a/src/saveload/order_sl.cpp
+++ b/src/saveload/order_sl.cpp
@@ -121,7 +121,7 @@ static void Load_ORDR()
{
if (CheckSavegameVersionOldStyle(5, 2)) {
/* Version older than 5.2 did not have a ->next pointer. Convert them
- (in the old days, the orderlist was 5000 items big) */
+ * (in the old days, the orderlist was 5000 items big) */
size_t len = SlGetFieldLength();
uint i;
@@ -170,6 +170,17 @@ static void Load_ORDR()
}
}
+static void Ptrs_ORDR()
+{
+ if (CheckSavegameVersionOldStyle(5, 2)) return;
+
+ Order *o;
+
+ FOR_ALL_ORDERS(o) {
+ SlObject(o, GetOrderDescription());
+ }
+}
+
const SaveLoad *GetOrderListDescription()
{
static const SaveLoad _orderlist_desc[] = {
@@ -195,12 +206,23 @@ static void Load_ORDL()
int index;
while ((index = SlIterateArray()) != -1) {
- OrderList *list = new (index) OrderList();
+ /* set num_orders to 0 so it's a valid OrderList */
+ OrderList *list = new (index) OrderList(0);
+ SlObject(list, GetOrderListDescription());
+ }
+
+}
+
+static void Ptrs_ORDL()
+{
+ OrderList *list;
+
+ FOR_ALL_ORDER_LISTS(list) {
SlObject(list, GetOrderListDescription());
}
}
extern const ChunkHandler _order_chunk_handlers[] = {
- { 'ORDR', Save_ORDR, Load_ORDR, CH_ARRAY},
- { 'ORDL', Save_ORDL, Load_ORDL, CH_ARRAY | CH_LAST},
+ { 'ORDR', Save_ORDR, Load_ORDR, Ptrs_ORDR, CH_ARRAY},
+ { 'ORDL', Save_ORDL, Load_ORDL, Ptrs_ORDL, CH_ARRAY | CH_LAST},
};