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
.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:
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
# 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=
$(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
.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:
-#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
+
/*
===============================================================================
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
}
void Sys_Quit (void)
{
Host_Shutdown();
+#ifndef WIN32
fcntl (0, F_SETFL, fcntl (0, F_GETFL, 0) & ~FNDELAY);
+#endif
fflush(stdout);
exit(0);
}
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);
}
-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)
{
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)
com_argc = argc;
com_argv = argv;
+#ifndef WIN32
fcntl(0, F_SETFL, fcntl (0, F_GETFL, 0) | FNDELAY);
+#endif
Sys_Shared_EarlyInit();
'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, ...)
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);
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
}