(svn r2694) Various smaller changes: eol-style, static, code simplification
authortron
Sat, 23 Jul 2005 18:46:17 +0000
changeset 2180 efe39e3d3fb4
parent 2179 f1c4cdb03623
child 2181 659d7d8d1ccd
(svn r2694) Various smaller changes: eol-style, static, code simplification
os2.c
video/dedicated_v.c
--- a/os2.c	Sat Jul 23 17:45:42 2005 +0000
+++ b/os2.c	Sat Jul 23 18:46:17 2005 +0000
@@ -620,22 +620,6 @@
 	mkdir(_path.scenario_dir);
 }
 
-// FUNCTION: OS2_SwitchToConsoleMode
-//
-// Switches OpenTTD to a console app at run-time, instead of a PM app
-// Necessary to see stdout, etc
-
-void OS2_SwitchToConsoleMode(void)
-{
-	PPIB pib;
-	PTIB tib;
-
-	DosGetInfoBlocks(&tib, &pib);
-
-	// Change flag from PM to VIO
-	pib->pib_ultype = 3;
-}
-
 /**
  * Insert a chunk of text from the clipboard onto the textbuffer. Get TEXT clipboard
  * and append this up to the maximum length (either absolute or screenlength). If maxlength
--- a/video/dedicated_v.c	Sat Jul 23 17:45:42 2005 +0000
+++ b/video/dedicated_v.c	Sat Jul 23 18:46:17 2005 +0000
@@ -3,6 +3,7 @@
 #include "debug.h"
 #include "functions.h"
 #include "network.h"
+#include "video/dedicated_v.h"
 
 #ifdef ENABLE_NETWORK
 
@@ -11,12 +12,6 @@
 #include "command.h"
 #include "console.h"
 #include "variables.h"
-#include "video/dedicated_v.h"
-
-#ifdef WIN32
-#	include <windows.h> /* GetTickCount */
-#	include <conio.h>
-#endif
 
 #ifdef __OS2__
 #	include <sys/time.h> /* gettimeofday */
@@ -25,7 +20,19 @@
 #	include <conio.h>
 #	define STDIN 0  /* file descriptor for standard input */
 
-	extern void OS2_SwitchToConsoleMode();
+/** 
+ * Switches OpenTTD to a console app at run-time, instead of a PM app
+ * Necessary to see stdout, etc. */
+static void OS2_SwitchToConsoleMode(void)
+{
+	PPIB pib;
+	PTIB tib;
+
+	DosGetInfoBlocks(&tib, &pib);
+
+	// Change flag from PM to VIO
+	pib->pib_ultype = 3;
+}
 #endif
 
 #ifdef UNIX
@@ -34,14 +41,7 @@
 #	include <unistd.h>
 #	include <signal.h>
 #	define STDIN 0  /* file descriptor for standard input */
-#endif
-
-static void *_dedicated_video_mem;
 
-extern bool SafeSaveOrLoad(const char *filename, int mode, int newgm);
-extern void SwitchMode(int new_mode);
-
-#ifdef UNIX
 /* Signal handlers */
 static void DedicatedSignalHandler(int sig)
 {
@@ -51,13 +51,15 @@
 #endif
 
 #ifdef WIN32
+#include <windows.h> /* GetTickCount */
+#include <conio.h>
 #include <time.h>
-HANDLE hEvent;
+static HANDLE hEvent;
 static HANDLE hThread; // Thread to close
 static char _win_console_thread_buffer[200];
 
 /* Windows Console thread. Just loop and signal when input has been received */
-void WINAPI CheckForConsoleInput(void)
+static void WINAPI CheckForConsoleInput(void)
 {
 	while (true) {
 		fgets(_win_console_thread_buffer, lengthof(_win_console_thread_buffer), stdin);
@@ -65,7 +67,7 @@
 	}
 }
 
-void CreateWindowsConsoleThread(void)
+static void CreateWindowsConsoleThread(void)
 {
 	static char tbuffer[9];
 	DWORD dwThreadId;
@@ -81,7 +83,7 @@
 	DEBUG(misc, 0) ("Windows console thread started...");
 }
 
-void CloseWindowsConsoleThread(void)
+static void CloseWindowsConsoleThread(void)
 {
 	CloseHandle(hThread);
 	CloseHandle(hEvent);
@@ -90,6 +92,13 @@
 
 #endif
 
+
+static void *_dedicated_video_mem;
+
+extern bool SafeSaveOrLoad(const char *filename, int mode, int newgm);
+extern void SwitchMode(int new_mode);
+
+
 static const char *DedicatedVideoStart(const char * const *parm)
 {
 	_screen.width = _screen.pitch = _cur_resolution[0];
@@ -132,7 +141,6 @@
 {
 	struct timeval tv;
 	fd_set readfds;
-	byte ret;
 
 	tv.tv_sec = 0;
 	tv.tv_usec = 1;
@@ -141,21 +149,29 @@
 	FD_SET(STDIN, &readfds);
 
 	/* don't care about writefds and exceptfds: */
-	ret = select(STDIN + 1, &readfds, NULL, NULL, &tv);
+	return select(STDIN + 1, &readfds, NULL, NULL, &tv) > 0;
+}
 
-	if (ret > 0)
-		return true;
+static uint32 GetTime(void)
+{
+	struct timeval tim;
 
-	return false;
+	gettimeofday(&tim, NULL);
+	return tim.tv_usec / 1000 + tim.tv_sec * 1000;
 }
+
 #else
+
 static bool InputWaiting(void)
 {
-	if (WaitForSingleObject(hEvent, 1) == WAIT_OBJECT_0)
-		return true;
+	return WaitForSingleObject(hEvent, 1) == WAIT_OBJECT_0;
+}
 
-	return false;
+static uint32 GetTime(void)
+{
+	return GetTickCount();
 }
+
 #endif
 
 static void DedicatedHandleKeyInput(void)
@@ -195,18 +211,10 @@
 
 static int DedicatedVideoMainLoop(void)
 {
-#ifndef WIN32
-	struct timeval tim;
-#endif
 	uint32 next_tick;
 	uint32 cur_ticks;
 
-#ifdef WIN32
-	next_tick = GetTickCount() + 30;
-#else
-	gettimeofday(&tim, NULL);
-	next_tick = (tim.tv_usec / 1000) + 30 + (tim.tv_sec * 1000);
-#endif
+	next_tick = GetTime() + 30;
 
 	/* Signal handlers */
 #ifdef UNIX
@@ -254,12 +262,7 @@
 		if (!_dedicated_forks)
 			DedicatedHandleKeyInput();
 
-#ifdef WIN32
-		cur_ticks = GetTickCount();
-#else
-		gettimeofday(&tim, NULL);
-		cur_ticks = (tim.tv_usec / 1000) + (tim.tv_sec * 1000);
-#endif
+		cur_ticks = GetTime();
 
 		if (cur_ticks >= next_tick) {
 			next_tick += 30;
@@ -272,6 +275,22 @@
 	}
 }
 
+#else
+
+static const char *DedicatedVideoStart(const char * const *parm)
+{
+	DEBUG(misc, 0) ("OpenTTD compiled without network support, exiting.");
+
+	return NULL;
+}
+
+static void DedicatedVideoStop(void) {}
+static void DedicatedVideoMakeDirty(int left, int top, int width, int height) {}
+static bool DedicatedVideoChangeRes(int w, int h) { return false; }
+static void DedicatedVideoFullScreen(bool fs) {}
+static int DedicatedVideoMainLoop(void) { return ML_QUIT; }
+
+#endif /* ENABLE_NETWORK */
 
 const HalVideoDriver _dedicated_video_driver = {
 	DedicatedVideoStart,
@@ -281,31 +300,3 @@
 	DedicatedVideoChangeRes,
 	DedicatedVideoFullScreen,
 };
-
-#else
-
-static void *_dedicated_video_mem;
-
-static const char *DedicatedVideoStart(const char * const *parm)
-{
-	DEBUG(misc, 0) ("OpenTTD compiled without network support, exiting.");
-
-	return NULL;
-}
-
-static void DedicatedVideoStop(void) { free(_dedicated_video_mem); }
-static void DedicatedVideoMakeDirty(int left, int top, int width, int height) {}
-static bool DedicatedVideoChangeRes(int w, int h) { return false; }
-static void DedicatedVideoFullScreen(bool fs) {}
-static int DedicatedVideoMainLoop(void) { return ML_QUIT; }
-
-const HalVideoDriver _dedicated_video_driver = {
-	DedicatedVideoStart,
-	DedicatedVideoStop,
-	DedicatedVideoMakeDirty,
-	DedicatedVideoMainLoop,
-	DedicatedVideoChangeRes,
-	DedicatedVideoFullScreen,
-};
-
-#endif /* ENABLE_NETWORK */