mirror of
https://github.com/OpenTTD/OpenTTD.git
synced 2025-08-27 08:29:11 +00:00
Codechange: Move Ticks into their own class
This commit is contained in:
@@ -11,6 +11,7 @@
|
||||
|
||||
#include "../strings_func.h"
|
||||
#include "../command_func.h"
|
||||
#include "../timer/timer_game_tick.h"
|
||||
#include "../timer/timer_game_calendar.h"
|
||||
#include "network_admin.h"
|
||||
#include "network_client.h"
|
||||
@@ -274,8 +275,8 @@ uint NetworkCalculateLag(const NetworkClientSocket *cs)
|
||||
/* This client has missed their ACK packet after 1 DAY_TICKS..
|
||||
* so we increase their lag for every frame that passes!
|
||||
* The packet can be out by a max of _net_frame_freq */
|
||||
if (cs->last_frame_server + DAY_TICKS + _settings_client.network.frame_freq < _frame_counter) {
|
||||
lag += _frame_counter - (cs->last_frame_server + DAY_TICKS + _settings_client.network.frame_freq);
|
||||
if (cs->last_frame_server + Ticks::DAY_TICKS + _settings_client.network.frame_freq < _frame_counter) {
|
||||
lag += _frame_counter - (cs->last_frame_server + Ticks::DAY_TICKS + _settings_client.network.frame_freq);
|
||||
}
|
||||
return lag;
|
||||
}
|
||||
|
@@ -20,6 +20,7 @@
|
||||
#include "../company_gui.h"
|
||||
#include "../company_cmd.h"
|
||||
#include "../core/random_func.hpp"
|
||||
#include "../timer/timer_game_tick.h"
|
||||
#include "../timer/timer_game_calendar.h"
|
||||
#include "../gfx_func.h"
|
||||
#include "../error.h"
|
||||
@@ -876,7 +877,7 @@ NetworkRecvStatus ClientNetworkGameSocketHandler::Receive_SERVER_FRAME(Packet *p
|
||||
/* Let the server know that we received this frame correctly
|
||||
* We do this only once per day, to save some bandwidth ;) */
|
||||
if (!_network_first_time && last_ack_frame < _frame_counter) {
|
||||
last_ack_frame = _frame_counter + DAY_TICKS;
|
||||
last_ack_frame = _frame_counter + Ticks::DAY_TICKS;
|
||||
Debug(net, 7, "Sent ACK at {}", _frame_counter);
|
||||
SendAck();
|
||||
}
|
||||
|
@@ -1141,7 +1141,7 @@ NetworkRecvStatus ServerNetworkGameSocketHandler::Receive_CLIENT_ACK(Packet *p)
|
||||
/* The client is trying to catch up with the server */
|
||||
if (this->status == STATUS_PRE_ACTIVE) {
|
||||
/* The client is not yet caught up? */
|
||||
if (frame + DAY_TICKS < _frame_counter) return NETWORK_RECV_STATUS_OKAY;
|
||||
if (frame + Ticks::DAY_TICKS < _frame_counter) return NETWORK_RECV_STATUS_OKAY;
|
||||
|
||||
/* Now it is! Unpause the game */
|
||||
this->status = STATUS_ACTIVE;
|
||||
@@ -1724,7 +1724,7 @@ void NetworkServer_Tick(bool send_frame)
|
||||
* did not receive a packet, then the client is not just
|
||||
* slow, but the connection is likely severed. Mentioning
|
||||
* frame_freq is not useful in this case. */
|
||||
if (lag > (uint)DAY_TICKS && cs->lag_test == 0 && cs->last_packet + std::chrono::seconds(2) > std::chrono::steady_clock::now()) {
|
||||
if (lag > (uint)Ticks::DAY_TICKS && cs->lag_test == 0 && cs->last_packet + std::chrono::seconds(2) > std::chrono::steady_clock::now()) {
|
||||
IConsolePrint(CC_WARNING, "[{}] Client #{} is slow, try increasing [network.]frame_freq to a higher value!", _frame_counter, cs->client_id);
|
||||
cs->lag_test = 1;
|
||||
}
|
||||
|
Reference in New Issue
Block a user