mirror of
https://github.com/yquake2/yquake2remaster.git
synced 2025-02-20 19:02:23 +00:00
Räume posix.c und system.c auf und fixe einige Abartigkeiten
This commit is contained in:
parent
00dd2eb4af
commit
1ad221b667
5 changed files with 466 additions and 390 deletions
|
@ -543,8 +543,6 @@ void CL_ConnectionlessPacket (void)
|
|||
return;
|
||||
}
|
||||
|
||||
Sys_AppActivate ();
|
||||
|
||||
s = MSG_ReadString (&net_message);
|
||||
Cbuf_AddText (s);
|
||||
Cbuf_AddText ("\n");
|
||||
|
|
|
@ -719,10 +719,6 @@ void SCR_DebugGraph (float value, int color);
|
|||
|
||||
/* NON-PORTABLE SYSTEM SERVICES */
|
||||
|
||||
void Sys_Init (void);
|
||||
|
||||
void Sys_AppActivate (void);
|
||||
|
||||
void Sys_UnloadGame (void);
|
||||
void *Sys_GetGameAPI (void *parms);
|
||||
|
||||
|
|
|
@ -245,10 +245,7 @@ void Qcommon_Init (int argc, char **argv)
|
|||
if (dedicated->value)
|
||||
Cmd_AddCommand ("quit", Com_Quit);
|
||||
|
||||
Sys_Init ();
|
||||
|
||||
Netchan_Init ();
|
||||
|
||||
SV_Init ();
|
||||
#ifndef DEDICATED_ONLY
|
||||
CL_Init ();
|
||||
|
|
|
@ -1,22 +1,22 @@
|
|||
/*
|
||||
Copyright (C) 1997-2001 Id Software, Inc.
|
||||
|
||||
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 the Free Software
|
||||
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
|
||||
*/
|
||||
* Copyright (C) 1997-2001 Id Software, Inc.
|
||||
*
|
||||
* 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 the Free Software
|
||||
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
*
|
||||
*/
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
|
@ -25,253 +25,301 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|||
#include <ctype.h>
|
||||
#include <dirent.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#if defined(__linux__)
|
||||
#define __USE_GNU
|
||||
#endif
|
||||
|
||||
#include <sys/mman.h>
|
||||
#include <sys/time.h>
|
||||
|
||||
#include "glob/glob.h"
|
||||
|
||||
#include "glob/glob.h"
|
||||
#include "../common/header/common.h"
|
||||
|
||||
#if defined(__FreeBSD__)
|
||||
#include <machine/param.h>
|
||||
|
||||
#if defined( __FreeBSD__ )
|
||||
#include <machine/param.h>
|
||||
#define MAP_ANONYMOUS MAP_ANON
|
||||
#endif
|
||||
|
||||
//===============================================================================
|
||||
|
||||
/* For mremap() */
|
||||
#if defined( __linux__ )
|
||||
#define __USE_GNU
|
||||
#endif
|
||||
|
||||
byte *membase;
|
||||
int maxhunksize;
|
||||
int curhunksize;
|
||||
|
||||
void *Hunk_Begin (int maxsize)
|
||||
void *
|
||||
Hunk_Begin ( int maxsize )
|
||||
{
|
||||
// reserve a huge chunk of memory, but don't commit any yet
|
||||
maxhunksize = maxsize + sizeof(int);
|
||||
/* reserve a huge chunk of memory, but don't commit any yet */
|
||||
maxhunksize = maxsize + sizeof ( int );
|
||||
curhunksize = 0;
|
||||
|
||||
#if (defined __FreeBSD__)
|
||||
membase = mmap(0, maxhunksize, PROT_READ|PROT_WRITE,
|
||||
MAP_PRIVATE|MAP_ANON, -1, 0);
|
||||
#else
|
||||
membase = mmap(0, maxhunksize, PROT_READ|PROT_WRITE,
|
||||
MAP_PRIVATE|MAP_ANONYMOUS, -1, 0);
|
||||
#endif
|
||||
membase = mmap( 0, maxhunksize, PROT_READ | PROT_WRITE,
|
||||
MAP_PRIVATE | MAP_ANONYMOUS, -1, 0 );
|
||||
|
||||
if (membase == NULL || membase == (byte *)-1)
|
||||
Sys_Error("unable to virtual allocate %d bytes", maxsize);
|
||||
if ( ( membase == NULL ) || ( membase == (byte *) -1 ) )
|
||||
{
|
||||
Sys_Error( "unable to virtual allocate %d bytes", maxsize );
|
||||
}
|
||||
|
||||
*((int *)membase) = curhunksize;
|
||||
*( (int *) membase ) = curhunksize;
|
||||
|
||||
return membase + sizeof(int);
|
||||
return ( membase + sizeof ( int ) );
|
||||
}
|
||||
|
||||
void *Hunk_Alloc (int size)
|
||||
void *
|
||||
Hunk_Alloc ( int size )
|
||||
{
|
||||
byte *buf;
|
||||
|
||||
// round to cacheline
|
||||
size = (size+31)&~31;
|
||||
if (curhunksize + size > maxhunksize)
|
||||
Sys_Error("Hunk_Alloc overflow");
|
||||
buf = membase + sizeof(int) + curhunksize;
|
||||
/* round to cacheline */
|
||||
size = ( size + 31 ) & ~31;
|
||||
|
||||
if ( curhunksize + size > maxhunksize )
|
||||
{
|
||||
Sys_Error( "Hunk_Alloc overflow" );
|
||||
}
|
||||
|
||||
buf = membase + sizeof ( int ) + curhunksize;
|
||||
curhunksize += size;
|
||||
return buf;
|
||||
return ( buf );
|
||||
}
|
||||
|
||||
int Hunk_End (void)
|
||||
int
|
||||
Hunk_End ( void )
|
||||
{
|
||||
byte *n = NULL;
|
||||
|
||||
#if defined(__FreeBSD__)
|
||||
size_t old_size = maxhunksize;
|
||||
size_t new_size = curhunksize + sizeof(int);
|
||||
void * unmap_base;
|
||||
size_t unmap_len;
|
||||
#if defined( __FreeBSD__ )
|
||||
size_t old_size = maxhunksize;
|
||||
size_t new_size = curhunksize + sizeof ( int );
|
||||
void *unmap_base;
|
||||
size_t unmap_len;
|
||||
|
||||
new_size = round_page(new_size);
|
||||
old_size = round_page(old_size);
|
||||
if (new_size > old_size)
|
||||
n = 0; /* error */
|
||||
else if (new_size < old_size)
|
||||
{
|
||||
unmap_base = (caddr_t)(membase + new_size);
|
||||
unmap_len = old_size - new_size;
|
||||
n = munmap(unmap_base, unmap_len) + membase;
|
||||
}
|
||||
#endif
|
||||
new_size = round_page( new_size );
|
||||
old_size = round_page( old_size );
|
||||
|
||||
#if defined(__linux__)
|
||||
n = mremap(membase, maxhunksize, curhunksize + sizeof(int), 0);
|
||||
#endif
|
||||
|
||||
if (n != membase)
|
||||
Sys_Error("Hunk_End: Could not remap virtual block (%d)", errno);
|
||||
*((int *)membase) = curhunksize + sizeof(int);
|
||||
|
||||
return curhunksize;
|
||||
}
|
||||
|
||||
void Hunk_Free (void *base)
|
||||
{
|
||||
byte *m;
|
||||
|
||||
if (base) {
|
||||
m = ((byte *)base) - sizeof(int);
|
||||
if (munmap(m, *((int *)m)))
|
||||
Sys_Error("Hunk_Free: munmap failed (%d)", errno);
|
||||
}
|
||||
}
|
||||
|
||||
//===============================================================================
|
||||
|
||||
/*
|
||||
================
|
||||
Sys_Milliseconds
|
||||
================
|
||||
*/
|
||||
int curtime;
|
||||
int Sys_Milliseconds (void)
|
||||
{
|
||||
struct timeval tp;
|
||||
struct timezone tzp;
|
||||
static int secbase;
|
||||
|
||||
gettimeofday(&tp, &tzp);
|
||||
|
||||
if (!secbase)
|
||||
if ( new_size > old_size )
|
||||
{
|
||||
secbase = tp.tv_sec;
|
||||
return tp.tv_usec/1000;
|
||||
n = 0; /* error */
|
||||
}
|
||||
else if ( new_size < old_size )
|
||||
{
|
||||
unmap_base = (caddr_t) ( membase + new_size );
|
||||
unmap_len = old_size - new_size;
|
||||
n = munmap( unmap_base, unmap_len ) + membase;
|
||||
}
|
||||
|
||||
curtime = (tp.tv_sec - secbase)*1000 + tp.tv_usec/1000;
|
||||
|
||||
return curtime;
|
||||
}
|
||||
#endif
|
||||
|
||||
void Sys_Mkdir (char *path)
|
||||
{
|
||||
mkdir (path, 0777);
|
||||
#if defined( __linux__ )
|
||||
n = mremap( membase, maxhunksize, curhunksize + sizeof ( int ), 0 );
|
||||
#endif
|
||||
|
||||
if ( n != membase )
|
||||
{
|
||||
Sys_Error( "Hunk_End: Could not remap virtual block (%d)", errno );
|
||||
}
|
||||
|
||||
*( (int *) membase ) = curhunksize + sizeof ( int );
|
||||
|
||||
return ( curhunksize );
|
||||
}
|
||||
|
||||
void
|
||||
Sys_Rmdir(char *path)
|
||||
Hunk_Free ( void *base )
|
||||
{
|
||||
rmdir(path);
|
||||
}
|
||||
byte *m;
|
||||
|
||||
if ( base )
|
||||
{
|
||||
m = ( (byte *) base ) - sizeof ( int );
|
||||
|
||||
if ( munmap( m, *( (int *) m ) ) )
|
||||
{
|
||||
Sys_Error( "Hunk_Free: munmap failed (%d)", errno );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int curtime;
|
||||
|
||||
int
|
||||
Sys_Milliseconds ( void )
|
||||
{
|
||||
struct timeval tp;
|
||||
struct timezone tzp;
|
||||
static int secbase;
|
||||
|
||||
gettimeofday( &tp, &tzp );
|
||||
|
||||
if ( !secbase )
|
||||
{
|
||||
secbase = tp.tv_sec;
|
||||
return ( tp.tv_usec / 1000 );
|
||||
}
|
||||
|
||||
curtime = ( tp.tv_sec - secbase ) * 1000 + tp.tv_usec / 1000;
|
||||
|
||||
return ( curtime );
|
||||
}
|
||||
|
||||
void
|
||||
Sys_Mkdir ( char *path )
|
||||
{
|
||||
mkdir( path, 0755 );
|
||||
}
|
||||
|
||||
void
|
||||
Sys_Rmdir ( char *path )
|
||||
{
|
||||
rmdir( path );
|
||||
}
|
||||
|
||||
char *
|
||||
Sys_GetCurrentDirectory(void)
|
||||
Sys_GetCurrentDirectory ( void )
|
||||
{
|
||||
static char dir[MAX_OSPATH];
|
||||
static char dir [ MAX_OSPATH ];
|
||||
|
||||
if (!getcwd(dir, sizeof(dir)))
|
||||
Sys_Error("Couldn't get current working directory");
|
||||
if ( !getcwd( dir, sizeof ( dir ) ) )
|
||||
{
|
||||
Sys_Error( "Couldn't get current working directory" );
|
||||
}
|
||||
|
||||
return dir;
|
||||
return ( dir );
|
||||
}
|
||||
|
||||
char *strlwr (char *s)
|
||||
char *
|
||||
strlwr ( char *s )
|
||||
{
|
||||
char *p = s;
|
||||
while (*s) {
|
||||
*s = tolower(*s);
|
||||
|
||||
while ( *s )
|
||||
{
|
||||
*s = tolower( *s );
|
||||
s++;
|
||||
}
|
||||
return p;
|
||||
|
||||
return ( p );
|
||||
}
|
||||
|
||||
//============================================
|
||||
|
||||
static char findbase[MAX_OSPATH];
|
||||
static char findpath[MAX_OSPATH];
|
||||
static char findpattern[MAX_OSPATH];
|
||||
static DIR *fdir;
|
||||
static char findbase [ MAX_OSPATH ];
|
||||
static char findpath [ MAX_OSPATH ];
|
||||
static char findpattern [ MAX_OSPATH ];
|
||||
static DIR *fdir;
|
||||
|
||||
static qboolean CompareAttributes(char *path, char *name,
|
||||
unsigned musthave, unsigned canthave )
|
||||
static qboolean
|
||||
CompareAttributes ( char *path, char *name, unsigned musthave, unsigned canthave )
|
||||
{
|
||||
struct stat st;
|
||||
char fn[MAX_OSPATH];
|
||||
char fn [ MAX_OSPATH ];
|
||||
|
||||
// . and .. never match
|
||||
if (strcmp(name, ".") == 0 || strcmp(name, "..") == 0)
|
||||
return false;
|
||||
/* . and .. never match */
|
||||
if ( ( strcmp( name, "." ) == 0 ) || ( strcmp( name, ".." ) == 0 ) )
|
||||
{
|
||||
return ( false );
|
||||
}
|
||||
|
||||
return true;
|
||||
return ( true );
|
||||
|
||||
if (stat(fn, &st) == -1)
|
||||
return false; // shouldn't happen
|
||||
if ( stat( fn, &st ) == -1 )
|
||||
{
|
||||
return ( false ); /* shouldn't happen */
|
||||
}
|
||||
|
||||
if ( ( st.st_mode & S_IFDIR ) && ( canthave & SFF_SUBDIR ) )
|
||||
return false;
|
||||
{
|
||||
return ( false );
|
||||
}
|
||||
|
||||
if ( ( musthave & SFF_SUBDIR ) && !( st.st_mode & S_IFDIR ) )
|
||||
return false;
|
||||
{
|
||||
return ( false );
|
||||
}
|
||||
|
||||
return true;
|
||||
return ( true );
|
||||
}
|
||||
|
||||
char *Sys_FindFirst (char *path, unsigned musthave, unsigned canhave)
|
||||
char *
|
||||
Sys_FindFirst ( char *path, unsigned musthave, unsigned canhave )
|
||||
{
|
||||
struct dirent *d;
|
||||
char *p;
|
||||
|
||||
if (fdir)
|
||||
Sys_Error ("Sys_BeginFind without close");
|
||||
if ( fdir )
|
||||
{
|
||||
Sys_Error( "Sys_BeginFind without close" );
|
||||
}
|
||||
|
||||
strcpy(findbase, path);
|
||||
strcpy( findbase, path );
|
||||
|
||||
if ((p = strrchr(findbase, '/')) != NULL) {
|
||||
if ( ( p = strrchr( findbase, '/' ) ) != NULL )
|
||||
{
|
||||
*p = 0;
|
||||
strcpy(findpattern, p + 1);
|
||||
} else
|
||||
strcpy(findpattern, "*");
|
||||
strcpy( findpattern, p + 1 );
|
||||
}
|
||||
else
|
||||
{
|
||||
strcpy( findpattern, "*" );
|
||||
}
|
||||
|
||||
if (strcmp(findpattern, "*.*") == 0)
|
||||
strcpy(findpattern, "*");
|
||||
|
||||
if ((fdir = opendir(findbase)) == NULL)
|
||||
return NULL;
|
||||
while ((d = readdir(fdir)) != NULL) {
|
||||
if (!*findpattern || glob_match(findpattern, d->d_name)) {
|
||||
if (CompareAttributes(findbase, d->d_name, musthave, canhave)) {
|
||||
sprintf (findpath, "%s/%s", findbase, d->d_name);
|
||||
return findpath;
|
||||
if ( strcmp( findpattern, "*.*" ) == 0 )
|
||||
{
|
||||
strcpy( findpattern, "*" );
|
||||
}
|
||||
|
||||
if ( ( fdir = opendir( findbase ) ) == NULL )
|
||||
{
|
||||
return ( NULL );
|
||||
}
|
||||
|
||||
while ( ( d = readdir( fdir ) ) != NULL )
|
||||
{
|
||||
if ( !*findpattern || glob_match( findpattern, d->d_name ) )
|
||||
{
|
||||
if ( CompareAttributes( findbase, d->d_name, musthave, canhave ) )
|
||||
{
|
||||
sprintf( findpath, "%s/%s", findbase, d->d_name );
|
||||
return ( findpath );
|
||||
}
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
|
||||
return ( NULL );
|
||||
}
|
||||
|
||||
char *Sys_FindNext (unsigned musthave, unsigned canhave)
|
||||
char *
|
||||
Sys_FindNext ( unsigned musthave, unsigned canhave )
|
||||
{
|
||||
struct dirent *d;
|
||||
|
||||
if (fdir == NULL)
|
||||
return NULL;
|
||||
while ((d = readdir(fdir)) != NULL) {
|
||||
if (!*findpattern || glob_match(findpattern, d->d_name)) {
|
||||
if (CompareAttributes(findbase, d->d_name, musthave, canhave)) {
|
||||
sprintf (findpath, "%s/%s", findbase, d->d_name);
|
||||
return findpath;
|
||||
if ( fdir == NULL )
|
||||
{
|
||||
return ( NULL );
|
||||
}
|
||||
|
||||
while ( ( d = readdir( fdir ) ) != NULL )
|
||||
{
|
||||
if ( !*findpattern || glob_match( findpattern, d->d_name ) )
|
||||
{
|
||||
if ( CompareAttributes( findbase, d->d_name, musthave, canhave ) )
|
||||
{
|
||||
sprintf( findpath, "%s/%s", findbase, d->d_name );
|
||||
return ( findpath );
|
||||
}
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
|
||||
return ( NULL );
|
||||
}
|
||||
|
||||
void Sys_FindClose (void)
|
||||
void
|
||||
Sys_FindClose ( void )
|
||||
{
|
||||
if (fdir != NULL)
|
||||
closedir(fdir);
|
||||
if ( fdir != NULL )
|
||||
{
|
||||
closedir( fdir );
|
||||
}
|
||||
|
||||
fdir = NULL;
|
||||
}
|
||||
|
||||
|
||||
//============================================
|
||||
|
||||
|
|
|
@ -1,22 +1,22 @@
|
|||
/*
|
||||
Copyright (C) 1997-2001 Id Software, Inc.
|
||||
|
||||
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 the Free Software
|
||||
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
|
||||
*/
|
||||
* Copyright (C) 1997-2001 Id Software, Inc.
|
||||
*
|
||||
* 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 the Free Software
|
||||
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
*
|
||||
*/
|
||||
#include <unistd.h>
|
||||
#include <signal.h>
|
||||
#include <stdlib.h>
|
||||
|
@ -41,285 +41,322 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|||
|
||||
#include "posix.h"
|
||||
|
||||
unsigned sys_frame_time;
|
||||
static void *game_library;
|
||||
|
||||
cvar_t *nostdout;
|
||||
|
||||
unsigned sys_frame_time;
|
||||
|
||||
uid_t saved_euid;
|
||||
qboolean stdin_active = true;
|
||||
|
||||
// =======================================================================
|
||||
// General routines
|
||||
// =======================================================================
|
||||
|
||||
void Sys_ConsoleOutput (char *string)
|
||||
void
|
||||
Sys_ConsoleOutput ( char *string )
|
||||
{
|
||||
if (nostdout && nostdout->value)
|
||||
if ( nostdout && nostdout->value )
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
fputs(string, stdout);
|
||||
fputs( string, stdout );
|
||||
}
|
||||
|
||||
void Sys_Printf (char *fmt, ...)
|
||||
void
|
||||
Sys_Printf ( char *fmt, ... )
|
||||
{
|
||||
va_list argptr;
|
||||
char text[1024];
|
||||
unsigned char *p;
|
||||
va_list argptr;
|
||||
char text [ 1024 ];
|
||||
unsigned char *p;
|
||||
|
||||
va_start (argptr,fmt);
|
||||
vsnprintf (text,1024,fmt,argptr);
|
||||
va_end (argptr);
|
||||
va_start( argptr, fmt );
|
||||
vsnprintf( text, 1024, fmt, argptr );
|
||||
va_end( argptr );
|
||||
|
||||
if (nostdout && nostdout->value)
|
||||
if ( nostdout && nostdout->value )
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
for (p = (unsigned char *)text; *p; p++) {
|
||||
for ( p = (unsigned char *) text; *p; p++ )
|
||||
{
|
||||
*p &= 0x7f;
|
||||
if ((*p > 128 || *p < 32) && *p != 10 && *p != 13 && *p != 9)
|
||||
printf("[%02x]", *p);
|
||||
|
||||
if ( ( ( *p > 128 ) || ( *p < 32 ) ) && ( *p != 10 ) && ( *p != 13 ) && ( *p != 9 ) )
|
||||
{
|
||||
printf( "[%02x]", *p );
|
||||
}
|
||||
else
|
||||
putc(*p, stdout);
|
||||
{
|
||||
putc( *p, stdout );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Sys_Quit (void)
|
||||
void
|
||||
Sys_Quit ( void )
|
||||
{
|
||||
#ifndef DEDICATED_ONLY
|
||||
CL_Shutdown ();
|
||||
CL_Shutdown();
|
||||
#endif
|
||||
Qcommon_Shutdown ();
|
||||
fcntl (0, F_SETFL, fcntl (0, F_GETFL, 0) & ~FNDELAY);
|
||||
_exit(0);
|
||||
Qcommon_Shutdown();
|
||||
fcntl( 0, F_SETFL, fcntl( 0, F_GETFL, 0 ) & ~FNDELAY );
|
||||
exit( 0 );
|
||||
}
|
||||
|
||||
void Sys_Init(void)
|
||||
void
|
||||
Sys_Error ( char *error, ... )
|
||||
{
|
||||
}
|
||||
va_list argptr;
|
||||
char string [ 1024 ];
|
||||
|
||||
void Sys_Error (char *error, ...)
|
||||
{
|
||||
va_list argptr;
|
||||
char string[1024];
|
||||
|
||||
// change stdin to non blocking
|
||||
fcntl (0, F_SETFL, fcntl (0, F_GETFL, 0) & ~FNDELAY);
|
||||
/* change stdin to non blocking */
|
||||
fcntl( 0, F_SETFL, fcntl( 0, F_GETFL, 0 ) & ~FNDELAY );
|
||||
|
||||
#ifndef DEDICATED_ONLY
|
||||
CL_Shutdown ();
|
||||
CL_Shutdown();
|
||||
#endif
|
||||
Qcommon_Shutdown ();
|
||||
|
||||
va_start (argptr,error);
|
||||
vsnprintf (string,1024,error,argptr);
|
||||
va_end (argptr);
|
||||
fprintf(stderr, "Error: %s\n", string);
|
||||
Qcommon_Shutdown();
|
||||
|
||||
_exit (1);
|
||||
va_start( argptr, error );
|
||||
vsnprintf( string, 1024, error, argptr );
|
||||
va_end( argptr );
|
||||
fprintf( stderr, "Error: %s\n", string );
|
||||
|
||||
}
|
||||
exit( 1 );
|
||||
}
|
||||
|
||||
void Sys_Warn (char *warning, ...)
|
||||
{
|
||||
va_list argptr;
|
||||
char string[1024];
|
||||
void
|
||||
Sys_Warn ( char *warning, ... )
|
||||
{
|
||||
va_list argptr;
|
||||
char string [ 1024 ];
|
||||
|
||||
va_start (argptr,warning);
|
||||
vsnprintf (string,1024,warning,argptr);
|
||||
va_end (argptr);
|
||||
fprintf(stderr, "Warning: %s", string);
|
||||
}
|
||||
va_start( argptr, warning );
|
||||
vsnprintf( string, 1024, warning, argptr );
|
||||
va_end( argptr );
|
||||
fprintf( stderr, "Warning: %s", string );
|
||||
}
|
||||
|
||||
/*
|
||||
============
|
||||
Sys_FileTime
|
||||
|
||||
returns -1 if not present
|
||||
============
|
||||
*/
|
||||
int Sys_FileTime (char *path)
|
||||
* returns -1 if not present
|
||||
*/
|
||||
int
|
||||
Sys_FileTime ( char *path )
|
||||
{
|
||||
struct stat buf;
|
||||
|
||||
if (stat (path,&buf) == -1)
|
||||
return -1;
|
||||
|
||||
return buf.st_mtime;
|
||||
struct stat buf;
|
||||
|
||||
if ( stat( path, &buf ) == -1 )
|
||||
{
|
||||
return ( -1 );
|
||||
}
|
||||
|
||||
return ( buf.st_mtime );
|
||||
}
|
||||
|
||||
void floating_point_exception_handler(int whatever)
|
||||
void
|
||||
floating_point_exception_handler ( int whatever )
|
||||
{
|
||||
signal(SIGFPE, floating_point_exception_handler);
|
||||
signal( SIGFPE, floating_point_exception_handler );
|
||||
}
|
||||
|
||||
char *Sys_ConsoleInput(void)
|
||||
char *
|
||||
Sys_ConsoleInput ( void )
|
||||
{
|
||||
static char text[256];
|
||||
int len;
|
||||
fd_set fdset;
|
||||
static char text [ 256 ];
|
||||
int len;
|
||||
fd_set fdset;
|
||||
struct timeval timeout;
|
||||
|
||||
if (!dedicated || !dedicated->value)
|
||||
return NULL;
|
||||
|
||||
if (!stdin_active)
|
||||
return NULL;
|
||||
|
||||
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 == 0) { // eof!
|
||||
stdin_active = false;
|
||||
return NULL;
|
||||
if ( !dedicated || !dedicated->value )
|
||||
{
|
||||
return ( NULL );
|
||||
}
|
||||
|
||||
if (len < 1)
|
||||
return NULL;
|
||||
text[len-1] = 0; // rip off the /n and terminate
|
||||
if ( !stdin_active )
|
||||
{
|
||||
return ( NULL );
|
||||
}
|
||||
|
||||
return text;
|
||||
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 == 0 ) /* eof! */
|
||||
{
|
||||
stdin_active = false;
|
||||
return ( NULL );
|
||||
}
|
||||
|
||||
if ( len < 1 )
|
||||
{
|
||||
return ( NULL );
|
||||
}
|
||||
|
||||
text [ len - 1 ] = 0; /* rip off the /n and terminate */
|
||||
|
||||
return ( text );
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
|
||||
static void *game_library;
|
||||
|
||||
/*
|
||||
=================
|
||||
Sys_UnloadGame
|
||||
=================
|
||||
*/
|
||||
void Sys_UnloadGame (void)
|
||||
void
|
||||
Sys_UnloadGame ( void )
|
||||
{
|
||||
if (game_library)
|
||||
dlclose (game_library);
|
||||
if ( game_library )
|
||||
{
|
||||
dlclose( game_library );
|
||||
}
|
||||
|
||||
game_library = NULL;
|
||||
}
|
||||
|
||||
/*
|
||||
=================
|
||||
Sys_GetGameAPI
|
||||
|
||||
Loads the game dll
|
||||
=================
|
||||
*/
|
||||
void *Sys_GetGameAPI (void *parms)
|
||||
* Loads the game dll
|
||||
*/
|
||||
void *
|
||||
Sys_GetGameAPI ( void *parms )
|
||||
{
|
||||
void *(*GetGameAPI) (void *);
|
||||
|
||||
FILE *fp;
|
||||
char name[MAX_OSPATH];
|
||||
char *path;
|
||||
char *str_p;
|
||||
void *( *GetGameAPI )(void *);
|
||||
|
||||
FILE *fp;
|
||||
char name [ MAX_OSPATH ];
|
||||
char *path;
|
||||
char *str_p;
|
||||
const char *gamename = "game.so";
|
||||
|
||||
setreuid(getuid(), getuid());
|
||||
setegid(getgid());
|
||||
setreuid( getuid(), getuid() );
|
||||
setegid( getgid() );
|
||||
|
||||
if (game_library)
|
||||
Com_Error (ERR_FATAL, "Sys_GetGameAPI without Sys_UnloadingGame");
|
||||
|
||||
Com_Printf("------- Loading %s -------\n", gamename);
|
||||
|
||||
// now run through the search paths
|
||||
path = NULL;
|
||||
while (1)
|
||||
if ( game_library )
|
||||
{
|
||||
path = FS_NextPath (path);
|
||||
if (!path)
|
||||
return NULL; // couldn't find one anywhere
|
||||
snprintf (name, MAX_OSPATH, "%s/%s", path, gamename);
|
||||
|
||||
Com_Error( ERR_FATAL, "Sys_GetGameAPI without Sys_UnloadingGame" );
|
||||
}
|
||||
|
||||
Com_Printf( "------- Loading %s -------\n", gamename );
|
||||
|
||||
/* now run through the search paths */
|
||||
path = NULL;
|
||||
|
||||
while ( 1 )
|
||||
{
|
||||
path = FS_NextPath( path );
|
||||
|
||||
if ( !path )
|
||||
{
|
||||
return ( NULL ); /* couldn't find one anywhere */
|
||||
}
|
||||
|
||||
snprintf( name, MAX_OSPATH, "%s/%s", path, gamename );
|
||||
|
||||
/* skip it if it just doesn't exist */
|
||||
fp = fopen(name, "rb");
|
||||
if (fp == NULL)
|
||||
fp = fopen( name, "rb" );
|
||||
|
||||
if ( fp == NULL )
|
||||
{
|
||||
continue;
|
||||
fclose(fp);
|
||||
|
||||
game_library = dlopen (name, RTLD_NOW);
|
||||
if (game_library)
|
||||
}
|
||||
|
||||
fclose( fp );
|
||||
|
||||
game_library = dlopen( name, RTLD_NOW );
|
||||
|
||||
if ( game_library )
|
||||
{
|
||||
Com_MDPrintf ("LoadLibrary (%s)\n",name);
|
||||
Com_MDPrintf( "LoadLibrary (%s)\n", name );
|
||||
break;
|
||||
}
|
||||
else
|
||||
}
|
||||
else
|
||||
{
|
||||
Com_Printf ("LoadLibrary (%s):", name);
|
||||
|
||||
path = (char *)dlerror();
|
||||
str_p = strchr(path, ':'); // skip the path (already shown)
|
||||
if (str_p == NULL)
|
||||
Com_Printf( "LoadLibrary (%s):", name );
|
||||
|
||||
path = (char *) dlerror();
|
||||
str_p = strchr( path, ':' ); /* skip the path (already shown) */
|
||||
|
||||
if ( str_p == NULL )
|
||||
{
|
||||
str_p = path;
|
||||
}
|
||||
else
|
||||
{
|
||||
str_p++;
|
||||
|
||||
Com_Printf ("%s\n", str_p);
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
Com_Printf( "%s\n", str_p );
|
||||
|
||||
return ( NULL );
|
||||
}
|
||||
}
|
||||
|
||||
GetGameAPI = (void *)dlsym (game_library, "GetGameAPI");
|
||||
GetGameAPI = (void *) dlsym( game_library, "GetGameAPI" );
|
||||
|
||||
if (!GetGameAPI)
|
||||
if ( !GetGameAPI )
|
||||
{
|
||||
Sys_UnloadGame ();
|
||||
return NULL;
|
||||
Sys_UnloadGame();
|
||||
return ( NULL );
|
||||
}
|
||||
|
||||
return GetGameAPI (parms);
|
||||
return ( GetGameAPI( parms ) );
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
|
||||
void Sys_AppActivate (void)
|
||||
{
|
||||
}
|
||||
|
||||
void Sys_SendKeyEvents (void)
|
||||
void
|
||||
Sys_SendKeyEvents ( void )
|
||||
{
|
||||
#ifndef DEDICATED_ONLY
|
||||
if (KBD_Update_fp)
|
||||
|
||||
if ( KBD_Update_fp )
|
||||
{
|
||||
KBD_Update_fp();
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
// grab frame time
|
||||
/* grab frame time */
|
||||
sys_frame_time = Sys_Milliseconds();
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
|
||||
int main (int argc, char **argv)
|
||||
int
|
||||
main ( int argc, char **argv )
|
||||
{
|
||||
int time, oldtime, newtime;
|
||||
int time, oldtime, newtime;
|
||||
|
||||
// go back to real user for config loads
|
||||
/* go back to real user for config loads */
|
||||
saved_euid = geteuid();
|
||||
seteuid(getuid());
|
||||
|
||||
printf ("Quake 2\n");
|
||||
seteuid( getuid() );
|
||||
|
||||
Qcommon_Init(argc, argv);
|
||||
printf( "Quake 2\n" );
|
||||
|
||||
fcntl(0, F_SETFL, fcntl (0, F_GETFL, 0) | FNDELAY);
|
||||
Qcommon_Init( argc, argv );
|
||||
|
||||
nostdout = Cvar_Get("nostdout", "0", 0);
|
||||
if (!nostdout->value) {
|
||||
fcntl(0, F_SETFL, fcntl (0, F_GETFL, 0) | FNDELAY);
|
||||
}
|
||||
oldtime = Sys_Milliseconds ();
|
||||
while (1)
|
||||
fcntl( 0, F_SETFL, fcntl( 0, F_GETFL, 0 ) | FNDELAY );
|
||||
|
||||
nostdout = Cvar_Get( "nostdout", "0", 0 );
|
||||
|
||||
if ( !nostdout->value )
|
||||
{
|
||||
// find time spent rendering last frame
|
||||
do {
|
||||
newtime = Sys_Milliseconds ();
|
||||
fcntl( 0, F_SETFL, fcntl( 0, F_GETFL, 0 ) | FNDELAY );
|
||||
}
|
||||
|
||||
oldtime = Sys_Milliseconds();
|
||||
|
||||
/* The legendary Quake II mainloop */
|
||||
while ( 1 )
|
||||
{
|
||||
/* find time spent rendering last frame */
|
||||
do
|
||||
{
|
||||
newtime = Sys_Milliseconds();
|
||||
time = newtime - oldtime;
|
||||
} while (time < 1);
|
||||
Qcommon_Frame (time);
|
||||
}
|
||||
while ( time < 1 );
|
||||
|
||||
Qcommon_Frame( time );
|
||||
oldtime = newtime;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue