Add: store headers for most savegame chunks

When a header is added, the chunk changes from CH_ARRAY type to
CH_TABLE type.
This commit is contained in:
Patric Stout
2021-05-30 15:59:40 +02:00
committed by Patric Stout
parent 7dd5fd6ed4
commit cdb3dd0493
57 changed files with 1410 additions and 289 deletions

View File

@@ -8,10 +8,12 @@
/** @file object_sl.cpp Code handling saving and loading of objects */
#include "../stdafx.h"
#include "../object_base.h"
#include "../object_map.h"
#include "saveload.h"
#include "compat/object_sl_compat.h"
#include "../object_base.h"
#include "../object_map.h"
#include "newgrf_sl.h"
#include "../safeguards.h"
@@ -29,6 +31,8 @@ static const SaveLoad _object_desc[] = {
static void Save_OBJS()
{
SlTableHeader(_object_desc);
/* Write the objects */
for (Object *o : Object::Iterate()) {
SlSetArrayIndex(o->index);
@@ -38,10 +42,12 @@ static void Save_OBJS()
static void Load_OBJS()
{
const std::vector<SaveLoad> slt = SlCompatTableHeader(_object_desc, _object_sl_compat);
int index;
while ((index = SlIterateArray()) != -1) {
Object *o = new (index) Object();
SlObject(o, _object_desc);
SlObject(o, slt);
}
}
@@ -67,8 +73,8 @@ static void Load_OBID()
}
static const ChunkHandler object_chunk_handlers[] = {
{ 'OBID', Save_OBID, Load_OBID, nullptr, nullptr, CH_ARRAY },
{ 'OBJS', Save_OBJS, Load_OBJS, Ptrs_OBJS, nullptr, CH_ARRAY },
{ 'OBID', Save_OBID, Load_OBID, nullptr, nullptr, CH_TABLE },
{ 'OBJS', Save_OBJS, Load_OBJS, Ptrs_OBJS, nullptr, CH_TABLE },
};
extern const ChunkHandlerTable _object_chunk_handlers(object_chunk_handlers);