Changeset - r25600:a0060616e61f
[Not reviewed]
master
0 3 0
Patric Stout - 3 years ago 2021-06-04 07:31:28
truebrain@openttd.org
Codechange: move SLF_NO_NETWORK_SYNC into settings

It is a settings-only flag, so don't pollute SaveLoad code with it.
3 files changed with 10 insertions and 19 deletions:
0 comments (0 inline, 0 general)
src/saveload/saveload.cpp
Show inline comments
 
@@ -584,7 +584,7 @@ static inline uint SlGetArrayLength(size
 
 * @param conv VarType type of variable that is used for calculating the size
 
 * @return Return the size of this type in bytes
 
 */
 
static inline uint SlCalcConvMemLen(VarType conv)
 
uint SlCalcConvMemLen(VarType conv)
 
{
 
	static const byte conv_mem_size[] = {1, 1, 1, 2, 2, 4, 4, 8, 8, 0};
 
	byte length = GB(conv, 4, 4);
 
@@ -1412,21 +1412,6 @@ static inline bool SlIsObjectValidInSave
 
}
 

	
 
/**
 
 * Are we going to load this variable when loading a savegame or not?
 
 * @note If the variable is skipped it is skipped in the savegame
 
 * bytestream itself as well, so there is no need to skip it somewhere else
 
 */
 
static inline bool SlSkipVariableOnLoad(const SaveLoad &sld)
 
{
 
	if ((sld.conv & SLF_NO_NETWORK_SYNC) && _sl.action != SLA_SAVE && _networking && !_network_server) {
 
		SlSkipBytes(SlCalcConvMemLen(sld.conv) * sld.length);
 
		return true;
 
	}
 

	
 
	return false;
 
}
 

	
 
/**
 
 * Calculate the size of an object.
 
 * @param object to be measured.
 
 * @param slt The SaveLoad table with objects to save/load.
 
@@ -1538,7 +1523,6 @@ bool SlObjectMember(void *ptr, const Sav
 
		case SL_STDSTR:
 
			/* CONDITIONAL saveload types depend on the savegame version */
 
			if (!SlIsObjectValidInSavegame(sld)) return false;
 
			if (SlSkipVariableOnLoad(sld)) return false;
 

	
 
			switch (sld.cmd) {
 
				case SL_VAR: SlSaveLoadConv(ptr, conv); break;
src/saveload/saveload.h
Show inline comments
 
@@ -896,6 +896,7 @@ void WriteValue(void *ptr, VarType conv,
 
void SlSetArrayIndex(uint index);
 
int SlIterateArray();
 

	
 
uint SlCalcConvMemLen(VarType conv);
 
void SlAutolength(AutolengthProc *proc, void *arg);
 
size_t SlGetFieldLength();
 
void SlSetLength(size_t length);
src/settings.cpp
Show inline comments
 
@@ -2025,9 +2025,15 @@ static void LoadSettings(const SettingTa
 
	for (auto &osd : settings) {
 
		if (osd->save.conv & SLF_NOT_IN_SAVE) continue;
 

	
 
		void *ptr = GetVariableAddress(object, osd->save);
 
		SaveLoad sl = osd->save;
 
		if ((osd->save.conv & SLF_NO_NETWORK_SYNC) && _networking && !_network_server) {
 
			/* We don't want to read this setting, so we do need to skip over it. */
 
			sl = SLE_NULL(static_cast<uint16>(SlCalcConvMemLen(osd->save.conv) * osd->save.length));
 
		}
 

	
 
		if (!SlObjectMember(ptr, osd->save)) continue;
 
		void *ptr = GetVariableAddress(object, sl);
 
		if (!SlObjectMember(ptr, sl)) continue;
 

	
 
		if (osd->IsIntSetting()) {
 
			const IntSettingDesc *int_setting = osd->AsIntSetting();
 
			int_setting->MakeValueValidAndWrite(object, int_setting->Read(object));
0 comments (0 inline, 0 general)