2001-02-19 21:15:25 +00:00
|
|
|
/*
|
|
|
|
sys_win.c
|
|
|
|
|
|
|
|
@description@
|
|
|
|
|
|
|
|
Copyright (C) 1996-1997 Id Software, Inc.
|
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or
|
|
|
|
modify it under the terms of the GNU General Public License
|
|
|
|
as published by the Free Software Foundation; either version 2
|
|
|
|
of the License, or (at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
|
|
|
|
|
|
See the GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program; if not, write to:
|
|
|
|
|
|
|
|
Free Software Foundation, Inc.
|
|
|
|
59 Temple Place - Suite 330
|
|
|
|
Boston, MA 02111-1307, USA
|
|
|
|
|
|
|
|
$Id$
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
# include "config.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "winquake.h"
|
|
|
|
#include "conproc.h"
|
2001-04-10 23:17:47 +00:00
|
|
|
#include "resource.h"
|
|
|
|
|
2001-06-01 00:39:31 +00:00
|
|
|
#include "QF/cvar.h"
|
2001-04-10 23:17:47 +00:00
|
|
|
#include "QF/qargs.h"
|
2001-05-30 04:34:06 +00:00
|
|
|
#include "QF/screen.h"
|
2001-04-10 23:17:47 +00:00
|
|
|
#include "QF/sys.h"
|
2001-05-30 04:34:06 +00:00
|
|
|
#include "QF/vfile.h"
|
2001-04-10 23:17:47 +00:00
|
|
|
|
|
|
|
#include "client.h"
|
2001-06-01 00:39:31 +00:00
|
|
|
#include "compat.h"
|
2001-04-10 23:17:47 +00:00
|
|
|
#include "game.h"
|
|
|
|
#include "host.h"
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
#define MINIMUM_WIN_MEMORY 0x0880000
|
|
|
|
#define MAXIMUM_WIN_MEMORY 0x1000000
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
#define CONSOLE_ERROR_TIMEOUT 60.0 // # of seconds to wait on Sys_Error
|
|
|
|
// running
|
|
|
|
// dedicated before exiting
|
|
|
|
#define PAUSE_SLEEP 50 // sleep time on pause or
|
|
|
|
// minimization
|
2001-02-19 21:15:25 +00:00
|
|
|
#define NOT_FOCUS_SLEEP 20 // sleep time when not focus
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
qboolean ActiveApp, Minimized;
|
|
|
|
qboolean WinNT;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
static double pfreq;
|
|
|
|
static int lowshift;
|
|
|
|
qboolean isDedicated;
|
|
|
|
static qboolean sc_return_on_enter = false;
|
|
|
|
HANDLE hinput, houtput;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-04-10 23:17:47 +00:00
|
|
|
static const char tracking_tag[] = "Clams & Mooses";
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
static HANDLE tevent;
|
|
|
|
static HANDLE hFile;
|
|
|
|
static HANDLE heventParent;
|
|
|
|
static HANDLE heventChild;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
void MaskExceptions (void);
|
|
|
|
void Sys_PushFPCW_SetHigh (void);
|
|
|
|
void Sys_PopFPCW (void);
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
volatile int sys_checksum;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
void
|
|
|
|
Sys_PageIn (void *ptr, int size)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
2001-02-26 06:48:02 +00:00
|
|
|
byte *x;
|
2001-04-10 23:17:47 +00:00
|
|
|
int m, n;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-08-27 07:13:32 +00:00
|
|
|
// touch all the memory to make sure it's there. The 16-page skip is to
|
|
|
|
// keep Win 95 from thinking we're trying to page ourselves in (we are
|
|
|
|
// doing that, of course, but there's no reason we shouldn't)
|
2001-02-26 06:48:02 +00:00
|
|
|
x = (byte *) ptr;
|
|
|
|
|
|
|
|
for (n = 0; n < 4; n++) {
|
|
|
|
for (m = 0; m < (size - 16 * 0x1000); m += 4) {
|
|
|
|
sys_checksum += *(int *) &x[m];
|
|
|
|
sys_checksum += *(int *) &x[m + 16 * 0x1000];
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-08-27 07:13:32 +00:00
|
|
|
// FILE IO ====================================================================
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
#define MAX_HANDLES 10
|
2001-05-30 03:21:19 +00:00
|
|
|
VFile *sys_handles[MAX_HANDLES];
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
int
|
|
|
|
findhandle (void)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
2001-02-26 06:48:02 +00:00
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 1; i < MAX_HANDLES; i++)
|
2001-02-19 21:15:25 +00:00
|
|
|
if (!sys_handles[i])
|
|
|
|
return i;
|
|
|
|
Sys_Error ("out of handles");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2001-08-27 07:13:32 +00:00
|
|
|
// SYSTEM IO ==================================================================
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-06-08 02:47:30 +00:00
|
|
|
#ifndef USE_INTEL_ASM
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
void
|
|
|
|
Sys_SetFPCW (void)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
void
|
|
|
|
Sys_PushFPCW_SetHigh (void)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
void
|
|
|
|
Sys_PopFPCW (void)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
void
|
|
|
|
MaskExceptions (void)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
void
|
|
|
|
Sys_Init (void)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
2001-02-26 06:48:02 +00:00
|
|
|
LARGE_INTEGER PerformanceFreq;
|
|
|
|
unsigned int lowpart, highpart;
|
|
|
|
OSVERSIONINFO vinfo;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
MaskExceptions ();
|
|
|
|
Sys_SetFPCW ();
|
|
|
|
|
|
|
|
if (!QueryPerformanceFrequency (&PerformanceFreq))
|
|
|
|
Sys_Error ("No hardware timer available");
|
|
|
|
|
2001-08-27 07:13:32 +00:00
|
|
|
// get 32 out of the 64 time bits such that we have around
|
|
|
|
// 1 microsecond resolution
|
2001-02-26 06:48:02 +00:00
|
|
|
lowpart = (unsigned int) PerformanceFreq.LowPart;
|
|
|
|
highpart = (unsigned int) PerformanceFreq.HighPart;
|
2001-02-19 21:15:25 +00:00
|
|
|
lowshift = 0;
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
while (highpart || (lowpart > 2000000.0)) {
|
2001-02-19 21:15:25 +00:00
|
|
|
lowshift++;
|
|
|
|
lowpart >>= 1;
|
|
|
|
lowpart |= (highpart & 1) << 31;
|
|
|
|
highpart >>= 1;
|
|
|
|
}
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
pfreq = 1.0 / (double) lowpart;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
vinfo.dwOSVersionInfoSize = sizeof (vinfo);
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
if (!GetVersionEx (&vinfo))
|
|
|
|
Sys_Error ("Couldn't get OS info");
|
|
|
|
|
|
|
|
if ((vinfo.dwMajorVersion < 4) ||
|
2001-02-26 06:48:02 +00:00
|
|
|
(vinfo.dwPlatformId == VER_PLATFORM_WIN32s)) {
|
2001-02-19 21:15:25 +00:00
|
|
|
Sys_Error ("WinQuake requires at least Win95 or NT 4.0");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (vinfo.dwPlatformId == VER_PLATFORM_WIN32_NT)
|
|
|
|
WinNT = true;
|
|
|
|
else
|
|
|
|
WinNT = false;
|
|
|
|
}
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
void
|
2001-04-10 23:17:47 +00:00
|
|
|
Sys_Error (const char *error, ...)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
2001-02-26 06:48:02 +00:00
|
|
|
va_list argptr;
|
|
|
|
char text[1024], text2[1024];
|
|
|
|
char *text3 = "Press Enter to exit\n";
|
|
|
|
char *text4 = "***********************************\n";
|
|
|
|
char *text5 = "\n";
|
|
|
|
DWORD dummy;
|
|
|
|
double starttime;
|
|
|
|
static int in_sys_error0 = 0;
|
|
|
|
static int in_sys_error1 = 0;
|
|
|
|
static int in_sys_error2 = 0;
|
|
|
|
static int in_sys_error3 = 0;
|
|
|
|
|
|
|
|
if (!in_sys_error3) {
|
2001-02-19 21:15:25 +00:00
|
|
|
in_sys_error3 = 1;
|
|
|
|
VID_ForceUnlockedAndReturnState ();
|
|
|
|
}
|
|
|
|
|
|
|
|
va_start (argptr, error);
|
2001-02-26 06:48:02 +00:00
|
|
|
vsnprintf (text, sizeof (text), error, argptr);
|
2001-02-19 21:15:25 +00:00
|
|
|
va_end (argptr);
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
if (isDedicated) {
|
2001-02-19 21:15:25 +00:00
|
|
|
va_start (argptr, error);
|
2001-02-26 06:48:02 +00:00
|
|
|
vsnprintf (text, sizeof (text), error, argptr);
|
2001-02-19 21:15:25 +00:00
|
|
|
va_end (argptr);
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
snprintf (text2, sizeof (text2), "ERROR: %s\n", text);
|
2001-02-19 21:15:25 +00:00
|
|
|
WriteFile (houtput, text5, strlen (text5), &dummy, NULL);
|
|
|
|
WriteFile (houtput, text4, strlen (text4), &dummy, NULL);
|
|
|
|
WriteFile (houtput, text2, strlen (text2), &dummy, NULL);
|
|
|
|
WriteFile (houtput, text3, strlen (text3), &dummy, NULL);
|
|
|
|
WriteFile (houtput, text4, strlen (text4), &dummy, NULL);
|
|
|
|
|
|
|
|
starttime = Sys_DoubleTime ();
|
2001-02-26 06:48:02 +00:00
|
|
|
sc_return_on_enter = true; // so Enter will get us out of here
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
while (!Sys_ConsoleInput () &&
|
2001-02-26 06:48:02 +00:00
|
|
|
((Sys_DoubleTime () - starttime) < CONSOLE_ERROR_TIMEOUT)) {
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
2001-02-26 06:48:02 +00:00
|
|
|
} else {
|
|
|
|
// switch to windowed so the message box is visible, unless we
|
2001-08-27 07:13:32 +00:00
|
|
|
// already tried that and failed
|
2001-02-26 06:48:02 +00:00
|
|
|
if (!in_sys_error0) {
|
2001-02-19 21:15:25 +00:00
|
|
|
in_sys_error0 = 1;
|
|
|
|
VID_SetDefaultMode ();
|
2001-02-26 06:48:02 +00:00
|
|
|
MessageBox (NULL, text, "Quake Error",
|
|
|
|
MB_OK | MB_SETFOREGROUND | MB_ICONSTOP);
|
|
|
|
} else {
|
|
|
|
MessageBox (NULL, text, "Double Quake Error",
|
|
|
|
MB_OK | MB_SETFOREGROUND | MB_ICONSTOP);
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
if (!in_sys_error1) {
|
2001-02-19 21:15:25 +00:00
|
|
|
in_sys_error1 = 1;
|
|
|
|
Host_Shutdown ();
|
|
|
|
}
|
2001-08-27 07:13:32 +00:00
|
|
|
// shut down QHOST hooks if necessary
|
2001-02-26 06:48:02 +00:00
|
|
|
if (!in_sys_error2) {
|
2001-02-19 21:15:25 +00:00
|
|
|
in_sys_error2 = 1;
|
|
|
|
DeinitConProc ();
|
|
|
|
}
|
|
|
|
|
|
|
|
exit (1);
|
|
|
|
}
|
2001-02-26 06:48:02 +00:00
|
|
|
|
|
|
|
void
|
|
|
|
Sys_Quit (void)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
|
|
|
|
|
|
|
VID_ForceUnlockedAndReturnState ();
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
Host_Shutdown ();
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
if (tevent)
|
|
|
|
CloseHandle (tevent);
|
|
|
|
|
|
|
|
if (isDedicated)
|
|
|
|
FreeConsole ();
|
|
|
|
|
2001-08-27 07:13:32 +00:00
|
|
|
// shut down QHOST hooks if necessary
|
2001-02-19 21:15:25 +00:00
|
|
|
DeinitConProc ();
|
|
|
|
|
|
|
|
exit (0);
|
|
|
|
}
|
|
|
|
|
2001-08-02 23:00:39 +00:00
|
|
|
const char *
|
2001-02-26 06:48:02 +00:00
|
|
|
Sys_ConsoleInput (void)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
2001-02-26 06:48:02 +00:00
|
|
|
static char text[256];
|
|
|
|
static int len;
|
|
|
|
INPUT_RECORD recs[1024];
|
2001-04-10 23:17:47 +00:00
|
|
|
DWORD dummy;
|
|
|
|
int ch;
|
|
|
|
DWORD numread;
|
|
|
|
DWORD numevents;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
if (!isDedicated)
|
|
|
|
return NULL;
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
for (;;) {
|
2001-02-19 21:15:25 +00:00
|
|
|
if (!GetNumberOfConsoleInputEvents (hinput, &numevents))
|
|
|
|
Sys_Error ("Error getting # of console events");
|
|
|
|
|
|
|
|
if (numevents <= 0)
|
|
|
|
break;
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
if (!ReadConsoleInput (hinput, recs, 1, &numread))
|
2001-02-19 21:15:25 +00:00
|
|
|
Sys_Error ("Error reading console input");
|
|
|
|
|
|
|
|
if (numread != 1)
|
|
|
|
Sys_Error ("Couldn't read console input");
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
if (recs[0].EventType == KEY_EVENT) {
|
|
|
|
if (!recs[0].Event.KeyEvent.bKeyDown) {
|
2001-02-19 21:15:25 +00:00
|
|
|
ch = recs[0].Event.KeyEvent.uChar.AsciiChar;
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
switch (ch) {
|
2001-08-27 07:13:32 +00:00
|
|
|
case '\r':
|
2001-02-26 06:48:02 +00:00
|
|
|
WriteFile (houtput, "\r\n", 2, &dummy, NULL);
|
|
|
|
|
|
|
|
if (len) {
|
|
|
|
text[len] = 0;
|
|
|
|
len = 0;
|
|
|
|
return text;
|
|
|
|
} else if (sc_return_on_enter) {
|
|
|
|
// special case to allow exiting from the error
|
|
|
|
// handler on Enter
|
|
|
|
text[0] = '\r';
|
|
|
|
len = 0;
|
|
|
|
return text;
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-08-27 07:13:32 +00:00
|
|
|
case '\b':
|
2001-02-26 06:48:02 +00:00
|
|
|
WriteFile (houtput, "\b \b", 3, &dummy, NULL);
|
|
|
|
if (len) {
|
|
|
|
len--;
|
|
|
|
}
|
|
|
|
break;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-08-27 07:13:32 +00:00
|
|
|
default:
|
2001-02-26 06:48:02 +00:00
|
|
|
if (ch >= ' ') {
|
|
|
|
WriteFile (houtput, &ch, 1, &dummy, NULL);
|
|
|
|
text[len] = ch;
|
|
|
|
len = (len + 1) & 0xff;
|
|
|
|
}
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
break;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2001-08-27 07:13:32 +00:00
|
|
|
// WINDOWS CRAP ===============================================================
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
void
|
|
|
|
SleepUntilInput (int time)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
2001-02-26 06:48:02 +00:00
|
|
|
MsgWaitForMultipleObjects (1, &tevent, FALSE, time, QS_ALLINPUT);
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
HINSTANCE global_hInstance;
|
|
|
|
int global_nCmdShow;
|
|
|
|
char *argv[MAX_NUM_ARGVS];
|
|
|
|
static char *empty_string = "";
|
|
|
|
HWND hwnd_dialog;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
int WINAPI
|
|
|
|
WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine,
|
|
|
|
int nCmdShow)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
2001-02-26 06:48:02 +00:00
|
|
|
quakeparms_t parms;
|
|
|
|
double time, oldtime, newtime;
|
|
|
|
MEMORYSTATUS lpBuffer;
|
|
|
|
static char cwd[1024];
|
|
|
|
int t;
|
|
|
|
RECT rect;
|
|
|
|
|
|
|
|
/* previous instances do not exist in Win32 */
|
|
|
|
if (hPrevInstance)
|
|
|
|
return 0;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
global_hInstance = hInstance;
|
|
|
|
global_nCmdShow = nCmdShow;
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
lpBuffer.dwLength = sizeof (MEMORYSTATUS);
|
2001-02-19 21:15:25 +00:00
|
|
|
GlobalMemoryStatus (&lpBuffer);
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
if (!GetCurrentDirectory (sizeof (cwd), cwd))
|
2001-02-19 21:15:25 +00:00
|
|
|
Sys_Error ("Couldn't determine current directory");
|
|
|
|
|
2001-04-10 23:17:47 +00:00
|
|
|
if (cwd[strlen (cwd) - 1] == '/')
|
|
|
|
cwd[strlen (cwd) - 1] = 0;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
parms.argc = 1;
|
|
|
|
argv[0] = empty_string;
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
while (*lpCmdLine && (parms.argc < MAX_NUM_ARGVS)) {
|
2001-02-19 21:15:25 +00:00
|
|
|
while (*lpCmdLine && ((*lpCmdLine <= 32) || (*lpCmdLine > 126)))
|
|
|
|
lpCmdLine++;
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
if (*lpCmdLine) {
|
2001-02-19 21:15:25 +00:00
|
|
|
argv[parms.argc] = lpCmdLine;
|
|
|
|
parms.argc++;
|
|
|
|
|
|
|
|
while (*lpCmdLine && ((*lpCmdLine > 32) && (*lpCmdLine <= 126)))
|
|
|
|
lpCmdLine++;
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
if (*lpCmdLine) {
|
2001-02-19 21:15:25 +00:00
|
|
|
*lpCmdLine = 0;
|
|
|
|
lpCmdLine++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
parms.argv = argv;
|
|
|
|
|
2001-08-02 23:00:39 +00:00
|
|
|
COM_InitArgv (parms.argc, (const char**)parms.argv);
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
parms.argc = com_argc;
|
|
|
|
parms.argv = com_argv;
|
|
|
|
|
|
|
|
isDedicated = (COM_CheckParm ("-dedicated") != 0);
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
if (!isDedicated) {
|
2001-08-27 07:13:32 +00:00
|
|
|
hwnd_dialog = CreateDialog (hInstance, MAKEINTRESOURCE (IDD_DIALOG1),
|
|
|
|
NULL, NULL);
|
2001-02-26 06:48:02 +00:00
|
|
|
|
|
|
|
if (hwnd_dialog) {
|
|
|
|
if (GetWindowRect (hwnd_dialog, &rect)) {
|
|
|
|
if (rect.left > (rect.top * 2)) {
|
2001-02-19 21:15:25 +00:00
|
|
|
SetWindowPos (hwnd_dialog, 0,
|
2001-02-26 06:48:02 +00:00
|
|
|
(rect.left / 2) -
|
|
|
|
((rect.right - rect.left) / 2), rect.top, 0,
|
|
|
|
0, SWP_NOZORDER | SWP_NOSIZE);
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ShowWindow (hwnd_dialog, SW_SHOWDEFAULT);
|
|
|
|
UpdateWindow (hwnd_dialog);
|
|
|
|
SetForegroundWindow (hwnd_dialog);
|
|
|
|
}
|
|
|
|
}
|
2001-08-27 07:13:32 +00:00
|
|
|
// take the greater of all the available memory or half the total memory,
|
|
|
|
// but at least 8 Mb and no more than 16 Mb, unless they explicitly
|
|
|
|
// request otherwise
|
2001-02-19 21:15:25 +00:00
|
|
|
parms.memsize = lpBuffer.dwAvailPhys;
|
|
|
|
|
|
|
|
if (parms.memsize < MINIMUM_WIN_MEMORY)
|
|
|
|
parms.memsize = MINIMUM_WIN_MEMORY;
|
|
|
|
|
|
|
|
if (parms.memsize < (lpBuffer.dwTotalPhys >> 1))
|
|
|
|
parms.memsize = lpBuffer.dwTotalPhys >> 1;
|
|
|
|
|
|
|
|
if (parms.memsize > MAXIMUM_WIN_MEMORY)
|
|
|
|
parms.memsize = MAXIMUM_WIN_MEMORY;
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
if (COM_CheckParm ("-heapsize")) {
|
|
|
|
t = COM_CheckParm ("-heapsize") + 1;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
if (t < com_argc)
|
2001-04-10 23:17:47 +00:00
|
|
|
parms.memsize = atoi (com_argv[t]) * 1024;
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
parms.membase = malloc (parms.memsize);
|
|
|
|
|
|
|
|
if (!parms.membase)
|
|
|
|
Sys_Error ("Not enough memory free; check disk space\n");
|
|
|
|
|
|
|
|
Sys_PageIn (parms.membase, parms.memsize);
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
tevent = CreateEvent (NULL, FALSE, FALSE, NULL);
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
if (!tevent)
|
|
|
|
Sys_Error ("Couldn't create event");
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
if (isDedicated) {
|
|
|
|
if (!AllocConsole ()) {
|
2001-02-19 21:15:25 +00:00
|
|
|
Sys_Error ("Couldn't create dedicated server console");
|
|
|
|
}
|
|
|
|
|
|
|
|
hinput = GetStdHandle (STD_INPUT_HANDLE);
|
|
|
|
houtput = GetStdHandle (STD_OUTPUT_HANDLE);
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
// give QHOST a chance to hook into the console
|
|
|
|
if ((t = COM_CheckParm ("-HFILE")) > 0) {
|
2001-02-19 21:15:25 +00:00
|
|
|
if (t < com_argc)
|
2001-04-10 23:17:47 +00:00
|
|
|
hFile = (HANDLE) atoi (com_argv[t + 1]);
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
2001-02-26 06:48:02 +00:00
|
|
|
|
|
|
|
if ((t = COM_CheckParm ("-HPARENT")) > 0) {
|
2001-02-19 21:15:25 +00:00
|
|
|
if (t < com_argc)
|
2001-04-10 23:17:47 +00:00
|
|
|
heventParent = (HANDLE) atoi (com_argv[t + 1]);
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
2001-02-26 06:48:02 +00:00
|
|
|
|
|
|
|
if ((t = COM_CheckParm ("-HCHILD")) > 0) {
|
2001-02-19 21:15:25 +00:00
|
|
|
if (t < com_argc)
|
2001-04-10 23:17:47 +00:00
|
|
|
heventChild = (HANDLE) atoi (com_argv[t + 1]);
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
InitConProc (hFile, heventParent, heventChild);
|
|
|
|
}
|
|
|
|
|
|
|
|
Sys_Init ();
|
|
|
|
|
|
|
|
// because sound is off until we become active
|
2001-05-22 19:13:23 +00:00
|
|
|
//XXX S_BlockSound ();
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
Sys_Printf ("Host_Init\n");
|
|
|
|
Host_Init (&parms);
|
|
|
|
|
2001-08-29 17:45:53 +00:00
|
|
|
Sys_Init_Cvars ();
|
|
|
|
Sys_Init ();
|
|
|
|
|
2001-02-19 21:15:25 +00:00
|
|
|
oldtime = Sys_DoubleTime ();
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
/* main window message loop */
|
|
|
|
while (1) {
|
|
|
|
if (isDedicated) {
|
2001-02-19 21:15:25 +00:00
|
|
|
newtime = Sys_DoubleTime ();
|
|
|
|
time = newtime - oldtime;
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
while (time < sys_ticrate->value) {
|
2001-08-29 17:45:53 +00:00
|
|
|
Sleep (1);
|
2001-02-19 21:15:25 +00:00
|
|
|
newtime = Sys_DoubleTime ();
|
|
|
|
time = newtime - oldtime;
|
|
|
|
}
|
2001-02-26 06:48:02 +00:00
|
|
|
} else {
|
|
|
|
// yield the CPU for a little while when paused, minimized, or
|
|
|
|
// not the focus
|
|
|
|
if ((cl.paused && (!ActiveApp && !DDActive)) || Minimized
|
|
|
|
|| block_drawing) {
|
2001-02-19 21:15:25 +00:00
|
|
|
SleepUntilInput (PAUSE_SLEEP);
|
|
|
|
scr_skipupdate = 1; // no point in bothering to draw
|
2001-02-26 06:48:02 +00:00
|
|
|
} else if (!ActiveApp && !DDActive) {
|
2001-02-19 21:15:25 +00:00
|
|
|
SleepUntilInput (NOT_FOCUS_SLEEP);
|
|
|
|
}
|
|
|
|
|
|
|
|
newtime = Sys_DoubleTime ();
|
|
|
|
time = newtime - oldtime;
|
|
|
|
}
|
|
|
|
|
|
|
|
Host_Frame (time);
|
|
|
|
oldtime = newtime;
|
|
|
|
}
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
/* return success of application */
|
|
|
|
return TRUE;
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
2001-04-11 21:55:27 +00:00
|
|
|
|
|
|
|
void
|
2001-08-02 23:00:39 +00:00
|
|
|
Sys_DebugLog (const char *file, const char *fmt, ...)
|
2001-04-11 21:55:27 +00:00
|
|
|
{
|
|
|
|
}
|