2019-03-13 13:51:55 +01:00
|
|
|
/**************************************************************************/
|
|
|
|
/* java_godot_wrapper.cpp */
|
|
|
|
/**************************************************************************/
|
|
|
|
/* This file is part of: */
|
|
|
|
/* GODOT ENGINE */
|
|
|
|
/* https://godotengine.org */
|
|
|
|
/**************************************************************************/
|
|
|
|
/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
|
|
|
|
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
|
|
|
|
/* */
|
|
|
|
/* 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
|
2021-01-19 13:29:41 +01:00
|
|
|
// from get_jni_env(). For one or two we expect to pass the environment
|
2019-03-13 13:51:55 +01:00
|
|
|
|
|
|
|
// TODO we could probably create a base class for this...
|
|
|
|
|
2020-06-15 09:46:13 +02:00
|
|
|
GodotJavaWrapper::GodotJavaWrapper(JNIEnv *p_env, jobject p_activity, jobject p_godot_instance) {
|
2019-03-13 13:51:55 +01:00
|
|
|
godot_instance = p_env->NewGlobalRef(p_godot_instance);
|
2020-06-15 09:46:13 +02:00
|
|
|
activity = p_env->NewGlobalRef(p_activity);
|
2019-03-13 13:51:55 +01:00
|
|
|
|
|
|
|
// get info about our Godot class so we can get pointers and stuff...
|
2020-06-15 09:46:13 +02:00
|
|
|
godot_class = p_env->FindClass("org/godotengine/godot/Godot");
|
|
|
|
if (godot_class) {
|
|
|
|
godot_class = (jclass)p_env->NewGlobalRef(godot_class);
|
2019-03-13 13:51:55 +01:00
|
|
|
} else {
|
|
|
|
// this is a pretty serious fail.. bail... pointers will stay 0
|
|
|
|
return;
|
|
|
|
}
|
2020-06-15 09:46:13 +02: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...
|
|
|
|
_restart = p_env->GetMethodID(godot_class, "restart", "()V");
|
2023-01-26 11:55:47 +01:00
|
|
|
_finish = p_env->GetMethodID(godot_class, "forceQuit", "(I)Z");
|
2020-06-15 09:46:13 +02:00
|
|
|
_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");
|
2023-09-26 05:00:04 +02:00
|
|
|
_is_dark_mode_supported = p_env->GetMethodID(godot_class, "isDarkModeSupported", "()Z");
|
|
|
|
_is_dark_mode = p_env->GetMethodID(godot_class, "isDarkMode", "()Z");
|
2020-06-15 09:46:13 +02:00
|
|
|
_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 14:04:52 +01:00
|
|
|
_has_clipboard = p_env->GetMethodID(godot_class, "hasClipboard", "()Z");
|
2020-06-15 09:46:13 +02: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;");
|
2023-04-13 21:17:55 +02:00
|
|
|
_get_ca_certificates = p_env->GetMethodID(godot_class, "getCACertificates", "()Ljava/lang/String;");
|
2020-06-15 09:46:13 +02:00
|
|
|
_init_input_devices = p_env->GetMethodID(godot_class, "initInputDevices", "()V");
|
2024-05-02 15:15:42 +02:00
|
|
|
_vibrate = p_env->GetMethodID(godot_class, "vibrate", "(II)V");
|
2020-06-15 09:46:13 +02:00
|
|
|
_get_input_fallback_mapping = p_env->GetMethodID(godot_class, "getInputFallbackMapping", "()Ljava/lang/String;");
|
2021-03-16 08:36:31 +01:00
|
|
|
_on_godot_setup_completed = p_env->GetMethodID(godot_class, "onGodotSetupCompleted", "()V");
|
2020-06-15 09:46:13 +02:00
|
|
|
_on_godot_main_loop_started = p_env->GetMethodID(godot_class, "onGodotMainLoopStarted", "()V");
|
2023-01-26 11:55:47 +01:00
|
|
|
_create_new_godot_instance = p_env->GetMethodID(godot_class, "createNewGodotInstance", "([Ljava/lang/String;)I");
|
2022-10-05 19:48:08 +02:00
|
|
|
_get_render_view = p_env->GetMethodID(godot_class, "getRenderView", "()Lorg/godotengine/godot/GodotRenderView;");
|
2023-12-08 12:52:49 +01:00
|
|
|
_begin_benchmark_measure = p_env->GetMethodID(godot_class, "nativeBeginBenchmarkMeasure", "(Ljava/lang/String;Ljava/lang/String;)V");
|
|
|
|
_end_benchmark_measure = p_env->GetMethodID(godot_class, "nativeEndBenchmarkMeasure", "(Ljava/lang/String;Ljava/lang/String;)V");
|
2023-05-23 00:40:38 +02:00
|
|
|
_dump_benchmark = p_env->GetMethodID(godot_class, "nativeDumpBenchmark", "(Ljava/lang/String;)V");
|
2023-07-17 21:11:37 +02:00
|
|
|
_get_gdextension_list_config_file = p_env->GetMethodID(godot_class, "getGDExtensionConfigFiles", "()[Ljava/lang/String;");
|
2023-06-08 04:05:20 +02:00
|
|
|
_has_feature = p_env->GetMethodID(godot_class, "hasFeature", "(Ljava/lang/String;)Z");
|
2019-03-13 13:51:55 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
GodotJavaWrapper::~GodotJavaWrapper() {
|
2022-10-05 19:48:08 +02:00
|
|
|
if (godot_view) {
|
|
|
|
delete godot_view;
|
|
|
|
}
|
|
|
|
|
|
|
|
JNIEnv *env = get_jni_env();
|
|
|
|
ERR_FAIL_NULL(env);
|
|
|
|
env->DeleteGlobalRef(godot_instance);
|
|
|
|
env->DeleteGlobalRef(godot_class);
|
|
|
|
env->DeleteGlobalRef(activity);
|
|
|
|
env->DeleteGlobalRef(activity_class);
|
2019-03-13 13:51:55 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
jobject GodotJavaWrapper::get_activity() {
|
2020-06-15 09:46:13 +02:00
|
|
|
return activity;
|
2019-03-13 13:51:55 +01:00
|
|
|
}
|
|
|
|
|
2020-11-01 02:30:40 +01:00
|
|
|
GodotJavaViewWrapper *GodotJavaWrapper::get_godot_view() {
|
2022-10-05 19:48:08 +02:00
|
|
|
if (godot_view != nullptr) {
|
|
|
|
return godot_view;
|
2020-11-01 02:30:40 +01:00
|
|
|
}
|
2022-10-05 19:48:08 +02:00
|
|
|
if (_get_render_view) {
|
|
|
|
JNIEnv *env = get_jni_env();
|
|
|
|
ERR_FAIL_NULL_V(env, nullptr);
|
|
|
|
jobject godot_render_view = env->CallObjectMethod(godot_instance, _get_render_view);
|
|
|
|
if (!env->IsSameObject(godot_render_view, nullptr)) {
|
|
|
|
godot_view = new GodotJavaViewWrapper(godot_render_view);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return godot_view;
|
2020-11-01 02:30:40 +01:00
|
|
|
}
|
|
|
|
|
2021-03-16 08:36:31 +01:00
|
|
|
void GodotJavaWrapper::on_godot_setup_completed(JNIEnv *p_env) {
|
|
|
|
if (_on_godot_setup_completed) {
|
|
|
|
if (p_env == nullptr) {
|
|
|
|
p_env = get_jni_env();
|
|
|
|
}
|
|
|
|
p_env->CallVoidMethod(godot_instance, _on_godot_setup_completed);
|
|
|
|
}
|
2019-03-13 13:51:55 +01:00
|
|
|
}
|
|
|
|
|
2020-03-19 23:28:33 +01:00
|
|
|
void GodotJavaWrapper::on_godot_main_loop_started(JNIEnv *p_env) {
|
|
|
|
if (_on_godot_main_loop_started) {
|
2020-04-02 01:20:12 +02:00
|
|
|
if (p_env == nullptr) {
|
2021-01-19 13:29:41 +01:00
|
|
|
p_env = get_jni_env();
|
2019-10-18 18:59:04 +02:00
|
|
|
}
|
2022-05-30 23:13:49 +02:00
|
|
|
ERR_FAIL_NULL(p_env);
|
2021-03-16 08:36:31 +01:00
|
|
|
p_env->CallVoidMethod(godot_instance, _on_godot_main_loop_started);
|
2019-10-18 18:59:04 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-03-13 13:51:55 +01:00
|
|
|
void GodotJavaWrapper::restart(JNIEnv *p_env) {
|
2021-03-16 08:36:31 +01:00
|
|
|
if (_restart) {
|
2022-02-16 13:56:32 +01:00
|
|
|
if (p_env == nullptr) {
|
2021-01-19 13:29:41 +01:00
|
|
|
p_env = get_jni_env();
|
2022-02-16 13:56:32 +01:00
|
|
|
}
|
2022-05-30 23:13:49 +02:00
|
|
|
ERR_FAIL_NULL(p_env);
|
2021-03-16 08:36:31 +01:00
|
|
|
p_env->CallVoidMethod(godot_instance, _restart);
|
|
|
|
}
|
2019-03-13 13:51:55 +01:00
|
|
|
}
|
|
|
|
|
2023-01-26 11:55:47 +01:00
|
|
|
bool GodotJavaWrapper::force_quit(JNIEnv *p_env, int p_instance_id) {
|
2021-03-16 08:36:31 +01:00
|
|
|
if (_finish) {
|
2022-02-16 13:56:32 +01:00
|
|
|
if (p_env == nullptr) {
|
2021-01-19 13:29:41 +01:00
|
|
|
p_env = get_jni_env();
|
2022-02-16 13:56:32 +01:00
|
|
|
}
|
2023-01-26 11:55:47 +01:00
|
|
|
ERR_FAIL_NULL_V(p_env, false);
|
|
|
|
return p_env->CallBooleanMethod(godot_instance, _finish, p_instance_id);
|
2021-03-16 08:36:31 +01:00
|
|
|
}
|
2023-01-26 11:55:47 +01:00
|
|
|
return false;
|
2019-03-13 13:51:55 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void GodotJavaWrapper::set_keep_screen_on(bool p_enabled) {
|
|
|
|
if (_set_keep_screen_on) {
|
2021-01-19 13:29:41 +01:00
|
|
|
JNIEnv *env = get_jni_env();
|
2022-05-30 23:13:49 +02:00
|
|
|
ERR_FAIL_NULL(env);
|
2019-03-13 13:51:55 +01: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-19 13:29:41 +01:00
|
|
|
JNIEnv *env = get_jni_env();
|
2022-05-30 23:13:49 +02:00
|
|
|
ERR_FAIL_NULL(env);
|
2019-03-13 13:51:55 +01: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);
|
2024-04-15 19:30:18 +02:00
|
|
|
env->DeleteLocalRef(jStrMessage);
|
|
|
|
env->DeleteLocalRef(jStrTitle);
|
2019-03-13 13:51:55 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-09-26 05:00:04 +02:00
|
|
|
bool GodotJavaWrapper::is_dark_mode_supported() {
|
|
|
|
if (_is_dark_mode_supported) {
|
|
|
|
JNIEnv *env = get_jni_env();
|
|
|
|
ERR_FAIL_NULL_V(env, false);
|
|
|
|
return env->CallBooleanMethod(godot_instance, _is_dark_mode_supported);
|
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool GodotJavaWrapper::is_dark_mode() {
|
|
|
|
if (_is_dark_mode) {
|
|
|
|
JNIEnv *env = get_jni_env();
|
|
|
|
ERR_FAIL_NULL_V(env, false);
|
|
|
|
return env->CallBooleanMethod(godot_instance, _is_dark_mode);
|
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-03-13 13:51:55 +01:00
|
|
|
bool GodotJavaWrapper::has_get_clipboard() {
|
2022-05-30 23:13:49 +02:00
|
|
|
return _get_clipboard != nullptr;
|
2019-03-13 13:51:55 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
String GodotJavaWrapper::get_clipboard() {
|
|
|
|
if (_get_clipboard) {
|
2021-01-19 13:29:41 +01:00
|
|
|
JNIEnv *env = get_jni_env();
|
2022-05-30 23:13:49 +02:00
|
|
|
ERR_FAIL_NULL_V(env, String());
|
2019-03-13 13:51:55 +01:00
|
|
|
jstring s = (jstring)env->CallObjectMethod(godot_instance, _get_clipboard);
|
|
|
|
return jstring_to_string(s, env);
|
|
|
|
} else {
|
|
|
|
return String();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-08-27 02:47:13 +02:00
|
|
|
String GodotJavaWrapper::get_input_fallback_mapping() {
|
|
|
|
if (_get_input_fallback_mapping) {
|
2021-01-19 13:29:41 +01:00
|
|
|
JNIEnv *env = get_jni_env();
|
2022-05-30 23:13:49 +02:00
|
|
|
ERR_FAIL_NULL_V(env, String());
|
2019-08-27 02:47:13 +02: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 13:51:55 +01:00
|
|
|
bool GodotJavaWrapper::has_set_clipboard() {
|
2022-05-30 23:13:49 +02:00
|
|
|
return _set_clipboard != nullptr;
|
2019-03-13 13:51:55 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void GodotJavaWrapper::set_clipboard(const String &p_text) {
|
|
|
|
if (_set_clipboard) {
|
2021-01-19 13:29:41 +01:00
|
|
|
JNIEnv *env = get_jni_env();
|
2022-05-30 23:13:49 +02:00
|
|
|
ERR_FAIL_NULL(env);
|
2019-03-13 13:51:55 +01:00
|
|
|
jstring jStr = env->NewStringUTF(p_text.utf8().get_data());
|
|
|
|
env->CallVoidMethod(godot_instance, _set_clipboard, jStr);
|
2024-04-15 19:30:18 +02:00
|
|
|
env->DeleteLocalRef(jStr);
|
2019-03-13 13:51:55 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-01-19 14:04:52 +01:00
|
|
|
bool GodotJavaWrapper::has_has_clipboard() {
|
2022-05-30 23:13:49 +02:00
|
|
|
return _has_clipboard != nullptr;
|
2022-01-19 14:04:52 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
bool GodotJavaWrapper::has_clipboard() {
|
|
|
|
if (_has_clipboard) {
|
|
|
|
JNIEnv *env = get_jni_env();
|
2022-05-30 23:13:49 +02:00
|
|
|
ERR_FAIL_NULL_V(env, false);
|
2022-01-19 14:04:52 +01:00
|
|
|
return env->CallBooleanMethod(godot_instance, _has_clipboard);
|
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-03-13 13:51:55 +01:00
|
|
|
bool GodotJavaWrapper::request_permission(const String &p_name) {
|
|
|
|
if (_request_permission) {
|
2021-01-19 13:29:41 +01:00
|
|
|
JNIEnv *env = get_jni_env();
|
2022-05-30 23:13:49 +02:00
|
|
|
ERR_FAIL_NULL_V(env, false);
|
2019-03-13 13:51:55 +01:00
|
|
|
jstring jStrName = env->NewStringUTF(p_name.utf8().get_data());
|
2024-04-15 19:30:18 +02:00
|
|
|
bool result = env->CallBooleanMethod(godot_instance, _request_permission, jStrName);
|
|
|
|
env->DeleteLocalRef(jStrName);
|
|
|
|
return result;
|
2019-03-13 13:51:55 +01:00
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
2019-05-03 15:56:44 +02:00
|
|
|
|
2019-10-06 20:17:44 +02:00
|
|
|
bool GodotJavaWrapper::request_permissions() {
|
|
|
|
if (_request_permissions) {
|
2021-01-19 13:29:41 +01:00
|
|
|
JNIEnv *env = get_jni_env();
|
2022-05-30 23:13:49 +02:00
|
|
|
ERR_FAIL_NULL_V(env, false);
|
2019-10-06 20:17:44 +02: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-19 13:29:41 +01:00
|
|
|
JNIEnv *env = get_jni_env();
|
2022-05-30 23:13:49 +02:00
|
|
|
ERR_FAIL_NULL_V(env, permissions_list);
|
2019-10-06 20:17:44 +02:00
|
|
|
jobject permissions_object = env->CallObjectMethod(godot_instance, _get_granted_permissions);
|
|
|
|
jobjectArray *arr = reinterpret_cast<jobjectArray *>(&permissions_object);
|
|
|
|
|
|
|
|
jsize len = env->GetArrayLength(*arr);
|
2022-05-30 23:13:49 +02:00
|
|
|
for (int i = 0; i < len; i++) {
|
2019-10-06 20:17:44 +02:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2023-07-17 21:11:37 +02:00
|
|
|
Vector<String> GodotJavaWrapper::get_gdextension_list_config_file() const {
|
|
|
|
Vector<String> config_file_list;
|
|
|
|
if (_get_gdextension_list_config_file) {
|
|
|
|
JNIEnv *env = get_jni_env();
|
|
|
|
ERR_FAIL_NULL_V(env, config_file_list);
|
|
|
|
jobject config_file_list_object = env->CallObjectMethod(godot_instance, _get_gdextension_list_config_file);
|
|
|
|
jobjectArray *arr = reinterpret_cast<jobjectArray *>(&config_file_list_object);
|
|
|
|
|
|
|
|
jsize len = env->GetArrayLength(*arr);
|
|
|
|
for (int i = 0; i < len; i++) {
|
|
|
|
jstring j_config_file = (jstring)env->GetObjectArrayElement(*arr, i);
|
|
|
|
String config_file = jstring_to_string(j_config_file, env);
|
|
|
|
config_file_list.push_back(config_file);
|
|
|
|
env->DeleteLocalRef(j_config_file);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return config_file_list;
|
|
|
|
}
|
|
|
|
|
2023-04-13 21:17:55 +02:00
|
|
|
String GodotJavaWrapper::get_ca_certificates() const {
|
|
|
|
if (_get_ca_certificates) {
|
|
|
|
JNIEnv *env = get_jni_env();
|
|
|
|
ERR_FAIL_NULL_V(env, String());
|
|
|
|
jstring s = (jstring)env->CallObjectMethod(godot_instance, _get_ca_certificates);
|
|
|
|
return jstring_to_string(s, env);
|
|
|
|
} else {
|
|
|
|
return String();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-05-03 15:56:44 +02:00
|
|
|
void GodotJavaWrapper::init_input_devices() {
|
|
|
|
if (_init_input_devices) {
|
2021-01-19 13:29:41 +01:00
|
|
|
JNIEnv *env = get_jni_env();
|
2022-05-30 23:13:49 +02:00
|
|
|
ERR_FAIL_NULL(env);
|
2019-05-03 15:56:44 +02:00
|
|
|
env->CallVoidMethod(godot_instance, _init_input_devices);
|
|
|
|
}
|
|
|
|
}
|
2019-05-30 21:50:36 +02:00
|
|
|
|
2024-05-02 15:15:42 +02:00
|
|
|
void GodotJavaWrapper::vibrate(int p_duration_ms, float p_amplitude) {
|
2019-08-17 17:27:29 +02:00
|
|
|
if (_vibrate) {
|
2021-01-19 13:29:41 +01:00
|
|
|
JNIEnv *env = get_jni_env();
|
2022-05-30 23:13:49 +02:00
|
|
|
ERR_FAIL_NULL(env);
|
2024-05-02 15:15:42 +02:00
|
|
|
|
|
|
|
int j_amplitude = -1.0;
|
|
|
|
|
|
|
|
if (p_amplitude != -1.0) {
|
|
|
|
j_amplitude = CLAMP(int(p_amplitude * 255), 1, 255);
|
|
|
|
}
|
|
|
|
|
|
|
|
env->CallVoidMethod(godot_instance, _vibrate, p_duration_ms, j_amplitude);
|
2019-08-17 17:27:29 +02:00
|
|
|
}
|
|
|
|
}
|
2021-06-25 15:45:16 +02:00
|
|
|
|
2021-08-01 21:47:20 +02:00
|
|
|
int GodotJavaWrapper::create_new_godot_instance(const List<String> &args) {
|
2021-06-25 15:45:16 +02:00
|
|
|
if (_create_new_godot_instance) {
|
|
|
|
JNIEnv *env = get_jni_env();
|
2023-01-26 11:55:47 +01:00
|
|
|
ERR_FAIL_NULL_V(env, 0);
|
2021-06-25 15:45:16 +02:00
|
|
|
jobjectArray jargs = env->NewObjectArray(args.size(), env->FindClass("java/lang/String"), env->NewStringUTF(""));
|
|
|
|
for (int i = 0; i < args.size(); i++) {
|
2024-04-15 19:30:18 +02:00
|
|
|
jstring j_arg = env->NewStringUTF(args[i].utf8().get_data());
|
|
|
|
env->SetObjectArrayElement(jargs, i, j_arg);
|
|
|
|
env->DeleteLocalRef(j_arg);
|
2021-06-25 15:45:16 +02:00
|
|
|
}
|
2023-01-26 11:55:47 +01:00
|
|
|
return env->CallIntMethod(godot_instance, _create_new_godot_instance, jargs);
|
|
|
|
} else {
|
|
|
|
return 0;
|
2021-06-25 15:45:16 +02:00
|
|
|
}
|
|
|
|
}
|
2023-01-13 20:24:12 +01:00
|
|
|
|
2023-12-08 12:52:49 +01:00
|
|
|
void GodotJavaWrapper::begin_benchmark_measure(const String &p_context, const String &p_label) {
|
2023-01-13 20:24:12 +01:00
|
|
|
if (_begin_benchmark_measure) {
|
|
|
|
JNIEnv *env = get_jni_env();
|
|
|
|
ERR_FAIL_NULL(env);
|
2023-12-08 12:52:49 +01:00
|
|
|
jstring j_context = env->NewStringUTF(p_context.utf8().get_data());
|
2023-01-13 20:24:12 +01:00
|
|
|
jstring j_label = env->NewStringUTF(p_label.utf8().get_data());
|
2023-12-08 12:52:49 +01:00
|
|
|
env->CallVoidMethod(godot_instance, _begin_benchmark_measure, j_context, j_label);
|
2024-04-15 19:30:18 +02:00
|
|
|
env->DeleteLocalRef(j_context);
|
|
|
|
env->DeleteLocalRef(j_label);
|
2023-01-13 20:24:12 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-12-08 12:52:49 +01:00
|
|
|
void GodotJavaWrapper::end_benchmark_measure(const String &p_context, const String &p_label) {
|
2023-01-13 20:24:12 +01:00
|
|
|
if (_end_benchmark_measure) {
|
|
|
|
JNIEnv *env = get_jni_env();
|
|
|
|
ERR_FAIL_NULL(env);
|
2023-12-08 12:52:49 +01:00
|
|
|
jstring j_context = env->NewStringUTF(p_context.utf8().get_data());
|
2023-01-13 20:24:12 +01:00
|
|
|
jstring j_label = env->NewStringUTF(p_label.utf8().get_data());
|
2023-12-08 12:52:49 +01:00
|
|
|
env->CallVoidMethod(godot_instance, _end_benchmark_measure, j_context, j_label);
|
2024-04-15 19:30:18 +02:00
|
|
|
env->DeleteLocalRef(j_context);
|
|
|
|
env->DeleteLocalRef(j_label);
|
2023-01-13 20:24:12 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void GodotJavaWrapper::dump_benchmark(const String &benchmark_file) {
|
|
|
|
if (_dump_benchmark) {
|
|
|
|
JNIEnv *env = get_jni_env();
|
|
|
|
ERR_FAIL_NULL(env);
|
|
|
|
jstring j_benchmark_file = env->NewStringUTF(benchmark_file.utf8().get_data());
|
|
|
|
env->CallVoidMethod(godot_instance, _dump_benchmark, j_benchmark_file);
|
2024-04-15 19:30:18 +02:00
|
|
|
env->DeleteLocalRef(j_benchmark_file);
|
2023-01-13 20:24:12 +01:00
|
|
|
}
|
|
|
|
}
|
2023-06-08 04:05:20 +02:00
|
|
|
|
|
|
|
bool GodotJavaWrapper::has_feature(const String &p_feature) const {
|
|
|
|
if (_has_feature) {
|
|
|
|
JNIEnv *env = get_jni_env();
|
|
|
|
ERR_FAIL_NULL_V(env, false);
|
|
|
|
|
|
|
|
jstring j_feature = env->NewStringUTF(p_feature.utf8().get_data());
|
2024-04-15 19:30:18 +02:00
|
|
|
bool result = env->CallBooleanMethod(godot_instance, _has_feature, j_feature);
|
|
|
|
env->DeleteLocalRef(j_feature);
|
|
|
|
return result;
|
2023-06-08 04:05:20 +02:00
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|