Skip to content

Commit 9f09afd

Browse files
committed
feat: add comprehensive logging diagnostics for random number generation, sleepy updates, and frame tracking.
1 parent 62539d8 commit 9f09afd

22 files changed

Lines changed: 28936 additions & 33 deletions

File tree

CRCLogs2/DiagLog.txt

Lines changed: 2709 additions & 0 deletions
Large diffs are not rendered by default.

CRCLogs2/RegDiag.txt

Lines changed: 1406 additions & 0 deletions
Large diffs are not rendered by default.

CRCLogs2/SleepyDiag.txt

Lines changed: 24517 additions & 0 deletions
Large diffs are not rendered by default.

Core/GameEngine/Include/Common/CRCDebug.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@
7070

7171
void addCRCDebugLine(const char *fmt, ...);
7272
void addCRCDebugLineNoCounter(const char *fmt, ...);
73+
void addCRCRandomLine(const char *fmt, ...);
7374
void addCRCDumpLine(const char *fmt, ...);
7475
void addCRCGenLine(const char *fmt, ...);
7576
#define CRCDEBUG_LOG(x) addCRCDebugLine x
@@ -100,6 +101,7 @@
100101
extern AsciiString g_saveDebugCRCPerFrameDir;
101102

102103
extern Bool g_logObjectCRCs;
104+
extern Bool g_logRandom;
103105

104106
#else // DEBUG_CRC
105107

Core/GameEngine/Include/Common/Debug.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -286,13 +286,13 @@ class SimpleProfiler
286286
#endif
287287

288288
// #define DEBUG_BUILDMAPCACHE_FLAG
289-
// #define DEBUG_INFO_MAC_FLAG
289+
#define DEBUG_INFO_MAC_FLAG
290290
// #define DEBUG_FILESYSTEM_MAC_FLAG
291291
// #define DEBUG_RENDER_CORE_MAC_FLAG
292292
#define DEBUG_NETWORK_MAC_FLAG
293293
// #define DEBUG_AUTH_MAC_FLAG
294294
// #define DEBUG_EAC_MAC_FLAG
295-
// #define DEBUG_LOG_FLAG_V2
295+
#define DEBUG_LOG_FLAG_V2
296296
#define DEBUG_SETTINGS_MAC_FLAG
297297

298298
#ifdef DEBUG_BUILDMAPCACHE_FLAG

Core/GameEngine/Source/Common/CRCDebug.cpp

Lines changed: 49 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,8 @@ Int lastCRCDebugFrame = 0;
114114
Int lastCRCDebugIndex = 0;
115115
extern Bool inCRCGen;
116116

117+
static void outputCRCDebugLinesPerFrame();
118+
117119
void CRCDebugStartNewGame()
118120
{
119121
if (TheGameLogic->isInShellGame())
@@ -131,9 +133,21 @@ void CRCDebugStartNewGame()
131133
FilenameList::iterator it;
132134
for (it = files.begin(); it != files.end(); ++it)
133135
{
134-
DeleteFile(it->str());
136+
// TheSuperHackers @fix Preserve the pre-game log (InitRandom, etc.)
137+
// if it was already created in an earlier phase of the current startup sequence.
138+
if (strstr(it->str(), "-00001") == nullptr)
139+
{
140+
DeleteFile(it->str());
141+
}
135142
}
136143
}
144+
145+
if (numDebugStrings > 0)
146+
{
147+
lastCRCDebugFrame = -1;
148+
outputCRCDebugLinesPerFrame();
149+
}
150+
137151
nextDebugString = 0;
138152
numDebugStrings = 0;
139153
lastCRCDebugFrame = 0;
@@ -251,6 +265,40 @@ void addCRCDebugLineNoCounter(const char *fmt, ...)
251265
va_end(args);
252266
}
253267

268+
void addCRCRandomLine(const char *fmt, ...)
269+
{
270+
va_list args;
271+
va_start(args, fmt);
272+
273+
if (lastCRCDebugFrame != (TheGameLogic ? TheGameLogic->getFrame() : -1))
274+
{
275+
outputCRCDebugLinesPerFrame();
276+
lastCRCDebugFrame = (TheGameLogic ? TheGameLogic->getFrame() : -1);
277+
lastCRCDebugIndex = 0;
278+
}
279+
280+
DebugStrings[nextDebugString][0] = 0;
281+
Int len = 0;
282+
283+
vsnprintf(DebugStrings[nextDebugString]+len, MaxStringLen-len, fmt, args);
284+
285+
char *tmp = DebugStrings[nextDebugString];
286+
while (tmp && *tmp)
287+
{
288+
if (*tmp == '\r' || *tmp == '\n')
289+
*tmp = ' ';
290+
++tmp;
291+
}
292+
293+
++nextDebugString;
294+
++numDebugStrings;
295+
if (nextDebugString == MaxStrings)
296+
nextDebugString = 0;
297+
298+
va_end(args);
299+
}
300+
301+
254302
void addCRCGenLine(const char *fmt, ...)
255303
{
256304
if (!(IS_FRAME_OK_TO_LOG))

Core/GameEngine/Source/Common/RandomValue.cpp

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
#include "Common/RandomValue.h"
3333
#include "Common/crc.h"
3434
#include "Common/Debug.h"
35+
#include "Common/CRCDebug.h"
3536
#include "GameLogic/GameLogic.h"
3637

3738
#undef DEBUG_RANDOM_AUDIO
@@ -115,6 +116,9 @@ void InitRandom()
115116

116117
void InitRandom( UnsignedInt seed )
117118
{
119+
#ifdef DEBUG_CRC
120+
CRCGEN_LOG(("InitRandom called with seed: %u", seed));
121+
#endif
118122
#ifdef DETERMINISTIC
119123
seed = 0;
120124
#endif
@@ -124,6 +128,10 @@ void InitRandom( UnsignedInt seed )
124128
seedRandom(seed, theGameLogicSeed);
125129
theGameLogicBaseSeed = seed;
126130

131+
if (g_logRandom)
132+
{
133+
addCRCRandomLine("InitRandom %08lx", seed);
134+
}
127135
#ifdef DEBUG_RANDOM_LOGIC
128136
DEBUG_LOG(("InitRandom %08lx", seed));
129137
#endif
@@ -280,6 +288,10 @@ Int GetGameLogicRandomValue( int lo, int hi, const char *file, int line )
280288

281289
const Int rval = ((Int)(randomValue(theGameLogicSeed) % delta)) + lo;
282290

291+
if (g_logRandom)
292+
{
293+
addCRCRandomLine("%d: GetGameLogicRandomValue = %d (%d - %d), %s line %d", TheGameLogic ? TheGameLogic->getFrame() : -1, rval, lo, hi, file, line);
294+
}
283295
#ifdef DEBUG_RANDOM_LOGIC
284296
DEBUG_LOG(( "%d: GetGameLogicRandomValue = %d (%d - %d), %s line %d",
285297
TheGameLogic->getFrame(), rval, lo, hi, file, line ));
@@ -307,6 +319,10 @@ Real GetGameLogicRandomValueReal( Real lo, Real hi, const char *file, int line )
307319

308320
const Real rval = ((Real)(randomValue(theGameLogicSeed)) * theMultFactor) * delta + lo;
309321

322+
if (g_logRandom)
323+
{
324+
addCRCRandomLine("%d: GetGameLogicRandomValueReal = %f, %s line %d", TheGameLogic ? TheGameLogic->getFrame() : -1, rval, file, line);
325+
}
310326
#ifdef DEBUG_RANDOM_LOGIC
311327
DEBUG_LOG(( "%d: GetGameLogicRandomValueReal = %f, %s line %d",
312328
TheGameLogic->getFrame(), rval, file, line ));
@@ -337,6 +353,10 @@ Int GetGameLogicRandomValueUnchanged( int lo, int hi, const char *file, int line
337353
const UnsignedInt delta = hi - lo + 1;
338354
const Int rval = ((Int)(randomValue(seed) % delta)) + lo;
339355

356+
if (g_logRandom)
357+
{
358+
addCRCRandomLine("%d: GetGameLogicRandomValueUnchanged = %d (%d - %d), %s line %d", TheGameLogic ? TheGameLogic->getFrame() : -1, rval, lo, hi, file, line);
359+
}
340360
#ifdef DEBUG_RANDOM_LOGIC
341361
DEBUG_LOG(( "%d: GetGameLogicRandomValueUnchanged = %d (%d - %d), %s line %d",
342362
TheGameLogic->getFrame(), rval, lo, hi, file, line ));
@@ -367,6 +387,10 @@ Real GetGameLogicRandomValueRealUnchanged( Real lo, Real hi, const char *file, i
367387
const Real delta = hi - lo;
368388
const Real rval = ((Real)(randomValue(seed)) * theMultFactor) * delta + lo;
369389

390+
if (g_logRandom)
391+
{
392+
addCRCRandomLine("%d: GetGameLogicRandomValueRealUnchanged = %f, %s line %d", TheGameLogic ? TheGameLogic->getFrame() : -1, rval, file, line);
393+
}
370394
#ifdef DEBUG_RANDOM_LOGIC
371395
DEBUG_LOG(( "%d: GetGameLogicRandomValueRealUnchanged = %f, %s line %d",
372396
TheGameLogic->getFrame(), rval, file, line ));

Core/GameEngine/Source/GameNetwork/LANAPI.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -331,7 +331,11 @@ void LANAPI::update()
331331
{
332332
if (LANbuttonPushed)
333333
return;
334+
#ifdef __APPLE__
335+
static const UnsignedInt LANAPIUpdateDelay = 33;
336+
#else
334337
static const UnsignedInt LANAPIUpdateDelay = 200;
338+
#endif
335339
UnsignedInt now = timeGetTime();
336340

337341
if (now > m_lastUpdate + LANAPIUpdateDelay)

Core/GameEngine/Source/GameNetwork/LANAPICallbacks.cpp

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,21 @@ void LANAPI::OnGameStart()
189189

190190
if (m_currentGame)
191191
{
192+
#ifdef __APPLE__
193+
printf("MAC_LANAPI: === OnGameStart === amIHost=%d, localSlot=%d, seed=%u\n",
194+
m_currentGame->amIHost(), m_currentGame->getLocalSlotNum(), m_currentGame->getSeed());
195+
for (Int dbgSlot = 0; dbgSlot < MAX_SLOTS; ++dbgSlot)
196+
{
197+
GameSlot *dbgS = m_currentGame->getSlot(dbgSlot);
198+
if (dbgS && dbgS->isOccupied())
199+
{
200+
printf("MAC_LANAPI: Slot %d: human=%d, ai=%d, playerTemplate=%d, color=%d, startPos=%d, team=%d, IP=0x%08X\n",
201+
dbgSlot, dbgS->isHuman(), dbgS->isAI(), dbgS->getPlayerTemplate(),
202+
dbgS->getColor(), dbgS->getStartPos(), dbgS->getTeamNumber(), dbgS->getIP());
203+
}
204+
}
205+
fflush(stdout);
206+
#endif
192207
LANPreferences pref;
193208
AsciiString option;
194209
option.format("%d", m_currentGame->getLANSlot( m_currentGame->getLocalSlotNum() )->getPlayerTemplate());
@@ -340,6 +355,11 @@ void LANAPI::OnGameOptions( UnsignedInt playerIP, Int playerSlot, AsciiString op
340355
// Parse player requests (side, color, etc)
341356
if( AmIHost() && m_localIP != playerIP)
342357
{
358+
#ifdef __APPLE__
359+
printf("MAC_LANAPI: [HOST] received options from slot %d (IP=0x%08X): \"%s\"\n",
360+
playerSlot, playerIP, options.str());
361+
fflush(stdout);
362+
#endif
343363
if (options.compare("HELLO") == 0)
344364
{
345365
m_currentGame->setPlayerLastHeard(playerSlot, timeGetTime());
@@ -466,6 +486,12 @@ void LANAPI::OnGameOptions( UnsignedInt playerIP, Int playerSlot, AsciiString op
466486
DEBUG_LOG(("Slot value is color=%d, PlayerTemplate=%d, startPos=%d, team=%d",
467487
slot->getColor(), slot->getPlayerTemplate(), slot->getStartPos(), slot->getTeamNumber()));
468488
DEBUG_LOG(("Slot list updated to %s", GenerateGameOptionsString().str()));
489+
#ifdef __APPLE__
490+
printf("MAC_LANAPI: [HOST] applied change for slot %d: color=%d, playerTemplate=%d, startPos=%d, team=%d\n",
491+
playerSlot, slot->getColor(), slot->getPlayerTemplate(), slot->getStartPos(), slot->getTeamNumber());
492+
printf("MAC_LANAPI: [HOST] broadcasting: %s\n", GenerateGameOptionsString().str());
493+
fflush(stdout);
494+
#endif
469495
}
470496
}
471497
}
@@ -523,6 +549,11 @@ void LANAPI::OnGameJoin( ReturnType ret, LANGameInfo *theGame )
523549

524550
LANPreferences pref;
525551
AsciiString options;
552+
#ifdef __APPLE__
553+
printf("MAC_LANAPI: OnGameJoin OK: preferredFaction=%d, preferredColor=%d\n",
554+
pref.getPreferredFaction(), pref.getPreferredColor());
555+
fflush(stdout);
556+
#endif
526557
options.format("PlayerTemplate=%d", pref.getPreferredFaction());
527558
RequestGameOptions(options, true);
528559
options.format("Color=%d", pref.getPreferredColor());

Core/GameEngine/Source/GameNetwork/LANAPIhandlers.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -706,6 +706,13 @@ void LANAPI::handleChat( LANMessage *msg, UnsignedInt senderIP )
706706

707707
void LANAPI::handleGameStart( LANMessage *msg, UnsignedInt senderIP )
708708
{
709+
#ifdef __APPLE__
710+
printf("MAC_LANAPI: handleGameStart RECEIVED from %08X, inLobby=%d, hasGame=%d, hostIP=%08X, inProgress=%d\n",
711+
senderIP, m_inLobby, m_currentGame != nullptr,
712+
m_currentGame ? m_currentGame->getIP(0) : 0,
713+
m_currentGame ? m_currentGame->isGameInProgress() : -1);
714+
fflush(stdout);
715+
#endif
709716
if (!m_inLobby && m_currentGame && m_currentGame->getIP(0) == senderIP && !m_currentGame->isGameInProgress())
710717
{
711718
OnGameStart();

0 commit comments

Comments
 (0)