Skip to content

Commit

Permalink
filesystem: don't check for SDL whether we can load Android assets, b…
Browse files Browse the repository at this point in the history
…ecause filesystem doesn't know anything about SDL

Replace it with runtime check instead.
  • Loading branch information
a1batross committed Mar 11, 2024
1 parent 599a1f0 commit e039ef3
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 11 deletions.
4 changes: 0 additions & 4 deletions common/defaults.h
Original file line number Diff line number Diff line change
Expand Up @@ -164,10 +164,6 @@ Default build-depended cvar and constant values
#define XASH_INTERNAL_GAMELIBS
#endif // XASH_ANDROID || XASH_IOS || XASH_EMSCRIPTEN

#if XASH_ANDROID && XASH_SDL
#define XASH_ANDROID_ASSETS 1
#endif

// Defaults
#ifndef DEFAULT_TOUCH_ENABLE
#define DEFAULT_TOUCH_ENABLE "0"
Expand Down
13 changes: 9 additions & 4 deletions filesystem/android.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,8 @@ GNU General Public License for more details.
*/

#include "port.h"
#include "defaults.h"

#if XASH_ANDROID_ASSETS
#if XASH_ANDROID

#include <sys/types.h>
#include <sys/stat.h>
Expand Down Expand Up @@ -277,6 +276,9 @@ searchpath_t *FS_AddAndroidAssets_Fullpath( const char *path, int flags )
android_assets_t *assets = NULL;
qboolean engine = true;

if( !jni.getPackageName || !jni.getCallingPackage || !jni.getAssetsList || !jni.getAssets )
return NULL;

if( FBitSet( flags, FS_STATIC_PATH | FS_CUSTOM_PATH ))
return NULL;

Expand All @@ -287,7 +289,7 @@ searchpath_t *FS_AddAndroidAssets_Fullpath( const char *path, int flags )

if( !assets )
{
Con_Reportf( S_ERROR "%s: unable to load Android assets \"%s\"\n", __FUNCTION__, Android_GetPackageName( engine ));
Con_Reportf( S_ERROR "%s: unable to load Android assets \"%s\"\n", __func__, Android_GetPackageName( engine ));
return NULL;
}

Expand Down Expand Up @@ -327,6 +329,9 @@ void FS_InitAndroid( void )
jni.getCallingPackage = (*jni.env)->GetMethodID( jni.env, jni.activity_class, "getCallingPackage", "()Ljava/lang/String;" );
jni.getAssetsList = (*jni.env)->GetMethodID( jni.env, jni.activity_class, "getAssetsList", "(ZLjava/lang/String;)[Ljava/lang/String;" );
jni.getAssets = (*jni.env)->GetMethodID( jni.env, jni.activity_class, "getAssets", "(Z)Landroid/content/res/AssetManager;" );

if( !jni.getPackageName || !jni.getCallingPackage || !jni.getAssetsList || !jni.getAssets )
Con_Reportf( S_WARN "%s: unable to find required JNI interface to load Android assets\n", __func__ );
}

#endif // XASH_ANDROID_ASSETS
#endif // XASH_ANDROID
6 changes: 3 additions & 3 deletions filesystem/filesystem.c
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ const fs_archive_t g_archives[] =
static const fs_archive_t g_directory_archive =
{ NULL, SEARCHPATH_PLAIN, FS_AddDir_Fullpath, false };

#if XASH_ANDROID_ASSETS
#if XASH_ANDROID
static const fs_archive_t g_android_archive =
{ NULL, SEARCHPATH_ANDROID_ASSETS, FS_AddAndroidAssets_Fullpath, false };
#endif
Expand Down Expand Up @@ -406,7 +406,7 @@ void FS_AddGameDirectory( const char *dir, uint flags )

stringlistfreecontents( &list );

#if XASH_ANDROID_ASSETS
#if XASH_ANDROID
FS_AddArchive_Fullpath( &g_android_archive, dir, flags );
#endif

Expand Down Expand Up @@ -1461,7 +1461,7 @@ qboolean FS_InitStdio( qboolean unused_set_to_true, const char *rootdir, const c

FS_InitMemory();

#if XASH_ANDROID_ASSETS
#if XASH_ANDROID
FS_InitAndroid();
#endif

Expand Down

0 comments on commit e039ef3

Please sign in to comment.