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-08-27 07:13:32 +00:00
|
|
|
#ifdef HAVE_UNISTD_H
|
|
|
|
# include <unistd.h>
|
|
|
|
#endif
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
#include <errno.h>
|
|
|
|
#include <fcntl.h>
|
|
|
|
#include <signal.h>
|
2001-08-27 07:13:32 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
2001-02-19 21:15:25 +00:00
|
|
|
#include <time.h>
|
2001-08-27 07:13:32 +00:00
|
|
|
#include <sys/mman.h>
|
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <sys/time.h>
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-03-27 20:33:07 +00:00
|
|
|
#include "QF/cvar.h"
|
2001-08-29 17:45:53 +00:00
|
|
|
#include "QF/qargs.h"
|
|
|
|
#include "QF/sys.h"
|
2001-08-27 07:13:32 +00:00
|
|
|
|
2001-02-19 21:15:25 +00:00
|
|
|
#include "host.h"
|
2001-08-27 07:13:32 +00:00
|
|
|
#include "server.h"
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-08-29 17:45:53 +00:00
|
|
|
qboolean isDedicated = false;
|
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
|
|
|
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
|
|
|
|
|
|
|
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
|
|
|
|
2001-08-27 07:13:32 +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-08-27 07:13:32 +00:00
|
|
|
// Sys_Warn("floating point exception\n");
|
2001-02-26 06:48:02 +00:00
|
|
|
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
|
|
|
{
|
|
|
|
}
|
|
|
|
#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);
|
|
|
|
|
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-08-29 17:45:53 +00:00
|
|
|
Sys_Init_Cvars ();
|
2001-02-26 06:48:02 +00:00
|
|
|
Sys_Init ();
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-08-29 17:45:53 +00:00
|
|
|
if (!sys_nostdout->int_val) {
|
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-08-27 07:13:32 +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);
|
2001-08-27 07:13:32 +00:00
|
|
|
continue; // not time to run a server only tic yet
|
2001-02-26 06:48:02 +00:00
|
|
|
}
|
|
|
|
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
|
|
|
}
|