Merge pull request #37300 from m4gr3d/android_codebase_misc_cleanup_3.2
[3.2] Miscellaneous cleanup for the Android codebase
This commit is contained in:
commit
abb70a6165
|
@ -16,6 +16,7 @@ android_files = [
|
|||
'java_godot_wrapper.cpp',
|
||||
'java_godot_io_wrapper.cpp',
|
||||
'jni_utils.cpp',
|
||||
'android_keys_utils.cpp',
|
||||
'plugin/godot_plugin_jni.cpp',
|
||||
#'power_android.cpp'
|
||||
]
|
||||
|
|
|
@ -0,0 +1,43 @@
|
|||
/*************************************************************************/
|
||||
/* android_keys_utils.cpp */
|
||||
/*************************************************************************/
|
||||
/* This file is part of: */
|
||||
/* GODOT ENGINE */
|
||||
/* https://godotengine.org */
|
||||
/*************************************************************************/
|
||||
/* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */
|
||||
/* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md). */
|
||||
/* */
|
||||
/* Permission is hereby granted, free of charge, to any person obtaining */
|
||||
/* a copy of this software and associated documentation files (the */
|
||||
/* "Software"), to deal in the Software without restriction, including */
|
||||
/* without limitation the rights to use, copy, modify, merge, publish, */
|
||||
/* distribute, sublicense, and/or sell copies of the Software, and to */
|
||||
/* permit persons to whom the Software is furnished to do so, subject to */
|
||||
/* the following conditions: */
|
||||
/* */
|
||||
/* The above copyright notice and this permission notice shall be */
|
||||
/* included in all copies or substantial portions of the Software. */
|
||||
/* */
|
||||
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
|
||||
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
|
||||
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
|
||||
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
|
||||
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
|
||||
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
|
||||
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
||||
/*************************************************************************/
|
||||
|
||||
#include "android_keys_utils.h"
|
||||
|
||||
unsigned int android_get_keysym(unsigned int p_code) {
|
||||
for (int i = 0; _ak_to_keycode[i].keysym != KEY_UNKNOWN; i++) {
|
||||
|
||||
if (_ak_to_keycode[i].keycode == p_code) {
|
||||
|
||||
return _ak_to_keycode[i].keysym;
|
||||
}
|
||||
}
|
||||
|
||||
return KEY_UNKNOWN;
|
||||
}
|
|
@ -0,0 +1,280 @@
|
|||
/*************************************************************************/
|
||||
/* android_keys_utils.h */
|
||||
/*************************************************************************/
|
||||
/* This file is part of: */
|
||||
/* GODOT ENGINE */
|
||||
/* https://godotengine.org */
|
||||
/*************************************************************************/
|
||||
/* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */
|
||||
/* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md). */
|
||||
/* */
|
||||
/* 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. */
|
||||
/*************************************************************************/
|
||||
|
||||
#ifndef ANDROID_KEYS_UTILS_H
|
||||
#define ANDROID_KEYS_UTILS_H
|
||||
|
||||
#include <core/os/keyboard.h>
|
||||
|
||||
/*
|
||||
* Android Key codes.
|
||||
*/
|
||||
enum {
|
||||
AKEYCODE_UNKNOWN = 0,
|
||||
AKEYCODE_SOFT_LEFT = 1,
|
||||
AKEYCODE_SOFT_RIGHT = 2,
|
||||
AKEYCODE_HOME = 3,
|
||||
AKEYCODE_BACK = 4,
|
||||
AKEYCODE_CALL = 5,
|
||||
AKEYCODE_ENDCALL = 6,
|
||||
AKEYCODE_0 = 7,
|
||||
AKEYCODE_1 = 8,
|
||||
AKEYCODE_2 = 9,
|
||||
AKEYCODE_3 = 10,
|
||||
AKEYCODE_4 = 11,
|
||||
AKEYCODE_5 = 12,
|
||||
AKEYCODE_6 = 13,
|
||||
AKEYCODE_7 = 14,
|
||||
AKEYCODE_8 = 15,
|
||||
AKEYCODE_9 = 16,
|
||||
AKEYCODE_STAR = 17,
|
||||
AKEYCODE_POUND = 18,
|
||||
AKEYCODE_DPAD_UP = 19,
|
||||
AKEYCODE_DPAD_DOWN = 20,
|
||||
AKEYCODE_DPAD_LEFT = 21,
|
||||
AKEYCODE_DPAD_RIGHT = 22,
|
||||
AKEYCODE_DPAD_CENTER = 23,
|
||||
AKEYCODE_VOLUME_UP = 24,
|
||||
AKEYCODE_VOLUME_DOWN = 25,
|
||||
AKEYCODE_POWER = 26,
|
||||
AKEYCODE_CAMERA = 27,
|
||||
AKEYCODE_CLEAR = 28,
|
||||
AKEYCODE_A = 29,
|
||||
AKEYCODE_B = 30,
|
||||
AKEYCODE_C = 31,
|
||||
AKEYCODE_D = 32,
|
||||
AKEYCODE_E = 33,
|
||||
AKEYCODE_F = 34,
|
||||
AKEYCODE_G = 35,
|
||||
AKEYCODE_H = 36,
|
||||
AKEYCODE_I = 37,
|
||||
AKEYCODE_J = 38,
|
||||
AKEYCODE_K = 39,
|
||||
AKEYCODE_L = 40,
|
||||
AKEYCODE_M = 41,
|
||||
AKEYCODE_N = 42,
|
||||
AKEYCODE_O = 43,
|
||||
AKEYCODE_P = 44,
|
||||
AKEYCODE_Q = 45,
|
||||
AKEYCODE_R = 46,
|
||||
AKEYCODE_S = 47,
|
||||
AKEYCODE_T = 48,
|
||||
AKEYCODE_U = 49,
|
||||
AKEYCODE_V = 50,
|
||||
AKEYCODE_W = 51,
|
||||
AKEYCODE_X = 52,
|
||||
AKEYCODE_Y = 53,
|
||||
AKEYCODE_Z = 54,
|
||||
AKEYCODE_COMMA = 55,
|
||||
AKEYCODE_PERIOD = 56,
|
||||
AKEYCODE_ALT_LEFT = 57,
|
||||
AKEYCODE_ALT_RIGHT = 58,
|
||||
AKEYCODE_SHIFT_LEFT = 59,
|
||||
AKEYCODE_SHIFT_RIGHT = 60,
|
||||
AKEYCODE_TAB = 61,
|
||||
AKEYCODE_SPACE = 62,
|
||||
AKEYCODE_SYM = 63,
|
||||
AKEYCODE_EXPLORER = 64,
|
||||
AKEYCODE_ENVELOPE = 65,
|
||||
AKEYCODE_ENTER = 66,
|
||||
AKEYCODE_DEL = 67,
|
||||
AKEYCODE_GRAVE = 68,
|
||||
AKEYCODE_MINUS = 69,
|
||||
AKEYCODE_EQUALS = 70,
|
||||
AKEYCODE_LEFT_BRACKET = 71,
|
||||
AKEYCODE_RIGHT_BRACKET = 72,
|
||||
AKEYCODE_BACKSLASH = 73,
|
||||
AKEYCODE_SEMICOLON = 74,
|
||||
AKEYCODE_APOSTROPHE = 75,
|
||||
AKEYCODE_SLASH = 76,
|
||||
AKEYCODE_AT = 77,
|
||||
AKEYCODE_NUM = 78,
|
||||
AKEYCODE_HEADSETHOOK = 79,
|
||||
AKEYCODE_FOCUS = 80, // *Camera* focus
|
||||
AKEYCODE_PLUS = 81,
|
||||
AKEYCODE_MENU = 82,
|
||||
AKEYCODE_NOTIFICATION = 83,
|
||||
AKEYCODE_SEARCH = 84,
|
||||
AKEYCODE_MEDIA_PLAY_PAUSE = 85,
|
||||
AKEYCODE_MEDIA_STOP = 86,
|
||||
AKEYCODE_MEDIA_NEXT = 87,
|
||||
AKEYCODE_MEDIA_PREVIOUS = 88,
|
||||
AKEYCODE_MEDIA_REWIND = 89,
|
||||
AKEYCODE_MEDIA_FAST_FORWARD = 90,
|
||||
AKEYCODE_MUTE = 91,
|
||||
AKEYCODE_PAGE_UP = 92,
|
||||
AKEYCODE_PAGE_DOWN = 93,
|
||||
AKEYCODE_PICTSYMBOLS = 94,
|
||||
AKEYCODE_SWITCH_CHARSET = 95,
|
||||
AKEYCODE_BUTTON_A = 96,
|
||||
AKEYCODE_BUTTON_B = 97,
|
||||
AKEYCODE_BUTTON_C = 98,
|
||||
AKEYCODE_BUTTON_X = 99,
|
||||
AKEYCODE_BUTTON_Y = 100,
|
||||
AKEYCODE_BUTTON_Z = 101,
|
||||
AKEYCODE_BUTTON_L1 = 102,
|
||||
AKEYCODE_BUTTON_R1 = 103,
|
||||
AKEYCODE_BUTTON_L2 = 104,
|
||||
AKEYCODE_BUTTON_R2 = 105,
|
||||
AKEYCODE_BUTTON_THUMBL = 106,
|
||||
AKEYCODE_BUTTON_THUMBR = 107,
|
||||
AKEYCODE_BUTTON_START = 108,
|
||||
AKEYCODE_BUTTON_SELECT = 109,
|
||||
AKEYCODE_BUTTON_MODE = 110,
|
||||
|
||||
// NOTE: If you add a new keycode here you must also add it to several other files.
|
||||
// Refer to frameworks/base/core/java/android/view/KeyEvent.java for the full list.
|
||||
};
|
||||
|
||||
struct _WinTranslatePair {
|
||||
|
||||
unsigned int keysym;
|
||||
unsigned int keycode;
|
||||
};
|
||||
|
||||
static _WinTranslatePair _ak_to_keycode[] = {
|
||||
{ KEY_TAB, AKEYCODE_TAB },
|
||||
{ KEY_ENTER, AKEYCODE_ENTER },
|
||||
{ KEY_SHIFT, AKEYCODE_SHIFT_LEFT },
|
||||
{ KEY_SHIFT, AKEYCODE_SHIFT_RIGHT },
|
||||
{ KEY_ALT, AKEYCODE_ALT_LEFT },
|
||||
{ KEY_ALT, AKEYCODE_ALT_RIGHT },
|
||||
{ KEY_MENU, AKEYCODE_MENU },
|
||||
{ KEY_PAUSE, AKEYCODE_MEDIA_PLAY_PAUSE },
|
||||
{ KEY_ESCAPE, AKEYCODE_BACK },
|
||||
{ KEY_SPACE, AKEYCODE_SPACE },
|
||||
{ KEY_PAGEUP, AKEYCODE_PAGE_UP },
|
||||
{ KEY_PAGEDOWN, AKEYCODE_PAGE_DOWN },
|
||||
{ KEY_HOME, AKEYCODE_HOME }, //(0x24)
|
||||
{ KEY_LEFT, AKEYCODE_DPAD_LEFT },
|
||||
{ KEY_UP, AKEYCODE_DPAD_UP },
|
||||
{ KEY_RIGHT, AKEYCODE_DPAD_RIGHT },
|
||||
{ KEY_DOWN, AKEYCODE_DPAD_DOWN },
|
||||
{ KEY_PERIODCENTERED, AKEYCODE_DPAD_CENTER },
|
||||
{ KEY_BACKSPACE, AKEYCODE_DEL },
|
||||
{ KEY_0, AKEYCODE_0 }, ////0 key
|
||||
{ KEY_1, AKEYCODE_1 }, ////1 key
|
||||
{ KEY_2, AKEYCODE_2 }, ////2 key
|
||||
{ KEY_3, AKEYCODE_3 }, ////3 key
|
||||
{ KEY_4, AKEYCODE_4 }, ////4 key
|
||||
{ KEY_5, AKEYCODE_5 }, ////5 key
|
||||
{ KEY_6, AKEYCODE_6 }, ////6 key
|
||||
{ KEY_7, AKEYCODE_7 }, ////7 key
|
||||
{ KEY_8, AKEYCODE_8 }, ////8 key
|
||||
{ KEY_9, AKEYCODE_9 }, ////9 key
|
||||
{ KEY_A, AKEYCODE_A }, ////A key
|
||||
{ KEY_B, AKEYCODE_B }, ////B key
|
||||
{ KEY_C, AKEYCODE_C }, ////C key
|
||||
{ KEY_D, AKEYCODE_D }, ////D key
|
||||
{ KEY_E, AKEYCODE_E }, ////E key
|
||||
{ KEY_F, AKEYCODE_F }, ////F key
|
||||
{ KEY_G, AKEYCODE_G }, ////G key
|
||||
{ KEY_H, AKEYCODE_H }, ////H key
|
||||
{ KEY_I, AKEYCODE_I }, ////I key
|
||||
{ KEY_J, AKEYCODE_J }, ////J key
|
||||
{ KEY_K, AKEYCODE_K }, ////K key
|
||||
{ KEY_L, AKEYCODE_L }, ////L key
|
||||
{ KEY_M, AKEYCODE_M }, ////M key
|
||||
{ KEY_N, AKEYCODE_N }, ////N key
|
||||
{ KEY_O, AKEYCODE_O }, ////O key
|
||||
{ KEY_P, AKEYCODE_P }, ////P key
|
||||
{ KEY_Q, AKEYCODE_Q }, ////Q key
|
||||
{ KEY_R, AKEYCODE_R }, ////R key
|
||||
{ KEY_S, AKEYCODE_S }, ////S key
|
||||
{ KEY_T, AKEYCODE_T }, ////T key
|
||||
{ KEY_U, AKEYCODE_U }, ////U key
|
||||
{ KEY_V, AKEYCODE_V }, ////V key
|
||||
{ KEY_W, AKEYCODE_W }, ////W key
|
||||
{ KEY_X, AKEYCODE_X }, ////X key
|
||||
{ KEY_Y, AKEYCODE_Y }, ////Y key
|
||||
{ KEY_Z, AKEYCODE_Z }, ////Z key
|
||||
{ KEY_HOMEPAGE, AKEYCODE_EXPLORER },
|
||||
{ KEY_LAUNCH0, AKEYCODE_BUTTON_A },
|
||||
{ KEY_LAUNCH1, AKEYCODE_BUTTON_B },
|
||||
{ KEY_LAUNCH2, AKEYCODE_BUTTON_C },
|
||||
{ KEY_LAUNCH3, AKEYCODE_BUTTON_X },
|
||||
{ KEY_LAUNCH4, AKEYCODE_BUTTON_Y },
|
||||
{ KEY_LAUNCH5, AKEYCODE_BUTTON_Z },
|
||||
{ KEY_LAUNCH6, AKEYCODE_BUTTON_L1 },
|
||||
{ KEY_LAUNCH7, AKEYCODE_BUTTON_R1 },
|
||||
{ KEY_LAUNCH8, AKEYCODE_BUTTON_L2 },
|
||||
{ KEY_LAUNCH9, AKEYCODE_BUTTON_R2 },
|
||||
{ KEY_LAUNCHA, AKEYCODE_BUTTON_THUMBL },
|
||||
{ KEY_LAUNCHB, AKEYCODE_BUTTON_THUMBR },
|
||||
{ KEY_LAUNCHC, AKEYCODE_BUTTON_START },
|
||||
{ KEY_LAUNCHD, AKEYCODE_BUTTON_SELECT },
|
||||
{ KEY_LAUNCHE, AKEYCODE_BUTTON_MODE },
|
||||
{ KEY_VOLUMEMUTE, AKEYCODE_MUTE },
|
||||
{ KEY_VOLUMEDOWN, AKEYCODE_VOLUME_DOWN },
|
||||
{ KEY_VOLUMEUP, AKEYCODE_VOLUME_UP },
|
||||
{ KEY_BACK, AKEYCODE_MEDIA_REWIND },
|
||||
{ KEY_FORWARD, AKEYCODE_MEDIA_FAST_FORWARD },
|
||||
{ KEY_MEDIANEXT, AKEYCODE_MEDIA_NEXT },
|
||||
{ KEY_MEDIAPREVIOUS, AKEYCODE_MEDIA_PREVIOUS },
|
||||
{ KEY_MEDIASTOP, AKEYCODE_MEDIA_STOP },
|
||||
{ KEY_PLUS, AKEYCODE_PLUS },
|
||||
{ KEY_EQUAL, AKEYCODE_EQUALS }, // the '+' key
|
||||
{ KEY_COMMA, AKEYCODE_COMMA }, // the ',' key
|
||||
{ KEY_MINUS, AKEYCODE_MINUS }, // the '-' key
|
||||
{ KEY_SLASH, AKEYCODE_SLASH }, // the '/?' key
|
||||
{ KEY_BACKSLASH, AKEYCODE_BACKSLASH },
|
||||
{ KEY_BRACKETLEFT, AKEYCODE_LEFT_BRACKET },
|
||||
{ KEY_BRACKETRIGHT, AKEYCODE_RIGHT_BRACKET },
|
||||
{ KEY_UNKNOWN, 0 }
|
||||
};
|
||||
/*
|
||||
TODO: map these android key:
|
||||
AKEYCODE_SOFT_LEFT = 1,
|
||||
AKEYCODE_SOFT_RIGHT = 2,
|
||||
AKEYCODE_CALL = 5,
|
||||
AKEYCODE_ENDCALL = 6,
|
||||
AKEYCODE_STAR = 17,
|
||||
AKEYCODE_POUND = 18,
|
||||
AKEYCODE_POWER = 26,
|
||||
AKEYCODE_CAMERA = 27,
|
||||
AKEYCODE_CLEAR = 28,
|
||||
AKEYCODE_SYM = 63,
|
||||
AKEYCODE_ENVELOPE = 65,
|
||||
AKEYCODE_GRAVE = 68,
|
||||
AKEYCODE_SEMICOLON = 74,
|
||||
AKEYCODE_APOSTROPHE = 75,
|
||||
AKEYCODE_AT = 77,
|
||||
AKEYCODE_NUM = 78,
|
||||
AKEYCODE_HEADSETHOOK = 79,
|
||||
AKEYCODE_FOCUS = 80, // *Camera* focus
|
||||
AKEYCODE_NOTIFICATION = 83,
|
||||
AKEYCODE_SEARCH = 84,
|
||||
AKEYCODE_PICTSYMBOLS = 94,
|
||||
AKEYCODE_SWITCH_CHARSET = 95,
|
||||
*/
|
||||
|
||||
unsigned int android_get_keysym(unsigned int p_code);
|
||||
|
||||
#endif // ANDROID_KEYS_UTILS_H
|
|
@ -1,9 +1,9 @@
|
|||
ext.versions = [
|
||||
androidGradlePlugin: '3.4.2',
|
||||
compileSdk : 28,
|
||||
androidGradlePlugin: '3.6.0',
|
||||
compileSdk : 29,
|
||||
minSdk : 18,
|
||||
targetSdk : 28,
|
||||
buildTools : '28.0.3',
|
||||
targetSdk : 29,
|
||||
buildTools : '29.0.1',
|
||||
supportCoreUtils : '28.0.0',
|
||||
v4Support : '28.0.0'
|
||||
|
||||
|
|
|
@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
|
|||
distributionPath=wrapper/dists
|
||||
zipStoreBase=GRADLE_USER_HOME
|
||||
zipStorePath=wrapper/dists
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-5.1.1-all.zip
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-5.6.4-all.zip
|
||||
|
|
|
@ -33,10 +33,10 @@
|
|||
#include "java_godot_wrapper.h"
|
||||
|
||||
#include "android/asset_manager_jni.h"
|
||||
#include "android_keys_utils.h"
|
||||
#include "api/java_class_wrapper.h"
|
||||
#include "audio_driver_jandroid.h"
|
||||
#include "core/engine.h"
|
||||
#include "core/os/keyboard.h"
|
||||
#include "core/project_settings.h"
|
||||
#include "dir_access_jandroid.h"
|
||||
#include "file_access_android.h"
|
||||
|
@ -64,260 +64,6 @@ static Vector3 gravity;
|
|||
static Vector3 magnetometer;
|
||||
static Vector3 gyroscope;
|
||||
|
||||
/*
|
||||
* Android Key codes.
|
||||
*/
|
||||
enum {
|
||||
AKEYCODE_UNKNOWN = 0,
|
||||
AKEYCODE_SOFT_LEFT = 1,
|
||||
AKEYCODE_SOFT_RIGHT = 2,
|
||||
AKEYCODE_HOME = 3,
|
||||
AKEYCODE_BACK = 4,
|
||||
AKEYCODE_CALL = 5,
|
||||
AKEYCODE_ENDCALL = 6,
|
||||
AKEYCODE_0 = 7,
|
||||
AKEYCODE_1 = 8,
|
||||
AKEYCODE_2 = 9,
|
||||
AKEYCODE_3 = 10,
|
||||
AKEYCODE_4 = 11,
|
||||
AKEYCODE_5 = 12,
|
||||
AKEYCODE_6 = 13,
|
||||
AKEYCODE_7 = 14,
|
||||
AKEYCODE_8 = 15,
|
||||
AKEYCODE_9 = 16,
|
||||
AKEYCODE_STAR = 17,
|
||||
AKEYCODE_POUND = 18,
|
||||
AKEYCODE_DPAD_UP = 19,
|
||||
AKEYCODE_DPAD_DOWN = 20,
|
||||
AKEYCODE_DPAD_LEFT = 21,
|
||||
AKEYCODE_DPAD_RIGHT = 22,
|
||||
AKEYCODE_DPAD_CENTER = 23,
|
||||
AKEYCODE_VOLUME_UP = 24,
|
||||
AKEYCODE_VOLUME_DOWN = 25,
|
||||
AKEYCODE_POWER = 26,
|
||||
AKEYCODE_CAMERA = 27,
|
||||
AKEYCODE_CLEAR = 28,
|
||||
AKEYCODE_A = 29,
|
||||
AKEYCODE_B = 30,
|
||||
AKEYCODE_C = 31,
|
||||
AKEYCODE_D = 32,
|
||||
AKEYCODE_E = 33,
|
||||
AKEYCODE_F = 34,
|
||||
AKEYCODE_G = 35,
|
||||
AKEYCODE_H = 36,
|
||||
AKEYCODE_I = 37,
|
||||
AKEYCODE_J = 38,
|
||||
AKEYCODE_K = 39,
|
||||
AKEYCODE_L = 40,
|
||||
AKEYCODE_M = 41,
|
||||
AKEYCODE_N = 42,
|
||||
AKEYCODE_O = 43,
|
||||
AKEYCODE_P = 44,
|
||||
AKEYCODE_Q = 45,
|
||||
AKEYCODE_R = 46,
|
||||
AKEYCODE_S = 47,
|
||||
AKEYCODE_T = 48,
|
||||
AKEYCODE_U = 49,
|
||||
AKEYCODE_V = 50,
|
||||
AKEYCODE_W = 51,
|
||||
AKEYCODE_X = 52,
|
||||
AKEYCODE_Y = 53,
|
||||
AKEYCODE_Z = 54,
|
||||
AKEYCODE_COMMA = 55,
|
||||
AKEYCODE_PERIOD = 56,
|
||||
AKEYCODE_ALT_LEFT = 57,
|
||||
AKEYCODE_ALT_RIGHT = 58,
|
||||
AKEYCODE_SHIFT_LEFT = 59,
|
||||
AKEYCODE_SHIFT_RIGHT = 60,
|
||||
AKEYCODE_TAB = 61,
|
||||
AKEYCODE_SPACE = 62,
|
||||
AKEYCODE_SYM = 63,
|
||||
AKEYCODE_EXPLORER = 64,
|
||||
AKEYCODE_ENVELOPE = 65,
|
||||
AKEYCODE_ENTER = 66,
|
||||
AKEYCODE_DEL = 67,
|
||||
AKEYCODE_GRAVE = 68,
|
||||
AKEYCODE_MINUS = 69,
|
||||
AKEYCODE_EQUALS = 70,
|
||||
AKEYCODE_LEFT_BRACKET = 71,
|
||||
AKEYCODE_RIGHT_BRACKET = 72,
|
||||
AKEYCODE_BACKSLASH = 73,
|
||||
AKEYCODE_SEMICOLON = 74,
|
||||
AKEYCODE_APOSTROPHE = 75,
|
||||
AKEYCODE_SLASH = 76,
|
||||
AKEYCODE_AT = 77,
|
||||
AKEYCODE_NUM = 78,
|
||||
AKEYCODE_HEADSETHOOK = 79,
|
||||
AKEYCODE_FOCUS = 80, // *Camera* focus
|
||||
AKEYCODE_PLUS = 81,
|
||||
AKEYCODE_MENU = 82,
|
||||
AKEYCODE_NOTIFICATION = 83,
|
||||
AKEYCODE_SEARCH = 84,
|
||||
AKEYCODE_MEDIA_PLAY_PAUSE = 85,
|
||||
AKEYCODE_MEDIA_STOP = 86,
|
||||
AKEYCODE_MEDIA_NEXT = 87,
|
||||
AKEYCODE_MEDIA_PREVIOUS = 88,
|
||||
AKEYCODE_MEDIA_REWIND = 89,
|
||||
AKEYCODE_MEDIA_FAST_FORWARD = 90,
|
||||
AKEYCODE_MUTE = 91,
|
||||
AKEYCODE_PAGE_UP = 92,
|
||||
AKEYCODE_PAGE_DOWN = 93,
|
||||
AKEYCODE_PICTSYMBOLS = 94,
|
||||
AKEYCODE_SWITCH_CHARSET = 95,
|
||||
AKEYCODE_BUTTON_A = 96,
|
||||
AKEYCODE_BUTTON_B = 97,
|
||||
AKEYCODE_BUTTON_C = 98,
|
||||
AKEYCODE_BUTTON_X = 99,
|
||||
AKEYCODE_BUTTON_Y = 100,
|
||||
AKEYCODE_BUTTON_Z = 101,
|
||||
AKEYCODE_BUTTON_L1 = 102,
|
||||
AKEYCODE_BUTTON_R1 = 103,
|
||||
AKEYCODE_BUTTON_L2 = 104,
|
||||
AKEYCODE_BUTTON_R2 = 105,
|
||||
AKEYCODE_BUTTON_THUMBL = 106,
|
||||
AKEYCODE_BUTTON_THUMBR = 107,
|
||||
AKEYCODE_BUTTON_START = 108,
|
||||
AKEYCODE_BUTTON_SELECT = 109,
|
||||
AKEYCODE_BUTTON_MODE = 110,
|
||||
|
||||
// NOTE: If you add a new keycode here you must also add it to several other files.
|
||||
// Refer to frameworks/base/core/java/android/view/KeyEvent.java for the full list.
|
||||
};
|
||||
|
||||
struct _WinTranslatePair {
|
||||
|
||||
unsigned int keysym;
|
||||
unsigned int keycode;
|
||||
};
|
||||
|
||||
static _WinTranslatePair _ak_to_keycode[] = {
|
||||
{ KEY_TAB, AKEYCODE_TAB },
|
||||
{ KEY_ENTER, AKEYCODE_ENTER },
|
||||
{ KEY_SHIFT, AKEYCODE_SHIFT_LEFT },
|
||||
{ KEY_SHIFT, AKEYCODE_SHIFT_RIGHT },
|
||||
{ KEY_ALT, AKEYCODE_ALT_LEFT },
|
||||
{ KEY_ALT, AKEYCODE_ALT_RIGHT },
|
||||
{ KEY_MENU, AKEYCODE_MENU },
|
||||
{ KEY_PAUSE, AKEYCODE_MEDIA_PLAY_PAUSE },
|
||||
{ KEY_ESCAPE, AKEYCODE_BACK },
|
||||
{ KEY_SPACE, AKEYCODE_SPACE },
|
||||
{ KEY_PAGEUP, AKEYCODE_PAGE_UP },
|
||||
{ KEY_PAGEDOWN, AKEYCODE_PAGE_DOWN },
|
||||
{ KEY_HOME, AKEYCODE_HOME }, //(0x24)
|
||||
{ KEY_LEFT, AKEYCODE_DPAD_LEFT },
|
||||
{ KEY_UP, AKEYCODE_DPAD_UP },
|
||||
{ KEY_RIGHT, AKEYCODE_DPAD_RIGHT },
|
||||
{ KEY_DOWN, AKEYCODE_DPAD_DOWN },
|
||||
{ KEY_PERIODCENTERED, AKEYCODE_DPAD_CENTER },
|
||||
{ KEY_BACKSPACE, AKEYCODE_DEL },
|
||||
{ KEY_0, AKEYCODE_0 }, ////0 key
|
||||
{ KEY_1, AKEYCODE_1 }, ////1 key
|
||||
{ KEY_2, AKEYCODE_2 }, ////2 key
|
||||
{ KEY_3, AKEYCODE_3 }, ////3 key
|
||||
{ KEY_4, AKEYCODE_4 }, ////4 key
|
||||
{ KEY_5, AKEYCODE_5 }, ////5 key
|
||||
{ KEY_6, AKEYCODE_6 }, ////6 key
|
||||
{ KEY_7, AKEYCODE_7 }, ////7 key
|
||||
{ KEY_8, AKEYCODE_8 }, ////8 key
|
||||
{ KEY_9, AKEYCODE_9 }, ////9 key
|
||||
{ KEY_A, AKEYCODE_A }, ////A key
|
||||
{ KEY_B, AKEYCODE_B }, ////B key
|
||||
{ KEY_C, AKEYCODE_C }, ////C key
|
||||
{ KEY_D, AKEYCODE_D }, ////D key
|
||||
{ KEY_E, AKEYCODE_E }, ////E key
|
||||
{ KEY_F, AKEYCODE_F }, ////F key
|
||||
{ KEY_G, AKEYCODE_G }, ////G key
|
||||
{ KEY_H, AKEYCODE_H }, ////H key
|
||||
{ KEY_I, AKEYCODE_I }, ////I key
|
||||
{ KEY_J, AKEYCODE_J }, ////J key
|
||||
{ KEY_K, AKEYCODE_K }, ////K key
|
||||
{ KEY_L, AKEYCODE_L }, ////L key
|
||||
{ KEY_M, AKEYCODE_M }, ////M key
|
||||
{ KEY_N, AKEYCODE_N }, ////N key
|
||||
{ KEY_O, AKEYCODE_O }, ////O key
|
||||
{ KEY_P, AKEYCODE_P }, ////P key
|
||||
{ KEY_Q, AKEYCODE_Q }, ////Q key
|
||||
{ KEY_R, AKEYCODE_R }, ////R key
|
||||
{ KEY_S, AKEYCODE_S }, ////S key
|
||||
{ KEY_T, AKEYCODE_T }, ////T key
|
||||
{ KEY_U, AKEYCODE_U }, ////U key
|
||||
{ KEY_V, AKEYCODE_V }, ////V key
|
||||
{ KEY_W, AKEYCODE_W }, ////W key
|
||||
{ KEY_X, AKEYCODE_X }, ////X key
|
||||
{ KEY_Y, AKEYCODE_Y }, ////Y key
|
||||
{ KEY_Z, AKEYCODE_Z }, ////Z key
|
||||
{ KEY_HOMEPAGE, AKEYCODE_EXPLORER },
|
||||
{ KEY_LAUNCH0, AKEYCODE_BUTTON_A },
|
||||
{ KEY_LAUNCH1, AKEYCODE_BUTTON_B },
|
||||
{ KEY_LAUNCH2, AKEYCODE_BUTTON_C },
|
||||
{ KEY_LAUNCH3, AKEYCODE_BUTTON_X },
|
||||
{ KEY_LAUNCH4, AKEYCODE_BUTTON_Y },
|
||||
{ KEY_LAUNCH5, AKEYCODE_BUTTON_Z },
|
||||
{ KEY_LAUNCH6, AKEYCODE_BUTTON_L1 },
|
||||
{ KEY_LAUNCH7, AKEYCODE_BUTTON_R1 },
|
||||
{ KEY_LAUNCH8, AKEYCODE_BUTTON_L2 },
|
||||
{ KEY_LAUNCH9, AKEYCODE_BUTTON_R2 },
|
||||
{ KEY_LAUNCHA, AKEYCODE_BUTTON_THUMBL },
|
||||
{ KEY_LAUNCHB, AKEYCODE_BUTTON_THUMBR },
|
||||
{ KEY_LAUNCHC, AKEYCODE_BUTTON_START },
|
||||
{ KEY_LAUNCHD, AKEYCODE_BUTTON_SELECT },
|
||||
{ KEY_LAUNCHE, AKEYCODE_BUTTON_MODE },
|
||||
{ KEY_VOLUMEMUTE, AKEYCODE_MUTE },
|
||||
{ KEY_VOLUMEDOWN, AKEYCODE_VOLUME_DOWN },
|
||||
{ KEY_VOLUMEUP, AKEYCODE_VOLUME_UP },
|
||||
{ KEY_BACK, AKEYCODE_MEDIA_REWIND },
|
||||
{ KEY_FORWARD, AKEYCODE_MEDIA_FAST_FORWARD },
|
||||
{ KEY_MEDIANEXT, AKEYCODE_MEDIA_NEXT },
|
||||
{ KEY_MEDIAPREVIOUS, AKEYCODE_MEDIA_PREVIOUS },
|
||||
{ KEY_MEDIASTOP, AKEYCODE_MEDIA_STOP },
|
||||
{ KEY_PLUS, AKEYCODE_PLUS },
|
||||
{ KEY_EQUAL, AKEYCODE_EQUALS }, // the '+' key
|
||||
{ KEY_COMMA, AKEYCODE_COMMA }, // the ',' key
|
||||
{ KEY_MINUS, AKEYCODE_MINUS }, // the '-' key
|
||||
{ KEY_SLASH, AKEYCODE_SLASH }, // the '/?' key
|
||||
{ KEY_BACKSLASH, AKEYCODE_BACKSLASH },
|
||||
{ KEY_BRACKETLEFT, AKEYCODE_LEFT_BRACKET },
|
||||
{ KEY_BRACKETRIGHT, AKEYCODE_RIGHT_BRACKET },
|
||||
{ KEY_UNKNOWN, 0 }
|
||||
};
|
||||
/*
|
||||
TODO: map these android key:
|
||||
AKEYCODE_SOFT_LEFT = 1,
|
||||
AKEYCODE_SOFT_RIGHT = 2,
|
||||
AKEYCODE_CALL = 5,
|
||||
AKEYCODE_ENDCALL = 6,
|
||||
AKEYCODE_STAR = 17,
|
||||
AKEYCODE_POUND = 18,
|
||||
AKEYCODE_POWER = 26,
|
||||
AKEYCODE_CAMERA = 27,
|
||||
AKEYCODE_CLEAR = 28,
|
||||
AKEYCODE_SYM = 63,
|
||||
AKEYCODE_ENVELOPE = 65,
|
||||
AKEYCODE_GRAVE = 68,
|
||||
AKEYCODE_SEMICOLON = 74,
|
||||
AKEYCODE_APOSTROPHE = 75,
|
||||
AKEYCODE_AT = 77,
|
||||
AKEYCODE_NUM = 78,
|
||||
AKEYCODE_HEADSETHOOK = 79,
|
||||
AKEYCODE_FOCUS = 80, // *Camera* focus
|
||||
AKEYCODE_NOTIFICATION = 83,
|
||||
AKEYCODE_SEARCH = 84,
|
||||
AKEYCODE_PICTSYMBOLS = 94,
|
||||
AKEYCODE_SWITCH_CHARSET = 95,
|
||||
*/
|
||||
|
||||
static unsigned int android_get_keysym(unsigned int p_code) {
|
||||
for (int i = 0; _ak_to_keycode[i].keysym != KEY_UNKNOWN; i++) {
|
||||
|
||||
if (_ak_to_keycode[i].keycode == p_code) {
|
||||
|
||||
return _ak_to_keycode[i].keysym;
|
||||
}
|
||||
}
|
||||
|
||||
return KEY_UNKNOWN;
|
||||
}
|
||||
|
||||
static void _initialize_java_modules() {
|
||||
|
||||
if (!ProjectSettings::get_singleton()->has_setting("android/modules")) {
|
||||
|
|
|
@ -32,6 +32,7 @@
|
|||
#define JNI_UTILS_H
|
||||
|
||||
#include "string_android.h"
|
||||
#include <core/engine.h>
|
||||
#include <core/variant.h>
|
||||
#include <jni.h>
|
||||
|
||||
|
@ -52,4 +53,189 @@ Variant::Type get_jni_type(const String &p_type);
|
|||
|
||||
const char *get_jni_sig(const String &p_type);
|
||||
|
||||
class JNISingleton : public Object {
|
||||
|
||||
GDCLASS(JNISingleton, Object);
|
||||
|
||||
struct MethodData {
|
||||
|
||||
jmethodID method;
|
||||
Variant::Type ret_type;
|
||||
Vector<Variant::Type> argtypes;
|
||||
};
|
||||
|
||||
jobject instance;
|
||||
Map<StringName, MethodData> method_map;
|
||||
|
||||
public:
|
||||
virtual Variant call(const StringName &p_method, const Variant **p_args, int p_argcount, Variant::CallError &r_error) {
|
||||
|
||||
ERR_FAIL_COND_V(!instance, Variant());
|
||||
|
||||
r_error.error = Variant::CallError::CALL_OK;
|
||||
|
||||
Map<StringName, MethodData>::Element *E = method_map.find(p_method);
|
||||
if (!E) {
|
||||
|
||||
r_error.error = Variant::CallError::CALL_ERROR_INVALID_METHOD;
|
||||
return Variant();
|
||||
}
|
||||
|
||||
int ac = E->get().argtypes.size();
|
||||
if (ac < p_argcount) {
|
||||
|
||||
r_error.error = Variant::CallError::CALL_ERROR_TOO_FEW_ARGUMENTS;
|
||||
r_error.argument = ac;
|
||||
return Variant();
|
||||
}
|
||||
|
||||
if (ac > p_argcount) {
|
||||
|
||||
r_error.error = Variant::CallError::CALL_ERROR_TOO_MANY_ARGUMENTS;
|
||||
r_error.argument = ac;
|
||||
return Variant();
|
||||
}
|
||||
|
||||
for (int i = 0; i < p_argcount; i++) {
|
||||
|
||||
if (!Variant::can_convert(p_args[i]->get_type(), E->get().argtypes[i])) {
|
||||
|
||||
r_error.error = Variant::CallError::CALL_ERROR_INVALID_ARGUMENT;
|
||||
r_error.argument = i;
|
||||
r_error.expected = E->get().argtypes[i];
|
||||
}
|
||||
}
|
||||
|
||||
jvalue *v = NULL;
|
||||
|
||||
if (p_argcount) {
|
||||
|
||||
v = (jvalue *)alloca(sizeof(jvalue) * p_argcount);
|
||||
}
|
||||
|
||||
JNIEnv *env = ThreadAndroid::get_env();
|
||||
|
||||
int res = env->PushLocalFrame(16);
|
||||
|
||||
ERR_FAIL_COND_V(res != 0, Variant());
|
||||
|
||||
List<jobject> to_erase;
|
||||
for (int i = 0; i < p_argcount; i++) {
|
||||
|
||||
jvalret vr = _variant_to_jvalue(env, E->get().argtypes[i], p_args[i]);
|
||||
v[i] = vr.val;
|
||||
if (vr.obj)
|
||||
to_erase.push_back(vr.obj);
|
||||
}
|
||||
|
||||
Variant ret;
|
||||
|
||||
switch (E->get().ret_type) {
|
||||
|
||||
case Variant::NIL: {
|
||||
|
||||
env->CallVoidMethodA(instance, E->get().method, v);
|
||||
} break;
|
||||
case Variant::BOOL: {
|
||||
|
||||
ret = env->CallBooleanMethodA(instance, E->get().method, v) == JNI_TRUE;
|
||||
} break;
|
||||
case Variant::INT: {
|
||||
|
||||
ret = env->CallIntMethodA(instance, E->get().method, v);
|
||||
} break;
|
||||
case Variant::REAL: {
|
||||
|
||||
ret = env->CallFloatMethodA(instance, E->get().method, v);
|
||||
} break;
|
||||
case Variant::STRING: {
|
||||
|
||||
jobject o = env->CallObjectMethodA(instance, E->get().method, v);
|
||||
ret = jstring_to_string((jstring)o, env);
|
||||
env->DeleteLocalRef(o);
|
||||
} break;
|
||||
case Variant::POOL_STRING_ARRAY: {
|
||||
|
||||
jobjectArray arr = (jobjectArray)env->CallObjectMethodA(instance, E->get().method, v);
|
||||
|
||||
ret = _jobject_to_variant(env, arr);
|
||||
|
||||
env->DeleteLocalRef(arr);
|
||||
} break;
|
||||
case Variant::POOL_INT_ARRAY: {
|
||||
|
||||
jintArray arr = (jintArray)env->CallObjectMethodA(instance, E->get().method, v);
|
||||
|
||||
int fCount = env->GetArrayLength(arr);
|
||||
PoolVector<int> sarr;
|
||||
sarr.resize(fCount);
|
||||
|
||||
PoolVector<int>::Write w = sarr.write();
|
||||
env->GetIntArrayRegion(arr, 0, fCount, w.ptr());
|
||||
w.release();
|
||||
ret = sarr;
|
||||
env->DeleteLocalRef(arr);
|
||||
} break;
|
||||
case Variant::POOL_REAL_ARRAY: {
|
||||
|
||||
jfloatArray arr = (jfloatArray)env->CallObjectMethodA(instance, E->get().method, v);
|
||||
|
||||
int fCount = env->GetArrayLength(arr);
|
||||
PoolVector<float> sarr;
|
||||
sarr.resize(fCount);
|
||||
|
||||
PoolVector<float>::Write w = sarr.write();
|
||||
env->GetFloatArrayRegion(arr, 0, fCount, w.ptr());
|
||||
w.release();
|
||||
ret = sarr;
|
||||
env->DeleteLocalRef(arr);
|
||||
} break;
|
||||
|
||||
case Variant::DICTIONARY: {
|
||||
|
||||
jobject obj = env->CallObjectMethodA(instance, E->get().method, v);
|
||||
ret = _jobject_to_variant(env, obj);
|
||||
env->DeleteLocalRef(obj);
|
||||
|
||||
} break;
|
||||
default: {
|
||||
|
||||
env->PopLocalFrame(NULL);
|
||||
ERR_FAIL_V(Variant());
|
||||
} break;
|
||||
}
|
||||
|
||||
while (to_erase.size()) {
|
||||
env->DeleteLocalRef(to_erase.front()->get());
|
||||
to_erase.pop_front();
|
||||
}
|
||||
|
||||
env->PopLocalFrame(NULL);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
jobject get_instance() const {
|
||||
|
||||
return instance;
|
||||
}
|
||||
void set_instance(jobject p_instance) {
|
||||
|
||||
instance = p_instance;
|
||||
}
|
||||
|
||||
void add_method(const StringName &p_name, jmethodID p_method, const Vector<Variant::Type> &p_args, Variant::Type p_ret_type) {
|
||||
|
||||
MethodData md;
|
||||
md.method = p_method;
|
||||
md.argtypes = p_args;
|
||||
md.ret_type = p_ret_type;
|
||||
method_map[p_name] = md;
|
||||
}
|
||||
|
||||
JNISingleton() {
|
||||
instance = NULL;
|
||||
}
|
||||
};
|
||||
|
||||
#endif // JNI_UTILS_H
|
||||
|
|
|
@ -36,191 +36,6 @@
|
|||
#include <platform/android/jni_utils.h>
|
||||
#include <platform/android/string_android.h>
|
||||
|
||||
class JNISingleton : public Object {
|
||||
|
||||
GDCLASS(JNISingleton, Object);
|
||||
|
||||
struct MethodData {
|
||||
|
||||
jmethodID method;
|
||||
Variant::Type ret_type;
|
||||
Vector<Variant::Type> argtypes;
|
||||
};
|
||||
|
||||
jobject instance;
|
||||
Map<StringName, MethodData> method_map;
|
||||
|
||||
public:
|
||||
virtual Variant call(const StringName &p_method, const Variant **p_args, int p_argcount, Variant::CallError &r_error) {
|
||||
|
||||
ERR_FAIL_COND_V(!instance, Variant());
|
||||
|
||||
r_error.error = Variant::CallError::CALL_OK;
|
||||
|
||||
Map<StringName, MethodData>::Element *E = method_map.find(p_method);
|
||||
if (!E) {
|
||||
|
||||
r_error.error = Variant::CallError::CALL_ERROR_INVALID_METHOD;
|
||||
return Variant();
|
||||
}
|
||||
|
||||
int ac = E->get().argtypes.size();
|
||||
if (ac < p_argcount) {
|
||||
|
||||
r_error.error = Variant::CallError::CALL_ERROR_TOO_FEW_ARGUMENTS;
|
||||
r_error.argument = ac;
|
||||
return Variant();
|
||||
}
|
||||
|
||||
if (ac > p_argcount) {
|
||||
|
||||
r_error.error = Variant::CallError::CALL_ERROR_TOO_MANY_ARGUMENTS;
|
||||
r_error.argument = ac;
|
||||
return Variant();
|
||||
}
|
||||
|
||||
for (int i = 0; i < p_argcount; i++) {
|
||||
|
||||
if (!Variant::can_convert(p_args[i]->get_type(), E->get().argtypes[i])) {
|
||||
|
||||
r_error.error = Variant::CallError::CALL_ERROR_INVALID_ARGUMENT;
|
||||
r_error.argument = i;
|
||||
r_error.expected = E->get().argtypes[i];
|
||||
}
|
||||
}
|
||||
|
||||
jvalue *v = NULL;
|
||||
|
||||
if (p_argcount) {
|
||||
|
||||
v = (jvalue *)alloca(sizeof(jvalue) * p_argcount);
|
||||
}
|
||||
|
||||
JNIEnv *env = ThreadAndroid::get_env();
|
||||
|
||||
int res = env->PushLocalFrame(16);
|
||||
|
||||
ERR_FAIL_COND_V(res != 0, Variant());
|
||||
|
||||
List<jobject> to_erase;
|
||||
for (int i = 0; i < p_argcount; i++) {
|
||||
|
||||
jvalret vr = _variant_to_jvalue(env, E->get().argtypes[i], p_args[i]);
|
||||
v[i] = vr.val;
|
||||
if (vr.obj)
|
||||
to_erase.push_back(vr.obj);
|
||||
}
|
||||
|
||||
Variant ret;
|
||||
|
||||
switch (E->get().ret_type) {
|
||||
|
||||
case Variant::NIL: {
|
||||
|
||||
env->CallVoidMethodA(instance, E->get().method, v);
|
||||
} break;
|
||||
case Variant::BOOL: {
|
||||
|
||||
ret = env->CallBooleanMethodA(instance, E->get().method, v) == JNI_TRUE;
|
||||
} break;
|
||||
case Variant::INT: {
|
||||
|
||||
ret = env->CallIntMethodA(instance, E->get().method, v);
|
||||
} break;
|
||||
case Variant::REAL: {
|
||||
|
||||
ret = env->CallFloatMethodA(instance, E->get().method, v);
|
||||
} break;
|
||||
case Variant::STRING: {
|
||||
|
||||
jobject o = env->CallObjectMethodA(instance, E->get().method, v);
|
||||
ret = jstring_to_string((jstring)o, env);
|
||||
env->DeleteLocalRef(o);
|
||||
} break;
|
||||
case Variant::POOL_STRING_ARRAY: {
|
||||
|
||||
jobjectArray arr = (jobjectArray)env->CallObjectMethodA(instance, E->get().method, v);
|
||||
|
||||
ret = _jobject_to_variant(env, arr);
|
||||
|
||||
env->DeleteLocalRef(arr);
|
||||
} break;
|
||||
case Variant::POOL_INT_ARRAY: {
|
||||
|
||||
jintArray arr = (jintArray)env->CallObjectMethodA(instance, E->get().method, v);
|
||||
|
||||
int fCount = env->GetArrayLength(arr);
|
||||
PoolVector<int> sarr;
|
||||
sarr.resize(fCount);
|
||||
|
||||
PoolVector<int>::Write w = sarr.write();
|
||||
env->GetIntArrayRegion(arr, 0, fCount, w.ptr());
|
||||
w.release();
|
||||
ret = sarr;
|
||||
env->DeleteLocalRef(arr);
|
||||
} break;
|
||||
case Variant::POOL_REAL_ARRAY: {
|
||||
|
||||
jfloatArray arr = (jfloatArray)env->CallObjectMethodA(instance, E->get().method, v);
|
||||
|
||||
int fCount = env->GetArrayLength(arr);
|
||||
PoolVector<float> sarr;
|
||||
sarr.resize(fCount);
|
||||
|
||||
PoolVector<float>::Write w = sarr.write();
|
||||
env->GetFloatArrayRegion(arr, 0, fCount, w.ptr());
|
||||
w.release();
|
||||
ret = sarr;
|
||||
env->DeleteLocalRef(arr);
|
||||
} break;
|
||||
|
||||
case Variant::DICTIONARY: {
|
||||
|
||||
jobject obj = env->CallObjectMethodA(instance, E->get().method, v);
|
||||
ret = _jobject_to_variant(env, obj);
|
||||
env->DeleteLocalRef(obj);
|
||||
|
||||
} break;
|
||||
default: {
|
||||
|
||||
env->PopLocalFrame(NULL);
|
||||
ERR_FAIL_V(Variant());
|
||||
} break;
|
||||
}
|
||||
|
||||
while (to_erase.size()) {
|
||||
env->DeleteLocalRef(to_erase.front()->get());
|
||||
to_erase.pop_front();
|
||||
}
|
||||
|
||||
env->PopLocalFrame(NULL);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
jobject get_instance() const {
|
||||
|
||||
return instance;
|
||||
}
|
||||
void set_instance(jobject p_instance) {
|
||||
|
||||
instance = p_instance;
|
||||
}
|
||||
|
||||
void add_method(const StringName &p_name, jmethodID p_method, const Vector<Variant::Type> &p_args, Variant::Type p_ret_type) {
|
||||
|
||||
MethodData md;
|
||||
md.method = p_method;
|
||||
md.argtypes = p_args;
|
||||
md.ret_type = p_ret_type;
|
||||
method_map[p_name] = md;
|
||||
}
|
||||
|
||||
JNISingleton() {
|
||||
instance = NULL;
|
||||
}
|
||||
};
|
||||
|
||||
static HashMap<String, JNISingleton *> jni_singletons;
|
||||
|
||||
extern "C" {
|
||||
|
|
Loading…
Reference in New Issue