Saveload: Adjust flags for saving using upstream chunks
This commit is contained in:
@@ -387,6 +387,9 @@ static void SlNullPointers()
|
||||
SlXvSetCurrentState();
|
||||
|
||||
for (auto &ch : ChunkHandlers()) {
|
||||
if (ch.special_proc != nullptr) {
|
||||
if (ch.special_proc(ch.id, CSLSO_PRE_PTRS) == CSLSOR_LOAD_CHUNK_CONSUMED) continue;
|
||||
}
|
||||
if (ch.ptrs_proc != nullptr) {
|
||||
DEBUG(sl, 3, "Nulling pointers for %c%c%c%c", ch.id >> 24, ch.id >> 16, ch.id >> 8, ch.id);
|
||||
ch.ptrs_proc();
|
||||
@@ -2312,7 +2315,10 @@ static void SlLoadCheckChunk(const ChunkHandler *ch)
|
||||
*/
|
||||
static void SlSaveChunk(const ChunkHandler &ch)
|
||||
{
|
||||
if (ch.type == CH_UPSTREAM_SAVE) {
|
||||
if (ch.special_proc != nullptr) {
|
||||
ChunkSaveLoadSpecialOpResult result = ch.special_proc(ch.id, CSLSO_SHOULD_SAVE_CHUNK);
|
||||
if (result == CSLSOR_DONT_SAVE_CHUNK) return;
|
||||
if (result == CSLSOR_UPSTREAM_SAVE_CHUNK) {
|
||||
SaveLoadVersion old_ver = _sl_version;
|
||||
_sl_version = MAX_LOAD_SAVEGAME_VERSION;
|
||||
auto guard = scope_guard([&]() {
|
||||
@@ -2321,16 +2327,13 @@ static void SlSaveChunk(const ChunkHandler &ch)
|
||||
upstream_sl::SlSaveChunkChunkByID(ch.id);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
ChunkSaveLoadProc *proc = ch.save_proc;
|
||||
|
||||
/* Don't save any chunk information if there is no save handler. */
|
||||
if (proc == nullptr) return;
|
||||
|
||||
if (ch.special_proc != nullptr) {
|
||||
if (ch.special_proc(ch.id, CSLSO_SHOULD_SAVE_CHUNK) == CSLSOR_DONT_SAVE_CHUNK) return;
|
||||
}
|
||||
|
||||
SlWriteUint32(ch.id);
|
||||
DEBUG(sl, 2, "Saving chunk %c%c%c%c", ch.id >> 24, ch.id >> 16, ch.id >> 8, ch.id);
|
||||
|
||||
@@ -2449,6 +2452,9 @@ static void SlFixPointers()
|
||||
_sl.action = SLA_PTRS;
|
||||
|
||||
for (auto &ch : ChunkHandlers()) {
|
||||
if (ch.special_proc != nullptr) {
|
||||
if (ch.special_proc(ch.id, CSLSO_PRE_PTRS) == CSLSOR_LOAD_CHUNK_CONSUMED) continue;
|
||||
}
|
||||
if (ch.ptrs_proc != nullptr) {
|
||||
DEBUG(sl, 3, "Fixing pointers for %c%c%c%c", ch.id >> 24, ch.id >> 16, ch.id >> 8, ch.id);
|
||||
ch.ptrs_proc();
|
||||
|
@@ -83,12 +83,14 @@ void SlUnreachablePlaceholder();
|
||||
enum ChunkSaveLoadSpecialOp {
|
||||
CSLSO_PRE_LOAD,
|
||||
CSLSO_PRE_LOADCHECK,
|
||||
CSLSO_PRE_PTRS,
|
||||
CSLSO_SHOULD_SAVE_CHUNK,
|
||||
};
|
||||
enum ChunkSaveLoadSpecialOpResult {
|
||||
CSLSOR_NONE,
|
||||
CSLSOR_LOAD_CHUNK_CONSUMED,
|
||||
CSLSOR_DONT_SAVE_CHUNK,
|
||||
CSLSOR_UPSTREAM_SAVE_CHUNK,
|
||||
};
|
||||
typedef ChunkSaveLoadSpecialOpResult ChunkSaveLoadSpecialProc(uint32, ChunkSaveLoadSpecialOp);
|
||||
|
||||
@@ -99,7 +101,7 @@ enum ChunkType {
|
||||
CH_SPARSE_ARRAY = 2,
|
||||
CH_EXT_HDR = 15, ///< Extended chunk header
|
||||
|
||||
CH_UPSTREAM_SAVE = 0x80,
|
||||
CH_UNUSED = 0x80,
|
||||
};
|
||||
|
||||
/** Handlers and description of chunk. */
|
||||
@@ -135,15 +137,11 @@ namespace upstream_sl {
|
||||
|
||||
ChunkHandler ch = {
|
||||
id,
|
||||
nullptr,
|
||||
SlUnreachablePlaceholder,
|
||||
[]() {
|
||||
SlExecWithSlVersion(F::GetLoadVersion(), []() {
|
||||
SlFixPointerChunkByID(id);
|
||||
});
|
||||
},
|
||||
SlUnreachablePlaceholder,
|
||||
CH_UPSTREAM_SAVE
|
||||
SlUnreachablePlaceholder,
|
||||
SlUnreachablePlaceholder,
|
||||
CH_UNUSED
|
||||
};
|
||||
ch.special_proc = [](uint32 chunk_id, ChunkSaveLoadSpecialOp op) -> ChunkSaveLoadSpecialOpResult {
|
||||
assert(id == chunk_id);
|
||||
@@ -158,6 +156,13 @@ namespace upstream_sl {
|
||||
SlLoadCheckChunkByID(id);
|
||||
});
|
||||
return CSLSOR_LOAD_CHUNK_CONSUMED;
|
||||
case CSLSO_PRE_PTRS:
|
||||
SlExecWithSlVersion(F::GetLoadVersion(), []() {
|
||||
SlFixPointerChunkByID(id);
|
||||
});
|
||||
return CSLSOR_LOAD_CHUNK_CONSUMED;
|
||||
case CSLSO_SHOULD_SAVE_CHUNK:
|
||||
return CSLSOR_UPSTREAM_SAVE_CHUNK;
|
||||
default:
|
||||
return CSLSOR_NONE;
|
||||
}
|
||||
|
Reference in New Issue
Block a user