int starttime;
qboolean ActiveApp, Minimized;
-qboolean isDedicated;
static qboolean sc_return_on_enter = false;
HANDLE hinput, houtput;
-static char *tracking_tag = "Clams & Mooses";
+//static char *tracking_tag = "Clams & Mooses";
static HANDLE tevent;
static HANDLE hFile;
static HANDLE heventParent;
static HANDLE heventChild;
-volatile int sys_checksum;
-
-
-/*
-================
-Sys_PageIn
-================
-*/
-/*
-void Sys_PageIn (void *ptr, int size)
-{
- byte *x;
- int m, n;
-
-// touch all the memory to make sure it's there. The 16-page skip is to
-// keep Win 95 from thinking we're trying to page ourselves in (we are
-// doing that, of course, but there's no reason we shouldn't)
- x = (byte *)ptr;
-
- for (n=0 ; n<4 ; n++)
- {
- for (m=0 ; m<(size - 16 * 0x1000) ; m += 4)
- {
- sys_checksum += *(int *)&x[m];
- sys_checksum += *(int *)&x[m + 16 * 0x1000];
- }
- }
-}
-*/
-
-
/*
===============================================================================
/*
================
-filelength
+Sys_FileLength
================
*/
-int filelength (QFile *f)
+int Sys_FileLength (QFile *f)
{
int pos;
int end;
{
sys_handles[i] = f;
*hndl = i;
- retval = filelength(f);
+ retval = Sys_FileLength(f);
}
return retval;
f = Qopen(path, "wb");
if (!f)
- Host_Error ("Error opening %s: %s", path,strerror(errno));
+ {
+ Con_Printf("Sys_FileOpenWrite: Error opening %s: %s", path, strerror(errno));
+ return 0;
+ }
sys_handles[i] = f;
return i;
int Sys_FileRead (int handle, void *dest, int count)
{
- return Qread (dest, 1, count, sys_handles[handle]);
+ return Qread (sys_handles[handle], dest, count);
}
int Sys_FileWrite (int handle, void *data, int count)
{
- return Qwrite (data, 1, count, sys_handles[handle]);
+ return Qwrite (sys_handles[handle], data, count);
}
int Sys_FileTime (char *path)
vsprintf (text, error, argptr);
va_end (argptr);
- if (isDedicated)
+ if (cls.state == ca_dedicated)
{
va_start (argptr, error);
vsprintf (text, error, argptr);
starttime = Sys_DoubleTime ();
sc_return_on_enter = true; // so Enter will get us out of here
- while (!Sys_ConsoleInput () &&
- ((Sys_DoubleTime () - starttime) < CONSOLE_ERROR_TIMEOUT))
+ while (!Sys_ConsoleInput () && ((Sys_DoubleTime () - starttime) < CONSOLE_ERROR_TIMEOUT))
{
}
}
{
in_sys_error0 = 1;
VID_SetDefaultMode ();
- MessageBox(NULL, text, "Quake Error",
- MB_OK | MB_SETFOREGROUND | MB_ICONSTOP);
+ MessageBox(NULL, text, "Quake Error", MB_OK | MB_SETFOREGROUND | MB_ICONSTOP);
}
else
{
- MessageBox(NULL, text, "Double Quake Error",
- MB_OK | MB_SETFOREGROUND | MB_ICONSTOP);
+ MessageBox(NULL, text, "Double Quake Error", MB_OK | MB_SETFOREGROUND | MB_ICONSTOP);
}
}
exit (1);
}
-void Sys_Printf (char *fmt, ...)
-{
- va_list argptr;
- char text[1024];
- DWORD dummy;
-
- if (isDedicated)
- {
- va_start (argptr,fmt);
- vsprintf (text, fmt, argptr);
- va_end (argptr);
-
- WriteFile(houtput, text, strlen (text), &dummy, NULL);
- }
-}
-
void Sys_Quit (void)
{
if (tevent)
CloseHandle (tevent);
- if (isDedicated)
+ if (cls.state == ca_dedicated)
FreeConsole ();
// shut down QHOST hooks if necessary
static double oldtime = 0.0, basetime = 0.0, old = 0.0;
double newtime, now;
- now = (double) timeGetTime () - basetime;
+ now = (double) timeGetTime () + basetime;
if (first)
{
if (now < old)
{
// wrapped
- basetime -= (65536.0 * 65536.0);
+ basetime += (65536.0 * 65536.0);
now += (65536.0 * 65536.0);
}
old = now;
char *Sys_ConsoleInput (void)
{
- static char text[256];
- static int len;
- INPUT_RECORD recs[1024];
- int dummy;
- int ch, numread, numevents;
+ static char text[256];
+ static int len;
+ INPUT_RECORD recs[1024];
+ int ch;
+ DWORD numread, numevents, dummy;
- if (!isDedicated)
+ if (cls.state != ca_dedicated)
return NULL;
int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{
- double time, oldtime, newtime/*, timediff*/;
+ double oldtime, newtime;
MEMORYSTATUS lpBuffer;
static char cwd[1024];
int t;
*lpCmdLine = 0;
lpCmdLine++;
}
-
+
}
}
host_parms.argc = com_argc;
host_parms.argv = com_argv;
- isDedicated = (COM_CheckParm ("-dedicated") != 0);
-
-// take the greater of all the available memory or half the total memory,
-// but at least 8 Mb and no more than 16 Mb, unless they explicitly
-// request otherwise
- /*
- host_parms.memsize = lpBuffer.dwAvailPhys;
-
- if (host_parms.memsize < MINIMUM_WIN_MEMORY)
- host_parms.memsize = MINIMUM_WIN_MEMORY;
-
- if (host_parms.memsize < (lpBuffer.dwTotalPhys >> 1))
- host_parms.memsize = lpBuffer.dwTotalPhys >> 1;
-
- if (host_parms.memsize > MAXIMUM_WIN_MEMORY)
- host_parms.memsize = MAXIMUM_WIN_MEMORY;
- */
-
-// Sys_PageIn (parms.membase, parms.memsize);
+ Sys_Shared_EarlyInit();
tevent = CreateEvent(NULL, false, false, NULL);
if (!tevent)
Sys_Error ("Couldn't create event");
- if (isDedicated)
+ // LordHavoc: can't check cls.state because it hasn't been initialized yet
+ // if (cls.state == ca_dedicated)
+ if (COM_CheckParm("-dedicated"))
{
if (!AllocConsole ())
- {
Sys_Error ("Couldn't create dedicated server console");
- }
hinput = GetStdHandle (STD_INPUT_HANDLE);
houtput = GetStdHandle (STD_OUTPUT_HANDLE);
if (t < com_argc)
hFile = (HANDLE)atoi (com_argv[t+1]);
}
-
+
if ((t = COM_CheckParm ("-HPARENT")) > 0)
{
if (t < com_argc)
heventParent = (HANDLE)atoi (com_argv[t+1]);
}
-
+
if ((t = COM_CheckParm ("-HCHILD")) > 0)
{
if (t < com_argc)
timeBeginPeriod (1);
#endif
- Sys_Printf ("Host_Init\n");
Host_Init ();
+ Sys_Shared_LateInit();
+
oldtime = Sys_DoubleTime ();
/* main window message loop */
while (1)
{
- if (!isDedicated)
+ if (cls.state != ca_dedicated)
{
// yield the CPU for a little while when paused, minimized, or not the focus
- if ((cl.paused && (!ActiveApp && !DDActive)) || Minimized)
+ if ((cl.paused && !ActiveApp) || Minimized)
{
SleepUntilInput (PAUSE_SLEEP);
scr_skipupdate = 1; // no point in bothering to draw
}
- else if (!ActiveApp && !DDActive)
- {
+ else if (!ActiveApp)
SleepUntilInput (NOT_FOCUS_SLEEP);
- }
-
- newtime = Sys_DoubleTime ();
- time = newtime - oldtime;
}
- Host_Frame (time);
+ newtime = Sys_DoubleTime ();
+ Host_Frame (newtime - oldtime);
oldtime = newtime;
}