2
0
mirror of https://github.com/FWGS/xash3d-fwgs synced 2024-11-29 05:20:23 +01:00

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)

This commit is contained in:
Alibek Omarov (a1batross) 2017-03-04 17:13:21 +03:00
parent e2faa06de2
commit b028a18d16
6 changed files with 108 additions and 65 deletions

View File

@ -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

View File

@ -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)

View File

@ -0,0 +1,65 @@
/*
gpgs_support.cpp -- a Google Play Games support library
Copyright (C) 2016 a1batross
*/
#include <jni.h>
#include <android/log.h>
#if defined(GOOGLE_PLAY_BUILD)
#include <gpg/game_services.h>
#include <gpg/android_initialization.h>
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;
}

View File

@ -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)

View File

@ -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 <jni.h>
#include <stdlib.h>
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;
}

View File

@ -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);