2019-03-13 12:51:55 +00:00
|
|
|
/*************************************************************************/
|
|
|
|
/* java_godot_wrapper.cpp */
|
|
|
|
/*************************************************************************/
|
|
|
|
/* This file is part of: */
|
|
|
|
/* GODOT ENGINE */
|
|
|
|
/* https://godotengine.org */
|
|
|
|
/*************************************************************************/
|
2022-01-13 08:45:09 +00:00
|
|
|
/* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */
|
|
|
|
/* Copyright (c) 2014-2022 Godot Engine contributors (cf. AUTHORS.md). */
|
2019-03-13 12:51:55 +00:00
|
|
|
/* */
|
|
|
|
/* Permission is hereby granted, free of charge, to any person obtaining */
|
|
|
|
/* a copy of this software and associated documentation files (the */
|
|
|
|
/* "Software"), to deal in the Software without restriction, including */
|
|
|
|
/* without limitation the rights to use, copy, modify, merge, publish, */
|
|
|
|
/* distribute, sublicense, and/or sell copies of the Software, and to */
|
|
|
|
/* permit persons to whom the Software is furnished to do so, subject to */
|
|
|
|
/* the following conditions: */
|
|
|
|
/* */
|
|
|
|
/* The above copyright notice and this permission notice shall be */
|
|
|
|
/* included in all copies or substantial portions of the Software. */
|
|
|
|
/* */
|
|
|
|
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
|
|
|
|
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
|
|
|
|
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
|
|
|
|
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
|
|
|
|
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
|
|
|
|
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
|
|
|
|
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
|
|
|
/*************************************************************************/
|
|
|
|
|
|
|
|
#include "java_godot_wrapper.h"
|
|
|
|
|
|
|
|
// JNIEnv is only valid within the thread it belongs to, in a multi threading environment
|
|
|
|
// we can't cache it.
|
|
|
|
// For Godot we call most access methods from our thread and we thus get a valid JNIEnv
|
|
|
|
// from ThreadAndroid. For one or two we expect to pass the environment
|
|
|
|
|
|
|
|
// TODO we could probably create a base class for this...
|
|
|
|
|
2020-06-15 07:46:13 +00:00
|
|
|
GodotJavaWrapper::GodotJavaWrapper(JNIEnv *p_env, jobject p_activity, jobject p_godot_instance) {
|
2019-03-13 12:51:55 +00:00
|
|
|
godot_instance = p_env->NewGlobalRef(p_godot_instance);
|
2020-06-15 07:46:13 +00:00
|
|
|
activity = p_env->NewGlobalRef(p_activity);
|
2019-03-13 12:51:55 +00:00
|
|
|
|
|
|
|
// get info about our Godot class so we can get pointers and stuff...
|
2020-06-15 07:46:13 +00:00
|
|
|
godot_class = p_env->FindClass("org/godotengine/godot/Godot");
|
|
|
|
if (godot_class) {
|
|
|
|
godot_class = (jclass)p_env->NewGlobalRef(godot_class);
|
2019-03-13 12:51:55 +00:00
|
|
|
} else {
|
|
|
|
// this is a pretty serious fail.. bail... pointers will stay 0
|
|
|
|
return;
|
|
|
|
}
|
2020-06-15 07:46:13 +00:00
|
|
|
activity_class = p_env->FindClass("android/app/Activity");
|
|
|
|
if (activity_class) {
|
|
|
|
activity_class = (jclass)p_env->NewGlobalRef(activity_class);
|
|
|
|
} else {
|
|
|
|
// this is a pretty serious fail.. bail... pointers will stay 0
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// get some Godot method pointers...
|
|
|
|
_on_video_init = p_env->GetMethodID(godot_class, "onVideoInit", "()V");
|
2021-09-24 12:07:44 +00:00
|
|
|
_create_offscreen_gl = p_env->GetMethodID(godot_class, "createOffscreenGL", "()Z");
|
|
|
|
_destroy_offscreen_gl = p_env->GetMethodID(godot_class, "destroyOffscreenGL", "()V");
|
|
|
|
_set_offscreen_gl_current = p_env->GetMethodID(godot_class, "setOffscreenGLCurrent", "(Z)V");
|
2020-06-15 07:46:13 +00:00
|
|
|
_restart = p_env->GetMethodID(godot_class, "restart", "()V");
|
|
|
|
_finish = p_env->GetMethodID(godot_class, "forceQuit", "()V");
|
|
|
|
_set_keep_screen_on = p_env->GetMethodID(godot_class, "setKeepScreenOn", "(Z)V");
|
|
|
|
_alert = p_env->GetMethodID(godot_class, "alert", "(Ljava/lang/String;Ljava/lang/String;)V");
|
|
|
|
_get_GLES_version_code = p_env->GetMethodID(godot_class, "getGLESVersionCode", "()I");
|
|
|
|
_get_clipboard = p_env->GetMethodID(godot_class, "getClipboard", "()Ljava/lang/String;");
|
|
|
|
_set_clipboard = p_env->GetMethodID(godot_class, "setClipboard", "(Ljava/lang/String;)V");
|
2022-01-19 12:06:44 +00:00
|
|
|
_has_clipboard = p_env->GetMethodID(godot_class, "hasClipboard", "()Z");
|
2020-06-15 07:46:13 +00:00
|
|
|
_request_permission = p_env->GetMethodID(godot_class, "requestPermission", "(Ljava/lang/String;)Z");
|
|
|
|
_request_permissions = p_env->GetMethodID(godot_class, "requestPermissions", "()Z");
|
|
|
|
_get_granted_permissions = p_env->GetMethodID(godot_class, "getGrantedPermissions", "()[Ljava/lang/String;");
|
|
|
|
_init_input_devices = p_env->GetMethodID(godot_class, "initInputDevices", "()V");
|
|
|
|
_get_surface = p_env->GetMethodID(godot_class, "getSurface", "()Landroid/view/Surface;");
|
|
|
|
_is_activity_resumed = p_env->GetMethodID(godot_class, "isActivityResumed", "()Z");
|
|
|
|
_vibrate = p_env->GetMethodID(godot_class, "vibrate", "(I)V");
|
|
|
|
_get_input_fallback_mapping = p_env->GetMethodID(godot_class, "getInputFallbackMapping", "()Ljava/lang/String;");
|
2021-03-16 07:36:31 +00:00
|
|
|
_on_godot_setup_completed = p_env->GetMethodID(godot_class, "onGodotSetupCompleted", "()V");
|
2020-06-15 07:46:13 +00:00
|
|
|
_on_godot_main_loop_started = p_env->GetMethodID(godot_class, "onGodotMainLoopStarted", "()V");
|
2021-06-25 13:45:16 +00:00
|
|
|
_create_new_godot_instance = p_env->GetMethodID(godot_class, "createNewGodotInstance", "([Ljava/lang/String;)V");
|
2019-03-13 12:51:55 +00:00
|
|
|
|
2020-06-15 07:46:13 +00:00
|
|
|
// get some Activity method pointers...
|
|
|
|
_get_class_loader = p_env->GetMethodID(activity_class, "getClassLoader", "()Ljava/lang/ClassLoader;");
|
2019-03-13 12:51:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
GodotJavaWrapper::~GodotJavaWrapper() {
|
|
|
|
// nothing to do here for now
|
|
|
|
}
|
|
|
|
|
|
|
|
jobject GodotJavaWrapper::get_activity() {
|
2020-06-15 07:46:13 +00:00
|
|
|
return activity;
|
2019-03-13 12:51:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
jobject GodotJavaWrapper::get_member_object(const char *p_name, const char *p_class, JNIEnv *p_env) {
|
2020-06-15 07:46:13 +00:00
|
|
|
if (godot_class) {
|
2019-03-13 12:51:55 +00:00
|
|
|
if (p_env == NULL)
|
2021-01-27 19:10:10 +00:00
|
|
|
p_env = get_jni_env();
|
2019-03-13 12:51:55 +00:00
|
|
|
|
2021-03-09 10:19:57 +00:00
|
|
|
ERR_FAIL_COND_V(p_env == nullptr, nullptr);
|
|
|
|
|
2020-06-15 07:46:13 +00:00
|
|
|
jfieldID fid = p_env->GetStaticFieldID(godot_class, p_name, p_class);
|
|
|
|
return p_env->GetStaticObjectField(godot_class, fid);
|
2019-03-13 12:51:55 +00:00
|
|
|
} else {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
jobject GodotJavaWrapper::get_class_loader() {
|
2020-06-15 07:46:13 +00:00
|
|
|
if (_get_class_loader) {
|
2021-01-27 19:10:10 +00:00
|
|
|
JNIEnv *env = get_jni_env();
|
2021-03-09 10:19:57 +00:00
|
|
|
ERR_FAIL_COND_V(env == nullptr, nullptr);
|
|
|
|
|
2020-12-23 10:07:37 +00:00
|
|
|
return env->CallObjectMethod(activity, _get_class_loader);
|
2019-03-13 12:51:55 +00:00
|
|
|
} else {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void GodotJavaWrapper::gfx_init(bool gl2) {
|
|
|
|
// beats me what this once did, there was no code,
|
|
|
|
// but we're getting false if our GLES3 driver is initialised
|
|
|
|
// and true for our GLES2 driver
|
|
|
|
// Maybe we're supposed to communicate this back or store it?
|
|
|
|
}
|
|
|
|
|
|
|
|
void GodotJavaWrapper::on_video_init(JNIEnv *p_env) {
|
2021-03-16 07:36:31 +00:00
|
|
|
if (_on_video_init) {
|
2019-03-13 12:51:55 +00:00
|
|
|
if (p_env == NULL)
|
2021-01-27 19:10:10 +00:00
|
|
|
p_env = get_jni_env();
|
2021-03-09 10:19:57 +00:00
|
|
|
ERR_FAIL_COND(p_env == nullptr);
|
2019-03-13 12:51:55 +00:00
|
|
|
|
2021-03-16 07:36:31 +00:00
|
|
|
p_env->CallVoidMethod(godot_instance, _on_video_init);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-09-24 12:07:44 +00:00
|
|
|
bool GodotJavaWrapper::create_offscreen_gl(JNIEnv *p_env) {
|
|
|
|
if (_create_offscreen_gl) {
|
|
|
|
return p_env->CallBooleanMethod(godot_instance, _create_offscreen_gl);
|
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void GodotJavaWrapper::destroy_offscreen_gl(JNIEnv *p_env) {
|
|
|
|
if (_destroy_offscreen_gl) {
|
2022-01-12 00:01:24 +00:00
|
|
|
p_env->CallVoidMethod(godot_instance, _destroy_offscreen_gl);
|
2021-09-24 12:07:44 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void GodotJavaWrapper::set_offscreen_gl_current(JNIEnv *p_env, bool p_current) {
|
|
|
|
if (_set_offscreen_gl_current) {
|
|
|
|
if (p_env == NULL)
|
|
|
|
p_env = get_jni_env();
|
|
|
|
ERR_FAIL_COND(p_env == nullptr);
|
|
|
|
p_env->CallVoidMethod(godot_instance, _set_offscreen_gl_current, p_current);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-03-16 07:36:31 +00:00
|
|
|
void GodotJavaWrapper::on_godot_setup_completed(JNIEnv *p_env) {
|
|
|
|
if (_on_godot_setup_completed) {
|
|
|
|
if (p_env == NULL) {
|
|
|
|
p_env = get_jni_env();
|
|
|
|
}
|
2021-03-09 10:19:57 +00:00
|
|
|
ERR_FAIL_COND(p_env == nullptr);
|
2021-03-16 07:36:31 +00:00
|
|
|
p_env->CallVoidMethod(godot_instance, _on_godot_setup_completed);
|
|
|
|
}
|
2019-03-13 12:51:55 +00:00
|
|
|
}
|
|
|
|
|
2020-03-19 22:41:50 +00:00
|
|
|
void GodotJavaWrapper::on_godot_main_loop_started(JNIEnv *p_env) {
|
|
|
|
if (_on_godot_main_loop_started) {
|
2019-10-18 16:59:04 +00:00
|
|
|
if (p_env == NULL) {
|
2021-01-27 19:10:10 +00:00
|
|
|
p_env = get_jni_env();
|
2019-10-18 16:59:04 +00:00
|
|
|
}
|
2021-03-09 10:19:57 +00:00
|
|
|
ERR_FAIL_COND(p_env == nullptr);
|
2021-03-16 07:36:31 +00:00
|
|
|
p_env->CallVoidMethod(godot_instance, _on_godot_main_loop_started);
|
2019-10-18 16:59:04 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-03-13 12:51:55 +00:00
|
|
|
void GodotJavaWrapper::restart(JNIEnv *p_env) {
|
2021-03-16 07:36:31 +00:00
|
|
|
if (_restart) {
|
2019-03-13 12:51:55 +00:00
|
|
|
if (p_env == NULL)
|
2021-01-27 19:10:10 +00:00
|
|
|
p_env = get_jni_env();
|
2021-03-09 10:19:57 +00:00
|
|
|
ERR_FAIL_COND(p_env == nullptr);
|
2019-03-13 12:51:55 +00:00
|
|
|
|
2021-03-16 07:36:31 +00:00
|
|
|
p_env->CallVoidMethod(godot_instance, _restart);
|
|
|
|
}
|
2019-03-13 12:51:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void GodotJavaWrapper::force_quit(JNIEnv *p_env) {
|
2021-03-16 07:36:31 +00:00
|
|
|
if (_finish) {
|
2019-03-13 12:51:55 +00:00
|
|
|
if (p_env == NULL)
|
2021-01-27 19:10:10 +00:00
|
|
|
p_env = get_jni_env();
|
2021-03-09 10:19:57 +00:00
|
|
|
ERR_FAIL_COND(p_env == nullptr);
|
2019-03-13 12:51:55 +00:00
|
|
|
|
2021-03-16 07:36:31 +00:00
|
|
|
p_env->CallVoidMethod(godot_instance, _finish);
|
|
|
|
}
|
2019-03-13 12:51:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void GodotJavaWrapper::set_keep_screen_on(bool p_enabled) {
|
|
|
|
if (_set_keep_screen_on) {
|
2021-01-27 19:10:10 +00:00
|
|
|
JNIEnv *env = get_jni_env();
|
2021-03-09 10:19:57 +00:00
|
|
|
ERR_FAIL_COND(env == nullptr);
|
|
|
|
|
2019-03-13 12:51:55 +00:00
|
|
|
env->CallVoidMethod(godot_instance, _set_keep_screen_on, p_enabled);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void GodotJavaWrapper::alert(const String &p_message, const String &p_title) {
|
|
|
|
if (_alert) {
|
2021-01-27 19:10:10 +00:00
|
|
|
JNIEnv *env = get_jni_env();
|
2021-03-09 10:19:57 +00:00
|
|
|
ERR_FAIL_COND(env == nullptr);
|
|
|
|
|
2019-03-13 12:51:55 +00:00
|
|
|
jstring jStrMessage = env->NewStringUTF(p_message.utf8().get_data());
|
|
|
|
jstring jStrTitle = env->NewStringUTF(p_title.utf8().get_data());
|
|
|
|
env->CallVoidMethod(godot_instance, _alert, jStrMessage, jStrTitle);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int GodotJavaWrapper::get_gles_version_code() {
|
2021-01-27 19:10:10 +00:00
|
|
|
JNIEnv *env = get_jni_env();
|
2021-03-09 10:19:57 +00:00
|
|
|
ERR_FAIL_COND_V(env == nullptr, 0);
|
|
|
|
|
2019-03-13 12:51:55 +00:00
|
|
|
if (_get_GLES_version_code) {
|
|
|
|
return env->CallIntMethod(godot_instance, _get_GLES_version_code);
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool GodotJavaWrapper::has_get_clipboard() {
|
|
|
|
return _get_clipboard != 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
String GodotJavaWrapper::get_clipboard() {
|
|
|
|
if (_get_clipboard) {
|
2021-01-27 19:10:10 +00:00
|
|
|
JNIEnv *env = get_jni_env();
|
2021-03-09 10:19:57 +00:00
|
|
|
ERR_FAIL_COND_V(env == nullptr, String());
|
|
|
|
|
2019-03-13 12:51:55 +00:00
|
|
|
jstring s = (jstring)env->CallObjectMethod(godot_instance, _get_clipboard);
|
|
|
|
return jstring_to_string(s, env);
|
|
|
|
} else {
|
|
|
|
return String();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-08-27 00:47:13 +00:00
|
|
|
String GodotJavaWrapper::get_input_fallback_mapping() {
|
|
|
|
if (_get_input_fallback_mapping) {
|
2021-01-27 19:10:10 +00:00
|
|
|
JNIEnv *env = get_jni_env();
|
2021-03-09 10:19:57 +00:00
|
|
|
ERR_FAIL_COND_V(env == nullptr, String());
|
|
|
|
|
2019-08-27 00:47:13 +00:00
|
|
|
jstring fallback_mapping = (jstring)env->CallObjectMethod(godot_instance, _get_input_fallback_mapping);
|
|
|
|
return jstring_to_string(fallback_mapping, env);
|
|
|
|
} else {
|
|
|
|
return String();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-03-13 12:51:55 +00:00
|
|
|
bool GodotJavaWrapper::has_set_clipboard() {
|
|
|
|
return _set_clipboard != 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void GodotJavaWrapper::set_clipboard(const String &p_text) {
|
|
|
|
if (_set_clipboard) {
|
2021-01-27 19:10:10 +00:00
|
|
|
JNIEnv *env = get_jni_env();
|
2021-03-09 10:19:57 +00:00
|
|
|
ERR_FAIL_COND(env == nullptr);
|
|
|
|
|
2019-03-13 12:51:55 +00:00
|
|
|
jstring jStr = env->NewStringUTF(p_text.utf8().get_data());
|
|
|
|
env->CallVoidMethod(godot_instance, _set_clipboard, jStr);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-01-19 12:06:44 +00:00
|
|
|
bool GodotJavaWrapper::has_has_clipboard() {
|
|
|
|
return _has_clipboard != 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool GodotJavaWrapper::has_clipboard() {
|
|
|
|
if (_has_clipboard) {
|
|
|
|
JNIEnv *env = get_jni_env();
|
|
|
|
ERR_FAIL_COND_V(env == nullptr, false);
|
|
|
|
|
|
|
|
return env->CallBooleanMethod(godot_instance, _has_clipboard);
|
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-03-13 12:51:55 +00:00
|
|
|
bool GodotJavaWrapper::request_permission(const String &p_name) {
|
|
|
|
if (_request_permission) {
|
2021-01-27 19:10:10 +00:00
|
|
|
JNIEnv *env = get_jni_env();
|
2021-03-09 10:19:57 +00:00
|
|
|
ERR_FAIL_COND_V(env == nullptr, false);
|
|
|
|
|
2019-03-13 12:51:55 +00:00
|
|
|
jstring jStrName = env->NewStringUTF(p_name.utf8().get_data());
|
|
|
|
return env->CallBooleanMethod(godot_instance, _request_permission, jStrName);
|
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
2019-05-03 13:56:44 +00:00
|
|
|
|
2019-10-06 18:17:44 +00:00
|
|
|
bool GodotJavaWrapper::request_permissions() {
|
|
|
|
if (_request_permissions) {
|
2021-01-27 19:10:10 +00:00
|
|
|
JNIEnv *env = get_jni_env();
|
2021-03-09 10:19:57 +00:00
|
|
|
ERR_FAIL_COND_V(env == nullptr, false);
|
|
|
|
|
2019-10-06 18:17:44 +00:00
|
|
|
return env->CallBooleanMethod(godot_instance, _request_permissions);
|
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Vector<String> GodotJavaWrapper::get_granted_permissions() const {
|
|
|
|
Vector<String> permissions_list;
|
|
|
|
if (_get_granted_permissions) {
|
2021-01-27 19:10:10 +00:00
|
|
|
JNIEnv *env = get_jni_env();
|
2021-03-09 10:19:57 +00:00
|
|
|
ERR_FAIL_COND_V(env == nullptr, permissions_list);
|
|
|
|
|
2019-10-06 18:17:44 +00:00
|
|
|
jobject permissions_object = env->CallObjectMethod(godot_instance, _get_granted_permissions);
|
|
|
|
jobjectArray *arr = reinterpret_cast<jobjectArray *>(&permissions_object);
|
|
|
|
|
|
|
|
int i = 0;
|
|
|
|
jsize len = env->GetArrayLength(*arr);
|
|
|
|
for (i = 0; i < len; i++) {
|
|
|
|
jstring jstr = (jstring)env->GetObjectArrayElement(*arr, i);
|
|
|
|
String str = jstring_to_string(jstr, env);
|
|
|
|
permissions_list.push_back(str);
|
|
|
|
env->DeleteLocalRef(jstr);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return permissions_list;
|
|
|
|
}
|
|
|
|
|
2019-05-03 13:56:44 +00:00
|
|
|
void GodotJavaWrapper::init_input_devices() {
|
|
|
|
if (_init_input_devices) {
|
2021-01-27 19:10:10 +00:00
|
|
|
JNIEnv *env = get_jni_env();
|
2021-03-09 10:19:57 +00:00
|
|
|
ERR_FAIL_COND(env == nullptr);
|
|
|
|
|
2019-05-03 13:56:44 +00:00
|
|
|
env->CallVoidMethod(godot_instance, _init_input_devices);
|
|
|
|
}
|
|
|
|
}
|
2019-05-30 19:50:36 +00:00
|
|
|
|
|
|
|
jobject GodotJavaWrapper::get_surface() {
|
|
|
|
if (_get_surface) {
|
2021-01-27 19:10:10 +00:00
|
|
|
JNIEnv *env = get_jni_env();
|
2021-03-09 10:19:57 +00:00
|
|
|
ERR_FAIL_COND_V(env == nullptr, nullptr);
|
|
|
|
|
2019-05-30 19:50:36 +00:00
|
|
|
return env->CallObjectMethod(godot_instance, _get_surface);
|
|
|
|
} else {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool GodotJavaWrapper::is_activity_resumed() {
|
|
|
|
if (_is_activity_resumed) {
|
2021-01-27 19:10:10 +00:00
|
|
|
JNIEnv *env = get_jni_env();
|
2021-03-09 10:19:57 +00:00
|
|
|
ERR_FAIL_COND_V(env == nullptr, false);
|
|
|
|
|
2019-05-30 19:50:36 +00:00
|
|
|
return env->CallBooleanMethod(godot_instance, _is_activity_resumed);
|
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
2019-08-17 15:27:29 +00:00
|
|
|
|
|
|
|
void GodotJavaWrapper::vibrate(int p_duration_ms) {
|
|
|
|
if (_vibrate) {
|
2021-01-27 19:10:10 +00:00
|
|
|
JNIEnv *env = get_jni_env();
|
2021-03-09 10:19:57 +00:00
|
|
|
ERR_FAIL_COND(env == nullptr);
|
|
|
|
|
2019-08-17 15:27:29 +00:00
|
|
|
env->CallVoidMethod(godot_instance, _vibrate, p_duration_ms);
|
|
|
|
}
|
|
|
|
}
|
2021-06-25 13:45:16 +00:00
|
|
|
|
|
|
|
void GodotJavaWrapper::create_new_godot_instance(List<String> args) {
|
|
|
|
if (_create_new_godot_instance) {
|
|
|
|
JNIEnv *env = get_jni_env();
|
|
|
|
ERR_FAIL_COND(env == nullptr);
|
|
|
|
|
|
|
|
jobjectArray jargs = env->NewObjectArray(args.size(), env->FindClass("java/lang/String"), env->NewStringUTF(""));
|
|
|
|
for (int i = 0; i < args.size(); i++) {
|
|
|
|
env->SetObjectArrayElement(jargs, i, env->NewStringUTF(args[i].utf8().get_data()));
|
|
|
|
}
|
|
|
|
env->CallVoidMethod(godot_instance, _create_new_godot_instance, jargs);
|
|
|
|
}
|
|
|
|
}
|