2001-02-19 21:15:25 +00:00
|
|
|
/*
|
|
|
|
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
|
2001-05-09 05:41:34 +00:00
|
|
|
#ifdef HAVE_STRING_H
|
|
|
|
# include <string.h>
|
|
|
|
#endif
|
|
|
|
#ifdef HAVE_STRINGS_H
|
|
|
|
# include <strings.h>
|
|
|
|
#endif
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <sys/time.h>
|
|
|
|
#include <fcntl.h>
|
|
|
|
#include <sys/mman.h>
|
|
|
|
#include <signal.h>
|
|
|
|
#include <time.h>
|
|
|
|
|
2001-03-27 20:33:07 +00:00
|
|
|
#include "QF/sys.h"
|
|
|
|
#include "QF/qargs.h"
|
|
|
|
#include "QF/cvar.h"
|
2001-02-19 21:15:25 +00:00
|
|
|
#include "server.h"
|
|
|
|
#include "host.h"
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
qboolean isDedicated;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
char *basedir = ".";
|
|
|
|
char *cachedir = "/tmp";
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
cvar_t *sys_linerefresh;
|
|
|
|
cvar_t *timestamps;
|
|
|
|
cvar_t *timeformat;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-08-18 21:57:45 +00:00
|
|
|
|
2001-02-19 21:15:25 +00:00
|
|
|
void
|
2001-08-18 21:57:45 +00:00
|
|
|
Sys_Init (void)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
2001-08-18 21:57:45 +00:00
|
|
|
#ifdef USE_INTEL_ASM
|
|
|
|
Sys_SetFPCW ();
|
|
|
|
#endif
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2001-08-18 21:57:45 +00:00
|
|
|
Sys_Quit
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
Sys_Quit (void)
|
|
|
|
{
|
|
|
|
Host_Shutdown ();
|
|
|
|
fcntl (0, F_SETFL, fcntl (0, F_GETFL, 0) & ~FNDELAY);
|
|
|
|
fflush (stdout);
|
|
|
|
exit (0);
|
|
|
|
}
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-08-18 21:57:45 +00:00
|
|
|
/*
|
|
|
|
Sys_Error
|
|
|
|
*/
|
2001-02-19 21:15:25 +00:00
|
|
|
void
|
2001-03-30 23:24:57 +00:00
|
|
|
Sys_Error (const char *error, ...)
|
2001-02-26 06:48:02 +00:00
|
|
|
{
|
|
|
|
va_list argptr;
|
|
|
|
char string[1024];
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
// change stdin to non blocking
|
2001-02-26 06:48:02 +00:00
|
|
|
fcntl (0, F_SETFL, fcntl (0, F_GETFL, 0) & ~FNDELAY);
|
|
|
|
|
|
|
|
va_start (argptr, error);
|
|
|
|
vsnprintf (string, sizeof (string), error, argptr);
|
|
|
|
va_end (argptr);
|
|
|
|
fprintf (stderr, "Error: %s\n", string);
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
Host_Shutdown ();
|
|
|
|
exit (1);
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
}
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
void
|
2001-08-18 21:57:45 +00:00
|
|
|
Sys_DebugLog (const char *file, const char *fmt, ...)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
2001-08-18 21:57:45 +00:00
|
|
|
va_list argptr;
|
|
|
|
static char data[1024];
|
|
|
|
int fd;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-08-18 21:57:45 +00:00
|
|
|
va_start (argptr, fmt);
|
|
|
|
vsnprintf (data, sizeof (data), fmt, argptr);
|
|
|
|
va_end (argptr);
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-08-18 21:57:45 +00:00
|
|
|
fd = open (file, O_WRONLY | O_CREAT | O_APPEND, 0666);
|
|
|
|
write (fd, data, strlen (data));
|
|
|
|
close (fd);
|
|
|
|
}
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
void
|
|
|
|
floating_point_exception_handler (int whatever)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
2001-02-26 06:48:02 +00:00
|
|
|
// Sys_Warn("floating point exception\n");
|
|
|
|
signal (SIGFPE, floating_point_exception_handler);
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
|
|
|
|
2001-08-18 21:57:45 +00:00
|
|
|
/*
|
|
|
|
Sys_ConsoleInput
|
|
|
|
|
|
|
|
Checks for a complete line of text typed in at the console, then forwards
|
|
|
|
it to the host command processor
|
|
|
|
*/
|
2001-07-15 07:04:17 +00:00
|
|
|
const char *
|
2001-02-26 06:48:02 +00:00
|
|
|
Sys_ConsoleInput (void)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
2001-02-26 06:48:02 +00:00
|
|
|
static char text[256];
|
|
|
|
int len;
|
|
|
|
fd_set fdset;
|
|
|
|
struct timeval timeout;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
if (cls.state == ca_dedicated) {
|
2001-02-26 06:48:02 +00:00
|
|
|
FD_ZERO (&fdset);
|
|
|
|
FD_SET (0, &fdset); // stdin
|
2001-02-19 21:15:25 +00:00
|
|
|
timeout.tv_sec = 0;
|
|
|
|
timeout.tv_usec = 0;
|
2001-02-26 06:48:02 +00:00
|
|
|
if (select (1, &fdset, NULL, NULL, &timeout) == -1
|
|
|
|
|| !FD_ISSET (0, &fdset)) return NULL;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
len = read (0, text, sizeof (text));
|
2001-02-19 21:15:25 +00:00
|
|
|
if (len < 1)
|
|
|
|
return NULL;
|
2001-02-26 06:48:02 +00:00
|
|
|
text[len - 1] = 0; // rip off the /n and terminate
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
return text;
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifndef USE_INTEL_ASM
|
2001-02-26 06:48:02 +00:00
|
|
|
void
|
|
|
|
Sys_HighFPPrecision (void)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
void
|
|
|
|
Sys_LowFPPrecision (void)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
|
|
|
}
|
2001-02-26 06:48:02 +00:00
|
|
|
|
2001-02-19 21:15:25 +00:00
|
|
|
#endif
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
int
|
2001-07-15 07:04:17 +00:00
|
|
|
main (int c, const char *v[])
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
double time, oldtime, newtime;
|
2001-02-19 21:15:25 +00:00
|
|
|
quakeparms_t parms;
|
2001-07-16 23:36:43 +00:00
|
|
|
extern VFile *vcrFile;
|
2001-02-26 06:48:02 +00:00
|
|
|
extern int recording;
|
|
|
|
int j;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-07-05 00:12:43 +00:00
|
|
|
signal (SIGFPE, SIG_IGN);
|
2001-07-02 18:11:34 +00:00
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
memset (&parms, 0, sizeof (parms));
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
COM_InitArgv (c, v);
|
2001-02-19 21:15:25 +00:00
|
|
|
parms.argc = com_argc;
|
|
|
|
parms.argv = com_argv;
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
parms.memsize = 16 * 1024 * 1024;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
j = COM_CheckParm ("-mem");
|
2001-02-19 21:15:25 +00:00
|
|
|
if (j)
|
2001-02-26 06:48:02 +00:00
|
|
|
parms.memsize = (int) (atof (com_argv[j + 1]) * 1024 * 1024);
|
2001-02-19 21:15:25 +00:00
|
|
|
parms.membase = malloc (parms.memsize);
|
|
|
|
|
|
|
|
parms.basedir = basedir;
|
|
|
|
// caching is disabled by default, use -cachedir to enable
|
2001-02-26 06:48:02 +00:00
|
|
|
// parms.cachedir = cachedir;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
fcntl (0, F_SETFL, fcntl (0, F_GETFL, 0) | FNDELAY);
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
Host_Init (&parms);
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
Sys_Init ();
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-04-10 23:39:30 +00:00
|
|
|
sys_nostdout = Cvar_Get ("sys_nostdout", "0", CVAR_NONE, NULL,
|
|
|
|
"set to disable std out");
|
2001-02-26 06:48:02 +00:00
|
|
|
if (COM_CheckParm ("-nostdout"))
|
2001-03-30 23:24:57 +00:00
|
|
|
Cvar_Set (sys_nostdout, "1");
|
2001-02-19 21:15:25 +00:00
|
|
|
else {
|
2001-02-26 06:48:02 +00:00
|
|
|
fcntl (0, F_SETFL, fcntl (0, F_GETFL, 0) | FNDELAY);
|
2001-02-20 04:57:07 +00:00
|
|
|
printf ("Quake -- Version %s\n", NQ_VERSION);
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
oldtime = Sys_DoubleTime () - 0.1;
|
|
|
|
while (1) {
|
2001-02-19 21:15:25 +00:00
|
|
|
// find time spent rendering last frame
|
2001-02-26 06:48:02 +00:00
|
|
|
newtime = Sys_DoubleTime ();
|
|
|
|
time = newtime - oldtime;
|
|
|
|
|
|
|
|
if (cls.state == ca_dedicated) { // play vcrfiles at max speed
|
2001-07-16 23:36:43 +00:00
|
|
|
if (time < sys_ticrate->value && (!vcrFile || recording)) {
|
2001-02-26 06:48:02 +00:00
|
|
|
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);
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
}
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
}
|
2001-07-05 03:28:40 +00:00
|
|
|
|