summaryrefslogtreecommitdiff
path: root/src/saveload
diff options
context:
space:
mode:
authorPatric Stout <truebrain@openttd.org>2021-06-11 15:05:58 +0200
committerPatric Stout <github@truebrain.nl>2021-06-15 16:45:04 +0200
commit75e7451151ea9ab1ed18cd04b1229f68b7d3dcf5 (patch)
tree9684b71717d67741ed69da3706ac74747f0ab5aa /src/saveload
parenta146bcfe93a6c913781cfe471166359e744195d7 (diff)
downloadopenttd-75e7451151ea9ab1ed18cd04b1229f68b7d3dcf5.tar.xz
Change: indicate in the savegame if a SL_STRUCT contains any data
This helps external tooling to understand if a SL_STRUCT should be skipped when reading. Basically, this transforms an SL_STRUCT into a SL_STRUCTLIST with either 0 or 1 length.
Diffstat (limited to 'src/saveload')
-rw-r--r--src/saveload/saveload.cpp37
1 files changed, 33 insertions, 4 deletions
diff --git a/src/saveload/saveload.cpp b/src/saveload/saveload.cpp
index 3ca10b527..9f3aa7d1d 100644
--- a/src/saveload/saveload.cpp
+++ b/src/saveload/saveload.cpp
@@ -1467,6 +1467,10 @@ size_t SlCalcObjMemberLength(const void *object, const SaveLoad &sld)
_sl.obj_len = old_obj_len;
_sl.need_length = old_need_length;
+ if (sld.cmd == SL_STRUCT) {
+ length += SlGetArrayLength(1);
+ }
+
return length;
}
default: NOT_REACHED();
@@ -1575,10 +1579,35 @@ static bool SlObjectMember(void *object, const SaveLoad &sld)
if (!SlIsObjectValidInSavegame(sld)) return false;
switch (_sl.action) {
- case SLA_SAVE: sld.handler->Save(object); break;
- case SLA_LOAD_CHECK: sld.handler->LoadCheck(object); break;
- case SLA_LOAD: sld.handler->Load(object); break;
- case SLA_PTRS: sld.handler->FixPointers(object); break;
+ case SLA_SAVE: {
+ if (sld.cmd == SL_STRUCT) {
+ /* Store in the savegame if this struct was written or not. */
+ SlSetStructListLength(SlCalcObjMemberLength(object, sld) > SlGetArrayLength(1) ? 1 : 0);
+ }
+ sld.handler->Save(object);
+ break;
+ }
+
+ case SLA_LOAD_CHECK: {
+ if (sld.cmd == SL_STRUCT && !IsSavegameVersionBefore(SLV_SAVELOAD_LIST_LENGTH)) {
+ SlGetStructListLength(1);
+ }
+ sld.handler->LoadCheck(object);
+ break;
+ }
+
+ case SLA_LOAD: {
+ if (sld.cmd == SL_STRUCT && !IsSavegameVersionBefore(SLV_SAVELOAD_LIST_LENGTH)) {
+ SlGetStructListLength(1);
+ }
+ sld.handler->Load(object);
+ break;
+ }
+
+ case SLA_PTRS:
+ sld.handler->FixPointers(object);
+ break;
+
case SLA_NULL: break;
default: NOT_REACHED();
}