]> git.xonotic.org Git - xonotic/darkplaces.git/commitdiff
darkplaces-dedicated.exe now builds
authorhavoc <havoc@d7cf8633-e32d-0410-b094-e92efae38249>
Sun, 25 May 2003 15:48:00 +0000 (15:48 +0000)
committerhavoc <havoc@d7cf8633-e32d-0410-b094-e92efae38249>
Sun, 25 May 2003 15:48:00 +0000 (15:48 +0000)
sys_linux.c (needs new name badly!) modified to support windows for purposes of darkplaces-dedicated.exe
Sys_Printf probably no longer works properly with darkplaces.exe (but we'll see)
darkplaces.exe should now be a proper windows app again (how I got --mwindows in there I don't know), so -dedicated may work

git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@3031 d7cf8633-e32d-0410-b094-e92efae38249

makefile
makefile.mingwcross
sys_linux.c
sys_shared.c

index a2c2bd7943be2a2385dbd6feebd6ffecc388e46c..c6ffbf33a35645763726dbb3f579f2a6214965a4 100644 (file)
--- a/makefile
+++ b/makefile
@@ -50,12 +50,14 @@ SHAREDOBJECTS=      builddate.o cmd.o collision.o common.o crc.o cvar.o \
                filematch.o host.o host_cmd.o image.o mathlib.o matrixlib.o \
                model_alias.o model_brush.o model_shared.o model_sprite.o \
                net_bsd.o net_dgrm.o net_loop.o net_main.o net_master.o \
-               net_udp.o palette.o portals.o protocol.o fs.o sys_linux.o \
+               net_udp.o palette.o portals.o protocol.o fs.o \
                sys_shared.o world.o wad.o zone.o
+COMMONOBJECTS= $(CLIENTOBJECTS) $(SERVEROBJECTS) $(SHAREDOBJECTS)
 
-OBJ_COMMON= $(CLIENTOBJECTS) $(SERVEROBJECTS) $(SHAREDOBJECTS)
-OBJ_GLX= vid_glx.o $(OBJ_CD) $(OBJ_SND)
-OBJ_DED= vid_null.o cd_null.o snd_null.o
+# objects used by glx target
+OBJ_GLX= sys_linux.o vid_glx.o $(OBJ_CD) $(OBJ_SND) $(COMMONOBJECTS)
+# objects used by dedicated target
+OBJ_DED= sys_linux.o vid_null.o cd_null.o snd_null.o $(COMMONOBJECTS)
 
 
 # Compilation
@@ -170,10 +172,10 @@ vid_glx.o: vid_glx.c
 .c.o:
        $(DO_CC)
 
-$(EXE_GLX):  $(OBJ_COMMON) $(OBJ_GLX)
+$(EXE_GLX):  $(OBJ_GLX)
        $(DO_LD) $(GLX_LIB)
 
-$(EXE_DED): $(OBJ_COMMON) $(OBJ_DED)
+$(EXE_DED): $(OBJ_DED)
        $(DO_LD)
 
 clean:
index de72410a86ea548286feafb5636339f0a70aaf86..7d0f5d38fa3223249cf1964bd67ed34a85ef2743 100644 (file)
@@ -36,14 +36,15 @@ SERVEROBJECTS=      pr_cmds.o pr_edict.o pr_exec.o sv_light.o sv_main.o sv_move.o \
 SHAREDOBJECTS= builddate.o cmd.o collision.o common.o crc.o cvar.o \
                filematch.o host.o host_cmd.o image.o mathlib.o matrixlib.o \
                model_alias.o model_brush.o model_shared.o model_sprite.o \
-               net_dgrm.o net_loop.o net_main.o net_master.o \
-               palette.o portals.o protocol.o fs.o \
+               net_bsd.o net_dgrm.o net_loop.o net_main.o net_master.o \
+               net_udp.o palette.o portals.o protocol.o fs.o \
                sys_shared.o world.o wad.o zone.o
+COMMONOBJECTS= $(CLIENTOBJECTS) $(SERVEROBJECTS) $(SHAREDOBJECTS)
 
-
-OBJ_COMMON= $(CLIENTOBJECTS) $(SERVEROBJECTS) $(SHAREDOBJECTS)
-OBJ_WGL= vid_wgl.o $(OBJ_CD) $(OBJ_SND) net_bsd.o net_udp.o sys_win.o
-OBJ_DED= vid_null.o cd_null.o snd_null.o net_bsd.o net_udp.o sys_win.o
+# objects used by wgl target
+OBJ_WGL= sys_win.o vid_wgl.o $(OBJ_CD) $(OBJ_SND) $(COMMONOBJECTS)
+# objects used by dedicated target
+OBJ_DED= sys_linux.o vid_null.o cd_null.o snd_null.o $(COMMONOBJECTS)
 
 
 # Compilation
@@ -62,7 +63,8 @@ DO_CC=$(CC) $(CFLAGS) -c $< -o $@
 
 
 # Link
-LDFLAGS_COMMON=--mwindows -luser32 -lgdi32 -lwinmm -ldxguid -ldinput -lopengl32 -lcomctl32 -lwsock32
+LDFLAGS_WGL=-mwindows -luser32 -lgdi32 -lwinmm -ldxguid -ldinput -lcomctl32 -lwsock32
+LDFLAGS_DED=-mwindows -lwinmm -lwsock32
 LDFLAGS_DEBUG=-g -ggdb
 LDFLAGS_PROFILE=-g -pg
 LDFLAGS_RELEASE=
@@ -108,22 +110,22 @@ release :
        $(MAKE) -f makefile.mingwcross wgl-release ded-release
 
 wgl-debug :
-       $(MAKE) -f makefile.mingwcross bin-debug EXE="$(EXE_WGL)"
+       $(MAKE) -f makefile.mingwcross bin-debug EXE="$(EXE_WGL)" LDFLAGS_COMMON="$(LDFLAGS_WGL)"
 
 wgl-profile :
-       $(MAKE) -f makefile.mingwcross bin-profile EXE="$(EXE_WGL)"
+       $(MAKE) -f makefile.mingwcross bin-profile EXE="$(EXE_WGL)" LDFLAGS_COMMON="$(LDFLAGS_WGL)"
 
 wgl-release :
-       $(MAKE) -f makefile.mingwcross bin-release EXE="$(EXE_WGL)"
+       $(MAKE) -f makefile.mingwcross bin-release EXE="$(EXE_WGL)" LDFLAGS_COMMON="$(LDFLAGS_WGL)"
 
 ded-debug :
-       $(MAKE) -f makefile.mingwcross bin-debug EXE="$(EXE_DED)"
+       $(MAKE) -f makefile.mingwcross bin-debug EXE="$(EXE_DED)" LDFLAGS_COMMON="$(LDFLAGS_DED)"
 
 ded-profile :
-       $(MAKE) -f makefile.mingwcross bin-profile EXE="$(EXE_DED)"
+       $(MAKE) -f makefile.mingwcross bin-profile EXE="$(EXE_DED)" LDFLAGS_COMMON="$(LDFLAGS_DED)"
 
 ded-release :
-       $(MAKE) -f makefile.mingwcross bin-release EXE="$(EXE_DED)"
+       $(MAKE) -f makefile.mingwcross bin-release EXE="$(EXE_DED)" LDFLAGS_COMMON="$(LDFLAGS_DED)"
 
 bin-debug :
        @echo
@@ -156,10 +158,10 @@ builddate:
 .c.o:
        $(DO_CC)
 
-$(EXE_WGL):  $(OBJ_COMMON) $(OBJ_WGL)
+$(EXE_WGL):  $(OBJ_WGL)
        $(DO_LD) $(WGL_LIB)
 
-$(EXE_DED): $(OBJ_COMMON) $(OBJ_DED)
+$(EXE_DED): $(OBJ_DED)
        $(DO_LD)
 
 clean:
index 1e675e4799a5865f88cba7deb9421d6d4f0d5d4e..148f540bb91e2f4bc5cf4c02b4f1b0eb028d9790 100644 (file)
@@ -1,28 +1,22 @@
-#include <stdlib.h>
-#include <stdio.h>
-#include <stdarg.h>
 
-#include <sys/types.h>
-#include <sys/stat.h>
+#ifdef WIN32
+#include "conio.h"
+#else
 #include <unistd.h>
 #include <fcntl.h>
-
-#include <signal.h>
-#include <limits.h>
-#include <sys/ipc.h>
-#include <sys/shm.h>
 #include <sys/time.h>
-#include <sys/wait.h>
-#include <sys/mman.h>
-#include <string.h>
-#include <ctype.h>
-#include <errno.h>
-#include <time.h>
-
 #include <dlfcn.h>
+#endif
+
+#include <signal.h>
 
 #include "quakedef.h"
 
+
+#ifdef WIN32
+cvar_t sys_usetimegettime = {CVAR_SAVE, "sys_usetimegettime", "1"};
+#endif
+
 /*
 ===============================================================================
 
@@ -33,17 +27,29 @@ DLL MANAGEMENT
 
 dllhandle_t Sys_LoadLibrary (const char* name)
 {
+#ifdef WIN32
+       return LoadLibrary (name);
+#else
        return dlopen (name, RTLD_LAZY);
+#endif
 }
 
 void Sys_UnloadLibrary (dllhandle_t handle)
 {
+#ifdef WIN32
+       FreeLibrary (handle);
+#else
        dlclose (handle);
+#endif
 }
 
 void* Sys_GetProcAddress (dllhandle_t handle, const char* name)
 {
+#ifdef WIN32
+       return (void *)GetProcAddress (handle, name);
+#else
        return (void *)dlsym (handle, name);
+#endif
 }
 
 
@@ -54,7 +60,9 @@ void* Sys_GetProcAddress (dllhandle_t handle, const char* name)
 void Sys_Quit (void)
 {
        Host_Shutdown();
+#ifndef WIN32
        fcntl (0, F_SETFL, fcntl (0, F_GETFL, 0) & ~FNDELAY);
+#endif
        fflush(stdout);
        exit(0);
 }
@@ -65,7 +73,9 @@ void Sys_Error (const char *error, ...)
        char string[1024];
 
 // change stdin to non blocking
+#ifndef WIN32
        fcntl (0, F_SETFL, fcntl (0, F_GETFL, 0) & ~FNDELAY);
+#endif
 
        va_start (argptr,error);
        vsprintf (string,error,argptr);
@@ -77,27 +87,64 @@ void Sys_Error (const char *error, ...)
 
 }
 
-void Sys_Warn (const char *warning, ...)
-{
-       va_list argptr;
-       char string[1024];
-
-       va_start (argptr,warning);
-       vsprintf (string,warning,argptr);
-       va_end (argptr);
-       fprintf(stderr, "Warning: %s", string);
-}
-
 double Sys_DoubleTime (void)
 {
        static int first = true;
        static double oldtime = 0.0, curtime = 0.0;
        double newtime;
+#ifdef WIN32
+       // LordHavoc: note to people modifying this code, DWORD is specifically defined as an unsigned 32bit number, therefore the 65536.0 * 65536.0 is fine.
+       if (sys_usetimegettime.integer)
+       {
+               static int firsttimegettime = true;
+               // timeGetTime
+               // platform:
+               // Windows 95/98/ME/NT/2000/XP
+               // features:
+               // reasonable accuracy (millisecond)
+               // issues:
+               // wraps around every 47 days or so (but this is non-fatal to us, odd times are rejected, only causes a one frame stutter)
+
+               // make sure the timer is high precision, otherwise different versions of windows have varying accuracy
+               if (firsttimegettime)
+               {
+                       timeBeginPeriod (1);
+                       firsttimegettime = false;
+               }
+
+               newtime = (double) timeGetTime () / 1000.0;
+       }
+       else
+       {
+               // QueryPerformanceCounter
+               // platform:
+               // Windows 95/98/ME/NT/2000/XP
+               // features:
+               // very accurate (CPU cycles)
+               // known issues:
+               // does not necessarily match realtime too well (tends to get faster and faster in win98)
+               // wraps around occasionally on some platforms (depends on CPU speed and probably other unknown factors)
+               double timescale;
+               LARGE_INTEGER PerformanceFreq;
+               LARGE_INTEGER PerformanceCount;
+
+               if (!QueryPerformanceFrequency (&PerformanceFreq))
+                       Sys_Error ("No hardware timer available");
+               QueryPerformanceCounter (&PerformanceCount);
+
+               #ifdef __BORLANDC__
+               timescale = 1.0 / ((double) PerformanceFreq.u.LowPart + (double) PerformanceFreq.u.HighPart * 65536.0 * 65536.0);
+               newtime = ((double) PerformanceCount.u.LowPart + (double) PerformanceCount.u.HighPart * 65536.0 * 65536.0) * timescale;
+               #else
+               timescale = 1.0 / ((double) PerformanceFreq.LowPart + (double) PerformanceFreq.HighPart * 65536.0 * 65536.0);
+               newtime = ((double) PerformanceCount.LowPart + (double) PerformanceCount.HighPart * 65536.0 * 65536.0) * timescale;
+               #endif
+       }
+#else
        struct timeval tp;
-
        gettimeofday(&tp, NULL);
-
        newtime = (double) tp.tv_sec + tp.tv_usec / 1000000.0;
+#endif
 
        if (first)
        {
@@ -118,51 +165,73 @@ double Sys_DoubleTime (void)
        return curtime;
 }
 
-// =======================================================================
-// Sleeps for microseconds
-// =======================================================================
-
-static volatile int oktogo;
-
-void alarm_handler(int x)
-{
-       oktogo=1;
-}
-
-void floating_point_exception_handler(int whatever)
-{
-       signal(SIGFPE, floating_point_exception_handler);
-}
-
 char *Sys_ConsoleInput(void)
 {
-       static char text[256];
-       int len;
-       fd_set fdset;
-       struct timeval timeout;
-
        if (cls.state == ca_dedicated)
        {
+               static char text[256];
+               int len;
+#ifdef WIN32
+               int c;
+
+               // read a line out
+               while (_kbhit ())
+               {
+                       c = _getch ();
+                       putch (c);
+                       if (c == '\r')
+                       {
+                               text[len] = 0;
+                               putch ('\n');
+                               len = 0;
+                               return text;
+                       }
+                       if (c == 8)
+                       {
+                               if (len)
+                               {
+                                       putch (' ');
+                                       putch (c);
+                                       len--;
+                                       text[len] = 0;
+                               }
+                               continue;
+                       }
+                       text[len] = c;
+                       len++;
+                       text[len] = 0;
+                       if (len == sizeof (text))
+                               len = 0;
+               }
+#else
+               fd_set fdset;
+               struct timeval timeout;
                FD_ZERO(&fdset);
                FD_SET(0, &fdset); // stdin
                timeout.tv_sec = 0;
                timeout.tv_usec = 0;
-               if (select (1, &fdset, NULL, NULL, &timeout) == -1 || !FD_ISSET(0, &fdset))
-                       return NULL;
-
-               len = read (0, text, sizeof(text));
-               if (len < 1)
-                       return NULL;
-               text[len-1] = 0;    // rip off the /n and terminate
-
-               return text;
+               if (select (1, &fdset, NULL, NULL, &timeout) != -1 && FD_ISSET(0, &fdset))
+               {
+                       len = read (0, text, sizeof(text));
+                       if (len >= 1)
+                       {
+                               // rip off the \n and terminate
+                               text[len-1] = 0;
+                               return text;
+                       }
+               }
+#endif
        }
        return NULL;
 }
 
 void Sys_Sleep(void)
 {
+#ifdef WIN32
+       Sleep (1);
+#else
        usleep(1);
+#endif
 }
 
 int main (int argc, const char **argv)
@@ -174,7 +243,9 @@ int main (int argc, const char **argv)
        com_argc = argc;
        com_argv = argv;
 
+#ifndef WIN32
        fcntl(0, F_SETFL, fcntl (0, F_GETFL, 0) | FNDELAY);
+#endif
 
        Sys_Shared_EarlyInit();
 
index f6f6804f6a158f624902f6ab34fdcf9bd13f4a98..ddd831e2ecfa07a1791c2280e5e1839fe154ed8d 100644 (file)
@@ -48,9 +48,9 @@ static char qfont_table[256] = {
        'x',  'y',  'z',  '{',  '|',  '}',  '~',  '<'
 };
 
-#ifdef WIN32
-extern HANDLE hinput, houtput;
-#endif
+//#ifdef WIN32
+//extern HANDLE houtput;
+//#endif
 
 #define MAX_PRINT_MSG  16384
 void Sys_Printf (const char *fmt, ...)
@@ -64,9 +64,9 @@ void Sys_Printf (const char *fmt, ...)
        struct tm       *local = NULL;
 
        unsigned char           *p;
-#ifdef WIN32
-       DWORD           dummy;
-#endif
+//#ifdef WIN32
+//     DWORD           dummy;
+//#endif
 
        va_start (argptr, fmt);
        vsnprintf (start, sizeof(start), fmt, argptr);
@@ -90,12 +90,12 @@ void Sys_Printf (const char *fmt, ...)
        final[MAX_PRINT_MSG - 1] = 0;
        for (p = (unsigned char *) final;*p; p++)
                *p = qfont_table[*p];
-#ifdef WIN32
-       if (cls.state == ca_dedicated)
-               WriteFile(houtput, final, strlen (final), &dummy, NULL);
-#else
+//#ifdef WIN32
+//     if (cls.state == ca_dedicated)
+//             WriteFile(houtput, final, strlen (final), &dummy, NULL);
+//#else
        printf("%s", final);
-#endif
+//#endif
 }