(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
This commit is contained in:
smatz
2009-05-17 16:28:29 +00:00
parent 21e2842f34
commit 769de62daf
29 changed files with 231 additions and 99 deletions

View File

@@ -118,10 +118,9 @@ static const SaveLoad _station_speclist_desc[] = {
SLE_END()
};
void SaveLoad_STNS(Station *st)
const SaveLoad *GetGoodsDesc()
{
static const SaveLoad _goods_desc[] = {
static const SaveLoad goods_desc[] = {
SLEG_CONDVAR( _waiting_acceptance, SLE_UINT16, 0, 67),
SLE_CONDVAR(GoodsEntry, acceptance_pickup, SLE_UINT8, 68, SL_MAX_VERSION),
SLE_CONDNULL(2, 51, 67),
@@ -140,7 +139,12 @@ void SaveLoad_STNS(Station *st)
SLE_END()
};
return goods_desc;
}
static void SaveLoad_STNS(Station *st)
{
SlObject(st, _station_desc);
_waiting_acceptance = 0;
@@ -148,7 +152,7 @@ void SaveLoad_STNS(Station *st)
uint num_cargo = CheckSavegameVersion(55) ? 12 : NUM_CARGO;
for (CargoID i = 0; i < num_cargo; i++) {
GoodsEntry *ge = &st->goods[i];
SlObject(ge, _goods_desc);
SlObject(ge, GetGoodsDesc());
if (CheckSavegameVersion(68)) {
SB(ge->acceptance_pickup, GoodsEntry::ACCEPTANCE, 1, HasBit(_waiting_acceptance, 15));
if (GB(_waiting_acceptance, 0, 12) != 0) {
@@ -197,6 +201,21 @@ static void Load_STNS()
}
}
void Ptrs_STNS()
{
Station *st;
FOR_ALL_STATIONS(st) {
if (!CheckSavegameVersion(68)) {
for (CargoID i = 0; i < NUM_CARGO; i++) {
GoodsEntry *ge = &st->goods[i];
SlObject(ge, GetGoodsDesc());
}
}
SlObject(st, _station_desc);
}
}
static void Save_ROADSTOP()
{
RoadStop *rs;
@@ -218,7 +237,15 @@ static void Load_ROADSTOP()
}
}
static void Ptrs_ROADSTOP()
{
RoadStop *rs;
FOR_ALL_ROADSTOPS(rs) {
SlObject(rs, _roadstop_desc);
}
}
extern const ChunkHandler _station_chunk_handlers[] = {
{ 'STNS', Save_STNS, Load_STNS, CH_ARRAY },
{ 'ROAD', Save_ROADSTOP, Load_ROADSTOP, CH_ARRAY | CH_LAST},
{ 'STNS', Save_STNS, Load_STNS, Ptrs_STNS, CH_ARRAY },
{ 'ROAD', Save_ROADSTOP, Load_ROADSTOP, Ptrs_ROADSTOP, CH_ARRAY | CH_LAST},
};