2010-02-15 23:26:55 +00:00
|
|
|
/*
|
|
|
|
Copyright (C) 1996-2001 Id Software, Inc.
|
|
|
|
Copyright (C) 2002-2005 John Fitzgibbons and others
|
|
|
|
Copyright (C) 2007-2008 Kristian Duske
|
2014-09-22 08:55:46 +00:00
|
|
|
Copyright (C) 2010-2014 QuakeSpasm developers
|
2010-02-15 23:26:55 +00:00
|
|
|
|
|
|
|
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 the Free Software
|
|
|
|
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
2010-06-22 11:01:24 +00:00
|
|
|
#ifndef WIN32_LEAN_AND_MEAN
|
|
|
|
#define WIN32_LEAN_AND_MEAN
|
|
|
|
#endif
|
|
|
|
#include <windows.h>
|
2015-04-14 18:01:33 +00:00
|
|
|
#include <mmsystem.h>
|
2010-06-22 11:01:24 +00:00
|
|
|
|
2010-06-19 16:50:15 +00:00
|
|
|
#include "quakedef.h"
|
|
|
|
|
2010-02-27 07:47:16 +00:00
|
|
|
#include <sys/types.h>
|
2010-06-22 11:01:24 +00:00
|
|
|
#include <errno.h>
|
2010-02-27 07:47:16 +00:00
|
|
|
#include <io.h>
|
|
|
|
#include <direct.h>
|
|
|
|
|
2012-08-16 04:51:41 +00:00
|
|
|
#if defined(SDL_FRAMEWORK) || defined(NO_SDL_CONFIG)
|
2014-09-10 17:41:34 +00:00
|
|
|
#if defined(USE_SDL2)
|
|
|
|
#include <SDL2/SDL.h>
|
|
|
|
#else
|
2012-08-16 04:51:41 +00:00
|
|
|
#include <SDL/SDL.h>
|
2014-09-10 17:41:34 +00:00
|
|
|
#endif
|
2012-08-16 04:51:41 +00:00
|
|
|
#else
|
2010-06-19 22:50:48 +00:00
|
|
|
#include "SDL.h"
|
2012-08-16 04:51:41 +00:00
|
|
|
#endif
|
2010-06-19 22:50:48 +00:00
|
|
|
|
2010-06-22 11:01:24 +00:00
|
|
|
|
2010-02-17 23:32:04 +00:00
|
|
|
qboolean isDedicated;
|
2010-12-30 17:00:19 +00:00
|
|
|
qboolean Win95, Win95old, WinNT, WinVista;
|
2011-12-28 22:01:33 +00:00
|
|
|
cvar_t sys_throttle = {"sys_throttle", "0.02", CVAR_ARCHIVE};
|
2010-06-22 11:01:24 +00:00
|
|
|
|
|
|
|
static HANDLE hinput, houtput;
|
2010-02-15 23:26:55 +00:00
|
|
|
|
2010-02-17 23:32:04 +00:00
|
|
|
#define MAX_HANDLES 32 /* johnfitz -- was 10 */
|
2010-06-22 11:01:24 +00:00
|
|
|
static FILE *sys_handles[MAX_HANDLES];
|
|
|
|
|
2010-02-15 23:26:55 +00:00
|
|
|
|
2010-06-22 11:01:24 +00:00
|
|
|
static int findhandle (void)
|
2010-02-15 23:26:55 +00:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
2010-06-22 11:01:24 +00:00
|
|
|
for (i = 1; i < MAX_HANDLES; i++)
|
|
|
|
{
|
2010-02-17 23:32:04 +00:00
|
|
|
if (!sys_handles[i])
|
|
|
|
return i;
|
2010-06-22 11:01:24 +00:00
|
|
|
}
|
2010-02-17 23:32:04 +00:00
|
|
|
Sys_Error ("out of handles");
|
2010-02-15 23:26:55 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2011-02-10 17:25:43 +00:00
|
|
|
long Sys_filelength (FILE *f)
|
2010-02-15 23:26:55 +00:00
|
|
|
{
|
2011-02-10 17:25:43 +00:00
|
|
|
long pos, end;
|
2010-02-15 23:26:55 +00:00
|
|
|
|
2010-02-17 23:32:04 +00:00
|
|
|
pos = ftell (f);
|
|
|
|
fseek (f, 0, SEEK_END);
|
|
|
|
end = ftell (f);
|
|
|
|
fseek (f, pos, SEEK_SET);
|
2010-02-15 23:26:55 +00:00
|
|
|
|
2010-02-17 23:32:04 +00:00
|
|
|
return end;
|
2010-02-15 23:26:55 +00:00
|
|
|
}
|
|
|
|
|
2010-08-29 02:22:55 +00:00
|
|
|
int Sys_FileOpenRead (const char *path, int *hndl)
|
2010-02-15 23:26:55 +00:00
|
|
|
{
|
|
|
|
FILE *f;
|
2010-06-22 11:01:24 +00:00
|
|
|
int i, retval;
|
2010-02-15 23:26:55 +00:00
|
|
|
|
|
|
|
i = findhandle ();
|
|
|
|
f = fopen(path, "rb");
|
|
|
|
|
|
|
|
if (!f)
|
|
|
|
{
|
|
|
|
*hndl = -1;
|
|
|
|
retval = -1;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
sys_handles[i] = f;
|
|
|
|
*hndl = i;
|
2010-02-27 07:45:12 +00:00
|
|
|
retval = Sys_filelength(f);
|
2010-02-15 23:26:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
2010-08-29 02:22:55 +00:00
|
|
|
int Sys_FileOpenWrite (const char *path)
|
2010-02-15 23:26:55 +00:00
|
|
|
{
|
|
|
|
FILE *f;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
i = findhandle ();
|
|
|
|
f = fopen(path, "wb");
|
|
|
|
|
|
|
|
if (!f)
|
|
|
|
Sys_Error ("Error opening %s: %s", path, strerror(errno));
|
2010-02-17 23:32:04 +00:00
|
|
|
|
|
|
|
sys_handles[i] = f;
|
2010-02-15 23:26:55 +00:00
|
|
|
return i;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Sys_FileClose (int handle)
|
|
|
|
{
|
|
|
|
fclose (sys_handles[handle]);
|
|
|
|
sys_handles[handle] = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Sys_FileSeek (int handle, int position)
|
|
|
|
{
|
|
|
|
fseek (sys_handles[handle], position, SEEK_SET);
|
|
|
|
}
|
|
|
|
|
|
|
|
int Sys_FileRead (int handle, void *dest, int count)
|
|
|
|
{
|
|
|
|
return fread (dest, 1, count, sys_handles[handle]);
|
|
|
|
}
|
|
|
|
|
2010-08-29 02:22:55 +00:00
|
|
|
int Sys_FileWrite (int handle, const void *data, int count)
|
2010-02-15 23:26:55 +00:00
|
|
|
{
|
|
|
|
return fwrite (data, 1, count, sys_handles[handle]);
|
|
|
|
}
|
|
|
|
|
2010-08-29 02:22:55 +00:00
|
|
|
int Sys_FileTime (const char *path)
|
2010-02-15 23:26:55 +00:00
|
|
|
{
|
2010-02-17 23:32:04 +00:00
|
|
|
FILE *f;
|
2010-02-15 23:26:55 +00:00
|
|
|
|
2010-02-17 23:32:04 +00:00
|
|
|
f = fopen(path, "rb");
|
2010-02-15 23:26:55 +00:00
|
|
|
|
2010-02-17 23:32:04 +00:00
|
|
|
if (f)
|
|
|
|
{
|
|
|
|
fclose(f);
|
|
|
|
return 1;
|
|
|
|
}
|
2010-02-15 23:26:55 +00:00
|
|
|
|
2010-02-17 23:32:04 +00:00
|
|
|
return -1;
|
2010-02-15 23:26:55 +00:00
|
|
|
}
|
|
|
|
|
2014-09-10 09:51:35 +00:00
|
|
|
static char cwd[1024];
|
|
|
|
|
|
|
|
static void Sys_GetBasedir (char *argv0, char *dst, size_t dstsize)
|
|
|
|
{
|
2017-03-10 20:01:47 +00:00
|
|
|
char *tmp;
|
|
|
|
size_t rc;
|
2014-09-10 09:51:35 +00:00
|
|
|
|
2017-03-10 20:01:47 +00:00
|
|
|
rc = GetCurrentDirectory(dstsize, dst);
|
|
|
|
if (rc == 0 || rc > dstsize)
|
2014-09-10 09:51:35 +00:00
|
|
|
Sys_Error ("Couldn't determine current directory");
|
|
|
|
|
|
|
|
tmp = dst;
|
|
|
|
while (*tmp != 0)
|
|
|
|
tmp++;
|
|
|
|
while (*tmp == 0 && tmp != dst)
|
|
|
|
{
|
|
|
|
--tmp;
|
|
|
|
if (tmp != dst && (*tmp == '/' || *tmp == '\\'))
|
|
|
|
*tmp = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-10-16 23:01:43 +00:00
|
|
|
typedef enum { dpi_unaware = 0, dpi_system_aware = 1, dpi_monitor_aware = 2 } dpi_awareness;
|
2015-09-07 20:36:39 +00:00
|
|
|
typedef BOOL (WINAPI *SetProcessDPIAwareFunc)();
|
|
|
|
typedef HRESULT (WINAPI *SetProcessDPIAwarenessFunc)(dpi_awareness value);
|
2014-10-16 23:01:43 +00:00
|
|
|
|
2014-11-03 09:10:18 +00:00
|
|
|
static void Sys_SetDPIAware (void)
|
2014-10-16 23:01:43 +00:00
|
|
|
{
|
|
|
|
HMODULE hUser32, hShcore;
|
|
|
|
SetProcessDPIAwarenessFunc setDPIAwareness;
|
|
|
|
SetProcessDPIAwareFunc setDPIAware;
|
|
|
|
|
|
|
|
/* Neither SDL 1.2 nor SDL 2.0.3 can handle the OS scaling our window.
|
|
|
|
(e.g. https://bugzilla.libsdl.org/show_bug.cgi?id=2713)
|
|
|
|
Call SetProcessDpiAwareness/SetProcessDPIAware to opt out of scaling.
|
|
|
|
*/
|
|
|
|
|
|
|
|
hShcore = LoadLibraryA ("Shcore.dll");
|
|
|
|
hUser32 = LoadLibraryA ("user32.dll");
|
2014-10-17 00:15:49 +00:00
|
|
|
setDPIAwareness = (SetProcessDPIAwarenessFunc) (hShcore ? GetProcAddress (hShcore, "SetProcessDpiAwareness") : NULL);
|
|
|
|
setDPIAware = (SetProcessDPIAwareFunc) (hUser32 ? GetProcAddress (hUser32, "SetProcessDPIAware") : NULL);
|
2014-10-16 23:01:43 +00:00
|
|
|
|
|
|
|
if (setDPIAwareness) /* Windows 8.1+ */
|
|
|
|
setDPIAwareness (dpi_monitor_aware);
|
|
|
|
else if (setDPIAware) /* Windows Vista-8.0 */
|
|
|
|
setDPIAware ();
|
|
|
|
|
|
|
|
if (hShcore)
|
|
|
|
FreeLibrary (hShcore);
|
|
|
|
if (hUser32)
|
|
|
|
FreeLibrary (hUser32);
|
|
|
|
}
|
|
|
|
|
2015-04-14 18:01:33 +00:00
|
|
|
static void Sys_SetTimerResolution(void)
|
|
|
|
{
|
|
|
|
/* Set OS timer resolution to 1ms.
|
|
|
|
Works around buffer underruns with directsound and SDL2, but also
|
|
|
|
will make Sleep()/SDL_Dleay() accurate to 1ms which should help framerate
|
|
|
|
stability.
|
|
|
|
*/
|
|
|
|
timeBeginPeriod (1);
|
|
|
|
}
|
|
|
|
|
2010-06-22 11:01:24 +00:00
|
|
|
void Sys_Init (void)
|
|
|
|
{
|
2010-12-30 17:00:19 +00:00
|
|
|
OSVERSIONINFO vinfo;
|
|
|
|
|
2015-04-14 18:01:33 +00:00
|
|
|
Sys_SetTimerResolution ();
|
2014-10-16 23:01:43 +00:00
|
|
|
Sys_SetDPIAware ();
|
|
|
|
|
2014-09-10 09:51:35 +00:00
|
|
|
memset (cwd, 0, sizeof(cwd));
|
|
|
|
Sys_GetBasedir(NULL, cwd, sizeof(cwd));
|
|
|
|
host_parms->basedir = cwd;
|
|
|
|
|
|
|
|
/* userdirs not really necessary for windows guys.
|
|
|
|
* can be done if necessary, though... */
|
|
|
|
host_parms->userdir = host_parms->basedir; /* code elsewhere relies on this ! */
|
2011-04-19 16:41:45 +00:00
|
|
|
|
2010-12-30 17:00:19 +00:00
|
|
|
vinfo.dwOSVersionInfoSize = sizeof(vinfo);
|
|
|
|
|
|
|
|
if (!GetVersionEx (&vinfo))
|
|
|
|
Sys_Error ("Couldn't get OS info");
|
|
|
|
|
|
|
|
if ((vinfo.dwMajorVersion < 4) ||
|
|
|
|
(vinfo.dwPlatformId == VER_PLATFORM_WIN32s))
|
|
|
|
{
|
|
|
|
Sys_Error ("QuakeSpasm requires at least Win95 or NT 4.0");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (vinfo.dwPlatformId == VER_PLATFORM_WIN32_NT)
|
|
|
|
{
|
2014-11-03 09:10:18 +00:00
|
|
|
SYSTEM_INFO info;
|
2010-12-30 17:00:19 +00:00
|
|
|
WinNT = true;
|
|
|
|
if (vinfo.dwMajorVersion >= 6)
|
|
|
|
WinVista = true;
|
2014-11-03 09:10:18 +00:00
|
|
|
GetSystemInfo(&info);
|
|
|
|
host_parms->numcpus = info.dwNumberOfProcessors;
|
|
|
|
if (host_parms->numcpus < 1)
|
|
|
|
host_parms->numcpus = 1;
|
2010-12-30 17:00:19 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
WinNT = false; /* Win9x or WinME */
|
2014-11-03 09:10:18 +00:00
|
|
|
host_parms->numcpus = 1;
|
2010-12-30 17:00:19 +00:00
|
|
|
if ((vinfo.dwMajorVersion == 4) && (vinfo.dwMinorVersion == 0))
|
|
|
|
{
|
|
|
|
Win95 = true;
|
|
|
|
/* Win95-gold or Win95A can't switch bpp automatically */
|
|
|
|
if (vinfo.szCSDVersion[1] != 'C' && vinfo.szCSDVersion[1] != 'B')
|
|
|
|
Win95old = true;
|
|
|
|
}
|
|
|
|
}
|
2014-11-03 09:10:18 +00:00
|
|
|
Sys_Printf("Detected %d CPUs.\n", host_parms->numcpus);
|
2010-12-30 17:00:19 +00:00
|
|
|
|
2010-06-22 11:01:24 +00:00
|
|
|
if (isDedicated)
|
|
|
|
{
|
|
|
|
if (!AllocConsole ())
|
|
|
|
{
|
|
|
|
isDedicated = false; /* so that we have a graphical error dialog */
|
|
|
|
Sys_Error ("Couldn't create dedicated server console");
|
|
|
|
}
|
|
|
|
|
|
|
|
hinput = GetStdHandle (STD_INPUT_HANDLE);
|
|
|
|
houtput = GetStdHandle (STD_OUTPUT_HANDLE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-08-29 02:22:55 +00:00
|
|
|
void Sys_mkdir (const char *path)
|
2010-02-15 23:26:55 +00:00
|
|
|
{
|
2011-12-12 10:50:26 +00:00
|
|
|
if (CreateDirectory(path, NULL) != 0)
|
|
|
|
return;
|
|
|
|
if (GetLastError() != ERROR_ALREADY_EXISTS)
|
2010-02-27 07:47:16 +00:00
|
|
|
Sys_Error("Unable to create directory %s", path);
|
2010-02-15 23:26:55 +00:00
|
|
|
}
|
|
|
|
|
2010-06-22 11:01:24 +00:00
|
|
|
static const char errortxt1[] = "\nERROR-OUT BEGIN\n\n";
|
|
|
|
static const char errortxt2[] = "\nQUAKE ERROR: ";
|
2010-02-15 23:26:55 +00:00
|
|
|
|
Constified Con_DebugLog, Con_Print, Con_Printf, Con_Warning, Con_DPrintf,
Con_DPrintf2, Con_SafePrintf, Con_CenterPrintf, Con_LogCenterPrint,
Con_NotifyBox, PL_ErrorDialog, PR_RunError, Host_EndGame, Host_Error,
SV_ClientPrintf, SV_BroadcastPrintf, Host_ClientCommands, Sys_DebugLog,
Sys_Error, Sys_Printf, BOPS_Error and va. Added noreturn attribute to
Sys_Error, Sys_Quit, BOPS_Error, PR_RunError, Host_EndGame and Host_Error.
Added format printf attribute to Con_DebugLog, Con_Printf, Con_Warning,
Con_DPrintf, Con_DPrintf2, Con_SafePrintf, Con_CenterPrintf, PL_ErrorDialog,
PR_RunError, Host_EndGame, Host_Error, SV_ClientPrintf, SV_BroadcastPrintf,
Host_ClientCommands, Sys_DebugLog, Sys_Error, Sys_Printf and va. Adjusted
Host_Status_f and NET_Ban_f for the new attributes. Fixed broken format
strings in Con_Dump_f, Mod_LoadTexinfo, PR_AllocStringSlots and FloorDivMod.
Defined __attribute__ macros in quakedef.h so that we don't break non-gcc
compilers.
git-svn-id: svn://svn.code.sf.net/p/quakespasm/code/trunk/quakespasm@154 af15c1b1-3010-417e-b628-4374ebc0bcbd
2010-04-26 16:30:40 +00:00
|
|
|
void Sys_Error (const char *error, ...)
|
2010-02-15 23:26:55 +00:00
|
|
|
{
|
2010-02-17 23:32:04 +00:00
|
|
|
va_list argptr;
|
2010-06-22 11:01:24 +00:00
|
|
|
char text[1024];
|
|
|
|
DWORD dummy;
|
2010-02-17 23:32:04 +00:00
|
|
|
|
2018-02-21 07:33:07 +00:00
|
|
|
host_parms->errstate++;
|
|
|
|
|
2010-02-17 23:32:04 +00:00
|
|
|
va_start (argptr, error);
|
2010-08-31 16:57:12 +00:00
|
|
|
q_vsnprintf (text, sizeof(text), error, argptr);
|
2010-02-17 23:32:04 +00:00
|
|
|
va_end (argptr);
|
|
|
|
|
|
|
|
if (isDedicated)
|
2010-06-22 11:01:24 +00:00
|
|
|
WriteFile (houtput, errortxt1, strlen(errortxt1), &dummy, NULL);
|
|
|
|
/* SDL will put these into its own stderr log,
|
|
|
|
so print to stderr even in graphical mode. */
|
|
|
|
fputs (errortxt1, stderr);
|
|
|
|
Host_Shutdown ();
|
|
|
|
fputs (errortxt2, stderr);
|
|
|
|
fputs (text, stderr);
|
|
|
|
fputs ("\n\n", stderr);
|
|
|
|
if (!isDedicated)
|
|
|
|
PL_ErrorDialog(text);
|
2010-02-17 23:32:04 +00:00
|
|
|
else
|
|
|
|
{
|
2010-06-22 11:01:24 +00:00
|
|
|
WriteFile (houtput, errortxt2, strlen(errortxt2), &dummy, NULL);
|
|
|
|
WriteFile (houtput, text, strlen(text), &dummy, NULL);
|
|
|
|
WriteFile (houtput, "\r\n", 2, &dummy, NULL);
|
|
|
|
SDL_Delay (3000); /* show the console 3 more seconds */
|
2010-02-17 23:32:04 +00:00
|
|
|
}
|
2010-02-15 23:26:55 +00:00
|
|
|
|
|
|
|
exit (1);
|
|
|
|
}
|
|
|
|
|
Constified Con_DebugLog, Con_Print, Con_Printf, Con_Warning, Con_DPrintf,
Con_DPrintf2, Con_SafePrintf, Con_CenterPrintf, Con_LogCenterPrint,
Con_NotifyBox, PL_ErrorDialog, PR_RunError, Host_EndGame, Host_Error,
SV_ClientPrintf, SV_BroadcastPrintf, Host_ClientCommands, Sys_DebugLog,
Sys_Error, Sys_Printf, BOPS_Error and va. Added noreturn attribute to
Sys_Error, Sys_Quit, BOPS_Error, PR_RunError, Host_EndGame and Host_Error.
Added format printf attribute to Con_DebugLog, Con_Printf, Con_Warning,
Con_DPrintf, Con_DPrintf2, Con_SafePrintf, Con_CenterPrintf, PL_ErrorDialog,
PR_RunError, Host_EndGame, Host_Error, SV_ClientPrintf, SV_BroadcastPrintf,
Host_ClientCommands, Sys_DebugLog, Sys_Error, Sys_Printf and va. Adjusted
Host_Status_f and NET_Ban_f for the new attributes. Fixed broken format
strings in Con_Dump_f, Mod_LoadTexinfo, PR_AllocStringSlots and FloorDivMod.
Defined __attribute__ macros in quakedef.h so that we don't break non-gcc
compilers.
git-svn-id: svn://svn.code.sf.net/p/quakespasm/code/trunk/quakespasm@154 af15c1b1-3010-417e-b628-4374ebc0bcbd
2010-04-26 16:30:40 +00:00
|
|
|
void Sys_Printf (const char *fmt, ...)
|
2010-02-15 23:26:55 +00:00
|
|
|
{
|
2010-06-22 11:01:24 +00:00
|
|
|
va_list argptr;
|
|
|
|
char text[1024];
|
|
|
|
DWORD dummy;
|
|
|
|
|
|
|
|
va_start (argptr,fmt);
|
2010-08-31 16:57:12 +00:00
|
|
|
q_vsnprintf (text, sizeof(text), fmt, argptr);
|
2010-06-22 11:01:24 +00:00
|
|
|
va_end (argptr);
|
|
|
|
|
|
|
|
if (isDedicated)
|
|
|
|
{
|
|
|
|
WriteFile(houtput, text, strlen(text), &dummy, NULL);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* SDL will put these into its own stdout log,
|
|
|
|
so print to stdout even in graphical mode. */
|
|
|
|
fputs (text, stdout);
|
|
|
|
}
|
2010-02-15 23:26:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Sys_Quit (void)
|
|
|
|
{
|
|
|
|
Host_Shutdown();
|
|
|
|
|
2010-06-22 11:01:24 +00:00
|
|
|
if (isDedicated)
|
|
|
|
FreeConsole ();
|
2010-02-15 23:26:55 +00:00
|
|
|
|
|
|
|
exit (0);
|
|
|
|
}
|
|
|
|
|
2011-12-12 16:01:01 +00:00
|
|
|
double Sys_DoubleTime (void)
|
2010-02-15 23:26:55 +00:00
|
|
|
{
|
2010-02-17 23:32:04 +00:00
|
|
|
return SDL_GetTicks() / 1000.0;
|
2010-02-15 23:26:55 +00:00
|
|
|
}
|
|
|
|
|
2011-12-12 12:02:37 +00:00
|
|
|
const char *Sys_ConsoleInput (void)
|
2010-02-15 23:26:55 +00:00
|
|
|
{
|
2010-06-19 16:50:15 +00:00
|
|
|
static char con_text[256];
|
2011-12-12 10:50:26 +00:00
|
|
|
static int textlen;
|
2010-06-22 11:01:24 +00:00
|
|
|
INPUT_RECORD recs[1024];
|
|
|
|
int ch;
|
|
|
|
DWORD dummy, numread, numevents;
|
2010-06-19 16:50:15 +00:00
|
|
|
|
2010-06-22 11:01:24 +00:00
|
|
|
for ( ;; )
|
2010-06-19 16:50:15 +00:00
|
|
|
{
|
2011-12-12 10:50:26 +00:00
|
|
|
if (GetNumberOfConsoleInputEvents(hinput, &numevents) == 0)
|
2010-06-22 11:01:24 +00:00
|
|
|
Sys_Error ("Error getting # of console events");
|
|
|
|
|
2017-08-04 20:36:59 +00:00
|
|
|
if (! numevents)
|
2010-06-22 11:01:24 +00:00
|
|
|
break;
|
|
|
|
|
2011-12-12 10:50:26 +00:00
|
|
|
if (ReadConsoleInput(hinput, recs, 1, &numread) == 0)
|
2010-06-22 11:01:24 +00:00
|
|
|
Sys_Error ("Error reading console input");
|
|
|
|
|
|
|
|
if (numread != 1)
|
|
|
|
Sys_Error ("Couldn't read console input");
|
|
|
|
|
|
|
|
if (recs[0].EventType == KEY_EVENT)
|
2010-06-19 16:50:15 +00:00
|
|
|
{
|
2011-12-12 10:50:26 +00:00
|
|
|
if (recs[0].Event.KeyEvent.bKeyDown == FALSE)
|
|
|
|
{
|
|
|
|
ch = recs[0].Event.KeyEvent.uChar.AsciiChar;
|
|
|
|
|
|
|
|
switch (ch)
|
2010-06-19 16:50:15 +00:00
|
|
|
{
|
2011-12-12 10:50:26 +00:00
|
|
|
case '\r':
|
|
|
|
WriteFile(houtput, "\r\n", 2, &dummy, NULL);
|
|
|
|
|
|
|
|
if (textlen != 0)
|
|
|
|
{
|
|
|
|
con_text[textlen] = 0;
|
|
|
|
textlen = 0;
|
|
|
|
return con_text;
|
|
|
|
}
|
2010-06-22 11:01:24 +00:00
|
|
|
|
2011-12-12 10:50:26 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case '\b':
|
|
|
|
WriteFile(houtput, "\b \b", 3, &dummy, NULL);
|
|
|
|
if (textlen != 0)
|
|
|
|
textlen--;
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
if (ch >= ' ')
|
2010-06-22 11:01:24 +00:00
|
|
|
{
|
2011-12-12 10:50:26 +00:00
|
|
|
WriteFile(houtput, &ch, 1, &dummy, NULL);
|
|
|
|
con_text[textlen] = ch;
|
|
|
|
textlen = (textlen + 1) & 0xff;
|
2010-06-22 11:01:24 +00:00
|
|
|
}
|
2011-12-12 10:50:26 +00:00
|
|
|
|
|
|
|
break;
|
2010-06-19 16:50:15 +00:00
|
|
|
}
|
2011-12-12 10:50:26 +00:00
|
|
|
}
|
2010-06-19 16:50:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
2010-02-15 23:26:55 +00:00
|
|
|
}
|
|
|
|
|
2011-12-12 16:01:01 +00:00
|
|
|
void Sys_Sleep (unsigned long msecs)
|
2010-02-15 23:26:55 +00:00
|
|
|
{
|
2011-12-21 10:40:18 +00:00
|
|
|
/* Sleep (msecs);*/
|
|
|
|
SDL_Delay (msecs);
|
2010-02-15 23:26:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Sys_SendKeyEvents (void)
|
|
|
|
{
|
2016-03-01 21:58:08 +00:00
|
|
|
IN_Commands(); //ericw -- allow joysticks to add keys so they can be used to confirm SCR_ModalMessage
|
2011-12-16 14:11:37 +00:00
|
|
|
IN_SendKeyEvents();
|
2010-02-15 23:26:55 +00:00
|
|
|
}
|
|
|
|
|