1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-09-16 09:26:28 +02:00

use JNIEnv object from SDL instead of forwarding from Java for Client

This commit is contained in:
Andrey Filipenkov
2023-02-25 10:34:37 +03:00
parent 2a28109f2d
commit 5b1f3bf0db
6 changed files with 10 additions and 13 deletions

View File

@@ -30,8 +30,6 @@ public class NativeMethods
public static native void initClassloader(); public static native void initClassloader();
public static native void clientSetupJNI();
public static native void createServer(); public static native void createServer();
public static native void notifyServerReady(); public static native void notifyServerReady();

View File

@@ -54,8 +54,6 @@ public final class LibsLoader
loadCommon(); loadCommon();
loadLib("vcmiclient", false); loadLib("vcmiclient", false);
SDL.setContext(ctx); SDL.setContext(ctx);
NativeMethods.clientSetupJNI();
NativeMethods.initClassloader();
} }
public static void loadServerLibs() public static void loadServerLibs()

View File

@@ -156,6 +156,7 @@ int main(int argc, char * argv[])
#endif #endif
{ {
#ifdef VCMI_ANDROID #ifdef VCMI_ANDROID
CAndroidVMHelper::initClassloader(SDL_AndroidGetJNIEnv());
// boost will crash without this // boost will crash without this
setenv("LANG", "C", 1); setenv("LANG", "C", 1);
#endif #endif

View File

@@ -778,13 +778,6 @@ void CClient::removeGUI()
} }
#ifdef VCMI_ANDROID #ifdef VCMI_ANDROID
extern "C" JNIEXPORT void JNICALL Java_eu_vcmi_vcmi_NativeMethods_clientSetupJNI(JNIEnv * env, jclass cls)
{
logNetwork->info("Received clientSetupJNI");
CAndroidVMHelper::cacheVM(env);
}
extern "C" JNIEXPORT void JNICALL Java_eu_vcmi_vcmi_NativeMethods_notifyServerClosed(JNIEnv * env, jclass cls) extern "C" JNIEXPORT void JNICALL Java_eu_vcmi_vcmi_NativeMethods_notifyServerClosed(JNIEnv * env, jclass cls)
{ {
logNetwork->info("Received server closed signal"); logNetwork->info("Received server closed signal");

View File

@@ -96,9 +96,9 @@ jclass CAndroidVMHelper::findClass(const std::string & name, bool classloaded)
return get()->FindClass(name.c_str()); return get()->FindClass(name.c_str());
} }
extern "C" JNIEXPORT void JNICALL Java_eu_vcmi_vcmi_NativeMethods_initClassloader(JNIEnv * baseEnv, jclass cls) void CAndroidVMHelper::initClassloader(void * baseEnv)
{ {
CAndroidVMHelper::cacheVM(baseEnv); CAndroidVMHelper::cacheVM(static_cast<JNIEnv *>(baseEnv));
CAndroidVMHelper envHelper; CAndroidVMHelper envHelper;
auto env = envHelper.get(); auto env = envHelper.get();
auto anyVCMIClass = env->FindClass(CAndroidVMHelper::NATIVE_METHODS_DEFAULT_CLASS); auto anyVCMIClass = env->FindClass(CAndroidVMHelper::NATIVE_METHODS_DEFAULT_CLASS);
@@ -108,4 +108,9 @@ extern "C" JNIEXPORT void JNICALL Java_eu_vcmi_vcmi_NativeMethods_initClassloade
vcmiClassLoader = (jclass) env->NewGlobalRef(env->CallObjectMethod(anyVCMIClass, getClassLoaderMethod)); vcmiClassLoader = (jclass) env->NewGlobalRef(env->CallObjectMethod(anyVCMIClass, getClassLoaderMethod));
vcmiFindClassMethod = env->GetMethodID(classLoaderClass, "findClass", "(Ljava/lang/String;)Ljava/lang/Class;"); vcmiFindClassMethod = env->GetMethodID(classLoaderClass, "findClass", "(Ljava/lang/String;)Ljava/lang/Class;");
} }
extern "C" JNIEXPORT void JNICALL Java_eu_vcmi_vcmi_NativeMethods_initClassloader(JNIEnv * baseEnv, jclass cls)
{
CAndroidVMHelper::initClassloader(baseEnv);
}
#endif #endif

View File

@@ -42,6 +42,8 @@ public:
static void cacheVM(JNIEnv * env); static void cacheVM(JNIEnv * env);
static void initClassloader(void * baseEnv);
static constexpr const char * NATIVE_METHODS_DEFAULT_CLASS = "eu/vcmi/vcmi/NativeMethods"; static constexpr const char * NATIVE_METHODS_DEFAULT_CLASS = "eu/vcmi/vcmi/NativeMethods";
}; };