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
|
|
|
|
|
|
|
|
#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-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"
|
|
|
|
|
2020-06-21 14:15:17 +00:00
|
|
|
#include "nq/include/client.h"
|
|
|
|
#include "nq/include/host.h"
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2023-06-13 09:06:11 +00:00
|
|
|
bool isDedicated = false;
|
2011-09-03 10:58:03 +00:00
|
|
|
|
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
|
|
|
|
|
2023-06-13 09:06:11 +00:00
|
|
|
bool ActiveApp, Minimized;
|
|
|
|
bool WinNT;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
static double pfreq;
|
|
|
|
static int lowshift;
|
|
|
|
HANDLE hinput, houtput;
|
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
|
2020-03-21 13:24:11 +00:00
|
|
|
shutdown_f (void *data)
|
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
|
|
|
|
2011-09-03 10:58:03 +00:00
|
|
|
static void
|
|
|
|
init_handles (HINSTANCE hInstance)
|
|
|
|
{
|
|
|
|
RECT rect;
|
|
|
|
|
|
|
|
if (!isDedicated) {
|
|
|
|
hwnd_dialog = CreateDialog (hInstance, MAKEINTRESOURCE (IDD_DIALOG1),
|
|
|
|
NULL, NULL);
|
|
|
|
|
|
|
|
if (hwnd_dialog) {
|
|
|
|
if (GetWindowRect (hwnd_dialog, &rect)) {
|
|
|
|
if (rect.left > (rect.top * 2)) {
|
|
|
|
SetWindowPos (hwnd_dialog, 0,
|
|
|
|
(rect.left / 2) -
|
|
|
|
((rect.right - rect.left) / 2), rect.top, 0,
|
|
|
|
0, SWP_NOZORDER | SWP_NOSIZE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ShowWindow (hwnd_dialog, SW_SHOWDEFAULT);
|
|
|
|
UpdateWindow (hwnd_dialog);
|
|
|
|
SetForegroundWindow (hwnd_dialog);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
tevent = CreateEvent (NULL, FALSE, FALSE, NULL);
|
|
|
|
|
|
|
|
if (!tevent)
|
|
|
|
Sys_Error ("Couldn't create event");
|
|
|
|
}
|
|
|
|
|
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;
|
2011-09-03 10:58:03 +00:00
|
|
|
int argc;
|
2001-02-26 06:48:02 +00:00
|
|
|
|
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);
|
|
|
|
|
2011-09-03 10:58:03 +00:00
|
|
|
argc = 1;
|
2001-02-19 21:15:25 +00:00
|
|
|
argv[0] = empty_string;
|
|
|
|
|
2011-09-03 10:58:03 +00:00
|
|
|
while (*lpCmdLine && (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) {
|
2011-09-03 10:58:03 +00:00
|
|
|
argv[argc] = lpCmdLine;
|
|
|
|
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++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-09-03 10:58:03 +00:00
|
|
|
memset (&host_parms, 0, sizeof (host_parms));
|
|
|
|
|
|
|
|
COM_InitArgv (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);
|
|
|
|
|
2011-09-03 10:58:03 +00:00
|
|
|
if (!isDedicated)
|
|
|
|
init_handles (hInstance);
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2020-03-21 13:24:11 +00:00
|
|
|
Sys_RegisterShutdown (shutdown_f, 0);
|
2001-09-24 21:00:23 +00:00
|
|
|
|
2011-09-03 10:58:03 +00:00
|
|
|
Host_Init ();
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2011-09-03 10:58:03 +00:00
|
|
|
oldtime = Sys_DoubleTime () - 0.1;
|
|
|
|
while (1) { // Main message loop
|
|
|
|
if (!isDedicated) {
|
2001-02-26 06:48:02 +00:00
|
|
|
// yield the CPU for a little while when paused, minimized, or
|
|
|
|
// not the focus
|
2004-02-15 03:40:50 +00:00
|
|
|
if ((cl.paused && !ActiveApp) || Minimized) {
|
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);
|
|
|
|
}
|
2011-09-03 10:58:03 +00:00
|
|
|
}
|
|
|
|
// find time spent rendering last frame
|
|
|
|
newtime = Sys_DoubleTime ();
|
|
|
|
time = newtime - oldtime;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2022-04-06 10:32:55 +00:00
|
|
|
if (net_is_dedicated) { // play vcrfiles at max speed
|
[cvar] Make cvars properly typed
This is an extremely extensive patch as it hits every cvar, and every
usage of the cvars. Cvars no longer store the value they control,
instead, they use a cexpr value object to reference the value and
specify the value's type (currently, a null type is used for strings).
Non-string cvars are passed through cexpr, allowing expressions in the
cvars' settings. Also, cvars have returned to an enhanced version of the
original (id quake) registration scheme.
As a minor benefit, relevant code having direct access to the
cvar-controlled variables is probably a slight optimization as it
removed a pointer dereference, and the variables can be located for data
locality.
The static cvar descriptors are made private as an additional safety
layer, though there's nothing stopping external modification via
Cvar_FindVar (which is needed for adding listeners).
While not used yet (partly due to working out the design), cvars can
have a validation function.
Registering a cvar allows a primary listener (and its data) to be
specified: it will always be called first when the cvar is modified. The
combination of proper listeners and direct access to the controlled
variable greatly simplifies the more complex cvar interactions as much
less null checking is required, and there's no need for one cvar's
callback to call another's.
nq-x11 is known to work at least well enough for the demos. More testing
will come.
2022-04-23 03:22:45 +00:00
|
|
|
if (time < sys_ticrate && (!vcrFile || recording)) {
|
2011-09-03 10:58:03 +00:00
|
|
|
Sleep (1);
|
|
|
|
continue; // not time to run a server-only tic yet
|
|
|
|
}
|
[cvar] Make cvars properly typed
This is an extremely extensive patch as it hits every cvar, and every
usage of the cvars. Cvars no longer store the value they control,
instead, they use a cexpr value object to reference the value and
specify the value's type (currently, a null type is used for strings).
Non-string cvars are passed through cexpr, allowing expressions in the
cvars' settings. Also, cvars have returned to an enhanced version of the
original (id quake) registration scheme.
As a minor benefit, relevant code having direct access to the
cvar-controlled variables is probably a slight optimization as it
removed a pointer dereference, and the variables can be located for data
locality.
The static cvar descriptors are made private as an additional safety
layer, though there's nothing stopping external modification via
Cvar_FindVar (which is needed for adding listeners).
While not used yet (partly due to working out the design), cvars can
have a validation function.
Registering a cvar allows a primary listener (and its data) to be
specified: it will always be called first when the cvar is modified. The
combination of proper listeners and direct access to the controlled
variable greatly simplifies the more complex cvar interactions as much
less null checking is required, and there's no need for one cvar's
callback to call another's.
nq-x11 is known to work at least well enough for the demos. More testing
will come.
2022-04-23 03:22:45 +00:00
|
|
|
time = sys_ticrate;
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
|
|
|
|
[cvar] Make cvars properly typed
This is an extremely extensive patch as it hits every cvar, and every
usage of the cvars. Cvars no longer store the value they control,
instead, they use a cexpr value object to reference the value and
specify the value's type (currently, a null type is used for strings).
Non-string cvars are passed through cexpr, allowing expressions in the
cvars' settings. Also, cvars have returned to an enhanced version of the
original (id quake) registration scheme.
As a minor benefit, relevant code having direct access to the
cvar-controlled variables is probably a slight optimization as it
removed a pointer dereference, and the variables can be located for data
locality.
The static cvar descriptors are made private as an additional safety
layer, though there's nothing stopping external modification via
Cvar_FindVar (which is needed for adding listeners).
While not used yet (partly due to working out the design), cvars can
have a validation function.
Registering a cvar allows a primary listener (and its data) to be
specified: it will always be called first when the cvar is modified. The
combination of proper listeners and direct access to the controlled
variable greatly simplifies the more complex cvar interactions as much
less null checking is required, and there's no need for one cvar's
callback to call another's.
nq-x11 is known to work at least well enough for the demos. More testing
will come.
2022-04-23 03:22:45 +00:00
|
|
|
if (time > sys_ticrate * 2)
|
2011-09-03 10:58:03 +00:00
|
|
|
oldtime = newtime;
|
|
|
|
else
|
|
|
|
oldtime += time;
|
|
|
|
|
2001-02-19 21:15:25 +00:00
|
|
|
Host_Frame (time);
|
|
|
|
}
|
|
|
|
}
|