2014-02-10 01:10:30 +00:00
|
|
|
/*************************************************************************/
|
2019-03-13 12:51:55 +00:00
|
|
|
/* java_godot_lib_jni.cpp */
|
2014-02-10 01:10:30 +00:00
|
|
|
/*************************************************************************/
|
|
|
|
/* This file is part of: */
|
|
|
|
/* GODOT ENGINE */
|
2017-08-27 12:16:55 +00:00
|
|
|
/* https://godotengine.org */
|
2014-02-10 01:10:30 +00:00
|
|
|
/*************************************************************************/
|
2020-01-01 10:16:22 +00:00
|
|
|
/* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */
|
|
|
|
/* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md). */
|
2014-02-10 01:10:30 +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. */
|
|
|
|
/*************************************************************************/
|
2018-01-04 23:50:27 +00:00
|
|
|
|
2019-03-13 12:51:55 +00:00
|
|
|
#include "java_godot_lib_jni.h"
|
|
|
|
#include "java_godot_io_wrapper.h"
|
|
|
|
#include "java_godot_wrapper.h"
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
#include "android/asset_manager_jni.h"
|
2020-03-04 17:21:59 +00:00
|
|
|
#include "android_keys_utils.h"
|
2020-01-19 19:02:40 +00:00
|
|
|
#include "api/java_class_wrapper.h"
|
2014-02-10 01:10:30 +00:00
|
|
|
#include "audio_driver_jandroid.h"
|
2018-09-11 16:13:45 +00:00
|
|
|
#include "core/engine.h"
|
2020-03-01 22:14:37 +00:00
|
|
|
#include "core/input/input.h"
|
2018-09-11 16:13:45 +00:00
|
|
|
#include "core/project_settings.h"
|
2017-03-05 15:44:50 +00:00
|
|
|
#include "dir_access_jandroid.h"
|
|
|
|
#include "file_access_android.h"
|
|
|
|
#include "file_access_jandroid.h"
|
2020-03-04 17:21:59 +00:00
|
|
|
#include "jni_utils.h"
|
2017-03-05 15:44:50 +00:00
|
|
|
#include "main/main.h"
|
2019-11-25 14:01:44 +00:00
|
|
|
#include "net_socket_android.h"
|
2017-03-05 15:44:50 +00:00
|
|
|
#include "os_android.h"
|
2019-02-26 20:54:45 +00:00
|
|
|
#include "string_android.h"
|
2017-03-05 15:44:50 +00:00
|
|
|
#include "thread_jandroid.h"
|
|
|
|
#include <unistd.h>
|
2014-09-03 02:13:40 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
static JavaClassWrapper *java_class_wrapper = NULL;
|
|
|
|
static OS_Android *os_android = NULL;
|
2019-03-13 12:51:55 +00:00
|
|
|
static GodotJavaWrapper *godot_java = NULL;
|
|
|
|
static GodotIOJavaWrapper *godot_io_java = NULL;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2020-03-04 17:21:59 +00:00
|
|
|
static bool initialized = false;
|
|
|
|
static int step = 0;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2020-03-04 17:21:59 +00:00
|
|
|
static Size2 new_size;
|
|
|
|
static Vector3 accelerometer;
|
|
|
|
static Vector3 gravity;
|
|
|
|
static Vector3 magnetometer;
|
|
|
|
static Vector3 gyroscope;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2020-03-04 17:21:59 +00:00
|
|
|
extern "C" {
|
2014-03-14 01:57:24 +00:00
|
|
|
|
2020-03-04 17:21:59 +00:00
|
|
|
JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_setVirtualKeyboardHeight(JNIEnv *env, jclass clazz, jint p_height) {
|
2019-03-13 12:51:55 +00:00
|
|
|
if (godot_io_java) {
|
|
|
|
godot_io_java->set_vk_height(p_height);
|
|
|
|
}
|
2017-10-04 08:39:31 +00:00
|
|
|
}
|
|
|
|
|
2020-03-04 17:21:59 +00:00
|
|
|
JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_initialize(JNIEnv *env, jclass clazz, jobject activity, jobject p_asset_manager, jboolean p_use_apk_expansion) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
initialized = true;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
JavaVM *jvm;
|
|
|
|
env->GetJavaVM(&jvm);
|
|
|
|
|
2019-03-13 12:51:55 +00:00
|
|
|
// create our wrapper classes
|
|
|
|
godot_java = new GodotJavaWrapper(env, activity); // our activity is our godot instance is our activity..
|
|
|
|
godot_io_java = new GodotIOJavaWrapper(env, godot_java->get_member_object("io", "Lorg/godotengine/godot/GodotIO;", env));
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2019-03-13 12:51:55 +00:00
|
|
|
ThreadAndroid::make_default(jvm);
|
2015-09-04 02:24:55 +00:00
|
|
|
#ifdef USE_JAVA_FILE_ACCESS
|
2019-03-13 12:51:55 +00:00
|
|
|
FileAccessJAndroid::setup(godot_io_java->get_instance());
|
2015-09-04 02:24:55 +00:00
|
|
|
#else
|
|
|
|
|
2019-03-13 12:51:55 +00:00
|
|
|
jobject amgr = env->NewGlobalRef(p_asset_manager);
|
2015-09-04 02:24:55 +00:00
|
|
|
|
2019-03-13 12:51:55 +00:00
|
|
|
FileAccessAndroid::asset_manager = AAssetManager_fromJava(env, amgr);
|
2015-09-04 02:24:55 +00:00
|
|
|
#endif
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2019-03-13 12:51:55 +00:00
|
|
|
DirAccessJAndroid::setup(godot_io_java->get_instance());
|
|
|
|
AudioDriverAndroid::setup(godot_io_java->get_instance());
|
2019-11-25 14:01:44 +00:00
|
|
|
NetSocketAndroid::setup(godot_java->get_member_object("netUtils", "Lorg/godotengine/godot/utils/GodotNetUtils;", env));
|
2019-03-13 12:51:55 +00:00
|
|
|
|
|
|
|
os_android = new OS_Android(godot_java, godot_io_java, p_use_apk_expansion);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
char wd[500];
|
2017-03-05 15:44:50 +00:00
|
|
|
getcwd(wd, 500);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2019-03-13 12:51:55 +00:00
|
|
|
godot_java->on_video_init(env);
|
|
|
|
}
|
|
|
|
|
2020-03-04 17:21:59 +00:00
|
|
|
JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_ondestroy(JNIEnv *env, jclass clazz, jobject activity) {
|
2019-03-13 12:51:55 +00:00
|
|
|
// lets cleanup
|
|
|
|
if (godot_io_java) {
|
|
|
|
delete godot_io_java;
|
|
|
|
}
|
|
|
|
if (godot_java) {
|
|
|
|
delete godot_java;
|
|
|
|
}
|
|
|
|
if (os_android) {
|
|
|
|
delete os_android;
|
|
|
|
}
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2020-03-04 17:21:59 +00:00
|
|
|
JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_setup(JNIEnv *env, jclass clazz, jobjectArray p_cmdline) {
|
2014-02-10 01:10:30 +00:00
|
|
|
ThreadAndroid::setup_thread();
|
|
|
|
|
2017-08-18 14:17:35 +00:00
|
|
|
const char **cmdline = NULL;
|
2019-02-26 20:54:45 +00:00
|
|
|
jstring *j_cmdline = NULL;
|
2017-08-18 14:17:35 +00:00
|
|
|
int cmdlen = 0;
|
|
|
|
if (p_cmdline) {
|
|
|
|
cmdlen = env->GetArrayLength(p_cmdline);
|
|
|
|
if (cmdlen) {
|
2019-02-26 20:54:45 +00:00
|
|
|
cmdline = (const char **)malloc((cmdlen + 1) * sizeof(const char *));
|
2017-08-18 14:17:35 +00:00
|
|
|
cmdline[cmdlen] = NULL;
|
2019-02-26 20:54:45 +00:00
|
|
|
j_cmdline = (jstring *)malloc(cmdlen * sizeof(jstring));
|
2017-08-18 14:17:35 +00: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 20:54:45 +00:00
|
|
|
j_cmdline[i] = string;
|
2017-08-18 14:17:35 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Error err = Main::setup("apk", cmdlen, (char **)cmdline, false);
|
|
|
|
if (cmdline) {
|
2019-02-26 20:54:45 +00:00
|
|
|
if (j_cmdline) {
|
|
|
|
for (int i = 0; i < cmdlen; ++i) {
|
|
|
|
env->ReleaseStringUTFChars(j_cmdline[i], cmdline[i]);
|
|
|
|
}
|
|
|
|
free(j_cmdline);
|
|
|
|
}
|
2017-08-18 14:17:35 +00:00
|
|
|
free(cmdline);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (err != OK) {
|
|
|
|
return; //should exit instead and print the error
|
|
|
|
}
|
|
|
|
|
2019-03-13 12:51:55 +00:00
|
|
|
java_class_wrapper = memnew(JavaClassWrapper(godot_java->get_activity()));
|
2017-08-18 14:17:35 +00:00
|
|
|
}
|
|
|
|
|
2020-03-04 17:21:59 +00:00
|
|
|
JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_resize(JNIEnv *env, jclass clazz, jint width, jint height) {
|
2017-08-18 14:17:35 +00:00
|
|
|
|
|
|
|
if (os_android)
|
|
|
|
os_android->set_display_size(Size2(width, height));
|
|
|
|
}
|
|
|
|
|
2020-03-04 17:21:59 +00:00
|
|
|
JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_newcontext(JNIEnv *env, jclass clazz, jboolean p_32_bits) {
|
2017-08-18 14:17:35 +00:00
|
|
|
|
|
|
|
if (os_android) {
|
2019-03-05 22:29:44 +00:00
|
|
|
if (step == 0) {
|
|
|
|
// During startup
|
|
|
|
os_android->set_context_is_16_bits(!p_32_bits);
|
|
|
|
} else {
|
|
|
|
// GL context recreated because it was lost; restart app to let it reload everything
|
|
|
|
os_android->main_loop_end();
|
2019-03-13 12:51:55 +00:00
|
|
|
godot_java->restart(env);
|
2019-03-05 22:29:44 +00:00
|
|
|
step = -1; // Ensure no further steps are attempted
|
|
|
|
}
|
2017-08-18 14:17:35 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-03-04 17:21:59 +00:00
|
|
|
JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_back(JNIEnv *env, jclass clazz) {
|
2018-03-27 15:03:44 +00:00
|
|
|
if (step == 0)
|
|
|
|
return;
|
|
|
|
|
2017-10-02 09:40:16 +00:00
|
|
|
os_android->main_loop_request_go_back();
|
2017-08-18 14:17:35 +00:00
|
|
|
}
|
|
|
|
|
2020-03-04 17:21:59 +00:00
|
|
|
JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_step(JNIEnv *env, jclass clazz) {
|
2019-03-05 22:29:44 +00:00
|
|
|
if (step == -1)
|
|
|
|
return;
|
|
|
|
|
2017-08-18 14:17:35 +00:00
|
|
|
if (step == 0) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-08-22 15:21:41 +00:00
|
|
|
// Since Godot is initialized on the UI thread, _main_thread_id was set to that thread's id,
|
|
|
|
// but for Godot purposes, the main thread is the one running the game loop
|
|
|
|
Main::setup2(Thread::get_caller_id());
|
2014-02-10 01:10:30 +00:00
|
|
|
++step;
|
|
|
|
return;
|
2017-08-18 14:17:35 +00:00
|
|
|
}
|
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
if (step == 1) {
|
|
|
|
if (!Main::start()) {
|
|
|
|
return; //should exit instead and print the error
|
|
|
|
}
|
|
|
|
|
|
|
|
os_android->main_loop_begin();
|
2020-03-19 22:28:33 +00:00
|
|
|
godot_java->on_godot_main_loop_started(env);
|
2014-02-10 01:10:30 +00:00
|
|
|
++step;
|
|
|
|
}
|
|
|
|
|
|
|
|
os_android->process_accelerometer(accelerometer);
|
2017-11-10 22:42:23 +00:00
|
|
|
os_android->process_gravity(gravity);
|
2016-05-27 17:29:37 +00:00
|
|
|
os_android->process_magnetometer(magnetometer);
|
2016-07-15 07:31:34 +00:00
|
|
|
os_android->process_gyroscope(gyroscope);
|
|
|
|
|
2018-10-03 17:40:37 +00:00
|
|
|
if (os_android->main_loop_iterate()) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2019-03-13 12:51:55 +00:00
|
|
|
godot_java->force_quit(env);
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-03-04 17:21:59 +00:00
|
|
|
JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_touch(JNIEnv *env, jclass clazz, jint ev, jint pointer, jint count, jintArray positions) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2018-03-27 15:03:44 +00:00
|
|
|
if (step == 0)
|
|
|
|
return;
|
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
Vector<OS_Android::TouchPos> points;
|
2017-03-05 15:44:50 +00:00
|
|
|
for (int i = 0; i < count; i++) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
jint p[3];
|
2017-03-05 15:44:50 +00:00
|
|
|
env->GetIntArrayRegion(positions, i * 3, 3, p);
|
2014-02-10 01:10:30 +00:00
|
|
|
OS_Android::TouchPos tp;
|
2017-03-05 15:44:50 +00:00
|
|
|
tp.pos = Point2(p[1], p[2]);
|
|
|
|
tp.id = p[0];
|
2014-02-10 01:10:30 +00:00
|
|
|
points.push_back(tp);
|
|
|
|
}
|
|
|
|
|
2017-10-02 09:40:16 +00:00
|
|
|
os_android->process_touch(ev, pointer, points);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-01-14 11:26:56 +00:00
|
|
|
/*
|
|
|
|
if (os_android)
|
|
|
|
os_android->process_touch(ev,pointer,points);
|
|
|
|
*/
|
2018-08-29 15:06:48 +00:00
|
|
|
}
|
|
|
|
|
2020-03-04 17:21:59 +00:00
|
|
|
JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_hover(JNIEnv *env, jclass clazz, jint p_type, jint p_x, jint p_y) {
|
2018-08-29 15:06:48 +00:00
|
|
|
if (step == 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
os_android->process_hover(p_type, Point2(p_x, p_y));
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2020-03-04 17:21:59 +00:00
|
|
|
JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_doubletap(JNIEnv *env, jclass clazz, jint p_x, jint p_y) {
|
2019-11-14 23:34:50 +00:00
|
|
|
if (step == 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
os_android->process_double_tap(Point2(p_x, p_y));
|
|
|
|
}
|
|
|
|
|
2020-03-04 17:21:59 +00:00
|
|
|
JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_scroll(JNIEnv *env, jclass clazz, jint p_x, jint p_y) {
|
2019-11-14 23:34:50 +00:00
|
|
|
if (step == 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
os_android->process_scroll(Point2(p_x, p_y));
|
|
|
|
}
|
|
|
|
|
2020-03-04 17:21:59 +00:00
|
|
|
JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_joybutton(JNIEnv *env, jclass clazz, jint p_device, jint p_button, jboolean p_pressed) {
|
2018-03-27 15:03:44 +00:00
|
|
|
if (step == 0)
|
|
|
|
return;
|
2014-07-02 03:09:36 +00:00
|
|
|
|
2017-01-08 20:05:51 +00:00
|
|
|
OS_Android::JoypadEvent jevent;
|
2016-01-24 04:11:59 +00:00
|
|
|
jevent.device = p_device;
|
|
|
|
jevent.type = OS_Android::JOY_EVENT_BUTTON;
|
|
|
|
jevent.index = p_button;
|
2017-06-07 03:29:19 +00:00
|
|
|
jevent.pressed = p_pressed;
|
2014-07-02 03:09:36 +00:00
|
|
|
|
2017-10-02 09:40:16 +00:00
|
|
|
os_android->process_joy_event(jevent);
|
2016-07-21 10:07:01 +00:00
|
|
|
}
|
2014-07-02 03:09:36 +00:00
|
|
|
|
2020-03-04 17:21:59 +00:00
|
|
|
JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_joyaxis(JNIEnv *env, jclass clazz, jint p_device, jint p_axis, jfloat p_value) {
|
2018-03-27 15:03:44 +00:00
|
|
|
if (step == 0)
|
|
|
|
return;
|
2014-07-02 03:09:36 +00:00
|
|
|
|
2017-01-08 20:05:51 +00:00
|
|
|
OS_Android::JoypadEvent jevent;
|
2016-01-24 04:11:59 +00:00
|
|
|
jevent.device = p_device;
|
|
|
|
jevent.type = OS_Android::JOY_EVENT_AXIS;
|
|
|
|
jevent.index = p_axis;
|
|
|
|
jevent.value = p_value;
|
2014-07-02 03:09:36 +00:00
|
|
|
|
2017-10-02 09:40:16 +00:00
|
|
|
os_android->process_joy_event(jevent);
|
2016-07-21 10:07:01 +00:00
|
|
|
}
|
2014-07-02 03:09:36 +00:00
|
|
|
|
2020-03-04 17:21:59 +00: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) {
|
2018-03-27 15:03:44 +00:00
|
|
|
if (step == 0)
|
|
|
|
return;
|
|
|
|
|
2017-01-08 20:05:51 +00:00
|
|
|
OS_Android::JoypadEvent jevent;
|
2016-01-24 04:11:59 +00:00
|
|
|
jevent.device = p_device;
|
|
|
|
jevent.type = OS_Android::JOY_EVENT_HAT;
|
|
|
|
int hat = 0;
|
|
|
|
if (p_hat_x != 0) {
|
2017-03-05 15:44:50 +00:00
|
|
|
if (p_hat_x < 0)
|
|
|
|
hat |= InputDefault::HAT_MASK_LEFT;
|
|
|
|
else
|
|
|
|
hat |= InputDefault::HAT_MASK_RIGHT;
|
2016-01-24 04:11:59 +00:00
|
|
|
}
|
|
|
|
if (p_hat_y != 0) {
|
2017-03-05 15:44:50 +00:00
|
|
|
if (p_hat_y < 0)
|
|
|
|
hat |= InputDefault::HAT_MASK_UP;
|
|
|
|
else
|
|
|
|
hat |= InputDefault::HAT_MASK_DOWN;
|
2016-01-24 04:11:59 +00:00
|
|
|
}
|
|
|
|
jevent.hat = hat;
|
2017-10-02 09:40:16 +00:00
|
|
|
|
|
|
|
os_android->process_joy_event(jevent);
|
2016-01-24 04:11:59 +00:00
|
|
|
}
|
|
|
|
|
2020-03-04 17:21:59 +00: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 04:11:59 +00:00
|
|
|
if (os_android) {
|
2019-02-26 20:54:45 +00:00
|
|
|
String name = jstring_to_string(p_name, env);
|
2016-01-24 04:11:59 +00:00
|
|
|
os_android->joy_connection_changed(p_device, p_connected, name);
|
|
|
|
}
|
|
|
|
}
|
2014-07-02 03:09:36 +00:00
|
|
|
|
2020-03-04 17:21:59 +00: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) {
|
2018-03-27 15:03:44 +00:00
|
|
|
if (step == 0)
|
|
|
|
return;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-05-20 15:38:03 +00:00
|
|
|
Ref<InputEventKey> ievent;
|
2017-10-02 09:40:16 +00:00
|
|
|
ievent.instance();
|
2014-02-10 01:10:30 +00:00
|
|
|
int val = p_unicode_char;
|
2018-04-05 17:59:35 +00:00
|
|
|
int keycode = android_get_keysym(p_keycode);
|
|
|
|
int phy_keycode = android_get_keysym(p_scancode);
|
|
|
|
ievent->set_keycode(keycode);
|
|
|
|
ievent->set_physical_keycode(phy_keycode);
|
2017-05-20 15:38:03 +00:00
|
|
|
ievent->set_unicode(val);
|
|
|
|
ievent->set_pressed(p_pressed);
|
2014-03-12 12:41:09 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
if (val == '\n') {
|
2018-04-05 17:59:35 +00:00
|
|
|
ievent->set_keycode(KEY_ENTER);
|
2017-03-05 15:44:50 +00:00
|
|
|
} else if (val == 61448) {
|
2018-04-05 17:59:35 +00:00
|
|
|
ievent->set_keycode(KEY_BACKSPACE);
|
2017-05-20 15:38:03 +00:00
|
|
|
ievent->set_unicode(KEY_BACKSPACE);
|
2014-03-13 10:31:30 +00:00
|
|
|
} else if (val == 61453) {
|
2018-04-05 17:59:35 +00:00
|
|
|
ievent->set_keycode(KEY_ENTER);
|
2017-05-20 15:38:03 +00:00
|
|
|
ievent->set_unicode(KEY_ENTER);
|
2018-04-05 17:59:35 +00:00
|
|
|
} else if (p_keycode == 4) {
|
2017-10-02 09:40:16 +00:00
|
|
|
os_android->main_loop_request_go_back();
|
2017-03-05 15:44:50 +00:00
|
|
|
}
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-10-02 09:40:16 +00:00
|
|
|
os_android->process_event(ievent);
|
2016-07-21 10:07:01 +00:00
|
|
|
}
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2020-03-04 17:21:59 +00:00
|
|
|
JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_accelerometer(JNIEnv *env, jclass clazz, jfloat x, jfloat y, jfloat z) {
|
2017-03-05 15:44:50 +00:00
|
|
|
accelerometer = Vector3(x, y, z);
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2020-03-04 17:21:59 +00:00
|
|
|
JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_gravity(JNIEnv *env, jclass clazz, jfloat x, jfloat y, jfloat z) {
|
2017-11-10 22:42:23 +00:00
|
|
|
gravity = Vector3(x, y, z);
|
|
|
|
}
|
|
|
|
|
2020-03-04 17:21:59 +00:00
|
|
|
JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_magnetometer(JNIEnv *env, jclass clazz, jfloat x, jfloat y, jfloat z) {
|
2017-03-05 15:44:50 +00:00
|
|
|
magnetometer = Vector3(x, y, z);
|
2016-05-27 17:29:37 +00:00
|
|
|
}
|
|
|
|
|
2020-03-04 17:21:59 +00:00
|
|
|
JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_gyroscope(JNIEnv *env, jclass clazz, jfloat x, jfloat y, jfloat z) {
|
2017-03-05 15:44:50 +00:00
|
|
|
gyroscope = Vector3(x, y, z);
|
2016-07-15 07:31:34 +00:00
|
|
|
}
|
|
|
|
|
2020-03-04 17:21:59 +00:00
|
|
|
JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_focusin(JNIEnv *env, jclass clazz) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2018-03-27 15:03:44 +00:00
|
|
|
if (step == 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
os_android->main_loop_focusin();
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2020-03-04 17:21:59 +00:00
|
|
|
JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_focusout(JNIEnv *env, jclass clazz) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2018-03-27 15:03:44 +00:00
|
|
|
if (step == 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
os_android->main_loop_focusout();
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2020-03-04 17:21:59 +00:00
|
|
|
JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_audio(JNIEnv *env, jclass clazz) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
ThreadAndroid::setup_thread();
|
|
|
|
AudioDriverAndroid::thread_func(env);
|
|
|
|
}
|
|
|
|
|
2020-03-04 17:21:59 +00:00
|
|
|
JNIEXPORT jstring JNICALL Java_org_godotengine_godot_GodotLib_getGlobal(JNIEnv *env, jclass clazz, jstring path) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2019-02-26 20:54:45 +00:00
|
|
|
String js = jstring_to_string(path, env);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-07-19 20:00:46 +00:00
|
|
|
return env->NewStringUTF(ProjectSettings::get_singleton()->get(js).operator String().utf8().get_data());
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2020-03-04 17:21:59 +00:00
|
|
|
JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_callobject(JNIEnv *env, jclass clazz, jint ID, jstring method, jobjectArray params) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2020-02-29 18:40:24 +00:00
|
|
|
Object *obj = ObjectDB::get_instance(ObjectID((uint64_t)ID));
|
2014-02-10 01:10:30 +00:00
|
|
|
ERR_FAIL_COND(!obj);
|
|
|
|
|
2015-05-18 15:45:53 +00:00
|
|
|
int res = env->PushLocalFrame(16);
|
2017-03-05 15:44:50 +00:00
|
|
|
ERR_FAIL_COND(res != 0);
|
2015-05-18 15:45:53 +00:00
|
|
|
|
2019-02-26 20:54:45 +00:00
|
|
|
String str_method = jstring_to_string(method, env);
|
2015-05-18 15:45:53 +00:00
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
int count = env->GetArrayLength(params);
|
2017-03-05 15:44:50 +00:00
|
|
|
Variant *vlist = (Variant *)alloca(sizeof(Variant) * count);
|
|
|
|
Variant **vptr = (Variant **)alloca(sizeof(Variant *) * count);
|
|
|
|
for (int i = 0; i < count; i++) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
jobject obj = env->GetObjectArrayElement(params, i);
|
2014-08-02 01:10:38 +00:00
|
|
|
Variant v;
|
|
|
|
if (obj)
|
2017-03-05 15:44:50 +00:00
|
|
|
v = _jobject_to_variant(env, obj);
|
2014-02-10 01:10:30 +00:00
|
|
|
memnew_placement(&vlist[i], Variant);
|
|
|
|
vlist[i] = v;
|
|
|
|
vptr[i] = &vlist[i];
|
2015-03-03 17:39:13 +00:00
|
|
|
env->DeleteLocalRef(obj);
|
2014-02-10 01:10:30 +00:00
|
|
|
};
|
|
|
|
|
2020-02-19 19:27:19 +00:00
|
|
|
Callable::CallError err;
|
2017-03-05 15:44:50 +00:00
|
|
|
obj->call(str_method, (const Variant **)vptr, count, err);
|
2014-02-10 01:10:30 +00:00
|
|
|
// something
|
2015-05-18 15:45:53 +00:00
|
|
|
|
|
|
|
env->PopLocalFrame(NULL);
|
2016-07-21 10:07:01 +00:00
|
|
|
}
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2020-03-04 17:21:59 +00:00
|
|
|
JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_calldeferred(JNIEnv *env, jclass clazz, jint ID, jstring method, jobjectArray params) {
|
2014-02-13 21:03:28 +00:00
|
|
|
|
2020-02-29 18:40:24 +00:00
|
|
|
Object *obj = ObjectDB::get_instance(ObjectID((uint64_t)ID));
|
2014-02-13 21:03:28 +00:00
|
|
|
ERR_FAIL_COND(!obj);
|
|
|
|
|
2015-05-18 15:45:53 +00:00
|
|
|
int res = env->PushLocalFrame(16);
|
2017-03-05 15:44:50 +00:00
|
|
|
ERR_FAIL_COND(res != 0);
|
2015-05-18 15:45:53 +00:00
|
|
|
|
2019-02-26 20:54:45 +00:00
|
|
|
String str_method = jstring_to_string(method, env);
|
2015-05-18 15:45:53 +00:00
|
|
|
|
2014-02-13 21:03:28 +00:00
|
|
|
int count = env->GetArrayLength(params);
|
|
|
|
Variant args[VARIANT_ARG_MAX];
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
for (int i = 0; i < MIN(count, VARIANT_ARG_MAX); i++) {
|
2014-02-13 21:03:28 +00:00
|
|
|
|
|
|
|
jobject obj = env->GetObjectArrayElement(params, i);
|
2014-08-02 01:10:38 +00:00
|
|
|
if (obj)
|
|
|
|
args[i] = _jobject_to_variant(env, obj);
|
2015-03-03 17:39:13 +00:00
|
|
|
env->DeleteLocalRef(obj);
|
2014-02-13 21:03:28 +00:00
|
|
|
};
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
obj->call_deferred(str_method, args[0], args[1], args[2], args[3], args[4]);
|
2014-02-13 21:03:28 +00:00
|
|
|
// something
|
2015-05-18 15:45:53 +00:00
|
|
|
env->PopLocalFrame(NULL);
|
2016-07-21 10:07:01 +00:00
|
|
|
}
|
2019-03-05 02:06:37 +00:00
|
|
|
|
2020-03-04 17:21:59 +00:00
|
|
|
JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_requestPermissionResult(JNIEnv *env, jclass clazz, jstring p_permission, jboolean p_result) {
|
2019-03-05 02:06:37 +00: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 18:17:44 +00:00
|
|
|
|
|
|
|
if (os_android->get_main_loop()) {
|
|
|
|
os_android->get_main_loop()->emit_signal("on_request_permissions_result", permission, p_result == JNI_TRUE);
|
|
|
|
}
|
2019-03-05 02:06:37 +00:00
|
|
|
}
|
2019-09-09 21:42:17 +00:00
|
|
|
|
|
|
|
JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_onRendererResumed(JNIEnv *env, jclass clazz) {
|
|
|
|
if (step == 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (os_android->get_main_loop()) {
|
|
|
|
os_android->get_main_loop()->notification(MainLoop::NOTIFICATION_APP_RESUMED);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_onRendererPaused(JNIEnv *env, jclass clazz) {
|
|
|
|
if (step == 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (os_android->get_main_loop()) {
|
|
|
|
os_android->get_main_loop()->notification(MainLoop::NOTIFICATION_APP_PAUSED);
|
|
|
|
}
|
|
|
|
}
|
2020-03-04 17:21:59 +00:00
|
|
|
}
|