mirror of
https://github.com/YGGverse/xash3d-fwgs.git
synced 2025-01-30 16:54:29 +00:00
engine: platform: android: merge new SDL2 based Android port from @Velaron's tree
This commit is contained in:
parent
febdfacbd3
commit
d2237fa144
157
engine/platform/android/android.c
Normal file
157
engine/platform/android/android.c
Normal file
@ -0,0 +1,157 @@
|
|||||||
|
/*
|
||||||
|
android_nosdl.c - android backend
|
||||||
|
Copyright (C) 2016-2019 mittorn
|
||||||
|
|
||||||
|
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 3 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.
|
||||||
|
*/
|
||||||
|
#include "platform/platform.h"
|
||||||
|
|
||||||
|
#if !defined(XASH_DEDICATED)
|
||||||
|
|
||||||
|
#include "input.h"
|
||||||
|
#include "client.h"
|
||||||
|
#include "sound.h"
|
||||||
|
#include "errno.h"
|
||||||
|
#include <pthread.h>
|
||||||
|
#include <sys/prctl.h>
|
||||||
|
|
||||||
|
#include <android/log.h>
|
||||||
|
#include <jni.h>
|
||||||
|
#include <SDL.h>
|
||||||
|
|
||||||
|
struct jnimethods_s
|
||||||
|
{
|
||||||
|
JNIEnv *env;
|
||||||
|
jobject activity;
|
||||||
|
jclass actcls;
|
||||||
|
jmethodID getID;
|
||||||
|
jmethodID saveID;
|
||||||
|
jmethodID loadID;
|
||||||
|
jmethodID getKeyboardHeight;
|
||||||
|
} jni;
|
||||||
|
|
||||||
|
void Android_Init( void )
|
||||||
|
{
|
||||||
|
jni.env = (JNIEnv *)SDL_AndroidGetJNIEnv();
|
||||||
|
jni.activity = (jobject)SDL_AndroidGetActivity();
|
||||||
|
jni.actcls = (*jni.env)->GetObjectClass( jni.env, jni.activity );
|
||||||
|
jni.loadID = (*jni.env)->GetMethodID( jni.env, jni.actcls, "loadAndroidID", "()Ljava/lang/String;" );
|
||||||
|
jni.getID = (*jni.env)->GetMethodID( jni.env, jni.actcls, "getAndroidID", "()Ljava/lang/String;" );
|
||||||
|
jni.saveID = (*jni.env)->GetMethodID( jni.env, jni.actcls, "saveAndroidID", "(Ljava/lang/String;)V" );
|
||||||
|
jni.getKeyboardHeight = (*jni.env)->GetMethodID( jni.env, jni.actcls, "getKeyboardHeight", "()I" );
|
||||||
|
|
||||||
|
SDL_SetHint( SDL_HINT_ORIENTATIONS, "LandscapeLeft LandscapeRight" );
|
||||||
|
SDL_SetHint( SDL_HINT_JOYSTICK_HIDAPI_STEAM, "1" );
|
||||||
|
SDL_SetHint( SDL_HINT_ANDROID_BLOCK_ON_PAUSE, "0" );
|
||||||
|
SDL_SetHint( SDL_HINT_ANDROID_BLOCK_ON_PAUSE_PAUSEAUDIO, "0" );
|
||||||
|
SDL_SetHint( SDL_HINT_ANDROID_TRAP_BACK_BUTTON, "1" );
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
========================
|
||||||
|
Android_GetNativeObject
|
||||||
|
========================
|
||||||
|
*/
|
||||||
|
|
||||||
|
void *Android_GetNativeObject( const char *name )
|
||||||
|
{
|
||||||
|
static const char *availObjects[] = { "JNIEnv", "ActivityClass", NULL };
|
||||||
|
void *object = NULL;
|
||||||
|
|
||||||
|
if( !name )
|
||||||
|
{
|
||||||
|
object = (void *)availObjects;
|
||||||
|
}
|
||||||
|
else if( !strcasecmp( name, "JNIEnv" ) )
|
||||||
|
{
|
||||||
|
object = (void *)jni.env;
|
||||||
|
}
|
||||||
|
else if( !strcasecmp( name, "ActivityClass" ) )
|
||||||
|
{
|
||||||
|
object = (void *)jni.actcls;
|
||||||
|
}
|
||||||
|
|
||||||
|
return object;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
========================
|
||||||
|
Android_GetAndroidID
|
||||||
|
========================
|
||||||
|
*/
|
||||||
|
const char *Android_GetAndroidID( void )
|
||||||
|
{
|
||||||
|
static char id[32];
|
||||||
|
jstring resultJNIStr;
|
||||||
|
const char *resultCStr;
|
||||||
|
|
||||||
|
if( COM_CheckString( id ) ) return id;
|
||||||
|
|
||||||
|
resultJNIStr = (*jni.env)->CallObjectMethod( jni.env, jni.activity, jni.getID );
|
||||||
|
resultCStr = (*jni.env)->GetStringUTFChars( jni.env, resultJNIStr, NULL );
|
||||||
|
Q_strncpy( id, resultCStr, sizeof( id ) );
|
||||||
|
(*jni.env)->ReleaseStringUTFChars( jni.env, resultJNIStr, resultCStr );
|
||||||
|
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
========================
|
||||||
|
Android_LoadID
|
||||||
|
========================
|
||||||
|
*/
|
||||||
|
const char *Android_LoadID( void )
|
||||||
|
{
|
||||||
|
static char id[32];
|
||||||
|
jstring resultJNIStr;
|
||||||
|
const char *resultCStr;
|
||||||
|
|
||||||
|
resultJNIStr = (*jni.env)->CallObjectMethod( jni.env, jni.activity, jni.loadID );
|
||||||
|
resultCStr = (*jni.env)->GetStringUTFChars( jni.env, resultJNIStr, NULL );
|
||||||
|
Q_strncpy( id, resultCStr, sizeof( id ) );
|
||||||
|
(*jni.env)->ReleaseStringUTFChars( jni.env, resultJNIStr, resultCStr );
|
||||||
|
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
========================
|
||||||
|
Android_SaveID
|
||||||
|
========================
|
||||||
|
*/
|
||||||
|
void Android_SaveID( const char *id )
|
||||||
|
{
|
||||||
|
(*jni.env)->CallVoidMethod( jni.env, jni.activity, jni.saveID, (*jni.env)->NewStringUTF( jni.env, id ) );
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
========================
|
||||||
|
Android_ShellExecute
|
||||||
|
========================
|
||||||
|
*/
|
||||||
|
void Platform_ShellExecute( const char *path, const char *parms )
|
||||||
|
{
|
||||||
|
#if SDL_VERSION_ATLEAST( 2, 0, 14 )
|
||||||
|
SDL_OpenURL( path );
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
========================
|
||||||
|
Android_GetKeyboardHeight
|
||||||
|
========================
|
||||||
|
*/
|
||||||
|
int Android_GetKeyboardHeight( void )
|
||||||
|
{
|
||||||
|
return (*jni.env)->CallIntMethod( jni.env, jni.activity, jni.getKeyboardHeight );
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif // XASH_DEDICATED
|
@ -43,7 +43,7 @@ void *ANDROID_LoadLibrary( const char *dllname )
|
|||||||
}
|
}
|
||||||
|
|
||||||
// HACKHACK: keep old behaviour for compability
|
// HACKHACK: keep old behaviour for compability
|
||||||
if( Q_strstr( dllname, "." OS_LIB_EXT ) || Q_strstr( dllname, PATH_SPLITTER ))
|
if( Q_strstr( dllname, "." OS_LIB_EXT ) || Q_strstr( dllname, "/" ))
|
||||||
{
|
{
|
||||||
pHandle = dlopen( dllname, RTLD_LAZY );
|
pHandle = dlopen( dllname, RTLD_LAZY );
|
||||||
if( pHandle )
|
if( pHandle )
|
||||||
|
@ -140,10 +140,10 @@ struct soinfo {
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(USE_RELA)
|
#if defined(USE_RELA)
|
||||||
Elf_Rela* plt_rela;
|
Elf_RelA* plt_rela;
|
||||||
size_t plt_rela_count;
|
size_t plt_rela_count;
|
||||||
|
|
||||||
Elf_Rela* rela;
|
Elf_RelA* rela;
|
||||||
size_t rela_count;
|
size_t rela_count;
|
||||||
#else
|
#else
|
||||||
Elf_Rel* plt_rel;
|
Elf_Rel* plt_rel;
|
||||||
|
@ -43,6 +43,9 @@ qboolean Sys_DebuggerPresent( void ); // optional, see Sys_DebugBreak
|
|||||||
const char *Android_GetAndroidID( void );
|
const char *Android_GetAndroidID( void );
|
||||||
const char *Android_LoadID( void );
|
const char *Android_LoadID( void );
|
||||||
void Android_SaveID( const char *id );
|
void Android_SaveID( const char *id );
|
||||||
|
void Android_Init( void );
|
||||||
|
void *Android_GetNativeObject( const char *name );
|
||||||
|
int Android_GetKeyboardHeight( void );
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if XASH_WIN32
|
#if XASH_WIN32
|
||||||
|
Loading…
x
Reference in New Issue
Block a user