mirror of https://github.com/OpenTTD/OpenTTD
Change: only output settings that are changed in crashlog
parent
6a4a89a73e
commit
b6b559c518
|
@ -136,7 +136,7 @@ void CrashLog::FillCrashLog()
|
||||||
if (!this->TryExecute("companies", [&game]() { SurveyCompanies(game["companies"]); return true; })) {
|
if (!this->TryExecute("companies", [&game]() { SurveyCompanies(game["companies"]); return true; })) {
|
||||||
game["companies"] = "crashed while gathering information";
|
game["companies"] = "crashed while gathering information";
|
||||||
}
|
}
|
||||||
if (!this->TryExecute("settings", [&game]() { SurveySettings(game["settings"]); return true; })) {
|
if (!this->TryExecute("settings", [&game]() { SurveySettings(game["settings_changed"], true); return true; })) {
|
||||||
game["settings"] = "crashed while gathering information";
|
game["settings"] = "crashed while gathering information";
|
||||||
}
|
}
|
||||||
if (!this->TryExecute("grfs", [&game]() { SurveyGrfs(game["grfs"]); return true; })) {
|
if (!this->TryExecute("grfs", [&game]() { SurveyGrfs(game["grfs"]); return true; })) {
|
||||||
|
|
|
@ -66,7 +66,7 @@ std::string NetworkSurveyHandler::CreatePayload(Reason reason, bool for_preview)
|
||||||
auto &game = survey["game"];
|
auto &game = survey["game"];
|
||||||
SurveyTimers(game["timers"]);
|
SurveyTimers(game["timers"]);
|
||||||
SurveyCompanies(game["companies"]);
|
SurveyCompanies(game["companies"]);
|
||||||
SurveySettings(game["settings"]);
|
SurveySettings(game["settings"], false);
|
||||||
SurveyGrfs(game["grfs"]);
|
SurveyGrfs(game["grfs"]);
|
||||||
SurveyGameScript(game["game_script"]);
|
SurveyGameScript(game["game_script"]);
|
||||||
}
|
}
|
||||||
|
|
|
@ -716,6 +716,12 @@ bool IntSettingDesc::IsSameValue(const IniItem *item, void *object) const
|
||||||
return item_value == object_value;
|
return item_value == object_value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool IntSettingDesc::IsDefaultValue(void *object) const
|
||||||
|
{
|
||||||
|
int32_t object_value = this->Read(object);
|
||||||
|
return this->def == object_value;
|
||||||
|
}
|
||||||
|
|
||||||
std::string StringSettingDesc::FormatValue(const void *object) const
|
std::string StringSettingDesc::FormatValue(const void *object) const
|
||||||
{
|
{
|
||||||
const std::string &str = this->Read(object);
|
const std::string &str = this->Read(object);
|
||||||
|
@ -742,12 +748,24 @@ bool StringSettingDesc::IsSameValue(const IniItem *item, void *object) const
|
||||||
return item->value->compare(str) == 0;
|
return item->value->compare(str) == 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool StringSettingDesc::IsDefaultValue(void *object) const
|
||||||
|
{
|
||||||
|
const std::string &str = this->Read(object);
|
||||||
|
return this->def == str;
|
||||||
|
}
|
||||||
|
|
||||||
bool ListSettingDesc::IsSameValue(const IniItem *item, void *object) const
|
bool ListSettingDesc::IsSameValue(const IniItem *item, void *object) const
|
||||||
{
|
{
|
||||||
/* Checking for equality is way more expensive than just writing the value. */
|
/* Checking for equality is way more expensive than just writing the value. */
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool ListSettingDesc::IsDefaultValue(void *object) const
|
||||||
|
{
|
||||||
|
/* Defaults of lists are often complicated, and hard to compare. */
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Loads all items from a 'grpname' section into a list
|
* Loads all items from a 'grpname' section into a list
|
||||||
* The list parameter can be a nullptr pointer, in this case nothing will be
|
* The list parameter can be a nullptr pointer, in this case nothing will be
|
||||||
|
|
|
@ -130,6 +130,14 @@ struct SettingDesc {
|
||||||
* @return True if the value is definitely the same (might be false when the same).
|
* @return True if the value is definitely the same (might be false when the same).
|
||||||
*/
|
*/
|
||||||
virtual bool IsSameValue(const IniItem *item, void *object) const = 0;
|
virtual bool IsSameValue(const IniItem *item, void *object) const = 0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check whether the value is the same as the default value.
|
||||||
|
*
|
||||||
|
* @param object The object the setting is in.
|
||||||
|
* @return true iff the value is the default value.
|
||||||
|
*/
|
||||||
|
virtual bool IsDefaultValue(void *object) const = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
/** Base integer type, including boolean, settings. Only these are shown in the settings UI. */
|
/** Base integer type, including boolean, settings. Only these are shown in the settings UI. */
|
||||||
|
@ -215,6 +223,7 @@ struct IntSettingDesc : SettingDesc {
|
||||||
std::string FormatValue(const void *object) const override;
|
std::string FormatValue(const void *object) const override;
|
||||||
void ParseValue(const IniItem *item, void *object) const override;
|
void ParseValue(const IniItem *item, void *object) const override;
|
||||||
bool IsSameValue(const IniItem *item, void *object) const override;
|
bool IsSameValue(const IniItem *item, void *object) const override;
|
||||||
|
bool IsDefaultValue(void *object) const override;
|
||||||
int32_t Read(const void *object) const;
|
int32_t Read(const void *object) const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
@ -307,6 +316,7 @@ struct StringSettingDesc : SettingDesc {
|
||||||
std::string FormatValue(const void *object) const override;
|
std::string FormatValue(const void *object) const override;
|
||||||
void ParseValue(const IniItem *item, void *object) const override;
|
void ParseValue(const IniItem *item, void *object) const override;
|
||||||
bool IsSameValue(const IniItem *item, void *object) const override;
|
bool IsSameValue(const IniItem *item, void *object) const override;
|
||||||
|
bool IsDefaultValue(void *object) const override;
|
||||||
const std::string &Read(const void *object) const;
|
const std::string &Read(const void *object) const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
@ -324,6 +334,7 @@ struct ListSettingDesc : SettingDesc {
|
||||||
std::string FormatValue(const void *object) const override;
|
std::string FormatValue(const void *object) const override;
|
||||||
void ParseValue(const IniItem *item, void *object) const override;
|
void ParseValue(const IniItem *item, void *object) const override;
|
||||||
bool IsSameValue(const IniItem *item, void *object) const override;
|
bool IsSameValue(const IniItem *item, void *object) const override;
|
||||||
|
bool IsDefaultValue(void *object) const override;
|
||||||
};
|
};
|
||||||
|
|
||||||
/** Placeholder for settings that have been removed, but might still linger in the savegame. */
|
/** Placeholder for settings that have been removed, but might still linger in the savegame. */
|
||||||
|
@ -334,6 +345,7 @@ struct NullSettingDesc : SettingDesc {
|
||||||
std::string FormatValue(const void *object) const override { NOT_REACHED(); }
|
std::string FormatValue(const void *object) const override { NOT_REACHED(); }
|
||||||
void ParseValue(const IniItem *item, void *object) const override { NOT_REACHED(); }
|
void ParseValue(const IniItem *item, void *object) const override { NOT_REACHED(); }
|
||||||
bool IsSameValue(const IniItem *item, void *object) const override { NOT_REACHED(); }
|
bool IsSameValue(const IniItem *item, void *object) const override { NOT_REACHED(); }
|
||||||
|
bool IsDefaultValue(void *object) const override { NOT_REACHED(); }
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef std::variant<IntSettingDesc, BoolSettingDesc, OneOfManySettingDesc, ManyOfManySettingDesc, StringSettingDesc, ListSettingDesc, NullSettingDesc> SettingVariant;
|
typedef std::variant<IntSettingDesc, BoolSettingDesc, OneOfManySettingDesc, ManyOfManySettingDesc, StringSettingDesc, ListSettingDesc, NullSettingDesc> SettingVariant;
|
||||||
|
|
|
@ -122,8 +122,9 @@ static auto &GenericSettingTables()
|
||||||
* @param survey The JSON object.
|
* @param survey The JSON object.
|
||||||
* @param table The settings table to convert.
|
* @param table The settings table to convert.
|
||||||
* @param object The object to get the settings from.
|
* @param object The object to get the settings from.
|
||||||
|
* @param skip_if_default If true, skip any settings that are on their default value.
|
||||||
*/
|
*/
|
||||||
static void SurveySettingsTable(nlohmann::json &survey, const SettingTable &table, void *object)
|
static void SurveySettingsTable(nlohmann::json &survey, const SettingTable &table, void *object, bool skip_if_default)
|
||||||
{
|
{
|
||||||
for (auto &desc : table) {
|
for (auto &desc : table) {
|
||||||
const SettingDesc *sd = GetSettingDesc(desc);
|
const SettingDesc *sd = GetSettingDesc(desc);
|
||||||
|
@ -131,6 +132,7 @@ static void SurveySettingsTable(nlohmann::json &survey, const SettingTable &tabl
|
||||||
if (!SlIsObjectCurrentlyValid(sd->save.version_from, sd->save.version_to)) continue;
|
if (!SlIsObjectCurrentlyValid(sd->save.version_from, sd->save.version_to)) continue;
|
||||||
|
|
||||||
auto name = sd->GetName();
|
auto name = sd->GetName();
|
||||||
|
if (skip_if_default && sd->IsDefaultValue(object)) continue;
|
||||||
survey[name] = sd->FormatValue(object);
|
survey[name] = sd->FormatValue(object);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -140,17 +142,17 @@ static void SurveySettingsTable(nlohmann::json &survey, const SettingTable &tabl
|
||||||
*
|
*
|
||||||
* @param survey The JSON object.
|
* @param survey The JSON object.
|
||||||
*/
|
*/
|
||||||
void SurveySettings(nlohmann::json &survey)
|
void SurveySettings(nlohmann::json &survey, bool skip_if_default)
|
||||||
{
|
{
|
||||||
SurveySettingsTable(survey, _misc_settings, nullptr);
|
SurveySettingsTable(survey, _misc_settings, nullptr, skip_if_default);
|
||||||
#if defined(_WIN32) && !defined(DEDICATED)
|
#if defined(_WIN32) && !defined(DEDICATED)
|
||||||
SurveySettingsTable(survey, _win32_settings, nullptr);
|
SurveySettingsTable(survey, _win32_settings, nullptr, skip_if_default);
|
||||||
#endif
|
#endif
|
||||||
for (auto &table : GenericSettingTables()) {
|
for (auto &table : GenericSettingTables()) {
|
||||||
SurveySettingsTable(survey, table, &_settings_game);
|
SurveySettingsTable(survey, table, &_settings_game, skip_if_default);
|
||||||
}
|
}
|
||||||
SurveySettingsTable(survey, _currency_settings, &_custom_currency);
|
SurveySettingsTable(survey, _currency_settings, &_custom_currency, skip_if_default);
|
||||||
SurveySettingsTable(survey, _company_settings, &_settings_client.company);
|
SurveySettingsTable(survey, _company_settings, &_settings_client.company, skip_if_default);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -22,7 +22,7 @@ void SurveyGameScript(nlohmann::json &survey);
|
||||||
void SurveyGrfs(nlohmann::json &survey);
|
void SurveyGrfs(nlohmann::json &survey);
|
||||||
void SurveyLibraries(nlohmann::json &survey);
|
void SurveyLibraries(nlohmann::json &survey);
|
||||||
void SurveyOpenTTD(nlohmann::json &survey);
|
void SurveyOpenTTD(nlohmann::json &survey);
|
||||||
void SurveySettings(nlohmann::json &survey);
|
void SurveySettings(nlohmann::json &survey, bool skip_if_default);
|
||||||
void SurveyTimers(nlohmann::json &survey);
|
void SurveyTimers(nlohmann::json &survey);
|
||||||
|
|
||||||
/* Defined in os/<os>/survey_<os>.cpp. */
|
/* Defined in os/<os>/survey_<os>.cpp. */
|
||||||
|
|
Loading…
Reference in New Issue