mirror of
https://git.code.sf.net/p/quake/newtree
synced 2025-03-14 04:01:06 +00:00
Moved sys_unix.c and sys_linux.c into sys_linux.c, cl_sys_unix.c and
sv_sys_unix.c.
This commit is contained in:
parent
c7d068a829
commit
52867ce15d
4 changed files with 313 additions and 355 deletions
|
@ -11,8 +11,8 @@ if SYSTYPE_WIN32
|
||||||
cl_sys = sys_win.c cl_sys_win.c
|
cl_sys = sys_win.c cl_sys_win.c
|
||||||
sv_sys = sys_win.c sv_sys_win.c
|
sv_sys = sys_win.c sv_sys_win.c
|
||||||
else
|
else
|
||||||
cl_sys = sys_linux.c
|
cl_sys = sys_unix.c cl_sys_unix.c
|
||||||
sv_sys = sys_unix.c
|
sv_sys = sys_unix.c sv_sys_unix.c
|
||||||
endif
|
endif
|
||||||
|
|
||||||
common_SOURCES= net_chan.c net_com.c net_udp.c pmove.c pmovetst.c zone.c \
|
common_SOURCES= net_chan.c net_com.c net_udp.c pmove.c pmovetst.c zone.c \
|
||||||
|
@ -43,8 +43,9 @@ svga_SOURCES= vid_svgalib.c
|
||||||
x11_SOURCES= vid_x11.c
|
x11_SOURCES= vid_x11.c
|
||||||
glx_SOURCES= vid_glx.c
|
glx_SOURCES= vid_glx.c
|
||||||
|
|
||||||
EXTRA_qf_server_SOURCES= sys_linux.c sys_unix.c sys_win.c cl_sys_win.c \
|
# We just has to list these once, but a plain EXTRA_SOURCES isn't allowed
|
||||||
sv_sys_win.c
|
EXTRA_qf_server_SOURCES= sys_unix.c cl_sys_unix.c sv_sys_unix.c \
|
||||||
|
sys_win.c cl_sys_win.c sv_sys_win.c
|
||||||
|
|
||||||
qf_server_SOURCES= $(common_SOURCES) $(server_SOURCES)
|
qf_server_SOURCES= $(common_SOURCES) $(server_SOURCES)
|
||||||
qf_client_ggi_SOURCES= $(common_SOURCES) $(client_SOURCES) $(soft_SOURCES) $(ggi_SOURCES)
|
qf_client_ggi_SOURCES= $(common_SOURCES) $(client_SOURCES) $(soft_SOURCES) $(ggi_SOURCES)
|
||||||
|
|
|
@ -1,9 +1,10 @@
|
||||||
/*
|
/*
|
||||||
sys_linux.c
|
cl_sys_unix.c
|
||||||
|
|
||||||
(description)
|
(description)
|
||||||
|
|
||||||
Copyright (C) 1996-1997 Id Software, Inc.
|
Copyright (C) 1996-1997 Id Software, Inc.
|
||||||
|
Copyright (C) 2000 Marcus Sundberg [mackan@stacken.kth.se]
|
||||||
|
|
||||||
This program is free software; you can redistribute it and/or
|
This program is free software; you can redistribute it and/or
|
||||||
modify it under the terms of the GNU General Public License
|
modify it under the terms of the GNU General Public License
|
||||||
|
@ -29,86 +30,36 @@
|
||||||
#ifdef HAVE_CONFIG_H
|
#ifdef HAVE_CONFIG_H
|
||||||
# include <config.h>
|
# include <config.h>
|
||||||
#endif
|
#endif
|
||||||
#include <unistd.h>
|
|
||||||
#include <signal.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <limits.h>
|
|
||||||
#include <sys/time.h>
|
|
||||||
#include <sys/types.h>
|
|
||||||
#include <unistd.h>
|
|
||||||
#include <fcntl.h>
|
|
||||||
#include <stdarg.h>
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <sys/ipc.h>
|
#include <stdlib.h>
|
||||||
#include <sys/shm.h>
|
#include <errno.h>
|
||||||
#include <sys/stat.h>
|
#include <unistd.h>
|
||||||
|
#include <stdarg.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
#include <sys/wait.h>
|
#include <fcntl.h>
|
||||||
|
#include <signal.h>
|
||||||
|
#include <limits.h>
|
||||||
|
#include <sys/types.h>
|
||||||
#include <sys/mman.h>
|
#include <sys/mman.h>
|
||||||
#include <errno.h>
|
|
||||||
|
|
||||||
#include "sys.h"
|
#include "sys.h"
|
||||||
#include "quakedef.h"
|
#include "quakedef.h"
|
||||||
|
|
||||||
int noconinput = 0;
|
int noconinput = 0;
|
||||||
int nostdout = 0;
|
|
||||||
|
|
||||||
char *basedir = ".";
|
#define BASEDIR "."
|
||||||
char *cachedir = "/tmp";
|
|
||||||
qboolean is_server = false;
|
|
||||||
|
|
||||||
/* cvar_t sys_linerefresh = {"sys_linerefresh","0"};// set for entity display
|
/* cvar_t sys_linerefresh = {"sys_linerefresh","0"};// set for entity display
|
||||||
CVAR_FIXME */
|
CVAR_FIXME */
|
||||||
cvar_t *sys_linerefresh;// set for entity display
|
cvar_t *sys_linerefresh;// set for entity display
|
||||||
|
|
||||||
// The translation table between the graphical font and plain ASCII --KB
|
|
||||||
char qfont_table[256] =
|
|
||||||
{
|
|
||||||
'\0', '#', '#', '#', '#', '.', '#', '#',
|
|
||||||
'#', 9, 10, '#', ' ', 13, '.', '.',
|
|
||||||
'[', ']', '0', '1', '2', '3', '4', '5',
|
|
||||||
'6', '7', '8', '9', '.', '<', '=', '>',
|
|
||||||
' ', '!', '"', '#', '$', '%', '&', '\'',
|
|
||||||
'(', ')', '*', '+', ',', '-', '.', '/',
|
|
||||||
'0', '1', '2', '3', '4', '5', '6', '7',
|
|
||||||
'8', '9', ':', ';', '<', '=', '>', '?',
|
|
||||||
'@', 'A', 'B', 'C', 'D', 'E', 'F', 'G',
|
|
||||||
'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O',
|
|
||||||
'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W',
|
|
||||||
'X', 'Y', 'Z', '[', '\\', ']', '^', '_',
|
|
||||||
'`', 'a', 'b', 'c', 'd', 'e', 'f', 'g',
|
|
||||||
'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o',
|
|
||||||
'p', 'q', 'r', 's', 't', 'u', 'v', 'w',
|
|
||||||
'x', 'y', 'z', '{', '|', '}', '~', '<',
|
|
||||||
|
|
||||||
'<', '=', '>', '#', '#', '.', '#', '#',
|
|
||||||
'#', '#', ' ', '#', ' ', '>', '.', '.',
|
|
||||||
'[', ']', '0', '1', '2', '3', '4', '5',
|
|
||||||
'6', '7', '8', '9', '.', '<', '=', '>',
|
|
||||||
' ', '!', '"', '#', '$', '%', '&', '\'',
|
|
||||||
'(', ')', '*', '+', ',', '-', '.', '/',
|
|
||||||
'0', '1', '2', '3', '4', '5', '6', '7',
|
|
||||||
'8', '9', ':', ';', '<', '=', '>', '?',
|
|
||||||
'@', 'A', 'B', 'C', 'D', 'E', 'F', 'G',
|
|
||||||
'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O',
|
|
||||||
'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W',
|
|
||||||
'X', 'Y', 'Z', '[', '\\', ']', '^', '_',
|
|
||||||
'`', 'a', 'b', 'c', 'd', 'e', 'f', 'g',
|
|
||||||
'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o',
|
|
||||||
'p', 'q', 'r', 's', 't', 'u', 'v', 'w',
|
|
||||||
'x', 'y', 'z', '{', '|', '}', '~', '<'
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
// =======================================================================
|
// =======================================================================
|
||||||
// General routines
|
// General routines
|
||||||
// =======================================================================
|
// =======================================================================
|
||||||
|
|
||||||
void Sys_DebugNumber(int y, int val)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
void Sys_Printf (char *fmt, ...)
|
void Sys_Printf (char *fmt, ...)
|
||||||
{
|
{
|
||||||
|
@ -156,24 +107,6 @@ void Sys_Printf (char *fmt, ...)
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
void Sys_Printf (char *fmt, ...)
|
|
||||||
{
|
|
||||||
va_list argptr;
|
|
||||||
char text[2048];
|
|
||||||
unsigned char *p;
|
|
||||||
|
|
||||||
va_start (argptr,fmt);
|
|
||||||
vsnprintf (text, sizeof(text), fmt, argptr);
|
|
||||||
va_end (argptr);
|
|
||||||
|
|
||||||
if (nostdout)
|
|
||||||
return;
|
|
||||||
|
|
||||||
// translate to ASCII instead of printing [xx] --KB
|
|
||||||
for (p = (unsigned char *)text; *p; p++)
|
|
||||||
putc(qfont_table[*p], stdout);
|
|
||||||
}
|
|
||||||
|
|
||||||
void Sys_Quit (void)
|
void Sys_Quit (void)
|
||||||
{
|
{
|
||||||
Host_Shutdown();
|
Host_Shutdown();
|
||||||
|
@ -183,6 +116,7 @@ void Sys_Quit (void)
|
||||||
|
|
||||||
void Sys_Init(void)
|
void Sys_Init(void)
|
||||||
{
|
{
|
||||||
|
sys_nostdout = Cvar_Get("sys_nostdout", "0", CVAR_NONE, "None");
|
||||||
#ifdef USE_INTEL_ASM
|
#ifdef USE_INTEL_ASM
|
||||||
Sys_SetFPCW();
|
Sys_SetFPCW();
|
||||||
#endif
|
#endif
|
||||||
|
@ -217,29 +151,6 @@ void Sys_Warn (char *warning, ...)
|
||||||
fprintf(stderr, "Warning: %s", string);
|
fprintf(stderr, "Warning: %s", string);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
============
|
|
||||||
Sys_FileTime
|
|
||||||
|
|
||||||
returns -1 if not present
|
|
||||||
============
|
|
||||||
*/
|
|
||||||
int Sys_FileTime (char *path)
|
|
||||||
{
|
|
||||||
struct stat buf;
|
|
||||||
|
|
||||||
if (stat (path,&buf) == -1)
|
|
||||||
return -1;
|
|
||||||
|
|
||||||
return buf.st_mtime;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void Sys_mkdir (char *path)
|
|
||||||
{
|
|
||||||
mkdir (path, 0777);
|
|
||||||
}
|
|
||||||
|
|
||||||
void Sys_DebugLog(char *file, char *fmt, ...)
|
void Sys_DebugLog(char *file, char *fmt, ...)
|
||||||
{
|
{
|
||||||
va_list argptr;
|
va_list argptr;
|
||||||
|
@ -255,34 +166,6 @@ void Sys_DebugLog(char *file, char *fmt, ...)
|
||||||
close(fd);
|
close(fd);
|
||||||
}
|
}
|
||||||
|
|
||||||
double Sys_DoubleTime (void)
|
|
||||||
{
|
|
||||||
struct timeval tp;
|
|
||||||
struct timezone tzp;
|
|
||||||
static int secbase;
|
|
||||||
|
|
||||||
gettimeofday(&tp, &tzp);
|
|
||||||
|
|
||||||
if (!secbase)
|
|
||||||
{
|
|
||||||
secbase = tp.tv_sec;
|
|
||||||
return tp.tv_usec/1000000.0;
|
|
||||||
}
|
|
||||||
|
|
||||||
return (tp.tv_sec - secbase) + tp.tv_usec/1000000.0;
|
|
||||||
}
|
|
||||||
|
|
||||||
// =======================================================================
|
|
||||||
// Sleeps for microseconds
|
|
||||||
// =======================================================================
|
|
||||||
|
|
||||||
static volatile int oktogo;
|
|
||||||
|
|
||||||
void alarm_handler(int x)
|
|
||||||
{
|
|
||||||
oktogo=1;
|
|
||||||
}
|
|
||||||
|
|
||||||
void floating_point_exception_handler(int whatever)
|
void floating_point_exception_handler(int whatever)
|
||||||
{
|
{
|
||||||
// Sys_Warn("floating point exception\n");
|
// Sys_Warn("floating point exception\n");
|
||||||
|
@ -348,18 +231,17 @@ int main (int c, char **v)
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
parms.basedir = basedir;
|
parms.basedir = BASEDIR;
|
||||||
|
|
||||||
// caching is disabled by default, use -cachedir to enable
|
// caching is disabled by default, use -cachedir to enable
|
||||||
// parms.cachedir = cachedir;
|
// parms.cachedir = cachedir;
|
||||||
|
|
||||||
|
Sys_Init();
|
||||||
|
|
||||||
noconinput = COM_CheckParm("-noconinput");
|
noconinput = COM_CheckParm("-noconinput");
|
||||||
if (!noconinput)
|
if (!noconinput)
|
||||||
fcntl(0, F_SETFL, fcntl (0, F_GETFL, 0) | FNDELAY);
|
fcntl(0, F_SETFL, fcntl (0, F_GETFL, 0) | FNDELAY);
|
||||||
|
if (COM_CheckParm("-nostdout")) Cvar_Set(sys_nostdout, "1");
|
||||||
if (COM_CheckParm("-nostdout"))
|
|
||||||
nostdout = 1;
|
|
||||||
|
|
||||||
Sys_Init();
|
|
||||||
|
|
||||||
Host_Init(&parms);
|
Host_Init(&parms);
|
||||||
|
|
||||||
|
@ -400,4 +282,3 @@ void Sys_MakeCodeWriteable (unsigned long startaddr, unsigned long length)
|
||||||
Sys_Error("Protection change failed\n");
|
Sys_Error("Protection change failed\n");
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
220
source/sv_sys_unix.c
Normal file
220
source/sv_sys_unix.c
Normal file
|
@ -0,0 +1,220 @@
|
||||||
|
/*
|
||||||
|
sv_sys_unix.c
|
||||||
|
|
||||||
|
(description)
|
||||||
|
|
||||||
|
Copyright (C) 1996-1997 Id Software, Inc.
|
||||||
|
Copyright (C) 2000 Marcus Sundberg [mackan@stacken.kth.se]
|
||||||
|
|
||||||
|
This program is free software; you can redistribute it and/or
|
||||||
|
modify it under the terms of the GNU General Public License
|
||||||
|
as published by the Free Software Foundation; either version 2
|
||||||
|
of the License, or (at your option) any later version.
|
||||||
|
|
||||||
|
This program is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||||
|
|
||||||
|
See the GNU General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with this program; if not, write to:
|
||||||
|
|
||||||
|
Free Software Foundation, Inc.
|
||||||
|
59 Temple Place - Suite 330
|
||||||
|
Boston, MA 02111-1307, USA
|
||||||
|
|
||||||
|
$Id$
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifdef HAVE_CONFIG_H
|
||||||
|
# include <config.h>
|
||||||
|
#endif
|
||||||
|
#include <sys/types.h>
|
||||||
|
#include "qwsvdef.h"
|
||||||
|
|
||||||
|
#ifdef NeXT
|
||||||
|
#include <libc.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <errno.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <sys/time.h>
|
||||||
|
|
||||||
|
|
||||||
|
/* cvar_t sys_extrasleep = {"sys_extrasleep","0"};
|
||||||
|
CVAR_FIXME */
|
||||||
|
cvar_t *sys_extrasleep;
|
||||||
|
|
||||||
|
qboolean stdin_ready;
|
||||||
|
|
||||||
|
#define BASEDIR "."
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
===============================================================================
|
||||||
|
|
||||||
|
REQUIRED SYS FUNCTIONS
|
||||||
|
|
||||||
|
===============================================================================
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
================
|
||||||
|
Sys_Error
|
||||||
|
================
|
||||||
|
*/
|
||||||
|
void Sys_Error (char *error, ...)
|
||||||
|
{
|
||||||
|
va_list argptr;
|
||||||
|
char string[1024];
|
||||||
|
|
||||||
|
va_start (argptr, error);
|
||||||
|
vsnprintf (string, sizeof(string), error,argptr);
|
||||||
|
va_end (argptr);
|
||||||
|
printf ("Fatal error: %s\n",string);
|
||||||
|
|
||||||
|
exit (1);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
================
|
||||||
|
Sys_Quit
|
||||||
|
================
|
||||||
|
*/
|
||||||
|
void Sys_Quit (void)
|
||||||
|
{
|
||||||
|
exit (0); // appkit isn't running
|
||||||
|
}
|
||||||
|
|
||||||
|
static int do_stdin = 1;
|
||||||
|
|
||||||
|
/*
|
||||||
|
================
|
||||||
|
Sys_ConsoleInput
|
||||||
|
|
||||||
|
Checks for a complete line of text typed in at the console, then forwards
|
||||||
|
it to the host command processor
|
||||||
|
================
|
||||||
|
*/
|
||||||
|
char *Sys_ConsoleInput (void)
|
||||||
|
{
|
||||||
|
static char text[256];
|
||||||
|
int len;
|
||||||
|
|
||||||
|
if (!stdin_ready || !do_stdin)
|
||||||
|
return NULL; // the select didn't say it was ready
|
||||||
|
stdin_ready = false;
|
||||||
|
|
||||||
|
len = read (0, text, sizeof(text));
|
||||||
|
if (len == 0) {
|
||||||
|
// end of file
|
||||||
|
do_stdin = 0;
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
if (len < 1)
|
||||||
|
return NULL;
|
||||||
|
text[len-1] = 0; // rip off the /n and terminate
|
||||||
|
|
||||||
|
return text;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
=============
|
||||||
|
Sys_Init
|
||||||
|
|
||||||
|
Quake calls this so the system can register variables before host_hunklevel
|
||||||
|
is marked
|
||||||
|
=============
|
||||||
|
*/
|
||||||
|
void Sys_Init (void)
|
||||||
|
{
|
||||||
|
/* Cvar_RegisterVariable (&sys_nostdout);
|
||||||
|
CVAR_FIXME */
|
||||||
|
sys_nostdout = Cvar_Get("sys_nostdout", "0", CVAR_NONE, "None");
|
||||||
|
/* Cvar_RegisterVariable (&sys_extrasleep);
|
||||||
|
CVAR_FIXME */
|
||||||
|
sys_extrasleep = Cvar_Get("sys_extrasleep", "0", CVAR_NONE, "None");
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
=============
|
||||||
|
main
|
||||||
|
=============
|
||||||
|
*/
|
||||||
|
int main(int argc, char *argv[])
|
||||||
|
{
|
||||||
|
double time, oldtime, newtime;
|
||||||
|
quakeparms_t parms;
|
||||||
|
fd_set fdset;
|
||||||
|
extern int net_socket;
|
||||||
|
struct timeval timeout;
|
||||||
|
int j;
|
||||||
|
|
||||||
|
memset (&parms, 0, sizeof(parms));
|
||||||
|
|
||||||
|
COM_InitArgv (argc, argv);
|
||||||
|
parms.argc = com_argc;
|
||||||
|
parms.argv = com_argv;
|
||||||
|
|
||||||
|
parms.memsize = 16*1024*1024;
|
||||||
|
|
||||||
|
j = COM_CheckParm("-mem");
|
||||||
|
if (j)
|
||||||
|
parms.memsize = (int) (Q_atof(com_argv[j+1]) * 1024 * 1024);
|
||||||
|
if ((parms.membase = malloc (parms.memsize)) == NULL)
|
||||||
|
Sys_Error("Can't allocate %ld\n", parms.memsize);
|
||||||
|
|
||||||
|
parms.basedir = BASEDIR;
|
||||||
|
|
||||||
|
/*
|
||||||
|
if (Sys_FileTime ("id1/pak0.pak") != -1)
|
||||||
|
else
|
||||||
|
parms.basedir = "/raid/quake/v2";
|
||||||
|
*/
|
||||||
|
|
||||||
|
SV_Init (&parms);
|
||||||
|
|
||||||
|
// run one frame immediately for first heartbeat
|
||||||
|
SV_Frame (0.1);
|
||||||
|
|
||||||
|
//
|
||||||
|
// main loop
|
||||||
|
//
|
||||||
|
oldtime = Sys_DoubleTime () - 0.1;
|
||||||
|
while (1)
|
||||||
|
{
|
||||||
|
// select on the net socket and stdin
|
||||||
|
// the only reason we have a timeout at all is so that if the last
|
||||||
|
// connected client times out, the message would not otherwise
|
||||||
|
// be printed until the next event.
|
||||||
|
FD_ZERO(&fdset);
|
||||||
|
if (do_stdin)
|
||||||
|
FD_SET(0, &fdset);
|
||||||
|
FD_SET(net_socket, &fdset);
|
||||||
|
timeout.tv_sec = 1;
|
||||||
|
timeout.tv_usec = 0;
|
||||||
|
if (select (net_socket+1, &fdset, NULL, NULL, &timeout) == -1)
|
||||||
|
continue;
|
||||||
|
stdin_ready = FD_ISSET(0, &fdset);
|
||||||
|
|
||||||
|
// find time passed since last cycle
|
||||||
|
newtime = Sys_DoubleTime ();
|
||||||
|
time = newtime - oldtime;
|
||||||
|
oldtime = newtime;
|
||||||
|
|
||||||
|
SV_Frame (time);
|
||||||
|
|
||||||
|
// extrasleep is just a way to generate a fucked up connection on purpose
|
||||||
|
/* if (sys_extrasleep.value)
|
||||||
|
CVAR_FIXME */
|
||||||
|
if (sys_extrasleep->value)
|
||||||
|
/* usleep (sys_extrasleep.value);
|
||||||
|
CVAR_FIXME */
|
||||||
|
usleep (sys_extrasleep->value);
|
||||||
|
}
|
||||||
|
return 1;
|
||||||
|
}
|
|
@ -4,6 +4,7 @@
|
||||||
(description)
|
(description)
|
||||||
|
|
||||||
Copyright (C) 1996-1997 Id Software, Inc.
|
Copyright (C) 1996-1997 Id Software, Inc.
|
||||||
|
Copyright (C) 2000 Marcus Sundberg [mackan@stacken.kth.se]
|
||||||
|
|
||||||
This program is free software; you can redistribute it and/or
|
This program is free software; you can redistribute it and/or
|
||||||
modify it under the terms of the GNU General Public License
|
modify it under the terms of the GNU General Public License
|
||||||
|
@ -29,39 +30,86 @@
|
||||||
#ifdef HAVE_CONFIG_H
|
#ifdef HAVE_CONFIG_H
|
||||||
# include <config.h>
|
# include <config.h>
|
||||||
#endif
|
#endif
|
||||||
#include <sys/types.h>
|
|
||||||
#include "qwsvdef.h"
|
|
||||||
|
|
||||||
#ifdef NeXT
|
|
||||||
#include <libc.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
#include <sys/time.h>
|
#include <sys/time.h>
|
||||||
|
|
||||||
#ifdef HAVE_SYS_DIR_H
|
#include "sys.h"
|
||||||
# include <sys/dir.h>
|
#include "quakedef.h"
|
||||||
#endif
|
|
||||||
|
|
||||||
/* cvar_t sys_nostdout = {"sys_nostdout","0"};
|
/* cvar_t sys_nostdout = {"sys_nostdout","0"};
|
||||||
CVAR_FIXME */
|
CVAR_FIXME */
|
||||||
cvar_t *sys_nostdout;
|
cvar_t *sys_nostdout;
|
||||||
/* cvar_t sys_extrasleep = {"sys_extrasleep","0"};
|
|
||||||
CVAR_FIXME */
|
|
||||||
cvar_t *sys_extrasleep;
|
|
||||||
|
|
||||||
qboolean stdin_ready;
|
|
||||||
qboolean is_server = true;
|
qboolean is_server = true;
|
||||||
|
|
||||||
|
|
||||||
|
/* The translation table between the graphical font and plain ASCII --KB */
|
||||||
|
static char qfont_table[256] =
|
||||||
|
{
|
||||||
|
'\0', '#', '#', '#', '#', '.', '#', '#',
|
||||||
|
'#', 9, 10, '#', ' ', 13, '.', '.',
|
||||||
|
'[', ']', '0', '1', '2', '3', '4', '5',
|
||||||
|
'6', '7', '8', '9', '.', '<', '=', '>',
|
||||||
|
' ', '!', '"', '#', '$', '%', '&', '\'',
|
||||||
|
'(', ')', '*', '+', ',', '-', '.', '/',
|
||||||
|
'0', '1', '2', '3', '4', '5', '6', '7',
|
||||||
|
'8', '9', ':', ';', '<', '=', '>', '?',
|
||||||
|
'@', 'A', 'B', 'C', 'D', 'E', 'F', 'G',
|
||||||
|
'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O',
|
||||||
|
'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W',
|
||||||
|
'X', 'Y', 'Z', '[', '\\', ']', '^', '_',
|
||||||
|
'`', 'a', 'b', 'c', 'd', 'e', 'f', 'g',
|
||||||
|
'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o',
|
||||||
|
'p', 'q', 'r', 's', 't', 'u', 'v', 'w',
|
||||||
|
'x', 'y', 'z', '{', '|', '}', '~', '<',
|
||||||
|
|
||||||
|
'<', '=', '>', '#', '#', '.', '#', '#',
|
||||||
|
'#', '#', ' ', '#', ' ', '>', '.', '.',
|
||||||
|
'[', ']', '0', '1', '2', '3', '4', '5',
|
||||||
|
'6', '7', '8', '9', '.', '<', '=', '>',
|
||||||
|
' ', '!', '"', '#', '$', '%', '&', '\'',
|
||||||
|
'(', ')', '*', '+', ',', '-', '.', '/',
|
||||||
|
'0', '1', '2', '3', '4', '5', '6', '7',
|
||||||
|
'8', '9', ':', ';', '<', '=', '>', '?',
|
||||||
|
'@', 'A', 'B', 'C', 'D', 'E', 'F', 'G',
|
||||||
|
'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O',
|
||||||
|
'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W',
|
||||||
|
'X', 'Y', 'Z', '[', '\\', ']', '^', '_',
|
||||||
|
'`', 'a', 'b', 'c', 'd', 'e', 'f', 'g',
|
||||||
|
'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o',
|
||||||
|
'p', 'q', 'r', 's', 't', 'u', 'v', 'w',
|
||||||
|
'x', 'y', 'z', '{', '|', '}', '~', '<'
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
===============================================================================
|
================
|
||||||
|
Sys_Printf
|
||||||
REQUIRED SYS FUNCTIONS
|
================
|
||||||
|
|
||||||
===============================================================================
|
|
||||||
*/
|
*/
|
||||||
|
void Sys_Printf (char *fmt, ...)
|
||||||
|
{
|
||||||
|
va_list argptr;
|
||||||
|
char text[2048];
|
||||||
|
unsigned char *p;
|
||||||
|
|
||||||
|
if (sys_nostdout->value) return;
|
||||||
|
|
||||||
|
va_start(argptr,fmt);
|
||||||
|
vsnprintf(text, sizeof(text), fmt, argptr);
|
||||||
|
va_end(argptr);
|
||||||
|
|
||||||
|
/* translate to ASCII instead of printing [xx] --KB */
|
||||||
|
for (p = (unsigned char *)text; *p; p++)
|
||||||
|
putc(qfont_table[*p], stdout);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
============
|
============
|
||||||
|
@ -72,10 +120,9 @@ returns -1 if not present
|
||||||
*/
|
*/
|
||||||
int Sys_FileTime (char *path)
|
int Sys_FileTime (char *path)
|
||||||
{
|
{
|
||||||
struct stat buf;
|
struct stat buf;
|
||||||
|
|
||||||
if (stat (path,&buf) == -1)
|
if (stat(path,&buf) == -1) return -1;
|
||||||
return -1;
|
|
||||||
|
|
||||||
return buf.st_mtime;
|
return buf.st_mtime;
|
||||||
}
|
}
|
||||||
|
@ -89,10 +136,8 @@ Sys_mkdir
|
||||||
*/
|
*/
|
||||||
void Sys_mkdir (char *path)
|
void Sys_mkdir (char *path)
|
||||||
{
|
{
|
||||||
if (mkdir (path, 0777) != -1)
|
if (mkdir(path, 0777) == 0) return;
|
||||||
return;
|
if (errno != EEXIST) Sys_Error("mkdir %s: %s",path, strerror(errno));
|
||||||
if (errno != EEXIST)
|
|
||||||
Sys_Error ("mkdir %s: %s",path, strerror(errno));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -117,192 +162,3 @@ double Sys_DoubleTime (void)
|
||||||
|
|
||||||
return (tp.tv_sec - secbase) + tp.tv_usec/1000000.0;
|
return (tp.tv_sec - secbase) + tp.tv_usec/1000000.0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
================
|
|
||||||
Sys_Error
|
|
||||||
================
|
|
||||||
*/
|
|
||||||
void Sys_Error (char *error, ...)
|
|
||||||
{
|
|
||||||
va_list argptr;
|
|
||||||
char string[1024];
|
|
||||||
|
|
||||||
va_start (argptr, error);
|
|
||||||
vsnprintf (string, sizeof(string), error,argptr);
|
|
||||||
va_end (argptr);
|
|
||||||
printf ("Fatal error: %s\n",string);
|
|
||||||
|
|
||||||
exit (1);
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
================
|
|
||||||
Sys_Printf
|
|
||||||
================
|
|
||||||
*/
|
|
||||||
void Sys_Printf (char *fmt, ...)
|
|
||||||
{
|
|
||||||
va_list argptr;
|
|
||||||
static char text[2048];
|
|
||||||
unsigned char *p;
|
|
||||||
|
|
||||||
va_start (argptr, fmt);
|
|
||||||
vsnprintf (text, sizeof(text), fmt, argptr);
|
|
||||||
va_end (argptr);
|
|
||||||
|
|
||||||
/* if (sys_nostdout.value)
|
|
||||||
CVAR_FIXME */
|
|
||||||
if (sys_nostdout->value)
|
|
||||||
return;
|
|
||||||
|
|
||||||
for (p = (unsigned char *)text; *p; p++) {
|
|
||||||
*p &= 0x7f;
|
|
||||||
if ((*p > 128 || *p < 32) && *p != 10 && *p != 13 && *p != 9)
|
|
||||||
printf("[%02x]", *p);
|
|
||||||
else
|
|
||||||
putc(*p, stdout);
|
|
||||||
}
|
|
||||||
fflush(stdout);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
================
|
|
||||||
Sys_Quit
|
|
||||||
================
|
|
||||||
*/
|
|
||||||
void Sys_Quit (void)
|
|
||||||
{
|
|
||||||
exit (0); // appkit isn't running
|
|
||||||
}
|
|
||||||
|
|
||||||
static int do_stdin = 1;
|
|
||||||
|
|
||||||
/*
|
|
||||||
================
|
|
||||||
Sys_ConsoleInput
|
|
||||||
|
|
||||||
Checks for a complete line of text typed in at the console, then forwards
|
|
||||||
it to the host command processor
|
|
||||||
================
|
|
||||||
*/
|
|
||||||
char *Sys_ConsoleInput (void)
|
|
||||||
{
|
|
||||||
static char text[256];
|
|
||||||
int len;
|
|
||||||
|
|
||||||
if (!stdin_ready || !do_stdin)
|
|
||||||
return NULL; // the select didn't say it was ready
|
|
||||||
stdin_ready = false;
|
|
||||||
|
|
||||||
len = read (0, text, sizeof(text));
|
|
||||||
if (len == 0) {
|
|
||||||
// end of file
|
|
||||||
do_stdin = 0;
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
if (len < 1)
|
|
||||||
return NULL;
|
|
||||||
text[len-1] = 0; // rip off the /n and terminate
|
|
||||||
|
|
||||||
return text;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
=============
|
|
||||||
Sys_Init
|
|
||||||
|
|
||||||
Quake calls this so the system can register variables before host_hunklevel
|
|
||||||
is marked
|
|
||||||
=============
|
|
||||||
*/
|
|
||||||
void Sys_Init (void)
|
|
||||||
{
|
|
||||||
/* Cvar_RegisterVariable (&sys_nostdout);
|
|
||||||
CVAR_FIXME */
|
|
||||||
sys_nostdout = Cvar_Get("sys_nostdout", "0", CVAR_NONE, "None");
|
|
||||||
/* Cvar_RegisterVariable (&sys_extrasleep);
|
|
||||||
CVAR_FIXME */
|
|
||||||
sys_extrasleep = Cvar_Get("sys_extrasleep", "0", CVAR_NONE, "None");
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
=============
|
|
||||||
main
|
|
||||||
=============
|
|
||||||
*/
|
|
||||||
int main(int argc, char *argv[])
|
|
||||||
{
|
|
||||||
double time, oldtime, newtime;
|
|
||||||
quakeparms_t parms;
|
|
||||||
fd_set fdset;
|
|
||||||
extern int net_socket;
|
|
||||||
struct timeval timeout;
|
|
||||||
int j;
|
|
||||||
|
|
||||||
memset (&parms, 0, sizeof(parms));
|
|
||||||
|
|
||||||
COM_InitArgv (argc, argv);
|
|
||||||
parms.argc = com_argc;
|
|
||||||
parms.argv = com_argv;
|
|
||||||
|
|
||||||
parms.memsize = 16*1024*1024;
|
|
||||||
|
|
||||||
j = COM_CheckParm("-mem");
|
|
||||||
if (j)
|
|
||||||
parms.memsize = (int) (Q_atof(com_argv[j+1]) * 1024 * 1024);
|
|
||||||
if ((parms.membase = malloc (parms.memsize)) == NULL)
|
|
||||||
Sys_Error("Can't allocate %ld\n", parms.memsize);
|
|
||||||
|
|
||||||
parms.basedir = ".";
|
|
||||||
|
|
||||||
/*
|
|
||||||
if (Sys_FileTime ("id1/pak0.pak") != -1)
|
|
||||||
else
|
|
||||||
parms.basedir = "/raid/quake/v2";
|
|
||||||
*/
|
|
||||||
|
|
||||||
SV_Init (&parms);
|
|
||||||
|
|
||||||
// run one frame immediately for first heartbeat
|
|
||||||
SV_Frame (0.1);
|
|
||||||
|
|
||||||
//
|
|
||||||
// main loop
|
|
||||||
//
|
|
||||||
oldtime = Sys_DoubleTime () - 0.1;
|
|
||||||
while (1)
|
|
||||||
{
|
|
||||||
// select on the net socket and stdin
|
|
||||||
// the only reason we have a timeout at all is so that if the last
|
|
||||||
// connected client times out, the message would not otherwise
|
|
||||||
// be printed until the next event.
|
|
||||||
FD_ZERO(&fdset);
|
|
||||||
if (do_stdin)
|
|
||||||
FD_SET(0, &fdset);
|
|
||||||
FD_SET(net_socket, &fdset);
|
|
||||||
timeout.tv_sec = 1;
|
|
||||||
timeout.tv_usec = 0;
|
|
||||||
if (select (net_socket+1, &fdset, NULL, NULL, &timeout) == -1)
|
|
||||||
continue;
|
|
||||||
stdin_ready = FD_ISSET(0, &fdset);
|
|
||||||
|
|
||||||
// find time passed since last cycle
|
|
||||||
newtime = Sys_DoubleTime ();
|
|
||||||
time = newtime - oldtime;
|
|
||||||
oldtime = newtime;
|
|
||||||
|
|
||||||
SV_Frame (time);
|
|
||||||
|
|
||||||
// extrasleep is just a way to generate a fucked up connection on purpose
|
|
||||||
/* if (sys_extrasleep.value)
|
|
||||||
CVAR_FIXME */
|
|
||||||
if (sys_extrasleep->value)
|
|
||||||
/* usleep (sys_extrasleep.value);
|
|
||||||
CVAR_FIXME */
|
|
||||||
usleep (sys_extrasleep->value);
|
|
||||||
}
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue