2009-02-28 14:41:18 +00:00
|
|
|
/*
|
2010-10-18 13:04:28 +00:00
|
|
|
* Copyright (C) 1997-2001 Id Software, Inc.
|
|
|
|
*
|
2010-10-18 13:19:17 +00:00
|
|
|
* 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.
|
2010-10-18 13:04:28 +00:00
|
|
|
*
|
2010-10-18 13:19:17 +00:00
|
|
|
* This program is distributed in the hope that it will be useful, but
|
|
|
|
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
2010-10-18 13:04:28 +00:00
|
|
|
* 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
|
2010-10-18 13:19:17 +00:00
|
|
|
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
|
|
|
|
* 02111-1307, USA.
|
2010-10-18 13:04:28 +00:00
|
|
|
*
|
2010-10-18 13:19:17 +00:00
|
|
|
* =======================================================================
|
|
|
|
*
|
|
|
|
* This file implements all system dependend generic funktions
|
|
|
|
*
|
|
|
|
* =======================================================================
|
2010-10-18 13:04:28 +00:00
|
|
|
*/
|
2010-10-18 13:19:17 +00:00
|
|
|
|
2009-02-28 14:41:18 +00:00
|
|
|
#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 <sys/ipc.h>
|
|
|
|
#include <sys/shm.h>
|
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <ctype.h>
|
|
|
|
#include <sys/wait.h>
|
|
|
|
#include <sys/mman.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#include <dlfcn.h>
|
2010-10-18 13:19:17 +00:00
|
|
|
#include <dirent.h>
|
2009-02-28 14:41:18 +00:00
|
|
|
|
2010-10-18 13:28:14 +00:00
|
|
|
#include "header/glob.h"
|
2010-09-01 08:45:26 +00:00
|
|
|
#include "../common/header/common.h"
|
2010-10-18 13:28:14 +00:00
|
|
|
#include "header/unix.h"
|
2009-02-28 14:41:18 +00:00
|
|
|
|
2010-10-18 13:04:28 +00:00
|
|
|
unsigned sys_frame_time;
|
2010-10-18 13:19:17 +00:00
|
|
|
int curtime;
|
2010-10-18 13:04:28 +00:00
|
|
|
static void *game_library;
|
2009-02-28 14:41:18 +00:00
|
|
|
|
2010-10-18 13:19:17 +00:00
|
|
|
static char findbase [ MAX_OSPATH ];
|
|
|
|
static char findpath [ MAX_OSPATH ];
|
|
|
|
static char findpattern [ MAX_OSPATH ];
|
|
|
|
static DIR *fdir;
|
|
|
|
|
2010-10-18 13:04:28 +00:00
|
|
|
cvar_t *nostdout;
|
2009-02-28 14:41:18 +00:00
|
|
|
uid_t saved_euid;
|
|
|
|
qboolean stdin_active = true;
|
|
|
|
|
2010-10-18 13:19:17 +00:00
|
|
|
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 )
|
|
|
|
{
|
|
|
|
static char dir [ MAX_OSPATH ];
|
|
|
|
|
|
|
|
if ( !getcwd( dir, sizeof ( dir ) ) )
|
|
|
|
{
|
|
|
|
Sys_Error( "Couldn't get current working directory" );
|
|
|
|
}
|
|
|
|
|
|
|
|
return ( dir );
|
|
|
|
}
|
|
|
|
|
|
|
|
char *
|
|
|
|
strlwr ( char *s )
|
|
|
|
{
|
|
|
|
char *p = s;
|
|
|
|
|
|
|
|
while ( *s )
|
|
|
|
{
|
|
|
|
*s = tolower( *s );
|
|
|
|
s++;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ( p );
|
|
|
|
}
|
|
|
|
|
|
|
|
static qboolean
|
|
|
|
CompareAttributes ( char *path, char *name, unsigned musthave, unsigned canthave )
|
|
|
|
{
|
|
|
|
struct stat st;
|
|
|
|
char fn [ MAX_OSPATH ];
|
|
|
|
|
|
|
|
/* . and .. never match */
|
|
|
|
if ( ( strcmp( name, "." ) == 0 ) || ( strcmp( name, ".." ) == 0 ) )
|
|
|
|
{
|
|
|
|
return ( false );
|
|
|
|
}
|
|
|
|
|
|
|
|
return ( true );
|
|
|
|
|
|
|
|
if ( stat( fn, &st ) == -1 )
|
|
|
|
{
|
|
|
|
return ( false ); /* shouldn't happen */
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( ( st.st_mode & S_IFDIR ) && ( canthave & SFF_SUBDIR ) )
|
|
|
|
{
|
|
|
|
return ( false );
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( ( musthave & SFF_SUBDIR ) && !( st.st_mode & S_IFDIR ) )
|
|
|
|
{
|
|
|
|
return ( false );
|
|
|
|
}
|
|
|
|
|
|
|
|
return ( true );
|
|
|
|
}
|
|
|
|
|
|
|
|
char *
|
|
|
|
Sys_FindFirst ( char *path, unsigned musthave, unsigned canhave )
|
|
|
|
{
|
|
|
|
struct dirent *d;
|
|
|
|
char *p;
|
|
|
|
|
|
|
|
if ( fdir )
|
|
|
|
{
|
|
|
|
Sys_Error( "Sys_BeginFind without close" );
|
|
|
|
}
|
|
|
|
|
|
|
|
strcpy( findbase, path );
|
|
|
|
|
|
|
|
if ( ( p = strrchr( findbase, '/' ) ) != NULL )
|
|
|
|
{
|
|
|
|
*p = 0;
|
|
|
|
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 );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return ( NULL );
|
|
|
|
}
|
|
|
|
|
|
|
|
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 );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return ( NULL );
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
Sys_FindClose ( void )
|
|
|
|
{
|
|
|
|
if ( fdir != NULL )
|
|
|
|
{
|
|
|
|
closedir( fdir );
|
|
|
|
}
|
|
|
|
|
|
|
|
fdir = NULL;
|
|
|
|
}
|
|
|
|
|
2010-10-18 13:04:28 +00:00
|
|
|
void
|
|
|
|
Sys_ConsoleOutput ( char *string )
|
2009-02-28 14:41:18 +00:00
|
|
|
{
|
2010-10-18 13:04:28 +00:00
|
|
|
if ( nostdout && nostdout->value )
|
|
|
|
{
|
2009-02-28 14:41:18 +00:00
|
|
|
return;
|
2010-10-18 13:04:28 +00:00
|
|
|
}
|
2009-02-28 14:41:18 +00:00
|
|
|
|
2010-10-18 13:04:28 +00:00
|
|
|
fputs( string, stdout );
|
2009-02-28 14:41:18 +00:00
|
|
|
}
|
|
|
|
|
2010-10-18 13:04:28 +00:00
|
|
|
void
|
|
|
|
Sys_Printf ( char *fmt, ... )
|
2009-02-28 14:41:18 +00:00
|
|
|
{
|
2010-10-18 13:04:28 +00:00
|
|
|
va_list argptr;
|
|
|
|
char text [ 1024 ];
|
|
|
|
unsigned char *p;
|
2009-02-28 14:41:18 +00:00
|
|
|
|
2010-10-18 13:04:28 +00:00
|
|
|
va_start( argptr, fmt );
|
|
|
|
vsnprintf( text, 1024, fmt, argptr );
|
|
|
|
va_end( argptr );
|
2009-02-28 14:41:18 +00:00
|
|
|
|
2010-10-18 13:04:28 +00:00
|
|
|
if ( nostdout && nostdout->value )
|
|
|
|
{
|
2009-02-28 14:41:18 +00:00
|
|
|
return;
|
2010-10-18 13:04:28 +00:00
|
|
|
}
|
2009-02-28 14:41:18 +00:00
|
|
|
|
2010-10-18 13:04:28 +00:00
|
|
|
for ( p = (unsigned char *) text; *p; p++ )
|
|
|
|
{
|
2009-02-28 14:41:18 +00:00
|
|
|
*p &= 0x7f;
|
2010-10-18 13:04:28 +00:00
|
|
|
|
|
|
|
if ( ( ( *p > 128 ) || ( *p < 32 ) ) && ( *p != 10 ) && ( *p != 13 ) && ( *p != 9 ) )
|
|
|
|
{
|
|
|
|
printf( "[%02x]", *p );
|
|
|
|
}
|
2009-02-28 14:41:18 +00:00
|
|
|
else
|
2010-10-18 13:04:28 +00:00
|
|
|
{
|
|
|
|
putc( *p, stdout );
|
|
|
|
}
|
2009-02-28 14:41:18 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-10-18 13:04:28 +00:00
|
|
|
void
|
|
|
|
Sys_Quit ( void )
|
2009-02-28 14:41:18 +00:00
|
|
|
{
|
2009-03-04 16:24:55 +00:00
|
|
|
#ifndef DEDICATED_ONLY
|
2010-10-18 13:04:28 +00:00
|
|
|
CL_Shutdown();
|
2009-03-04 16:24:55 +00:00
|
|
|
#endif
|
2010-10-18 13:04:28 +00:00
|
|
|
Qcommon_Shutdown();
|
|
|
|
fcntl( 0, F_SETFL, fcntl( 0, F_GETFL, 0 ) & ~FNDELAY );
|
|
|
|
exit( 0 );
|
2009-02-28 14:41:18 +00:00
|
|
|
}
|
|
|
|
|
2010-10-18 13:04:28 +00:00
|
|
|
void
|
|
|
|
Sys_Error ( char *error, ... )
|
2009-02-28 14:41:18 +00:00
|
|
|
{
|
2010-10-18 13:04:28 +00:00
|
|
|
va_list argptr;
|
|
|
|
char string [ 1024 ];
|
2009-02-28 14:41:18 +00:00
|
|
|
|
2010-10-18 13:04:28 +00:00
|
|
|
/* change stdin to non blocking */
|
|
|
|
fcntl( 0, F_SETFL, fcntl( 0, F_GETFL, 0 ) & ~FNDELAY );
|
2009-02-28 14:41:18 +00:00
|
|
|
|
2009-03-04 16:24:55 +00:00
|
|
|
#ifndef DEDICATED_ONLY
|
2010-10-18 13:04:28 +00:00
|
|
|
CL_Shutdown();
|
2009-03-04 16:24:55 +00:00
|
|
|
#endif
|
2010-10-18 13:04:28 +00:00
|
|
|
Qcommon_Shutdown();
|
2009-02-28 14:41:18 +00:00
|
|
|
|
2010-10-18 13:04:28 +00:00
|
|
|
va_start( argptr, error );
|
|
|
|
vsnprintf( string, 1024, error, argptr );
|
|
|
|
va_end( argptr );
|
|
|
|
fprintf( stderr, "Error: %s\n", string );
|
2009-02-28 14:41:18 +00:00
|
|
|
|
2010-10-18 13:04:28 +00:00
|
|
|
exit( 1 );
|
|
|
|
}
|
2009-02-28 14:41:18 +00:00
|
|
|
|
2010-10-18 13:04:28 +00:00
|
|
|
void
|
|
|
|
Sys_Warn ( char *warning, ... )
|
|
|
|
{
|
|
|
|
va_list argptr;
|
|
|
|
char string [ 1024 ];
|
2009-02-28 14:41:18 +00:00
|
|
|
|
2010-10-18 13:04:28 +00:00
|
|
|
va_start( argptr, warning );
|
|
|
|
vsnprintf( string, 1024, warning, argptr );
|
|
|
|
va_end( argptr );
|
|
|
|
fprintf( stderr, "Warning: %s", string );
|
|
|
|
}
|
2009-02-28 14:41:18 +00:00
|
|
|
|
|
|
|
/*
|
2010-10-18 13:04:28 +00:00
|
|
|
* returns -1 if not present
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
Sys_FileTime ( char *path )
|
2009-02-28 14:41:18 +00:00
|
|
|
{
|
2010-10-18 13:04:28 +00:00
|
|
|
struct stat buf;
|
|
|
|
|
|
|
|
if ( stat( path, &buf ) == -1 )
|
|
|
|
{
|
|
|
|
return ( -1 );
|
|
|
|
}
|
|
|
|
|
|
|
|
return ( buf.st_mtime );
|
2009-02-28 14:41:18 +00:00
|
|
|
}
|
|
|
|
|
2010-10-18 13:04:28 +00:00
|
|
|
void
|
|
|
|
floating_point_exception_handler ( int whatever )
|
2009-02-28 14:41:18 +00:00
|
|
|
{
|
2010-10-18 13:04:28 +00:00
|
|
|
signal( SIGFPE, floating_point_exception_handler );
|
2009-02-28 14:41:18 +00:00
|
|
|
}
|
|
|
|
|
2010-10-18 13:04:28 +00:00
|
|
|
char *
|
|
|
|
Sys_ConsoleInput ( void )
|
2009-02-28 14:41:18 +00:00
|
|
|
{
|
2010-10-18 13:04:28 +00:00
|
|
|
static char text [ 256 ];
|
|
|
|
int len;
|
|
|
|
fd_set fdset;
|
2009-02-28 14:41:18 +00:00
|
|
|
struct timeval timeout;
|
|
|
|
|
2010-10-18 13:04:28 +00:00
|
|
|
if ( !dedicated || !dedicated->value )
|
|
|
|
{
|
|
|
|
return ( NULL );
|
|
|
|
}
|
2009-02-28 14:41:18 +00:00
|
|
|
|
2010-10-18 13:04:28 +00:00
|
|
|
if ( !stdin_active )
|
|
|
|
{
|
|
|
|
return ( NULL );
|
|
|
|
}
|
2009-02-28 14:41:18 +00:00
|
|
|
|
2010-10-18 13:04:28 +00:00
|
|
|
FD_ZERO( &fdset );
|
|
|
|
FD_SET( 0, &fdset ); /* stdin */
|
2009-02-28 14:41:18 +00:00
|
|
|
timeout.tv_sec = 0;
|
|
|
|
timeout.tv_usec = 0;
|
|
|
|
|
2010-10-18 13:04:28 +00:00
|
|
|
if ( ( select( 1, &fdset, NULL, NULL, &timeout ) == -1 ) || !FD_ISSET( 0, &fdset ) )
|
|
|
|
{
|
|
|
|
return ( NULL );
|
|
|
|
}
|
|
|
|
|
|
|
|
len = read( 0, text, sizeof ( text ) );
|
|
|
|
|
|
|
|
if ( len == 0 ) /* eof! */
|
|
|
|
{
|
2009-02-28 14:41:18 +00:00
|
|
|
stdin_active = false;
|
2010-10-18 13:04:28 +00:00
|
|
|
return ( NULL );
|
2009-02-28 14:41:18 +00:00
|
|
|
}
|
|
|
|
|
2010-10-18 13:04:28 +00:00
|
|
|
if ( len < 1 )
|
|
|
|
{
|
|
|
|
return ( NULL );
|
|
|
|
}
|
2009-02-28 14:41:18 +00:00
|
|
|
|
2010-10-18 13:04:28 +00:00
|
|
|
text [ len - 1 ] = 0; /* rip off the /n and terminate */
|
2009-02-28 14:41:18 +00:00
|
|
|
|
2010-10-18 13:04:28 +00:00
|
|
|
return ( text );
|
|
|
|
}
|
2009-02-28 14:41:18 +00:00
|
|
|
|
2010-10-18 13:04:28 +00:00
|
|
|
void
|
|
|
|
Sys_UnloadGame ( void )
|
2009-02-28 14:41:18 +00:00
|
|
|
{
|
2010-10-18 13:04:28 +00:00
|
|
|
if ( game_library )
|
|
|
|
{
|
|
|
|
dlclose( game_library );
|
|
|
|
}
|
|
|
|
|
2009-02-28 14:41:18 +00:00
|
|
|
game_library = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2010-10-18 13:04:28 +00:00
|
|
|
* Loads the game dll
|
|
|
|
*/
|
|
|
|
void *
|
|
|
|
Sys_GetGameAPI ( void *parms )
|
2009-02-28 14:41:18 +00:00
|
|
|
{
|
2010-10-18 13:04:28 +00:00
|
|
|
void *( *GetGameAPI )(void *);
|
|
|
|
|
|
|
|
FILE *fp;
|
|
|
|
char name [ MAX_OSPATH ];
|
|
|
|
char *path;
|
|
|
|
char *str_p;
|
2009-03-04 16:04:40 +00:00
|
|
|
const char *gamename = "game.so";
|
2009-02-28 14:41:18 +00:00
|
|
|
|
2010-10-18 13:04:28 +00:00
|
|
|
setreuid( getuid(), getuid() );
|
|
|
|
setegid( getgid() );
|
2009-02-28 14:41:18 +00:00
|
|
|
|
2010-10-18 13:04:28 +00:00
|
|
|
if ( game_library )
|
|
|
|
{
|
|
|
|
Com_Error( ERR_FATAL, "Sys_GetGameAPI without Sys_UnloadingGame" );
|
|
|
|
}
|
2009-02-28 14:41:18 +00:00
|
|
|
|
2010-10-18 13:04:28 +00:00
|
|
|
Com_Printf( "------- Loading %s -------\n", gamename );
|
2009-02-28 14:41:18 +00:00
|
|
|
|
2010-10-18 13:04:28 +00:00
|
|
|
/* now run through the search paths */
|
2009-02-28 14:41:18 +00:00
|
|
|
path = NULL;
|
2010-10-18 13:04:28 +00:00
|
|
|
|
|
|
|
while ( 1 )
|
2009-02-28 14:41:18 +00:00
|
|
|
{
|
2010-10-18 13:04:28 +00:00
|
|
|
path = FS_NextPath( path );
|
|
|
|
|
|
|
|
if ( !path )
|
|
|
|
{
|
|
|
|
return ( NULL ); /* couldn't find one anywhere */
|
|
|
|
}
|
|
|
|
|
|
|
|
snprintf( name, MAX_OSPATH, "%s/%s", path, gamename );
|
|
|
|
|
2009-02-28 14:41:18 +00:00
|
|
|
/* skip it if it just doesn't exist */
|
2010-10-18 13:04:28 +00:00
|
|
|
fp = fopen( name, "rb" );
|
|
|
|
|
|
|
|
if ( fp == NULL )
|
|
|
|
{
|
2009-02-28 14:41:18 +00:00
|
|
|
continue;
|
2010-10-18 13:04:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
fclose( fp );
|
|
|
|
|
|
|
|
game_library = dlopen( name, RTLD_NOW );
|
|
|
|
|
|
|
|
if ( game_library )
|
2009-02-28 14:41:18 +00:00
|
|
|
{
|
2010-10-18 13:04:28 +00:00
|
|
|
Com_MDPrintf( "LoadLibrary (%s)\n", name );
|
2009-02-28 14:41:18 +00:00
|
|
|
break;
|
2010-10-18 13:04:28 +00:00
|
|
|
}
|
|
|
|
else
|
2009-02-28 14:41:18 +00:00
|
|
|
{
|
2010-10-18 13:04:28 +00:00
|
|
|
Com_Printf( "LoadLibrary (%s):", name );
|
|
|
|
|
|
|
|
path = (char *) dlerror();
|
|
|
|
str_p = strchr( path, ':' ); /* skip the path (already shown) */
|
|
|
|
|
|
|
|
if ( str_p == NULL )
|
|
|
|
{
|
2009-02-28 14:41:18 +00:00
|
|
|
str_p = path;
|
2010-10-18 13:04:28 +00:00
|
|
|
}
|
2009-02-28 14:41:18 +00:00
|
|
|
else
|
2010-10-18 13:04:28 +00:00
|
|
|
{
|
2009-02-28 14:41:18 +00:00
|
|
|
str_p++;
|
2010-10-18 13:04:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Com_Printf( "%s\n", str_p );
|
|
|
|
|
|
|
|
return ( NULL );
|
2009-02-28 14:41:18 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-10-18 13:04:28 +00:00
|
|
|
GetGameAPI = (void *) dlsym( game_library, "GetGameAPI" );
|
2009-02-28 14:41:18 +00:00
|
|
|
|
2010-10-18 13:04:28 +00:00
|
|
|
if ( !GetGameAPI )
|
2009-02-28 14:41:18 +00:00
|
|
|
{
|
2010-10-18 13:04:28 +00:00
|
|
|
Sys_UnloadGame();
|
|
|
|
return ( NULL );
|
2009-02-28 14:41:18 +00:00
|
|
|
}
|
|
|
|
|
2010-10-18 13:04:28 +00:00
|
|
|
return ( GetGameAPI( parms ) );
|
2009-02-28 14:41:18 +00:00
|
|
|
}
|
|
|
|
|
2010-10-18 13:04:28 +00:00
|
|
|
void
|
|
|
|
Sys_SendKeyEvents ( void )
|
2009-02-28 14:41:18 +00:00
|
|
|
{
|
|
|
|
#ifndef DEDICATED_ONLY
|
2010-10-18 13:04:28 +00:00
|
|
|
|
|
|
|
if ( KBD_Update_fp )
|
|
|
|
{
|
2009-02-28 14:41:18 +00:00
|
|
|
KBD_Update_fp();
|
2010-10-18 13:04:28 +00:00
|
|
|
}
|
|
|
|
|
2009-02-28 14:41:18 +00:00
|
|
|
#endif
|
|
|
|
|
2010-10-18 13:04:28 +00:00
|
|
|
/* grab frame time */
|
2009-02-28 14:41:18 +00:00
|
|
|
sys_frame_time = Sys_Milliseconds();
|
|
|
|
}
|
|
|
|
|
2010-10-18 13:04:28 +00:00
|
|
|
int
|
|
|
|
main ( int argc, char **argv )
|
2009-02-28 14:41:18 +00:00
|
|
|
{
|
2010-10-18 13:04:28 +00:00
|
|
|
int time, oldtime, newtime;
|
2009-02-28 14:41:18 +00:00
|
|
|
|
2010-10-18 13:04:28 +00:00
|
|
|
/* go back to real user for config loads */
|
2009-02-28 14:41:18 +00:00
|
|
|
saved_euid = geteuid();
|
2010-10-18 13:04:28 +00:00
|
|
|
seteuid( getuid() );
|
2009-02-28 14:41:18 +00:00
|
|
|
|
2010-10-18 13:04:28 +00:00
|
|
|
printf( "Quake 2\n" );
|
2009-02-28 14:41:18 +00:00
|
|
|
|
2010-10-18 13:04:28 +00:00
|
|
|
Qcommon_Init( argc, argv );
|
2009-02-28 14:41:18 +00:00
|
|
|
|
2010-10-18 13:04:28 +00:00
|
|
|
fcntl( 0, F_SETFL, fcntl( 0, F_GETFL, 0 ) | FNDELAY );
|
|
|
|
|
|
|
|
nostdout = Cvar_Get( "nostdout", "0", 0 );
|
|
|
|
|
|
|
|
if ( !nostdout->value )
|
|
|
|
{
|
|
|
|
fcntl( 0, F_SETFL, fcntl( 0, F_GETFL, 0 ) | FNDELAY );
|
2009-02-28 14:41:18 +00:00
|
|
|
}
|
2010-10-18 13:04:28 +00:00
|
|
|
|
|
|
|
oldtime = Sys_Milliseconds();
|
|
|
|
|
|
|
|
/* The legendary Quake II mainloop */
|
|
|
|
while ( 1 )
|
2009-02-28 14:41:18 +00:00
|
|
|
{
|
2010-10-18 13:04:28 +00:00
|
|
|
/* find time spent rendering last frame */
|
|
|
|
do
|
|
|
|
{
|
|
|
|
newtime = Sys_Milliseconds();
|
2009-02-28 14:41:18 +00:00
|
|
|
time = newtime - oldtime;
|
2010-10-18 13:04:28 +00:00
|
|
|
}
|
|
|
|
while ( time < 1 );
|
|
|
|
|
|
|
|
Qcommon_Frame( time );
|
2009-02-28 14:41:18 +00:00
|
|
|
oldtime = newtime;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|