(svn r11811) -Fix: make compilation without networking work again (and thus move the debugdumpcommand stuff out of the network 'area').
authorrubidium
Fri, 11 Jan 2008 00:30:32 +0000
changeset 8743 62a558995c35
parent 8742 a55430b832a6
child 8744 f926fa3978c8
(svn r11811) -Fix: make compilation without networking work again (and thus move the debugdumpcommand stuff out of the network 'area').
config.lib
src/command.cpp
src/date.cpp
src/debug.cpp
src/debug.h
src/network/network.cpp
src/network/network.h
src/network/network_data.cpp
src/openttd.cpp
src/players.cpp
src/saveload.cpp
src/video/sdl_v.cpp
--- a/config.lib	Thu Jan 10 22:46:04 2008 +0000
+++ b/config.lib	Fri Jan 11 00:30:32 2008 +0000
@@ -2242,6 +2242,7 @@
 	echo ""
 	echo "Features and packages:"
 	echo "  --enable-debug[=LVL]           enable debug-mode (LVL=[0123], 0 is release)"
+	echo "  --enable_desync_debug=[LVL]    enable desync debug options (LVL=[012], 0 is none"
 	echo "  --enable-profiling             enables profiling"
 	echo "  --enable-dedicated             compile a dedicated server (without video)"
 	echo "  --enable-static                enable static compile (doesn't work for"
--- a/src/command.cpp	Thu Jan 10 22:46:04 2008 +0000
+++ b/src/command.cpp	Fri Jan 11 00:30:32 2008 +0000
@@ -18,6 +18,8 @@
 #include "gfx_func.h"
 #include "functions.h"
 #include "town.h"
+#include "date_func.h"
+#include "debug.h"
 
 const char *_cmd_text = NULL;
 
@@ -613,11 +615,7 @@
 		return true;
 	}
 #endif /* ENABLE_NETWORK */
-#ifdef DEBUG_DUMP_COMMANDS
-	extern Date      _date;
-	extern DateFract _date_fract;
-	debug_dump_commands("ddc:cmd:%d;%d;%d;%d;%d;%d;%d;%s\n", _date, _date_fract, (int)_current_player, tile, p1, p2, cmd, _cmd_text);
-#endif /* DUMP_COMMANDS */
+	DebugDumpCommands("ddc:cmd:%d;%d;%d;%d;%d;%d;%d;%s\n", _date, _date_fract, (int)_current_player, tile, p1, p2, cmd, _cmd_text);
 
 	/* update last build coordinate of player. */
 	if (tile != 0 && IsValidPlayer(_current_player)) {
--- a/src/date.cpp	Thu Jan 10 22:46:04 2008 +0000
+++ b/src/date.cpp	Fri Jan 11 00:30:32 2008 +0000
@@ -13,6 +13,7 @@
 #include "functions.h"
 #include "date_func.h"
 #include "vehicle_base.h"
+#include "debug.h"
 #ifdef DEBUG_DUMP_COMMANDS
 #include "saveload.h"
 #include "town_map.h"
@@ -282,7 +283,7 @@
 		char name[MAX_PATH];
 		snprintf(name, lengthof(name), "dmp_cmds_%d.sav", _date);
 		SaveOrLoad(name, SL_SAVE, AUTOSAVE_DIR);
-		debug_dump_commands("ddc:save:%s\n", name);
+		DebugDumpCommands("ddc:save:%s\n", name);
 #endif /* DUMP_COMMANDS */
 		if (_opt.autosave != 0 && (_cur_month % _autosave_months[_opt.autosave]) == 0) {
 			_do_autosave = true;
--- a/src/debug.cpp	Thu Jan 10 22:46:04 2008 +0000
+++ b/src/debug.cpp	Fri Jan 11 00:30:32 2008 +0000
@@ -176,3 +176,20 @@
 
 	return dbgstr;
 }
+
+#ifdef DEBUG_DUMP_COMMANDS
+#include "fileio.h"
+
+void CDECL DebugDumpCommands(const char *s, ...)
+{
+	static FILE *f = FioFOpenFile("commands-out.log", "wb", AUTOSAVE_DIR);
+	if (f == NULL) return;
+
+	va_list va;
+	va_start(va, s);
+	vfprintf(f, s, va);
+	va_end(va);
+
+	fflush(f);
+}
+#endif /* DEBUG_DUMP_COMMANDS */
--- a/src/debug.h	Thu Jan 10 22:46:04 2008 +0000
+++ b/src/debug.h	Fri Jan 11 00:30:32 2008 +0000
@@ -132,4 +132,10 @@
 void ShowInfo(const char *str);
 void CDECL ShowInfoF(const char *str, ...);
 
+#ifdef DEBUG_DUMP_COMMANDS
+	void CDECL DebugDumpCommands(const char *s, ...);
+#else /* DEBUG_DUMP_COMMANDS */
+	static inline void DebugDumpCommands(const char *s, ...) {}
+#endif /* DEBUG_DUMP_COMMANDS */
+
 #endif /* DEBUG_H */
--- a/src/network/network.cpp	Thu Jan 10 22:46:04 2008 +0000
+++ b/src/network/network.cpp	Fri Jan 11 00:30:32 2008 +0000
@@ -34,7 +34,7 @@
 #include "../string_func.h"
 #ifdef DEBUG_DUMP_COMMANDS
 	#include "../core/alloc_func.hpp"
-#endif
+#endif /* DEBUG_DUMP_COMMANDS */
 
 /* Check whether NETWORK_NUM_LANDSCAPES is still in sync with NUM_LANDSCAPE */
 assert_compile((int)NETWORK_NUM_LANDSCAPES == (int)NUM_LANDSCAPE);
@@ -193,9 +193,7 @@
 			break;
 	}
 
-#ifdef DEBUG_DUMP_COMMANDS
-	debug_dump_commands("ddc:cmsg:%d;%d;%s\n", _date, _date_fract, message);
-#endif /* DUMP_COMMANDS */
+	DebugDumpCommands("ddc:cmsg:%d;%d;%s\n", _date, _date_fract, message);
 	IConsolePrintF(color, "%s", message);
 	AddChatMessage(color, duration, "%s", message);
 }
@@ -1236,9 +1234,7 @@
 			if (_sync_seed_1 != _random_seeds[0][0]) {
 #endif
 				NetworkError(STR_NETWORK_ERR_DESYNC);
-#ifdef DEBUG_DUMP_COMMANDS
-				debug_dump_commands("ddc:serr:%d;%d\n", _date, _date_fract);
-#endif /* DUMP_COMMANDS */
+				DebugDumpCommands("ddc:serr:%d;%d\n", _date, _date_fract);
 				DEBUG(net, 0, "Sync error detected!");
 				NetworkClientError(NETWORK_RECV_STATUS_DESYNC, DEREF_CLIENT(0));
 				return false;
@@ -1313,7 +1309,7 @@
 			sscanf(&buff[8], "%d;%d;%d;%d;%d;%d;%d;%s", &next_date, &next_date_fract, &player, &cp->tile, &cp->p1, &cp->p2, &cp->cmd, cp->text);
 			cp->player = (Owner)player;
 		}
-#endif /* DUMP_COMMANDS */
+#endif /* DEBUG_DUMP_COMMANDS */
 
 		bool send_frame = false;
 
@@ -1467,18 +1463,4 @@
 	return strncmp(_openttd_revision, other, NETWORK_REVISION_LENGTH - 1) == 0;
 }
 
-#ifdef DEBUG_DUMP_COMMANDS
-void CDECL debug_dump_commands(const char *s, ...)
-{
-	static FILE *f = FioFOpenFile("commands-out.log", "wb", AUTOSAVE_DIR);
-	if (f == NULL) return;
-
-	va_list va;
-	va_start(va, s);
-	vfprintf(f, s, va);
-	va_end(va);
-
-	fflush(f);
-}
-#endif /* DEBUG_DUMP_COMMANDS */
 #endif /* ENABLE_NETWORK */
--- a/src/network/network.h	Thu Jan 10 22:46:04 2008 +0000
+++ b/src/network/network.h	Fri Jan 11 00:30:32 2008 +0000
@@ -18,17 +18,6 @@
 //  nothing will happen.
 //#define ENABLE_NETWORK_SYNC_EVERY_FRAME
 
-/*
- * Dumps all commands that are sent/received to stderr and saves every month.
- * This log can become quite large over time; say in the order of two to three
- * times the bandwidth used for network games.
- */
-//#define DEBUG_DUMP_COMMANDS
-
-#ifdef DEBUG_DUMP_COMMANDS
-void CDECL debug_dump_commands(const char *s, ...);
-#endif /* DEBUG_DUMP_COMMANDS */
-
 // In theory sending 1 of the 2 seeds is enough to check for desyncs
 //   so in theory, this next define can be left off.
 //#define NETWORK_SEND_DOUBLE_SEED
--- a/src/network/network_data.cpp	Thu Jan 10 22:46:04 2008 +0000
+++ b/src/network/network_data.cpp	Fri Jan 11 00:30:32 2008 +0000
@@ -10,6 +10,7 @@
 #include "../callback_table.h"
 #include "../core/alloc_func.hpp"
 #include "../string_func.h"
+#include "../date_func.h"
 
 // Add a command to the local command queue
 void NetworkAddCommandQueue(NetworkTCPSocketHandler *cs, CommandPacket *cp)
@@ -99,11 +100,7 @@
 		cp->callback = 0;
 	}
 
-#ifdef DEBUG_DUMP_COMMANDS
-	extern Date      _date;
-	extern DateFract _date_fract;
-	debug_dump_commands("ddc:cmd:%d;%d;%d;%d;%d;%d;%d;%s\n", _date, _date_fract, (int)cp->player, cp->tile, cp->p1, cp->p2, cp->cmd, cp->text);
-#endif /* DUMP_COMMANDS */
+	DebugDumpCommands("ddc:cmd:%d;%d;%d;%d;%d;%d;%d;%s\n", _date, _date_fract, (int)cp->player, cp->tile, cp->p1, cp->p2, cp->cmd, cp->text);
 
 	DoCommandP(cp->tile, cp->p1, cp->p2, _callback_table[cp->callback], cp->cmd | CMD_NETWORK_COMMAND, cp->my_cmd);
 }
--- a/src/openttd.cpp	Thu Jan 10 22:46:04 2008 +0000
+++ b/src/openttd.cpp	Fri Jan 11 00:30:32 2008 +0000
@@ -696,12 +696,14 @@
 	SettingsDisableElrail(_patches.disable_elrails);
 	SetDefaultRailGui();
 
+#ifdef ENABLE_NETWORK
 	/* We are the server, we start a new player (not dedicated),
 	 * so set the default password *if* needed. */
 	if (_network_server && !StrEmpty(_network_default_company_pass)) {
 		char *password = _network_default_company_pass;
 		NetworkChangeCompanyPassword(1, &password);
 	}
+#endif /* ENABLE_NETWORK */
 
 	MarkWholeScreenDirty();
 }
--- a/src/players.cpp	Thu Jan 10 22:46:04 2008 +0000
+++ b/src/players.cpp	Fri Jan 11 00:30:32 2008 +0000
@@ -811,10 +811,12 @@
 		if (_local_player != _network_playas && _network_playas == p->index) {
 			assert(_local_player == PLAYER_SPECTATOR);
 			SetLocalPlayer(p->index);
+#ifdef ENABLE_NETWORK
 			if (!StrEmpty(_network_default_company_pass)) {
 				char *password = _network_default_company_pass;
 				NetworkChangeCompanyPassword(1, &password);
 			}
+#endif /* ENABLE_NETWORK */
 			MarkWholeScreenDirty();
 		}
 
--- a/src/saveload.cpp	Thu Jan 10 22:46:04 2008 +0000
+++ b/src/saveload.cpp	Fri Jan 11 00:30:32 2008 +0000
@@ -1655,9 +1655,7 @@
 			}
 		} else { /* LOAD game */
 			assert(mode == SL_LOAD);
-	#ifdef DEBUG_DUMP_COMMANDS
-			debug_dump_commands("ddc:load:%s\n", filename);
-	#endif /* DUMP_COMMANDS */
+			DebugDumpCommands("ddc:load:%s\n", filename);
 
 			if (fread(hdr, sizeof(hdr), 1, _sl.fh) != 1) SlError(STR_GAME_SAVELOAD_ERROR_FILE_NOT_READABLE);
 
--- a/src/video/sdl_v.cpp	Thu Jan 10 22:46:04 2008 +0000
+++ b/src/video/sdl_v.cpp	Fri Jan 11 00:30:32 2008 +0000
@@ -11,6 +11,7 @@
 #include "../variables.h"
 #include "../blitter/factory.hpp"
 #include "../network/network.h"
+#include "../core/math_func.hpp"
 #include "sdl_v.h"
 #include <SDL.h>