| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | /*************************************************************************/ | 
					
						
							| 
									
										
										
										
											2019-03-13 23:51:55 +11:00
										 |  |  | /*  java_godot_lib_jni.cpp                                               */ | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | /*************************************************************************/ | 
					
						
							|  |  |  | /*                       This file is part of:                           */ | 
					
						
							|  |  |  | /*                           GODOT ENGINE                                */ | 
					
						
							| 
									
										
										
										
											2017-08-27 14:16:55 +02:00
										 |  |  | /*                      https://godotengine.org                          */ | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | /*************************************************************************/ | 
					
						
							| 
									
										
										
										
											2022-01-03 21:27:34 +01:00
										 |  |  | /* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur.                 */ | 
					
						
							|  |  |  | /* Copyright (c) 2014-2022 Godot Engine contributors (cf. AUTHORS.md).   */ | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03: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.                */ | 
					
						
							|  |  |  | /*************************************************************************/ | 
					
						
							| 
									
										
										
										
											2018-01-05 00:50:27 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-03-13 23:51:55 +11:00
										 |  |  | #include "java_godot_lib_jni.h"
 | 
					
						
							| 
									
										
										
										
											2020-03-04 13:36:09 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-03-13 23:51:55 +11:00
										 |  |  | #include "java_godot_io_wrapper.h"
 | 
					
						
							|  |  |  | #include "java_godot_wrapper.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | #include "android/asset_manager_jni.h"
 | 
					
						
							| 
									
										
										
										
											2021-08-04 21:22:11 +02:00
										 |  |  | #include "android_input_handler.h"
 | 
					
						
							| 
									
										
										
										
											2020-01-19 20:02:40 +01:00
										 |  |  | #include "api/java_class_wrapper.h"
 | 
					
						
							| 
									
										
										
										
											2020-03-25 14:01:12 -07:00
										 |  |  | #include "api/jni_singleton.h"
 | 
					
						
							| 
									
										
										
										
											2020-11-07 19:33:38 -03:00
										 |  |  | #include "core/config/engine.h"
 | 
					
						
							|  |  |  | #include "core/config/project_settings.h"
 | 
					
						
							| 
									
										
										
										
											2020-04-28 15:19:37 +02:00
										 |  |  | #include "core/input/input.h"
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | #include "dir_access_jandroid.h"
 | 
					
						
							| 
									
										
										
										
											2020-03-27 17:30:18 +01:00
										 |  |  | #include "display_server_android.h"
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | #include "file_access_android.h"
 | 
					
						
							| 
									
										
										
										
											2020-03-04 09:21:59 -08:00
										 |  |  | #include "jni_utils.h"
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | #include "main/main.h"
 | 
					
						
							| 
									
										
										
										
											2019-11-25 15:01:44 +01:00
										 |  |  | #include "net_socket_android.h"
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | #include "os_android.h"
 | 
					
						
							| 
									
										
										
										
											2019-02-26 23:54:45 +03:00
										 |  |  | #include "string_android.h"
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | #include "thread_jandroid.h"
 | 
					
						
							| 
									
										
										
										
											2020-03-04 13:36:09 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-10-08 02:37:58 +03:00
										 |  |  | #include <android/input.h>
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | #include <unistd.h>
 | 
					
						
							| 
									
										
										
										
											2014-09-02 23:13:40 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-05 19:00:28 +01:00
										 |  |  | #include <android/native_window_jni.h>
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-04-02 01:20:12 +02:00
										 |  |  | static JavaClassWrapper *java_class_wrapper = nullptr; | 
					
						
							|  |  |  | static OS_Android *os_android = nullptr; | 
					
						
							| 
									
										
										
										
											2021-08-04 21:22:11 +02:00
										 |  |  | static AndroidInputHandler *input_handler = nullptr; | 
					
						
							| 
									
										
										
										
											2020-04-02 01:20:12 +02:00
										 |  |  | static GodotJavaWrapper *godot_java = nullptr; | 
					
						
							|  |  |  | static GodotIOJavaWrapper *godot_io_java = nullptr; | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-04 09:21:59 -08:00
										 |  |  | static bool initialized = false; | 
					
						
							| 
									
										
										
										
											2021-08-04 21:22:11 +02:00
										 |  |  | static SafeNumeric<int> step; // Shared between UI and render threads
 | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-04 09:21:59 -08:00
										 |  |  | static Size2 new_size; | 
					
						
							|  |  |  | static Vector3 accelerometer; | 
					
						
							|  |  |  | static Vector3 gravity; | 
					
						
							|  |  |  | static Vector3 magnetometer; | 
					
						
							|  |  |  | static Vector3 gyroscope; | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-04 09:21:59 -08:00
										 |  |  | extern "C" { | 
					
						
							| 
									
										
										
										
											2014-03-13 22:57:24 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-04 09:21:59 -08:00
										 |  |  | JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_setVirtualKeyboardHeight(JNIEnv *env, jclass clazz, jint p_height) { | 
					
						
							| 
									
										
										
										
											2019-03-13 23:51:55 +11:00
										 |  |  | 	if (godot_io_java) { | 
					
						
							|  |  |  | 		godot_io_java->set_vk_height(p_height); | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2017-10-04 15:39:31 +07:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-06-15 00:46:13 -07:00
										 |  |  | JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_initialize(JNIEnv *env, jclass clazz, jobject activity, jobject godot_instance, jobject p_asset_manager, jboolean p_use_apk_expansion) { | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	initialized = true; | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	JavaVM *jvm; | 
					
						
							|  |  |  | 	env->GetJavaVM(&jvm); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-03-13 23:51:55 +11:00
										 |  |  | 	// create our wrapper classes
 | 
					
						
							| 
									
										
										
										
											2020-06-15 00:46:13 -07:00
										 |  |  | 	godot_java = new GodotJavaWrapper(env, activity, godot_instance); | 
					
						
							| 
									
										
										
										
											2019-03-13 23:51:55 +11:00
										 |  |  | 	godot_io_java = new GodotIOJavaWrapper(env, godot_java->get_member_object("io", "Lorg/godotengine/godot/GodotIO;", env)); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-01-19 13:29:41 +01:00
										 |  |  | 	init_thread_jandroid(jvm, env); | 
					
						
							| 
									
										
										
										
											2015-09-03 23:24:55 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-03-13 23:51:55 +11:00
										 |  |  | 	jobject amgr = env->NewGlobalRef(p_asset_manager); | 
					
						
							| 
									
										
										
										
											2015-09-03 23:24:55 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-03-13 23:51:55 +11:00
										 |  |  | 	FileAccessAndroid::asset_manager = AAssetManager_fromJava(env, amgr); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-03-13 23:51:55 +11:00
										 |  |  | 	DirAccessJAndroid::setup(godot_io_java->get_instance()); | 
					
						
							| 
									
										
										
										
											2019-11-25 15:01:44 +01:00
										 |  |  | 	NetSocketAndroid::setup(godot_java->get_member_object("netUtils", "Lorg/godotengine/godot/utils/GodotNetUtils;", env)); | 
					
						
							| 
									
										
										
										
											2019-03-13 23:51:55 +11:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	os_android = new OS_Android(godot_java, godot_io_java, p_use_apk_expansion); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	char wd[500]; | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	getcwd(wd, 500); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-03-13 23:51:55 +11:00
										 |  |  | 	godot_java->on_video_init(env); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-06-15 00:46:13 -07:00
										 |  |  | JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_ondestroy(JNIEnv *env, jclass clazz) { | 
					
						
							| 
									
										
										
										
											2019-03-13 23:51:55 +11:00
										 |  |  | 	// lets cleanup
 | 
					
						
							|  |  |  | 	if (godot_io_java) { | 
					
						
							|  |  |  | 		delete godot_io_java; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	if (godot_java) { | 
					
						
							|  |  |  | 		delete godot_java; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2021-08-04 21:22:11 +02:00
										 |  |  | 	if (input_handler) { | 
					
						
							|  |  |  | 		delete input_handler; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2019-03-13 23:51:55 +11:00
										 |  |  | 	if (os_android) { | 
					
						
							|  |  |  | 		delete os_android; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-04 09:21:59 -08:00
										 |  |  | JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_setup(JNIEnv *env, jclass clazz, jobjectArray p_cmdline) { | 
					
						
							| 
									
										
										
										
											2021-01-19 13:29:41 +01:00
										 |  |  | 	setup_android_thread(); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-04-02 01:20:12 +02:00
										 |  |  | 	const char **cmdline = nullptr; | 
					
						
							|  |  |  | 	jstring *j_cmdline = nullptr; | 
					
						
							| 
									
										
										
										
											2017-08-18 21:17:35 +07:00
										 |  |  | 	int cmdlen = 0; | 
					
						
							|  |  |  | 	if (p_cmdline) { | 
					
						
							|  |  |  | 		cmdlen = env->GetArrayLength(p_cmdline); | 
					
						
							|  |  |  | 		if (cmdlen) { | 
					
						
							| 
									
										
										
										
											2021-03-10 18:31:44 +00:00
										 |  |  | 			cmdline = (const char **)memalloc((cmdlen + 1) * sizeof(const char *)); | 
					
						
							|  |  |  | 			ERR_FAIL_NULL_MSG(cmdline, "Out of memory."); | 
					
						
							| 
									
										
										
										
											2020-04-02 01:20:12 +02:00
										 |  |  | 			cmdline[cmdlen] = nullptr; | 
					
						
							| 
									
										
										
										
											2021-03-10 18:31:44 +00:00
										 |  |  | 			j_cmdline = (jstring *)memalloc(cmdlen * sizeof(jstring)); | 
					
						
							|  |  |  | 			ERR_FAIL_NULL_MSG(j_cmdline, "Out of memory."); | 
					
						
							| 
									
										
										
										
											2017-08-18 21:17:35 +07:00
										 |  |  | 
 | 
					
						
							|  |  |  | 			for (int i = 0; i < cmdlen; i++) { | 
					
						
							|  |  |  | 				jstring string = (jstring)env->GetObjectArrayElement(p_cmdline, i); | 
					
						
							|  |  |  | 				const char *rawString = env->GetStringUTFChars(string, 0); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 				cmdline[i] = rawString; | 
					
						
							| 
									
										
										
										
											2019-02-26 23:54:45 +03:00
										 |  |  | 				j_cmdline[i] = string; | 
					
						
							| 
									
										
										
										
											2017-08-18 21:17:35 +07:00
										 |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	Error err = Main::setup("apk", cmdlen, (char **)cmdline, false); | 
					
						
							|  |  |  | 	if (cmdline) { | 
					
						
							| 
									
										
										
										
											2019-02-26 23:54:45 +03:00
										 |  |  | 		if (j_cmdline) { | 
					
						
							|  |  |  | 			for (int i = 0; i < cmdlen; ++i) { | 
					
						
							|  |  |  | 				env->ReleaseStringUTFChars(j_cmdline[i], cmdline[i]); | 
					
						
							|  |  |  | 			} | 
					
						
							| 
									
										
										
										
											2021-03-10 18:31:44 +00:00
										 |  |  | 			memfree(j_cmdline); | 
					
						
							| 
									
										
										
										
											2019-02-26 23:54:45 +03:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2021-03-10 18:31:44 +00:00
										 |  |  | 		memfree(cmdline); | 
					
						
							| 
									
										
										
										
											2017-08-18 21:17:35 +07:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (err != OK) { | 
					
						
							| 
									
										
										
										
											2021-03-16 00:36:31 -07:00
										 |  |  | 		return; // should exit instead and print the error
 | 
					
						
							| 
									
										
										
										
											2017-08-18 21:17:35 +07:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-03-13 23:51:55 +11:00
										 |  |  | 	java_class_wrapper = memnew(JavaClassWrapper(godot_java->get_activity())); | 
					
						
							| 
									
										
										
										
											2021-07-11 19:30:33 -03:00
										 |  |  | 	GDREGISTER_CLASS(JNISingleton); | 
					
						
							| 
									
										
										
										
											2017-08-18 21:17:35 +07:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-05-24 10:04:59 +02:00
										 |  |  | JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_resize(JNIEnv *env, jclass clazz, jobject p_surface, jint p_width, jint p_height) { | 
					
						
							|  |  |  | 	if (os_android) { | 
					
						
							|  |  |  | 		os_android->set_display_size(Size2i(p_width, p_height)); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		// No need to reset the surface during startup
 | 
					
						
							| 
									
										
										
										
											2021-08-04 21:22:11 +02:00
										 |  |  | 		if (step.get() > 0) { | 
					
						
							| 
									
										
										
										
											2020-05-24 10:04:59 +02:00
										 |  |  | 			if (p_surface) { | 
					
						
							|  |  |  | 				ANativeWindow *native_window = ANativeWindow_fromSurface(env, p_surface); | 
					
						
							|  |  |  | 				os_android->set_native_window(native_window); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 				DisplayServerAndroid::get_singleton()->reset_window(); | 
					
						
							| 
									
										
										
										
											2021-05-03 09:23:05 -07:00
										 |  |  | 				DisplayServerAndroid::get_singleton()->notify_surface_changed(p_width, p_height); | 
					
						
							| 
									
										
										
										
											2020-05-24 10:04:59 +02:00
										 |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2017-08-18 21:17:35 +07:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-10-31 20:22:48 +01:00
										 |  |  | JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_newcontext(JNIEnv *env, jclass clazz, jobject p_surface) { | 
					
						
							| 
									
										
										
										
											2017-08-18 21:17:35 +07:00
										 |  |  | 	if (os_android) { | 
					
						
							| 
									
										
										
										
											2021-08-04 21:22:11 +02:00
										 |  |  | 		if (step.get() == 0) { | 
					
						
							| 
									
										
										
										
											2019-03-05 23:29:44 +01:00
										 |  |  | 			// During startup
 | 
					
						
							| 
									
										
										
										
											2020-03-05 19:00:28 +01:00
										 |  |  | 			if (p_surface) { | 
					
						
							|  |  |  | 				ANativeWindow *native_window = ANativeWindow_fromSurface(env, p_surface); | 
					
						
							|  |  |  | 				os_android->set_native_window(native_window); | 
					
						
							|  |  |  | 			} | 
					
						
							| 
									
										
										
										
											2019-03-05 23:29:44 +01:00
										 |  |  | 		} else { | 
					
						
							| 
									
										
										
										
											2020-03-05 19:00:28 +01:00
										 |  |  | 			// Rendering context recreated because it was lost; restart app to let it reload everything
 | 
					
						
							| 
									
										
										
										
											2021-08-04 21:22:11 +02:00
										 |  |  | 			step.set(-1); // Ensure no further steps are attempted and no further events are sent
 | 
					
						
							| 
									
										
										
										
											2019-03-05 23:29:44 +01:00
										 |  |  | 			os_android->main_loop_end(); | 
					
						
							| 
									
										
										
										
											2019-03-13 23:51:55 +11:00
										 |  |  | 			godot_java->restart(env); | 
					
						
							| 
									
										
										
										
											2019-03-05 23:29:44 +01:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2017-08-18 21:17:35 +07:00
										 |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-04 09:21:59 -08:00
										 |  |  | JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_back(JNIEnv *env, jclass clazz) { | 
					
						
							| 
									
										
										
										
											2022-02-16 13:56:32 +01:00
										 |  |  | 	if (step.get() == 0) { | 
					
						
							| 
									
										
										
										
											2018-03-27 22:03:44 +07:00
										 |  |  | 		return; | 
					
						
							| 
									
										
										
										
											2022-02-16 13:56:32 +01:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2018-03-27 22:03:44 +07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-08-04 21:22:11 +02:00
										 |  |  | 	if (DisplayServerAndroid *dsa = Object::cast_to<DisplayServerAndroid>(DisplayServer::get_singleton())) { | 
					
						
							|  |  |  | 		dsa->send_window_event(DisplayServer::WINDOW_EVENT_GO_BACK_REQUEST); | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2017-08-18 21:17:35 +07:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-04 09:21:59 -08:00
										 |  |  | JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_step(JNIEnv *env, jclass clazz) { | 
					
						
							| 
									
										
										
										
											2022-02-16 13:56:32 +01:00
										 |  |  | 	if (step.get() == -1) { | 
					
						
							| 
									
										
										
										
											2019-03-05 23:29:44 +01:00
										 |  |  | 		return; | 
					
						
							| 
									
										
										
										
											2022-02-16 13:56:32 +01:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2019-03-05 23:29:44 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-08-04 21:22:11 +02:00
										 |  |  | 	if (step.get() == 0) { | 
					
						
							| 
									
										
										
										
											2021-01-19 13:29:41 +01:00
										 |  |  | 		// Since Godot is initialized on the UI thread, main_thread_id was set to that thread's id,
 | 
					
						
							| 
									
										
										
										
											2017-08-22 17:21:41 +02:00
										 |  |  | 		// but for Godot purposes, the main thread is the one running the game loop
 | 
					
						
							|  |  |  | 		Main::setup2(Thread::get_caller_id()); | 
					
						
							| 
									
										
										
										
											2021-08-04 21:22:11 +02:00
										 |  |  | 		input_handler = new AndroidInputHandler(); | 
					
						
							|  |  |  | 		step.increment(); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 		return; | 
					
						
							| 
									
										
										
										
											2017-08-18 21:17:35 +07:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-08-04 21:22:11 +02:00
										 |  |  | 	if (step.get() == 1) { | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 		if (!Main::start()) { | 
					
						
							| 
									
										
										
										
											2021-03-16 00:36:31 -07:00
										 |  |  | 			return; // should exit instead and print the error
 | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-03-16 00:36:31 -07:00
										 |  |  | 		godot_java->on_godot_setup_completed(env); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 		os_android->main_loop_begin(); | 
					
						
							| 
									
										
										
										
											2020-03-19 15:28:33 -07:00
										 |  |  | 		godot_java->on_godot_main_loop_started(env); | 
					
						
							| 
									
										
										
										
											2021-08-04 21:22:11 +02:00
										 |  |  | 		step.increment(); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-27 17:30:18 +01:00
										 |  |  | 	DisplayServerAndroid::get_singleton()->process_accelerometer(accelerometer); | 
					
						
							|  |  |  | 	DisplayServerAndroid::get_singleton()->process_gravity(gravity); | 
					
						
							|  |  |  | 	DisplayServerAndroid::get_singleton()->process_magnetometer(magnetometer); | 
					
						
							|  |  |  | 	DisplayServerAndroid::get_singleton()->process_gyroscope(gyroscope); | 
					
						
							| 
									
										
										
										
											2016-07-15 15:31:34 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-10-03 13:40:37 -04:00
										 |  |  | 	if (os_android->main_loop_iterate()) { | 
					
						
							| 
									
										
										
										
											2019-03-13 23:51:55 +11:00
										 |  |  | 		godot_java->force_quit(env); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-10-08 02:37:58 +03:00
										 |  |  | void touch_preprocessing(JNIEnv *env, jclass clazz, jint input_device, jint ev, jint pointer, jint pointer_count, jfloatArray positions, jint buttons_mask, jfloat vertical_factor, jfloat horizontal_factor) { | 
					
						
							| 
									
										
										
										
											2022-02-16 13:56:32 +01:00
										 |  |  | 	if (step.get() <= 0) { | 
					
						
							| 
									
										
										
										
											2018-03-27 22:03:44 +07:00
										 |  |  | 		return; | 
					
						
							| 
									
										
										
										
											2022-02-16 13:56:32 +01:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2018-03-27 22:03:44 +07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-08-04 21:22:11 +02:00
										 |  |  | 	Vector<AndroidInputHandler::TouchPos> points; | 
					
						
							| 
									
										
										
										
											2020-10-08 02:37:58 +03:00
										 |  |  | 	for (int i = 0; i < pointer_count; i++) { | 
					
						
							|  |  |  | 		jfloat p[3]; | 
					
						
							|  |  |  | 		env->GetFloatArrayRegion(positions, i * 3, 3, p); | 
					
						
							| 
									
										
										
										
											2021-08-04 21:22:11 +02:00
										 |  |  | 		AndroidInputHandler::TouchPos tp; | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 		tp.pos = Point2(p[1], p[2]); | 
					
						
							| 
									
										
										
										
											2020-10-08 02:37:58 +03:00
										 |  |  | 		tp.id = (int)p[0]; | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 		points.push_back(tp); | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2020-11-01 03:30:40 +02:00
										 |  |  | 	if ((input_device & AINPUT_SOURCE_MOUSE) == AINPUT_SOURCE_MOUSE || (input_device & AINPUT_SOURCE_MOUSE_RELATIVE) == AINPUT_SOURCE_MOUSE_RELATIVE) { | 
					
						
							| 
									
										
										
										
											2021-08-04 21:22:11 +02:00
										 |  |  | 		input_handler->process_mouse_event(input_device, ev, buttons_mask, points[0].pos, vertical_factor, horizontal_factor); | 
					
						
							| 
									
										
										
										
											2020-10-08 02:37:58 +03:00
										 |  |  | 	} else { | 
					
						
							| 
									
										
										
										
											2021-08-04 21:22:11 +02:00
										 |  |  | 		input_handler->process_touch(ev, pointer, points); | 
					
						
							| 
									
										
										
										
											2020-10-08 02:37:58 +03:00
										 |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-08-04 21:22:11 +02:00
										 |  |  | // Called on the UI thread
 | 
					
						
							| 
									
										
										
										
											2020-10-08 02:37:58 +03:00
										 |  |  | JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_touch__IIII_3F(JNIEnv *env, jclass clazz, jint input_device, jint ev, jint pointer, jint pointer_count, jfloatArray position) { | 
					
						
							|  |  |  | 	touch_preprocessing(env, clazz, input_device, ev, pointer, pointer_count, position); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-08-04 21:22:11 +02:00
										 |  |  | // Called on the UI thread
 | 
					
						
							| 
									
										
										
										
											2020-10-08 02:37:58 +03:00
										 |  |  | JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_touch__IIII_3FI(JNIEnv *env, jclass clazz, jint input_device, jint ev, jint pointer, jint pointer_count, jfloatArray position, jint buttons_mask) { | 
					
						
							|  |  |  | 	touch_preprocessing(env, clazz, input_device, ev, pointer, pointer_count, position, buttons_mask); | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-08-04 21:22:11 +02:00
										 |  |  | // Called on the UI thread
 | 
					
						
							| 
									
										
										
										
											2020-10-08 02:37:58 +03:00
										 |  |  | JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_touch__IIII_3FIFF(JNIEnv *env, jclass clazz, jint input_device, jint ev, jint pointer, jint pointer_count, jfloatArray position, jint buttons_mask, jfloat vertical_factor, jfloat horizontal_factor) { | 
					
						
							|  |  |  | 	touch_preprocessing(env, clazz, input_device, ev, pointer, pointer_count, position, buttons_mask, vertical_factor, horizontal_factor); | 
					
						
							| 
									
										
										
										
											2018-08-29 17:06:48 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-08-04 21:22:11 +02:00
										 |  |  | // Called on the UI thread
 | 
					
						
							| 
									
										
										
										
											2020-10-08 02:37:58 +03:00
										 |  |  | JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_hover(JNIEnv *env, jclass clazz, jint p_type, jfloat p_x, jfloat p_y) { | 
					
						
							| 
									
										
										
										
											2022-02-16 13:56:32 +01:00
										 |  |  | 	if (step.get() <= 0) { | 
					
						
							| 
									
										
										
										
											2018-08-29 17:06:48 +02:00
										 |  |  | 		return; | 
					
						
							| 
									
										
										
										
											2022-02-16 13:56:32 +01:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2018-08-29 17:06:48 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-08-04 21:22:11 +02:00
										 |  |  | 	input_handler->process_hover(p_type, Point2(p_x, p_y)); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-08-04 21:22:11 +02:00
										 |  |  | // Called on the UI thread
 | 
					
						
							| 
									
										
										
										
											2020-10-08 02:37:58 +03:00
										 |  |  | JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_doubleTap(JNIEnv *env, jclass clazz, jint p_button_mask, jint p_x, jint p_y) { | 
					
						
							| 
									
										
										
										
											2022-02-16 13:56:32 +01:00
										 |  |  | 	if (step.get() <= 0) { | 
					
						
							| 
									
										
										
										
											2019-11-15 00:34:50 +01:00
										 |  |  | 		return; | 
					
						
							| 
									
										
										
										
											2022-02-16 13:56:32 +01:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2019-11-15 00:34:50 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-08-04 21:22:11 +02:00
										 |  |  | 	input_handler->process_double_tap(p_button_mask, Point2(p_x, p_y)); | 
					
						
							| 
									
										
										
										
											2019-11-15 00:34:50 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-08-04 21:22:11 +02:00
										 |  |  | // Called on the UI thread
 | 
					
						
							| 
									
										
										
										
											2020-03-04 09:21:59 -08:00
										 |  |  | JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_scroll(JNIEnv *env, jclass clazz, jint p_x, jint p_y) { | 
					
						
							| 
									
										
										
										
											2022-02-16 13:56:32 +01:00
										 |  |  | 	if (step.get() <= 0) { | 
					
						
							| 
									
										
										
										
											2019-11-15 00:34:50 +01:00
										 |  |  | 		return; | 
					
						
							| 
									
										
										
										
											2022-02-16 13:56:32 +01:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2019-11-15 00:34:50 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-08-04 21:22:11 +02:00
										 |  |  | 	input_handler->process_scroll(Point2(p_x, p_y)); | 
					
						
							| 
									
										
										
										
											2019-11-15 00:34:50 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-08-04 21:22:11 +02:00
										 |  |  | // Called on the UI thread
 | 
					
						
							| 
									
										
										
										
											2020-03-04 09:21:59 -08:00
										 |  |  | JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_joybutton(JNIEnv *env, jclass clazz, jint p_device, jint p_button, jboolean p_pressed) { | 
					
						
							| 
									
										
										
										
											2022-02-16 13:56:32 +01:00
										 |  |  | 	if (step.get() <= 0) { | 
					
						
							| 
									
										
										
										
											2018-03-27 22:03:44 +07:00
										 |  |  | 		return; | 
					
						
							| 
									
										
										
										
											2022-02-16 13:56:32 +01:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2014-07-02 00:09:36 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-08-04 21:22:11 +02:00
										 |  |  | 	AndroidInputHandler::JoypadEvent jevent; | 
					
						
							| 
									
										
										
										
											2016-01-24 05:11:59 +01:00
										 |  |  | 	jevent.device = p_device; | 
					
						
							| 
									
										
										
										
											2021-08-04 21:22:11 +02:00
										 |  |  | 	jevent.type = AndroidInputHandler::JOY_EVENT_BUTTON; | 
					
						
							| 
									
										
										
										
											2016-01-24 05:11:59 +01:00
										 |  |  | 	jevent.index = p_button; | 
					
						
							| 
									
										
										
										
											2017-06-06 22:29:19 -05:00
										 |  |  | 	jevent.pressed = p_pressed; | 
					
						
							| 
									
										
										
										
											2014-07-02 00:09:36 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-08-04 21:22:11 +02:00
										 |  |  | 	input_handler->process_joy_event(jevent); | 
					
						
							| 
									
										
										
										
											2016-07-21 12:07:01 +02:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2014-07-02 00:09:36 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-08-04 21:22:11 +02:00
										 |  |  | // Called on the UI thread
 | 
					
						
							| 
									
										
										
										
											2020-03-04 09:21:59 -08:00
										 |  |  | JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_joyaxis(JNIEnv *env, jclass clazz, jint p_device, jint p_axis, jfloat p_value) { | 
					
						
							| 
									
										
										
										
											2021-08-13 16:31:57 -05:00
										 |  |  | 	if (step.get() <= 0) { | 
					
						
							| 
									
										
										
										
											2018-03-27 22:03:44 +07:00
										 |  |  | 		return; | 
					
						
							| 
									
										
										
										
											2021-08-13 16:31:57 -05:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2014-07-02 00:09:36 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-08-04 21:22:11 +02:00
										 |  |  | 	AndroidInputHandler::JoypadEvent jevent; | 
					
						
							| 
									
										
										
										
											2016-01-24 05:11:59 +01:00
										 |  |  | 	jevent.device = p_device; | 
					
						
							| 
									
										
										
										
											2021-08-04 21:22:11 +02:00
										 |  |  | 	jevent.type = AndroidInputHandler::JOY_EVENT_AXIS; | 
					
						
							| 
									
										
										
										
											2016-01-24 05:11:59 +01:00
										 |  |  | 	jevent.index = p_axis; | 
					
						
							|  |  |  | 	jevent.value = p_value; | 
					
						
							| 
									
										
										
										
											2014-07-02 00:09:36 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-08-04 21:22:11 +02:00
										 |  |  | 	input_handler->process_joy_event(jevent); | 
					
						
							| 
									
										
										
										
											2016-07-21 12:07:01 +02:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2014-07-02 00:09:36 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-08-04 21:22:11 +02:00
										 |  |  | // Called on the UI thread
 | 
					
						
							| 
									
										
										
										
											2020-03-04 09:21:59 -08:00
										 |  |  | JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_joyhat(JNIEnv *env, jclass clazz, jint p_device, jint p_hat_x, jint p_hat_y) { | 
					
						
							| 
									
										
										
										
											2021-08-13 16:31:57 -05:00
										 |  |  | 	if (step.get() <= 0) { | 
					
						
							| 
									
										
										
										
											2018-03-27 22:03:44 +07:00
										 |  |  | 		return; | 
					
						
							| 
									
										
										
										
											2021-08-13 16:31:57 -05:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2018-03-27 22:03:44 +07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-08-04 21:22:11 +02:00
										 |  |  | 	AndroidInputHandler::JoypadEvent jevent; | 
					
						
							| 
									
										
										
										
											2016-01-24 05:11:59 +01:00
										 |  |  | 	jevent.device = p_device; | 
					
						
							| 
									
										
										
										
											2021-08-04 21:22:11 +02:00
										 |  |  | 	jevent.type = AndroidInputHandler::JOY_EVENT_HAT; | 
					
						
							| 
									
										
										
										
											2021-08-13 16:31:57 -05:00
										 |  |  | 	HatMask hat = HatMask::CENTER; | 
					
						
							| 
									
										
										
										
											2016-01-24 05:11:59 +01:00
										 |  |  | 	if (p_hat_x != 0) { | 
					
						
							| 
									
										
										
										
											2021-08-13 16:31:57 -05:00
										 |  |  | 		if (p_hat_x < 0) { | 
					
						
							|  |  |  | 			hat |= HatMask::LEFT; | 
					
						
							|  |  |  | 		} else { | 
					
						
							|  |  |  | 			hat |= HatMask::RIGHT; | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2016-01-24 05:11:59 +01:00
										 |  |  | 	} | 
					
						
							|  |  |  | 	if (p_hat_y != 0) { | 
					
						
							| 
									
										
										
										
											2021-08-13 16:31:57 -05:00
										 |  |  | 		if (p_hat_y < 0) { | 
					
						
							|  |  |  | 			hat |= HatMask::UP; | 
					
						
							|  |  |  | 		} else { | 
					
						
							|  |  |  | 			hat |= HatMask::DOWN; | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2016-01-24 05:11:59 +01:00
										 |  |  | 	} | 
					
						
							|  |  |  | 	jevent.hat = hat; | 
					
						
							| 
									
										
										
										
											2017-10-02 16:40:16 +07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-08-04 21:22:11 +02:00
										 |  |  | 	input_handler->process_joy_event(jevent); | 
					
						
							| 
									
										
										
										
											2016-01-24 05:11:59 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-08-04 21:22:11 +02:00
										 |  |  | // Called on the UI thread
 | 
					
						
							| 
									
										
										
										
											2020-03-04 09:21:59 -08:00
										 |  |  | JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_joyconnectionchanged(JNIEnv *env, jclass clazz, jint p_device, jboolean p_connected, jstring p_name) { | 
					
						
							| 
									
										
										
										
											2016-01-24 05:11:59 +01:00
										 |  |  | 	if (os_android) { | 
					
						
							| 
									
										
										
										
											2019-02-26 23:54:45 +03:00
										 |  |  | 		String name = jstring_to_string(p_name, env); | 
					
						
							| 
									
										
										
										
											2020-04-28 15:19:37 +02:00
										 |  |  | 		Input::get_singleton()->joy_connection_changed(p_device, p_connected, name); | 
					
						
							| 
									
										
										
										
											2016-01-24 05:11:59 +01:00
										 |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2014-07-02 00:09:36 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-08-04 21:22:11 +02:00
										 |  |  | // Called on the UI thread
 | 
					
						
							| 
									
										
										
										
											2020-03-04 09:21:59 -08:00
										 |  |  | JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_key(JNIEnv *env, jclass clazz, jint p_keycode, jint p_scancode, jint p_unicode_char, jboolean p_pressed) { | 
					
						
							| 
									
										
										
										
											2022-02-16 13:56:32 +01:00
										 |  |  | 	if (step.get() <= 0) { | 
					
						
							| 
									
										
										
										
											2018-03-27 22:03:44 +07:00
										 |  |  | 		return; | 
					
						
							| 
									
										
										
										
											2022-02-16 13:56:32 +01:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-08-04 21:22:11 +02:00
										 |  |  | 	input_handler->process_key_event(p_keycode, p_scancode, p_unicode_char, p_pressed); | 
					
						
							| 
									
										
										
										
											2016-07-21 12:07:01 +02:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-04 09:21:59 -08:00
										 |  |  | JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_accelerometer(JNIEnv *env, jclass clazz, jfloat x, jfloat y, jfloat z) { | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	accelerometer = Vector3(x, y, z); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-04 09:21:59 -08:00
										 |  |  | JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_gravity(JNIEnv *env, jclass clazz, jfloat x, jfloat y, jfloat z) { | 
					
						
							| 
									
										
										
										
											2017-11-11 09:42:23 +11:00
										 |  |  | 	gravity = Vector3(x, y, z); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-04 09:21:59 -08:00
										 |  |  | JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_magnetometer(JNIEnv *env, jclass clazz, jfloat x, jfloat y, jfloat z) { | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	magnetometer = Vector3(x, y, z); | 
					
						
							| 
									
										
										
										
											2016-05-27 14:29:37 -03:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-04 09:21:59 -08:00
										 |  |  | JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_gyroscope(JNIEnv *env, jclass clazz, jfloat x, jfloat y, jfloat z) { | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	gyroscope = Vector3(x, y, z); | 
					
						
							| 
									
										
										
										
											2016-07-15 15:31:34 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-04 09:21:59 -08:00
										 |  |  | JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_focusin(JNIEnv *env, jclass clazz) { | 
					
						
							| 
									
										
										
										
											2022-02-16 13:56:32 +01:00
										 |  |  | 	if (step.get() <= 0) { | 
					
						
							| 
									
										
										
										
											2018-03-27 22:03:44 +07:00
										 |  |  | 		return; | 
					
						
							| 
									
										
										
										
											2022-02-16 13:56:32 +01:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2018-03-27 22:03:44 +07:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	os_android->main_loop_focusin(); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-04 09:21:59 -08:00
										 |  |  | JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_focusout(JNIEnv *env, jclass clazz) { | 
					
						
							| 
									
										
										
										
											2022-02-16 13:56:32 +01:00
										 |  |  | 	if (step.get() <= 0) { | 
					
						
							| 
									
										
										
										
											2018-03-27 22:03:44 +07:00
										 |  |  | 		return; | 
					
						
							| 
									
										
										
										
											2022-02-16 13:56:32 +01:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2018-03-27 22:03:44 +07:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	os_android->main_loop_focusout(); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-04 09:21:59 -08:00
										 |  |  | JNIEXPORT jstring JNICALL Java_org_godotengine_godot_GodotLib_getGlobal(JNIEnv *env, jclass clazz, jstring path) { | 
					
						
							| 
									
										
										
										
											2019-02-26 23:54:45 +03:00
										 |  |  | 	String js = jstring_to_string(path, env); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-07-19 17:00:46 -03:00
										 |  |  | 	return env->NewStringUTF(ProjectSettings::get_singleton()->get(js).operator String().utf8().get_data()); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-05-24 13:26:18 +02:00
										 |  |  | JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_callobject(JNIEnv *env, jclass clazz, jlong ID, jstring method, jobjectArray params) { | 
					
						
							|  |  |  | 	Object *obj = ObjectDB::get_instance(ObjectID(ID)); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 	ERR_FAIL_COND(!obj); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-05-18 12:45:53 -03:00
										 |  |  | 	int res = env->PushLocalFrame(16); | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	ERR_FAIL_COND(res != 0); | 
					
						
							| 
									
										
										
										
											2015-05-18 12:45:53 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-02-26 23:54:45 +03:00
										 |  |  | 	String str_method = jstring_to_string(method, env); | 
					
						
							| 
									
										
										
										
											2015-05-18 12:45:53 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 	int count = env->GetArrayLength(params); | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	Variant *vlist = (Variant *)alloca(sizeof(Variant) * count); | 
					
						
							|  |  |  | 	Variant **vptr = (Variant **)alloca(sizeof(Variant *) * count); | 
					
						
							|  |  |  | 	for (int i = 0; i < count; i++) { | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 		jobject obj = env->GetObjectArrayElement(params, i); | 
					
						
							| 
									
										
										
										
											2014-08-01 22:10:38 -03:00
										 |  |  | 		Variant v; | 
					
						
							| 
									
										
										
										
											2022-02-16 13:56:32 +01:00
										 |  |  | 		if (obj) { | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 			v = _jobject_to_variant(env, obj); | 
					
						
							| 
									
										
										
										
											2022-02-16 13:56:32 +01:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 		memnew_placement(&vlist[i], Variant); | 
					
						
							|  |  |  | 		vlist[i] = v; | 
					
						
							|  |  |  | 		vptr[i] = &vlist[i]; | 
					
						
							| 
									
										
										
										
											2015-03-03 14:39:13 -03:00
										 |  |  | 		env->DeleteLocalRef(obj); | 
					
						
							| 
									
										
										
										
											2022-02-16 13:56:32 +01:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-02-19 16:27:19 -03:00
										 |  |  | 	Callable::CallError err; | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	obj->call(str_method, (const Variant **)vptr, count, err); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 	// something
 | 
					
						
							| 
									
										
										
										
											2015-05-18 12:45:53 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-04-02 01:20:12 +02:00
										 |  |  | 	env->PopLocalFrame(nullptr); | 
					
						
							| 
									
										
										
										
											2016-07-21 12:07:01 +02:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-05-24 13:26:18 +02:00
										 |  |  | JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_calldeferred(JNIEnv *env, jclass clazz, jlong ID, jstring method, jobjectArray params) { | 
					
						
							|  |  |  | 	Object *obj = ObjectDB::get_instance(ObjectID(ID)); | 
					
						
							| 
									
										
										
										
											2014-02-13 18:03:28 -03:00
										 |  |  | 	ERR_FAIL_COND(!obj); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-05-18 12:45:53 -03:00
										 |  |  | 	int res = env->PushLocalFrame(16); | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	ERR_FAIL_COND(res != 0); | 
					
						
							| 
									
										
										
										
											2015-05-18 12:45:53 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-02-26 23:54:45 +03:00
										 |  |  | 	String str_method = jstring_to_string(method, env); | 
					
						
							| 
									
										
										
										
											2015-05-18 12:45:53 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-02-13 18:03:28 -03:00
										 |  |  | 	int count = env->GetArrayLength(params); | 
					
						
							|  |  |  | 	Variant args[VARIANT_ARG_MAX]; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	for (int i = 0; i < MIN(count, VARIANT_ARG_MAX); i++) { | 
					
						
							| 
									
										
										
										
											2014-02-13 18:03:28 -03:00
										 |  |  | 		jobject obj = env->GetObjectArrayElement(params, i); | 
					
						
							| 
									
										
										
										
											2022-02-16 13:56:32 +01:00
										 |  |  | 		if (obj) { | 
					
						
							| 
									
										
										
										
											2014-08-01 22:10:38 -03:00
										 |  |  | 			args[i] = _jobject_to_variant(env, obj); | 
					
						
							| 
									
										
										
										
											2022-02-16 13:56:32 +01:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2015-03-03 14:39:13 -03:00
										 |  |  | 		env->DeleteLocalRef(obj); | 
					
						
							| 
									
										
										
										
											2022-02-16 13:56:32 +01:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2014-02-13 18:03:28 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-07-06 17:07:16 +02:00
										 |  |  | 	static_assert(VARIANT_ARG_MAX == 8, "This code needs to be updated if VARIANT_ARG_MAX != 8"); | 
					
						
							|  |  |  | 	obj->call_deferred(str_method, args[0], args[1], args[2], args[3], args[4], args[5], args[6], args[7]); | 
					
						
							| 
									
										
										
										
											2014-02-13 18:03:28 -03:00
										 |  |  | 	// something
 | 
					
						
							| 
									
										
										
										
											2020-04-02 01:20:12 +02:00
										 |  |  | 	env->PopLocalFrame(nullptr); | 
					
						
							| 
									
										
										
										
											2016-07-21 12:07:01 +02:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2019-03-04 23:06:37 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-04 09:21:59 -08:00
										 |  |  | JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_requestPermissionResult(JNIEnv *env, jclass clazz, jstring p_permission, jboolean p_result) { | 
					
						
							| 
									
										
										
										
											2019-03-04 23:06:37 -03:00
										 |  |  | 	String permission = jstring_to_string(p_permission, env); | 
					
						
							|  |  |  | 	if (permission == "android.permission.RECORD_AUDIO" && p_result) { | 
					
						
							|  |  |  | 		AudioDriver::get_singleton()->capture_start(); | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2019-10-06 21:17:44 +03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	if (os_android->get_main_loop()) { | 
					
						
							| 
									
										
										
										
											2021-07-17 18:22:52 -03:00
										 |  |  | 		os_android->get_main_loop()->emit_signal(SNAME("on_request_permissions_result"), permission, p_result == JNI_TRUE); | 
					
						
							| 
									
										
										
										
											2019-10-06 21:17:44 +03:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2019-03-04 23:06:37 -03:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2019-09-09 14:42:17 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  | JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_onRendererResumed(JNIEnv *env, jclass clazz) { | 
					
						
							| 
									
										
										
										
											2022-02-16 13:56:32 +01:00
										 |  |  | 	if (step.get() <= 0) { | 
					
						
							| 
									
										
										
										
											2019-09-09 14:42:17 -07:00
										 |  |  | 		return; | 
					
						
							| 
									
										
										
										
											2022-02-16 13:56:32 +01:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2019-09-09 14:42:17 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	if (os_android->get_main_loop()) { | 
					
						
							| 
									
										
										
										
											2020-06-29 20:47:18 -03:00
										 |  |  | 		os_android->get_main_loop()->notification(MainLoop::NOTIFICATION_APPLICATION_RESUMED); | 
					
						
							| 
									
										
										
										
											2019-09-09 14:42:17 -07:00
										 |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_onRendererPaused(JNIEnv *env, jclass clazz) { | 
					
						
							| 
									
										
										
										
											2022-02-16 13:56:32 +01:00
										 |  |  | 	if (step.get() <= 0) { | 
					
						
							| 
									
										
										
										
											2019-09-09 14:42:17 -07:00
										 |  |  | 		return; | 
					
						
							| 
									
										
										
										
											2022-02-16 13:56:32 +01:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2019-09-09 14:42:17 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	if (os_android->get_main_loop()) { | 
					
						
							| 
									
										
										
										
											2020-06-29 20:47:18 -03:00
										 |  |  | 		os_android->get_main_loop()->notification(MainLoop::NOTIFICATION_APPLICATION_PAUSED); | 
					
						
							| 
									
										
										
										
											2019-09-09 14:42:17 -07:00
										 |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2020-03-04 09:21:59 -08:00
										 |  |  | } |