]> de.git.xonotic.org Git - xonotic/darkplaces.git/blobdiff - sys_win.c
fix for really dumb mistake (missing memset) in Mod_SplitSurfMeshIfTooBig
[xonotic/darkplaces.git] / sys_win.c
index e4e6cfd6bd57f35d4502ae6e6ee32d3ff853210d..10226f3a577659386859f2b1e8d380915e468fd8 100644 (file)
--- a/sys_win.c
+++ b/sys_win.c
@@ -36,59 +36,27 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 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];
-               }
-       }
-}
-*/
-
-
 /*
 ===============================================================================
 
-FILE IO
+QFile IO
 
 ===============================================================================
 */
 
 // LordHavoc: 256 pak files (was 10)
 #define        MAX_HANDLES             256
-FILE   *sys_handles[MAX_HANDLES];
+QFile  *sys_handles[MAX_HANDLES];
 
 int            findhandle (void)
 {
@@ -103,30 +71,30 @@ int                findhandle (void)
 
 /*
 ================
-filelength
+Sys_FileLength
 ================
 */
-int filelength (FILE *f)
+int Sys_FileLength (QFile *f)
 {
        int             pos;
        int             end;
 
-       pos = ftell (f);
-       fseek (f, 0, SEEK_END);
-       end = ftell (f);
-       fseek (f, pos, SEEK_SET);
+       pos = Qtell (f);
+       Qseek (f, 0, SEEK_END);
+       end = Qtell (f);
+       Qseek (f, pos, SEEK_SET);
 
        return end;
 }
 
 int Sys_FileOpenRead (char *path, int *hndl)
 {
-       FILE    *f;
+       QFile   *f;
        int             i, retval;
 
        i = findhandle ();
 
-       f = fopen(path, "rb");
+       f = Qopen(path, "rbz");
 
        if (!f)
        {
@@ -137,7 +105,7 @@ int Sys_FileOpenRead (char *path, int *hndl)
        {
                sys_handles[i] = f;
                *hndl = i;
-               retval = filelength(f);
+               retval = Sys_FileLength(f);
        }
 
        return retval;
@@ -145,14 +113,17 @@ int Sys_FileOpenRead (char *path, int *hndl)
 
 int Sys_FileOpenWrite (char *path)
 {
-       FILE    *f;
+       QFile   *f;
        int             i;
 
        i = findhandle ();
 
-       f = fopen(path, "wb");
+       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;
@@ -160,33 +131,33 @@ int Sys_FileOpenWrite (char *path)
 
 void Sys_FileClose (int handle)
 {
-       fclose (sys_handles[handle]);
+       Qclose (sys_handles[handle]);
        sys_handles[handle] = NULL;
 }
 
 void Sys_FileSeek (int handle, int position)
 {
-       fseek (sys_handles[handle], position, SEEK_SET);
+       Qseek (sys_handles[handle], position, SEEK_SET);
 }
 
 int Sys_FileRead (int handle, void *dest, int count)
 {
-       return fread (dest, 1, count, sys_handles[handle]);
+       return Qread (sys_handles[handle], dest, count);
 }
 
 int Sys_FileWrite (int handle, void *data, int count)
 {
-       return fwrite (data, 1, count, sys_handles[handle]);
+       return Qwrite (sys_handles[handle], data, count);
 }
 
 int    Sys_FileTime (char *path)
 {
-       FILE    *f;
+       QFile   *f;
        
-       f = fopen(path, "rb");
+       f = Qopen(path, "rb");
        if (f)
        {
-               fclose(f);
+               Qclose(f);
                return 1;
        }
        
@@ -228,7 +199,7 @@ void Sys_Error (char *error, ...)
        vsprintf (text, error, argptr);
        va_end (argptr);
 
-       if (isDedicated)
+       if (cls.state == ca_dedicated)
        {
                va_start (argptr, error);
                vsprintf (text, error, argptr);
@@ -245,8 +216,7 @@ void Sys_Error (char *error, ...)
                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))
                {
                }
        }
@@ -258,13 +228,11 @@ void Sys_Error (char *error, ...)
                {
                        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);
                }
        }
 
@@ -284,22 +252,6 @@ void Sys_Error (char *error, ...)
        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)
 {
 
@@ -308,7 +260,7 @@ void Sys_Quit (void)
        if (tevent)
                CloseHandle (tevent);
 
-       if (isDedicated)
+       if (cls.state == ca_dedicated)
                FreeConsole ();
 
 // shut down QHOST hooks if necessary
@@ -338,7 +290,7 @@ double Sys_DoubleTime (void)
        static double oldtime = 0.0, basetime = 0.0, old = 0.0;
        double newtime, now;
 
-       now = (double) timeGetTime () - basetime;
+       now = (double) timeGetTime () + basetime;
 
        if (first)
        {
@@ -350,7 +302,7 @@ double Sys_DoubleTime (void)
        if (now < old)
        {
                // wrapped
-               basetime -= (65536.0 * 65536.0);
+               basetime += (65536.0 * 65536.0);
                now += (65536.0 * 65536.0);
        }
        old = now;
@@ -416,13 +368,13 @@ double Sys_DoubleTime (void)
 
 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;
 
 
@@ -550,7 +502,7 @@ static char *empty_string = "";
 
 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;
@@ -596,7 +548,7 @@ int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLin
                                *lpCmdLine = 0;
                                lpCmdLine++;
                        }
-                       
+
                }
        }
 
@@ -607,37 +559,19 @@ int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLin
        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);
@@ -648,13 +582,13 @@ int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLin
                        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)
@@ -676,32 +610,29 @@ int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLin
        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;
        }