Changeset - r18988:3f7b98056f8d
[Not reviewed]
master
0 4 0
rubidium - 12 years ago 2012-01-26 17:24:56
rubidium@openttd.org
(svn r23854) -Codechange: make it easier to put random debug stuff into the random log
4 files changed with 25 insertions and 25 deletions:
0 comments (0 inline, 0 general)
src/core/random_func.cpp
Show inline comments
 
@@ -69,11 +69,7 @@ void SetRandomSeed(uint32 seed)
 
uint32 DoRandom(int line, const char *file)
 
{
 
	if (_networking && (!_network_server || (NetworkClientSocket::IsValidID(0) && NetworkClientSocket::Get(0)->status != NetworkClientSocket::STATUS_INACTIVE))) {
 
		static FILE *f = FioFOpenFile("random-out.log", "wb", AUTOSAVE_DIR);
 
		if (f != NULL) {
 
			fprintf(f, "%08x; %02x; %04x; %02x; %s:%d\n", _date, _date_fract, _frame_counter, (byte)_current_company, file, line);
 
			fflush(f);
 
		}
 
		DEBUG(random, 0, "%08x; %02x; %04x; %02x; %s:%d", _date, _date_fract, _frame_counter, (byte)_current_company, file, line);
 
	}
 

	
 
	return _random.Next();
src/core/random_func.hpp
Show inline comments
 
@@ -17,19 +17,6 @@
 
	#define Random OTTD_Random
 
#endif /* __APPLE__ */
 

	
 
/**************
 
 * Warning: DO NOT enable this unless you understand what it does
 
 *
 
 * If enabled, in a network game all randoms will be dumped to the
 
 *  stdout if the first client joins (or if you are a client). This
 
 *  is to help finding desync problems.
 
 *
 
 * Warning: DO NOT enable this unless you understand what it does
 
 **************/
 

	
 
//#define RANDOM_DEBUG
 

	
 

	
 
/**
 
 * Structure to encapsulate the pseudo random number generators.
 
 */
src/debug.cpp
Show inline comments
 
@@ -39,6 +39,9 @@ int _debug_sl_level;
 
int _debug_gamelog_level;
 
int _debug_desync_level;
 
int _debug_console_level;
 
#ifdef RANDOM_DEBUG
 
int _debug_random_level;
 
#endif
 

	
 
uint32 _realtime_tick = 0;
 

	
 
@@ -64,6 +67,9 @@ struct DebugLevel {
 
	DEBUG_LEVEL(gamelog),
 
	DEBUG_LEVEL(desync),
 
	DEBUG_LEVEL(console),
 
#ifdef RANDOM_DEBUG
 
	DEBUG_LEVEL(random),
 
#endif
 
	};
 
#undef DEBUG_LEVEL
 

	
 
@@ -85,7 +91,21 @@ static void debug_print(const char *dbg,
 
		return;
 
	}
 
#endif /* ENABLE_NETWORK */
 
	if (strcmp(dbg, "desync") != 0) {
 
	if (strcmp(dbg, "desync") == 0) {
 
		static FILE *f = FioFOpenFile("commands-out.log", "wb", AUTOSAVE_DIR);
 
		if (f == NULL) return;
 

	
 
		fprintf(f, "%s%s\n", GetLogPrefix(), buf);
 
		fflush(f);
 
#ifdef RANDOM_DEBUG
 
	} else if (strcmp(dbg, "random") == 0) {
 
		static FILE *f = FioFOpenFile("random-out.log", "wb", AUTOSAVE_DIR);
 
		if (f == NULL) return;
 

	
 
		fprintf(f, "%s\n", buf);
 
		fflush(f);
 
#endif
 
	} else {
 
#if defined(WINCE)
 
		/* We need to do OTTD2FS twice, but as it uses a static buffer, we need to store one temporary */
 
		TCHAR tbuf[512];
 
@@ -98,12 +118,6 @@ static void debug_print(const char *dbg,
 
		NetworkAdminConsole(dbg, buf);
 
#endif /* ENABLE_NETWORK */
 
		IConsoleDebug(dbg, buf);
 
	} else {
 
		static FILE *f = FioFOpenFile("commands-out.log", "wb", AUTOSAVE_DIR);
 
		if (f == NULL) return;
 

	
 
		fprintf(f, "%s%s\n", GetLogPrefix(), buf);
 
		fflush(f);
 
	}
 
}
 

	
src/debug.h
Show inline comments
 
@@ -51,6 +51,9 @@
 
	extern int _debug_gamelog_level;
 
	extern int _debug_desync_level;
 
	extern int _debug_console_level;
 
#ifdef RANDOM_DEBUG
 
	extern int _debug_random_level;
 
#endif
 

	
 
	void CDECL debug(const char *dbg, const char *format, ...) WARN_FORMAT(2, 3);
 
#endif /* NO_DEBUG_MESSAGES */
0 comments (0 inline, 0 general)