Debug: Extend random debug logging to also include state checksum updates

pull/212/head
Jonathan G Rennison 3 years ago
parent 4f44540eb9
commit aacb70d371

@ -2163,6 +2163,7 @@ static bool AircraftEventHandler(Aircraft *v, int loop)
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);
if (!this->IsNormalAircraft()) return true;

@ -12,6 +12,16 @@
#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 {
uint64 state = 0;
@ -28,4 +38,15 @@ inline void UpdateStateChecksum(uint64 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 */

@ -52,6 +52,7 @@ int _debug_linkgraph_level;
int _debug_sound_level;
#ifdef RANDOM_DEBUG
int _debug_random_level;
int _debug_statecsum_level;
#endif
const char *_savegame_DBGL_data = nullptr;
@ -88,6 +89,7 @@ struct DebugLevel {
DEBUG_LEVEL(sound),
#ifdef RANDOM_DEBUG
DEBUG_LEVEL(random),
DEBUG_LEVEL(statecsum),
#endif
};
#undef DEBUG_LEVEL
@ -140,7 +142,7 @@ static void debug_print(const char *dbg, const char *buf)
fflush(f);
}
#ifdef RANDOM_DEBUG
} else if (strcmp(dbg, "random") == 0) {
} else if (strcmp(dbg, "random") == 0 || strcmp(dbg, "statecsum") == 0) {
#if defined(UNIX) && defined(__GLIBC__)
static bool have_inited = false;
static FILE *f = nullptr;

@ -55,6 +55,7 @@ extern int _debug_linkgraph_level;
extern int _debug_sound_level;
#ifdef RANDOM_DEBUG
extern int _debug_random_level;
extern int _debug_statecsum_level;
#endif
extern const char *_savegame_DBGL_data;

@ -716,6 +716,7 @@ static DisasterVehicleTickProc * const _disastervehicle_tick_procs[] = {
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);
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()
{
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);
return _effect_tick_procs[this->subtype](this);
}

@ -1852,6 +1852,7 @@ void StateGameLoop()
cur_company.Restore();
for (Company *c : Company::Iterate()) {
DEBUG_UPDATESTATECHECKSUM("Company: %u, Money: " OTTD_PRINTF64, c->index, (int64)c->money);
UpdateStateChecksum(c->money);
}
}

@ -1259,6 +1259,7 @@ static Trackdir RoadFindPathToDest(RoadVehicle *v, TileIndex tile, DiagDirection
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);
v->HandlePathfindingResult(path_found);
@ -2116,7 +2117,9 @@ Money RoadVehicle::GetRunningCost() const
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);
DEBUG_UPDATESTATECHECKSUM("RoadVehicle::Tick 2: v: %u, state: %d, frame: %d", this->index, this->state, this->frame);
UpdateStateChecksum((((uint64) this->state) << 32) | this->frame);
if (this->IsFrontEngine()) {
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();
}
}
DEBUG_UPDATESTATECHECKSUM("ChooseShipTrack: v: %u, path_found: %d, track: %d", v->index, path_found, track);
UpdateStateChecksum((((uint64) v->index) << 32) | (path_found << 16) | track);
v->HandlePathfindingResult(path_found);
@ -971,6 +972,7 @@ reverse_direction:
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);
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;
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);
if (new_tile == tile) best_track = next_track;
v->HandlePathfindingResult(path_found);
@ -5220,7 +5221,8 @@ Money Train::GetRunningCost() const
*/
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->vehstatus & VS_STOPPED) || this->IsWaitingInDepot()) || this->cur_speed > 0) this->running_ticks++;

Loading…
Cancel
Save