1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201
|
/*
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 the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
//#include <sys/types.h>
//#include <sys/timeb.h>
#include "qwsvdef.h"
#include <winsock2.h>
#include <conio.h>
#include <limits.h>
#include <direct.h> // _mkdir
cvar_t sys_sleep = {"sys_sleep", "8"};
cvar_t sys_nostdout = {"sys_nostdout","0"};
/*
================
Sys_mkdir
================
*/
void Sys_mkdir (const char *path)
{
_mkdir(path);
}
/*
================
Sys_Error
================
*/
void Sys_Error (char *error, ...) {
va_list argptr;
char text[1024];
va_start (argptr, error);
vsnprintf (text, sizeof(text), error, argptr);
va_end (argptr);
// MessageBox(NULL, text, "Error", 0 /* MB_OK */ );
printf ("ERROR: %s\n", text);
exit (1);
}
double Sys_DoubleTime (void)
{
static DWORD starttime;
static qbool first = true;
DWORD now;
now = timeGetTime();
if (first) {
first = false;
starttime = now;
return 0.0;
}
if (now < starttime) // wrapped?
return (now / 1000.0) + (LONG_MAX - starttime / 1000.0);
if (now - starttime == 0)
return 0.0;
return (now - starttime) / 1000.0;
}
/*
================
Sys_Printf
================
*/
void Sys_Printf (char *fmt, ...)
{
va_list argptr;
if (sys_nostdout.value)
return;
va_start (argptr,fmt);
vprintf (fmt,argptr);
va_end (argptr);
}
/*
================
Sys_Quit
================
*/
void Sys_Quit (void)
{
exit (0);
}
/*
=============
Sys_Init
Quake calls this so the system can register variables before host_hunklevel
is marked
=============
*/
void Sys_Init (void)
{
OSVERSIONINFO vinfo;
// make sure the timer is high precision, otherwise
// NT gets 18ms resolution
timeBeginPeriod( 1 );
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 ("QuakeWorld requires at least Win95 or NT 4.0");
}
if (vinfo.dwPlatformId == VER_PLATFORM_WIN32_NT)
WinNT = true;
else
WinNT = false;
Cvar_Register (&sys_sleep);
Cvar_Register (&sys_nostdout);
if (COM_CheckParm ("-nopriority"))
{
Cvar_Set (&sys_sleep, "0");
}
else
{
if ( ! SetPriorityClass (GetCurrentProcess(), HIGH_PRIORITY_CLASS))
Com_Printf ("SetPriorityClass() failed\n");
else
Com_Printf ("Process priority class set to HIGH\n");
}
}
/*
==================
main
==================
*/
int main (int argc, char **argv)
{
double newtime, time, oldtime;
int sleep_msec;
Host_Init (argc, argv, 16*1024*1024);
//
// main loop
//
oldtime = Sys_DoubleTime () - 0.1;
while (1)
{
sleep_msec = sys_sleep.value;
if (sleep_msec > 0)
{
if (sleep_msec > 13)
sleep_msec = 13;
Sleep (sleep_msec);
}
NET_Sleep (1);
// find time passed since last cycle
newtime = Sys_DoubleTime ();
time = newtime - oldtime;
oldtime = newtime;
Host_Frame (time);
}
return true;
}
|