video/dedicated_v.c
author tron
Sun, 24 Jul 2005 14:12:37 +0000
changeset 2186 db48cf29b983
parent 2181 c0ddc9695a14
child 2189 5cdc11ffeaa4
permissions -rw-r--r--
(svn r2701) Insert Id tags into all source files
2186
db48cf29b983 (svn r2701) Insert Id tags into all source files
tron
parents: 2181
diff changeset
     1
/* $Id$ */
db48cf29b983 (svn r2701) Insert Id tags into all source files
tron
parents: 2181
diff changeset
     2
543
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
     3
#include "stdafx.h"
1891
862800791170 (svn r2397) - CodeChange: rename all "ttd" files to "openttd" files.
Darkvater
parents: 1829
diff changeset
     4
#include "openttd.h"
1299
39c06aba09aa (svn r1803) Move debugging stuff into files of it's own
tron
parents: 1290
diff changeset
     5
#include "debug.h"
2163
b17b313113a0 (svn r2673) Include functions.h directly, not globally via openttd.h
tron
parents: 2159
diff changeset
     6
#include "functions.h"
543
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
     7
#include "network.h"
2180
c93b74122221 (svn r2694) Various smaller changes: eol-style, static, code simplification
tron
parents: 2177
diff changeset
     8
#include "video/dedicated_v.h"
543
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
     9
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
    10
#ifdef ENABLE_NETWORK
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
    11
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
    12
#include "gfx.h"
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
    13
#include "window.h"
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
    14
#include "command.h"
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
    15
#include "console.h"
2159
f6284cf5fab0 (svn r2669) Shuffle some more stuff around to reduce dependencies
tron
parents: 1959
diff changeset
    16
#include "variables.h"
781
4c9177888196 (svn r1248) -Add: initial OS/2 support (read docs/ReadMe_OS2.txt) (orudge)
truelight
parents: 774
diff changeset
    17
4c9177888196 (svn r1248) -Add: initial OS/2 support (read docs/ReadMe_OS2.txt) (orudge)
truelight
parents: 774
diff changeset
    18
#ifdef __OS2__
4c9177888196 (svn r1248) -Add: initial OS/2 support (read docs/ReadMe_OS2.txt) (orudge)
truelight
parents: 774
diff changeset
    19
#	include <sys/time.h> /* gettimeofday */
4c9177888196 (svn r1248) -Add: initial OS/2 support (read docs/ReadMe_OS2.txt) (orudge)
truelight
parents: 774
diff changeset
    20
#	include <sys/types.h>
4c9177888196 (svn r1248) -Add: initial OS/2 support (read docs/ReadMe_OS2.txt) (orudge)
truelight
parents: 774
diff changeset
    21
#	include <unistd.h>
4c9177888196 (svn r1248) -Add: initial OS/2 support (read docs/ReadMe_OS2.txt) (orudge)
truelight
parents: 774
diff changeset
    22
#	include <conio.h>
2181
c0ddc9695a14 (svn r2695) - Fix: OS/2 project update, add os2.h to dedicated_v.c
orudge
parents: 2180
diff changeset
    23
c0ddc9695a14 (svn r2695) - Fix: OS/2 project update, add os2.h to dedicated_v.c
orudge
parents: 2180
diff changeset
    24
#	define INCL_DOS
c0ddc9695a14 (svn r2695) - Fix: OS/2 project update, add os2.h to dedicated_v.c
orudge
parents: 2180
diff changeset
    25
#	include <os2.h>
c0ddc9695a14 (svn r2695) - Fix: OS/2 project update, add os2.h to dedicated_v.c
orudge
parents: 2180
diff changeset
    26
781
4c9177888196 (svn r1248) -Add: initial OS/2 support (read docs/ReadMe_OS2.txt) (orudge)
truelight
parents: 774
diff changeset
    27
#	define STDIN 0  /* file descriptor for standard input */
810
a1494b19bd2a (svn r1281) -Fix: the OS/2 is now finished. Fixes:
truelight
parents: 796
diff changeset
    28
2180
c93b74122221 (svn r2694) Various smaller changes: eol-style, static, code simplification
tron
parents: 2177
diff changeset
    29
/** 
c93b74122221 (svn r2694) Various smaller changes: eol-style, static, code simplification
tron
parents: 2177
diff changeset
    30
 * Switches OpenTTD to a console app at run-time, instead of a PM app
c93b74122221 (svn r2694) Various smaller changes: eol-style, static, code simplification
tron
parents: 2177
diff changeset
    31
 * Necessary to see stdout, etc. */
c93b74122221 (svn r2694) Various smaller changes: eol-style, static, code simplification
tron
parents: 2177
diff changeset
    32
static void OS2_SwitchToConsoleMode(void)
c93b74122221 (svn r2694) Various smaller changes: eol-style, static, code simplification
tron
parents: 2177
diff changeset
    33
{
c93b74122221 (svn r2694) Various smaller changes: eol-style, static, code simplification
tron
parents: 2177
diff changeset
    34
	PPIB pib;
c93b74122221 (svn r2694) Various smaller changes: eol-style, static, code simplification
tron
parents: 2177
diff changeset
    35
	PTIB tib;
c93b74122221 (svn r2694) Various smaller changes: eol-style, static, code simplification
tron
parents: 2177
diff changeset
    36
c93b74122221 (svn r2694) Various smaller changes: eol-style, static, code simplification
tron
parents: 2177
diff changeset
    37
	DosGetInfoBlocks(&tib, &pib);
c93b74122221 (svn r2694) Various smaller changes: eol-style, static, code simplification
tron
parents: 2177
diff changeset
    38
c93b74122221 (svn r2694) Various smaller changes: eol-style, static, code simplification
tron
parents: 2177
diff changeset
    39
	// Change flag from PM to VIO
c93b74122221 (svn r2694) Various smaller changes: eol-style, static, code simplification
tron
parents: 2177
diff changeset
    40
	pib->pib_ultype = 3;
c93b74122221 (svn r2694) Various smaller changes: eol-style, static, code simplification
tron
parents: 2177
diff changeset
    41
}
781
4c9177888196 (svn r1248) -Add: initial OS/2 support (read docs/ReadMe_OS2.txt) (orudge)
truelight
parents: 774
diff changeset
    42
#endif
4c9177888196 (svn r1248) -Add: initial OS/2 support (read docs/ReadMe_OS2.txt) (orudge)
truelight
parents: 774
diff changeset
    43
543
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
    44
#ifdef UNIX
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
    45
#	include <sys/time.h> /* gettimeofday */
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
    46
#	include <sys/types.h>
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
    47
#	include <unistd.h>
702
5e80e4d69057 (svn r1152) -Add: [Network] Added signal handling (GeniusDex)
truelight
parents: 626
diff changeset
    48
#	include <signal.h>
543
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
    49
#	define STDIN 0  /* file descriptor for standard input */
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
    50
702
5e80e4d69057 (svn r1152) -Add: [Network] Added signal handling (GeniusDex)
truelight
parents: 626
diff changeset
    51
/* Signal handlers */
704
e843dd369938 (svn r1154) -Add: [Network] Forked dedicated server (start openttd with -Df) (GeniusDex)
truelight
parents: 702
diff changeset
    52
static void DedicatedSignalHandler(int sig)
702
5e80e4d69057 (svn r1152) -Add: [Network] Added signal handling (GeniusDex)
truelight
parents: 626
diff changeset
    53
{
736
75bcef85daeb (svn r1188) -Fix: [Network] Fixed that CTRL+<key> could sometimes hang a dedicated
truelight
parents: 721
diff changeset
    54
	_exit_game = true;
75bcef85daeb (svn r1188) -Fix: [Network] Fixed that CTRL+<key> could sometimes hang a dedicated
truelight
parents: 721
diff changeset
    55
	signal(sig, DedicatedSignalHandler);
702
5e80e4d69057 (svn r1152) -Add: [Network] Added signal handling (GeniusDex)
truelight
parents: 626
diff changeset
    56
}
5e80e4d69057 (svn r1152) -Add: [Network] Added signal handling (GeniusDex)
truelight
parents: 626
diff changeset
    57
#endif
5e80e4d69057 (svn r1152) -Add: [Network] Added signal handling (GeniusDex)
truelight
parents: 626
diff changeset
    58
1046
f1d46abf7d35 (svn r1547) -Feature: windows dedicated (if anyone would run that, but ok), is now functioning correctly. There is no other way but to create a new thread, but that's only MS braindeadness
darkvater
parents: 915
diff changeset
    59
#ifdef WIN32
2180
c93b74122221 (svn r2694) Various smaller changes: eol-style, static, code simplification
tron
parents: 2177
diff changeset
    60
#include <windows.h> /* GetTickCount */
c93b74122221 (svn r2694) Various smaller changes: eol-style, static, code simplification
tron
parents: 2177
diff changeset
    61
#include <conio.h>
1114
74e602e41692 (svn r1615) -Fix: [1107350] console ignoring return character occasionally. For everyone that is running 2 dedicated servers on 1 windows machine, console input is now correct (event was the same so it was random which console received the input)
darkvater
parents: 1109
diff changeset
    62
#include <time.h>
2180
c93b74122221 (svn r2694) Various smaller changes: eol-style, static, code simplification
tron
parents: 2177
diff changeset
    63
static HANDLE hEvent;
1046
f1d46abf7d35 (svn r1547) -Feature: windows dedicated (if anyone would run that, but ok), is now functioning correctly. There is no other way but to create a new thread, but that's only MS braindeadness
darkvater
parents: 915
diff changeset
    64
static HANDLE hThread; // Thread to close
f1d46abf7d35 (svn r1547) -Feature: windows dedicated (if anyone would run that, but ok), is now functioning correctly. There is no other way but to create a new thread, but that's only MS braindeadness
darkvater
parents: 915
diff changeset
    65
static char _win_console_thread_buffer[200];
f1d46abf7d35 (svn r1547) -Feature: windows dedicated (if anyone would run that, but ok), is now functioning correctly. There is no other way but to create a new thread, but that's only MS braindeadness
darkvater
parents: 915
diff changeset
    66
f1d46abf7d35 (svn r1547) -Feature: windows dedicated (if anyone would run that, but ok), is now functioning correctly. There is no other way but to create a new thread, but that's only MS braindeadness
darkvater
parents: 915
diff changeset
    67
/* Windows Console thread. Just loop and signal when input has been received */
2180
c93b74122221 (svn r2694) Various smaller changes: eol-style, static, code simplification
tron
parents: 2177
diff changeset
    68
static void WINAPI CheckForConsoleInput(void)
1046
f1d46abf7d35 (svn r1547) -Feature: windows dedicated (if anyone would run that, but ok), is now functioning correctly. There is no other way but to create a new thread, but that's only MS braindeadness
darkvater
parents: 915
diff changeset
    69
{
f1d46abf7d35 (svn r1547) -Feature: windows dedicated (if anyone would run that, but ok), is now functioning correctly. There is no other way but to create a new thread, but that's only MS braindeadness
darkvater
parents: 915
diff changeset
    70
	while (true) {
f1d46abf7d35 (svn r1547) -Feature: windows dedicated (if anyone would run that, but ok), is now functioning correctly. There is no other way but to create a new thread, but that's only MS braindeadness
darkvater
parents: 915
diff changeset
    71
		fgets(_win_console_thread_buffer, lengthof(_win_console_thread_buffer), stdin);
f1d46abf7d35 (svn r1547) -Feature: windows dedicated (if anyone would run that, but ok), is now functioning correctly. There is no other way but to create a new thread, but that's only MS braindeadness
darkvater
parents: 915
diff changeset
    72
		SetEvent(hEvent); // signal input waiting that the line is ready
f1d46abf7d35 (svn r1547) -Feature: windows dedicated (if anyone would run that, but ok), is now functioning correctly. There is no other way but to create a new thread, but that's only MS braindeadness
darkvater
parents: 915
diff changeset
    73
	}
f1d46abf7d35 (svn r1547) -Feature: windows dedicated (if anyone would run that, but ok), is now functioning correctly. There is no other way but to create a new thread, but that's only MS braindeadness
darkvater
parents: 915
diff changeset
    74
}
f1d46abf7d35 (svn r1547) -Feature: windows dedicated (if anyone would run that, but ok), is now functioning correctly. There is no other way but to create a new thread, but that's only MS braindeadness
darkvater
parents: 915
diff changeset
    75
2180
c93b74122221 (svn r2694) Various smaller changes: eol-style, static, code simplification
tron
parents: 2177
diff changeset
    76
static void CreateWindowsConsoleThread(void)
1046
f1d46abf7d35 (svn r1547) -Feature: windows dedicated (if anyone would run that, but ok), is now functioning correctly. There is no other way but to create a new thread, but that's only MS braindeadness
darkvater
parents: 915
diff changeset
    77
{
1114
74e602e41692 (svn r1615) -Fix: [1107350] console ignoring return character occasionally. For everyone that is running 2 dedicated servers on 1 windows machine, console input is now correct (event was the same so it was random which console received the input)
darkvater
parents: 1109
diff changeset
    78
	static char tbuffer[9];
1762
2441d8946237 (svn r2266) - Feature: it is now possible to start a dedicated server on Win98/95, for the few sadistic geeks that really want to do this (thanks for testing Hackykid). Also fix up another glitch in console output
Darkvater
parents: 1626
diff changeset
    79
	DWORD dwThreadId;
1046
f1d46abf7d35 (svn r1547) -Feature: windows dedicated (if anyone would run that, but ok), is now functioning correctly. There is no other way but to create a new thread, but that's only MS braindeadness
darkvater
parents: 915
diff changeset
    80
	/* Create event to signal when console input is ready */
1114
74e602e41692 (svn r1615) -Fix: [1107350] console ignoring return character occasionally. For everyone that is running 2 dedicated servers on 1 windows machine, console input is now correct (event was the same so it was random which console received the input)
darkvater
parents: 1109
diff changeset
    81
	hEvent = CreateEvent(NULL, false, false, _strtime(tbuffer));
74e602e41692 (svn r1615) -Fix: [1107350] console ignoring return character occasionally. For everyone that is running 2 dedicated servers on 1 windows machine, console input is now correct (event was the same so it was random which console received the input)
darkvater
parents: 1109
diff changeset
    82
	if (hEvent == NULL)
74e602e41692 (svn r1615) -Fix: [1107350] console ignoring return character occasionally. For everyone that is running 2 dedicated servers on 1 windows machine, console input is now correct (event was the same so it was random which console received the input)
darkvater
parents: 1109
diff changeset
    83
		error("Cannot create console event!");
1046
f1d46abf7d35 (svn r1547) -Feature: windows dedicated (if anyone would run that, but ok), is now functioning correctly. There is no other way but to create a new thread, but that's only MS braindeadness
darkvater
parents: 915
diff changeset
    84
1762
2441d8946237 (svn r2266) - Feature: it is now possible to start a dedicated server on Win98/95, for the few sadistic geeks that really want to do this (thanks for testing Hackykid). Also fix up another glitch in console output
Darkvater
parents: 1626
diff changeset
    85
	hThread = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)CheckForConsoleInput, NULL, 0, &dwThreadId);
1046
f1d46abf7d35 (svn r1547) -Feature: windows dedicated (if anyone would run that, but ok), is now functioning correctly. There is no other way but to create a new thread, but that's only MS braindeadness
darkvater
parents: 915
diff changeset
    86
	if (hThread == NULL)
f1d46abf7d35 (svn r1547) -Feature: windows dedicated (if anyone would run that, but ok), is now functioning correctly. There is no other way but to create a new thread, but that's only MS braindeadness
darkvater
parents: 915
diff changeset
    87
		error("Cannot create console thread!");
f1d46abf7d35 (svn r1547) -Feature: windows dedicated (if anyone would run that, but ok), is now functioning correctly. There is no other way but to create a new thread, but that's only MS braindeadness
darkvater
parents: 915
diff changeset
    88
f1d46abf7d35 (svn r1547) -Feature: windows dedicated (if anyone would run that, but ok), is now functioning correctly. There is no other way but to create a new thread, but that's only MS braindeadness
darkvater
parents: 915
diff changeset
    89
	DEBUG(misc, 0) ("Windows console thread started...");
f1d46abf7d35 (svn r1547) -Feature: windows dedicated (if anyone would run that, but ok), is now functioning correctly. There is no other way but to create a new thread, but that's only MS braindeadness
darkvater
parents: 915
diff changeset
    90
}
f1d46abf7d35 (svn r1547) -Feature: windows dedicated (if anyone would run that, but ok), is now functioning correctly. There is no other way but to create a new thread, but that's only MS braindeadness
darkvater
parents: 915
diff changeset
    91
2180
c93b74122221 (svn r2694) Various smaller changes: eol-style, static, code simplification
tron
parents: 2177
diff changeset
    92
static void CloseWindowsConsoleThread(void)
1046
f1d46abf7d35 (svn r1547) -Feature: windows dedicated (if anyone would run that, but ok), is now functioning correctly. There is no other way but to create a new thread, but that's only MS braindeadness
darkvater
parents: 915
diff changeset
    93
{
f1d46abf7d35 (svn r1547) -Feature: windows dedicated (if anyone would run that, but ok), is now functioning correctly. There is no other way but to create a new thread, but that's only MS braindeadness
darkvater
parents: 915
diff changeset
    94
	CloseHandle(hThread);
1114
74e602e41692 (svn r1615) -Fix: [1107350] console ignoring return character occasionally. For everyone that is running 2 dedicated servers on 1 windows machine, console input is now correct (event was the same so it was random which console received the input)
darkvater
parents: 1109
diff changeset
    95
	CloseHandle(hEvent);
1046
f1d46abf7d35 (svn r1547) -Feature: windows dedicated (if anyone would run that, but ok), is now functioning correctly. There is no other way but to create a new thread, but that's only MS braindeadness
darkvater
parents: 915
diff changeset
    96
	DEBUG(misc, 0) ("Windows console thread shut down...");
f1d46abf7d35 (svn r1547) -Feature: windows dedicated (if anyone would run that, but ok), is now functioning correctly. There is no other way but to create a new thread, but that's only MS braindeadness
darkvater
parents: 915
diff changeset
    97
}
f1d46abf7d35 (svn r1547) -Feature: windows dedicated (if anyone would run that, but ok), is now functioning correctly. There is no other way but to create a new thread, but that's only MS braindeadness
darkvater
parents: 915
diff changeset
    98
f1d46abf7d35 (svn r1547) -Feature: windows dedicated (if anyone would run that, but ok), is now functioning correctly. There is no other way but to create a new thread, but that's only MS braindeadness
darkvater
parents: 915
diff changeset
    99
#endif
f1d46abf7d35 (svn r1547) -Feature: windows dedicated (if anyone would run that, but ok), is now functioning correctly. There is no other way but to create a new thread, but that's only MS braindeadness
darkvater
parents: 915
diff changeset
   100
2180
c93b74122221 (svn r2694) Various smaller changes: eol-style, static, code simplification
tron
parents: 2177
diff changeset
   101
c93b74122221 (svn r2694) Various smaller changes: eol-style, static, code simplification
tron
parents: 2177
diff changeset
   102
static void *_dedicated_video_mem;
c93b74122221 (svn r2694) Various smaller changes: eol-style, static, code simplification
tron
parents: 2177
diff changeset
   103
c93b74122221 (svn r2694) Various smaller changes: eol-style, static, code simplification
tron
parents: 2177
diff changeset
   104
extern bool SafeSaveOrLoad(const char *filename, int mode, int newgm);
c93b74122221 (svn r2694) Various smaller changes: eol-style, static, code simplification
tron
parents: 2177
diff changeset
   105
extern void SwitchMode(int new_mode);
c93b74122221 (svn r2694) Various smaller changes: eol-style, static, code simplification
tron
parents: 2177
diff changeset
   106
c93b74122221 (svn r2694) Various smaller changes: eol-style, static, code simplification
tron
parents: 2177
diff changeset
   107
1301
bf64ba5b6774 (svn r1805) Teach the driver layer a few things about const correctness
tron
parents: 1299
diff changeset
   108
static const char *DedicatedVideoStart(const char * const *parm)
bf64ba5b6774 (svn r1805) Teach the driver layer a few things about const correctness
tron
parents: 1299
diff changeset
   109
{
543
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   110
	_screen.width = _screen.pitch = _cur_resolution[0];
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   111
	_screen.height = _cur_resolution[1];
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   112
	_dedicated_video_mem = malloc(_cur_resolution[0]*_cur_resolution[1]);
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   113
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   114
	_debug_net_level = 6;
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   115
	_debug_misc_level = 0;
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   116
626
35294912464a (svn r1056) -Fix: [Network] Give the dedicated-server always a console in windows (sign_de)
truelight
parents: 543
diff changeset
   117
#ifdef WIN32
35294912464a (svn r1056) -Fix: [Network] Give the dedicated-server always a console in windows (sign_de)
truelight
parents: 543
diff changeset
   118
	// For win32 we need to allocate an console (debug mode does the same)
35294912464a (svn r1056) -Fix: [Network] Give the dedicated-server always a console in windows (sign_de)
truelight
parents: 543
diff changeset
   119
	CreateConsole();
1046
f1d46abf7d35 (svn r1547) -Feature: windows dedicated (if anyone would run that, but ok), is now functioning correctly. There is no other way but to create a new thread, but that's only MS braindeadness
darkvater
parents: 915
diff changeset
   120
	CreateWindowsConsoleThread();
626
35294912464a (svn r1056) -Fix: [Network] Give the dedicated-server always a console in windows (sign_de)
truelight
parents: 543
diff changeset
   121
	SetConsoleTitle("OpenTTD Dedicated Server");
35294912464a (svn r1056) -Fix: [Network] Give the dedicated-server always a console in windows (sign_de)
truelight
parents: 543
diff changeset
   122
#endif
35294912464a (svn r1056) -Fix: [Network] Give the dedicated-server always a console in windows (sign_de)
truelight
parents: 543
diff changeset
   123
810
a1494b19bd2a (svn r1281) -Fix: the OS/2 is now finished. Fixes:
truelight
parents: 796
diff changeset
   124
#ifdef __OS2__
a1494b19bd2a (svn r1281) -Fix: the OS/2 is now finished. Fixes:
truelight
parents: 796
diff changeset
   125
	// For OS/2 we also need to switch to console mode instead of PM mode
a1494b19bd2a (svn r1281) -Fix: the OS/2 is now finished. Fixes:
truelight
parents: 796
diff changeset
   126
	OS2_SwitchToConsoleMode();
a1494b19bd2a (svn r1281) -Fix: the OS/2 is now finished. Fixes:
truelight
parents: 796
diff changeset
   127
#endif
a1494b19bd2a (svn r1281) -Fix: the OS/2 is now finished. Fixes:
truelight
parents: 796
diff changeset
   128
543
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   129
	DEBUG(misc,0)("Loading dedicated server...");
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   130
	return NULL;
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   131
}
1046
f1d46abf7d35 (svn r1547) -Feature: windows dedicated (if anyone would run that, but ok), is now functioning correctly. There is no other way but to create a new thread, but that's only MS braindeadness
darkvater
parents: 915
diff changeset
   132
f1d46abf7d35 (svn r1547) -Feature: windows dedicated (if anyone would run that, but ok), is now functioning correctly. There is no other way but to create a new thread, but that's only MS braindeadness
darkvater
parents: 915
diff changeset
   133
static void DedicatedVideoStop(void)
f1d46abf7d35 (svn r1547) -Feature: windows dedicated (if anyone would run that, but ok), is now functioning correctly. There is no other way but to create a new thread, but that's only MS braindeadness
darkvater
parents: 915
diff changeset
   134
{
f1d46abf7d35 (svn r1547) -Feature: windows dedicated (if anyone would run that, but ok), is now functioning correctly. There is no other way but to create a new thread, but that's only MS braindeadness
darkvater
parents: 915
diff changeset
   135
#ifdef WIN32
f1d46abf7d35 (svn r1547) -Feature: windows dedicated (if anyone would run that, but ok), is now functioning correctly. There is no other way but to create a new thread, but that's only MS braindeadness
darkvater
parents: 915
diff changeset
   136
	CloseWindowsConsoleThread();
f1d46abf7d35 (svn r1547) -Feature: windows dedicated (if anyone would run that, but ok), is now functioning correctly. There is no other way but to create a new thread, but that's only MS braindeadness
darkvater
parents: 915
diff changeset
   137
#endif
1109
ecb98f43ba2c (svn r1610) Remove trailing whitespace (last time ever, i hope)
tron
parents: 1090
diff changeset
   138
	free(_dedicated_video_mem);
1046
f1d46abf7d35 (svn r1547) -Feature: windows dedicated (if anyone would run that, but ok), is now functioning correctly. There is no other way but to create a new thread, but that's only MS braindeadness
darkvater
parents: 915
diff changeset
   139
}
f1d46abf7d35 (svn r1547) -Feature: windows dedicated (if anyone would run that, but ok), is now functioning correctly. There is no other way but to create a new thread, but that's only MS braindeadness
darkvater
parents: 915
diff changeset
   140
543
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   141
static void DedicatedVideoMakeDirty(int left, int top, int width, int height) {}
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   142
static bool DedicatedVideoChangeRes(int w, int h) { return false; }
1829
e90fe433fa7d (svn r2334) - Fix (regression): moved togglefullscreen into the video-driver, now windows works, dedicated works and sdl works. Also reverted the change to the makefile.
Darkvater
parents: 1794
diff changeset
   143
static void DedicatedVideoFullScreen(bool fs) {}
543
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   144
1090
5d378bd5fcbc (svn r1591) Make dedicated servers on OS/2 check for input the UNIX way
tron
parents: 1046
diff changeset
   145
#if defined(UNIX) || defined(__OS2__)
1046
f1d46abf7d35 (svn r1547) -Feature: windows dedicated (if anyone would run that, but ok), is now functioning correctly. There is no other way but to create a new thread, but that's only MS braindeadness
darkvater
parents: 915
diff changeset
   146
static bool InputWaiting(void)
543
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   147
{
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   148
	struct timeval tv;
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   149
	fd_set readfds;
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   150
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   151
	tv.tv_sec = 0;
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   152
	tv.tv_usec = 1;
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   153
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   154
	FD_ZERO(&readfds);
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   155
	FD_SET(STDIN, &readfds);
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   156
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   157
	/* don't care about writefds and exceptfds: */
2180
c93b74122221 (svn r2694) Various smaller changes: eol-style, static, code simplification
tron
parents: 2177
diff changeset
   158
	return select(STDIN + 1, &readfds, NULL, NULL, &tv) > 0;
c93b74122221 (svn r2694) Various smaller changes: eol-style, static, code simplification
tron
parents: 2177
diff changeset
   159
}
543
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   160
2180
c93b74122221 (svn r2694) Various smaller changes: eol-style, static, code simplification
tron
parents: 2177
diff changeset
   161
static uint32 GetTime(void)
c93b74122221 (svn r2694) Various smaller changes: eol-style, static, code simplification
tron
parents: 2177
diff changeset
   162
{
c93b74122221 (svn r2694) Various smaller changes: eol-style, static, code simplification
tron
parents: 2177
diff changeset
   163
	struct timeval tim;
1046
f1d46abf7d35 (svn r1547) -Feature: windows dedicated (if anyone would run that, but ok), is now functioning correctly. There is no other way but to create a new thread, but that's only MS braindeadness
darkvater
parents: 915
diff changeset
   164
2180
c93b74122221 (svn r2694) Various smaller changes: eol-style, static, code simplification
tron
parents: 2177
diff changeset
   165
	gettimeofday(&tim, NULL);
c93b74122221 (svn r2694) Various smaller changes: eol-style, static, code simplification
tron
parents: 2177
diff changeset
   166
	return tim.tv_usec / 1000 + tim.tv_sec * 1000;
543
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   167
}
2180
c93b74122221 (svn r2694) Various smaller changes: eol-style, static, code simplification
tron
parents: 2177
diff changeset
   168
543
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   169
#else
2180
c93b74122221 (svn r2694) Various smaller changes: eol-style, static, code simplification
tron
parents: 2177
diff changeset
   170
1046
f1d46abf7d35 (svn r1547) -Feature: windows dedicated (if anyone would run that, but ok), is now functioning correctly. There is no other way but to create a new thread, but that's only MS braindeadness
darkvater
parents: 915
diff changeset
   171
static bool InputWaiting(void)
543
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   172
{
2180
c93b74122221 (svn r2694) Various smaller changes: eol-style, static, code simplification
tron
parents: 2177
diff changeset
   173
	return WaitForSingleObject(hEvent, 1) == WAIT_OBJECT_0;
c93b74122221 (svn r2694) Various smaller changes: eol-style, static, code simplification
tron
parents: 2177
diff changeset
   174
}
1109
ecb98f43ba2c (svn r1610) Remove trailing whitespace (last time ever, i hope)
tron
parents: 1090
diff changeset
   175
2180
c93b74122221 (svn r2694) Various smaller changes: eol-style, static, code simplification
tron
parents: 2177
diff changeset
   176
static uint32 GetTime(void)
c93b74122221 (svn r2694) Various smaller changes: eol-style, static, code simplification
tron
parents: 2177
diff changeset
   177
{
c93b74122221 (svn r2694) Various smaller changes: eol-style, static, code simplification
tron
parents: 2177
diff changeset
   178
	return GetTickCount();
543
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   179
}
2180
c93b74122221 (svn r2694) Various smaller changes: eol-style, static, code simplification
tron
parents: 2177
diff changeset
   180
543
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   181
#endif
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   182
1046
f1d46abf7d35 (svn r1547) -Feature: windows dedicated (if anyone would run that, but ok), is now functioning correctly. There is no other way but to create a new thread, but that's only MS braindeadness
darkvater
parents: 915
diff changeset
   183
static void DedicatedHandleKeyInput(void)
704
e843dd369938 (svn r1154) -Add: [Network] Forked dedicated server (start openttd with -Df) (GeniusDex)
truelight
parents: 702
diff changeset
   184
{
721
617a397f8b4b (svn r1173) -Fix: [Network] Console input in dedicated server for windows was not
truelight
parents: 720
diff changeset
   185
	static char input_line[200] = "";
704
e843dd369938 (svn r1154) -Add: [Network] Forked dedicated server (start openttd with -Df) (GeniusDex)
truelight
parents: 702
diff changeset
   186
1046
f1d46abf7d35 (svn r1547) -Feature: windows dedicated (if anyone would run that, but ok), is now functioning correctly. There is no other way but to create a new thread, but that's only MS braindeadness
darkvater
parents: 915
diff changeset
   187
	if (!InputWaiting())
f1d46abf7d35 (svn r1547) -Feature: windows dedicated (if anyone would run that, but ok), is now functioning correctly. There is no other way but to create a new thread, but that's only MS braindeadness
darkvater
parents: 915
diff changeset
   188
		return;
f1d46abf7d35 (svn r1547) -Feature: windows dedicated (if anyone would run that, but ok), is now functioning correctly. There is no other way but to create a new thread, but that's only MS braindeadness
darkvater
parents: 915
diff changeset
   189
f1d46abf7d35 (svn r1547) -Feature: windows dedicated (if anyone would run that, but ok), is now functioning correctly. There is no other way but to create a new thread, but that's only MS braindeadness
darkvater
parents: 915
diff changeset
   190
	if (_exit_game)
f1d46abf7d35 (svn r1547) -Feature: windows dedicated (if anyone would run that, but ok), is now functioning correctly. There is no other way but to create a new thread, but that's only MS braindeadness
darkvater
parents: 915
diff changeset
   191
		return;
f1d46abf7d35 (svn r1547) -Feature: windows dedicated (if anyone would run that, but ok), is now functioning correctly. There is no other way but to create a new thread, but that's only MS braindeadness
darkvater
parents: 915
diff changeset
   192
781
4c9177888196 (svn r1248) -Add: initial OS/2 support (read docs/ReadMe_OS2.txt) (orudge)
truelight
parents: 774
diff changeset
   193
#if defined(UNIX) || defined(__OS2__)
1046
f1d46abf7d35 (svn r1547) -Feature: windows dedicated (if anyone would run that, but ok), is now functioning correctly. There is no other way but to create a new thread, but that's only MS braindeadness
darkvater
parents: 915
diff changeset
   194
		fgets(input_line, lengthof(input_line), stdin);
f1d46abf7d35 (svn r1547) -Feature: windows dedicated (if anyone would run that, but ok), is now functioning correctly. There is no other way but to create a new thread, but that's only MS braindeadness
darkvater
parents: 915
diff changeset
   195
#else
f1d46abf7d35 (svn r1547) -Feature: windows dedicated (if anyone would run that, but ok), is now functioning correctly. There is no other way but to create a new thread, but that's only MS braindeadness
darkvater
parents: 915
diff changeset
   196
		strncpy(input_line, _win_console_thread_buffer, lengthof(input_line));
f1d46abf7d35 (svn r1547) -Feature: windows dedicated (if anyone would run that, but ok), is now functioning correctly. There is no other way but to create a new thread, but that's only MS braindeadness
darkvater
parents: 915
diff changeset
   197
#endif
736
75bcef85daeb (svn r1188) -Fix: [Network] Fixed that CTRL+<key> could sometimes hang a dedicated
truelight
parents: 721
diff changeset
   198
1046
f1d46abf7d35 (svn r1547) -Feature: windows dedicated (if anyone would run that, but ok), is now functioning correctly. There is no other way but to create a new thread, but that's only MS braindeadness
darkvater
parents: 915
diff changeset
   199
	/* XXX - strtok() does not 'forget' \n\r if it is the first character! */
f1d46abf7d35 (svn r1547) -Feature: windows dedicated (if anyone would run that, but ok), is now functioning correctly. There is no other way but to create a new thread, but that's only MS braindeadness
darkvater
parents: 915
diff changeset
   200
	strtok(input_line, "\r\n"); // Forget about the final \n (or \r)
f1d46abf7d35 (svn r1547) -Feature: windows dedicated (if anyone would run that, but ok), is now functioning correctly. There is no other way but to create a new thread, but that's only MS braindeadness
darkvater
parents: 915
diff changeset
   201
	{ /* Remove any special control characters */
f1d46abf7d35 (svn r1547) -Feature: windows dedicated (if anyone would run that, but ok), is now functioning correctly. There is no other way but to create a new thread, but that's only MS braindeadness
darkvater
parents: 915
diff changeset
   202
		uint i;
f1d46abf7d35 (svn r1547) -Feature: windows dedicated (if anyone would run that, but ok), is now functioning correctly. There is no other way but to create a new thread, but that's only MS braindeadness
darkvater
parents: 915
diff changeset
   203
		for (i = 0; i < lengthof(input_line); i++) {
f1d46abf7d35 (svn r1547) -Feature: windows dedicated (if anyone would run that, but ok), is now functioning correctly. There is no other way but to create a new thread, but that's only MS braindeadness
darkvater
parents: 915
diff changeset
   204
			if (input_line[i] == '\n' || input_line[i] == '\r') // cut missed beginning '\0'
f1d46abf7d35 (svn r1547) -Feature: windows dedicated (if anyone would run that, but ok), is now functioning correctly. There is no other way but to create a new thread, but that's only MS braindeadness
darkvater
parents: 915
diff changeset
   205
				input_line[i] = '\0';
f1d46abf7d35 (svn r1547) -Feature: windows dedicated (if anyone would run that, but ok), is now functioning correctly. There is no other way but to create a new thread, but that's only MS braindeadness
darkvater
parents: 915
diff changeset
   206
f1d46abf7d35 (svn r1547) -Feature: windows dedicated (if anyone would run that, but ok), is now functioning correctly. There is no other way but to create a new thread, but that's only MS braindeadness
darkvater
parents: 915
diff changeset
   207
			if (input_line[i] == '\0')
f1d46abf7d35 (svn r1547) -Feature: windows dedicated (if anyone would run that, but ok), is now functioning correctly. There is no other way but to create a new thread, but that's only MS braindeadness
darkvater
parents: 915
diff changeset
   208
				break;
f1d46abf7d35 (svn r1547) -Feature: windows dedicated (if anyone would run that, but ok), is now functioning correctly. There is no other way but to create a new thread, but that's only MS braindeadness
darkvater
parents: 915
diff changeset
   209
f1d46abf7d35 (svn r1547) -Feature: windows dedicated (if anyone would run that, but ok), is now functioning correctly. There is no other way but to create a new thread, but that's only MS braindeadness
darkvater
parents: 915
diff changeset
   210
			if (!IS_INT_INSIDE(input_line[i], ' ', 256))
f1d46abf7d35 (svn r1547) -Feature: windows dedicated (if anyone would run that, but ok), is now functioning correctly. There is no other way but to create a new thread, but that's only MS braindeadness
darkvater
parents: 915
diff changeset
   211
				input_line[i] = ' ';
704
e843dd369938 (svn r1154) -Add: [Network] Forked dedicated server (start openttd with -Df) (GeniusDex)
truelight
parents: 702
diff changeset
   212
		}
e843dd369938 (svn r1154) -Add: [Network] Forked dedicated server (start openttd with -Df) (GeniusDex)
truelight
parents: 702
diff changeset
   213
	}
1046
f1d46abf7d35 (svn r1547) -Feature: windows dedicated (if anyone would run that, but ok), is now functioning correctly. There is no other way but to create a new thread, but that's only MS braindeadness
darkvater
parents: 915
diff changeset
   214
f1d46abf7d35 (svn r1547) -Feature: windows dedicated (if anyone would run that, but ok), is now functioning correctly. There is no other way but to create a new thread, but that's only MS braindeadness
darkvater
parents: 915
diff changeset
   215
	IConsoleCmdExec(input_line); // execute command
704
e843dd369938 (svn r1154) -Add: [Network] Forked dedicated server (start openttd with -Df) (GeniusDex)
truelight
parents: 702
diff changeset
   216
}
e843dd369938 (svn r1154) -Add: [Network] Forked dedicated server (start openttd with -Df) (GeniusDex)
truelight
parents: 702
diff changeset
   217
1046
f1d46abf7d35 (svn r1547) -Feature: windows dedicated (if anyone would run that, but ok), is now functioning correctly. There is no other way but to create a new thread, but that's only MS braindeadness
darkvater
parents: 915
diff changeset
   218
static int DedicatedVideoMainLoop(void)
704
e843dd369938 (svn r1154) -Add: [Network] Forked dedicated server (start openttd with -Df) (GeniusDex)
truelight
parents: 702
diff changeset
   219
{
543
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   220
	uint32 next_tick;
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   221
	uint32 cur_ticks;
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   222
2180
c93b74122221 (svn r2694) Various smaller changes: eol-style, static, code simplification
tron
parents: 2177
diff changeset
   223
	next_tick = GetTime() + 30;
543
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   224
770
c2eacca29601 (svn r1236) MorphOS: added make release like in OSX (tokai)
bjarni
parents: 736
diff changeset
   225
	/* Signal handlers */
702
5e80e4d69057 (svn r1152) -Add: [Network] Added signal handling (GeniusDex)
truelight
parents: 626
diff changeset
   226
#ifdef UNIX
5e80e4d69057 (svn r1152) -Add: [Network] Added signal handling (GeniusDex)
truelight
parents: 626
diff changeset
   227
	signal(SIGTERM, DedicatedSignalHandler);
5e80e4d69057 (svn r1152) -Add: [Network] Added signal handling (GeniusDex)
truelight
parents: 626
diff changeset
   228
	signal(SIGINT, DedicatedSignalHandler);
736
75bcef85daeb (svn r1188) -Fix: [Network] Fixed that CTRL+<key> could sometimes hang a dedicated
truelight
parents: 721
diff changeset
   229
	signal(SIGQUIT, DedicatedSignalHandler);
702
5e80e4d69057 (svn r1152) -Add: [Network] Added signal handling (GeniusDex)
truelight
parents: 626
diff changeset
   230
#endif
5e80e4d69057 (svn r1152) -Add: [Network] Added signal handling (GeniusDex)
truelight
parents: 626
diff changeset
   231
543
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   232
	// Load the dedicated server stuff
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   233
	_is_network_server = true;
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   234
	_network_dedicated = true;
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   235
	_network_playas = OWNER_SPECTATOR;
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   236
	_local_player = OWNER_SPECTATOR;
1414
e7aa3a34712e (svn r1918) -Fix: [ 1101874 ] Dedicated server now accepts '-g' (load game) as param
truelight
parents: 1406
diff changeset
   237
e7aa3a34712e (svn r1918) -Fix: [ 1101874 ] Dedicated server now accepts '-g' (load game) as param
truelight
parents: 1406
diff changeset
   238
	/* If SwitchMode is SM_LOAD, it means that the user used the '-g' options */
e7aa3a34712e (svn r1918) -Fix: [ 1101874 ] Dedicated server now accepts '-g' (load game) as param
truelight
parents: 1406
diff changeset
   239
	if (_switch_mode != SM_LOAD) {
e7aa3a34712e (svn r1918) -Fix: [ 1101874 ] Dedicated server now accepts '-g' (load game) as param
truelight
parents: 1406
diff changeset
   240
		_switch_mode = SM_NONE;
1794
24b4239f2090 (svn r2298) - CodeChange: removed CmdAbuses: CmdSetTownNameType(), CmdStartNewGame(), CmdCreateScenario(), CmdSetNewLandscapeType() and CmdGenRandomNewGame().
Darkvater
parents: 1762
diff changeset
   241
		GenRandomNewGame(Random(), InteractiveRandom());
1414
e7aa3a34712e (svn r1918) -Fix: [ 1101874 ] Dedicated server now accepts '-g' (load game) as param
truelight
parents: 1406
diff changeset
   242
	} else {
e7aa3a34712e (svn r1918) -Fix: [ 1101874 ] Dedicated server now accepts '-g' (load game) as param
truelight
parents: 1406
diff changeset
   243
		_switch_mode = SM_NONE;
e7aa3a34712e (svn r1918) -Fix: [ 1101874 ] Dedicated server now accepts '-g' (load game) as param
truelight
parents: 1406
diff changeset
   244
		/* First we need to test if the savegame can be loaded, else we will end up playing the
e7aa3a34712e (svn r1918) -Fix: [ 1101874 ] Dedicated server now accepts '-g' (load game) as param
truelight
parents: 1406
diff changeset
   245
		 *  intro game... */
e7aa3a34712e (svn r1918) -Fix: [ 1101874 ] Dedicated server now accepts '-g' (load game) as param
truelight
parents: 1406
diff changeset
   246
		if (!SafeSaveOrLoad(_file_to_saveload.name, _file_to_saveload.mode, GM_NORMAL)) {
e7aa3a34712e (svn r1918) -Fix: [ 1101874 ] Dedicated server now accepts '-g' (load game) as param
truelight
parents: 1406
diff changeset
   247
			/* Loading failed, pop out.. */
1626
b0cda32b478a (svn r2130) Various spelling fixes in messages.
pasky
parents: 1614
diff changeset
   248
			DEBUG(net, 0)("Loading requested map failed. Aborting.");
1414
e7aa3a34712e (svn r1918) -Fix: [ 1101874 ] Dedicated server now accepts '-g' (load game) as param
truelight
parents: 1406
diff changeset
   249
			_networking = false;
e7aa3a34712e (svn r1918) -Fix: [ 1101874 ] Dedicated server now accepts '-g' (load game) as param
truelight
parents: 1406
diff changeset
   250
		} else {
e7aa3a34712e (svn r1918) -Fix: [ 1101874 ] Dedicated server now accepts '-g' (load game) as param
truelight
parents: 1406
diff changeset
   251
			/* We can load this game, so go ahead */
e7aa3a34712e (svn r1918) -Fix: [ 1101874 ] Dedicated server now accepts '-g' (load game) as param
truelight
parents: 1406
diff changeset
   252
			SwitchMode(SM_LOAD);
e7aa3a34712e (svn r1918) -Fix: [ 1101874 ] Dedicated server now accepts '-g' (load game) as param
truelight
parents: 1406
diff changeset
   253
		}
e7aa3a34712e (svn r1918) -Fix: [ 1101874 ] Dedicated server now accepts '-g' (load game) as param
truelight
parents: 1406
diff changeset
   254
	}
e7aa3a34712e (svn r1918) -Fix: [ 1101874 ] Dedicated server now accepts '-g' (load game) as param
truelight
parents: 1406
diff changeset
   255
543
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   256
	// Done loading, start game!
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   257
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   258
	if (!_networking) {
1626
b0cda32b478a (svn r2130) Various spelling fixes in messages.
pasky
parents: 1614
diff changeset
   259
		DEBUG(net, 1)("Dedicated server could not be launched. Aborting.");
543
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   260
		return ML_QUIT;
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   261
	}
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   262
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   263
	while (true) {
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   264
		InteractiveRandom(); // randomness
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   265
702
5e80e4d69057 (svn r1152) -Add: [Network] Added signal handling (GeniusDex)
truelight
parents: 626
diff changeset
   266
		if (_exit_game) return ML_QUIT;
5e80e4d69057 (svn r1152) -Add: [Network] Added signal handling (GeniusDex)
truelight
parents: 626
diff changeset
   267
704
e843dd369938 (svn r1154) -Add: [Network] Forked dedicated server (start openttd with -Df) (GeniusDex)
truelight
parents: 702
diff changeset
   268
		if (!_dedicated_forks)
e843dd369938 (svn r1154) -Add: [Network] Forked dedicated server (start openttd with -Df) (GeniusDex)
truelight
parents: 702
diff changeset
   269
			DedicatedHandleKeyInput();
543
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   270
2180
c93b74122221 (svn r2694) Various smaller changes: eol-style, static, code simplification
tron
parents: 2177
diff changeset
   271
		cur_ticks = GetTime();
543
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   272
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   273
		if (cur_ticks >= next_tick) {
1543
713bc7d94d4b (svn r2047) -Fix: never commit your own personal changes... :(
truelight
parents: 1542
diff changeset
   274
			next_tick += 30;
543
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   275
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   276
			GameLoop();
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   277
			_screen.dst_ptr = _dedicated_video_mem;
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   278
			UpdateWindows();
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   279
		}
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   280
		CSleep(1);
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   281
	}
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   282
}
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   283
2180
c93b74122221 (svn r2694) Various smaller changes: eol-style, static, code simplification
tron
parents: 2177
diff changeset
   284
#else
c93b74122221 (svn r2694) Various smaller changes: eol-style, static, code simplification
tron
parents: 2177
diff changeset
   285
c93b74122221 (svn r2694) Various smaller changes: eol-style, static, code simplification
tron
parents: 2177
diff changeset
   286
static const char *DedicatedVideoStart(const char * const *parm)
c93b74122221 (svn r2694) Various smaller changes: eol-style, static, code simplification
tron
parents: 2177
diff changeset
   287
{
c93b74122221 (svn r2694) Various smaller changes: eol-style, static, code simplification
tron
parents: 2177
diff changeset
   288
	DEBUG(misc, 0) ("OpenTTD compiled without network support, exiting.");
c93b74122221 (svn r2694) Various smaller changes: eol-style, static, code simplification
tron
parents: 2177
diff changeset
   289
c93b74122221 (svn r2694) Various smaller changes: eol-style, static, code simplification
tron
parents: 2177
diff changeset
   290
	return NULL;
c93b74122221 (svn r2694) Various smaller changes: eol-style, static, code simplification
tron
parents: 2177
diff changeset
   291
}
c93b74122221 (svn r2694) Various smaller changes: eol-style, static, code simplification
tron
parents: 2177
diff changeset
   292
c93b74122221 (svn r2694) Various smaller changes: eol-style, static, code simplification
tron
parents: 2177
diff changeset
   293
static void DedicatedVideoStop(void) {}
c93b74122221 (svn r2694) Various smaller changes: eol-style, static, code simplification
tron
parents: 2177
diff changeset
   294
static void DedicatedVideoMakeDirty(int left, int top, int width, int height) {}
c93b74122221 (svn r2694) Various smaller changes: eol-style, static, code simplification
tron
parents: 2177
diff changeset
   295
static bool DedicatedVideoChangeRes(int w, int h) { return false; }
c93b74122221 (svn r2694) Various smaller changes: eol-style, static, code simplification
tron
parents: 2177
diff changeset
   296
static void DedicatedVideoFullScreen(bool fs) {}
c93b74122221 (svn r2694) Various smaller changes: eol-style, static, code simplification
tron
parents: 2177
diff changeset
   297
static int DedicatedVideoMainLoop(void) { return ML_QUIT; }
c93b74122221 (svn r2694) Various smaller changes: eol-style, static, code simplification
tron
parents: 2177
diff changeset
   298
c93b74122221 (svn r2694) Various smaller changes: eol-style, static, code simplification
tron
parents: 2177
diff changeset
   299
#endif /* ENABLE_NETWORK */
543
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   300
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   301
const HalVideoDriver _dedicated_video_driver = {
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   302
	DedicatedVideoStart,
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   303
	DedicatedVideoStop,
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   304
	DedicatedVideoMakeDirty,
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   305
	DedicatedVideoMainLoop,
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   306
	DedicatedVideoChangeRes,
1829
e90fe433fa7d (svn r2334) - Fix (regression): moved togglefullscreen into the video-driver, now windows works, dedicated works and sdl works. Also reverted the change to the makefile.
Darkvater
parents: 1794
diff changeset
   307
	DedicatedVideoFullScreen,
543
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   308
};