Changeset - r25528:52b815c03f32
[Not reviewed]
master
0 11 0
rubidium42 - 3 years ago 2021-05-18 19:01:42
rubidium@openttd.org
Codechange: use initializer_lists for the settings tables

Not using vectors as those require copying from the initializer list and that
makes unique_ptrs to the actual SettingDesc objects later impossible.
11 files changed with 107 insertions and 117 deletions:
0 comments (0 inline, 0 general)
src/saveload/linkgraph_sl.cpp
Show inline comments
 
@@ -71,25 +71,25 @@ const SaveLoad *GetLinkGraphJobDesc()
 
	/* Build the SaveLoad array on first call and don't touch it later on */
 
	if (saveloads.size() == 0) {
 
		size_t prefixlen = strlen(prefix);
 

	
 
		int setting = 0;
 
		const SettingDesc *desc = GetSettingDescription(setting);
 
		while (desc->save.cmd != SL_END) {
 
		while (desc != nullptr) {
 
			if (desc->name != nullptr && strncmp(desc->name, prefix, prefixlen) == 0) {
 
				SaveLoad sl = desc->save;
 
				sl.address_proc = proc;
 
				saveloads.push_back(sl);
 
			}
 
			desc = GetSettingDescription(++setting);
 
		}
 

	
 
		int i = 0;
 
		do {
 
			saveloads.push_back(job_desc[i++]);
 
		} while (saveloads[saveloads.size() - 1].cmd != SL_END);
 
		} while (saveloads.back().cmd != SL_END);
 
	}
 

	
 
	return &saveloads[0];
 
}
 

	
 
/**
src/settings.cpp
Show inline comments
 
@@ -84,18 +84,40 @@ VehicleDefaultSettings _old_vds; ///< Us
 
std::string _config_file; ///< Configuration file of OpenTTD
 

	
 
typedef std::list<ErrorMessageData> ErrorList;
 
static ErrorList _settings_error_list; ///< Errors while loading minimal settings.
 

	
 

	
 
typedef void SettingDescProc(IniFile *ini, const SettingDesc *desc, const char *grpname, void *object, bool only_startup);
 
typedef void SettingDescProc(IniFile *ini, const SettingTable &desc, const char *grpname, void *object, bool only_startup);
 
typedef void SettingDescProcList(IniFile *ini, const char *grpname, StringList &list);
 

	
 
static bool IsSignedVarMemType(VarType vt);
 

	
 
/**
 
 * Get the setting at the given index into the settings table.
 
 * @param index The index to look for.
 
 * @return The setting at the given index, or nullptr when the index is invalid.
 
 */
 
const SettingDesc *GetSettingDescription(uint index)
 
{
 
	if (index >= _settings.size()) return nullptr;
 
	return &_settings.begin()[index];
 
}
 

	
 
/**
 
 * Get the setting at the given index into the company settings table.
 
 * @param index The index to look for.
 
 * @return The setting at the given index, or nullptr when the index is invalid.
 
 */
 
static const SettingDesc *GetCompanySettingDescription(uint index)
 
{
 
	if (index >= _company_settings.size()) return nullptr;
 
	return &_company_settings.begin()[index];
 
}
 

	
 
/**
 
 * Groups in openttd.cfg that are actually lists.
 
 */
 
static const char * const _list_group_names[] = {
 
	"bans",
 
	"newgrf",
 
	"servers",
 
@@ -526,29 +548,29 @@ static void Write_ValidateStdString(void
 
	}
 
}
 

	
 
/**
 
 * Load values from a group of an IniFile structure into the internal representation
 
 * @param ini pointer to IniFile structure that holds administrative information
 
 * @param sd pointer to SettingDesc structure whose internally pointed variables will
 
 * @param settings_table table with SettingDesc structures whose internally pointed variables will
 
 *        be given values
 
 * @param grpname the group of the IniFile to search in for the new values
 
 * @param object pointer to the object been loaded
 
 * @param only_startup load only the startup settings set
 
 */
 
static void IniLoadSettings(IniFile *ini, const SettingDesc *sd, const char *grpname, void *object, bool only_startup)
 
static void IniLoadSettings(IniFile *ini, const SettingTable &settings_table, const char *grpname, void *object, bool only_startup)
 
{
 
	IniGroup *group;
 
	IniGroup *group_def = ini->GetGroup(grpname);
 

	
 
	for (; sd->save.cmd != SL_END; sd++) {
 
		const SettingDescBase *sdb = sd;
 
		const SaveLoad        *sld = &sd->save;
 
	for (auto &sd : settings_table) {
 
		const SettingDescBase *sdb = &sd;
 
		const SaveLoad        *sld = &sd.save;
 

	
 
		if (!SlIsObjectCurrentlyValid(sld->version_from, sld->version_to)) continue;
 
		if (sd->startup != only_startup) continue;
 
		if (sd.startup != only_startup) continue;
 

	
 
		/* For settings.xx.yy load the settings from [xx] yy = ? */
 
		std::string s{ sdb->name };
 
		auto sc = s.find('.');
 
		if (sc != std::string::npos) {
 
			group = ini->GetGroup(s.substr(0, sc));
 
@@ -575,29 +597,29 @@ static void IniLoadSettings(IniFile *ini
 

	
 
		switch (sdb->cmd) {
 
			case SDT_BOOLX: // All four are various types of (integer) numbers
 
			case SDT_NUMX:
 
			case SDT_ONEOFMANY:
 
			case SDT_MANYOFMANY:
 
				Write_ValidateSetting(ptr, sd, (int32)(size_t)p);
 
				Write_ValidateSetting(ptr, &sd, (int32)(size_t)p);
 
				break;
 

	
 
			case SDT_STDSTRING:
 
				Write_ValidateStdString(ptr, sd, (const char *)p);
 
				Write_ValidateStdString(ptr, &sd, (const char *)p);
 
				break;
 

	
 
			case SDT_INTLIST: {
 
				if (!LoadIntList((const char*)p, ptr, sld->length, GetVarMemType(sld->conv))) {
 
					ErrorMessageData msg(STR_CONFIG_ERROR, STR_CONFIG_ERROR_ARRAY);
 
					msg.SetDParamStr(0, sdb->name);
 
					_settings_error_list.push_back(msg);
 

	
 
					/* Use default */
 
					LoadIntList((const char*)sdb->def, ptr, sld->length, GetVarMemType(sld->conv));
 
				} else if (sd->proc_cnvt != nullptr) {
 
					sd->proc_cnvt((const char*)p);
 
				} else if (sd.proc_cnvt != nullptr) {
 
					sd.proc_cnvt((const char*)p);
 
				}
 
				break;
 
			}
 
			default: NOT_REACHED();
 
		}
 
	}
 
@@ -612,22 +634,22 @@ static void IniLoadSettings(IniFile *ini
 
 * @param object pointer to the object been saved
 
 * The function works as follows: for each item in the SettingDesc structure we
 
 * have a look if the value has changed since we started the game (the original
 
 * values are reloaded when saving). If settings indeed have changed, we get
 
 * these and save them.
 
 */
 
static void IniSaveSettings(IniFile *ini, const SettingDesc *sd, const char *grpname, void *object, bool)
 
static void IniSaveSettings(IniFile *ini, const SettingTable &settings_table, const char *grpname, void *object, bool)
 
{
 
	IniGroup *group_def = nullptr, *group;
 
	IniItem *item;
 
	char buf[512];
 
	void *ptr;
 

	
 
	for (; sd->save.cmd != SL_END; sd++) {
 
		const SettingDescBase *sdb = sd;
 
		const SaveLoad        *sld = &sd->save;
 
	for (auto &sd : settings_table) {
 
		const SettingDescBase *sdb = &sd;
 
		const SaveLoad        *sld = &sd.save;
 

	
 
		/* If the setting is not saved to the configuration
 
		 * file, just continue with the next setting */
 
		if (!SlIsObjectCurrentlyValid(sld->version_from, sld->version_to)) continue;
 
		if (sld->conv & SLF_NOT_IN_CONFIG) continue;
 

	
 
@@ -1421,13 +1443,13 @@ static void HandleOldDiffCustom(bool sav
 
		}
 

	
 
		if (!old_diff_custom_used) return;
 
	}
 

	
 
	for (uint i = 0; i < options_to_load; i++) {
 
		const SettingDesc *sd = &_settings[i];
 
		const SettingDesc *sd = GetSettingDescription(i);
 
		/* Skip deprecated options */
 
		if (!SlIsObjectCurrentlyValid(sd->save.version_from, sd->save.version_to)) continue;
 
		void *var = GetVariableAddress(savegame ? &_settings_game : &_settings_newgame, &sd->save);
 
		Write_ValidateSetting(var, sd, (int32)((i == 4 ? 1000 : 1) * _old_diff_custom[i]));
 
	}
 
}
 
@@ -1705,15 +1727,15 @@ static void GRFSaveConfig(IniFile *ini, 
 
	}
 
}
 

	
 
/* Common handler for saving/loading variables to the configuration file */
 
static void HandleSettingDescs(IniFile *ini, SettingDescProc *proc, SettingDescProcList *proc_list, bool only_startup = false)
 
{
 
	proc(ini, (const SettingDesc*)_misc_settings,    "misc",  nullptr, only_startup);
 
	proc(ini, _misc_settings,    "misc",  nullptr, only_startup);
 
#if defined(_WIN32) && !defined(DEDICATED)
 
	proc(ini, (const SettingDesc*)_win32_settings,   "win32", nullptr, only_startup);
 
	proc(ini, _win32_settings,   "win32", nullptr, only_startup);
 
#endif /* _WIN32 */
 

	
 
	proc(ini, _settings,         "patches",  &_settings_newgame, only_startup);
 
	proc(ini, _currency_settings,"currency", &_custom_currency, only_startup);
 
	proc(ini, _company_settings, "company",  &_settings_client.company, only_startup);
 

	
 
@@ -1852,18 +1874,12 @@ void DeleteGRFPresetFromConfig(const cha
 
	IniFile *ini = IniLoadConfig();
 
	ini->RemoveGroup(section);
 
	ini->SaveToDisk(_config_file);
 
	delete ini;
 
}
 

	
 
const SettingDesc *GetSettingDescription(uint index)
 
{
 
	if (index >= lengthof(_settings)) return nullptr;
 
	return &_settings[index];
 
}
 

	
 
/**
 
 * Network-safe changing of settings (server-only).
 
 * @param tile unused
 
 * @param flags operation to perform
 
 * @param p1 the index of the setting in the SettingDesc array which identifies it
 
 * @param p2 the new value for the setting
 
@@ -1920,14 +1936,14 @@ CommandCost CmdChangeSetting(TileIndex t
 
 * The new value is properly clamped to its minimum/maximum when setting
 
 * @param text unused
 
 * @return the cost of this operation or an error
 
 */
 
CommandCost CmdChangeCompanySetting(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
 
{
 
	if (p1 >= lengthof(_company_settings)) return CMD_ERROR;
 
	const SettingDesc *sd = &_company_settings[p1];
 
	const SettingDesc *sd = GetCompanySettingDescription(p1);
 
	if (sd == nullptr) return CMD_ERROR;
 

	
 
	if (flags & DC_EXEC) {
 
		void *var = GetVariableAddress(&Company::Get(_current_company)->settings, &sd->save);
 

	
 
		int32 oldval = (int32)ReadValue(var, sd->save.conv);
 
		int32 newval = (int32)p2;
 
@@ -1952,14 +1968,25 @@ CommandCost CmdChangeCompanySetting(Tile
 
 * Get the index of the setting with this description.
 
 * @param sd the setting to get the index for.
 
 * @return the index of the setting to be used for CMD_CHANGE_SETTING.
 
 */
 
uint GetSettingIndex(const SettingDesc *sd)
 
{
 
	assert((sd->flags & SGF_PER_COMPANY) == 0);
 
	return sd - _settings;
 
	assert(sd != nullptr && (sd->flags & SGF_PER_COMPANY) == 0);
 
	return sd - _settings.begin();
 
}
 

	
 
/**
 
 * Get the index of the company setting with this description.
 
 * @param sd the setting to get the index for.
 
 * @return the index of the setting to be used for CMD_CHANGE_COMPANY_SETTING.
 
 */
 
static uint GetCompanySettingIndex(const SettingDesc *sd)
 
{
 
	assert(sd != nullptr && (sd->flags & SGF_PER_COMPANY) != 0);
 
	return sd - _company_settings.begin();
 
}
 

	
 
/**
 
 * Top function to save the new value of an element of the Settings struct
 
 * @param index offset in the SettingDesc array of the Settings struct which
 
 * identifies the setting member we want to change
 
@@ -1967,13 +1994,13 @@ uint GetSettingIndex(const SettingDesc *
 
 * @param force_newgame force the newgame settings
 
 */
 
bool SetSettingValue(const SettingDesc *sd, int32 value, bool force_newgame)
 
{
 
	if ((sd->flags & SGF_PER_COMPANY) != 0) {
 
		if (Company::IsValidID(_local_company) && _game_mode != GM_MENU) {
 
			return DoCommandP(0, sd - _company_settings, value, CMD_CHANGE_COMPANY_SETTING);
 
			return DoCommandP(0, GetCompanySettingIndex(sd), value, CMD_CHANGE_COMPANY_SETTING);
 
		}
 

	
 
		void *var = GetVariableAddress(&_settings_client.company, &sd->save);
 
		Write_ValidateSetting(var, sd, value);
 
		if (sd->proc != nullptr) sd->proc((int32)ReadValue(var, sd->save.conv));
 
		return true;
 
@@ -2017,45 +2044,42 @@ bool SetSettingValue(const SettingDesc *
 
/**
 
 * Set the company settings for a new company to their default values.
 
 */
 
void SetDefaultCompanySettings(CompanyID cid)
 
{
 
	Company *c = Company::Get(cid);
 
	const SettingDesc *sd;
 
	for (sd = _company_settings; sd->save.cmd != SL_END; sd++) {
 
		void *var = GetVariableAddress(&c->settings, &sd->save);
 
		Write_ValidateSetting(var, sd, (int32)(size_t)sd->def);
 
	for (auto &sd : _company_settings) {
 
		void *var = GetVariableAddress(&c->settings, &sd.save);
 
		Write_ValidateSetting(var, &sd, (int32)(size_t)sd.def);
 
	}
 
}
 

	
 
/**
 
 * Sync all company settings in a multiplayer game.
 
 */
 
void SyncCompanySettings()
 
{
 
	const SettingDesc *sd;
 
	uint i = 0;
 
	for (sd = _company_settings; sd->save.cmd != SL_END; sd++, i++) {
 
		const void *old_var = GetVariableAddress(&Company::Get(_current_company)->settings, &sd->save);
 
		const void *new_var = GetVariableAddress(&_settings_client.company, &sd->save);
 
		uint32 old_value = (uint32)ReadValue(old_var, sd->save.conv);
 
		uint32 new_value = (uint32)ReadValue(new_var, sd->save.conv);
 
	for (auto &sd : _company_settings) {
 
		const void *old_var = GetVariableAddress(&Company::Get(_current_company)->settings, &sd.save);
 
		const void *new_var = GetVariableAddress(&_settings_client.company, &sd.save);
 
		uint32 old_value = (uint32)ReadValue(old_var, sd.save.conv);
 
		uint32 new_value = (uint32)ReadValue(new_var, sd.save.conv);
 
		if (old_value != new_value) NetworkSendCommand(0, i, new_value, CMD_CHANGE_COMPANY_SETTING, nullptr, nullptr, _local_company);
 
		i++;
 
	}
 
}
 

	
 
/**
 
 * Get the index in the _company_settings array of a setting
 
 * @param name The name of the setting
 
 * @return The index in the _company_settings array
 
 */
 
uint GetCompanySettingIndex(const char *name)
 
{
 
	const SettingDesc *sd = GetSettingFromName(name);
 
	assert(sd != nullptr && (sd->flags & SGF_PER_COMPANY) != 0);
 
	return sd - _company_settings;
 
	return GetCompanySettingIndex(GetSettingFromName(name));
 
}
 

	
 
/**
 
 * Set a setting value with a string.
 
 * @param sd the setting to change.
 
 * @param value the value to write
 
@@ -2085,32 +2109,32 @@ bool SetSettingValue(const SettingDesc *
 
 * @return Pointer to the setting description of setting \a name if it can be found,
 
 *         \c nullptr indicates failure to obtain the description
 
 */
 
const SettingDesc *GetSettingFromName(const char *name)
 
{
 
	/* First check all full names */
 
	for (const SettingDesc *sd = _settings; sd->save.cmd != SL_END; sd++) {
 
		if (!SlIsObjectCurrentlyValid(sd->save.version_from, sd->save.version_to)) continue;
 
		if (strcmp(sd->name, name) == 0) return sd;
 
	for (auto &sd : _settings) {
 
		if (!SlIsObjectCurrentlyValid(sd.save.version_from, sd.save.version_to)) continue;
 
		if (strcmp(sd.name, name) == 0) return &sd;
 
	}
 

	
 
	/* Then check the shortcut variant of the name. */
 
	for (const SettingDesc *sd = _settings; sd->save.cmd != SL_END; sd++) {
 
		if (!SlIsObjectCurrentlyValid(sd->save.version_from, sd->save.version_to)) continue;
 
		const char *short_name = strchr(sd->name, '.');
 
	for (auto &sd : _settings) {
 
		if (!SlIsObjectCurrentlyValid(sd.save.version_from, sd.save.version_to)) continue;
 
		const char *short_name = strchr(sd.name, '.');
 
		if (short_name != nullptr) {
 
			short_name++;
 
			if (strcmp(short_name, name) == 0) return sd;
 
			if (strcmp(short_name, name) == 0) return &sd;
 
		}
 
	}
 

	
 
	if (strncmp(name, "company.", 8) == 0) name += 8;
 
	/* And finally the company-based settings */
 
	for (const SettingDesc *sd = _company_settings; sd->save.cmd != SL_END; sd++) {
 
		if (!SlIsObjectCurrentlyValid(sd->save.version_from, sd->save.version_to)) continue;
 
		if (strcmp(sd->name, name) == 0) return sd;
 
	for (auto &sd : _company_settings) {
 
		if (!SlIsObjectCurrentlyValid(sd.save.version_from, sd.save.version_to)) continue;
 
		if (strcmp(sd.name, name) == 0) return &sd;
 
	}
 

	
 
	return nullptr;
 
}
 

	
 
/* Those 2 functions need to be here, else we have to make some stuff non-static
 
@@ -2193,68 +2217,67 @@ void IConsoleGetSetting(const char *name
 
 * @param prefilter  If not \c nullptr, only list settings with names that begin with \a prefilter prefix
 
 */
 
void IConsoleListSettings(const char *prefilter)
 
{
 
	IConsolePrintF(CC_WARNING, "All settings with their current value:");
 

	
 
	for (const SettingDesc *sd = _settings; sd->save.cmd != SL_END; sd++) {
 
		if (!SlIsObjectCurrentlyValid(sd->save.version_from, sd->save.version_to)) continue;
 
		if (prefilter != nullptr && strstr(sd->name, prefilter) == nullptr) continue;
 
	for (auto &sd : _settings) {
 
		if (!SlIsObjectCurrentlyValid(sd.save.version_from, sd.save.version_to)) continue;
 
		if (prefilter != nullptr && strstr(sd.name, prefilter) == nullptr) continue;
 
		char value[80];
 
		const void *ptr = GetVariableAddress(&GetGameSettings(), &sd->save);
 
		const void *ptr = GetVariableAddress(&GetGameSettings(), &sd.save);
 

	
 
		if (sd->cmd == SDT_BOOLX) {
 
		if (sd.cmd == SDT_BOOLX) {
 
			seprintf(value, lastof(value), (*(const bool *)ptr != 0) ? "on" : "off");
 
		} else if (sd->cmd == SDT_STDSTRING) {
 
		} else if (sd.cmd == SDT_STDSTRING) {
 
			seprintf(value, lastof(value), "%s", reinterpret_cast<const std::string *>(ptr)->c_str());
 
		} else {
 
			seprintf(value, lastof(value), sd->min < 0 ? "%d" : "%u", (int32)ReadValue(ptr, sd->save.conv));
 
			seprintf(value, lastof(value), sd.min < 0 ? "%d" : "%u", (int32)ReadValue(ptr, sd.save.conv));
 
		}
 
		IConsolePrintF(CC_DEFAULT, "%s = %s", sd->name, value);
 
		IConsolePrintF(CC_DEFAULT, "%s = %s", sd.name, value);
 
	}
 

	
 
	IConsolePrintF(CC_WARNING, "Use 'setting' command to change a value");
 
}
 

	
 
/**
 
 * Save and load handler for settings
 
 * @param osd SettingDesc struct containing all information
 
 * @param settings SettingDesc struct containing all information
 
 * @param object can be either nullptr in which case we load global variables or
 
 * a pointer to a struct which is getting saved
 
 */
 
static void LoadSettings(const SettingDesc *osd, void *object)
 
static void LoadSettings(const SettingTable &settings, void *object)
 
{
 
	for (; osd->save.cmd != SL_END; osd++) {
 
		const SaveLoad *sld = &osd->save;
 
	for (auto &osd : settings) {
 
		const SaveLoad *sld = &osd.save;
 
		void *ptr = GetVariableAddress(object, sld);
 

	
 
		if (!SlObjectMember(ptr, sld)) continue;
 
		if (IsNumericType(sld->conv)) Write_ValidateSetting(ptr, osd, ReadValue(ptr, sld->conv));
 
		if (IsNumericType(sld->conv)) Write_ValidateSetting(ptr, &osd, ReadValue(ptr, sld->conv));
 
	}
 
}
 

	
 
/**
 
 * Save and load handler for settings
 
 * @param sd SettingDesc struct containing all information
 
 * @param settings SettingDesc struct containing all information
 
 * @param object can be either nullptr in which case we load global variables or
 
 * a pointer to a struct which is getting saved
 
 */
 
static void SaveSettings(const SettingDesc *sd, void *object)
 
static void SaveSettings(const SettingTable &settings, void *object)
 
{
 
	/* We need to write the CH_RIFF header, but unfortunately can't call
 
	 * SlCalcLength() because we have a different format. So do this manually */
 
	const SettingDesc *i;
 
	size_t length = 0;
 
	for (i = sd; i->save.cmd != SL_END; i++) {
 
		length += SlCalcObjMemberLength(object, &i->save);
 
	for (auto &sd : settings) {
 
		length += SlCalcObjMemberLength(object, &sd.save);
 
	}
 
	SlSetLength(length);
 

	
 
	for (i = sd; i->save.cmd != SL_END; i++) {
 
		void *ptr = GetVariableAddress(object, &i->save);
 
		SlObjectMember(ptr, &i->save);
 
	for (auto &sd : settings) {
 
		void *ptr = GetVariableAddress(object, &sd.save);
 
		SlObjectMember(ptr, &sd.save);
 
	}
 
}
 

	
 
static void Load_OPTS()
 
{
 
	/* Copy over default setting since some might not get loaded in
src/settings_internal.h
Show inline comments
 
@@ -104,12 +104,14 @@ struct SettingDesc : SettingDescBase {
 
	SaveLoad save;          ///< Internal structure (going to savegame, parts to config)
 

	
 
	bool IsEditable(bool do_command = false) const;
 
	SettingType GetType() const;
 
};
 

	
 
typedef std::initializer_list<const SettingDesc> SettingTable;
 

	
 
const SettingDesc *GetSettingFromName(const char *name);
 
bool SetSettingValue(const SettingDesc *sd, int32 value, bool force_newgame = false);
 
bool SetSettingValue(const SettingDesc *sd, const char *value, bool force_newgame = false);
 
uint GetSettingIndex(const SettingDesc *sd);
 

	
 
#endif /* SETTINGS_INTERNAL_H */
src/table/company_settings.ini
Show inline comments
 
@@ -9,19 +9,18 @@ static bool CheckInterval(int32 p1);
 
static bool InvalidateDetailsWindow(int32 p1);
 
static bool UpdateIntervalTrains(int32 p1);
 
static bool UpdateIntervalRoadVeh(int32 p1);
 
static bool UpdateIntervalShips(int32 p1);
 
static bool UpdateIntervalAircraft(int32 p1);
 

	
 
static const SettingDesc _company_settings[] = {
 
static const SettingTable _company_settings{
 
[post-amble]
 
};
 
[templates]
 
SDT_BOOL = SDT_BOOL($base, $var,        $flags, $guiflags, $def,                        $str, $strhelp, $strval, $proc, $from, $to, $cat, $extra, $startup),
 
SDT_VAR  =  SDT_VAR($base, $var, $type, $flags, $guiflags, $def, $min, $max, $interval, $str, $strhelp, $strval, $proc, $from, $to, $cat, $extra, $startup),
 
SDT_END  = SDT_END()
 

	
 
[validation]
 
SDT_VAR = static_assert($max <= MAX_$type, "Maximum value for $base.$var exceeds storage size");
 

	
 
[defaults]
 
flags    = 0
 
@@ -133,11 +132,6 @@ def      = 100
 
min      = 5
 
max      = 800
 
str      = STR_CONFIG_SETTING_SERVINT_AIRCRAFT
 
strhelp  = STR_CONFIG_SETTING_SERVINT_AIRCRAFT_HELPTEXT
 
strval   = STR_CONFIG_SETTING_SERVINT_VALUE
 
proc     = UpdateIntervalAircraft
 

	
 
[SDT_END]
 

	
 

	
 
};
src/table/currency_settings.ini
Show inline comments
 
@@ -2,19 +2,18 @@
 
; OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
 
; OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 
; See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
 
;
 

	
 
[pre-amble]
 
static const SettingDesc _currency_settings[] = {
 
static const SettingTable _currency_settings{
 
[post-amble]
 
};
 
[templates]
 
SDT_VAR  = SDT_VAR ($base, $var, $type, $flags, $guiflags, $def, $min, $max, $interval, $str, $strhelp, $strval, $proc, $from, $to, $cat, $extra, $startup),
 
SDT_SSTR = SDT_SSTR($base, $var, $type, $flags, $guiflags, $def,                        $str, $strhelp, $strval, $proc, $from, $to, $cat, $extra, $startup),
 
SDT_END  = SDT_END()
 

	
 
[validation]
 
SDT_VAR = static_assert($max <= MAX_$type, "Maximum value for $base.$var exceeds storage size");
 

	
 
[defaults]
 
flags    = SLF_NOT_IN_SAVE | SLF_NO_NETWORK_SYNC
 
@@ -64,9 +63,6 @@ def      = nullptr
 

	
 
[SDT_SSTR]
 
base     = CurrencySpec
 
var      = suffix
 
type     = SLE_STRQ
 
def      = "" credits""
 

	
 
[SDT_END]
 

	
src/table/gameopt_settings.ini
Show inline comments
 
@@ -20,13 +20,13 @@ static const char *_autosave_interval = 
 
static const char *_roadsides = "left|right";
 
static const char *_savegame_date = "long|short|iso";
 
static const char *_osk_activation = "disabled|double|single|immediately";
 
static const char *_settings_profiles = "easy|medium|hard";
 
static const char *_news_display = "off|summarized|full";
 

	
 
static const SettingDesc _gameopt_settings[] = {
 
static const SettingTable _gameopt_settings{
 
/* In version 4 a new difficulty setting has been added to the difficulty settings,
 
 * town attitude towards demolishing. Needs special handling because some dimwit thought
 
 * it funny to have the GameDifficulty struct be an array while it is a struct of
 
 * same-sized members
 
 * XXX - To save file-space and since values are never bigger than about 10? only
 
 * save the first 16 bits in the savegame. Question is why the values are still int32
 
@@ -40,13 +40,12 @@ SDTG_GENERAL = SDTG_GENERAL($name, $sdt_
 
SDTG_VAR     =     SDTG_VAR($name,                     $type, $flags, $guiflags, $var,          $def, $min, $max, $interval,        $str, $strhelp, $strval, $proc, $from, $to, $cat, $extra, $startup),
 
SDT_NULL     =   SDT_NULL($length, $from, $to),
 
SDTC_OMANY   = SDTC_OMANY(       $var, $type, $flags, $guiflags, $def,       $max, $full,            $str, $strhelp, $strval, $proc, $from, $to,        $cat, $extra, $startup),
 
SDTG_OMANY   = SDTG_OMANY($name,       $type, $flags, $guiflags, $var, $def, $max, $full,            $str, $strhelp, $strval, $proc, $from, $to,        $cat, $extra, $startup),
 
SDT_OMANY    =  SDT_OMANY($base, $var, $type, $flags, $guiflags, $def,       $max, $full,            $str, $strhelp, $strval, $proc, $from, $to, $load, $cat, $extra, $startup),
 
SDT_VAR      =    SDT_VAR($base, $var, $type, $flags, $guiflags, $def, $min, $max,        $interval, $str, $strhelp, $strval, $proc, $from, $to,        $cat, $extra, $startup),
 
SDT_END      = SDT_END()
 

	
 
[validation]
 
SDTG_VAR = static_assert($max <= MAX_$type, "Maximum value for $var exceeds storage size");
 
SDTG_OMANY = static_assert($max <= MAX_$type, "Maximum value for $var exceeds storage size");
 
SDTC_OMANY = static_assert($max <= MAX_$type, "Maximum value for $var exceeds storage size");
 
SDT_OMANY = static_assert($max <= MAX_$type, "Maximum value for $base.$var exceeds storage size");
 
@@ -183,9 +182,6 @@ base     = GameSettings
 
var      = vehicle.road_side
 
type     = SLE_UINT8
 
def      = 1
 
max      = 1
 
full     = _roadsides
 
cat      = SC_BASIC
 

	
 
[SDT_END]
 

	
src/table/misc_settings.ini
Show inline comments
 
@@ -13,23 +13,22 @@ static const char *_support8bppmodes = "
 
extern bool _allow_hidpi_window;
 
#endif
 
#ifndef WITH_COCOA
 
#define WITHOUT_COCOA
 
#endif
 

	
 
static const SettingDesc _misc_settings[] = {
 
static const SettingTable _misc_settings{
 
[post-amble]
 
};
 
[templates]
 
SDTG_LIST  =  SDTG_LIST($name, $type, $length, $flags, $guiflags, $var, $def,                               $str, $strhelp, $strval, $proc, $from, $to, $cat, $extra, $startup),
 
SDTG_MMANY = SDTG_MMANY($name, $type,          $flags, $guiflags, $var, $def,                        $full, $str, $strhelp, $strval, $proc, $from, $to, $cat, $extra, $startup),
 
SDTG_OMANY = SDTG_OMANY($name, $type,          $flags, $guiflags, $var, $def,       $max,            $full, $str, $strhelp, $strval, $proc, $from, $to, $cat, $extra, $startup),
 
SDTG_SSTR  =  SDTG_SSTR($name, $type,          $flags, $guiflags, $var, $def,                               $str, $strhelp, $strval, $proc, $from, $to, $cat, $extra, $startup),
 
SDTG_BOOL  =  SDTG_BOOL($name,                 $flags, $guiflags, $var, $def,                               $str, $strhelp, $strval, $proc, $from, $to, $cat, $extra, $startup),
 
SDTG_VAR   =   SDTG_VAR($name, $type,          $flags, $guiflags, $var, $def, $min, $max, $interval,        $str, $strhelp, $strval, $proc, $from, $to, $cat, $extra, $startup),
 
SDTG_END   = SDTG_END()
 

	
 
[validation]
 
SDTG_VAR = static_assert($max <= MAX_$type, "Maximum value for $var exceeds storage size");
 
SDTG_OMANY = static_assert($max <= MAX_$type, "Maximum value for $var exceeds storage size");
 

	
 
[defaults]
 
@@ -350,9 +349,6 @@ cat      = SC_BASIC
 

	
 
[SDTG_BOOL]
 
ifdef    = WITH_COCOA
 
name     = ""allow_hidpi""
 
var      = _allow_hidpi_window
 
def      = true
 

	
 
[SDTG_END]
 

	
src/table/settings.h.preamble
Show inline comments
 
@@ -80,14 +80,12 @@ static size_t ConvertLandscape(const cha
 
#define SDTG_MMANY(name, type, flags, guiflags, var, def, full, str, strhelp, strval, proc, from, to, cat, extra, startup)\
 
	SDTG_GENERAL(name, SDT_MANYOFMANY, SL_VAR, type, flags, guiflags, var, 0, def, 0, 0, 0, full, str, strhelp, strval, proc, from, to, cat, extra, startup)
 

	
 
#define SDTG_NULL(length, from, to)\
 
	{{"", nullptr, SDT_NUMX, SGF_NONE, 0, 0, 0, nullptr, STR_NULL, STR_NULL, STR_NULL, nullptr, nullptr, SC_NONE, false}, SLEG_NULL(length, from, to)}
 

	
 
#define SDTG_END() {{nullptr, nullptr, SDT_NUMX, SGF_NONE, 0, 0, 0, nullptr, STR_NULL, STR_NULL, STR_NULL, nullptr, nullptr, SC_NONE, false}, SLEG_END()}
 

	
 
/* Macros for various objects to go in the configuration file.
 
 * This section is for structures where their various members are saved */
 
#define SDT_GENERAL(name, sdt_cmd, sle_cmd, type, flags, guiflags, base, var, length, def, min, max, interval, full, str, strhelp, strval, proc, load, from, to, cat, extra, startup)\
 
	{NSD_GENERAL(name, def, sdt_cmd, guiflags, min, max, interval, full, str, strhelp, strval, proc, load, cat, startup), SLE_GENERAL(sle_cmd, base, var, type | flags, length, from, to, extra)}
 

	
 
#define SDT_VAR(base, var, type, flags, guiflags, def, min, max, interval, str, strhelp, strval, proc, from, to, cat, extra, startup)\
 
@@ -124,8 +122,6 @@ static size_t ConvertLandscape(const cha
 
#define SDTC_SSTR(var, type, flags, guiflags, def, max_length, str, strhelp, strval, proc, from, to, cat, extra, startup)\
 
	SDTG_GENERAL(#var, SDT_STDSTRING, SL_STDSTR, type, flags, guiflags, _settings_client.var, sizeof(_settings_client.var), def, 0, max_length, 0, nullptr, str, strhelp, strval, proc, from, to, cat, extra, startup)
 

	
 
#define SDTC_OMANY(var, type, flags, guiflags, def, max, full, str, strhelp, strval, proc, from, to, cat, extra, startup)\
 
	SDTG_GENERAL(#var, SDT_ONEOFMANY, SL_VAR, type, flags, guiflags, _settings_client.var, 1, def, 0, max, 0, full, str, strhelp, strval, proc, from, to, cat, extra, startup)
 

	
 
#define SDT_END() {{nullptr, nullptr, SDT_NUMX, SGF_NONE, 0, 0, 0, nullptr, STR_NULL, STR_NULL, STR_NULL, nullptr, nullptr, SC_NONE, false}, SLE_END()}
 

	
src/table/settings.ini
Show inline comments
 
@@ -56,13 +56,13 @@ static bool UpdateClientConfigValues(int
 
 * It is also a bit tricky since you would think that service_interval
 
 * for example doesn't need to be synched. Every client assigns the
 
 * service_interval value to the v->service_interval, meaning that every client
 
 * assigns its own value. If the setting was company-based, that would mean that
 
 * vehicles could decide on different moments that they are heading back to a
 
 * service depot, causing desyncs on a massive scale. */
 
const SettingDesc _settings[] = {
 
const SettingTable _settings{
 
[post-amble]
 
};
 
[templates]
 
SDTG_BOOL  =  SDTG_BOOL($name,              $flags, $guiflags, $var, $def,                        $str, $strhelp, $strval, $proc, $from, $to,        $cat, $extra, $startup),
 
SDTG_VAR   =   SDTG_VAR($name,       $type, $flags, $guiflags, $var, $def, $min, $max, $interval, $str, $strhelp, $strval, $proc, $from, $to,        $cat, $extra, $startup),
 
SDTG_OMANY = SDTG_OMANY($name,       $type, $flags, $guiflags, $var, $def,       $max, $full,     $str, $strhelp, $strval, $proc, $from, $to,        $cat, $extra, $startup),
 
@@ -73,13 +73,12 @@ SDTC_SSTR  =  SDTC_SSTR(       $var, $ty
 
SDTC_VAR   =   SDTC_VAR(       $var, $type, $flags, $guiflags, $def,       $min, $max, $interval, $str, $strhelp, $strval, $proc, $from, $to,        $cat, $extra, $startup),
 
SDT_BOOL   =   SDT_BOOL($base, $var,        $flags, $guiflags, $def,                              $str, $strhelp, $strval, $proc, $from, $to,        $cat, $extra, $startup),
 
SDT_OMANY  =  SDT_OMANY($base, $var, $type, $flags, $guiflags, $def,             $max, $full,     $str, $strhelp, $strval, $proc, $from, $to, $load, $cat, $extra, $startup),
 
SDT_SSTR   =   SDT_SSTR($base, $var, $type, $flags, $guiflags, $def,                              $str, $strhelp, $strval, $proc, $from, $to,        $cat, $extra, $startup),
 
SDT_VAR    =    SDT_VAR($base, $var, $type, $flags, $guiflags, $def,       $min, $max, $interval, $str, $strhelp, $strval, $proc, $from, $to,        $cat, $extra, $startup),
 
SDT_NULL   =   SDT_NULL($length, $from, $to),
 
SDT_END    = SDT_END()
 

	
 
[validation]
 
SDTG_VAR = static_assert($max <= MAX_$type, "Maximum value for $var exceeds storage size");
 
SDTG_OMANY = static_assert($max <= MAX_$type, "Maximum value for $var exceeds storage size");
 
SDTC_OMANY = static_assert($max <= MAX_$type, "Maximum value for $var exceeds storage size");
 
SDTC_VAR = static_assert($max <= MAX_$type, "Maximum value for $var exceeds storage size");
 
@@ -4109,9 +4108,6 @@ def      = 0
 
min      = 0
 
max      = 2
 
str      = STR_CONFIG_SETTING_RIGHT_MOUSE_BTN_EMU
 
strhelp  = STR_CONFIG_SETTING_RIGHT_MOUSE_BTN_EMU_HELPTEXT
 
strval   = STR_CONFIG_SETTING_RIGHT_MOUSE_BTN_EMU_COMMAND
 
cat      = SC_BASIC
 

	
 
[SDT_END]
 

	
src/table/win32_settings.ini
Show inline comments
 
@@ -6,20 +6,19 @@
 

	
 
[pre-amble]
 
/* win32_v.cpp only settings */
 
#if defined(_WIN32) && !defined(DEDICATED)
 
extern bool _window_maximize;
 

	
 
static const SettingDesc _win32_settings[] = {
 
static const SettingTable _win32_settings{
 
[post-amble]
 
};
 
#endif /* _WIN32 */
 
[templates]
 
SDTG_BOOL = SDTG_BOOL($name,        $flags, $guiflags, $var, $def,                        $str, $strhelp, $strval, $proc, $from, $to, $cat, $extra, $startup),
 
SDTG_VAR  =  SDTG_VAR($name, $type, $flags, $guiflags, $var, $def, $min, $max, $interval, $str, $strhelp, $strval, $proc, $from, $to, $cat, $extra, $startup),
 
SDTG_END  = SDTG_END()
 

	
 
[validation]
 
SDTG_VAR = static_assert($max <= MAX_$type, "Maximum value for $var exceeds storage size");
 

	
 
[defaults]
 
flags    = SLF_NOT_IN_SAVE | SLF_NO_NETWORK_SYNC
 
@@ -39,9 +38,6 @@ startup  = true
 

	
 
[SDTG_BOOL]
 
name     = ""window_maximize""
 
var      = _window_maximize
 
def      = false
 
cat      = SC_BASIC
 

	
 
[SDTG_END]
 

	
src/table/window_settings.ini
Show inline comments
 
@@ -3,19 +3,18 @@
 
; OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 
; See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
 
;
 

	
 
[pre-amble]
 

	
 
static const SettingDesc _window_settings[] = {
 
static const SettingTable _window_settings{
 
[post-amble]
 
};
 
[templates]
 
SDT_BOOL = SDT_BOOL($base, $var,        $flags, $guiflags, $def,                        $str, $strhelp, $strval, $proc, $from, $to, $cat, $extra, $startup),
 
SDT_VAR  =  SDT_VAR($base, $var, $type, $flags, $guiflags, $def, $min, $max, $interval, $str, $strhelp, $strval, $proc, $from, $to, $cat, $extra, $startup),
 
SDT_END  = SDT_END()
 

	
 
[validation]
 
SDT_VAR = static_assert($max <= MAX_$type, "Maximum value for $base.$var exceeds storage size");
 

	
 
[defaults]
 
base     = WindowDesc
 
@@ -49,10 +48,6 @@ max      = 32000
 
[SDT_VAR]
 
var      = pref_height
 
type     = SLE_INT16
 
def      = 0
 
min      = 0
 
max      = 32000
 

	
 
[SDT_END]
 

	
 
};
0 comments (0 inline, 0 general)