MCPcopy Create free account
hub / github.com/OpenTTD/OpenTTD / SlArray

Function SlArray

src/saveload/saveload.cpp:1180–1214  ·  view source on GitHub ↗

* Save/Load the length of the array followed by the array of SL_VAR elements. * @param array The array being manipulated * @param length The length of the array in elements * @param conv VarType type of the atomic array (int, uint8_t, uint64_t, etc.) */

Source from the content-addressed store, hash-verified

1178 * @param conv VarType type of the atomic array (int, uint8_t, uint64_t, etc.)
1179 */
1180static void SlArray(void *array, size_t length, VarType conv)
1181{
1182 switch (_sl.action) {
1183 case SLA_SAVE:
1184 SlWriteArrayLength(length);
1185 SlCopyInternal(array, length, conv);
1186 return;
1187
1188 case SLA_LOAD_CHECK:
1189 case SLA_LOAD: {
1190 if (!IsSavegameVersionBefore(SLV_SAVELOAD_LIST_LENGTH)) {
1191 size_t sv_length = SlReadArrayLength();
1192 if (GetVarMemType(conv) == SLE_VAR_NULL) {
1193 /* We don't know this field, so we assume the length in the savegame is correct. */
1194 length = sv_length;
1195 } else if (sv_length != length) {
1196 /* If the SLE_ARR changes size, a savegame bump is required
1197 * and the developer should have written conversion lines.
1198 * Error out to make this more visible. */
1199 SlErrorCorrupt("Fixed-length array is of wrong length");
1200 }
1201 }
1202
1203 SlCopyInternal(array, length, conv);
1204 return;
1205 }
1206
1207 case SLA_PTRS:
1208 case SLA_NULL:
1209 return;
1210
1211 default:
1212 NOT_REACHED();
1213 }
1214}
1215
1216/**
1217 * Pointers cannot be saved to a savegame, so this functions gets

Callers 1

SlObjectMemberFunction · 0.85

Calls 7

SlWriteArrayLengthFunction · 0.85
SlCopyInternalFunction · 0.85
IsSavegameVersionBeforeFunction · 0.85
SlReadArrayLengthFunction · 0.85
GetVarMemTypeFunction · 0.85
SlErrorCorruptFunction · 0.85
NOT_REACHEDFunction · 0.85

Tested by

no test coverage detected