mirror of https://github.com/OpenTTD/OpenTTD
Codechange: Use economy dates when debugging
parent
b2efe18ab8
commit
4da107e6f1
|
@ -18,7 +18,7 @@
|
||||||
#include "strings_func.h"
|
#include "strings_func.h"
|
||||||
#include "texteff.hpp"
|
#include "texteff.hpp"
|
||||||
#include "town.h"
|
#include "town.h"
|
||||||
#include "timer/timer_game_calendar.h"
|
#include "timer/timer_game_economy.h"
|
||||||
#include "company_func.h"
|
#include "company_func.h"
|
||||||
#include "company_base.h"
|
#include "company_base.h"
|
||||||
#include "signal_func.h"
|
#include "signal_func.h"
|
||||||
|
@ -274,7 +274,7 @@ void CommandHelperBase::InternalPostResult(const CommandCost &res, TileIndex til
|
||||||
/** Helper to make a desync log for a command. */
|
/** Helper to make a desync log for a command. */
|
||||||
void CommandHelperBase::LogCommandExecution(Commands cmd, StringID err_message, const CommandDataBuffer &args, bool failed)
|
void CommandHelperBase::LogCommandExecution(Commands cmd, StringID err_message, const CommandDataBuffer &args, bool failed)
|
||||||
{
|
{
|
||||||
Debug(desync, 1, "{}: {:08x}; {:02x}; {:02x}; {:08x}; {:08x}; {} ({})", failed ? "cmdf" : "cmd", (uint32_t)TimerGameCalendar::date.base(), TimerGameCalendar::date_fract, (int)_current_company, cmd, err_message, FormatArrayAsHex(args), GetCommandName(cmd));
|
Debug(desync, 1, "{}: {:08x}; {:02x}; {:02x}; {:08x}; {:08x}; {} ({})", failed ? "cmdf" : "cmd", (uint32_t)TimerGameEconomy::date.base(), TimerGameEconomy::date_fract, (int)_current_company, cmd, err_message, FormatArrayAsHex(args), GetCommandName(cmd));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -84,7 +84,7 @@ void SetRandomSeed(uint32_t seed)
|
||||||
uint32_t DoRandom(int line, const char *file)
|
uint32_t DoRandom(int line, const char *file)
|
||||||
{
|
{
|
||||||
if (_networking && (!_network_server || (NetworkClientSocket::IsValidID(0) && NetworkClientSocket::Get(0)->status != NetworkClientSocket::STATUS_INACTIVE))) {
|
if (_networking && (!_network_server || (NetworkClientSocket::IsValidID(0) && NetworkClientSocket::Get(0)->status != NetworkClientSocket::STATUS_INACTIVE))) {
|
||||||
Debug(random, 0, "{:08x}; {:02x}; {:04x}; {:02x}; {}:{}", TimerGameCalendar::date, TimerGameCalendar::date_fract, _frame_counter, (byte)_current_company, file, line);
|
Debug(random, 0, "{:08x}; {:02x}; {:04x}; {:02x}; {}:{}", TimerGameEconomy::date, TimerGameEconomy::date_fract, _frame_counter, (byte)_current_company, file, line);
|
||||||
}
|
}
|
||||||
|
|
||||||
return _random.Next();
|
return _random.Next();
|
||||||
|
|
|
@ -12,7 +12,7 @@
|
||||||
#include "../strings_func.h"
|
#include "../strings_func.h"
|
||||||
#include "../command_func.h"
|
#include "../command_func.h"
|
||||||
#include "../timer/timer_game_tick.h"
|
#include "../timer/timer_game_tick.h"
|
||||||
#include "../timer/timer_game_calendar.h"
|
#include "../timer/timer_game_economy.h"
|
||||||
#include "network_admin.h"
|
#include "network_admin.h"
|
||||||
#include "network_client.h"
|
#include "network_client.h"
|
||||||
#include "network_query.h"
|
#include "network_query.h"
|
||||||
|
@ -263,7 +263,7 @@ void NetworkTextMessage(NetworkAction action, TextColour colour, bool self_send,
|
||||||
Utf8Encode(iterator, _current_text_dir == TD_LTR ? CHAR_TD_LRM : CHAR_TD_RLM);
|
Utf8Encode(iterator, _current_text_dir == TD_LTR ? CHAR_TD_LRM : CHAR_TD_RLM);
|
||||||
std::string message = stream.str() + GetString(strid);
|
std::string message = stream.str() + GetString(strid);
|
||||||
|
|
||||||
Debug(desync, 1, "msg: {:08x}; {:02x}; {}", TimerGameCalendar::date, TimerGameCalendar::date_fract, message);
|
Debug(desync, 1, "msg: {:08x}; {:02x}; {}", TimerGameEconomy::date, TimerGameEconomy::date_fract, message);
|
||||||
IConsolePrint(colour, message);
|
IConsolePrint(colour, message);
|
||||||
NetworkAddChatMessage(colour, _settings_client.gui.network_chat_timeout, message);
|
NetworkAddChatMessage(colour, _settings_client.gui.network_chat_timeout, message);
|
||||||
}
|
}
|
||||||
|
@ -1043,42 +1043,42 @@ void NetworkGameLoop()
|
||||||
|
|
||||||
if (_network_server) {
|
if (_network_server) {
|
||||||
/* Log the sync state to check for in-syncedness of replays. */
|
/* Log the sync state to check for in-syncedness of replays. */
|
||||||
if (TimerGameCalendar::date_fract == 0) {
|
if (TimerGameEconomy::date_fract == 0) {
|
||||||
/* We don't want to log multiple times if paused. */
|
/* We don't want to log multiple times if paused. */
|
||||||
static TimerGameCalendar::Date last_log;
|
static TimerGameEconomy::Date last_log;
|
||||||
if (last_log != TimerGameCalendar::date) {
|
if (last_log != TimerGameEconomy::date) {
|
||||||
Debug(desync, 1, "sync: {:08x}; {:02x}; {:08x}; {:08x}", TimerGameCalendar::date, TimerGameCalendar::date_fract, _random.state[0], _random.state[1]);
|
Debug(desync, 1, "sync: {:08x}; {:02x}; {:08x}; {:08x}", TimerGameEconomy::date, TimerGameEconomy::date_fract, _random.state[0], _random.state[1]);
|
||||||
last_log = TimerGameCalendar::date;
|
last_log = TimerGameEconomy::date;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef DEBUG_DUMP_COMMANDS
|
#ifdef DEBUG_DUMP_COMMANDS
|
||||||
/* Loading of the debug commands from -ddesync>=1 */
|
/* Loading of the debug commands from -ddesync>=1 */
|
||||||
static FILE *f = FioFOpenFile("commands.log", "rb", SAVE_DIR);
|
static FILE *f = FioFOpenFile("commands.log", "rb", SAVE_DIR);
|
||||||
static TimerGameCalendar::Date next_date(0);
|
static TimerGameEconomy::Date next_date(0);
|
||||||
static uint32_t next_date_fract;
|
static uint32_t next_date_fract;
|
||||||
static CommandPacket *cp = nullptr;
|
static CommandPacket *cp = nullptr;
|
||||||
static bool check_sync_state = false;
|
static bool check_sync_state = false;
|
||||||
static uint32_t sync_state[2];
|
static uint32_t sync_state[2];
|
||||||
if (f == nullptr && next_date == 0) {
|
if (f == nullptr && next_date == 0) {
|
||||||
Debug(desync, 0, "Cannot open commands.log");
|
Debug(desync, 0, "Cannot open commands.log");
|
||||||
next_date = TimerGameCalendar::Date(1);
|
next_date = TimerGameEconomy::Date(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
while (f != nullptr && !feof(f)) {
|
while (f != nullptr && !feof(f)) {
|
||||||
if (TimerGameCalendar::date == next_date && TimerGameCalendar::date_fract == next_date_fract) {
|
if (TimerGameEconomy::date == next_date && TimerGameEconomy::date_fract == next_date_fract) {
|
||||||
if (cp != nullptr) {
|
if (cp != nullptr) {
|
||||||
NetworkSendCommand(cp->cmd, cp->err_msg, nullptr, cp->company, cp->data);
|
NetworkSendCommand(cp->cmd, cp->err_msg, nullptr, cp->company, cp->data);
|
||||||
Debug(desync, 0, "Injecting: {:08x}; {:02x}; {:02x}; {:08x}; {} ({})", TimerGameCalendar::date, TimerGameCalendar::date_fract, (int)_current_company, cp->cmd, FormatArrayAsHex(cp->data), GetCommandName(cp->cmd));
|
Debug(desync, 0, "Injecting: {:08x}; {:02x}; {:02x}; {:08x}; {} ({})", TimerGameEconomy::date, TimerGameEconomy::date_fract, (int)_current_company, cp->cmd, FormatArrayAsHex(cp->data), GetCommandName(cp->cmd));
|
||||||
delete cp;
|
delete cp;
|
||||||
cp = nullptr;
|
cp = nullptr;
|
||||||
}
|
}
|
||||||
if (check_sync_state) {
|
if (check_sync_state) {
|
||||||
if (sync_state[0] == _random.state[0] && sync_state[1] == _random.state[1]) {
|
if (sync_state[0] == _random.state[0] && sync_state[1] == _random.state[1]) {
|
||||||
Debug(desync, 0, "Sync check: {:08x}; {:02x}; match", TimerGameCalendar::date, TimerGameCalendar::date_fract);
|
Debug(desync, 0, "Sync check: {:08x}; {:02x}; match", TimerGameEconomy::date, TimerGameEconomy::date_fract);
|
||||||
} else {
|
} else {
|
||||||
Debug(desync, 0, "Sync check: {:08x}; {:02x}; mismatch expected {{{:08x}, {:08x}}}, got {{{:08x}, {:08x}}}",
|
Debug(desync, 0, "Sync check: {:08x}; {:02x}; mismatch expected {{{:08x}, {:08x}}}, got {{{:08x}, {:08x}}}",
|
||||||
TimerGameCalendar::date, TimerGameCalendar::date_fract, sync_state[0], sync_state[1], _random.state[0], _random.state[1]);
|
TimerGameEconomy::date, TimerGameEconomy::date_fract, sync_state[0], sync_state[1], _random.state[0], _random.state[1]);
|
||||||
NOT_REACHED();
|
NOT_REACHED();
|
||||||
}
|
}
|
||||||
check_sync_state = false;
|
check_sync_state = false;
|
||||||
|
@ -1112,7 +1112,7 @@ void NetworkGameLoop()
|
||||||
uint32_t next_date_raw;
|
uint32_t next_date_raw;
|
||||||
int ret = sscanf(p, "%x; %x; %x; %x; %x; %255s", &next_date_raw, &next_date_fract, &company, &cmd, &cp->err_msg, buffer);
|
int ret = sscanf(p, "%x; %x; %x; %x; %x; %255s", &next_date_raw, &next_date_fract, &company, &cmd, &cp->err_msg, buffer);
|
||||||
assert(ret == 6);
|
assert(ret == 6);
|
||||||
next_date = TimerGameCalendar::Date((int32_t)next_date_raw);
|
next_date = TimerGameEconomy::Date((int32_t)next_date_raw);
|
||||||
cp->company = (CompanyID)company;
|
cp->company = (CompanyID)company;
|
||||||
cp->cmd = (Commands)cmd;
|
cp->cmd = (Commands)cmd;
|
||||||
|
|
||||||
|
@ -1129,7 +1129,7 @@ void NetworkGameLoop()
|
||||||
/* Manually insert a pause when joining; this way the client can join at the exact right time. */
|
/* Manually insert a pause when joining; this way the client can join at the exact right time. */
|
||||||
uint32_t next_date_raw;
|
uint32_t next_date_raw;
|
||||||
int ret = sscanf(p + 6, "%x; %x", &next_date_raw, &next_date_fract);
|
int ret = sscanf(p + 6, "%x; %x", &next_date_raw, &next_date_fract);
|
||||||
next_date = TimerGameCalendar::Date((int32_t)next_date_raw);
|
next_date = TimerGameEconomy::Date((int32_t)next_date_raw);
|
||||||
assert(ret == 2);
|
assert(ret == 2);
|
||||||
Debug(desync, 0, "Injecting pause for join at {:08x}:{:02x}; please join when paused", next_date, next_date_fract);
|
Debug(desync, 0, "Injecting pause for join at {:08x}:{:02x}; please join when paused", next_date, next_date_fract);
|
||||||
cp = new CommandPacket();
|
cp = new CommandPacket();
|
||||||
|
@ -1140,7 +1140,7 @@ void NetworkGameLoop()
|
||||||
} else if (strncmp(p, "sync: ", 6) == 0) {
|
} else if (strncmp(p, "sync: ", 6) == 0) {
|
||||||
uint32_t next_date_raw;
|
uint32_t next_date_raw;
|
||||||
int ret = sscanf(p + 6, "%x; %x; %x; %x", &next_date_raw, &next_date_fract, &sync_state[0], &sync_state[1]);
|
int ret = sscanf(p + 6, "%x; %x; %x; %x", &next_date_raw, &next_date_fract, &sync_state[0], &sync_state[1]);
|
||||||
next_date = TimerGameCalendar::Date((int32_t)next_date_raw);
|
next_date = TimerGameEconomy::Date((int32_t)next_date_raw);
|
||||||
assert(ret == 4);
|
assert(ret == 4);
|
||||||
check_sync_state = true;
|
check_sync_state = true;
|
||||||
} else if (strncmp(p, "msg: ", 5) == 0 || strncmp(p, "client: ", 8) == 0 ||
|
} else if (strncmp(p, "msg: ", 5) == 0 || strncmp(p, "client: ", 8) == 0 ||
|
||||||
|
|
|
@ -282,7 +282,7 @@ void ClientNetworkGameSocketHandler::ClientError(NetworkRecvStatus res)
|
||||||
if (_sync_seed_1 != _random.state[0]) {
|
if (_sync_seed_1 != _random.state[0]) {
|
||||||
#endif
|
#endif
|
||||||
ShowNetworkError(STR_NETWORK_ERROR_DESYNC);
|
ShowNetworkError(STR_NETWORK_ERROR_DESYNC);
|
||||||
Debug(desync, 1, "sync_err: {:08x}; {:02x}", TimerGameCalendar::date, TimerGameCalendar::date_fract);
|
Debug(desync, 1, "sync_err: {:08x}; {:02x}", TimerGameEconomy::date, TimerGameEconomy::date_fract);
|
||||||
Debug(net, 0, "Sync error detected");
|
Debug(net, 0, "Sync error detected");
|
||||||
my_client->ClientError(NETWORK_RECV_STATUS_DESYNC);
|
my_client->ClientError(NETWORK_RECV_STATUS_DESYNC);
|
||||||
return false;
|
return false;
|
||||||
|
|
|
@ -886,7 +886,7 @@ NetworkRecvStatus ServerNetworkGameSocketHandler::Receive_CLIENT_JOIN(Packet *p)
|
||||||
ci->join_date = TimerGameCalendar::date;
|
ci->join_date = TimerGameCalendar::date;
|
||||||
ci->client_name = client_name;
|
ci->client_name = client_name;
|
||||||
ci->client_playas = playas;
|
ci->client_playas = playas;
|
||||||
Debug(desync, 1, "client: {:08x}; {:02x}; {:02x}; {:02x}", TimerGameCalendar::date, TimerGameCalendar::date_fract, (int)ci->client_playas, (int)ci->index);
|
Debug(desync, 1, "client: {:08x}; {:02x}; {:02x}; {:02x}", TimerGameEconomy::date, TimerGameEconomy::date_fract, (int)ci->client_playas, (int)ci->index);
|
||||||
|
|
||||||
/* Make sure companies to which people try to join are not autocleaned */
|
/* Make sure companies to which people try to join are not autocleaned */
|
||||||
if (Company::IsValidID(playas)) _network_company_states[playas].months_empty = 0;
|
if (Company::IsValidID(playas)) _network_company_states[playas].months_empty = 0;
|
||||||
|
@ -1480,7 +1480,7 @@ void NetworkUpdateClientInfo(ClientID client_id)
|
||||||
|
|
||||||
if (ci == nullptr) return;
|
if (ci == nullptr) return;
|
||||||
|
|
||||||
Debug(desync, 1, "client: {:08x}; {:02x}; {:02x}; {:04x}", TimerGameCalendar::date, TimerGameCalendar::date_fract, (int)ci->client_playas, client_id);
|
Debug(desync, 1, "client: {:08x}; {:02x}; {:02x}; {:04x}", TimerGameEconomy::date, TimerGameEconomy::date_fract, (int)ci->client_playas, client_id);
|
||||||
|
|
||||||
for (NetworkClientSocket *cs : NetworkClientSocket::Iterate()) {
|
for (NetworkClientSocket *cs : NetworkClientSocket::Iterate()) {
|
||||||
if (cs->status >= ServerNetworkGameSocketHandler::STATUS_AUTHORIZED) {
|
if (cs->status >= ServerNetworkGameSocketHandler::STATUS_AUTHORIZED) {
|
||||||
|
|
|
@ -1397,7 +1397,7 @@ void StateGameLoop()
|
||||||
CallWindowGameTickEvent();
|
CallWindowGameTickEvent();
|
||||||
NewsLoop();
|
NewsLoop();
|
||||||
} else {
|
} else {
|
||||||
if (_debug_desync_level > 2 && TimerGameCalendar::date_fract == 0 && (TimerGameCalendar::date.base() & 0x1F) == 0) {
|
if (_debug_desync_level > 2 && TimerGameEconomy::date_fract == 0 && (TimerGameEconomy::date.base() & 0x1F) == 0) {
|
||||||
/* Save the desync savegame if needed. */
|
/* Save the desync savegame if needed. */
|
||||||
std::string name = fmt::format("dmp_cmds_{:08x}_{:08x}.sav", _settings_game.game_creation.generation_seed, TimerGameCalendar::date);
|
std::string name = fmt::format("dmp_cmds_{:08x}_{:08x}.sav", _settings_game.game_creation.generation_seed, TimerGameCalendar::date);
|
||||||
SaveOrLoad(name, SLO_SAVE, DFT_GAME_FILE, AUTOSAVE_DIR, false);
|
SaveOrLoad(name, SLO_SAVE, DFT_GAME_FILE, AUTOSAVE_DIR, false);
|
||||||
|
|
Loading…
Reference in New Issue