1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-11-24 08:32:34 +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 clientSetupJNI();
public static native void createServer();
public static native void notifyServerReady();

View File

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

View File

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

View File

@ -778,13 +778,6 @@ void CClient::removeGUI()
}
#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)
{
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());
}
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;
auto env = envHelper.get();
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));
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

View File

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