Changeset - r25694:c6c087eb0d6f
[Not reviewed]
master
0 1 0
Patric Stout - 3 years ago 2021-06-11 13:05:58
truebrain@openttd.org
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.
1 file changed with 33 insertions and 4 deletions:
0 comments (0 inline, 0 general)
src/saveload/saveload.cpp
Show inline comments
 
@@ -1467,6 +1467,10 @@ size_t SlCalcObjMemberLength(const void 
 
			_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,
 
			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();
 
			}
0 comments (0 inline, 0 general)