changeset 4830:4f6ff5b2a5be draft

(svn r6754) -Codechange: Remove some #idef ENABLE_NETWORK specific defines. With networking disabled hardcode _networking/_network_available to zero and let the compiler handle all optimizations.
author Darkvater <Darkvater@openttd.org>
date Thu, 12 Oct 2006 14:59:27 +0000
parents 640f36a9346e
children 1965a9c3ce48
files date.c gui.h intro_gui.c main_gui.c network.h network_gui.c network_gui.h network_server.h network_udp.h openttd.c player_gui.c
diffstat 11 files changed, 55 insertions(+), 54 deletions(-) [+]
line wrap: on
line diff
--- a/date.c
+++ b/date.c
@@ -254,9 +254,7 @@
 		TownsMonthlyLoop();
 		IndustryMonthlyLoop();
 		StationMonthlyLoop();
-#ifdef ENABLE_NETWORK
 		if (_network_server) NetworkServerMonthlyLoop();
-#endif /* ENABLE_NETWORK */
 	}
 
 	/* check if we entered a new year? */
@@ -269,9 +267,7 @@
 	RoadVehiclesYearlyLoop();
 	AircraftYearlyLoop();
 	ShipsYearlyLoop();
-#ifdef ENABLE_NETWORK
 	if (_network_server) NetworkServerYearlyLoop();
-#endif /* ENABLE_NETWORK */
 
 	/* check if we reached end of the game */
 	if (_cur_year == _patches.ending_year) {
--- a/gui.h
+++ b/gui.h
@@ -120,9 +120,6 @@
 /* FIOS_TYPE_FILE, FIOS_TYPE_OLDFILE etc. different colours */
 extern const byte _fios_colors[];
 
-/* network gui */
-void ShowNetworkGameWindow(void);
-
 /* bridge_gui.c */
 void ShowBuildBridgeWindow(uint start, uint end, byte type);
 
--- a/intro_gui.c
+++ b/intro_gui.c
@@ -13,6 +13,7 @@
 #include "settings.h"
 #include "heightmap.h"
 #include "genworld.h"
+#include "network_gui.h"
 
 static const Widget _select_game_widgets[] = {
 {    WWT_CAPTION, RESIZE_NONE, 13,   0, 335,   0,  13, STR_0307_OPENTTD,         STR_NULL},
@@ -66,15 +67,11 @@
 		case 5: ShowSaveLoadDialog(SLD_LOAD_HEIGHTMAP); break;
 		case 6: ShowCreateScenario(); break;
 		case 7:
-#ifdef ENABLE_NETWORK
 			if (!_network_available) {
 				ShowErrorMessage(INVALID_STRING_ID, STR_NETWORK_ERR_NOTAVAILABLE, 0, 0);
 			} else {
 				ShowNetworkGameWindow();
 			}
-#else
-			ShowErrorMessage(INVALID_STRING_ID ,STR_NETWORK_ERR_NOTAVAILABLE, 0, 0);
-#endif
 			break;
 		case 8: case 9: case 10: case 11:
 			RaiseWindowWidget(w, _opt_newgame.landscape + 8);
--- a/main_gui.c
+++ b/main_gui.c
@@ -38,6 +38,7 @@
 #include "network_data.h"
 #include "network_client.h"
 #include "network_server.h"
+#include "network_gui.h"
 
 static int _rename_id;
 static int _rename_what;
@@ -221,23 +222,16 @@
 	ShowPlayerFinances(index);
 }
 
-#ifdef ENABLE_NETWORK
-extern void ShowClientList(void);
-#endif /* ENABLE_NETWORK */
-
 static void MenuClickCompany(int index)
 {
 	if (_networking && index == 0) {
-#ifdef ENABLE_NETWORK
 		ShowClientList();
-#endif /* ENABLE_NETWORK */
 	} else {
 		if (_networking) index--;
 		ShowPlayerCompany(index);
 	}
 }
 
-
 static void MenuClickGraphs(int index)
 {
 	switch (index) {
@@ -308,15 +302,12 @@
 }
 
 #ifdef ENABLE_NETWORK
-
-void ShowNetworkGiveMoneyWindow(byte player)
+void ShowNetworkGiveMoneyWindow(PlayerID player)
 {
 	_rename_id = player;
 	_rename_what = 3;
 	ShowQueryString(STR_EMPTY, STR_NETWORK_GIVE_MONEY_CAPTION, 30, 180, 1, 0, CS_NUMERAL);
 }
-
-
 #endif /* ENABLE_NETWORK */
 
 void ShowRenameSignWindow(const Sign *si)
@@ -2320,9 +2311,7 @@
 
 			case '1' | WKC_ALT: /* Gimme money */
 				/* Server can not cheat in advertise mode either! */
-#ifdef ENABLE_NETWORK
 				if (!_networking || !_network_server || !_network_advertise)
-#endif
 					DoCommandP(0, -10000000, 0, NULL, CMD_MONEY_CHEAT);
 				break;
 
--- a/network.h
+++ b/network.h
@@ -197,7 +197,6 @@
 
 VARDEF byte _network_lan_internet;
 
-VARDEF bool _network_advertise;
 VARDEF bool _network_need_advertise;
 VARDEF uint32 _network_last_advertise_frame;
 VARDEF uint8 _network_advertise_retries;
@@ -233,13 +232,26 @@
 bool NetworkClientConnectGame(const char* host, unsigned short port);
 void NetworkReboot(void);
 void NetworkDisconnect(void);
+
+VARDEF bool _networking;         ///< are we in networking mode?
+VARDEF bool _network_server;     ///< network-server is active
+VARDEF bool _network_available;  ///< is network mode available?
+
+#else /* ENABLE_NETWORK */
+/* Network function stubs when networking is disabled */
+
+static inline void NetworkStartUp(void) {}
+static inline void NetworkShutDown(void) {}
+
+#define _networking 0
+#define _network_server 0
+#define _network_available 0
+
 #endif /* ENABLE_NETWORK */
 
-// Those variables must always be registered!
-VARDEF bool _networking;
-VARDEF bool _network_available;  // is network mode available?
-VARDEF bool _network_server; // network-server is active
-VARDEF bool _network_dedicated; // are we a dedicated server?
-VARDEF PlayerID _network_playas; // an id to play as..
+/* These variables must always be registered! */
+VARDEF bool _network_dedicated;  ///< are we a dedicated server?
+VARDEF bool _network_advertise;  ///< is the server advertising to the master server?
+VARDEF PlayerID _network_playas; ///< an id to play as..
 
 #endif /* NETWORK_H */
--- a/network_gui.c
+++ b/network_gui.c
@@ -1720,6 +1720,4 @@
 	UpdateTextBufferSize(&WP(w, querystr_d).text);
 }
 
-#else
-void ShowJoinStatusWindowAfterJoin(void) {}
 #endif /* ENABLE_NETWORK */
--- a/network_gui.h
+++ b/network_gui.h
@@ -3,6 +3,25 @@
 #ifndef NETWORK_GUI_H
 #define NETWORK_GUI_H
 
+#ifdef ENABLE_NETWORK
+
+#include "network_data.h"
+
 void ShowNetworkNeedPassword(NetworkPasswordType npt);
+void ShowNetworkGiveMoneyWindow(byte player); // PlayerID
+void ShowNetworkChatQueryWindow(byte desttype, byte dest);
+void ShowJoinStatusWindowAfterJoin(void);
+void ShowNetworkGameWindow(void);
+void ShowClientList(void);
+
+#else /* ENABLE_NETWORK */
+/* Network function stubs when networking is disabled */
+
+static inline void ShowNetworkChatQueryWindow(byte desttype, byte dest) {}
+static inline void ShowClientList(void) {}
+static inline void ShowJoinStatusWindowAfterJoin(void) {}
+static inline void ShowNetworkGameWindow(void) {}
+
+#endif /* ENABLE_NETWORK */
 
 #endif /* NETWORK_GUI_H */
--- a/network_server.h
+++ b/network_server.h
@@ -28,6 +28,12 @@
 	return inet_ntoa(addr);
 }
 
+#else /* ENABLE_NETWORK */
+/* Network function stubs when networking is disabled */
+
+static inline void NetworkServerMonthlyLoop(void) {}
+static inline void NetworkServerYearlyLoop(void) {}
+
 #endif /* ENABLE_NETWORK */
 
 #endif /* NETWORK_SERVER_H */
--- a/network_udp.h
+++ b/network_udp.h
@@ -14,6 +14,6 @@
 void NetworkUDPAdvertise(void);
 void NetworkUDPRemoveAdvertise(void);
 
-#endif
+#endif /* ENABLE_NETWORK */
 
 #endif /* NETWORK_UDP_H */
--- a/openttd.c
+++ b/openttd.c
@@ -453,10 +453,7 @@
 	// restore saved music volume
 	_music_driver->set_volume(msf.music_vol);
 
-#ifdef ENABLE_NETWORK
-	// initialize network-core
-	NetworkStartUp();
-#endif /* ENABLE_NETWORK */
+	NetworkStartUp(); // initialize network-core
 
 	_opt_ptr = &_opt_newgame;
 
@@ -505,12 +502,7 @@
 	WaitTillSaved();
 	IConsoleFree();
 
-#ifdef ENABLE_NETWORK
-	if (_network_available) {
-		// Shut down the network and close any open connections
-		NetworkDisconnect();
-	}
-#endif /* ENABLE_NETWORK */
+	if (_network_available) NetworkShutDown(); // Shut down the network and close any open connections
 
 	_video_driver->stop();
 	_music_driver->stop();
@@ -986,8 +978,7 @@
 
 #ifdef ENABLE_NETWORK
 	// Check for UDP stuff
-	if (_network_available)
-		NetworkUDPGameLoop();
+	if (_network_available) NetworkUDPGameLoop();
 
 	if (_networking && !IsGeneratingWorld()) {
 		// Multiplayer
--- a/player_gui.c
+++ b/player_gui.c
@@ -18,15 +18,11 @@
 #include "train.h"
 #include "date.h"
 #include "newgrf.h"
-
-#ifdef ENABLE_NETWORK
 #include "network_data.h"
 #include "network_client.h"
-#endif
 
 static void DoShowPlayerFinances(PlayerID player, bool show_small, bool show_stickied);
 
-
 static void DrawPlayerEconomyStats(const Player *p, byte mode)
 {
 	int x,y,i,j,year;
@@ -811,15 +807,15 @@
 					DoCommandP(0, w->window_number, 0, NULL, CMD_SELL_SHARE_IN_COMPANY | CMD_MSG(STR_707C_CAN_T_SELL_25_SHARE_IN));
 					break;
 
+				#ifdef ENABLE_NETWORK
 				case PCW_WIDGET_COMPANY_PASSWORD:
-					#ifdef ENABLE_NETWORK
 					if (w->window_number == _local_player) {
 						WP(w,def_d).byte_1 = 2;
 						ShowQueryString(BindCString(_network_player_info[_local_player].password),
 							STR_SET_COMPANY_PASSWORD, sizeof(_network_player_info[_local_player].password), 250, w->window_class, w->window_number, CS_ALPHANUMERAL);
 					}
-					#endif
 					break;
+				#endif /* ENABLE_NETWORK */
 			}
 			break;
 
@@ -857,12 +853,12 @@
 				case 1: /* Change company name */
 					DoCommandP(0, 0, 0, NULL, CMD_CHANGE_COMPANY_NAME | CMD_MSG(STR_700C_CAN_T_CHANGE_COMPANY_NAME));
 					break;
+				#ifdef ENABLE_NETWORK
 				case 2: /* Change company password */
-					#ifdef ENABLE_NETWORK
 					if (*b == '\0') *b = '*'; // empty password is a '*' because of console argument
 					NetworkChangeCompanyPassword(1, &b);
-					#endif
 					break;
+				#endif /* ENABLE_NETWORK */
 			}
 			break;
 		}