summaryrefslogtreecommitdiff
path: root/src/saveload/saveload.h
diff options
context:
space:
mode:
authorglx22 <glx@openttd.org>2021-06-06 22:26:38 +0200
committerLoïc Guilloux <glx22@users.noreply.github.com>2021-07-06 22:29:08 +0200
commitf371a5ad705e10940612475cc697091914a2c96a (patch)
tree41541d31c70760dc5427ae9400b8b97803d93645 /src/saveload/saveload.h
parent7e7a4aad721f89c98a347a4d2104f6a01e8fbcaa (diff)
downloadopenttd-f371a5ad705e10940612475cc697091914a2c96a.tar.xz
Codechange: Preparation for ChunkHandler subclassing
Diffstat (limited to 'src/saveload/saveload.h')
-rw-r--r--src/saveload/saveload.h41
1 files changed, 41 insertions, 0 deletions
diff --git a/src/saveload/saveload.h b/src/saveload/saveload.h
index 34dea3cb1..381e355e0 100644
--- a/src/saveload/saveload.h
+++ b/src/saveload/saveload.h
@@ -407,6 +407,47 @@ struct ChunkHandler {
ChunkSaveLoadProc *ptrs_proc; ///< Manipulate pointers in the chunk.
ChunkSaveLoadProc *load_check_proc; ///< Load procedure for game preview.
ChunkType type; ///< Type of the chunk. @see ChunkType
+
+ bool fix_pointers = false;
+ bool load_check = false;
+
+ ChunkHandler(uint32 id, ChunkType type) : id(id), type(type) {}
+
+ ChunkHandler(uint32 id, ChunkSaveLoadProc *save_proc, ChunkSaveLoadProc *load_proc, ChunkSaveLoadProc *ptrs_proc, ChunkSaveLoadProc *load_check_proc, ChunkType type)
+ : id(id), save_proc(save_proc), load_proc(load_proc), ptrs_proc(ptrs_proc), load_check_proc(load_check_proc), type(type)
+ {
+ this->fix_pointers = ptrs_proc != nullptr;
+ this->load_check = load_check_proc != nullptr;
+ }
+
+ virtual ~ChunkHandler() {}
+
+ /**
+ * Save the chunk.
+ * Must be overridden, unless Chunk type is CH_READONLY.
+ */
+ virtual void Save() const;
+
+ /**
+ * Load the chunk.
+ * Must be overridden.
+ */
+ virtual void Load() const;
+
+ /**
+ * Fix the pointers.
+ * Pointers are saved using the index of the pointed object.
+ * On load, pointers are filled with indices and need to be fixed to point to the real object.
+ * Must be overridden if the chunk saves any pointer.
+ */
+ virtual void FixPointers() const;
+
+ /**
+ * Load the chunk for game preview.
+ * Default implementation just skips the data.
+ * @param len Number of bytes to skip.
+ */
+ virtual void LoadCheck(size_t len = 0) const;
};
/** A table of ChunkHandler entries. */