summaryrefslogtreecommitdiff
path: root/src/network/network_client.cpp
diff options
context:
space:
mode:
authorPatric Stout <truebrain@openttd.org>2021-02-25 20:30:16 +0100
committerPatric Stout <github@truebrain.nl>2021-02-27 00:36:14 +0100
commit53c28a8ec9845a90f0c9e1ed83a87dbb7959d14d (patch)
treeec8b01761fd3c819d4e1317c86e7da37070b1152 /src/network/network_client.cpp
parentdc7ba33b515c83ec0ebd9cb1789fd20294dee4ec (diff)
downloadopenttd-53c28a8ec9845a90f0c9e1ed83a87dbb7959d14d.tar.xz
Codechange: [Network] replace _realtime_tick with std::chrono
Diffstat (limited to 'src/network/network_client.cpp')
-rw-r--r--src/network/network_client.cpp20
1 files changed, 8 insertions, 12 deletions
diff --git a/src/network/network_client.cpp b/src/network/network_client.cpp
index 7a7ec9f21..cd1904269 100644
--- a/src/network/network_client.cpp
+++ b/src/network/network_client.cpp
@@ -877,7 +877,7 @@ NetworkRecvStatus ClientNetworkGameSocketHandler::Receive_SERVER_MAP_DONE(Packet
bool load_success = SafeLoad({}, SLO_LOAD, DFT_GAME_FILE, GM_NORMAL, NO_DIRECTORY, lf);
/* Long savegame loads shouldn't affect the lag calculation! */
- this->last_packet = _realtime_tick;
+ this->last_packet = std::chrono::steady_clock::now();
if (!load_success) {
DeleteWindowById(WC_NETWORK_STATUS_WINDOW, WN_NETWORK_STATUS_WINDOW_JOIN);
@@ -1178,27 +1178,23 @@ void ClientNetworkGameSocketHandler::CheckConnection()
/* Only once we're authorized we can expect a steady stream of packets. */
if (this->status < STATUS_AUTHORIZED) return;
- /* It might... sometimes occur that the realtime ticker overflows. */
- if (_realtime_tick < this->last_packet) this->last_packet = _realtime_tick;
-
- /* Lag is in milliseconds; 5 seconds are roughly twice the
- * server's "you're slow" threshold (1 game day). */
- uint lag = (_realtime_tick - this->last_packet) / 1000;
- if (lag < 5) return;
+ /* 5 seconds are roughly twice the server's "you're slow" threshold (1 game day). */
+ std::chrono::steady_clock::duration lag = std::chrono::steady_clock::now() - this->last_packet;
+ if (lag < std::chrono::seconds(5)) return;
/* 20 seconds are (way) more than 4 game days after which
* the server will forcefully disconnect you. */
- if (lag > 20) {
+ if (lag > std::chrono::seconds(20)) {
this->NetworkGameSocketHandler::CloseConnection();
return;
}
/* Prevent showing the lag message every tick; just update it when needed. */
- static uint last_lag = 0;
- if (last_lag == lag) return;
+ static std::chrono::steady_clock::duration last_lag = {};
+ if (std::chrono::duration_cast<std::chrono::seconds>(last_lag) == std::chrono::duration_cast<std::chrono::seconds>(lag)) return;
last_lag = lag;
- SetDParam(0, lag);
+ SetDParam(0, std::chrono::duration_cast<std::chrono::seconds>(lag).count());
ShowErrorMessage(STR_NETWORK_ERROR_CLIENT_GUI_LOST_CONNECTION_CAPTION, STR_NETWORK_ERROR_CLIENT_GUI_LOST_CONNECTION, WL_INFO);
}