2016-12-18 04:43:04 +00:00
|
|
|
/*
|
|
|
|
===========================================================================
|
|
|
|
Copyright (C) 1999-2005 Id Software, Inc.
|
|
|
|
|
|
|
|
This file is part of Quake III Arena source code.
|
|
|
|
|
|
|
|
Quake III Arena source code 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.
|
|
|
|
|
|
|
|
Quake III Arena source code 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 Quake III Arena source code; if not, write to the Free Software
|
|
|
|
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
|
|
|
===========================================================================
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "../qcommon/q_shared.h"
|
|
|
|
#include "../qcommon/qcommon.h"
|
|
|
|
#include "win_local.h"
|
2023-08-02 00:43:31 +00:00
|
|
|
#include <shlwapi.h>
|
2016-12-18 04:43:04 +00:00
|
|
|
|
|
|
|
|
|
|
|
int Sys_Milliseconds()
|
|
|
|
{
|
|
|
|
static int sys_timeBase = 0;
|
|
|
|
|
|
|
|
if (!sys_timeBase)
|
|
|
|
sys_timeBase = timeGetTime();
|
|
|
|
|
|
|
|
return (timeGetTime() - sys_timeBase);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-12-27 04:43:28 +00:00
|
|
|
void Sys_Sleep( int ms )
|
|
|
|
{
|
|
|
|
if (ms >= 1)
|
|
|
|
Sleep(ms);
|
|
|
|
}
|
|
|
|
|
2022-12-28 19:49:18 +00:00
|
|
|
|
2017-12-27 04:43:28 +00:00
|
|
|
void Sys_MicroSleep( int us )
|
|
|
|
{
|
2022-12-28 19:49:18 +00:00
|
|
|
if (us <= 50)
|
2017-12-27 04:43:28 +00:00
|
|
|
return;
|
|
|
|
|
2022-12-28 19:49:18 +00:00
|
|
|
us -= 50;
|
|
|
|
|
2017-12-27 04:43:28 +00:00
|
|
|
LARGE_INTEGER frequency;
|
|
|
|
LARGE_INTEGER endTime;
|
|
|
|
QueryPerformanceCounter(&endTime);
|
|
|
|
QueryPerformanceFrequency(&frequency);
|
|
|
|
endTime.QuadPart += ((LONGLONG)us * frequency.QuadPart) / 1000000LL;
|
|
|
|
|
2022-12-28 19:49:18 +00:00
|
|
|
// reminder: we call timeBeginPeriod(1) at init
|
|
|
|
// Sleep(1) will generally last 1000-2000 us,
|
|
|
|
// but in some cases quite a bit more (I've seen up to 3500 us)
|
|
|
|
// because threads can take longer to wake up
|
|
|
|
const LONGLONG thresholdUS = (LONGLONG)Cvar_Get("r_sleepThreshold", "2500", CVAR_ARCHIVE)->integer;
|
|
|
|
const LONGLONG bigSleepTicks = (thresholdUS * frequency.QuadPart) / 1000000LL;
|
|
|
|
|
|
|
|
for (;;) {
|
|
|
|
LARGE_INTEGER currentTime;
|
2017-12-27 04:43:28 +00:00
|
|
|
QueryPerformanceCounter(¤tTime);
|
2022-12-28 19:49:18 +00:00
|
|
|
const LONGLONG remainingTicks = endTime.QuadPart - currentTime.QuadPart;
|
|
|
|
if (remainingTicks <= 0) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (remainingTicks >= bigSleepTicks) {
|
|
|
|
Sleep(1);
|
|
|
|
} else {
|
|
|
|
YieldProcessor();
|
|
|
|
}
|
|
|
|
}
|
2017-12-27 04:43:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int64_t Sys_Microseconds()
|
|
|
|
{
|
|
|
|
static qbool initialized = qfalse;
|
|
|
|
static LARGE_INTEGER start;
|
|
|
|
static LARGE_INTEGER freq;
|
|
|
|
|
|
|
|
if (!initialized) {
|
|
|
|
initialized = qtrue;
|
|
|
|
QueryPerformanceFrequency(&freq);
|
|
|
|
QueryPerformanceCounter(&start);
|
|
|
|
}
|
|
|
|
|
|
|
|
LARGE_INTEGER now;
|
|
|
|
QueryPerformanceCounter(&now);
|
|
|
|
|
|
|
|
return ((now.QuadPart - start.QuadPart) * 1000000LL) / freq.QuadPart;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-12-18 04:43:04 +00:00
|
|
|
const char* Sys_DefaultHomePath()
|
|
|
|
{
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2017-07-06 04:10:29 +00:00
|
|
|
|
|
|
|
qbool Sys_HardReboot()
|
|
|
|
{
|
|
|
|
return qfalse;
|
|
|
|
}
|
|
|
|
|
2017-10-12 01:45:24 +00:00
|
|
|
|
|
|
|
qbool Sys_HasCNQ3Parent()
|
|
|
|
{
|
|
|
|
return qfalse;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int Sys_GetUptimeSeconds( qbool parent )
|
|
|
|
{
|
|
|
|
if (parent)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
FILETIME startFileTime;
|
|
|
|
FILETIME trash[3];
|
|
|
|
if (GetProcessTimes(GetCurrentProcess(), &startFileTime, &trash[0], &trash[1], &trash[2]) == 0)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
SYSTEMTIME endSystemTime;
|
|
|
|
GetSystemTime(&endSystemTime);
|
|
|
|
|
|
|
|
FILETIME endFileTime;
|
|
|
|
if (SystemTimeToFileTime(&endSystemTime, &endFileTime) == 0)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
// 1 FILETIME unit is 100-nanoseconds
|
|
|
|
ULARGE_INTEGER start, end;
|
|
|
|
start.LowPart = startFileTime.dwLowDateTime;
|
|
|
|
start.HighPart = startFileTime.dwHighDateTime;
|
|
|
|
end.LowPart = endFileTime.dwLowDateTime;
|
|
|
|
end.HighPart = endFileTime.dwHighDateTime;
|
|
|
|
const int seconds = (int)((end.QuadPart - start.QuadPart) / 1e7);
|
|
|
|
|
|
|
|
return seconds;
|
|
|
|
}
|
|
|
|
|
2022-04-10 19:24:36 +00:00
|
|
|
|
2022-11-22 03:58:04 +00:00
|
|
|
void Sys_DebugPrintf( PRINTF_FORMAT_STRING const char* fmt, ... )
|
2022-04-10 19:24:36 +00:00
|
|
|
{
|
|
|
|
char buffer[1024];
|
|
|
|
va_list argptr;
|
|
|
|
va_start(argptr, fmt);
|
|
|
|
const int len = vsprintf(buffer, fmt, argptr);
|
|
|
|
va_end(argptr);
|
|
|
|
|
|
|
|
if (len < 0)
|
|
|
|
return;
|
|
|
|
if (len >= sizeof(buffer))
|
|
|
|
buffer[sizeof(buffer) - 1] = '\0';
|
|
|
|
|
|
|
|
OutputDebugStringA(buffer);
|
|
|
|
}
|
|
|
|
|
2022-11-04 03:46:04 +00:00
|
|
|
|
|
|
|
qbool Sys_IsDebuggerAttached()
|
|
|
|
{
|
|
|
|
return IsDebuggerPresent();
|
|
|
|
}
|
|
|
|
|
2023-08-02 00:43:31 +00:00
|
|
|
|
|
|
|
qbool Sys_IsAbsolutePath( const char* path )
|
|
|
|
{
|
|
|
|
return PathIsRelativeA(path) != TRUE;
|
|
|
|
}
|
2022-12-28 19:49:18 +00:00
|
|
|
|
|
|
|
|
|
|
|
void Sys_Crash( const char* message, const char* file, int line, const char* function )
|
|
|
|
{
|
|
|
|
const ULONG_PTR args[4] = { (ULONG_PTR)message, (ULONG_PTR)file, (ULONG_PTR)line, (ULONG_PTR)function };
|
|
|
|
RaiseException(CNQ3_WINDOWS_EXCEPTION_CODE, EXCEPTION_NONCONTINUABLE, ARRAY_LEN(args), args);
|
|
|
|
}
|