From b028a18d16035081a093ebe00f65ee476832f395 Mon Sep 17 00:00:00 2001 From: "Alibek Omarov (a1batross)" Date: Sat, 4 Mar 2017 17:13:21 +0300 Subject: [PATCH] Remove jnisetenv library, restore old engine initialization. New library: gpgs_support, which initialized Google Play Games in Google Play builds. (In opensource builds does nothing) --- jni/Application.mk | 13 ++++-- jni/src/gpgs_support/Android.mk | 17 +++++++ jni/src/gpgs_support/gpgs_support.cpp | 65 ++++++++++++++++++++++++++ jni/src/jnisetenv/Android.mk | 13 ------ jni/src/jnisetenv/setenv.c | 27 ----------- src/in/celest/xash3d/XashActivity.java | 38 +++++++-------- 6 files changed, 108 insertions(+), 65 deletions(-) create mode 100644 jni/src/gpgs_support/Android.mk create mode 100644 jni/src/gpgs_support/gpgs_support.cpp delete mode 100644 jni/src/jnisetenv/Android.mk delete mode 100644 jni/src/jnisetenv/setenv.c diff --git a/jni/Application.mk b/jni/Application.mk index 2ed814f6..7138c14c 100644 --- a/jni/Application.mk +++ b/jni/Application.mk @@ -10,6 +10,8 @@ else APP_PLATFORM := android-9 endif +APP_STL := gnustl_static + # if non-zero, works only if single ABI selected XASH_THREAD_NUM ?= 0 @@ -37,7 +39,12 @@ APP_ABI := x86 armeabi armeabi-v7a-hard # ARMv6 and ARMv5 xash3d builds use softfp only and compatible only with softfp mods # Build both armeabi-v7a-hard and armeabi-v7a supported only for mods, not for engine -APP_MODULES := xash menu client server NanoGL jnisetenv -ifeq ($(XASH_SDL),1) -APP_MODULES += SDL2 +APP_MODULES := xash menu client server NanoGL gpgs_support +ifeq ($(GOOGLE_PLAY_BUILD),1) + APP_MODULES += libgpg-1 + CFLAGS_OPT += -DGOOGLE_PLAY_BUILD +endif + +ifeq ($(XASH_SDL),1) + APP_MODULES += SDL2 endif diff --git a/jni/src/gpgs_support/Android.mk b/jni/src/gpgs_support/Android.mk new file mode 100644 index 00000000..82c093c1 --- /dev/null +++ b/jni/src/gpgs_support/Android.mk @@ -0,0 +1,17 @@ +LOCAL_PATH := $(call my-dir) + +include $(CLEAR_VARS) + +LOCAL_MODULE := gpgs_support + +APP_PLATFORM := android-12 + +include $(XASH3D_CONFIG) + +LOCAL_CPPFLAGS += -std=c++11 + +LOCAL_SRC_FILES := gpgs_support.cpp +LOCAL_STATIC_LIBRARIES := libgpg-1 +LOCAL_LDLIBS := -llog + +include $(BUILD_SHARED_LIBRARY) diff --git a/jni/src/gpgs_support/gpgs_support.cpp b/jni/src/gpgs_support/gpgs_support.cpp new file mode 100644 index 00000000..03d04896 --- /dev/null +++ b/jni/src/gpgs_support/gpgs_support.cpp @@ -0,0 +1,65 @@ +/* +gpgs_support.cpp -- a Google Play Games support library +Copyright (C) 2016 a1batross +*/ + +#include +#include + +#if defined(GOOGLE_PLAY_BUILD) +#include +#include +using gpg::GameServices; +#else +typedef void *GameServices; +#endif + +GameServices *services = NULL; + +extern "C" +{ +// After construction of GameServices, pass pointer to this function +// GameServices is recommended to be created in client.dll +void SetGameServicesPtr( GameServices *ptr ); + +// Share a pointer to external code, like server library or menu. +GameServices *GetGameServicesPtr( void ); +} + +void SetGameServicesPtr( GameServices *ptr ) +{ +#ifdef GOOGLE_PLAY_BUILD + static bool once; + + if( once ) + { + __android_log_print( ANDROID_LOG_ERROR, "GPGSSupport", "To prevent overwriting of GameServices pointer, setting pointer twice is prohibited" ); + return; + } + + services = ptr; + once = true; +#else + __android_log_print( ANDROID_LOG_WARN, "GPGSSupport", "Not a Google Play build of engine!" ); +#endif +} + +gpg::GameServices *GetGameServicesPtr( void ) +{ +#ifdef GOOGLE_PLAY_BUILD + return services; +#else + return NULL; +#endif +} + +extern "C" __attribute__((visibility("default"))) jint JNI_OnLoad( JavaVM *vm, void *reserved ) +{ +#ifdef GOOGLE_PLAY_BUILD + gpg::AndroidInitialization::JNI_OnLoad( vm ); + + __android_log_print( ANDROID_LOG_VERBOSE, "GPGSSupport", "%s", __PRETTY_FUNCTION__ ); +#endif + + return JNI_VERSION_1_6; +} diff --git a/jni/src/jnisetenv/Android.mk b/jni/src/jnisetenv/Android.mk deleted file mode 100644 index 78628f38..00000000 --- a/jni/src/jnisetenv/Android.mk +++ /dev/null @@ -1,13 +0,0 @@ -LOCAL_PATH := $(call my-dir) - -include $(CLEAR_VARS) - -LOCAL_MODULE := jnisetenv - -APP_PLATFORM := android-12 - -include $(XASH3D_CONFIG) - -LOCAL_SRC_FILES := setenv.c - -include $(BUILD_SHARED_LIBRARY) diff --git a/jni/src/jnisetenv/setenv.c b/jni/src/jnisetenv/setenv.c deleted file mode 100644 index d3a0d177..00000000 --- a/jni/src/jnisetenv/setenv.c +++ /dev/null @@ -1,27 +0,0 @@ -/* -setenv.c -- a jni wrapper for setenv() call for XashActivity -Copyright (C) 2016 a1batross - -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 -#include - -JNIEXPORT int JNICALL Java_in_celest_xash3d_XashActivity_setenv( JNIEnv* env, jclass clazz, jstring key, jstring value, jboolean overwrite ) -{ - char* k = (char *) (*env)->GetStringUTFChars(env, key, NULL); - char* v = (char *) (*env)->GetStringUTFChars(env, value, NULL); - int err = setenv(k, v, overwrite); - (*env)->ReleaseStringUTFChars(env, key, k); - (*env)->ReleaseStringUTFChars(env, value, v); - return err; -} diff --git a/src/in/celest/xash3d/XashActivity.java b/src/in/celest/xash3d/XashActivity.java index 19135cdc..74f59c56 100644 --- a/src/in/celest/xash3d/XashActivity.java +++ b/src/in/celest/xash3d/XashActivity.java @@ -38,12 +38,12 @@ public class XashActivity extends Activity { // Main components protected static XashActivity mSingleton; protected static View mTextEdit; + protected static ViewGroup mLayout; public static EngineSurface mSurface; public static String mArgv[]; public static final int sdk = Integer.valueOf(Build.VERSION.SDK); public static final String TAG = "XASH3D:XashActivity"; public static int mPixelFormat; - protected static ViewGroup mLayout; public static JoystickHandler handler; public static ImmersiveMode mImmersiveMode; public static boolean keyboardVisible = false; @@ -69,10 +69,6 @@ public class XashActivity extends Activity { public static SharedPreferences mPref = null; private static boolean mUseVolume; public static View mDecorView; - - // Audio - private static Thread mAudioThread; - private static AudioTrack mAudioTrack; // Certificate checking private static String SIG = "DMsE8f5hlR7211D8uehbFpbA0n8="; @@ -80,7 +76,8 @@ public class XashActivity extends Activity { // Load the .so static { - System.loadLibrary("jnisetenv"); + System.loadLibrary("gpgs_support"); + System.loadLibrary("xash"); } // Shared between this activity and LauncherActivity @@ -154,12 +151,8 @@ public class XashActivity extends Activity { setupEnvironment(); - // HACKHACK: Call it here, so JNI_OnLoad will have proper envvars - // Don't call ANYTHING native before onCreate finish, otherwise you will get a link exception! - System.loadLibrary("xash"); - InstallReceiver.extractPAK(this, false); - + // Set up the surface mSurface = new EngineSurface(getApplication()); @@ -190,6 +183,14 @@ public class XashActivity extends Activity { mHasVibrator = ( mVibrator != null ) && ( mVibrator.hasVibrator() ); } + private String getStringExtraFromIntent( Intent intent, String extraString, String ifNotFound ) + { + String ret = intent.getStringExtra(extraString); + if( ret == null ) ret = ifNotFound; + + return ret; + } + private void setupEnvironment() { Intent intent = getIntent(); @@ -198,20 +199,13 @@ public class XashActivity extends Activity { // setup envs mPref = this.getSharedPreferences("engine", 0); - String argv = intent.getStringExtra("argv"); - if(argv == null) argv = mPref.getString("argv", "-dev 3 -log"); + String argv = getStringExtraFromIntent(intent, "argv", mPref.getString("argv", "-dev 3 -log")); + String gamelibdir = getStringExtraFromIntent(intent, "gamelibdir", enginedir); + String gamedir = getStringExtraFromIntent(intent, "gamedir", "valve"); + String basedir = getStringExtraFromIntent(intent, "basedir", mPref.getString("basedir","/sdcard/xash/")); mArgv = argv.split(" "); - String gamelibdir = intent.getStringExtra("gamelibdir"); - if(gamelibdir == null) gamelibdir = enginedir; - - String gamedir = intent.getStringExtra("gamedir"); - if(gamedir == null) gamedir = "valve"; - - String basedir = intent.getStringExtra("basedir"); - if(basedir == null) basedir = mPref.getString("basedir","/sdcard/xash/"); - setenv("XASH3D_BASEDIR", basedir, true); setenv("XASH3D_ENGLIBDIR", enginedir, true); setenv("XASH3D_GAMELIBDIR", gamelibdir, true);