Codechange: move all date-related variables inside the timer (#10706)
This commit is contained in:
@@ -14,6 +14,7 @@
|
||||
#include "../../core/bitmath_func.hpp"
|
||||
#include "../../company_base.h"
|
||||
#include "../../date_func.h"
|
||||
#include "../../timer/timer_game_calendar.h"
|
||||
#include "../../debug.h"
|
||||
#include "../../map_func.h"
|
||||
#include "../../game/game.hpp"
|
||||
@@ -149,7 +150,7 @@ const NetworkServerGameInfo *GetCurrentNetworkServerGameInfo()
|
||||
*/
|
||||
_network_game_info.companies_on = (byte)Company::GetNumItems();
|
||||
_network_game_info.spectators_on = NetworkSpectatorCount();
|
||||
_network_game_info.game_date = _date;
|
||||
_network_game_info.game_date = TimerGameCalendar::date;
|
||||
return &_network_game_info;
|
||||
}
|
||||
|
||||
|
@@ -11,7 +11,7 @@
|
||||
|
||||
#include "../strings_func.h"
|
||||
#include "../command_func.h"
|
||||
#include "../date_func.h"
|
||||
#include "../timer/timer_game_calendar.h"
|
||||
#include "network_admin.h"
|
||||
#include "network_client.h"
|
||||
#include "network_query.h"
|
||||
@@ -263,7 +263,7 @@ void NetworkTextMessage(NetworkAction action, TextColour colour, bool self_send,
|
||||
char *msg_ptr = message + Utf8Encode(message, _current_text_dir == TD_LTR ? CHAR_TD_LRM : CHAR_TD_RLM);
|
||||
GetString(msg_ptr, strid, lastof(message));
|
||||
|
||||
Debug(desync, 1, "msg: {:08x}; {:02x}; {}", _date, _date_fract, message);
|
||||
Debug(desync, 1, "msg: {:08x}; {:02x}; {}", TimerGameCalendar::date, TimerGameCalendar::date_fract, message);
|
||||
IConsolePrint(colour, message);
|
||||
NetworkAddChatMessage(colour, _settings_client.gui.network_chat_timeout, message);
|
||||
}
|
||||
@@ -1038,12 +1038,12 @@ void NetworkGameLoop()
|
||||
|
||||
if (_network_server) {
|
||||
/* Log the sync state to check for in-syncedness of replays. */
|
||||
if (_date_fract == 0) {
|
||||
if (TimerGameCalendar::date_fract == 0) {
|
||||
/* We don't want to log multiple times if paused. */
|
||||
static Date last_log;
|
||||
if (last_log != _date) {
|
||||
Debug(desync, 1, "sync: {:08x}; {:02x}; {:08x}; {:08x}", _date, _date_fract, _random.state[0], _random.state[1]);
|
||||
last_log = _date;
|
||||
if (last_log != TimerGameCalendar::date) {
|
||||
Debug(desync, 1, "sync: {:08x}; {:02x}; {:08x}; {:08x}", TimerGameCalendar::date, TimerGameCalendar::date_fract, _random.state[0], _random.state[1]);
|
||||
last_log = TimerGameCalendar::date;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1061,19 +1061,19 @@ void NetworkGameLoop()
|
||||
}
|
||||
|
||||
while (f != nullptr && !feof(f)) {
|
||||
if (_date == next_date && _date_fract == next_date_fract) {
|
||||
if (TimerGameCalendar::date == next_date && TimerGameCalendar::date_fract == next_date_fract) {
|
||||
if (cp != nullptr) {
|
||||
NetworkSendCommand(cp->cmd, cp->err_msg, nullptr, cp->company, cp->data);
|
||||
Debug(desync, 0, "Injecting: {:08x}; {:02x}; {:02x}; {:08x}; {:06x}; {} ({})", _date, _date_fract, (int)_current_company, cp->cmd, cp->tile, FormatArrayAsHex(cp->data), GetCommandName(cp->cmd));
|
||||
Debug(desync, 0, "Injecting: {:08x}; {:02x}; {:02x}; {:08x}; {:06x}; {} ({})", TimerGameCalendar::date, TimerGameCalendar::date_fract, (int)_current_company, cp->cmd, cp->tile, FormatArrayAsHex(cp->data), GetCommandName(cp->cmd));
|
||||
delete cp;
|
||||
cp = nullptr;
|
||||
}
|
||||
if (check_sync_state) {
|
||||
if (sync_state[0] == _random.state[0] && sync_state[1] == _random.state[1]) {
|
||||
Debug(desync, 0, "Sync check: {:08x}; {:02x}; match", _date, _date_fract);
|
||||
Debug(desync, 0, "Sync check: {:08x}; {:02x}; match", TimerGameCalendar::date, TimerGameCalendar::date_fract);
|
||||
} else {
|
||||
Debug(desync, 0, "Sync check: {:08x}; {:02x}; mismatch expected {{{:08x}, {:08x}}}, got {{{:08x}, {:08x}}}",
|
||||
_date, _date_fract, sync_state[0], sync_state[1], _random.state[0], _random.state[1]);
|
||||
TimerGameCalendar::date, TimerGameCalendar::date_fract, sync_state[0], sync_state[1], _random.state[0], _random.state[1]);
|
||||
NOT_REACHED();
|
||||
}
|
||||
check_sync_state = false;
|
||||
|
@@ -10,6 +10,7 @@
|
||||
#include "../stdafx.h"
|
||||
#include "../strings_func.h"
|
||||
#include "../date_func.h"
|
||||
#include "../timer/timer_game_calendar.h"
|
||||
#include "core/game_info.h"
|
||||
#include "network_admin.h"
|
||||
#include "network_base.h"
|
||||
@@ -207,7 +208,7 @@ NetworkRecvStatus ServerNetworkAdminSocketHandler::SendDate()
|
||||
{
|
||||
Packet *p = new Packet(ADMIN_PACKET_SERVER_DATE);
|
||||
|
||||
p->Send_uint32(_date);
|
||||
p->Send_uint32(TimerGameCalendar::date);
|
||||
this->SendPacket(p);
|
||||
|
||||
return NETWORK_RECV_STATUS_OKAY;
|
||||
|
@@ -20,7 +20,7 @@
|
||||
#include "../company_gui.h"
|
||||
#include "../company_cmd.h"
|
||||
#include "../core/random_func.hpp"
|
||||
#include "../date_func.h"
|
||||
#include "../timer/timer_game_calendar.h"
|
||||
#include "../gfx_func.h"
|
||||
#include "../error.h"
|
||||
#include "../rev.h"
|
||||
@@ -277,7 +277,7 @@ void ClientNetworkGameSocketHandler::ClientError(NetworkRecvStatus res)
|
||||
if (_sync_seed_1 != _random.state[0]) {
|
||||
#endif
|
||||
ShowNetworkError(STR_NETWORK_ERROR_DESYNC);
|
||||
Debug(desync, 1, "sync_err: {:08x}; {:02x}", _date, _date_fract);
|
||||
Debug(desync, 1, "sync_err: {:08x}; {:02x}", TimerGameCalendar::date, TimerGameCalendar::date_fract);
|
||||
Debug(net, 0, "Sync error detected");
|
||||
my_client->ClientError(NETWORK_RECV_STATUS_DESYNC);
|
||||
return false;
|
||||
|
@@ -9,7 +9,6 @@
|
||||
|
||||
#include "../stdafx.h"
|
||||
#include "../strings_func.h"
|
||||
#include "../date_func.h"
|
||||
#include "core/game_info.h"
|
||||
#include "network_admin.h"
|
||||
#include "network_server.h"
|
||||
@@ -882,10 +881,10 @@ NetworkRecvStatus ServerNetworkGameSocketHandler::Receive_CLIENT_JOIN(Packet *p)
|
||||
assert(NetworkClientInfo::CanAllocateItem());
|
||||
NetworkClientInfo *ci = new NetworkClientInfo(this->client_id);
|
||||
this->SetInfo(ci);
|
||||
ci->join_date = _date;
|
||||
ci->join_date = TimerGameCalendar::date;
|
||||
ci->client_name = client_name;
|
||||
ci->client_playas = playas;
|
||||
Debug(desync, 1, "client: {:08x}; {:02x}; {:02x}; {:02x}", _date, _date_fract, (int)ci->client_playas, (int)ci->index);
|
||||
Debug(desync, 1, "client: {:08x}; {:02x}; {:02x}; {:02x}", TimerGameCalendar::date, TimerGameCalendar::date_fract, (int)ci->client_playas, (int)ci->index);
|
||||
|
||||
/* Make sure companies to which people try to join are not autocleaned */
|
||||
if (Company::IsValidID(playas)) _network_company_states[playas].months_empty = 0;
|
||||
@@ -1479,7 +1478,7 @@ void NetworkUpdateClientInfo(ClientID client_id)
|
||||
|
||||
if (ci == nullptr) return;
|
||||
|
||||
Debug(desync, 1, "client: {:08x}; {:02x}; {:02x}; {:04x}", _date, _date_fract, (int)ci->client_playas, client_id);
|
||||
Debug(desync, 1, "client: {:08x}; {:02x}; {:02x}; {:04x}", TimerGameCalendar::date, TimerGameCalendar::date_fract, (int)ci->client_playas, client_id);
|
||||
|
||||
for (NetworkClientSocket *cs : NetworkClientSocket::Iterate()) {
|
||||
if (cs->status >= ServerNetworkGameSocketHandler::STATUS_AUTHORIZED) {
|
||||
@@ -1493,8 +1492,8 @@ void NetworkUpdateClientInfo(ClientID client_id)
|
||||
/** Check if we want to restart the map */
|
||||
static void NetworkCheckRestartMap()
|
||||
{
|
||||
if (_settings_client.network.restart_game_year != 0 && _cur_year >= _settings_client.network.restart_game_year) {
|
||||
Debug(net, 3, "Auto-restarting map: year {} reached", _cur_year);
|
||||
if (_settings_client.network.restart_game_year != 0 && TimerGameCalendar::year >= _settings_client.network.restart_game_year) {
|
||||
Debug(net, 3, "Auto-restarting map: year {} reached", TimerGameCalendar::year);
|
||||
|
||||
_settings_newgame.game_creation.generation_seed = GENERATE_NEW_SEED;
|
||||
switch(_file_to_saveload.abstract_ftype) {
|
||||
@@ -1829,7 +1828,7 @@ static IntervalTimer<TimerGameCalendar> _network_monthly({TimerGameCalendar::MON
|
||||
|
||||
NetworkAutoCleanCompanies();
|
||||
NetworkAdminUpdate(ADMIN_FREQUENCY_MONTHLY);
|
||||
if ((_cur_month % 3) == 0) NetworkAdminUpdate(ADMIN_FREQUENCY_QUARTERLY);
|
||||
if ((TimerGameCalendar::month % 3) == 0) NetworkAdminUpdate(ADMIN_FREQUENCY_QUARTERLY);
|
||||
});
|
||||
|
||||
/** Daily "callback". Called whenever the date changes. */
|
||||
@@ -1838,7 +1837,7 @@ static IntervalTimer<TimerGameCalendar> _network_daily({TimerGameCalendar::DAY,
|
||||
if (!_network_server) return;
|
||||
|
||||
NetworkAdminUpdate(ADMIN_FREQUENCY_DAILY);
|
||||
if ((_date % 7) == 3) NetworkAdminUpdate(ADMIN_FREQUENCY_WEEKLY);
|
||||
if ((TimerGameCalendar::date % 7) == 3) NetworkAdminUpdate(ADMIN_FREQUENCY_WEEKLY);
|
||||
});
|
||||
|
||||
/**
|
||||
|
Reference in New Issue
Block a user