]> de.git.xonotic.org Git - xonotic/darkplaces.git/blobdiff - sys_linux.c
added protocol.o
[xonotic/darkplaces.git] / sys_linux.c
index da6ae1d7f5748b2d8de8d78e86f11ec50b5e45a0..c1d14940f4e5e24a15150a8bf7e27b6166737932 100644 (file)
@@ -26,9 +26,9 @@ qboolean                      isDedicated;
 int nostdout = 0;
 
 char *basedir = ".";
+#if CACHEENABLE
 char *cachedir = "/tmp";
-
-cvar_t  sys_linerefresh = {"sys_linerefresh","0"};// set for entity display
+#endif
 
 extern cvar_t  timestamps;
 extern cvar_t  timeformat;
@@ -184,10 +184,6 @@ void Sys_Quit (void)
        exit(0);
 }
 
-void Sys_Init(void)
-{
-}
-
 void Sys_Error (char *error, ...)
 { 
     va_list     argptr;
@@ -307,44 +303,31 @@ void Sys_DebugLog(char *file, char *fmt, ...)
     close(fd);
 }
 
-void Sys_EditFile(char *filename)
+double Sys_DoubleTime (void)
 {
+       static int first = true;
+       static double oldtime = 0.0, basetime = 0.0;
+       double newtime;
+       struct timeval tp;
+       struct timezone tzp; 
 
-       char cmd[256];
-       char *term;
-       char *editor;
+       gettimeofday(&tp, &tzp);
 
-       term = getenv("TERM");
-       if (term && !strcmp(term, "xterm"))
+       newtime = (double) ((unsigned long) tp.tv_sec) + tp.tv_usec/1000000.0 - basetime;
+
+       if (first)
        {
-               editor = getenv("VISUAL");
-               if (!editor)
-                       editor = getenv("EDITOR");
-               if (!editor)
-                       editor = getenv("EDIT");
-               if (!editor)
-                       editor = "vi";
-               sprintf(cmd, "xterm -e %s %s", editor, filename);
-               system(cmd);
+               first = false;
+               basetime = newtime;
+               newtime = 0.0;
        }
 
-}
+       if (newtime < oldtime)
+               Sys_Error("Sys_DoubleTime: time running backwards??\n");
 
-double Sys_FloatTime (void)
-{
-    struct timeval tp;
-    struct timezone tzp; 
-    static int      secbase; 
-    
-    gettimeofday(&tp, &tzp);  
+       oldtime = newtime;
 
-    if (!secbase)
-    {
-        secbase = tp.tv_sec;
-        return tp.tv_usec/1000000.0;
-    }
-
-    return (tp.tv_sec - secbase) + tp.tv_usec/1000000.0;
+       return newtime;
 }
 
 // =======================================================================
@@ -358,10 +341,6 @@ void alarm_handler(int x)
        oktogo=1;
 }
 
-void Sys_LineRefresh(void)
-{
-}
-
 void floating_point_exception_handler(int whatever)
 {
 //     Sys_Warn("floating point exception\n");
@@ -393,13 +372,15 @@ char *Sys_ConsoleInput(void)
        return NULL;
 }
 
+void Sys_Sleep(void)
+{
+       usleep(1);
+}
+
 int main (int c, char **v)
 {
 
-       double          time, oldtime, newtime;
-       extern int vcrFile;
-       extern int recording;
-       int j;
+       double oldtime, newtime;
 
 //     static char cwd[1024];
 
@@ -414,26 +395,12 @@ int main (int c, char **v)
 
        host_parms.memsize = DEFAULTMEM * 1024*1024;
 
-       j = COM_CheckParm("-mem");
-       if (j)
-               host_parms.memsize = (int) (atof(com_argv[j+1]) * 1024 * 1024);
-       host_parms.membase = qmalloc(host_parms.memsize);
-       if (!host_parms.membase)
-       {
-               printf("Unable to allocate heap memory\n");
-               return 1;
-       }
-
        host_parms.basedir = basedir;
-// caching is disabled by default, use -cachedir to enable
-//     host_parms.cachedir = cachedir;
 
        fcntl(0, F_SETFL, fcntl (0, F_GETFL, 0) | FNDELAY);
 
        Host_Init();
 
-       Sys_Init();
-
        if (COM_CheckParm("-nostdout"))
                nostdout = 1;
        else
@@ -442,59 +409,15 @@ int main (int c, char **v)
                printf ("Linux DarkPlaces -- Version %0.3f (build %i)\n", VERSION, buildnumber);
        }
 
-       oldtime = Sys_FloatTime () - 0.1;
+       oldtime = Sys_DoubleTime () - 0.1;
        while (1)
        {
                // find time spent rendering last frame
-               newtime = Sys_FloatTime ();
-               time = newtime - oldtime;
-
-               if (cls.state == ca_dedicated)
-               {   // play vcrfiles at max speed
-                       if (time < sys_ticrate.value && (vcrFile == -1 || recording) )
-                       {
-                               usleep(1);
-                               continue;       // not time to run a server only tic yet
-                       }
-                       time = sys_ticrate.value;
-               }
-
-               if (time > sys_ticrate.value*2)
-                       oldtime = newtime;
-               else
-                       oldtime += time;
-
-               Host_Frame (time);
-
-               // graphic debugging aids
-               if (sys_linerefresh.value)
-                       Sys_LineRefresh ();
-       }
-       return 0;
-}
-
-
-/*
-================
-Sys_MakeCodeWriteable
-================
-*/
-void Sys_MakeCodeWriteable (unsigned long startaddr, unsigned long length)
-{
-
-       int r;
-       unsigned long addr;
-       int psize = getpagesize();
-
-       addr = (startaddr & ~(psize-1)) - psize;
-
-//     fprintf(stderr, "writable code %lx(%lx)-%lx, length=%lx\n", startaddr,
-//                     addr, startaddr+length, length);
+               newtime = Sys_DoubleTime ();
 
-       r = mprotect((char*)addr, length + startaddr - addr + psize, 7);
-
-       if (r < 0)
-               Sys_Error("Protection change failed\n");
+               Host_Frame (newtime - oldtime);
 
+               oldtime = newtime;
+       }
+       return 0;
 }
-