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
|
|
|
|
|
|
|
|
*/
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
# include "config.h"
|
|
|
|
#endif
|
|
|
|
|
2003-01-15 15:31:36 +00:00
|
|
|
static __attribute__ ((unused)) const char rcsid[] =
|
|
|
|
"$Id$";
|
|
|
|
|
2001-02-19 21:15:25 +00:00
|
|
|
#include "winquake.h"
|
2002-08-20 19:16:11 +00:00
|
|
|
#include "win32/resources/resource.h"
|
2001-04-10 23:17:47 +00:00
|
|
|
|
2001-09-28 16:53:11 +00:00
|
|
|
#include "QF/console.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"
|
2002-08-27 07:16:28 +00:00
|
|
|
#include "QF/quakeio.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"
|
|
|
|
|
|
|
|
#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
|
2002-07-02 20:34:51 +00:00
|
|
|
// 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;
|
|
|
|
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;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-08-27 07:13:32 +00:00
|
|
|
// SYSTEM IO ==================================================================
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2003-01-06 18:28:13 +00:00
|
|
|
static void
|
2002-06-07 15:46:15 +00:00
|
|
|
startup (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
|
|
|
|
2002-08-20 23:04:57 +00:00
|
|
|
Sys_MaskFPUExceptions ();
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
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-09-24 21:00:23 +00:00
|
|
|
static void
|
|
|
|
shutdown (void)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
|
|
|
if (tevent)
|
|
|
|
CloseHandle (tevent);
|
|
|
|
}
|
|
|
|
|
2001-08-27 07:13:32 +00:00
|
|
|
// WINDOWS CRAP ===============================================================
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2003-01-06 18:28:13 +00:00
|
|
|
static void
|
2001-02-26 06:48:02 +00:00
|
|
|
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;
|
2003-01-06 18:28:13 +00:00
|
|
|
const char *argv[MAX_NUM_ARGVS];
|
|
|
|
static const char *empty_string = "";
|
2001-02-26 06:48:02 +00:00
|
|
|
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
|
|
|
double time, oldtime, newtime;
|
|
|
|
MEMORYSTATUS lpBuffer;
|
|
|
|
static char cwd[1024];
|
|
|
|
RECT rect;
|
|
|
|
|
2002-07-02 20:34:51 +00:00
|
|
|
// previous instances do not exist in Win32
|
2001-02-26 06:48:02 +00:00
|
|
|
if (hPrevInstance)
|
|
|
|
return 0;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2002-06-07 15:46:15 +00:00
|
|
|
startup ();
|
|
|
|
|
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
|
|
|
|
2002-02-19 20:47:45 +00:00
|
|
|
host_parms.argc = 1;
|
2001-02-19 21:15:25 +00:00
|
|
|
argv[0] = empty_string;
|
|
|
|
|
2002-02-19 20:47:45 +00:00
|
|
|
while (*lpCmdLine && (host_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) {
|
2002-02-19 20:47:45 +00:00
|
|
|
argv[host_parms.argc] = lpCmdLine;
|
|
|
|
host_parms.argc++;
|
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
|
|
|
*lpCmdLine = 0;
|
|
|
|
lpCmdLine++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-01-06 18:28:13 +00:00
|
|
|
COM_InitArgv (host_parms.argc, argv);
|
2002-02-19 20:47:45 +00:00
|
|
|
host_parms.argc = com_argc;
|
|
|
|
host_parms.argv = com_argv;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
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-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");
|
|
|
|
|
2002-05-14 21:30:23 +00:00
|
|
|
Host_Init ();
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-09-24 21:00:23 +00:00
|
|
|
Sys_RegisterShutdown (Host_Shutdown);
|
|
|
|
Sys_RegisterShutdown (shutdown);
|
|
|
|
|
2001-02-19 21:15:25 +00:00
|
|
|
oldtime = Sys_DoubleTime ();
|
|
|
|
|
2002-07-02 20:34:51 +00:00
|
|
|
// main window message loop
|
2001-02-26 06:48:02 +00:00
|
|
|
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
|
2002-07-03 20:47:45 +00:00
|
|
|
if ((cl.paused && !ActiveApp) || Minimized
|
2001-02-26 06:48:02 +00:00
|
|
|
|| block_drawing) {
|
2001-02-19 21:15:25 +00:00
|
|
|
SleepUntilInput (PAUSE_SLEEP);
|
|
|
|
scr_skipupdate = 1; // no point in bothering to draw
|
2002-07-02 20:34:51 +00:00
|
|
|
} else if (!ActiveApp) {
|
2001-02-19 21:15:25 +00:00
|
|
|
SleepUntilInput (NOT_FOCUS_SLEEP);
|
|
|
|
}
|
|
|
|
|
|
|
|
newtime = Sys_DoubleTime ();
|
|
|
|
time = newtime - oldtime;
|
|
|
|
}
|
|
|
|
|
|
|
|
Host_Frame (time);
|
|
|
|
oldtime = newtime;
|
|
|
|
}
|
|
|
|
|
2002-07-02 20:34:51 +00:00
|
|
|
// return success of application
|
2001-02-26 06:48:02 +00:00
|
|
|
return TRUE;
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|