Merge branch 'master' into jgrpp

# Conflicts:
#	.github/workflows/ci-build.yml
#	.github/workflows/release-source.yml
#	CMakeLists.txt
#	COMPILING.md
#	src/network/network_survey.cpp
#	src/network/network_survey.h
#	src/openttd.cpp
#	src/tests/CMakeLists.txt
This commit is contained in:
Jonathan G Rennison
2023-11-17 19:16:55 +00:00
21 changed files with 217 additions and 103 deletions

View File

@@ -37,9 +37,7 @@
#include "../base_media_base.h"
#include "../blitter/factory.hpp"
#ifdef WITH_NLOHMANN_JSON
#include <nlohmann/json.hpp>
#endif /* WITH_NLOHMANN_JSON */
#include "../safeguards.h"
@@ -47,8 +45,6 @@ extern std::string _savegame_id;
NetworkSurveyHandler _survey = {};
#ifdef WITH_NLOHMANN_JSON
NLOHMANN_JSON_SERIALIZE_ENUM(NetworkSurveyHandler::Reason, {
{NetworkSurveyHandler::Reason::PREVIEW, "preview"},
{NetworkSurveyHandler::Reason::LEAVE, "leave"},
@@ -114,8 +110,12 @@ static void SurveySettings(nlohmann::json &survey)
*/
static void SurveyOpenTTD(nlohmann::json &survey)
{
survey["version"] = std::string(_openttd_revision);
survey["newgrf_version"] = _openttd_newgrf_version;
survey["version"]["revision"] = std::string(_openttd_revision);
survey["version"]["modified"] = _openttd_revision_modified;
survey["version"]["tagged"] = _openttd_revision_tagged;
survey["version"]["hash"] = std::string(_openttd_revision_hash);
survey["version"]["newgrf"] = fmt::format("{:X}", _openttd_newgrf_version);
survey["version"]["content"] = std::string(_openttd_content_version);
survey["build_date"] = std::string(_openttd_build_date);
survey["bits"] =
#ifdef POINTER_IS_64BIT
@@ -227,6 +227,21 @@ static void SurveyCompanies(nlohmann::json &survey)
}
}
/**
* Convert timer information to JSON.
*
* @param survey The JSON object.
*/
static void SurveyTimers(nlohmann::json &survey)
{
survey["ticks"] = _scaled_tick_counter;
survey["seconds"] = std::chrono::duration_cast<std::chrono::seconds>(std::chrono::steady_clock::now() - _switch_mode_time).count();
YearMonthDay ymd;
ConvertDateToYMD(_date, &ymd);
survey["calendar"] = fmt::format("{:04}-{:02}-{:02} ({})", ymd.year, ymd.month + 1, ymd.day, _date_fract);
}
/**
* Convert GRF information to JSON.
*
@@ -298,8 +313,6 @@ std::string SurveyMemoryToText(uint64_t memory)
return fmt::format("{} MiB", Ceil(memory, 4));
}
#endif /* WITH_NLOHMANN_JSON */
/**
* Create the payload for the survey.
*
@@ -309,9 +322,6 @@ std::string SurveyMemoryToText(uint64_t memory)
*/
std::string NetworkSurveyHandler::CreatePayload(Reason reason, bool for_preview)
{
#ifndef WITH_NLOHMANN_JSON
return "";
#else
nlohmann::json survey;
survey["schema"] = NETWORK_SURVEY_VERSION;
@@ -335,8 +345,7 @@ std::string NetworkSurveyHandler::CreatePayload(Reason reason, bool for_preview)
{
auto &game = survey["game"];
game["ticks"] = _scaled_tick_counter;
game["time"] = std::chrono::duration_cast<std::chrono::seconds>(std::chrono::steady_clock::now() - _switch_mode_time).count();
SurveyTimers(game["timers"]);
SurveyCompanies(game["companies"]);
SurveySettings(game["settings"]);
SurveyGrfs(game["grfs"]);
@@ -346,7 +355,6 @@ std::string NetworkSurveyHandler::CreatePayload(Reason reason, bool for_preview)
/* For preview, we indent with 4 whitespaces to make things more readable. */
int indent = for_preview ? 4 : -1;
return survey.dump(indent);
#endif /* WITH_NLOHMANN_JSON */
}
/**