From 570af0ce449b6c94427233d7eae07c40bb789197 Mon Sep 17 00:00:00 2001 From: smatz Date: Sun, 17 May 2009 16:28:29 +0000 Subject: (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 --- src/saveload/order_sl.cpp | 30 ++++++++++++++++++++++++++---- 1 file changed, 26 insertions(+), 4 deletions(-) (limited to 'src/saveload/order_sl.cpp') 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}, }; -- cgit v1.2.3-54-g00ecf