mirror of https://github.com/OpenTTD/OpenTTD
Cleanup: remove unneeded temporary variables and casts
parent
0d6597a9e6
commit
72ec81325b
|
@ -2199,7 +2199,7 @@ public:
|
||||||
case WID_CL_SERVER_NAME_EDIT: {
|
case WID_CL_SERVER_NAME_EDIT: {
|
||||||
if (!_network_server) break;
|
if (!_network_server) break;
|
||||||
|
|
||||||
SetSettingValue(GetSettingFromName("network.server_name"), StrEmpty(str) ? "Unnamed Server" : str);
|
SetSettingValue(GetSettingFromName("network.server_name")->AsStringSetting(), StrEmpty(str) ? "Unnamed Server" : str);
|
||||||
this->InvalidateData();
|
this->InvalidateData();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -2208,7 +2208,7 @@ public:
|
||||||
std::string client_name(str);
|
std::string client_name(str);
|
||||||
if (!NetworkValidateClientName(client_name)) break;
|
if (!NetworkValidateClientName(client_name)) break;
|
||||||
|
|
||||||
SetSettingValue(GetSettingFromName("network.client_name"), client_name.c_str());
|
SetSettingValue(GetSettingFromName("network.client_name")->AsStringSetting(), client_name.c_str());
|
||||||
this->InvalidateData();
|
this->InvalidateData();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
|
@ -556,14 +556,11 @@ static void IniLoadSettings(IniFile *ini, const SettingTable &settings_table, co
|
||||||
IniGroup *group_def = ini->GetGroup(grpname);
|
IniGroup *group_def = ini->GetGroup(grpname);
|
||||||
|
|
||||||
for (auto &sd : settings_table) {
|
for (auto &sd : settings_table) {
|
||||||
const SettingDesc *sdb = sd.get();
|
if (!SlIsObjectCurrentlyValid(sd->save.version_from, sd->save.version_to)) continue;
|
||||||
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 = ? */
|
/* For settings.xx.yy load the settings from [xx] yy = ? */
|
||||||
std::string s{ sdb->name };
|
std::string s{ sd->name };
|
||||||
auto sc = s.find('.');
|
auto sc = s.find('.');
|
||||||
if (sc != std::string::npos) {
|
if (sc != std::string::npos) {
|
||||||
group = ini->GetGroup(s.substr(0, sc));
|
group = ini->GetGroup(s.substr(0, sc));
|
||||||
|
@ -585,7 +582,7 @@ static void IniLoadSettings(IniFile *ini, const SettingTable &settings_table, co
|
||||||
if (sc != std::string::npos) item = ini->GetGroup(s.substr(0, sc))->GetItem(s.substr(sc + 1), false);
|
if (sc != std::string::npos) item = ini->GetGroup(s.substr(0, sc))->GetItem(s.substr(sc + 1), false);
|
||||||
}
|
}
|
||||||
|
|
||||||
sdb->ParseValue(item, object);
|
sd->ParseValue(item, object);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -634,16 +631,13 @@ static void IniSaveSettings(IniFile *ini, const SettingTable &settings_table, co
|
||||||
char buf[512];
|
char buf[512];
|
||||||
|
|
||||||
for (auto &sd : settings_table) {
|
for (auto &sd : settings_table) {
|
||||||
const SettingDesc *sdb = sd.get();
|
|
||||||
const SaveLoad *sld = &sd->save;
|
|
||||||
|
|
||||||
/* If the setting is not saved to the configuration
|
/* If the setting is not saved to the configuration
|
||||||
* file, just continue with the next setting */
|
* file, just continue with the next setting */
|
||||||
if (!SlIsObjectCurrentlyValid(sld->version_from, sld->version_to)) continue;
|
if (!SlIsObjectCurrentlyValid(sd->save.version_from, sd->save.version_to)) continue;
|
||||||
if (sld->conv & SLF_NOT_IN_CONFIG) continue;
|
if (sd->save.conv & SLF_NOT_IN_CONFIG) continue;
|
||||||
|
|
||||||
/* XXX - wtf is this?? (group override?) */
|
/* XXX - wtf is this?? (group override?) */
|
||||||
std::string s{ sdb->name };
|
std::string s{ sd->name };
|
||||||
auto sc = s.find('.');
|
auto sc = s.find('.');
|
||||||
if (sc != std::string::npos) {
|
if (sc != std::string::npos) {
|
||||||
group = ini->GetGroup(s.substr(0, sc));
|
group = ini->GetGroup(s.substr(0, sc));
|
||||||
|
@ -655,9 +649,9 @@ static void IniSaveSettings(IniFile *ini, const SettingTable &settings_table, co
|
||||||
|
|
||||||
item = group->GetItem(s, true);
|
item = group->GetItem(s, true);
|
||||||
|
|
||||||
if (!item->value.has_value() || !sdb->IsSameValue(item, object)) {
|
if (!item->value.has_value() || !sd->IsSameValue(item, object)) {
|
||||||
/* Value has changed, get the new value and put it into a buffer */
|
/* Value has changed, get the new value and put it into a buffer */
|
||||||
sdb->FormatValue(buf, lastof(buf), object);
|
sd->FormatValue(buf, lastof(buf), object);
|
||||||
|
|
||||||
/* The value is different, that means we have to write it to the ini */
|
/* The value is different, that means we have to write it to the ini */
|
||||||
item->value.emplace(buf);
|
item->value.emplace(buf);
|
||||||
|
@ -2009,7 +2003,7 @@ static uint GetCompanySettingIndex(const SettingDesc *sd)
|
||||||
* @param value new value of the setting
|
* @param value new value of the setting
|
||||||
* @param force_newgame force the newgame settings
|
* @param force_newgame force the newgame settings
|
||||||
*/
|
*/
|
||||||
bool SetSettingValue(const SettingDesc *sd, int32 value, bool force_newgame)
|
bool SetSettingValue(const IntSettingDesc *sd, int32 value, bool force_newgame)
|
||||||
{
|
{
|
||||||
const IntSettingDesc *setting = sd->AsIntSetting();
|
const IntSettingDesc *setting = sd->AsIntSetting();
|
||||||
if ((setting->flags & SGF_PER_COMPANY) != 0) {
|
if ((setting->flags & SGF_PER_COMPANY) != 0) {
|
||||||
|
@ -2090,7 +2084,7 @@ uint GetCompanySettingIndex(const char *name)
|
||||||
* @param force_newgame force the newgame settings
|
* @param force_newgame force the newgame settings
|
||||||
* @note Strings WILL NOT be synced over the network
|
* @note Strings WILL NOT be synced over the network
|
||||||
*/
|
*/
|
||||||
bool SetSettingValue(const SettingDesc *sd, const char *value, bool force_newgame)
|
bool SetSettingValue(const StringSettingDesc *sd, const char *value, bool force_newgame)
|
||||||
{
|
{
|
||||||
assert(sd->save.conv & SLF_NO_NETWORK_SYNC);
|
assert(sd->save.conv & SLF_NO_NETWORK_SYNC);
|
||||||
|
|
||||||
|
@ -2165,7 +2159,7 @@ void IConsoleSetSetting(const char *name, const char *value, bool force_newgame)
|
||||||
|
|
||||||
bool success;
|
bool success;
|
||||||
if (sd->cmd == SDT_STDSTRING) {
|
if (sd->cmd == SDT_STDSTRING) {
|
||||||
success = SetSettingValue(sd, value, force_newgame);
|
success = SetSettingValue(sd->AsStringSetting(), value, force_newgame);
|
||||||
} else {
|
} else {
|
||||||
uint32 val;
|
uint32 val;
|
||||||
extern bool GetArgumentInteger(uint32 *value, const char *arg);
|
extern bool GetArgumentInteger(uint32 *value, const char *arg);
|
||||||
|
@ -2175,7 +2169,7 @@ void IConsoleSetSetting(const char *name, const char *value, bool force_newgame)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
success = SetSettingValue(sd, val, force_newgame);
|
success = SetSettingValue(sd->AsIntSetting(), val, force_newgame);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!success) {
|
if (!success) {
|
||||||
|
@ -2191,7 +2185,7 @@ void IConsoleSetSetting(const char *name, int value)
|
||||||
{
|
{
|
||||||
const SettingDesc *sd = GetSettingFromName(name);
|
const SettingDesc *sd = GetSettingFromName(name);
|
||||||
assert(sd != nullptr);
|
assert(sd != nullptr);
|
||||||
SetSettingValue(sd, value);
|
SetSettingValue(sd->AsIntSetting(), value);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -2250,11 +2244,10 @@ void IConsoleListSettings(const char *prefilter)
|
||||||
static void LoadSettings(const SettingTable &settings, void *object)
|
static void LoadSettings(const SettingTable &settings, void *object)
|
||||||
{
|
{
|
||||||
for (auto &osd : settings) {
|
for (auto &osd : settings) {
|
||||||
const SaveLoad *sld = &osd->save;
|
void *ptr = GetVariableAddress(object, &osd->save);
|
||||||
void *ptr = GetVariableAddress(object, sld);
|
|
||||||
|
|
||||||
if (!SlObjectMember(ptr, sld)) continue;
|
if (!SlObjectMember(ptr, &osd->save)) continue;
|
||||||
if (osd->IsIntSetting()) osd->AsIntSetting()->Write_ValidateSetting(object, ReadValue(ptr, sld->conv));
|
if (osd->IsIntSetting()) osd->AsIntSetting()->Write_ValidateSetting(object, ReadValue(ptr, osd->save.conv));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -206,8 +206,8 @@ struct NullSettingDesc : SettingDesc {
|
||||||
typedef std::initializer_list<std::unique_ptr<const SettingDesc>> SettingTable;
|
typedef std::initializer_list<std::unique_ptr<const SettingDesc>> SettingTable;
|
||||||
|
|
||||||
const SettingDesc *GetSettingFromName(const char *name);
|
const SettingDesc *GetSettingFromName(const char *name);
|
||||||
bool SetSettingValue(const SettingDesc *sd, int32 value, bool force_newgame = false);
|
bool SetSettingValue(const IntSettingDesc *sd, int32 value, bool force_newgame = false);
|
||||||
bool SetSettingValue(const SettingDesc *sd, const char *value, bool force_newgame = false);
|
bool SetSettingValue(const StringSettingDesc *sd, const char *value, bool force_newgame = false);
|
||||||
uint GetSettingIndex(const SettingDesc *sd);
|
uint GetSettingIndex(const SettingDesc *sd);
|
||||||
|
|
||||||
#endif /* SETTINGS_INTERNAL_H */
|
#endif /* SETTINGS_INTERNAL_H */
|
||||||
|
|
Loading…
Reference in New Issue