2012-01-17 07:57:46 +00:00
# include <jni.h>
# include <errno.h>
# include <android/log.h>
# include "quakedef.h"
# include <unistd.h>
# include <fcntl.h>
# include <dlfcn.h>
# include <sys/stat.h>
# include <dirent.h>
# ifndef isDedicated
# ifdef SERVERONLY
qboolean isDedicated = true ;
# else
qboolean isDedicated = false ;
# endif
# endif
void * sys_window ; /*public so the renderer can attach to the correct place*/
2012-09-30 05:52:03 +00:00
static int sys_running = false ;
2012-07-05 19:42:36 +00:00
int sys_glesversion ;
2012-10-08 04:36:10 +00:00
int sys_soundflags ; /*1 means active. 2 means reset (so claim that its not active for one frame to force a reset)*/
2012-09-30 05:52:03 +00:00
static void * sys_memheap ;
static unsigned int sys_lastframe ;
static unsigned int vibrateduration ;
static char errormessage [ 256 ] ;
extern jmp_buf host_abort ;
2012-11-27 03:23:19 +00:00
cvar_t sys_vibrate = CVARD ( " sys_vibrate " , " 1 " , " Enables the system vibrator for damage events and such things. The value provided is a duration scaler. " ) ;
Android: fat presses, vibrator, onscreen keyboard, keep-screen-on, console scaling, touch-based console scrolling, additional bindables.
Some memory leaks fixed.
latency with the nq protocol over loopback is much reduced.
Terrain: now mostly a property of a (q1 for now) bsp map, file format changed, glsl now built in, terrain editor builtin improved/changed, holes supported.
git-svn-id: https://svn.code.sf.net/p/fteqw/code/trunk@4067 fc73d0e0-1445-4013-8a0c-d673dee63da5
2012-07-14 16:25:18 +00:00
cvar_t sys_osk = CVAR ( " sys_osk " , " 0 " ) ; //to be toggled
2012-11-27 03:23:19 +00:00
cvar_t sys_keepscreenon = CVARD ( " sys_keepscreenon " , " 1 " , " If set, the screen will never darken. This might cost some extra battery power, but then so will running a 3d engine. " ) ; //to be toggled
cvar_t sys_orientation = CVARD ( " sys_orientation " , " landscape " , " Specifies what angle to render quake at. \n Valid values are: sensor (autodetect), landscape, portrait, reverselandscape, reverseportrait " ) ;
cvar_t sys_glesversion_cvar = CVARD ( " sys_glesversion " , " 1 " , " Specifies which version of gles to use. 1 or 2 are valid values. " ) ;
2012-09-30 05:52:03 +00:00
extern cvar_t vid_conautoscale ;
2012-01-17 07:57:46 +00:00
# define LOGI(...) ((void)__android_log_print(ANDROID_LOG_INFO, DISTRIBUTION"Droid", __VA_ARGS__))
# define LOGW(...) ((void)__android_log_print(ANDROID_LOG_WARN, DISTRIBUTION"Droid", __VA_ARGS__))
2012-09-30 05:52:03 +00:00
# define LOGE(...) ((void)__android_log_print(ANDROID_LOG_ERROR, DISTRIBUTION"Droid", __VA_ARGS__))
Android: fat presses, vibrator, onscreen keyboard, keep-screen-on, console scaling, touch-based console scrolling, additional bindables.
Some memory leaks fixed.
latency with the nq protocol over loopback is much reduced.
Terrain: now mostly a property of a (q1 for now) bsp map, file format changed, glsl now built in, terrain editor builtin improved/changed, holes supported.
git-svn-id: https://svn.code.sf.net/p/fteqw/code/trunk@4067 fc73d0e0-1445-4013-8a0c-d673dee63da5
2012-07-14 16:25:18 +00:00
void Sys_Vibrate ( int count )
{
vibrateduration = count * 10 * sys_vibrate . value ;
}
JNIEXPORT jint JNICALL Java_com_fteqw_FTEDroidEngine_getvibrateduration ( JNIEnv * env , jobject obj )
{
unsigned int dur = vibrateduration ;
vibrateduration = 0 ;
return dur ;
}
2012-09-30 05:52:03 +00:00
JNIEXPORT jstring JNICALL Java_com_fteqw_FTEDroidEngine_geterrormessage ( JNIEnv * env , jobject obj )
{
return ( * env ) - > NewStringUTF ( env , errormessage ) ;
}
JNIEXPORT jstring JNICALL Java_com_fteqw_FTEDroidEngine_getpreferedorientation ( JNIEnv * env , jobject obj )
{
sys_orientation . modified = false ;
2012-11-27 03:23:19 +00:00
sys_glesversion_cvar . modified = false ;
2012-09-30 05:52:03 +00:00
return ( * env ) - > NewStringUTF ( env , sys_orientation . string ) ;
}
2012-11-27 03:23:19 +00:00
JNIEXPORT jint JNICALL Java_com_fteqw_FTEDroidEngine_getpreferedglesversion ( JNIEnv * env , jobject obj )
{
return sys_glesversion_cvar . ival ;
}
2012-10-14 09:00:49 +00:00
/*the java passes in all input directly via a 'UI' thread. we don't need to poll it at all*/
void INS_Move ( float * movements , int pnum )
{
}
void INS_Commands ( void )
{
}
void INS_Init ( void )
{
}
void INS_ReInit ( void )
{
}
void INS_Shutdown ( void )
{
}
JNIEXPORT void JNICALL Java_com_fteqw_FTEDroidEngine_keypress ( JNIEnv * env , jobject obj ,
jint down , jint keycode , jint unicode )
{
IN_KeyEvent ( 0 , down , keycode , unicode ) ;
}
JNIEXPORT void JNICALL Java_com_fteqw_FTEDroidEngine_motion ( JNIEnv * env , jobject obj ,
jint act , jint ptrid , jfloat x , jfloat y , jfloat size )
{
if ( act )
IN_KeyEvent ( ptrid , act = = 1 , K_MOUSE1 , 0 ) ;
else
IN_MouseMove ( ptrid , true , x , y , 0 , size ) ;
}
Android: fat presses, vibrator, onscreen keyboard, keep-screen-on, console scaling, touch-based console scrolling, additional bindables.
Some memory leaks fixed.
latency with the nq protocol over loopback is much reduced.
Terrain: now mostly a property of a (q1 for now) bsp map, file format changed, glsl now built in, terrain editor builtin improved/changed, holes supported.
git-svn-id: https://svn.code.sf.net/p/fteqw/code/trunk@4067 fc73d0e0-1445-4013-8a0c-d673dee63da5
2012-07-14 16:25:18 +00:00
JNIEXPORT jint JNICALL Java_com_fteqw_FTEDroidEngine_frame ( JNIEnv * env , jobject obj ,
2012-02-12 05:18:31 +00:00
jfloat ax , jfloat ay , jfloat az )
2012-01-17 07:57:46 +00:00
{
Android: fat presses, vibrator, onscreen keyboard, keep-screen-on, console scaling, touch-based console scrolling, additional bindables.
Some memory leaks fixed.
latency with the nq protocol over loopback is much reduced.
Terrain: now mostly a property of a (q1 for now) bsp map, file format changed, glsl now built in, terrain editor builtin improved/changed, holes supported.
git-svn-id: https://svn.code.sf.net/p/fteqw/code/trunk@4067 fc73d0e0-1445-4013-8a0c-d673dee63da5
2012-07-14 16:25:18 +00:00
int ret ;
2012-02-12 05:18:31 +00:00
static vec3_t oac ;
2012-09-30 05:52:03 +00:00
//if we had an error, don't even run a frame any more.
2012-11-27 03:23:19 +00:00
if ( * errormessage | | ! sys_running )
{
Sys_Printf ( " Crashed or quit \n " ) ;
2012-09-30 05:52:03 +00:00
return 8 ;
2012-11-27 03:23:19 +00:00
}
2012-09-30 05:52:03 +00:00
2012-01-17 07:57:46 +00:00
# ifdef SERVERONLY
SV_Frame ( ) ;
# else
unsigned int now = Sys_Milliseconds ( ) ;
double tdelta = ( now - sys_lastframe ) * 0.001 ;
2012-02-12 05:18:31 +00:00
if ( oac [ 0 ] ! = ax | | oac [ 1 ] ! = ay | | oac [ 2 ] ! = az )
{
Android: fat presses, vibrator, onscreen keyboard, keep-screen-on, console scaling, touch-based console scrolling, additional bindables.
Some memory leaks fixed.
latency with the nq protocol over loopback is much reduced.
Terrain: now mostly a property of a (q1 for now) bsp map, file format changed, glsl now built in, terrain editor builtin improved/changed, holes supported.
git-svn-id: https://svn.code.sf.net/p/fteqw/code/trunk@4067 fc73d0e0-1445-4013-8a0c-d673dee63da5
2012-07-14 16:25:18 +00:00
//down: x= +9.8
//left: y= -9.8
//up: z= +9.8
2012-02-12 05:18:31 +00:00
CSQC_Accelerometer ( ax , ay , az ) ;
oac [ 0 ] = ax ;
oac [ 1 ] = ay ;
oac [ 2 ] = az ;
}
2012-01-17 07:57:46 +00:00
Host_Frame ( tdelta ) ;
sys_lastframe = now ;
# endif
2012-07-08 23:28:41 +00:00
Android: fat presses, vibrator, onscreen keyboard, keep-screen-on, console scaling, touch-based console scrolling, additional bindables.
Some memory leaks fixed.
latency with the nq protocol over loopback is much reduced.
Terrain: now mostly a property of a (q1 for now) bsp map, file format changed, glsl now built in, terrain editor builtin improved/changed, holes supported.
git-svn-id: https://svn.code.sf.net/p/fteqw/code/trunk@4067 fc73d0e0-1445-4013-8a0c-d673dee63da5
2012-07-14 16:25:18 +00:00
ret = 0 ;
if ( key_dest = = key_console | | key_dest = = key_message | | ( key_dest = = key_game & & cls . state = = ca_disconnected ) | | sys_osk . ival )
ret | = 1 ;
if ( vibrateduration )
ret | = 2 ;
if ( sys_keepscreenon . ival )
ret | = 4 ;
2012-09-30 05:52:03 +00:00
if ( * errormessage )
ret | = 8 ;
2012-11-27 03:23:19 +00:00
if ( sys_orientation . modified | | sys_glesversion_cvar . modified )
2012-09-30 05:52:03 +00:00
ret | = 16 ;
2012-10-08 04:36:10 +00:00
if ( sys_soundflags )
{
if ( sys_soundflags & 2 )
sys_soundflags & = ~ 2 ;
else
ret | = 32 ;
}
Android: fat presses, vibrator, onscreen keyboard, keep-screen-on, console scaling, touch-based console scrolling, additional bindables.
Some memory leaks fixed.
latency with the nq protocol over loopback is much reduced.
Terrain: now mostly a property of a (q1 for now) bsp map, file format changed, glsl now built in, terrain editor builtin improved/changed, holes supported.
git-svn-id: https://svn.code.sf.net/p/fteqw/code/trunk@4067 fc73d0e0-1445-4013-8a0c-d673dee63da5
2012-07-14 16:25:18 +00:00
return ret ;
2012-01-17 07:57:46 +00:00
}
2012-09-30 05:52:03 +00:00
//tells us that our old gl context got completely obliterated
JNIEXPORT void JNICALL Java_com_fteqw_FTEDroidEngine_newglcontext ( JNIEnv * env , jobject obj )
{
if ( sys_running )
sys_running = 2 ;
//fixme: wipe image handles
}
//called for init or resizes
2012-01-17 07:57:46 +00:00
JNIEXPORT void JNICALL Java_com_fteqw_FTEDroidEngine_init ( JNIEnv * env , jobject obj ,
2012-07-05 19:42:36 +00:00
jint width , jint height , jint glesversion , jstring japkpath , jstring jusrpath )
2012-01-17 07:57:46 +00:00
{
2012-07-15 03:34:57 +00:00
const char * tmp ;
2012-09-30 05:52:03 +00:00
if ( * errormessage )
return ;
2012-01-17 07:57:46 +00:00
vid . pixelwidth = width ;
vid . pixelheight = height ;
2012-07-05 19:42:36 +00:00
sys_glesversion = glesversion ;
2012-01-29 12:53:12 +00:00
if ( sys_running )
2012-09-30 05:52:03 +00:00
{
Sys_Printf ( " vid size changed \n " ) ;
if ( 1 ) //FFS sys_running == 2)
{
//if our textures got destroyed, we need to reload them all
Cmd_ExecuteString ( " vid_restart \n " , RESTRICT_LOCAL ) ;
}
else
{
//otherwise we just need to set the size properly again.
Cvar_ForceCallback ( & vid_conautoscale ) ;
}
}
2012-01-29 12:53:12 +00:00
else
2012-01-17 07:57:46 +00:00
{
2012-02-12 05:18:31 +00:00
const char * args [ ] =
2012-01-28 10:30:44 +00:00
{
" ftedroid " ,
" -basepack " ,
2012-04-09 19:12:12 +00:00
NULL , /*filled in later*/
2012-01-28 10:30:44 +00:00
" " ,
" "
} ;
2012-07-15 03:34:57 +00:00
char * basepack ;
2012-07-08 23:28:41 +00:00
int align ;
2012-01-17 07:57:46 +00:00
quakeparms_t parms ;
2012-09-30 05:52:03 +00:00
Sys_Printf ( " reinit \n " ) ;
2012-04-09 19:12:12 +00:00
if ( sys_memheap )
free ( sys_memheap ) ;
2012-11-27 03:23:19 +00:00
memset ( & parms , 0 , sizeof ( parms ) ) ;
2012-04-09 19:12:12 +00:00
parms . basedir = NULL ; /*filled in later*/
2012-01-28 10:30:44 +00:00
parms . argc = 3 ;
parms . argv = args ;
Android: fat presses, vibrator, onscreen keyboard, keep-screen-on, console scaling, touch-based console scrolling, additional bindables.
Some memory leaks fixed.
latency with the nq protocol over loopback is much reduced.
Terrain: now mostly a property of a (q1 for now) bsp map, file format changed, glsl now built in, terrain editor builtin improved/changed, holes supported.
git-svn-id: https://svn.code.sf.net/p/fteqw/code/trunk@4067 fc73d0e0-1445-4013-8a0c-d673dee63da5
2012-07-14 16:25:18 +00:00
parms . memsize = 512 * 1024 * 1024 ;
2012-02-12 05:18:31 +00:00
parms . membase = sys_memheap = malloc ( parms . memsize ) ;
2012-01-17 07:57:46 +00:00
if ( ! parms . membase )
{
Sys_Printf ( " Unable to alloc heap \n " ) ;
2012-09-30 05:52:03 +00:00
Q_strncpyz ( errormessage , " Unable to alloc heap \n " , sizeof ( errormessage ) ) ;
2012-01-17 07:57:46 +00:00
return ;
}
2012-04-09 19:12:12 +00:00
2012-07-15 03:34:57 +00:00
basepack = parms . membase ;
2012-04-09 19:12:12 +00:00
tmp = ( * env ) - > GetStringUTFChars ( env , japkpath , NULL ) ;
2012-07-15 03:34:57 +00:00
strcpy ( basepack , tmp ) ;
2012-04-09 19:12:12 +00:00
( * env ) - > ReleaseStringUTFChars ( env , japkpath , tmp ) ;
2012-07-15 03:34:57 +00:00
parms . membase + = strlen ( basepack ) + 1 ;
parms . memsize - = strlen ( basepack ) + 1 ;
2012-04-09 19:12:12 +00:00
parms . basedir = parms . membase ;
tmp = ( * env ) - > GetStringUTFChars ( env , jusrpath , NULL ) ;
strcpy ( parms . basedir , tmp ) ;
( * env ) - > ReleaseStringUTFChars ( env , jusrpath , tmp ) ;
parms . membase + = strlen ( parms . basedir ) + 1 ;
parms . memsize - = strlen ( parms . basedir ) + 1 ;
2012-07-08 23:28:41 +00:00
align = ( int ) parms . membase & 15 ;
if ( align )
{
align = 16 - align ;
parms . membase + = align ;
parms . memsize - = align ;
}
2012-07-15 03:34:57 +00:00
args [ 2 ] = basepack ;
2012-04-09 19:12:12 +00:00
Sys_Printf ( " Starting up (apk=%s, usr=%s) \n " , args [ 2 ] , parms . basedir ) ;
2012-01-17 07:57:46 +00:00
COM_InitArgv ( parms . argc , parms . argv ) ;
TL_InitLanguages ( ) ;
# ifdef SERVERONLY
SV_Init ( & parms ) ;
# else
Host_Init ( & parms ) ;
# endif
sys_running = true ;
sys_lastframe = Sys_Milliseconds ( ) ;
2012-11-27 03:23:19 +00:00
sys_orientation . modified = true ;
2012-01-17 07:57:46 +00:00
}
}
static int secbase ;
2012-07-15 03:34:57 +00:00
# ifdef _POSIX_TIMERS
double Sys_DoubleTime ( void )
{
struct timespec ts ;
clock_gettime ( CLOCK_MONOTONIC , & ts ) ;
if ( ! secbase )
{
secbase = ts . tv_sec ;
return ts . tv_nsec / 1000000000.0 ;
}
return ( ts . tv_sec - secbase ) + ts . tv_nsec / 1000000000.0 ;
}
unsigned int Sys_Milliseconds ( void )
{
struct timespec ts ;
clock_gettime ( CLOCK_MONOTONIC , & ts ) ;
if ( ! secbase )
{
secbase = ts . tv_sec ;
return ts . tv_nsec / 1000000 ;
}
return ( ts . tv_sec - secbase ) * 1000 + ts . tv_nsec / 1000000 ;
}
# else
2012-01-17 07:57:46 +00:00
double Sys_DoubleTime ( void )
{
2012-07-15 03:34:57 +00:00
struct timeval tp ;
struct timezone tzp ;
2012-01-17 07:57:46 +00:00
2012-07-15 03:34:57 +00:00
gettimeofday ( & tp , & tzp ) ;
2012-01-17 07:57:46 +00:00
2012-07-15 03:34:57 +00:00
if ( ! secbase )
{
secbase = tp . tv_sec ;
return tp . tv_usec / 1000000.0 ;
}
2012-01-17 07:57:46 +00:00
2012-07-15 03:34:57 +00:00
return ( tp . tv_sec - secbase ) + tp . tv_usec / 1000000.0 ;
2012-01-17 07:57:46 +00:00
}
unsigned int Sys_Milliseconds ( void )
{
2012-07-15 03:34:57 +00:00
struct timeval tp ;
struct timezone tzp ;
2012-01-17 07:57:46 +00:00
2012-07-15 03:34:57 +00:00
gettimeofday ( & tp , & tzp ) ;
2012-01-17 07:57:46 +00:00
2012-07-15 03:34:57 +00:00
if ( ! secbase )
{
secbase = tp . tv_sec ;
return tp . tv_usec / 1000 ;
}
2012-01-17 07:57:46 +00:00
2012-07-15 03:34:57 +00:00
return ( tp . tv_sec - secbase ) * 1000 + tp . tv_usec / 1000 ;
2012-01-17 07:57:46 +00:00
}
2012-07-15 03:34:57 +00:00
# endif
2012-01-17 07:57:46 +00:00
void Sys_Shutdown ( void )
{
free ( sys_memheap ) ;
}
void Sys_Quit ( void )
{
# ifndef SERVERONLY
Host_Shutdown ( ) ;
# else
SV_Shutdown ( ) ;
# endif
2012-09-30 05:52:03 +00:00
LOGI ( " %s " , " quitting " ) ;
longjmp ( host_abort , 1 ) ;
exit ( 0 ) ;
2012-01-17 07:57:46 +00:00
}
void Sys_Error ( const char * error , . . . )
{
va_list argptr ;
char string [ 1024 ] ;
va_start ( argptr , error ) ;
vsnprintf ( string , sizeof ( string ) - 1 , error , argptr ) ;
va_end ( argptr ) ;
2012-09-30 05:52:03 +00:00
if ( ! * string )
strcpy ( string , " no error " ) ;
2012-01-17 07:57:46 +00:00
2012-09-30 05:52:03 +00:00
Q_strncpyz ( errormessage , string , sizeof ( errormessage ) ) ;
LOGE ( " %s " , string ) ;
2012-01-17 07:57:46 +00:00
2012-09-30 05:52:03 +00:00
longjmp ( host_abort , 1 ) ;
2012-01-17 07:57:46 +00:00
exit ( 1 ) ;
}
void Sys_Printf ( char * fmt , . . . )
{
va_list argptr ;
char string [ 1024 ] ;
va_start ( argptr , fmt ) ;
vsnprintf ( string , sizeof ( string ) - 1 , fmt , argptr ) ;
va_end ( argptr ) ;
LOGI ( " %s " , string ) ;
}
void Sys_Warn ( char * fmt , . . . )
{
va_list argptr ;
char string [ 1024 ] ;
va_start ( argptr , fmt ) ;
vsnprintf ( string , sizeof ( string ) - 1 , fmt , argptr ) ;
va_end ( argptr ) ;
LOGW ( " %s " , string ) ;
}
void Sys_CloseLibrary ( dllhandle_t * lib )
{
dlclose ( lib ) ;
}
dllhandle_t * Sys_LoadLibrary ( const char * name , dllfunction_t * funcs )
{
dllhandle_t * h ;
h = dlopen ( name , RTLD_LAZY ) ;
return h ;
}
void * Sys_GetAddressForName ( dllhandle_t * module , const char * exportname )
{
return dlsym ( module , exportname ) ;
}
void * Sys_GetGameAPI ( void * parms )
{
2012-02-27 12:23:15 +00:00
//don't implement - fix q2 code instead
2012-01-17 07:57:46 +00:00
return NULL ;
}
void Sys_UnloadGame ( void )
{
}
char * Sys_ConsoleInput ( void )
{
return NULL ;
}
void Sys_mkdir ( char * path ) //not all pre-unix systems have directories (including dos 1)
{
mkdir ( path , 0777 ) ;
}
qboolean Sys_remove ( char * path )
{
return ! unlink ( path ) ;
}
2012-04-24 07:59:11 +00:00
qboolean Sys_Rename ( char * oldfname , char * newfname )
{
return ! rename ( oldfname , newfname ) ;
}
2012-02-27 12:23:15 +00:00
void Sys_SendKeyEvents ( void )
{
}
2012-01-17 07:57:46 +00:00
void Sys_Init ( void )
{
Android: fat presses, vibrator, onscreen keyboard, keep-screen-on, console scaling, touch-based console scrolling, additional bindables.
Some memory leaks fixed.
latency with the nq protocol over loopback is much reduced.
Terrain: now mostly a property of a (q1 for now) bsp map, file format changed, glsl now built in, terrain editor builtin improved/changed, holes supported.
git-svn-id: https://svn.code.sf.net/p/fteqw/code/trunk@4067 fc73d0e0-1445-4013-8a0c-d673dee63da5
2012-07-14 16:25:18 +00:00
Cvar_Register ( & sys_vibrate , " android stuff " ) ;
Cvar_Register ( & sys_osk , " android stuff " ) ;
Cvar_Register ( & sys_keepscreenon , " android stuff " ) ;
2012-09-30 05:52:03 +00:00
Cvar_Register ( & sys_orientation , " android stuff " ) ;
2012-11-27 03:23:19 +00:00
Cvar_Register ( & sys_glesversion_cvar , " android stuff " ) ;
2012-01-17 07:57:46 +00:00
}
qboolean Sys_GetDesktopParameters ( int * width , int * height , int * bpp , int * refreshrate )
{
* width = 320 ;
* height = 240 ;
* bpp = 16 ;
* refreshrate = 60 ;
return false ;
}
qboolean Sys_RandomBytes ( qbyte * string , int len )
{
qboolean res = false ;
int fd = open ( " /dev/urandom " , 0 ) ;
if ( fd > = 0 )
{
res = ( read ( fd , string , len ) = = len ) ;
close ( fd ) ;
}
return res ;
}
void Sys_ServerActivity ( void )
{
/*FIXME: flash window*/
}
qboolean Sys_InitTerminal ( void )
{
/*switching to dedicated mode, show text window*/
return false ;
}
void Sys_CloseTerminal ( void )
{
}
char * Sys_GetClipboard ( void )
{
return NULL ;
}
void Sys_CloseClipboard ( char * buf )
{
}
void Sys_SaveClipboard ( char * text )
{
}
2013-03-31 04:21:08 +00:00
int Sys_EnumerateFiles ( const char * gpath , const char * match , int ( * func ) ( const char * , int , void * , void * ) , void * parm , void * spath )
2012-01-17 07:57:46 +00:00
{
2013-03-31 04:21:08 +00:00
DIR * dir ;
char apath [ MAX_OSPATH ] ;
char file [ MAX_OSPATH ] ;
char truepath [ MAX_OSPATH ] ;
char * s ;
struct dirent * ent ;
struct stat st ;
//printf("path = %s\n", gpath);
//printf("match = %s\n", match);
if ( ! gpath )
gpath = " " ;
* apath = ' \0 ' ;
Q_strncpyz ( apath , match , sizeof ( apath ) ) ;
for ( s = apath + strlen ( apath ) - 1 ; s > = apath ; s - - )
{
if ( * s = = ' / ' )
{
s [ 1 ] = ' \0 ' ;
match + = s - apath + 1 ;
break ;
}
}
if ( s < apath ) //didn't find a '/'
* apath = ' \0 ' ;
Q_snprintfz ( truepath , sizeof ( truepath ) , " %s/%s " , gpath , apath ) ;
//printf("truepath = %s\n", truepath);
//printf("gamepath = %s\n", gpath);
//printf("apppath = %s\n", apath);
//printf("match = %s\n", match);
dir = opendir ( truepath ) ;
if ( ! dir )
{
Con_DPrintf ( " Failed to open dir %s \n " , truepath ) ;
return true ;
}
do
{
ent = readdir ( dir ) ;
if ( ! ent )
break ;
if ( * ent - > d_name ! = ' . ' )
{
if ( wildcmp ( match , ent - > d_name ) )
{
Q_snprintfz ( file , sizeof ( file ) , " %s/%s " , truepath , ent - > d_name ) ;
if ( stat ( file , & st ) = = 0 )
{
Q_snprintfz ( file , sizeof ( file ) , " %s%s%s " , apath , ent - > d_name , S_ISDIR ( st . st_mode ) ? " / " : " " ) ;
if ( ! func ( file , st . st_size , parm , spath ) )
{
closedir ( dir ) ;
return false ;
}
}
else
printf ( " Stat failed for \" %s \" \n " , file ) ;
}
}
} while ( 1 ) ;
closedir ( dir ) ;
return true ;
2012-01-17 07:57:46 +00:00
}
2012-01-28 10:30:44 +00:00
#if 0
# include <android/asset_manager.h>
2012-01-17 07:57:46 +00:00
int Sys_EnumerateFiles ( const char * gpath , const char * match , int ( * func ) ( const char * , int , void * ) , void * parm )
{
qboolean go = true ;
const char * f ;
struct AAssetDir * ad ;
ad = AAssetManager_openDir ( assetmgr , gpath ) ;
while ( go & & ( f = AAssetDir_getNextFileName ( ad ) ) )
{
if ( wildcmp ( match , f ) )
{
Sys_Printf ( " Found %s \n " , f ) ;
go = func ( f , 0 , parm ) ;
}
}
AAssetDir_close ( ad ) ;
return 0 ;
}
2012-01-28 10:30:44 +00:00
2012-01-17 07:57:46 +00:00
typedef struct
{
vfsfile_t funcs ;
AAsset * handle ;
} assetfile_t ;
static int AF_ReadBytes ( vfsfile_t * h , void * buf , int len )
{
assetfile_t * f = ( assetfile_t * ) h ;
return AAsset_read ( f - > handle , buf , len ) ;
}
static qboolean AF_Seek ( vfsfile_t * h , unsigned long offs )
{
assetfile_t * f = ( assetfile_t * ) h ;
AAsset_seek ( f - > handle , offs , SEEK_SET ) ;
return true ;
}
static unsigned long AF_Tell ( vfsfile_t * h )
{
assetfile_t * f = ( assetfile_t * ) h ;
return AAsset_seek ( f - > handle , 0 , SEEK_CUR ) ;
}
static unsigned long AF_GetSize ( vfsfile_t * h )
{
assetfile_t * f = ( assetfile_t * ) h ;
return AAsset_getLength ( f - > handle ) ;
}
static void AF_Close ( vfsfile_t * h )
{
assetfile_t * f = ( assetfile_t * ) h ;
AAsset_close ( f - > handle ) ;
Z_Free ( f ) ;
}
static void AF_Flush ( vfsfile_t * h )
{
}
vfsfile_t * Sys_OpenAsset ( char * fname )
{
assetfile_t * file ;
AAsset * a ;
a = AAssetManager_open ( assetmgr , fname , AASSET_MODE_UNKNOWN ) ;
if ( ! a )
{
Sys_Printf ( " Unable to open asset %s \n " , fname ) ;
return NULL ;
}
Sys_Printf ( " opened asset %s \n " , fname ) ;
file = Z_Malloc ( sizeof ( assetfile_t ) ) ;
file - > funcs . ReadBytes = AF_ReadBytes ;
file - > funcs . WriteBytes = NULL ;
file - > funcs . Seek = AF_Seek ;
file - > funcs . Tell = AF_Tell ;
file - > funcs . GetLen = AF_GetSize ;
file - > funcs . Close = AF_Close ;
file - > funcs . Flush = AF_Flush ;
file - > handle = a ;
return ( vfsfile_t * ) file ;
}
2012-01-28 10:30:44 +00:00
# endif