src/video/dedicated_v.cpp
author KUDr
Fri, 12 Jan 2007 15:43:00 +0000
changeset 5620 eab6f02899a0
parent 5587 167d9a91ef02
child 6033 61682c6606c8
permissions -rw-r--r--
(svn r8079) -Fix [YAPF]: float division by zero when calculating stats (YAPF cache hit ratio). Caused BSOD on Win9x. (thanks 3iff for report, Darkvater for help)
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
2189
5cdc11ffeaa4 (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
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
     4
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
     5
#ifdef ENABLE_NETWORK
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
     6
2195
ed135f2dc5f8 (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
5cdc11ffeaa4 (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"
5cdc11ffeaa4 (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"
5cdc11ffeaa4 (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"
5469
7edfc643abbc (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: 5406
diff changeset
    11
#include "../network/network.h"
2189
5cdc11ffeaa4 (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"
5cdc11ffeaa4 (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"
5cdc11ffeaa4 (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
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 2791
diff changeset
    15
#include "../genworld.h"
2195
ed135f2dc5f8 (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
    16
#include "dedicated_v.h"
781
4c9177888196 (svn r1248) -Add: initial OS/2 support (read docs/ReadMe_OS2.txt) (orudge)
truelight
parents: 774
diff changeset
    17
2497
0fe349de34c7 (svn r3023) -Fix [BeOS] fixed compilation on BeOS R5 (MYOB)
bjarni
parents: 2261
diff changeset
    18
#ifdef BEOS_NET_SERVER
0fe349de34c7 (svn r3023) -Fix [BeOS] fixed compilation on BeOS R5 (MYOB)
bjarni
parents: 2261
diff changeset
    19
#include <net/socket.h>
0fe349de34c7 (svn r3023) -Fix [BeOS] fixed compilation on BeOS R5 (MYOB)
bjarni
parents: 2261
diff changeset
    20
#endif
0fe349de34c7 (svn r3023) -Fix [BeOS] fixed compilation on BeOS R5 (MYOB)
bjarni
parents: 2261
diff changeset
    21
781
4c9177888196 (svn r1248) -Add: initial OS/2 support (read docs/ReadMe_OS2.txt) (orudge)
truelight
parents: 774
diff changeset
    22
#ifdef __OS2__
4c9177888196 (svn r1248) -Add: initial OS/2 support (read docs/ReadMe_OS2.txt) (orudge)
truelight
parents: 774
diff changeset
    23
#	include <sys/time.h> /* gettimeofday */
4c9177888196 (svn r1248) -Add: initial OS/2 support (read docs/ReadMe_OS2.txt) (orudge)
truelight
parents: 774
diff changeset
    24
#	include <sys/types.h>
4c9177888196 (svn r1248) -Add: initial OS/2 support (read docs/ReadMe_OS2.txt) (orudge)
truelight
parents: 774
diff changeset
    25
#	include <unistd.h>
4c9177888196 (svn r1248) -Add: initial OS/2 support (read docs/ReadMe_OS2.txt) (orudge)
truelight
parents: 774
diff changeset
    26
#	include <conio.h>
2181
c0ddc9695a14 (svn r2695) - Fix: OS/2 project update, add os2.h to dedicated_v.c
orudge
parents: 2180
diff changeset
    27
c0ddc9695a14 (svn r2695) - Fix: OS/2 project update, add os2.h to dedicated_v.c
orudge
parents: 2180
diff changeset
    28
#	define INCL_DOS
c0ddc9695a14 (svn r2695) - Fix: OS/2 project update, add os2.h to dedicated_v.c
orudge
parents: 2180
diff changeset
    29
#	include <os2.h>
c0ddc9695a14 (svn r2695) - Fix: OS/2 project update, add os2.h to dedicated_v.c
orudge
parents: 2180
diff changeset
    30
781
4c9177888196 (svn r1248) -Add: initial OS/2 support (read docs/ReadMe_OS2.txt) (orudge)
truelight
parents: 774
diff changeset
    31
#	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
    32
2261
d3554e5d3e86 (svn r2781) Fix some of the issues with variables in .h files.
ludde
parents: 2228
diff changeset
    33
/**
2180
c93b74122221 (svn r2694) Various smaller changes: eol-style, static, code simplification
tron
parents: 2177
diff changeset
    34
 * 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
    35
 * Necessary to see stdout, etc. */
c93b74122221 (svn r2694) Various smaller changes: eol-style, static, code simplification
tron
parents: 2177
diff changeset
    36
static void OS2_SwitchToConsoleMode(void)
c93b74122221 (svn r2694) Various smaller changes: eol-style, static, code simplification
tron
parents: 2177
diff changeset
    37
{
c93b74122221 (svn r2694) Various smaller changes: eol-style, static, code simplification
tron
parents: 2177
diff changeset
    38
	PPIB pib;
c93b74122221 (svn r2694) Various smaller changes: eol-style, static, code simplification
tron
parents: 2177
diff changeset
    39
	PTIB tib;
c93b74122221 (svn r2694) Various smaller changes: eol-style, static, code simplification
tron
parents: 2177
diff changeset
    40
c93b74122221 (svn r2694) Various smaller changes: eol-style, static, code simplification
tron
parents: 2177
diff changeset
    41
	DosGetInfoBlocks(&tib, &pib);
c93b74122221 (svn r2694) Various smaller changes: eol-style, static, code simplification
tron
parents: 2177
diff changeset
    42
c93b74122221 (svn r2694) Various smaller changes: eol-style, static, code simplification
tron
parents: 2177
diff changeset
    43
	// Change flag from PM to VIO
c93b74122221 (svn r2694) Various smaller changes: eol-style, static, code simplification
tron
parents: 2177
diff changeset
    44
	pib->pib_ultype = 3;
c93b74122221 (svn r2694) Various smaller changes: eol-style, static, code simplification
tron
parents: 2177
diff changeset
    45
}
781
4c9177888196 (svn r1248) -Add: initial OS/2 support (read docs/ReadMe_OS2.txt) (orudge)
truelight
parents: 774
diff changeset
    46
#endif
4c9177888196 (svn r1248) -Add: initial OS/2 support (read docs/ReadMe_OS2.txt) (orudge)
truelight
parents: 774
diff changeset
    47
543
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
    48
#ifdef UNIX
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
    49
#	include <sys/time.h> /* gettimeofday */
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
    50
#	include <sys/types.h>
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
    51
#	include <unistd.h>
702
5e80e4d69057 (svn r1152) -Add: [Network] Added signal handling (GeniusDex)
truelight
parents: 626
diff changeset
    52
#	include <signal.h>
543
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
    53
#	define STDIN 0  /* file descriptor for standard input */
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
    54
702
5e80e4d69057 (svn r1152) -Add: [Network] Added signal handling (GeniusDex)
truelight
parents: 626
diff changeset
    55
/* Signal handlers */
704
e843dd369938 (svn r1154) -Add: [Network] Forked dedicated server (start openttd with -Df) (GeniusDex)
truelight
parents: 702
diff changeset
    56
static void DedicatedSignalHandler(int sig)
702
5e80e4d69057 (svn r1152) -Add: [Network] Added signal handling (GeniusDex)
truelight
parents: 626
diff changeset
    57
{
736
75bcef85daeb (svn r1188) -Fix: [Network] Fixed that CTRL+<key> could sometimes hang a dedicated
truelight
parents: 721
diff changeset
    58
	_exit_game = true;
75bcef85daeb (svn r1188) -Fix: [Network] Fixed that CTRL+<key> could sometimes hang a dedicated
truelight
parents: 721
diff changeset
    59
	signal(sig, DedicatedSignalHandler);
702
5e80e4d69057 (svn r1152) -Add: [Network] Added signal handling (GeniusDex)
truelight
parents: 626
diff changeset
    60
}
5e80e4d69057 (svn r1152) -Add: [Network] Added signal handling (GeniusDex)
truelight
parents: 626
diff changeset
    61
#endif
5e80e4d69057 (svn r1152) -Add: [Network] Added signal handling (GeniusDex)
truelight
parents: 626
diff changeset
    62
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
    63
#ifdef WIN32
2180
c93b74122221 (svn r2694) Various smaller changes: eol-style, static, code simplification
tron
parents: 2177
diff changeset
    64
#include <windows.h> /* GetTickCount */
c93b74122221 (svn r2694) Various smaller changes: eol-style, static, code simplification
tron
parents: 2177
diff changeset
    65
#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
    66
#include <time.h>
5168
e206899169c4 (svn r7278) -Codechange: [win32] Add UNICODE support so it should compile on OS's using UNICODE
Darkvater
parents: 4891
diff changeset
    67
#include <tchar.h>
4599
79009a39da03 (svn r6449) -Fix (Win32): The dedicated server could overwrite the keyboard input buffer
Darkvater
parents: 4300
diff changeset
    68
static HANDLE _hInputReady, _hWaitForInputHandling;
79009a39da03 (svn r6449) -Fix (Win32): The dedicated server could overwrite the keyboard input buffer
Darkvater
parents: 4300
diff changeset
    69
static HANDLE _hThread; // Thread to close
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
    70
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
    71
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
/* 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
    73
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
    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
	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
    76
		fgets(_win_console_thread_buffer, lengthof(_win_console_thread_buffer), stdin);
4599
79009a39da03 (svn r6449) -Fix (Win32): The dedicated server could overwrite the keyboard input buffer
Darkvater
parents: 4300
diff changeset
    77
		/* Signal input waiting that input is read and wait for it being handled
79009a39da03 (svn r6449) -Fix (Win32): The dedicated server could overwrite the keyboard input buffer
Darkvater
parents: 4300
diff changeset
    78
		 * SignalObjectAndWait() should be used here, but it's unsupported in Win98< */
79009a39da03 (svn r6449) -Fix (Win32): The dedicated server could overwrite the keyboard input buffer
Darkvater
parents: 4300
diff changeset
    79
		SetEvent(_hInputReady);
79009a39da03 (svn r6449) -Fix (Win32): The dedicated server could overwrite the keyboard input buffer
Darkvater
parents: 4300
diff changeset
    80
		WaitForSingleObject(_hWaitForInputHandling, INFINITE);
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
    81
	}
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
    82
}
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
    83
2180
c93b74122221 (svn r2694) Various smaller changes: eol-style, static, code simplification
tron
parents: 2177
diff changeset
    84
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
    85
{
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
    86
	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
    87
	/* Create event to signal when console input is ready */
4599
79009a39da03 (svn r6449) -Fix (Win32): The dedicated server could overwrite the keyboard input buffer
Darkvater
parents: 4300
diff changeset
    88
	_hInputReady = CreateEvent(NULL, false, false, NULL);
79009a39da03 (svn r6449) -Fix (Win32): The dedicated server could overwrite the keyboard input buffer
Darkvater
parents: 4300
diff changeset
    89
	_hWaitForInputHandling = CreateEvent(NULL, false, false, NULL);
79009a39da03 (svn r6449) -Fix (Win32): The dedicated server could overwrite the keyboard input buffer
Darkvater
parents: 4300
diff changeset
    90
	if (_hInputReady == NULL || _hWaitForInputHandling == NULL) 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
    91
4599
79009a39da03 (svn r6449) -Fix (Win32): The dedicated server could overwrite the keyboard input buffer
Darkvater
parents: 4300
diff changeset
    92
	_hThread = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)CheckForConsoleInput, NULL, 0, &dwThreadId);
79009a39da03 (svn r6449) -Fix (Win32): The dedicated server could overwrite the keyboard input buffer
Darkvater
parents: 4300
diff changeset
    93
	if (_hThread == NULL) error("Cannot create console thread!");
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
    94
5380
8ea58542b6e0 (svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents: 5168
diff changeset
    95
	DEBUG(driver, 2, "Windows console thread started");
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
}
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
2180
c93b74122221 (svn r2694) Various smaller changes: eol-style, static, code simplification
tron
parents: 2177
diff changeset
    98
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
    99
{
4599
79009a39da03 (svn r6449) -Fix (Win32): The dedicated server could overwrite the keyboard input buffer
Darkvater
parents: 4300
diff changeset
   100
	CloseHandle(_hThread);
79009a39da03 (svn r6449) -Fix (Win32): The dedicated server could overwrite the keyboard input buffer
Darkvater
parents: 4300
diff changeset
   101
	CloseHandle(_hInputReady);
79009a39da03 (svn r6449) -Fix (Win32): The dedicated server could overwrite the keyboard input buffer
Darkvater
parents: 4300
diff changeset
   102
	CloseHandle(_hWaitForInputHandling);
5380
8ea58542b6e0 (svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents: 5168
diff changeset
   103
	DEBUG(driver, 2, "Windows console thread shut down");
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
   104
}
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
   105
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
   106
#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
   107
2180
c93b74122221 (svn r2694) Various smaller changes: eol-style, static, code simplification
tron
parents: 2177
diff changeset
   108
c93b74122221 (svn r2694) Various smaller changes: eol-style, static, code simplification
tron
parents: 2177
diff changeset
   109
static void *_dedicated_video_mem;
c93b74122221 (svn r2694) Various smaller changes: eol-style, static, code simplification
tron
parents: 2177
diff changeset
   110
c93b74122221 (svn r2694) Various smaller changes: eol-style, static, code simplification
tron
parents: 2177
diff changeset
   111
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
   112
extern void SwitchMode(int new_mode);
c93b74122221 (svn r2694) Various smaller changes: eol-style, static, code simplification
tron
parents: 2177
diff changeset
   113
c93b74122221 (svn r2694) Various smaller changes: eol-style, static, code simplification
tron
parents: 2177
diff changeset
   114
1301
bf64ba5b6774 (svn r1805) Teach the driver layer a few things about const correctness
tron
parents: 1299
diff changeset
   115
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
   116
{
543
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   117
	_screen.width = _screen.pitch = _cur_resolution[0];
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   118
	_screen.height = _cur_resolution[1];
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   119
	_dedicated_video_mem = malloc(_cur_resolution[0]*_cur_resolution[1]);
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   120
5406
2df85542fee4 (svn r7602) -Fix (r7565): MSVC2003 and lower don't support variadic macros, so work around
Darkvater
parents: 5380
diff changeset
   121
	SetDebugString("net=6");
543
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   122
626
35294912464a (svn r1056) -Fix: [Network] Give the dedicated-server always a console in windows (sign_de)
truelight
parents: 543
diff changeset
   123
#ifdef WIN32
5168
e206899169c4 (svn r7278) -Codechange: [win32] Add UNICODE support so it should compile on OS's using UNICODE
Darkvater
parents: 4891
diff changeset
   124
	// For win32 we need to allocate a console (debug mode does the same)
626
35294912464a (svn r1056) -Fix: [Network] Give the dedicated-server always a console in windows (sign_de)
truelight
parents: 543
diff changeset
   125
	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
   126
	CreateWindowsConsoleThread();
5168
e206899169c4 (svn r7278) -Codechange: [win32] Add UNICODE support so it should compile on OS's using UNICODE
Darkvater
parents: 4891
diff changeset
   127
	SetConsoleTitle(_T("OpenTTD Dedicated Server"));
626
35294912464a (svn r1056) -Fix: [Network] Give the dedicated-server always a console in windows (sign_de)
truelight
parents: 543
diff changeset
   128
#endif
35294912464a (svn r1056) -Fix: [Network] Give the dedicated-server always a console in windows (sign_de)
truelight
parents: 543
diff changeset
   129
810
a1494b19bd2a (svn r1281) -Fix: the OS/2 is now finished. Fixes:
truelight
parents: 796
diff changeset
   130
#ifdef __OS2__
a1494b19bd2a (svn r1281) -Fix: the OS/2 is now finished. Fixes:
truelight
parents: 796
diff changeset
   131
	// 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
   132
	OS2_SwitchToConsoleMode();
a1494b19bd2a (svn r1281) -Fix: the OS/2 is now finished. Fixes:
truelight
parents: 796
diff changeset
   133
#endif
a1494b19bd2a (svn r1281) -Fix: the OS/2 is now finished. Fixes:
truelight
parents: 796
diff changeset
   134
5380
8ea58542b6e0 (svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents: 5168
diff changeset
   135
	DEBUG(driver, 1, "Loading dedicated server");
543
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   136
	return NULL;
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   137
}
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
   138
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
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
   140
{
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
   141
#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
   142
	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
   143
#endif
1109
ecb98f43ba2c (svn r1610) Remove trailing whitespace (last time ever, i hope)
tron
parents: 1090
diff changeset
   144
	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
   145
}
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
543
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   147
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
   148
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
   149
static void DedicatedVideoFullScreen(bool fs) {}
543
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   150
1090
5d378bd5fcbc (svn r1591) Make dedicated servers on OS/2 check for input the UNIX way
tron
parents: 1046
diff changeset
   151
#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
   152
static bool InputWaiting(void)
543
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
	struct timeval tv;
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   155
	fd_set 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
	tv.tv_sec = 0;
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   158
	tv.tv_usec = 1;
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   159
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   160
	FD_ZERO(&readfds);
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   161
	FD_SET(STDIN, &readfds);
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   162
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   163
	/* don't care about writefds and exceptfds: */
2180
c93b74122221 (svn r2694) Various smaller changes: eol-style, static, code simplification
tron
parents: 2177
diff changeset
   164
	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
   165
}
543
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   166
2180
c93b74122221 (svn r2694) Various smaller changes: eol-style, static, code simplification
tron
parents: 2177
diff changeset
   167
static uint32 GetTime(void)
c93b74122221 (svn r2694) Various smaller changes: eol-style, static, code simplification
tron
parents: 2177
diff changeset
   168
{
c93b74122221 (svn r2694) Various smaller changes: eol-style, static, code simplification
tron
parents: 2177
diff changeset
   169
	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
   170
2180
c93b74122221 (svn r2694) Various smaller changes: eol-style, static, code simplification
tron
parents: 2177
diff changeset
   171
	gettimeofday(&tim, NULL);
c93b74122221 (svn r2694) Various smaller changes: eol-style, static, code simplification
tron
parents: 2177
diff changeset
   172
	return tim.tv_usec / 1000 + tim.tv_sec * 1000;
543
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   173
}
2180
c93b74122221 (svn r2694) Various smaller changes: eol-style, static, code simplification
tron
parents: 2177
diff changeset
   174
543
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   175
#else
2180
c93b74122221 (svn r2694) Various smaller changes: eol-style, static, code simplification
tron
parents: 2177
diff changeset
   176
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
   177
static bool InputWaiting(void)
543
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   178
{
4599
79009a39da03 (svn r6449) -Fix (Win32): The dedicated server could overwrite the keyboard input buffer
Darkvater
parents: 4300
diff changeset
   179
	return WaitForSingleObject(_hInputReady, 1) == WAIT_OBJECT_0;
2180
c93b74122221 (svn r2694) Various smaller changes: eol-style, static, code simplification
tron
parents: 2177
diff changeset
   180
}
1109
ecb98f43ba2c (svn r1610) Remove trailing whitespace (last time ever, i hope)
tron
parents: 1090
diff changeset
   181
2180
c93b74122221 (svn r2694) Various smaller changes: eol-style, static, code simplification
tron
parents: 2177
diff changeset
   182
static uint32 GetTime(void)
c93b74122221 (svn r2694) Various smaller changes: eol-style, static, code simplification
tron
parents: 2177
diff changeset
   183
{
c93b74122221 (svn r2694) Various smaller changes: eol-style, static, code simplification
tron
parents: 2177
diff changeset
   184
	return GetTickCount();
543
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   185
}
2180
c93b74122221 (svn r2694) Various smaller changes: eol-style, static, code simplification
tron
parents: 2177
diff changeset
   186
543
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   187
#endif
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   188
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
   189
static void DedicatedHandleKeyInput(void)
704
e843dd369938 (svn r1154) -Add: [Network] Forked dedicated server (start openttd with -Df) (GeniusDex)
truelight
parents: 702
diff changeset
   190
{
721
617a397f8b4b (svn r1173) -Fix: [Network] Console input in dedicated server for windows was not
truelight
parents: 720
diff changeset
   191
	static char input_line[200] = "";
704
e843dd369938 (svn r1154) -Add: [Network] Forked dedicated server (start openttd with -Df) (GeniusDex)
truelight
parents: 702
diff changeset
   192
4599
79009a39da03 (svn r6449) -Fix (Win32): The dedicated server could overwrite the keyboard input buffer
Darkvater
parents: 4300
diff changeset
   193
	if (!InputWaiting()) return;
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
4599
79009a39da03 (svn r6449) -Fix (Win32): The dedicated server could overwrite the keyboard input buffer
Darkvater
parents: 4300
diff changeset
   195
	if (_exit_game) return;
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
   196
781
4c9177888196 (svn r1248) -Add: initial OS/2 support (read docs/ReadMe_OS2.txt) (orudge)
truelight
parents: 774
diff changeset
   197
#if defined(UNIX) || defined(__OS2__)
4891
90fed43ba450 (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
   198
	if (fgets(input_line, lengthof(input_line), stdin) == NULL) return;
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
#else
4599
79009a39da03 (svn r6449) -Fix (Win32): The dedicated server could overwrite the keyboard input buffer
Darkvater
parents: 4300
diff changeset
   200
	/* Handle console input, and singal console thread, it can accept input again */
79009a39da03 (svn r6449) -Fix (Win32): The dedicated server could overwrite the keyboard input buffer
Darkvater
parents: 4300
diff changeset
   201
	strncpy(input_line, _win_console_thread_buffer, lengthof(input_line));
79009a39da03 (svn r6449) -Fix (Win32): The dedicated server could overwrite the keyboard input buffer
Darkvater
parents: 4300
diff changeset
   202
	SetEvent(_hWaitForInputHandling);
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
   203
#endif
736
75bcef85daeb (svn r1188) -Fix: [Network] Fixed that CTRL+<key> could sometimes hang a dedicated
truelight
parents: 721
diff changeset
   204
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
   205
	/* 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
   206
	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
   207
	{ /* 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
   208
		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
   209
		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
   210
			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
   211
				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
   212
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
   213
			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
   214
				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
   215
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
   216
			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
   217
				input_line[i] = ' ';
704
e843dd369938 (svn r1154) -Add: [Network] Forked dedicated server (start openttd with -Df) (GeniusDex)
truelight
parents: 702
diff changeset
   218
		}
e843dd369938 (svn r1154) -Add: [Network] Forked dedicated server (start openttd with -Df) (GeniusDex)
truelight
parents: 702
diff changeset
   219
	}
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
   220
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
   221
	IConsoleCmdExec(input_line); // execute command
704
e843dd369938 (svn r1154) -Add: [Network] Forked dedicated server (start openttd with -Df) (GeniusDex)
truelight
parents: 702
diff changeset
   222
}
e843dd369938 (svn r1154) -Add: [Network] Forked dedicated server (start openttd with -Df) (GeniusDex)
truelight
parents: 702
diff changeset
   223
2228
93cdde0f85ba (svn r2748) Remove unused cruft from the main loop
tron
parents: 2210
diff changeset
   224
static void DedicatedVideoMainLoop(void)
704
e843dd369938 (svn r1154) -Add: [Network] Forked dedicated server (start openttd with -Df) (GeniusDex)
truelight
parents: 702
diff changeset
   225
{
5581
cf2b8ba6556b (svn r8028) -Fix: overflow of ticks was not handled properly, possibly resulting a non-reacting gameserver/gameclient.
rubidium
parents: 5475
diff changeset
   226
	uint32 cur_ticks = GetTime();
cf2b8ba6556b (svn r8028) -Fix: overflow of ticks was not handled properly, possibly resulting a non-reacting gameserver/gameclient.
rubidium
parents: 5475
diff changeset
   227
	uint32 next_tick = cur_ticks + 30;
543
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   228
770
c2eacca29601 (svn r1236) MorphOS: added make release like in OSX (tokai)
bjarni
parents: 736
diff changeset
   229
	/* Signal handlers */
702
5e80e4d69057 (svn r1152) -Add: [Network] Added signal handling (GeniusDex)
truelight
parents: 626
diff changeset
   230
#ifdef UNIX
5e80e4d69057 (svn r1152) -Add: [Network] Added signal handling (GeniusDex)
truelight
parents: 626
diff changeset
   231
	signal(SIGTERM, DedicatedSignalHandler);
5e80e4d69057 (svn r1152) -Add: [Network] Added signal handling (GeniusDex)
truelight
parents: 626
diff changeset
   232
	signal(SIGINT, DedicatedSignalHandler);
736
75bcef85daeb (svn r1188) -Fix: [Network] Fixed that CTRL+<key> could sometimes hang a dedicated
truelight
parents: 721
diff changeset
   233
	signal(SIGQUIT, DedicatedSignalHandler);
702
5e80e4d69057 (svn r1152) -Add: [Network] Added signal handling (GeniusDex)
truelight
parents: 626
diff changeset
   234
#endif
5e80e4d69057 (svn r1152) -Add: [Network] Added signal handling (GeniusDex)
truelight
parents: 626
diff changeset
   235
543
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   236
	// Load the dedicated server stuff
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   237
	_is_network_server = true;
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   238
	_network_dedicated = true;
4848
45f848b46222 (svn r6774) -Codechange: Rename the badly named OWNER_SPECTATOR to PLAYER_SPECTATOR and
Darkvater
parents: 4599
diff changeset
   239
	_network_playas = PLAYER_SPECTATOR;
45f848b46222 (svn r6774) -Codechange: Rename the badly named OWNER_SPECTATOR to PLAYER_SPECTATOR and
Darkvater
parents: 4599
diff changeset
   240
	_local_player = PLAYER_SPECTATOR;
1414
e7aa3a34712e (svn r1918) -Fix: [ 1101874 ] Dedicated server now accepts '-g' (load game) as param
truelight
parents: 1406
diff changeset
   241
e7aa3a34712e (svn r1918) -Fix: [ 1101874 ] Dedicated server now accepts '-g' (load game) as param
truelight
parents: 1406
diff changeset
   242
	/* 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
   243
	if (_switch_mode != SM_LOAD) {
4300
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 2791
diff changeset
   244
		StartNewGameWithoutGUI(GENERATE_NEW_SEED);
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 2791
diff changeset
   245
		SwitchMode(_switch_mode);
1414
e7aa3a34712e (svn r1918) -Fix: [ 1101874 ] Dedicated server now accepts '-g' (load game) as param
truelight
parents: 1406
diff changeset
   246
		_switch_mode = SM_NONE;
e7aa3a34712e (svn r1918) -Fix: [ 1101874 ] Dedicated server now accepts '-g' (load game) as param
truelight
parents: 1406
diff changeset
   247
	} else {
e7aa3a34712e (svn r1918) -Fix: [ 1101874 ] Dedicated server now accepts '-g' (load game) as param
truelight
parents: 1406
diff changeset
   248
		_switch_mode = SM_NONE;
e7aa3a34712e (svn r1918) -Fix: [ 1101874 ] Dedicated server now accepts '-g' (load game) as param
truelight
parents: 1406
diff changeset
   249
		/* 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
   250
		 *  intro game... */
e7aa3a34712e (svn r1918) -Fix: [ 1101874 ] Dedicated server now accepts '-g' (load game) as param
truelight
parents: 1406
diff changeset
   251
		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
   252
			/* Loading failed, pop out.. */
5380
8ea58542b6e0 (svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents: 5168
diff changeset
   253
			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
   254
			_networking = false;
e7aa3a34712e (svn r1918) -Fix: [ 1101874 ] Dedicated server now accepts '-g' (load game) as param
truelight
parents: 1406
diff changeset
   255
		} else {
e7aa3a34712e (svn r1918) -Fix: [ 1101874 ] Dedicated server now accepts '-g' (load game) as param
truelight
parents: 1406
diff changeset
   256
			/* 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
   257
			SwitchMode(SM_LOAD);
e7aa3a34712e (svn r1918) -Fix: [ 1101874 ] Dedicated server now accepts '-g' (load game) as param
truelight
parents: 1406
diff changeset
   258
		}
e7aa3a34712e (svn r1918) -Fix: [ 1101874 ] Dedicated server now accepts '-g' (load game) as param
truelight
parents: 1406
diff changeset
   259
	}
e7aa3a34712e (svn r1918) -Fix: [ 1101874 ] Dedicated server now accepts '-g' (load game) as param
truelight
parents: 1406
diff changeset
   260
543
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   261
	// Done loading, start game!
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
	if (!_networking) {
5380
8ea58542b6e0 (svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents: 5168
diff changeset
   264
		DEBUG(net, 0, "Dedicated server could not be started, aborting");
2228
93cdde0f85ba (svn r2748) Remove unused cruft from the main loop
tron
parents: 2210
diff changeset
   265
		return;
543
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   266
	}
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   267
2228
93cdde0f85ba (svn r2748) Remove unused cruft from the main loop
tron
parents: 2210
diff changeset
   268
	while (!_exit_game) {
5581
cf2b8ba6556b (svn r8028) -Fix: overflow of ticks was not handled properly, possibly resulting a non-reacting gameserver/gameclient.
rubidium
parents: 5475
diff changeset
   269
		uint32 prev_cur_ticks = cur_ticks; // to check for wrapping
543
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   270
		InteractiveRandom(); // randomness
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   271
704
e843dd369938 (svn r1154) -Add: [Network] Forked dedicated server (start openttd with -Df) (GeniusDex)
truelight
parents: 702
diff changeset
   272
		if (!_dedicated_forks)
e843dd369938 (svn r1154) -Add: [Network] Forked dedicated server (start openttd with -Df) (GeniusDex)
truelight
parents: 702
diff changeset
   273
			DedicatedHandleKeyInput();
543
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   274
2180
c93b74122221 (svn r2694) Various smaller changes: eol-style, static, code simplification
tron
parents: 2177
diff changeset
   275
		cur_ticks = GetTime();
5581
cf2b8ba6556b (svn r8028) -Fix: overflow of ticks was not handled properly, possibly resulting a non-reacting gameserver/gameclient.
rubidium
parents: 5475
diff changeset
   276
		if (cur_ticks >= next_tick || cur_ticks < prev_cur_ticks) {
cf2b8ba6556b (svn r8028) -Fix: overflow of ticks was not handled properly, possibly resulting a non-reacting gameserver/gameclient.
rubidium
parents: 5475
diff changeset
   277
			next_tick = cur_ticks + 30;
543
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   278
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   279
			GameLoop();
5587
167d9a91ef02 (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5584
diff changeset
   280
			_screen.dst_ptr = (Pixel*)_dedicated_video_mem;
543
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   281
			UpdateWindows();
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
		CSleep(1);
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   284
	}
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   285
}
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   286
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   287
const HalVideoDriver _dedicated_video_driver = {
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   288
	DedicatedVideoStart,
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   289
	DedicatedVideoStop,
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   290
	DedicatedVideoMakeDirty,
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   291
	DedicatedVideoMainLoop,
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   292
	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
   293
	DedicatedVideoFullScreen,
543
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff changeset
   294
};
2195
ed135f2dc5f8 (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
   295
ed135f2dc5f8 (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
   296
#endif /* ENABLE_NETWORK */