Debug: Extend random debug logging to also include state checksum updates
This commit is contained in:
@@ -2163,6 +2163,7 @@ static bool AircraftEventHandler(Aircraft *v, int loop)
|
|||||||
|
|
||||||
bool Aircraft::Tick()
|
bool Aircraft::Tick()
|
||||||
{
|
{
|
||||||
|
DEBUG_UPDATESTATECHECKSUM("Aircraft::Tick: v: %u, x: %d, y: %d", this->index, this->x_pos, this->y_pos);
|
||||||
UpdateStateChecksum((((uint64) this->x_pos) << 32) | this->y_pos);
|
UpdateStateChecksum((((uint64) this->x_pos) << 32) | this->y_pos);
|
||||||
if (!this->IsNormalAircraft()) return true;
|
if (!this->IsNormalAircraft()) return true;
|
||||||
|
|
||||||
|
@@ -12,6 +12,16 @@
|
|||||||
|
|
||||||
#include "bitmath_func.hpp"
|
#include "bitmath_func.hpp"
|
||||||
|
|
||||||
|
#ifdef RANDOM_DEBUG
|
||||||
|
#include "../network/network.h"
|
||||||
|
#include "../network/network_server.h"
|
||||||
|
#include "../network/network_internal.h"
|
||||||
|
#include "../company_func.h"
|
||||||
|
#include "../fileio_func.h"
|
||||||
|
#include "../date_func.h"
|
||||||
|
#include "../debug.h"
|
||||||
|
#endif /* RANDOM_DEBUG */
|
||||||
|
|
||||||
struct SimpleChecksum64 {
|
struct SimpleChecksum64 {
|
||||||
uint64 state = 0;
|
uint64 state = 0;
|
||||||
|
|
||||||
@@ -28,4 +38,15 @@ inline void UpdateStateChecksum(uint64 input)
|
|||||||
_state_checksum.Update(input);
|
_state_checksum.Update(input);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef RANDOM_DEBUG
|
||||||
|
inline bool ShouldLogUpdateStateChecksum()
|
||||||
|
{
|
||||||
|
return _networking && (!_network_server || (NetworkClientSocket::IsValidID(0) && NetworkClientSocket::Get(0)->status != NetworkClientSocket::STATUS_INACTIVE));
|
||||||
|
}
|
||||||
|
# define DEBUG_UPDATESTATECHECKSUM(str, ...) if (ShouldLogUpdateStateChecksum()) DEBUG(statecsum, 0, "date{%08x; %02x; %02x}; %04x; %02x; " OTTD_PRINTFHEX64PAD "; %s:%d " str, \
|
||||||
|
_date, _date_fract, _tick_skip_counter, _frame_counter, (byte)_current_company, _state_checksum.state, __FILE__, __LINE__, __VA_ARGS__);
|
||||||
|
#else
|
||||||
|
# define DEBUG_UPDATESTATECHECKSUM(str, ...)
|
||||||
|
#endif /* RANDOM_DEBUG */
|
||||||
|
|
||||||
#endif /* CHECKSUM_FUNC_HPP */
|
#endif /* CHECKSUM_FUNC_HPP */
|
||||||
|
@@ -52,6 +52,7 @@ int _debug_linkgraph_level;
|
|||||||
int _debug_sound_level;
|
int _debug_sound_level;
|
||||||
#ifdef RANDOM_DEBUG
|
#ifdef RANDOM_DEBUG
|
||||||
int _debug_random_level;
|
int _debug_random_level;
|
||||||
|
int _debug_statecsum_level;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
const char *_savegame_DBGL_data = nullptr;
|
const char *_savegame_DBGL_data = nullptr;
|
||||||
@@ -88,6 +89,7 @@ struct DebugLevel {
|
|||||||
DEBUG_LEVEL(sound),
|
DEBUG_LEVEL(sound),
|
||||||
#ifdef RANDOM_DEBUG
|
#ifdef RANDOM_DEBUG
|
||||||
DEBUG_LEVEL(random),
|
DEBUG_LEVEL(random),
|
||||||
|
DEBUG_LEVEL(statecsum),
|
||||||
#endif
|
#endif
|
||||||
};
|
};
|
||||||
#undef DEBUG_LEVEL
|
#undef DEBUG_LEVEL
|
||||||
@@ -140,7 +142,7 @@ static void debug_print(const char *dbg, const char *buf)
|
|||||||
fflush(f);
|
fflush(f);
|
||||||
}
|
}
|
||||||
#ifdef RANDOM_DEBUG
|
#ifdef RANDOM_DEBUG
|
||||||
} else if (strcmp(dbg, "random") == 0) {
|
} else if (strcmp(dbg, "random") == 0 || strcmp(dbg, "statecsum") == 0) {
|
||||||
#if defined(UNIX) && defined(__GLIBC__)
|
#if defined(UNIX) && defined(__GLIBC__)
|
||||||
static bool have_inited = false;
|
static bool have_inited = false;
|
||||||
static FILE *f = nullptr;
|
static FILE *f = nullptr;
|
||||||
|
@@ -55,6 +55,7 @@ extern int _debug_linkgraph_level;
|
|||||||
extern int _debug_sound_level;
|
extern int _debug_sound_level;
|
||||||
#ifdef RANDOM_DEBUG
|
#ifdef RANDOM_DEBUG
|
||||||
extern int _debug_random_level;
|
extern int _debug_random_level;
|
||||||
|
extern int _debug_statecsum_level;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
extern const char *_savegame_DBGL_data;
|
extern const char *_savegame_DBGL_data;
|
||||||
|
@@ -716,6 +716,7 @@ static DisasterVehicleTickProc * const _disastervehicle_tick_procs[] = {
|
|||||||
|
|
||||||
bool DisasterVehicle::Tick()
|
bool DisasterVehicle::Tick()
|
||||||
{
|
{
|
||||||
|
DEBUG_UPDATESTATECHECKSUM("DisasterVehicle::Tick: v: %u, x: %d, y: %d", this->index, this->x_pos, this->y_pos);
|
||||||
UpdateStateChecksum((((uint64) this->x_pos) << 32) | this->y_pos);
|
UpdateStateChecksum((((uint64) this->x_pos) << 32) | this->y_pos);
|
||||||
return _disastervehicle_tick_procs[this->subtype](this);
|
return _disastervehicle_tick_procs[this->subtype](this);
|
||||||
}
|
}
|
||||||
|
@@ -672,6 +672,7 @@ EffectVehicle *CreateEffectVehicleRel(const Vehicle *v, int x, int y, int z, Eff
|
|||||||
|
|
||||||
bool EffectVehicle::Tick()
|
bool EffectVehicle::Tick()
|
||||||
{
|
{
|
||||||
|
DEBUG_UPDATESTATECHECKSUM("EffectVehicle::Tick: v: %u, x: %d, y: %d", this->index, this->x_pos, this->y_pos);
|
||||||
UpdateStateChecksum((((uint64) this->x_pos) << 32) | this->y_pos);
|
UpdateStateChecksum((((uint64) this->x_pos) << 32) | this->y_pos);
|
||||||
return _effect_tick_procs[this->subtype](this);
|
return _effect_tick_procs[this->subtype](this);
|
||||||
}
|
}
|
||||||
|
@@ -1852,6 +1852,7 @@ void StateGameLoop()
|
|||||||
cur_company.Restore();
|
cur_company.Restore();
|
||||||
|
|
||||||
for (Company *c : Company::Iterate()) {
|
for (Company *c : Company::Iterate()) {
|
||||||
|
DEBUG_UPDATESTATECHECKSUM("Company: %u, Money: " OTTD_PRINTF64, c->index, (int64)c->money);
|
||||||
UpdateStateChecksum(c->money);
|
UpdateStateChecksum(c->money);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -1259,6 +1259,7 @@ static Trackdir RoadFindPathToDest(RoadVehicle *v, TileIndex tile, DiagDirection
|
|||||||
|
|
||||||
default: NOT_REACHED();
|
default: NOT_REACHED();
|
||||||
}
|
}
|
||||||
|
DEBUG_UPDATESTATECHECKSUM("RoadFindPathToDest: v: %u, path_found: %d, best_track: %d", v->index, path_found, best_track);
|
||||||
UpdateStateChecksum((((uint64) v->index) << 32) | (path_found << 16) | best_track);
|
UpdateStateChecksum((((uint64) v->index) << 32) | (path_found << 16) | best_track);
|
||||||
v->HandlePathfindingResult(path_found);
|
v->HandlePathfindingResult(path_found);
|
||||||
|
|
||||||
@@ -2116,7 +2117,9 @@ Money RoadVehicle::GetRunningCost() const
|
|||||||
|
|
||||||
bool RoadVehicle::Tick()
|
bool RoadVehicle::Tick()
|
||||||
{
|
{
|
||||||
|
DEBUG_UPDATESTATECHECKSUM("RoadVehicle::Tick 1: v: %u, x: %d, y: %d", this->index, this->x_pos, this->y_pos);
|
||||||
UpdateStateChecksum((((uint64) this->x_pos) << 32) | this->y_pos);
|
UpdateStateChecksum((((uint64) this->x_pos) << 32) | this->y_pos);
|
||||||
|
DEBUG_UPDATESTATECHECKSUM("RoadVehicle::Tick 2: v: %u, state: %d, frame: %d", this->index, this->state, this->frame);
|
||||||
UpdateStateChecksum((((uint64) this->state) << 32) | this->frame);
|
UpdateStateChecksum((((uint64) this->state) << 32) | this->frame);
|
||||||
if (this->IsFrontEngine()) {
|
if (this->IsFrontEngine()) {
|
||||||
if (!(this->IsRoadVehicleStopped() || this->IsWaitingInDepot())) this->running_ticks++;
|
if (!(this->IsRoadVehicleStopped() || this->IsWaitingInDepot())) this->running_ticks++;
|
||||||
|
@@ -524,6 +524,7 @@ static Track ChooseShipTrack(Ship *v, TileIndex tile, DiagDirection enterdir, Tr
|
|||||||
default: NOT_REACHED();
|
default: NOT_REACHED();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
DEBUG_UPDATESTATECHECKSUM("ChooseShipTrack: v: %u, path_found: %d, track: %d", v->index, path_found, track);
|
||||||
UpdateStateChecksum((((uint64) v->index) << 32) | (path_found << 16) | track);
|
UpdateStateChecksum((((uint64) v->index) << 32) | (path_found << 16) | track);
|
||||||
|
|
||||||
v->HandlePathfindingResult(path_found);
|
v->HandlePathfindingResult(path_found);
|
||||||
@@ -971,6 +972,7 @@ reverse_direction:
|
|||||||
|
|
||||||
bool Ship::Tick()
|
bool Ship::Tick()
|
||||||
{
|
{
|
||||||
|
DEBUG_UPDATESTATECHECKSUM("Ship::Tick: v: %u, x: %d, y: %d", this->index, this->x_pos, this->y_pos);
|
||||||
UpdateStateChecksum((((uint64) this->x_pos) << 32) | this->y_pos);
|
UpdateStateChecksum((((uint64) this->x_pos) << 32) | this->y_pos);
|
||||||
if (!((this->vehstatus & VS_STOPPED) || this->IsWaitingInDepot())) this->running_ticks++;
|
if (!((this->vehstatus & VS_STOPPED) || this->IsWaitingInDepot())) this->running_ticks++;
|
||||||
|
|
||||||
|
@@ -3326,6 +3326,7 @@ static Track ChooseTrainTrack(Train *v, TileIndex tile, DiagDirection enterdir,
|
|||||||
TileIndex new_tile = res_dest.tile;
|
TileIndex new_tile = res_dest.tile;
|
||||||
|
|
||||||
Track next_track = DoTrainPathfind(v, new_tile, dest_enterdir, tracks, path_found, do_track_reservation, &res_dest);
|
Track next_track = DoTrainPathfind(v, new_tile, dest_enterdir, tracks, path_found, do_track_reservation, &res_dest);
|
||||||
|
DEBUG_UPDATESTATECHECKSUM("ChooseTrainTrack: v: %u, path_found: %d, next_track: %d", v->index, path_found, next_track);
|
||||||
UpdateStateChecksum((((uint64) v->index) << 32) | (path_found << 16) | next_track);
|
UpdateStateChecksum((((uint64) v->index) << 32) | (path_found << 16) | next_track);
|
||||||
if (new_tile == tile) best_track = next_track;
|
if (new_tile == tile) best_track = next_track;
|
||||||
v->HandlePathfindingResult(path_found);
|
v->HandlePathfindingResult(path_found);
|
||||||
@@ -5220,7 +5221,8 @@ Money Train::GetRunningCost() const
|
|||||||
*/
|
*/
|
||||||
bool Train::Tick()
|
bool Train::Tick()
|
||||||
{
|
{
|
||||||
UpdateStateChecksum((((uint64) this->x_pos) << 32) | (this->y_pos << 16) | this->track );
|
DEBUG_UPDATESTATECHECKSUM("Train::Tick: v: %u, x: %d, y: %d, track: %d", this->index, this->x_pos, this->y_pos, this->track);
|
||||||
|
UpdateStateChecksum((((uint64) this->x_pos) << 32) | (this->y_pos << 16) | this->track);
|
||||||
if (this->IsFrontEngine()) {
|
if (this->IsFrontEngine()) {
|
||||||
if (!((this->vehstatus & VS_STOPPED) || this->IsWaitingInDepot()) || this->cur_speed > 0) this->running_ticks++;
|
if (!((this->vehstatus & VS_STOPPED) || this->IsWaitingInDepot()) || this->cur_speed > 0) this->running_ticks++;
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user