Changeset - r2180:a46dc84e7817
[Not reviewed]
master
0 2 0
tron - 19 years ago 2005-07-23 18:46:17
tron@openttd.org
(svn r2694) Various smaller changes: eol-style, static, code simplification
2 files changed with 61 insertions and 86 deletions:
0 comments (0 inline, 0 general)
os2.c
Show inline comments
 
@@ -617,28 +617,12 @@ void DeterminePaths(void)
 
	mkdir(_path.personal_dir);
 
	mkdir(_path.save_dir);
 
	mkdir(_path.autosave_dir);
 
	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
 
 * is zero, we don't care about the screenlength but only about the physical length of the string
 
 * @param tb @Textbuf type to be changed
 
 * @return Return true on successfull change of Textbuf, or false otherwise
video/dedicated_v.c
Show inline comments
 
#include "stdafx.h"
 
#include "openttd.h"
 
#include "debug.h"
 
#include "functions.h"
 
#include "network.h"
 
#include "video/dedicated_v.h"
 

	
 
#ifdef ENABLE_NETWORK
 

	
 
#include "gfx.h"
 
#include "window.h"
 
#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 */
 
#	include <sys/types.h>
 
#	include <unistd.h>
 
#	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
 
#	include <sys/time.h> /* gettimeofday */
 
#	include <sys/types.h>
 
#	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)
 
{
 
	_exit_game = true;
 
	signal(sig, DedicatedSignalHandler);
 
}
 
#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);
 
		SetEvent(hEvent); // signal input waiting that the line is ready
 
	}
 
}
 

	
 
void CreateWindowsConsoleThread(void)
 
static void CreateWindowsConsoleThread(void)
 
{
 
	static char tbuffer[9];
 
	DWORD dwThreadId;
 
	/* Create event to signal when console input is ready */
 
	hEvent = CreateEvent(NULL, false, false, _strtime(tbuffer));
 
	if (hEvent == NULL)
 
@@ -78,21 +80,28 @@ void CreateWindowsConsoleThread(void)
 
	if (hThread == NULL)
 
		error("Cannot create console thread!");
 

	
 
	DEBUG(misc, 0) ("Windows console thread started...");
 
}
 

	
 
void CloseWindowsConsoleThread(void)
 
static void CloseWindowsConsoleThread(void)
 
{
 
	CloseHandle(hThread);
 
	CloseHandle(hEvent);
 
	DEBUG(misc, 0) ("Windows console thread shut down...");
 
}
 

	
 
#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];
 
	_screen.height = _cur_resolution[1];
 
	_dedicated_video_mem = malloc(_cur_resolution[0]*_cur_resolution[1]);
 

	
 
@@ -129,36 +138,43 @@ static void DedicatedVideoFullScreen(boo
 

	
 
#if defined(UNIX) || defined(__OS2__)
 
static bool InputWaiting(void)
 
{
 
	struct timeval tv;
 
	fd_set readfds;
 
	byte ret;
 

	
 
	tv.tv_sec = 0;
 
	tv.tv_usec = 1;
 

	
 
	FD_ZERO(&readfds);
 
	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;
 
}
 

	
 
static uint32 GetTime(void)
 
{
 
	struct timeval tim;
 

	
 
	if (ret > 0)
 
		return true;
 
	gettimeofday(&tim, NULL);
 
	return tim.tv_usec / 1000 + tim.tv_sec * 1000;
 
}
 

	
 
	return false;
 
}
 
#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)
 
{
 
	static char input_line[200] = "";
 

	
 
@@ -192,24 +208,16 @@ static void DedicatedHandleKeyInput(void
 

	
 
	IConsoleCmdExec(input_line); // execute command
 
}
 

	
 
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
 
	signal(SIGTERM, DedicatedSignalHandler);
 
	signal(SIGINT, DedicatedSignalHandler);
 
	signal(SIGQUIT, DedicatedSignalHandler);
 
@@ -251,61 +259,44 @@ static int DedicatedVideoMainLoop(void)
 

	
 
		if (_exit_game) return ML_QUIT;
 

	
 
		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;
 

	
 
			GameLoop();
 
			_screen.dst_ptr = _dedicated_video_mem;
 
			UpdateWindows();
 
		}
 
		CSleep(1);
 
	}
 
}
 

	
 
#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,
 
	DedicatedVideoStop,
 
	DedicatedVideoMakeDirty,
 
	DedicatedVideoMainLoop,
 
	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 */
0 comments (0 inline, 0 general)