mirror of
https://github.com/JGRennison/OpenTTD-patches.git
synced 2024-11-04 06:00:15 +00:00
Survey: Don't transmit invalid realtime duration
This commit is contained in:
parent
903adceab5
commit
2f1d2a9f4b
@ -58,6 +58,7 @@ bool _check_special_modes;
|
|||||||
std::atomic<bool> _exit_game;
|
std::atomic<bool> _exit_game;
|
||||||
GameMode _game_mode;
|
GameMode _game_mode;
|
||||||
SwitchMode _switch_mode; ///< The next mainloop command.
|
SwitchMode _switch_mode; ///< The next mainloop command.
|
||||||
|
bool _switch_mode_time_valid = false;
|
||||||
std::chrono::steady_clock::time_point _switch_mode_time; ///< The time when the switch mode was requested.
|
std::chrono::steady_clock::time_point _switch_mode_time; ///< The time when the switch mode was requested.
|
||||||
PauseMode _pause_mode;
|
PauseMode _pause_mode;
|
||||||
uint32_t _pause_countdown;
|
uint32_t _pause_countdown;
|
||||||
|
@ -1371,7 +1371,10 @@ void SwitchToMode(SwitchMode new_mode)
|
|||||||
if (_game_mode == GM_NORMAL && new_mode != SM_SAVE_GAME) _survey.Transmit(NetworkSurveyHandler::Reason::LEAVE);
|
if (_game_mode == GM_NORMAL && new_mode != SM_SAVE_GAME) _survey.Transmit(NetworkSurveyHandler::Reason::LEAVE);
|
||||||
|
|
||||||
/* Keep track when we last switch mode. Used for survey, to know how long someone was in a game. */
|
/* Keep track when we last switch mode. Used for survey, to know how long someone was in a game. */
|
||||||
if (new_mode != SM_SAVE_GAME) _switch_mode_time = std::chrono::steady_clock::now();
|
if (new_mode != SM_SAVE_GAME) {
|
||||||
|
_switch_mode_time = std::chrono::steady_clock::now();
|
||||||
|
_switch_mode_time_valid = true;
|
||||||
|
}
|
||||||
|
|
||||||
switch (new_mode) {
|
switch (new_mode) {
|
||||||
case SM_EDITOR: // Switch to scenario editor
|
case SM_EDITOR: // Switch to scenario editor
|
||||||
|
@ -61,6 +61,7 @@ enum ExtraDisplayOptions {
|
|||||||
extern GameMode _game_mode;
|
extern GameMode _game_mode;
|
||||||
extern SwitchMode _switch_mode;
|
extern SwitchMode _switch_mode;
|
||||||
extern bool _check_special_modes;
|
extern bool _check_special_modes;
|
||||||
|
extern bool _switch_mode_time_valid;
|
||||||
extern std::chrono::steady_clock::time_point _switch_mode_time;
|
extern std::chrono::steady_clock::time_point _switch_mode_time;
|
||||||
extern std::atomic<bool> _exit_game;
|
extern std::atomic<bool> _exit_game;
|
||||||
extern bool _save_config;
|
extern bool _save_config;
|
||||||
|
@ -290,7 +290,11 @@ void SurveyCompanies(nlohmann::json &survey)
|
|||||||
void SurveyTimers(nlohmann::json &survey)
|
void SurveyTimers(nlohmann::json &survey)
|
||||||
{
|
{
|
||||||
survey["ticks"] = _scaled_tick_counter;
|
survey["ticks"] = _scaled_tick_counter;
|
||||||
survey["seconds"] = std::chrono::duration_cast<std::chrono::seconds>(std::chrono::steady_clock::now() - _switch_mode_time).count();
|
if (_switch_mode_time_valid) {
|
||||||
|
survey["seconds"] = std::chrono::duration_cast<std::chrono::seconds>(std::chrono::steady_clock::now() - _switch_mode_time).count();
|
||||||
|
} else {
|
||||||
|
survey["seconds"] = 0;
|
||||||
|
}
|
||||||
|
|
||||||
survey["calendar"] = fmt::format("{:04}-{:02}-{:02} ({})", _cur_date_ymd.year, _cur_date_ymd.month + 1, _cur_date_ymd.day, _date_fract);
|
survey["calendar"] = fmt::format("{:04}-{:02}-{:02} ({})", _cur_date_ymd.year, _cur_date_ymd.month + 1, _cur_date_ymd.day, _date_fract);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user