1
0
Fork 0

(svn r2694) Various smaller changes: eol-style, static, code simplification

release/0.4.5
tron 2005-07-23 18:46:17 +00:00
parent 3ecbbf3baf
commit 86a76d735e
2 changed files with 50 additions and 75 deletions

16
os2.c
View File

@ -620,22 +620,6 @@ void DeterminePaths(void)
mkdir(_path.scenario_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 * 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 * and append this up to the maximum length (either absolute or screenlength). If maxlength

View File

@ -3,6 +3,7 @@
#include "debug.h" #include "debug.h"
#include "functions.h" #include "functions.h"
#include "network.h" #include "network.h"
#include "video/dedicated_v.h"
#ifdef ENABLE_NETWORK #ifdef ENABLE_NETWORK
@ -11,12 +12,6 @@
#include "command.h" #include "command.h"
#include "console.h" #include "console.h"
#include "variables.h" #include "variables.h"
#include "video/dedicated_v.h"
#ifdef WIN32
# include <windows.h> /* GetTickCount */
# include <conio.h>
#endif
#ifdef __OS2__ #ifdef __OS2__
# include <sys/time.h> /* gettimeofday */ # include <sys/time.h> /* gettimeofday */
@ -25,7 +20,19 @@
# include <conio.h> # include <conio.h>
# define STDIN 0 /* file descriptor for standard input */ # 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 #endif
#ifdef UNIX #ifdef UNIX
@ -34,14 +41,7 @@
# include <unistd.h> # include <unistd.h>
# include <signal.h> # include <signal.h>
# define STDIN 0 /* file descriptor for standard input */ # 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 */ /* Signal handlers */
static void DedicatedSignalHandler(int sig) static void DedicatedSignalHandler(int sig)
{ {
@ -51,13 +51,15 @@ static void DedicatedSignalHandler(int sig)
#endif #endif
#ifdef WIN32 #ifdef WIN32
#include <windows.h> /* GetTickCount */
#include <conio.h>
#include <time.h> #include <time.h>
HANDLE hEvent; static HANDLE hEvent;
static HANDLE hThread; // Thread to close static HANDLE hThread; // Thread to close
static char _win_console_thread_buffer[200]; static char _win_console_thread_buffer[200];
/* Windows Console thread. Just loop and signal when input has been received */ /* Windows Console thread. Just loop and signal when input has been received */
void WINAPI CheckForConsoleInput(void) static void WINAPI CheckForConsoleInput(void)
{ {
while (true) { while (true) {
fgets(_win_console_thread_buffer, lengthof(_win_console_thread_buffer), stdin); fgets(_win_console_thread_buffer, lengthof(_win_console_thread_buffer), stdin);
@ -65,7 +67,7 @@ void WINAPI CheckForConsoleInput(void)
} }
} }
void CreateWindowsConsoleThread(void) static void CreateWindowsConsoleThread(void)
{ {
static char tbuffer[9]; static char tbuffer[9];
DWORD dwThreadId; DWORD dwThreadId;
@ -81,7 +83,7 @@ void CreateWindowsConsoleThread(void)
DEBUG(misc, 0) ("Windows console thread started..."); DEBUG(misc, 0) ("Windows console thread started...");
} }
void CloseWindowsConsoleThread(void) static void CloseWindowsConsoleThread(void)
{ {
CloseHandle(hThread); CloseHandle(hThread);
CloseHandle(hEvent); CloseHandle(hEvent);
@ -90,6 +92,13 @@ void CloseWindowsConsoleThread(void)
#endif #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) static const char *DedicatedVideoStart(const char * const *parm)
{ {
_screen.width = _screen.pitch = _cur_resolution[0]; _screen.width = _screen.pitch = _cur_resolution[0];
@ -132,7 +141,6 @@ static bool InputWaiting(void)
{ {
struct timeval tv; struct timeval tv;
fd_set readfds; fd_set readfds;
byte ret;
tv.tv_sec = 0; tv.tv_sec = 0;
tv.tv_usec = 1; tv.tv_usec = 1;
@ -141,21 +149,29 @@ static bool InputWaiting(void)
FD_SET(STDIN, &readfds); FD_SET(STDIN, &readfds);
/* don't care about writefds and exceptfds: */ /* 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;
return false;
} }
static uint32 GetTime(void)
{
struct timeval tim;
gettimeofday(&tim, NULL);
return tim.tv_usec / 1000 + tim.tv_sec * 1000;
}
#else #else
static bool InputWaiting(void) static bool InputWaiting(void)
{ {
if (WaitForSingleObject(hEvent, 1) == WAIT_OBJECT_0) return WaitForSingleObject(hEvent, 1) == WAIT_OBJECT_0;
return true;
return false;
} }
static uint32 GetTime(void)
{
return GetTickCount();
}
#endif #endif
static void DedicatedHandleKeyInput(void) static void DedicatedHandleKeyInput(void)
@ -195,18 +211,10 @@ static void DedicatedHandleKeyInput(void)
static int DedicatedVideoMainLoop(void) static int DedicatedVideoMainLoop(void)
{ {
#ifndef WIN32
struct timeval tim;
#endif
uint32 next_tick; uint32 next_tick;
uint32 cur_ticks; uint32 cur_ticks;
#ifdef WIN32 next_tick = GetTime() + 30;
next_tick = GetTickCount() + 30;
#else
gettimeofday(&tim, NULL);
next_tick = (tim.tv_usec / 1000) + 30 + (tim.tv_sec * 1000);
#endif
/* Signal handlers */ /* Signal handlers */
#ifdef UNIX #ifdef UNIX
@ -254,12 +262,7 @@ static int DedicatedVideoMainLoop(void)
if (!_dedicated_forks) if (!_dedicated_forks)
DedicatedHandleKeyInput(); DedicatedHandleKeyInput();
#ifdef WIN32 cur_ticks = GetTime();
cur_ticks = GetTickCount();
#else
gettimeofday(&tim, NULL);
cur_ticks = (tim.tv_usec / 1000) + (tim.tv_sec * 1000);
#endif
if (cur_ticks >= next_tick) { if (cur_ticks >= next_tick) {
next_tick += 30; next_tick += 30;
@ -272,20 +275,8 @@ static int DedicatedVideoMainLoop(void)
} }
} }
const HalVideoDriver _dedicated_video_driver = {
DedicatedVideoStart,
DedicatedVideoStop,
DedicatedVideoMakeDirty,
DedicatedVideoMainLoop,
DedicatedVideoChangeRes,
DedicatedVideoFullScreen,
};
#else #else
static void *_dedicated_video_mem;
static const char *DedicatedVideoStart(const char * const *parm) static const char *DedicatedVideoStart(const char * const *parm)
{ {
DEBUG(misc, 0) ("OpenTTD compiled without network support, exiting."); DEBUG(misc, 0) ("OpenTTD compiled without network support, exiting.");
@ -293,12 +284,14 @@ static const char *DedicatedVideoStart(const char * const *parm)
return NULL; return NULL;
} }
static void DedicatedVideoStop(void) { free(_dedicated_video_mem); } static void DedicatedVideoStop(void) {}
static void DedicatedVideoMakeDirty(int left, int top, int width, int height) {} static void DedicatedVideoMakeDirty(int left, int top, int width, int height) {}
static bool DedicatedVideoChangeRes(int w, int h) { return false; } static bool DedicatedVideoChangeRes(int w, int h) { return false; }
static void DedicatedVideoFullScreen(bool fs) {} static void DedicatedVideoFullScreen(bool fs) {}
static int DedicatedVideoMainLoop(void) { return ML_QUIT; } static int DedicatedVideoMainLoop(void) { return ML_QUIT; }
#endif /* ENABLE_NETWORK */
const HalVideoDriver _dedicated_video_driver = { const HalVideoDriver _dedicated_video_driver = {
DedicatedVideoStart, DedicatedVideoStart,
DedicatedVideoStop, DedicatedVideoStop,
@ -307,5 +300,3 @@ const HalVideoDriver _dedicated_video_driver = {
DedicatedVideoChangeRes, DedicatedVideoChangeRes,
DedicatedVideoFullScreen, DedicatedVideoFullScreen,
}; };
#endif /* ENABLE_NETWORK */