src/video/dedicated_v.cpp
author celestar
Tue, 19 Jun 2007 07:21:01 +0000
branchgamebalance
changeset 9913 e79cd19772dd
parent 9911 0b8b245a2391
permissions -rw-r--r--
(svn r10213) [gamebalance] -Sync: r10100:10200 from trunk
2186
461a2aff3486 (svn r2701) Insert Id tags into all source files
tron
parents: 2181
diff changeset
     1
/* $Id$ */
461a2aff3486 (svn r2701) Insert Id tags into all source files
tron
parents: 2181
diff changeset
     2
2189
d240b9097139 (svn r2704) Remove . from include path again, too much trouble. Also add some #ifdefs and #includes for the Windows build
tron
parents: 2186
diff changeset
     3
#include "../stdafx.h"
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
     4
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
     5
#ifdef ENABLE_NETWORK
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
     6
2195
8960c86bf103 (svn r2710) Simplify dedicated server code a bit and don't compile it at all, if network support ist disabled
tron
parents: 2189
diff changeset
     7
#include "../openttd.h"
2189
d240b9097139 (svn r2704) Remove . from include path again, too much trouble. Also add some #ifdefs and #includes for the Windows build
tron
parents: 2186
diff changeset
     8
#include "../debug.h"
d240b9097139 (svn r2704) Remove . from include path again, too much trouble. Also add some #ifdefs and #includes for the Windows build
tron
parents: 2186
diff changeset
     9
#include "../functions.h"
d240b9097139 (svn r2704) Remove . from include path again, too much trouble. Also add some #ifdefs and #includes for the Windows build
tron
parents: 2186
diff changeset
    10
#include "../gfx.h"
5720
cc0ceeafaa55 (svn r7751) -Codechange: move network_* to a new network map. Furthermore move the low level network functions to network/core, so they can be reused by the masterserver and website-serverlist-updater.
rubidium
parents: 5657
diff changeset
    11
#include "../network/network.h"
2189
d240b9097139 (svn r2704) Remove . from include path again, too much trouble. Also add some #ifdefs and #includes for the Windows build
tron
parents: 2186
diff changeset
    12
#include "../window.h"
d240b9097139 (svn r2704) Remove . from include path again, too much trouble. Also add some #ifdefs and #includes for the Windows build
tron
parents: 2186
diff changeset
    13
#include "../console.h"
d240b9097139 (svn r2704) Remove . from include path again, too much trouble. Also add some #ifdefs and #includes for the Windows build
tron
parents: 2186
diff changeset
    14
#include "../variables.h"
4300
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 2791
diff changeset
    15
#include "../genworld.h"
9913
e79cd19772dd (svn r10213) [gamebalance] -Sync: r10100:10200 from trunk
celestar
parents: 9911
diff changeset
    16
#include "../fileio.h"
e79cd19772dd (svn r10213) [gamebalance] -Sync: r10100:10200 from trunk
celestar
parents: 9911
diff changeset
    17
#include "../blitter/factory.hpp"
2195
8960c86bf103 (svn r2710) Simplify dedicated server code a bit and don't compile it at all, if network support ist disabled
tron
parents: 2189
diff changeset
    18
#include "dedicated_v.h"
781
9717ff353c17 (svn r1248) -Add: initial OS/2 support (read docs/ReadMe_OS2.txt) (orudge)
truelight
parents: 774
diff changeset
    19
2497
1c8460570c0d (svn r3023) -Fix [BeOS] fixed compilation on BeOS R5 (MYOB)
bjarni
parents: 2261
diff changeset
    20
#ifdef BEOS_NET_SERVER
1c8460570c0d (svn r3023) -Fix [BeOS] fixed compilation on BeOS R5 (MYOB)
bjarni
parents: 2261
diff changeset
    21
#include <net/socket.h>
1c8460570c0d (svn r3023) -Fix [BeOS] fixed compilation on BeOS R5 (MYOB)
bjarni
parents: 2261
diff changeset
    22
#endif
1c8460570c0d (svn r3023) -Fix [BeOS] fixed compilation on BeOS R5 (MYOB)
bjarni
parents: 2261
diff changeset
    23
781
9717ff353c17 (svn r1248) -Add: initial OS/2 support (read docs/ReadMe_OS2.txt) (orudge)
truelight
parents: 774
diff changeset
    24
#ifdef __OS2__
9717ff353c17 (svn r1248) -Add: initial OS/2 support (read docs/ReadMe_OS2.txt) (orudge)
truelight
parents: 774
diff changeset
    25
#	include <sys/time.h> /* gettimeofday */
9717ff353c17 (svn r1248) -Add: initial OS/2 support (read docs/ReadMe_OS2.txt) (orudge)
truelight
parents: 774
diff changeset
    26
#	include <sys/types.h>
9717ff353c17 (svn r1248) -Add: initial OS/2 support (read docs/ReadMe_OS2.txt) (orudge)
truelight
parents: 774
diff changeset
    27
#	include <unistd.h>
9717ff353c17 (svn r1248) -Add: initial OS/2 support (read docs/ReadMe_OS2.txt) (orudge)
truelight
parents: 774
diff changeset
    28
#	include <conio.h>
2181
659d7d8d1ccd (svn r2695) - Fix: OS/2 project update, add os2.h to dedicated_v.c
orudge
parents: 2180
diff changeset
    29
659d7d8d1ccd (svn r2695) - Fix: OS/2 project update, add os2.h to dedicated_v.c
orudge
parents: 2180
diff changeset
    30
#	define INCL_DOS
659d7d8d1ccd (svn r2695) - Fix: OS/2 project update, add os2.h to dedicated_v.c
orudge
parents: 2180
diff changeset
    31
#	include <os2.h>
659d7d8d1ccd (svn r2695) - Fix: OS/2 project update, add os2.h to dedicated_v.c
orudge
parents: 2180
diff changeset
    32
781
9717ff353c17 (svn r1248) -Add: initial OS/2 support (read docs/ReadMe_OS2.txt) (orudge)
truelight
parents: 774
diff changeset
    33
#	define STDIN 0  /* file descriptor for standard input */
810
7c51ba5a4368 (svn r1281) -Fix: the OS/2 is now finished. Fixes:
truelight
parents: 796
diff changeset
    34
2261
3f78323707bb (svn r2781) Fix some of the issues with variables in .h files.
ludde
parents: 2228
diff changeset
    35
/**
2180
efe39e3d3fb4 (svn r2694) Various smaller changes: eol-style, static, code simplification
tron
parents: 2177
diff changeset
    36
 * Switches OpenTTD to a console app at run-time, instead of a PM app
efe39e3d3fb4 (svn r2694) Various smaller changes: eol-style, static, code simplification
tron
parents: 2177
diff changeset
    37
 * Necessary to see stdout, etc. */
9895
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6359
diff changeset
    38
static void OS2_SwitchToConsoleMode()
2180
efe39e3d3fb4 (svn r2694) Various smaller changes: eol-style, static, code simplification
tron
parents: 2177
diff changeset
    39
{
efe39e3d3fb4 (svn r2694) Various smaller changes: eol-style, static, code simplification
tron
parents: 2177
diff changeset
    40
	PPIB pib;
efe39e3d3fb4 (svn r2694) Various smaller changes: eol-style, static, code simplification
tron
parents: 2177
diff changeset
    41
	PTIB tib;
efe39e3d3fb4 (svn r2694) Various smaller changes: eol-style, static, code simplification
tron
parents: 2177
diff changeset
    42
efe39e3d3fb4 (svn r2694) Various smaller changes: eol-style, static, code simplification
tron
parents: 2177
diff changeset
    43
	DosGetInfoBlocks(&tib, &pib);
efe39e3d3fb4 (svn r2694) Various smaller changes: eol-style, static, code simplification
tron
parents: 2177
diff changeset
    44
efe39e3d3fb4 (svn r2694) Various smaller changes: eol-style, static, code simplification
tron
parents: 2177
diff changeset
    45
	// Change flag from PM to VIO
efe39e3d3fb4 (svn r2694) Various smaller changes: eol-style, static, code simplification
tron
parents: 2177
diff changeset
    46
	pib->pib_ultype = 3;
efe39e3d3fb4 (svn r2694) Various smaller changes: eol-style, static, code simplification
tron
parents: 2177
diff changeset
    47
}
781
9717ff353c17 (svn r1248) -Add: initial OS/2 support (read docs/ReadMe_OS2.txt) (orudge)
truelight
parents: 774
diff changeset
    48
#endif
9717ff353c17 (svn r1248) -Add: initial OS/2 support (read docs/ReadMe_OS2.txt) (orudge)
truelight
parents: 774
diff changeset
    49
6359
fb2fe9142034 (svn r8756) [PSP] -Fix: made the dedicated code compile with PSP. It is almost UNIX, just it needs more includes ;)
truelight
parents: 5838
diff changeset
    50
#if defined(UNIX) || defined(PSP)
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
    51
#	include <sys/time.h> /* gettimeofday */
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
    52
#	include <sys/types.h>
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
    53
#	include <unistd.h>
702
e8f37893243e (svn r1152) -Add: [Network] Added signal handling (GeniusDex)
truelight
parents: 626
diff changeset
    54
#	include <signal.h>
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
    55
#	define STDIN 0  /* file descriptor for standard input */
6359
fb2fe9142034 (svn r8756) [PSP] -Fix: made the dedicated code compile with PSP. It is almost UNIX, just it needs more includes ;)
truelight
parents: 5838
diff changeset
    56
#	if defined(PSP)
fb2fe9142034 (svn r8756) [PSP] -Fix: made the dedicated code compile with PSP. It is almost UNIX, just it needs more includes ;)
truelight
parents: 5838
diff changeset
    57
#		include <sys/fd_set.h>
fb2fe9142034 (svn r8756) [PSP] -Fix: made the dedicated code compile with PSP. It is almost UNIX, just it needs more includes ;)
truelight
parents: 5838
diff changeset
    58
#		include <sys/select.h>
fb2fe9142034 (svn r8756) [PSP] -Fix: made the dedicated code compile with PSP. It is almost UNIX, just it needs more includes ;)
truelight
parents: 5838
diff changeset
    59
#	endif /* PSP */
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
    60
702
e8f37893243e (svn r1152) -Add: [Network] Added signal handling (GeniusDex)
truelight
parents: 626
diff changeset
    61
/* Signal handlers */
704
a526dc96fbfc (svn r1154) -Add: [Network] Forked dedicated server (start openttd with -Df) (GeniusDex)
truelight
parents: 702
diff changeset
    62
static void DedicatedSignalHandler(int sig)
702
e8f37893243e (svn r1152) -Add: [Network] Added signal handling (GeniusDex)
truelight
parents: 626
diff changeset
    63
{
736
53618d1ade61 (svn r1188) -Fix: [Network] Fixed that CTRL+<key> could sometimes hang a dedicated
truelight
parents: 721
diff changeset
    64
	_exit_game = true;
53618d1ade61 (svn r1188) -Fix: [Network] Fixed that CTRL+<key> could sometimes hang a dedicated
truelight
parents: 721
diff changeset
    65
	signal(sig, DedicatedSignalHandler);
702
e8f37893243e (svn r1152) -Add: [Network] Added signal handling (GeniusDex)
truelight
parents: 626
diff changeset
    66
}
e8f37893243e (svn r1152) -Add: [Network] Added signal handling (GeniusDex)
truelight
parents: 626
diff changeset
    67
#endif
e8f37893243e (svn r1152) -Add: [Network] Added signal handling (GeniusDex)
truelight
parents: 626
diff changeset
    68
1046
d46ccd96c40f (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
#ifdef WIN32
2180
efe39e3d3fb4 (svn r2694) Various smaller changes: eol-style, static, code simplification
tron
parents: 2177
diff changeset
    70
#include <windows.h> /* GetTickCount */
efe39e3d3fb4 (svn r2694) Various smaller changes: eol-style, static, code simplification
tron
parents: 2177
diff changeset
    71
#include <conio.h>
1114
5433cbd50835 (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
    72
#include <time.h>
5168
10a8dc9788d7 (svn r7278) -Codechange: [win32] Add UNICODE support so it should compile on OS's using UNICODE
Darkvater
parents: 4891
diff changeset
    73
#include <tchar.h>
4599
acdc5cac5b93 (svn r6449) -Fix (Win32): The dedicated server could overwrite the keyboard input buffer
Darkvater
parents: 4300
diff changeset
    74
static HANDLE _hInputReady, _hWaitForInputHandling;
acdc5cac5b93 (svn r6449) -Fix (Win32): The dedicated server could overwrite the keyboard input buffer
Darkvater
parents: 4300
diff changeset
    75
static HANDLE _hThread; // Thread to close
1046
d46ccd96c40f (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
    76
static char _win_console_thread_buffer[200];
d46ccd96c40f (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
d46ccd96c40f (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
    78
/* Windows Console thread. Just loop and signal when input has been received */
9895
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6359
diff changeset
    79
static void WINAPI CheckForConsoleInput()
1046
d46ccd96c40f (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
{
9895
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6359
diff changeset
    81
	DWORD nb;
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6359
diff changeset
    82
	HANDLE hStdin = GetStdHandle(STD_INPUT_HANDLE);
1046
d46ccd96c40f (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
    83
	while (true) {
9895
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6359
diff changeset
    84
		ReadFile(hStdin, _win_console_thread_buffer, lengthof(_win_console_thread_buffer), &nb, NULL);
4599
acdc5cac5b93 (svn r6449) -Fix (Win32): The dedicated server could overwrite the keyboard input buffer
Darkvater
parents: 4300
diff changeset
    85
		/* Signal input waiting that input is read and wait for it being handled
acdc5cac5b93 (svn r6449) -Fix (Win32): The dedicated server could overwrite the keyboard input buffer
Darkvater
parents: 4300
diff changeset
    86
		 * SignalObjectAndWait() should be used here, but it's unsupported in Win98< */
acdc5cac5b93 (svn r6449) -Fix (Win32): The dedicated server could overwrite the keyboard input buffer
Darkvater
parents: 4300
diff changeset
    87
		SetEvent(_hInputReady);
acdc5cac5b93 (svn r6449) -Fix (Win32): The dedicated server could overwrite the keyboard input buffer
Darkvater
parents: 4300
diff changeset
    88
		WaitForSingleObject(_hWaitForInputHandling, INFINITE);
1046
d46ccd96c40f (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
	}
d46ccd96c40f (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
}
d46ccd96c40f (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
9895
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6359
diff changeset
    92
static void CreateWindowsConsoleThread()
1046
d46ccd96c40f (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
{
1762
01d1e351aafe (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
    94
	DWORD dwThreadId;
1046
d46ccd96c40f (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
    95
	/* Create event to signal when console input is ready */
4599
acdc5cac5b93 (svn r6449) -Fix (Win32): The dedicated server could overwrite the keyboard input buffer
Darkvater
parents: 4300
diff changeset
    96
	_hInputReady = CreateEvent(NULL, false, false, NULL);
acdc5cac5b93 (svn r6449) -Fix (Win32): The dedicated server could overwrite the keyboard input buffer
Darkvater
parents: 4300
diff changeset
    97
	_hWaitForInputHandling = CreateEvent(NULL, false, false, NULL);
acdc5cac5b93 (svn r6449) -Fix (Win32): The dedicated server could overwrite the keyboard input buffer
Darkvater
parents: 4300
diff changeset
    98
	if (_hInputReady == NULL || _hWaitForInputHandling == NULL) error("Cannot create console event!");
1046
d46ccd96c40f (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
4599
acdc5cac5b93 (svn r6449) -Fix (Win32): The dedicated server could overwrite the keyboard input buffer
Darkvater
parents: 4300
diff changeset
   100
	_hThread = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)CheckForConsoleInput, NULL, 0, &dwThreadId);
acdc5cac5b93 (svn r6449) -Fix (Win32): The dedicated server could overwrite the keyboard input buffer
Darkvater
parents: 4300
diff changeset
   101
	if (_hThread == NULL) error("Cannot create console thread!");
1046
d46ccd96c40f (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
   102
5568
75f13d7bfaed (svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents: 5168
diff changeset
   103
	DEBUG(driver, 2, "Windows console thread started");
1046
d46ccd96c40f (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
   104
}
d46ccd96c40f (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
   105
9895
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6359
diff changeset
   106
static void CloseWindowsConsoleThread()
1046
d46ccd96c40f (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
   107
{
4599
acdc5cac5b93 (svn r6449) -Fix (Win32): The dedicated server could overwrite the keyboard input buffer
Darkvater
parents: 4300
diff changeset
   108
	CloseHandle(_hThread);
acdc5cac5b93 (svn r6449) -Fix (Win32): The dedicated server could overwrite the keyboard input buffer
Darkvater
parents: 4300
diff changeset
   109
	CloseHandle(_hInputReady);
acdc5cac5b93 (svn r6449) -Fix (Win32): The dedicated server could overwrite the keyboard input buffer
Darkvater
parents: 4300
diff changeset
   110
	CloseHandle(_hWaitForInputHandling);
5568
75f13d7bfaed (svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents: 5168
diff changeset
   111
	DEBUG(driver, 2, "Windows console thread shut down");
1046
d46ccd96c40f (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
   112
}
d46ccd96c40f (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
   113
d46ccd96c40f (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
   114
#endif
d46ccd96c40f (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
   115
2180
efe39e3d3fb4 (svn r2694) Various smaller changes: eol-style, static, code simplification
tron
parents: 2177
diff changeset
   116
9913
e79cd19772dd (svn r10213) [gamebalance] -Sync: r10100:10200 from trunk
celestar
parents: 9911
diff changeset
   117
static void *_dedicated_video_mem;
2180
efe39e3d3fb4 (svn r2694) Various smaller changes: eol-style, static, code simplification
tron
parents: 2177
diff changeset
   118
9913
e79cd19772dd (svn r10213) [gamebalance] -Sync: r10100:10200 from trunk
celestar
parents: 9911
diff changeset
   119
extern bool SafeSaveOrLoad(const char *filename, int mode, int newgm, Subdirectory subdir);
2180
efe39e3d3fb4 (svn r2694) Various smaller changes: eol-style, static, code simplification
tron
parents: 2177
diff changeset
   120
extern void SwitchMode(int new_mode);
efe39e3d3fb4 (svn r2694) Various smaller changes: eol-style, static, code simplification
tron
parents: 2177
diff changeset
   121
efe39e3d3fb4 (svn r2694) Various smaller changes: eol-style, static, code simplification
tron
parents: 2177
diff changeset
   122
1301
313804601383 (svn r1805) Teach the driver layer a few things about const correctness
tron
parents: 1299
diff changeset
   123
static const char *DedicatedVideoStart(const char * const *parm)
313804601383 (svn r1805) Teach the driver layer a few things about const correctness
tron
parents: 1299
diff changeset
   124
{
9913
e79cd19772dd (svn r10213) [gamebalance] -Sync: r10100:10200 from trunk
celestar
parents: 9911
diff changeset
   125
	int bpp = BlitterFactoryBase::GetCurrentBlitter()->GetScreenDepth();
e79cd19772dd (svn r10213) [gamebalance] -Sync: r10100:10200 from trunk
celestar
parents: 9911
diff changeset
   126
	if (bpp == 0) _dedicated_video_mem = NULL;
e79cd19772dd (svn r10213) [gamebalance] -Sync: r10100:10200 from trunk
celestar
parents: 9911
diff changeset
   127
	else          _dedicated_video_mem = malloc(_cur_resolution[0] * _cur_resolution[1] * (bpp / 8));
e79cd19772dd (svn r10213) [gamebalance] -Sync: r10100:10200 from trunk
celestar
parents: 9911
diff changeset
   128
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   129
	_screen.width = _screen.pitch = _cur_resolution[0];
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   130
	_screen.height = _cur_resolution[1];
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   131
5657
54c99d0f6ba4 (svn r7602) -Fix (r7565): MSVC2003 and lower don't support variadic macros, so work around
Darkvater
parents: 5568
diff changeset
   132
	SetDebugString("net=6");
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   133
626
78c7e1c9f7c5 (svn r1056) -Fix: [Network] Give the dedicated-server always a console in windows (sign_de)
truelight
parents: 543
diff changeset
   134
#ifdef WIN32
5168
10a8dc9788d7 (svn r7278) -Codechange: [win32] Add UNICODE support so it should compile on OS's using UNICODE
Darkvater
parents: 4891
diff changeset
   135
	// For win32 we need to allocate a console (debug mode does the same)
626
78c7e1c9f7c5 (svn r1056) -Fix: [Network] Give the dedicated-server always a console in windows (sign_de)
truelight
parents: 543
diff changeset
   136
	CreateConsole();
1046
d46ccd96c40f (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
	CreateWindowsConsoleThread();
5168
10a8dc9788d7 (svn r7278) -Codechange: [win32] Add UNICODE support so it should compile on OS's using UNICODE
Darkvater
parents: 4891
diff changeset
   138
	SetConsoleTitle(_T("OpenTTD Dedicated Server"));
626
78c7e1c9f7c5 (svn r1056) -Fix: [Network] Give the dedicated-server always a console in windows (sign_de)
truelight
parents: 543
diff changeset
   139
#endif
78c7e1c9f7c5 (svn r1056) -Fix: [Network] Give the dedicated-server always a console in windows (sign_de)
truelight
parents: 543
diff changeset
   140
810
7c51ba5a4368 (svn r1281) -Fix: the OS/2 is now finished. Fixes:
truelight
parents: 796
diff changeset
   141
#ifdef __OS2__
7c51ba5a4368 (svn r1281) -Fix: the OS/2 is now finished. Fixes:
truelight
parents: 796
diff changeset
   142
	// For OS/2 we also need to switch to console mode instead of PM mode
7c51ba5a4368 (svn r1281) -Fix: the OS/2 is now finished. Fixes:
truelight
parents: 796
diff changeset
   143
	OS2_SwitchToConsoleMode();
7c51ba5a4368 (svn r1281) -Fix: the OS/2 is now finished. Fixes:
truelight
parents: 796
diff changeset
   144
#endif
7c51ba5a4368 (svn r1281) -Fix: the OS/2 is now finished. Fixes:
truelight
parents: 796
diff changeset
   145
5568
75f13d7bfaed (svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents: 5168
diff changeset
   146
	DEBUG(driver, 1, "Loading dedicated server");
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   147
	return NULL;
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   148
}
1046
d46ccd96c40f (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
   149
9895
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6359
diff changeset
   150
static void DedicatedVideoStop()
1046
d46ccd96c40f (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
   151
{
d46ccd96c40f (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
   152
#ifdef WIN32
d46ccd96c40f (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
   153
	CloseWindowsConsoleThread();
d46ccd96c40f (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
   154
#endif
1109
1bab892228cd (svn r1610) Remove trailing whitespace (last time ever, i hope)
tron
parents: 1090
diff changeset
   155
	free(_dedicated_video_mem);
1046
d46ccd96c40f (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
   156
}
d46ccd96c40f (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
   157
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   158
static void DedicatedVideoMakeDirty(int left, int top, int width, int height) {}
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   159
static bool DedicatedVideoChangeRes(int w, int h) { return false; }
1829
0b6de3b4458a (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
   160
static void DedicatedVideoFullScreen(bool fs) {}
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   161
6359
fb2fe9142034 (svn r8756) [PSP] -Fix: made the dedicated code compile with PSP. It is almost UNIX, just it needs more includes ;)
truelight
parents: 5838
diff changeset
   162
#if defined(UNIX) || defined(__OS2__) || defined(PSP)
9895
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6359
diff changeset
   163
static bool InputWaiting()
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   164
{
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   165
	struct timeval tv;
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   166
	fd_set readfds;
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   167
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   168
	tv.tv_sec = 0;
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   169
	tv.tv_usec = 1;
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   170
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   171
	FD_ZERO(&readfds);
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   172
	FD_SET(STDIN, &readfds);
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   173
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   174
	/* don't care about writefds and exceptfds: */
2180
efe39e3d3fb4 (svn r2694) Various smaller changes: eol-style, static, code simplification
tron
parents: 2177
diff changeset
   175
	return select(STDIN + 1, &readfds, NULL, NULL, &tv) > 0;
efe39e3d3fb4 (svn r2694) Various smaller changes: eol-style, static, code simplification
tron
parents: 2177
diff changeset
   176
}
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   177
9895
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6359
diff changeset
   178
static uint32 GetTime()
2180
efe39e3d3fb4 (svn r2694) Various smaller changes: eol-style, static, code simplification
tron
parents: 2177
diff changeset
   179
{
efe39e3d3fb4 (svn r2694) Various smaller changes: eol-style, static, code simplification
tron
parents: 2177
diff changeset
   180
	struct timeval tim;
1046
d46ccd96c40f (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
   181
2180
efe39e3d3fb4 (svn r2694) Various smaller changes: eol-style, static, code simplification
tron
parents: 2177
diff changeset
   182
	gettimeofday(&tim, NULL);
efe39e3d3fb4 (svn r2694) Various smaller changes: eol-style, static, code simplification
tron
parents: 2177
diff changeset
   183
	return tim.tv_usec / 1000 + tim.tv_sec * 1000;
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   184
}
2180
efe39e3d3fb4 (svn r2694) Various smaller changes: eol-style, static, code simplification
tron
parents: 2177
diff changeset
   185
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   186
#else
2180
efe39e3d3fb4 (svn r2694) Various smaller changes: eol-style, static, code simplification
tron
parents: 2177
diff changeset
   187
9895
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6359
diff changeset
   188
static bool InputWaiting()
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   189
{
4599
acdc5cac5b93 (svn r6449) -Fix (Win32): The dedicated server could overwrite the keyboard input buffer
Darkvater
parents: 4300
diff changeset
   190
	return WaitForSingleObject(_hInputReady, 1) == WAIT_OBJECT_0;
2180
efe39e3d3fb4 (svn r2694) Various smaller changes: eol-style, static, code simplification
tron
parents: 2177
diff changeset
   191
}
1109
1bab892228cd (svn r1610) Remove trailing whitespace (last time ever, i hope)
tron
parents: 1090
diff changeset
   192
9895
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6359
diff changeset
   193
static uint32 GetTime()
2180
efe39e3d3fb4 (svn r2694) Various smaller changes: eol-style, static, code simplification
tron
parents: 2177
diff changeset
   194
{
efe39e3d3fb4 (svn r2694) Various smaller changes: eol-style, static, code simplification
tron
parents: 2177
diff changeset
   195
	return GetTickCount();
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   196
}
2180
efe39e3d3fb4 (svn r2694) Various smaller changes: eol-style, static, code simplification
tron
parents: 2177
diff changeset
   197
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   198
#endif
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   199
9895
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6359
diff changeset
   200
static void DedicatedHandleKeyInput()
704
a526dc96fbfc (svn r1154) -Add: [Network] Forked dedicated server (start openttd with -Df) (GeniusDex)
truelight
parents: 702
diff changeset
   201
{
721
20591395836b (svn r1173) -Fix: [Network] Console input in dedicated server for windows was not
truelight
parents: 720
diff changeset
   202
	static char input_line[200] = "";
704
a526dc96fbfc (svn r1154) -Add: [Network] Forked dedicated server (start openttd with -Df) (GeniusDex)
truelight
parents: 702
diff changeset
   203
4599
acdc5cac5b93 (svn r6449) -Fix (Win32): The dedicated server could overwrite the keyboard input buffer
Darkvater
parents: 4300
diff changeset
   204
	if (!InputWaiting()) return;
1046
d46ccd96c40f (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
4599
acdc5cac5b93 (svn r6449) -Fix (Win32): The dedicated server could overwrite the keyboard input buffer
Darkvater
parents: 4300
diff changeset
   206
	if (_exit_game) return;
1046
d46ccd96c40f (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
6359
fb2fe9142034 (svn r8756) [PSP] -Fix: made the dedicated code compile with PSP. It is almost UNIX, just it needs more includes ;)
truelight
parents: 5838
diff changeset
   208
#if defined(UNIX) || defined(__OS2__) || defined(PSP)
4891
74c29446124e (svn r6835) - Fix: Pressing ^D (EOF) at a dedicated console caused it to repeat the last command, instead of doing nothing.
peter1138
parents: 4848
diff changeset
   209
	if (fgets(input_line, lengthof(input_line), stdin) == NULL) return;
1046
d46ccd96c40f (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
#else
4599
acdc5cac5b93 (svn r6449) -Fix (Win32): The dedicated server could overwrite the keyboard input buffer
Darkvater
parents: 4300
diff changeset
   211
	/* Handle console input, and singal console thread, it can accept input again */
acdc5cac5b93 (svn r6449) -Fix (Win32): The dedicated server could overwrite the keyboard input buffer
Darkvater
parents: 4300
diff changeset
   212
	strncpy(input_line, _win_console_thread_buffer, lengthof(input_line));
acdc5cac5b93 (svn r6449) -Fix (Win32): The dedicated server could overwrite the keyboard input buffer
Darkvater
parents: 4300
diff changeset
   213
	SetEvent(_hWaitForInputHandling);
1046
d46ccd96c40f (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
#endif
736
53618d1ade61 (svn r1188) -Fix: [Network] Fixed that CTRL+<key> could sometimes hang a dedicated
truelight
parents: 721
diff changeset
   215
1046
d46ccd96c40f (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
   216
	/* XXX - strtok() does not 'forget' \n\r if it is the first character! */
d46ccd96c40f (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
   217
	strtok(input_line, "\r\n"); // Forget about the final \n (or \r)
d46ccd96c40f (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
	{ /* Remove any special control characters */
d46ccd96c40f (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
   219
		uint i;
d46ccd96c40f (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
   220
		for (i = 0; i < lengthof(input_line); i++) {
d46ccd96c40f (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
   221
			if (input_line[i] == '\n' || input_line[i] == '\r') // cut missed beginning '\0'
d46ccd96c40f (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
   222
				input_line[i] = '\0';
d46ccd96c40f (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
   223
d46ccd96c40f (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
   224
			if (input_line[i] == '\0')
d46ccd96c40f (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
   225
				break;
d46ccd96c40f (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
   226
d46ccd96c40f (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
   227
			if (!IS_INT_INSIDE(input_line[i], ' ', 256))
d46ccd96c40f (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
   228
				input_line[i] = ' ';
704
a526dc96fbfc (svn r1154) -Add: [Network] Forked dedicated server (start openttd with -Df) (GeniusDex)
truelight
parents: 702
diff changeset
   229
		}
a526dc96fbfc (svn r1154) -Add: [Network] Forked dedicated server (start openttd with -Df) (GeniusDex)
truelight
parents: 702
diff changeset
   230
	}
1046
d46ccd96c40f (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
   231
d46ccd96c40f (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
   232
	IConsoleCmdExec(input_line); // execute command
704
a526dc96fbfc (svn r1154) -Add: [Network] Forked dedicated server (start openttd with -Df) (GeniusDex)
truelight
parents: 702
diff changeset
   233
}
a526dc96fbfc (svn r1154) -Add: [Network] Forked dedicated server (start openttd with -Df) (GeniusDex)
truelight
parents: 702
diff changeset
   234
9895
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6359
diff changeset
   235
static void DedicatedVideoMainLoop()
704
a526dc96fbfc (svn r1154) -Add: [Network] Forked dedicated server (start openttd with -Df) (GeniusDex)
truelight
parents: 702
diff changeset
   236
{
5832
28aa8ad3bb04 (svn r8028) -Fix: overflow of ticks was not handled properly, possibly resulting a non-reacting gameserver/gameclient.
rubidium
parents: 5726
diff changeset
   237
	uint32 cur_ticks = GetTime();
28aa8ad3bb04 (svn r8028) -Fix: overflow of ticks was not handled properly, possibly resulting a non-reacting gameserver/gameclient.
rubidium
parents: 5726
diff changeset
   238
	uint32 next_tick = cur_ticks + 30;
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   239
770
89dab23f04ca (svn r1236) MorphOS: added make release like in OSX (tokai)
bjarni
parents: 736
diff changeset
   240
	/* Signal handlers */
6359
fb2fe9142034 (svn r8756) [PSP] -Fix: made the dedicated code compile with PSP. It is almost UNIX, just it needs more includes ;)
truelight
parents: 5838
diff changeset
   241
#if defined(UNIX) || defined(PSP)
702
e8f37893243e (svn r1152) -Add: [Network] Added signal handling (GeniusDex)
truelight
parents: 626
diff changeset
   242
	signal(SIGTERM, DedicatedSignalHandler);
e8f37893243e (svn r1152) -Add: [Network] Added signal handling (GeniusDex)
truelight
parents: 626
diff changeset
   243
	signal(SIGINT, DedicatedSignalHandler);
736
53618d1ade61 (svn r1188) -Fix: [Network] Fixed that CTRL+<key> could sometimes hang a dedicated
truelight
parents: 721
diff changeset
   244
	signal(SIGQUIT, DedicatedSignalHandler);
702
e8f37893243e (svn r1152) -Add: [Network] Added signal handling (GeniusDex)
truelight
parents: 626
diff changeset
   245
#endif
e8f37893243e (svn r1152) -Add: [Network] Added signal handling (GeniusDex)
truelight
parents: 626
diff changeset
   246
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   247
	// Load the dedicated server stuff
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   248
	_is_network_server = true;
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   249
	_network_dedicated = true;
4848
56549aa3e234 (svn r6774) -Codechange: Rename the badly named OWNER_SPECTATOR to PLAYER_SPECTATOR and
Darkvater
parents: 4599
diff changeset
   250
	_network_playas = PLAYER_SPECTATOR;
56549aa3e234 (svn r6774) -Codechange: Rename the badly named OWNER_SPECTATOR to PLAYER_SPECTATOR and
Darkvater
parents: 4599
diff changeset
   251
	_local_player = PLAYER_SPECTATOR;
1414
d7fa2709bf86 (svn r1918) -Fix: [ 1101874 ] Dedicated server now accepts '-g' (load game) as param
truelight
parents: 1406
diff changeset
   252
d7fa2709bf86 (svn r1918) -Fix: [ 1101874 ] Dedicated server now accepts '-g' (load game) as param
truelight
parents: 1406
diff changeset
   253
	/* If SwitchMode is SM_LOAD, it means that the user used the '-g' options */
d7fa2709bf86 (svn r1918) -Fix: [ 1101874 ] Dedicated server now accepts '-g' (load game) as param
truelight
parents: 1406
diff changeset
   254
	if (_switch_mode != SM_LOAD) {
4300
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 2791
diff changeset
   255
		StartNewGameWithoutGUI(GENERATE_NEW_SEED);
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 2791
diff changeset
   256
		SwitchMode(_switch_mode);
1414
d7fa2709bf86 (svn r1918) -Fix: [ 1101874 ] Dedicated server now accepts '-g' (load game) as param
truelight
parents: 1406
diff changeset
   257
		_switch_mode = SM_NONE;
d7fa2709bf86 (svn r1918) -Fix: [ 1101874 ] Dedicated server now accepts '-g' (load game) as param
truelight
parents: 1406
diff changeset
   258
	} else {
d7fa2709bf86 (svn r1918) -Fix: [ 1101874 ] Dedicated server now accepts '-g' (load game) as param
truelight
parents: 1406
diff changeset
   259
		_switch_mode = SM_NONE;
d7fa2709bf86 (svn r1918) -Fix: [ 1101874 ] Dedicated server now accepts '-g' (load game) as param
truelight
parents: 1406
diff changeset
   260
		/* First we need to test if the savegame can be loaded, else we will end up playing the
d7fa2709bf86 (svn r1918) -Fix: [ 1101874 ] Dedicated server now accepts '-g' (load game) as param
truelight
parents: 1406
diff changeset
   261
		 *  intro game... */
9913
e79cd19772dd (svn r10213) [gamebalance] -Sync: r10100:10200 from trunk
celestar
parents: 9911
diff changeset
   262
		if (!SafeSaveOrLoad(_file_to_saveload.name, _file_to_saveload.mode, GM_NORMAL, BASE_DIR)) {
1414
d7fa2709bf86 (svn r1918) -Fix: [ 1101874 ] Dedicated server now accepts '-g' (load game) as param
truelight
parents: 1406
diff changeset
   263
			/* Loading failed, pop out.. */
5568
75f13d7bfaed (svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents: 5168
diff changeset
   264
			DEBUG(net, 0, "Loading requested map failed, aborting");
1414
d7fa2709bf86 (svn r1918) -Fix: [ 1101874 ] Dedicated server now accepts '-g' (load game) as param
truelight
parents: 1406
diff changeset
   265
			_networking = false;
d7fa2709bf86 (svn r1918) -Fix: [ 1101874 ] Dedicated server now accepts '-g' (load game) as param
truelight
parents: 1406
diff changeset
   266
		} else {
d7fa2709bf86 (svn r1918) -Fix: [ 1101874 ] Dedicated server now accepts '-g' (load game) as param
truelight
parents: 1406
diff changeset
   267
			/* We can load this game, so go ahead */
d7fa2709bf86 (svn r1918) -Fix: [ 1101874 ] Dedicated server now accepts '-g' (load game) as param
truelight
parents: 1406
diff changeset
   268
			SwitchMode(SM_LOAD);
d7fa2709bf86 (svn r1918) -Fix: [ 1101874 ] Dedicated server now accepts '-g' (load game) as param
truelight
parents: 1406
diff changeset
   269
		}
d7fa2709bf86 (svn r1918) -Fix: [ 1101874 ] Dedicated server now accepts '-g' (load game) as param
truelight
parents: 1406
diff changeset
   270
	}
d7fa2709bf86 (svn r1918) -Fix: [ 1101874 ] Dedicated server now accepts '-g' (load game) as param
truelight
parents: 1406
diff changeset
   271
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   272
	// Done loading, start game!
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   273
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   274
	if (!_networking) {
5568
75f13d7bfaed (svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents: 5168
diff changeset
   275
		DEBUG(net, 0, "Dedicated server could not be started, aborting");
2228
7014d372374f (svn r2748) Remove unused cruft from the main loop
tron
parents: 2210
diff changeset
   276
		return;
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   277
	}
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   278
2228
7014d372374f (svn r2748) Remove unused cruft from the main loop
tron
parents: 2210
diff changeset
   279
	while (!_exit_game) {
5832
28aa8ad3bb04 (svn r8028) -Fix: overflow of ticks was not handled properly, possibly resulting a non-reacting gameserver/gameclient.
rubidium
parents: 5726
diff changeset
   280
		uint32 prev_cur_ticks = cur_ticks; // to check for wrapping
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   281
		InteractiveRandom(); // randomness
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   282
704
a526dc96fbfc (svn r1154) -Add: [Network] Forked dedicated server (start openttd with -Df) (GeniusDex)
truelight
parents: 702
diff changeset
   283
		if (!_dedicated_forks)
a526dc96fbfc (svn r1154) -Add: [Network] Forked dedicated server (start openttd with -Df) (GeniusDex)
truelight
parents: 702
diff changeset
   284
			DedicatedHandleKeyInput();
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   285
2180
efe39e3d3fb4 (svn r2694) Various smaller changes: eol-style, static, code simplification
tron
parents: 2177
diff changeset
   286
		cur_ticks = GetTime();
5832
28aa8ad3bb04 (svn r8028) -Fix: overflow of ticks was not handled properly, possibly resulting a non-reacting gameserver/gameclient.
rubidium
parents: 5726
diff changeset
   287
		if (cur_ticks >= next_tick || cur_ticks < prev_cur_ticks) {
28aa8ad3bb04 (svn r8028) -Fix: overflow of ticks was not handled properly, possibly resulting a non-reacting gameserver/gameclient.
rubidium
parents: 5726
diff changeset
   288
			next_tick = cur_ticks + 30;
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   289
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   290
			GameLoop();
9911
0b8b245a2391 (svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents: 9895
diff changeset
   291
			_screen.dst_ptr = _dedicated_video_mem;
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   292
			UpdateWindows();
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   293
		}
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   294
		CSleep(1);
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   295
	}
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   296
}
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   297
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   298
const HalVideoDriver _dedicated_video_driver = {
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   299
	DedicatedVideoStart,
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   300
	DedicatedVideoStop,
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   301
	DedicatedVideoMakeDirty,
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   302
	DedicatedVideoMainLoop,
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   303
	DedicatedVideoChangeRes,
1829
0b6de3b4458a (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
   304
	DedicatedVideoFullScreen,
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   305
};
2195
8960c86bf103 (svn r2710) Simplify dedicated server code a bit and don't compile it at all, if network support ist disabled
tron
parents: 2189
diff changeset
   306
8960c86bf103 (svn r2710) Simplify dedicated server code a bit and don't compile it at all, if network support ist disabled
tron
parents: 2189
diff changeset
   307
#endif /* ENABLE_NETWORK */