summaryrefslogtreecommitdiff
path: root/platform
diff options
context:
space:
mode:
Diffstat (limited to 'platform')
-rw-r--r--platform/android/SCsub8
-rw-r--r--platform/android/android_keys_utils.cpp (renamed from platform/iphone/power_iphone.h)30
-rw-r--r--platform/android/android_keys_utils.h280
-rw-r--r--platform/android/api/api.cpp4
-rw-r--r--platform/android/api/java_class_wrapper.h30
-rw-r--r--platform/android/audio_driver_jandroid.cpp13
-rw-r--r--platform/android/audio_driver_jandroid.h2
-rw-r--r--platform/android/audio_driver_opensl.cpp18
-rw-r--r--platform/android/audio_driver_opensl.h2
-rw-r--r--platform/android/detect.py6
-rw-r--r--platform/android/dir_access_jandroid.cpp2
-rw-r--r--platform/android/dir_access_jandroid.h2
-rw-r--r--platform/android/export/export.cpp343
-rw-r--r--platform/android/java/app/AndroidManifest.xml26
-rw-r--r--platform/android/java/app/build.gradle69
-rw-r--r--platform/android/java/app/config.gradle72
-rw-r--r--platform/android/java/build.gradle101
-rw-r--r--platform/android/java/gradle/wrapper/gradle-wrapper.properties2
-rw-r--r--platform/android/java/lib/build.gradle5
-rw-r--r--platform/android/java/lib/src/org/godotengine/godot/Godot.java201
-rw-r--r--platform/android/java/lib/src/org/godotengine/godot/GodotLib.java18
-rw-r--r--platform/android/java/lib/src/org/godotengine/godot/GodotRenderer.java20
-rw-r--r--platform/android/java/lib/src/org/godotengine/godot/GodotView.java3
-rw-r--r--platform/android/java/lib/src/org/godotengine/godot/input/GodotEditText.java2
-rw-r--r--platform/android/java/lib/src/org/godotengine/godot/input/GodotInputHandler.java6
-rw-r--r--platform/android/java/lib/src/org/godotengine/godot/input/GodotTextInputWrapper.java24
-rw-r--r--platform/android/java/lib/src/org/godotengine/godot/plugin/GodotPlugin.java256
-rw-r--r--platform/android/java/lib/src/org/godotengine/godot/plugin/GodotPluginRegistry.java199
-rw-r--r--platform/android/java/lib/src/org/godotengine/godot/utils/GLUtils.java1
-rw-r--r--platform/android/java/lib/src/org/godotengine/godot/vulkan/VkRenderer.kt (renamed from platform/uwp/power_uwp.cpp)98
-rw-r--r--platform/android/java/lib/src/org/godotengine/godot/vulkan/VkSurfaceView.kt136
-rw-r--r--platform/android/java/lib/src/org/godotengine/godot/vulkan/VkThread.kt230
-rw-r--r--platform/android/java/lib/src/org/godotengine/godot/xr/regular/RegularConfigChooser.java15
-rw-r--r--platform/android/java/lib/src/org/godotengine/godot/xr/regular/RegularContextFactory.java15
-rw-r--r--platform/android/java/plugins/godotpayment/build.gradle31
-rw-r--r--platform/android/java/plugins/godotpayment/src/main/AndroidManifest.xml11
-rw-r--r--platform/android/java/plugins/godotpayment/src/main/aidl/com/android/vending/billing/IInAppBillingService.aidl (renamed from platform/android/java/lib/aidl/com/android/vending/billing/IInAppBillingService.aidl)0
-rw-r--r--platform/android/java/plugins/godotpayment/src/main/java/org/godotengine/godot/plugin/payment/ConsumeTask.java (renamed from platform/android/java/lib/src/org/godotengine/godot/payments/ConsumeTask.java)2
-rw-r--r--platform/android/java/plugins/godotpayment/src/main/java/org/godotengine/godot/plugin/payment/GodotPayment.java (renamed from platform/android/java/lib/src/org/godotengine/godot/GodotPaymentV3.java)73
-rw-r--r--platform/android/java/plugins/godotpayment/src/main/java/org/godotengine/godot/plugin/payment/HandlePurchaseTask.java (renamed from platform/android/java/lib/src/org/godotengine/godot/payments/HandlePurchaseTask.java)2
-rw-r--r--platform/android/java/plugins/godotpayment/src/main/java/org/godotengine/godot/plugin/payment/PaymentsCache.java (renamed from platform/android/java/lib/src/org/godotengine/godot/payments/PaymentsCache.java)3
-rw-r--r--platform/android/java/plugins/godotpayment/src/main/java/org/godotengine/godot/plugin/payment/PaymentsManager.java (renamed from platform/android/java/lib/src/org/godotengine/godot/payments/PaymentsManager.java)84
-rw-r--r--platform/android/java/plugins/godotpayment/src/main/java/org/godotengine/godot/plugin/payment/PurchaseTask.java (renamed from platform/android/java/lib/src/org/godotengine/godot/payments/PurchaseTask.java)2
-rw-r--r--platform/android/java/plugins/godotpayment/src/main/java/org/godotengine/godot/plugin/payment/ReleaseAllConsumablesTask.java (renamed from platform/android/java/lib/src/org/godotengine/godot/payments/ReleaseAllConsumablesTask.java)2
-rw-r--r--platform/android/java/plugins/godotpayment/src/main/java/org/godotengine/godot/plugin/payment/ValidateTask.java (renamed from platform/android/java/lib/src/org/godotengine/godot/payments/ValidateTask.java)11
-rw-r--r--platform/android/java/settings.gradle1
-rw-r--r--platform/android/java_class_wrapper.cpp24
-rw-r--r--platform/android/java_godot_lib_jni.cpp1033
-rw-r--r--platform/android/java_godot_lib_jni.h58
-rw-r--r--platform/android/java_godot_wrapper.cpp17
-rw-r--r--platform/android/java_godot_wrapper.h3
-rw-r--r--platform/android/jni_utils.cpp434
-rw-r--r--platform/android/jni_utils.h242
-rw-r--r--platform/android/os_android.cpp68
-rw-r--r--platform/android/os_android.h3
-rw-r--r--platform/android/plugin/godot_plugin_jni.cpp115
-rw-r--r--platform/android/plugin/godot_plugin_jni.h43
-rw-r--r--platform/android/power_android.cpp255
-rw-r--r--platform/android/power_android.h80
-rw-r--r--platform/android/vulkan/vk_renderer_jni.cpp58
-rw-r--r--platform/android/vulkan/vk_renderer_jni.h46
-rw-r--r--platform/haiku/audio_driver_media_kit.cpp11
-rw-r--r--platform/haiku/audio_driver_media_kit.h2
-rw-r--r--platform/haiku/haiku_direct_window.cpp8
-rw-r--r--platform/haiku/os_haiku.cpp26
-rw-r--r--platform/haiku/os_haiku.h4
-rw-r--r--platform/haiku/platform_config.h1
-rw-r--r--platform/iphone/SCsub1
-rw-r--r--platform/iphone/app_delegate.h11
-rw-r--r--platform/iphone/app_delegate.mm15
-rw-r--r--platform/iphone/detect.py14
-rw-r--r--platform/iphone/export/export.cpp211
-rw-r--r--platform/iphone/game_center.mm14
-rw-r--r--platform/iphone/gl_view.mm16
-rw-r--r--platform/iphone/icloud.mm16
-rw-r--r--platform/iphone/in_app_store.mm16
-rw-r--r--platform/iphone/os_iphone.cpp75
-rw-r--r--platform/iphone/os_iphone.h9
-rw-r--r--platform/iphone/platform_config.h1
-rw-r--r--platform/iphone/semaphore_iphone.cpp112
-rw-r--r--platform/iphone/vulkan_context_iphone.h (renamed from platform/uwp/power_uwp.h)30
-rw-r--r--platform/iphone/vulkan_context_iphone.mm56
-rw-r--r--platform/javascript/SCsub41
-rw-r--r--platform/javascript/audio_driver_javascript.cpp93
-rw-r--r--platform/javascript/audio_driver_javascript.h1
-rw-r--r--platform/javascript/detect.py111
-rw-r--r--platform/javascript/dom_keys.inc2
-rw-r--r--platform/javascript/emscripten_helpers.py37
-rw-r--r--platform/javascript/engine.js413
-rw-r--r--platform/javascript/engine/engine.js184
-rw-r--r--platform/javascript/engine/externs.js3
-rw-r--r--platform/javascript/engine/loader.js33
-rw-r--r--platform/javascript/engine/preloader.js139
-rw-r--r--platform/javascript/engine/utils.js69
-rw-r--r--platform/javascript/export/export.cpp104
-rw-r--r--platform/javascript/http_client.h.inc2
-rw-r--r--platform/javascript/http_client_javascript.cpp33
-rw-r--r--platform/javascript/id_handler.js2
-rw-r--r--platform/javascript/javascript_eval.cpp22
-rw-r--r--platform/javascript/os_javascript.cpp140
-rw-r--r--platform/javascript/os_javascript.h10
-rw-r--r--platform/javascript/pre.js5
-rw-r--r--platform/osx/SCsub4
-rw-r--r--platform/osx/context_gl_osx.h (renamed from platform/osx/power_osx.h)56
-rw-r--r--platform/osx/context_gl_osx.mm172
-rw-r--r--platform/osx/detect.py42
-rw-r--r--platform/osx/export/export.cpp20
-rw-r--r--platform/osx/godot_main_osx.mm6
-rw-r--r--platform/osx/joypad_osx.cpp20
-rw-r--r--platform/osx/joypad_osx.h3
-rw-r--r--platform/osx/os_osx.h37
-rw-r--r--platform/osx/os_osx.mm519
-rw-r--r--platform/osx/platform_config.h1
-rw-r--r--platform/osx/power_osx.cpp252
-rw-r--r--platform/osx/semaphore_osx.cpp107
-rw-r--r--platform/osx/vulkan_context_osx.h (renamed from platform/osx/semaphore_osx.h)33
-rw-r--r--platform/osx/vulkan_context_osx.mm (renamed from platform/iphone/power_iphone.cpp)48
-rw-r--r--platform/server/SCsub3
-rw-r--r--platform/server/detect.py8
-rw-r--r--platform/server/os_server.cpp25
-rw-r--r--platform/server/os_server.h11
-rw-r--r--platform/uwp/SCsub1
-rw-r--r--platform/uwp/app.cpp6
-rw-r--r--platform/uwp/app.h1
-rw-r--r--platform/uwp/context_egl_uwp.h2
-rw-r--r--platform/uwp/export/export.cpp10
-rw-r--r--platform/uwp/os_uwp.cpp88
-rw-r--r--platform/uwp/os_uwp.h10
-rw-r--r--platform/windows/SCsub6
-rw-r--r--platform/windows/detect.py44
-rw-r--r--platform/windows/export/export.cpp12
-rw-r--r--platform/windows/key_mapping_windows.cpp164
-rw-r--r--platform/windows/key_mapping_windows.h1
-rw-r--r--[-rwxr-xr-x]platform/windows/os_windows.cpp241
-rw-r--r--platform/windows/os_windows.h28
-rw-r--r--platform/windows/platform_config.h5
-rw-r--r--platform/windows/power_windows.cpp131
-rw-r--r--platform/windows/vulkan_context_win.cpp57
-rw-r--r--platform/windows/vulkan_context_win.h (renamed from platform/windows/power_windows.h)30
-rw-r--r--platform/windows/windows_terminal_logger.cpp68
-rw-r--r--platform/x11/SCsub2
-rw-r--r--platform/x11/context_gl_x11.cpp18
-rw-r--r--platform/x11/context_gl_x11.h3
-rw-r--r--platform/x11/detect.py41
-rw-r--r--platform/x11/detect_prime.cpp1
-rw-r--r--platform/x11/joypad_linux.cpp28
-rw-r--r--platform/x11/joypad_linux.h2
-rw-r--r--platform/x11/key_mapping_x11.cpp134
-rw-r--r--platform/x11/key_mapping_x11.h1
-rw-r--r--platform/x11/os_x11.cpp467
-rw-r--r--platform/x11/os_x11.h28
-rw-r--r--platform/x11/platform_config.h1
-rw-r--r--platform/x11/power_x11.cpp577
-rw-r--r--platform/x11/power_x11.h66
-rw-r--r--platform/x11/vulkan_context_x11.cpp57
-rw-r--r--platform/x11/vulkan_context_x11.h (renamed from platform/iphone/semaphore_iphone.h)33
156 files changed, 5423 insertions, 5341 deletions
diff --git a/platform/android/SCsub b/platform/android/SCsub
index 3ff5b8278a..5ca5ce548c 100644
--- a/platform/android/SCsub
+++ b/platform/android/SCsub
@@ -1,8 +1,5 @@
#!/usr/bin/env python
-from detect import get_ndk_version
-from distutils.version import LooseVersion
-
Import('env')
android_files = [
@@ -18,7 +15,10 @@ android_files = [
'java_class_wrapper.cpp',
'java_godot_wrapper.cpp',
'java_godot_io_wrapper.cpp',
- #'power_android.cpp'
+ 'jni_utils.cpp',
+ 'android_keys_utils.cpp',
+ 'vulkan/vk_renderer_jni.cpp',
+ 'plugin/godot_plugin_jni.cpp'
]
env_android = env.Clone()
diff --git a/platform/iphone/power_iphone.h b/platform/android/android_keys_utils.cpp
index 47a4508509..88874ba2c7 100644
--- a/platform/iphone/power_iphone.h
+++ b/platform/android/android_keys_utils.cpp
@@ -1,5 +1,5 @@
/*************************************************************************/
-/* power_iphone.h */
+/* android_keys_utils.cpp */
/*************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
@@ -28,26 +28,16 @@
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/
-#ifndef POWER_IPHONE_H
-#define POWER_IPHONE_H
+#include "android_keys_utils.h"
-#include <os/os.h>
+unsigned int android_get_keysym(unsigned int p_code) {
+ for (int i = 0; _ak_to_keycode[i].keysym != KEY_UNKNOWN; i++) {
-class PowerIphone {
-private:
- int nsecs_left;
- int percent_left;
- OS::PowerState power_state;
+ if (_ak_to_keycode[i].keycode == p_code) {
- bool UpdatePowerInfo();
+ return _ak_to_keycode[i].keysym;
+ }
+ }
-public:
- PowerIphone();
- virtual ~PowerIphone();
-
- OS::PowerState get_power_state();
- int get_power_seconds_left();
- int get_power_percent_left();
-};
-
-#endif // POWER_IPHONE_H
+ return KEY_UNKNOWN;
+}
diff --git a/platform/android/android_keys_utils.h b/platform/android/android_keys_utils.h
new file mode 100644
index 0000000000..f076688ac8
--- /dev/null
+++ b/platform/android/android_keys_utils.h
@@ -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
diff --git a/platform/android/api/api.cpp b/platform/android/api/api.cpp
index 2146c5409b..7efb545524 100644
--- a/platform/android/api/api.cpp
+++ b/platform/android/api/api.cpp
@@ -62,14 +62,14 @@ void JavaClassWrapper::_bind_methods() {
#if !defined(ANDROID_ENABLED)
-Variant JavaClass::call(const StringName &, const Variant **, int, Variant::CallError &) {
+Variant JavaClass::call(const StringName &, const Variant **, int, Callable::CallError &) {
return Variant();
}
JavaClass::JavaClass() {
}
-Variant JavaObject::call(const StringName &, const Variant **, int, Variant::CallError &) {
+Variant JavaObject::call(const StringName &, const Variant **, int, Callable::CallError &) {
return Variant();
}
diff --git a/platform/android/api/java_class_wrapper.h b/platform/android/api/java_class_wrapper.h
index 6c06d57ac1..d7322deb81 100644
--- a/platform/android/api/java_class_wrapper.h
+++ b/platform/android/api/java_class_wrapper.h
@@ -113,12 +113,12 @@ class JavaClass : public Reference {
break;
case ARG_TYPE_FLOAT | ARG_NUMBER_CLASS_BIT:
case ARG_TYPE_FLOAT:
- r_type = Variant::REAL;
+ r_type = Variant::FLOAT;
likelihood = 1.0;
break;
case ARG_TYPE_DOUBLE | ARG_NUMBER_CLASS_BIT:
case ARG_TYPE_DOUBLE:
- r_type = Variant::REAL;
+ r_type = Variant::FLOAT;
likelihood = 0.5;
break;
case ARG_TYPE_STRING: r_type = Variant::STRING; break;
@@ -126,49 +126,49 @@ class JavaClass : public Reference {
case ARG_ARRAY_BIT | ARG_TYPE_VOID: r_type = Variant::NIL; break;
case ARG_ARRAY_BIT | ARG_TYPE_BOOLEAN: r_type = Variant::ARRAY; break;
case ARG_ARRAY_BIT | ARG_TYPE_BYTE:
- r_type = Variant::POOL_BYTE_ARRAY;
+ r_type = Variant::PACKED_BYTE_ARRAY;
likelihood = 1.0;
break;
case ARG_ARRAY_BIT | ARG_TYPE_CHAR:
- r_type = Variant::POOL_BYTE_ARRAY;
+ r_type = Variant::PACKED_BYTE_ARRAY;
likelihood = 0.5;
break;
case ARG_ARRAY_BIT | ARG_TYPE_SHORT:
- r_type = Variant::POOL_INT_ARRAY;
+ r_type = Variant::PACKED_INT32_ARRAY;
likelihood = 0.3;
break;
case ARG_ARRAY_BIT | ARG_TYPE_INT:
- r_type = Variant::POOL_INT_ARRAY;
+ r_type = Variant::PACKED_INT32_ARRAY;
likelihood = 1.0;
break;
case ARG_ARRAY_BIT | ARG_TYPE_LONG:
- r_type = Variant::POOL_INT_ARRAY;
+ r_type = Variant::PACKED_INT32_ARRAY;
likelihood = 0.5;
break;
case ARG_ARRAY_BIT | ARG_TYPE_FLOAT:
- r_type = Variant::POOL_REAL_ARRAY;
+ r_type = Variant::PACKED_FLOAT32_ARRAY;
likelihood = 1.0;
break;
case ARG_ARRAY_BIT | ARG_TYPE_DOUBLE:
- r_type = Variant::POOL_REAL_ARRAY;
+ r_type = Variant::PACKED_FLOAT32_ARRAY;
likelihood = 0.5;
break;
- case ARG_ARRAY_BIT | ARG_TYPE_STRING: r_type = Variant::POOL_STRING_ARRAY; break;
+ case ARG_ARRAY_BIT | ARG_TYPE_STRING: r_type = Variant::PACKED_STRING_ARRAY; break;
case ARG_ARRAY_BIT | ARG_TYPE_CLASS: r_type = Variant::ARRAY; break;
}
}
_FORCE_INLINE_ static bool _convert_object_to_variant(JNIEnv *env, jobject obj, Variant &var, uint32_t p_sig);
- bool _call_method(JavaObject *p_instance, const StringName &p_method, const Variant **p_args, int p_argcount, Variant::CallError &r_error, Variant &ret);
+ bool _call_method(JavaObject *p_instance, const StringName &p_method, const Variant **p_args, int p_argcount, Callable::CallError &r_error, Variant &ret);
friend class JavaClassWrapper;
- Map<StringName, List<MethodInfo> > methods;
+ Map<StringName, List<MethodInfo>> methods;
jclass _class;
#endif
public:
- virtual Variant call(const StringName &p_method, const Variant **p_args, int p_argcount, Variant::CallError &r_error);
+ virtual Variant call(const StringName &p_method, const Variant **p_args, int p_argcount, Callable::CallError &r_error);
JavaClass();
};
@@ -185,7 +185,7 @@ class JavaObject : public Reference {
#endif
public:
- virtual Variant call(const StringName &p_method, const Variant **p_args, int p_argcount, Variant::CallError &r_error);
+ virtual Variant call(const StringName &p_method, const Variant **p_args, int p_argcount, Callable::CallError &r_error);
#ifdef ANDROID_ENABLED
JavaObject(const Ref<JavaClass> &p_base, jobject *p_instance);
@@ -198,7 +198,7 @@ class JavaClassWrapper : public Object {
GDCLASS(JavaClassWrapper, Object);
#ifdef ANDROID_ENABLED
- Map<String, Ref<JavaClass> > class_cache;
+ Map<String, Ref<JavaClass>> class_cache;
friend class JavaClass;
jclass activityClass;
jmethodID findClass;
diff --git a/platform/android/audio_driver_jandroid.cpp b/platform/android/audio_driver_jandroid.cpp
index 5a8e3b94da..e94dad9ac6 100644
--- a/platform/android/audio_driver_jandroid.cpp
+++ b/platform/android/audio_driver_jandroid.cpp
@@ -48,7 +48,7 @@ int AudioDriverAndroid::mix_rate = 44100;
bool AudioDriverAndroid::quit = false;
jobject AudioDriverAndroid::audioBuffer = NULL;
void *AudioDriverAndroid::audioBufferPinned = NULL;
-Mutex *AudioDriverAndroid::mutex = NULL;
+Mutex AudioDriverAndroid::mutex;
int32_t *AudioDriverAndroid::audioBuffer32 = NULL;
const char *AudioDriverAndroid::get_name() const {
@@ -58,7 +58,6 @@ const char *AudioDriverAndroid::get_name() const {
Error AudioDriverAndroid::init() {
- mutex = Mutex::create();
/*
// TODO: pass in/return a (Java) device ID, also whether we're opening for input or output
this->spec.samples = Android_JNI_OpenAudioDevice(this->spec.freq, this->spec.format == AUDIO_U8 ? 0 : 1, this->spec.channels, this->spec.samples);
@@ -133,7 +132,7 @@ void AudioDriverAndroid::thread_func(JNIEnv *env) {
int16_t *ptr = (int16_t *)audioBufferPinned;
int fc = audioBufferFrames;
- if (!s_ad->active || mutex->try_lock() != OK) {
+ if (!s_ad->active || mutex.try_lock() != OK) {
for (int i = 0; i < fc; i++) {
ptr[i] = 0;
@@ -143,7 +142,7 @@ void AudioDriverAndroid::thread_func(JNIEnv *env) {
s_ad->audio_server_process(fc / 2, audioBuffer32);
- mutex->unlock();
+ mutex.unlock();
for (int i = 0; i < fc; i++) {
@@ -167,14 +166,12 @@ AudioDriver::SpeakerMode AudioDriverAndroid::get_speaker_mode() const {
void AudioDriverAndroid::lock() {
- if (mutex)
- mutex->lock();
+ mutex.lock();
}
void AudioDriverAndroid::unlock() {
- if (mutex)
- mutex->unlock();
+ mutex.unlock();
}
void AudioDriverAndroid::finish() {
diff --git a/platform/android/audio_driver_jandroid.h b/platform/android/audio_driver_jandroid.h
index d3d1641c20..b1cc3f9aa0 100644
--- a/platform/android/audio_driver_jandroid.h
+++ b/platform/android/audio_driver_jandroid.h
@@ -37,7 +37,7 @@
class AudioDriverAndroid : public AudioDriver {
- static Mutex *mutex;
+ static Mutex mutex;
static AudioDriverAndroid *s_ad;
static jobject io;
static jmethodID _init_audio;
diff --git a/platform/android/audio_driver_opensl.cpp b/platform/android/audio_driver_opensl.cpp
index 6e9864c803..222120f81f 100644
--- a/platform/android/audio_driver_opensl.cpp
+++ b/platform/android/audio_driver_opensl.cpp
@@ -44,8 +44,8 @@ void AudioDriverOpenSL::_buffer_callback(
if (pause) {
mix = false;
- } else if (mutex) {
- mix = mutex->try_lock() == OK;
+ } else {
+ mix = mutex.try_lock() == OK;
}
if (mix) {
@@ -58,8 +58,8 @@ void AudioDriverOpenSL::_buffer_callback(
}
}
- if (mutex && mix)
- mutex->unlock();
+ if (mix)
+ mutex.unlock();
const int32_t *src_buff = mixdown_buffer;
@@ -107,7 +107,6 @@ Error AudioDriverOpenSL::init() {
void AudioDriverOpenSL::start() {
- mutex = Mutex::create();
active = false;
SLresult res;
@@ -329,14 +328,14 @@ AudioDriver::SpeakerMode AudioDriverOpenSL::get_speaker_mode() const {
void AudioDriverOpenSL::lock() {
- if (active && mutex)
- mutex->lock();
+ if (active)
+ mutex.lock();
}
void AudioDriverOpenSL::unlock() {
- if (active && mutex)
- mutex->unlock();
+ if (active)
+ mutex.unlock();
}
void AudioDriverOpenSL::finish() {
@@ -359,7 +358,6 @@ void AudioDriverOpenSL::set_pause(bool p_pause) {
AudioDriverOpenSL::AudioDriverOpenSL() {
s_ad = this;
- mutex = Mutex::create(); //NULL;
pause = false;
active = false;
}
diff --git a/platform/android/audio_driver_opensl.h b/platform/android/audio_driver_opensl.h
index 57d9b30af6..569e2aa54b 100644
--- a/platform/android/audio_driver_opensl.h
+++ b/platform/android/audio_driver_opensl.h
@@ -40,7 +40,7 @@
class AudioDriverOpenSL : public AudioDriver {
bool active;
- Mutex *mutex;
+ Mutex mutex;
enum {
diff --git a/platform/android/detect.py b/platform/android/detect.py
index 8b62360888..ff3ca0706c 100644
--- a/platform/android/detect.py
+++ b/platform/android/detect.py
@@ -164,7 +164,6 @@ def configure(env):
env.Tool('gcc')
env.use_windows_spawn_fix()
- mt_link = True
if (sys.platform.startswith("linux")):
host_subpath = "linux-x86_64"
elif (sys.platform.startswith("darwin")):
@@ -173,12 +172,8 @@ def configure(env):
if (platform.machine().endswith('64')):
host_subpath = "windows-x86_64"
else:
- mt_link = False
host_subpath = "windows"
- if env["android_arch"] == "arm64v8":
- mt_link = False
-
compiler_path = env["ANDROID_NDK_ROOT"] + "/toolchains/llvm/prebuilt/" + host_subpath + "/bin"
gcc_toolchain_path = env["ANDROID_NDK_ROOT"] + "/toolchains/" + target_subpath + "/prebuilt/" + host_subpath
tools_path = gcc_toolchain_path + "/" + abi_subpath + "/bin"
@@ -205,7 +200,6 @@ def configure(env):
env.Append(CPPFLAGS=["-isystem", env["ANDROID_NDK_ROOT"] + "/sources/cxx-stl/llvm-libc++/include"])
env.Append(CPPFLAGS=["-isystem", env["ANDROID_NDK_ROOT"] + "/sources/cxx-stl/llvm-libc++abi/include"])
- env.Append(CXXFLAGS=["-std=gnu++14"])
# Disable exceptions and rtti on non-tools (template) builds
if env['tools']:
diff --git a/platform/android/dir_access_jandroid.cpp b/platform/android/dir_access_jandroid.cpp
index f52b511522..ebcac884db 100644
--- a/platform/android/dir_access_jandroid.cpp
+++ b/platform/android/dir_access_jandroid.cpp
@@ -144,7 +144,7 @@ Error DirAccessJAndroid::change_dir(String p_dir) {
return OK;
}
-String DirAccessJAndroid::get_current_dir() {
+String DirAccessJAndroid::get_current_dir(bool p_include_drive) {
return "res://" + current_dir;
}
diff --git a/platform/android/dir_access_jandroid.h b/platform/android/dir_access_jandroid.h
index caeb4b58b9..8dab3e50ce 100644
--- a/platform/android/dir_access_jandroid.h
+++ b/platform/android/dir_access_jandroid.h
@@ -65,7 +65,7 @@ public:
virtual String get_drive(int p_drive);
virtual Error change_dir(String p_dir); ///< can be relative or absolute, return false on success
- virtual String get_current_dir(); ///< return current dir location
+ virtual String get_current_dir(bool p_include_drive = true); ///< return current dir location
virtual bool file_exists(String p_file);
virtual bool dir_exists(String p_dir);
diff --git a/platform/android/export/export.cpp b/platform/android/export/export.cpp
index b9968c08aa..e7d4bc6c51 100644
--- a/platform/android/export/export.cpp
+++ b/platform/android/export/export.cpp
@@ -257,7 +257,7 @@ class EditorExportPlatformAndroid : public EditorExportPlatform {
Vector<Device> devices;
volatile bool devices_changed;
- Mutex *device_lock;
+ Mutex device_lock;
Thread *device_thread;
volatile bool quit_request;
@@ -288,7 +288,7 @@ class EditorExportPlatformAndroid : public EditorExportPlatform {
ldevices.push_back(d);
}
- ea->device_lock->lock();
+ MutexLock lock(ea->device_lock);
bool different = false;
@@ -337,7 +337,7 @@ class EditorExportPlatformAndroid : public EditorExportPlatform {
Vector<String> props = dp.split("\n");
String vendor;
String device;
- d.description + "Device ID: " + d.id + "\n";
+ d.description = "Device ID: " + d.id + "\n";
d.api_level = 0;
for (int j = 0; j < props.size(); j++) {
@@ -381,11 +381,9 @@ class EditorExportPlatformAndroid : public EditorExportPlatform {
ea->devices = ndevices;
ea->devices_changed = true;
}
-
- ea->device_lock->unlock();
}
- uint64_t sleep = OS::get_singleton()->get_power_state() == OS::POWERSTATE_ON_BATTERY ? 1000 : 100;
+ uint64_t sleep = 200;
uint64_t wait = 3000000;
uint64_t time = OS::get_singleton()->get_ticks_usec();
while (OS::get_singleton()->get_ticks_usec() - time < wait) {
@@ -610,7 +608,7 @@ class EditorExportPlatformAndroid : public EditorExportPlatform {
static Error save_apk_so(void *p_userdata, const SharedObject &p_so) {
if (!p_so.path.get_file().begins_with("lib")) {
String err = "Android .so file names must start with \"lib\", but got: " + p_so.path;
- ERR_PRINTS(err);
+ ERR_PRINT(err);
return FAILED;
}
APKExportData *ed = (APKExportData *)p_userdata;
@@ -631,7 +629,7 @@ class EditorExportPlatformAndroid : public EditorExportPlatform {
if (!exported) {
String abis_string = String(" ").join(abis);
String err = "Cannot determine ABI for library \"" + p_so.path + "\". One of the supported ABIs must be used as a tag: " + abis_string;
- ERR_PRINTS(err);
+ ERR_PRINT(err);
return FAILED;
}
return OK;
@@ -642,9 +640,6 @@ class EditorExportPlatformAndroid : public EditorExportPlatform {
String dst_path = p_path.replace_first("res://", "assets/");
store_in_apk(ed, dst_path, p_data, _should_compress_asset(p_path, p_data) ? Z_DEFLATED : 0);
- if (ed->ep->step("File: " + p_path, 3 + p_file * 100 / p_total)) {
- return ERR_SKIP;
- }
return OK;
}
@@ -686,8 +681,6 @@ class EditorExportPlatformAndroid : public EditorExportPlatform {
int orientation = p_preset->get("screen/orientation");
- bool min_gles3 = ProjectSettings::get_singleton()->get("rendering/quality/driver/driver_name") == "GLES3" &&
- !ProjectSettings::get_singleton()->get("rendering/quality/driver/fallback_to_gles2");
bool screen_support_small = p_preset->get("screen/support_small");
bool screen_support_normal = p_preset->get("screen/support_normal");
bool screen_support_large = p_preset->get("screen/support_large");
@@ -695,6 +688,8 @@ class EditorExportPlatformAndroid : public EditorExportPlatform {
int xr_mode_index = p_preset->get("xr_features/xr_mode");
+ String plugins = p_preset->get("custom_template/plugins");
+
Vector<String> perms;
const char **aperms = android_perms;
@@ -706,7 +701,7 @@ class EditorExportPlatformAndroid : public EditorExportPlatform {
aperms++;
}
- PoolStringArray user_perms = p_preset->get("permissions/custom_permissions");
+ PackedStringArray user_perms = p_preset->get("permissions/custom_permissions");
for (int i = 0; i < user_perms.size(); i++) {
String user_perm = user_perms[i].strip_edges();
@@ -842,11 +837,6 @@ class EditorExportPlatformAndroid : public EditorExportPlatform {
}
}
- if (tname == "uses-feature" && attrname == "glEsVersion") {
-
- encode_uint32(min_gles3 ? 0x00030000 : 0x00020000, &p_manifest.write[iofs + 16]);
- }
-
// FIXME: `attr_value != 0xFFFFFFFF` below added as a stopgap measure for GH-32553,
// but the issue should be debugged further and properly addressed.
if (tname == "meta-data" && attrname == "name" && value == "xr_mode_metadata_name") {
@@ -863,6 +853,11 @@ class EditorExportPlatformAndroid : public EditorExportPlatform {
}
}
+ if (tname == "meta-data" && attrname == "value" && value == "custom_template_plugins_value") {
+ // Update the meta-data 'android:value' attribute with the list of enabled plugins.
+ string_table.write[attr_value] = plugins;
+ }
+
iofs += 20;
}
@@ -1320,11 +1315,11 @@ class EditorExportPlatformAndroid : public EditorExportPlatform {
working_image->resize(p_icon.dimensions, p_icon.dimensions, Image::Interpolation::INTERPOLATE_LANCZOS);
}
- PoolVector<uint8_t> png_buffer;
+ Vector<uint8_t> png_buffer;
Error err = PNGDriverCommon::image_to_png(working_image, png_buffer);
if (err == OK) {
p_data.resize(png_buffer.size());
- memcpy(p_data.ptrw(), png_buffer.read().ptr(), p_data.size());
+ memcpy(p_data.ptrw(), png_buffer.ptr(), p_data.size());
} else {
String err_str = String("Failed to convert resized icon (") + p_processing_file_name + ") to png.";
WARN_PRINT(err_str.utf8().get_data());
@@ -1353,11 +1348,10 @@ public:
String driver = ProjectSettings::get_singleton()->get("rendering/quality/driver/driver_name");
if (driver == "GLES2") {
r_features->push_back("etc");
- } else if (driver == "GLES3") {
+ }
+ // FIXME: Review what texture formats are used for Vulkan.
+ if (driver == "Vulkan") {
r_features->push_back("etc2");
- if (ProjectSettings::get_singleton()->get("rendering/quality/driver/fallback_to_gles2")) {
- r_features->push_back("etc");
- }
}
Vector<String> abis = get_enabled_abis(p_preset);
@@ -1376,6 +1370,7 @@ public:
r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "custom_template/debug", PROPERTY_HINT_GLOBAL_FILE, "*.apk"), ""));
r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "custom_template/release", PROPERTY_HINT_GLOBAL_FILE, "*.apk"), ""));
r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "custom_template/use_custom_build"), false));
+ r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "custom_template/plugins", PROPERTY_HINT_PLACEHOLDER_TEXT, "Plugin1,Plugin2,..."), ""));
r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "command_line/extra_args"), ""));
r_options->push_back(ExportOption(PropertyInfo(Variant::INT, "version/code", PROPERTY_HINT_RANGE, "1,4096,1,or_greater"), 1));
r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "version/name"), "1.0"));
@@ -1409,7 +1404,7 @@ public:
r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "architectures/" + abi), is_default));
}
- r_options->push_back(ExportOption(PropertyInfo(Variant::POOL_STRING_ARRAY, "permissions/custom_permissions"), PoolStringArray()));
+ r_options->push_back(ExportOption(PropertyInfo(Variant::PACKED_STRING_ARRAY, "permissions/custom_permissions"), PackedStringArray()));
const char **perms = android_perms;
while (*perms) {
@@ -1427,7 +1422,7 @@ public:
return "Android";
}
- virtual Ref<Texture> get_logo() const {
+ virtual Ref<Texture2D> get_logo() const {
return logo;
}
@@ -1443,11 +1438,8 @@ public:
virtual int get_options_count() const {
- device_lock->lock();
- int dc = devices.size();
- device_lock->unlock();
-
- return dc;
+ MutexLock lock(device_lock);
+ return devices.size();
}
virtual String get_options_tooltip() const {
@@ -1458,16 +1450,14 @@ public:
virtual String get_option_label(int p_index) const {
ERR_FAIL_INDEX_V(p_index, devices.size(), "");
- device_lock->lock();
- String s = devices[p_index].name;
- device_lock->unlock();
- return s;
+ MutexLock lock(device_lock);
+ return devices[p_index].name;
}
virtual String get_option_tooltip(int p_index) const {
ERR_FAIL_INDEX_V(p_index, devices.size(), "");
- device_lock->lock();
+ MutexLock lock(device_lock);
String s = devices[p_index].description;
if (devices.size() == 1) {
// Tooltip will be:
@@ -1475,7 +1465,6 @@ public:
// Description
s = devices[p_index].name + "\n\n" + s;
}
- device_lock->unlock();
return s;
}
@@ -1490,15 +1479,14 @@ public:
return ERR_UNCONFIGURED;
}
- device_lock->lock();
+ MutexLock lock(device_lock);
EditorProgress ep("run", "Running on " + devices[p_device].name, 3);
String adb = EditorSettings::get_singleton()->get("export/android/adb");
// Export_temp APK.
- if (ep.step("Exporting APK", 0)) {
- device_lock->unlock();
+ if (ep.step("Exporting APK...", 0)) {
return ERR_SKIP;
}
@@ -1513,7 +1501,6 @@ public:
#define CLEANUP_AND_RETURN(m_err) \
{ \
DirAccess::remove_file_or_error(tmp_export_path); \
- device_lock->unlock(); \
return m_err; \
}
@@ -1547,7 +1534,7 @@ public:
}
print_line("Installing to device (please wait...): " + devices[p_device].name);
- if (ep.step("Installing to device (please wait...)", 2)) {
+ if (ep.step("Installing to device, please wait...", 2)) {
CLEANUP_AND_RETURN(ERR_SKIP);
}
@@ -1614,7 +1601,7 @@ public:
}
}
- if (ep.step("Running on Device...", 3)) {
+ if (ep.step("Running on device...", 3)) {
CLEANUP_AND_RETURN(ERR_SKIP);
}
args.clear();
@@ -1642,7 +1629,7 @@ public:
#undef CLEANUP_AND_RETURN
}
- virtual Ref<Texture> get_run_icon() const {
+ virtual Ref<Texture2D> get_run_icon() const {
return run_icon;
}
@@ -1764,260 +1751,6 @@ public:
return list;
}
- void _update_custom_build_project() {
-
- DirAccessRef da = DirAccess::open("res://android");
-
- ERR_FAIL_COND_MSG(!da, "Cannot open directory 'res://android'.");
- Map<String, List<String> > directory_paths;
- Map<String, List<String> > manifest_sections;
- Map<String, List<String> > gradle_sections;
- da->list_dir_begin();
- String d = da->get_next();
- while (d != String()) {
-
- if (!d.begins_with(".") && d != "build" && da->current_is_dir()) { //a dir and not the build dir
- //add directories found
- DirAccessRef ds = DirAccess::open(String("res://android").plus_file(d));
- if (ds) {
- ds->list_dir_begin();
- String sd = ds->get_next();
- while (sd != String()) {
-
- if (!sd.begins_with(".") && ds->current_is_dir()) {
- String key = sd.to_upper();
- if (!directory_paths.has(key)) {
- directory_paths[key] = List<String>();
- }
- String path = ProjectSettings::get_singleton()->get_resource_path().plus_file("android").plus_file(d).plus_file(sd);
- directory_paths[key].push_back(path);
- print_line("Add: " + sd + ":" + path);
- }
-
- sd = ds->get_next();
- }
- ds->list_dir_end();
- }
- //parse manifest
- {
- FileAccessRef f = FileAccess::open(String("res://android").plus_file(d).plus_file("AndroidManifest.conf"), FileAccess::READ);
- if (f) {
-
- String section;
- while (!f->eof_reached()) {
- String l = f->get_line();
- String k = l.strip_edges();
- if (k.begins_with("[")) {
- section = k.substr(1, k.length() - 2).strip_edges().to_upper();
- print_line("Section: " + section);
- } else if (k != String()) {
- if (!manifest_sections.has(section)) {
- manifest_sections[section] = List<String>();
- }
- manifest_sections[section].push_back(l);
- }
- }
-
- f->close();
- }
- }
- //parse gradle
- {
- FileAccessRef f = FileAccess::open(String("res://android").plus_file(d).plus_file("gradle.conf"), FileAccess::READ);
- if (f) {
-
- String section;
- while (!f->eof_reached()) {
- String l = f->get_line().strip_edges();
- String k = l.strip_edges();
- if (k.begins_with("[")) {
- section = k.substr(1, k.length() - 2).strip_edges().to_upper();
- print_line("Section: " + section);
- } else if (k != String()) {
- if (!gradle_sections.has(section)) {
- gradle_sections[section] = List<String>();
- }
- gradle_sections[section].push_back(l);
- }
- }
- }
- }
- }
- d = da->get_next();
- }
- da->list_dir_end();
-
- { //fix gradle build
-
- String new_file;
- {
- FileAccessRef f = FileAccess::open("res://android/build/build.gradle", FileAccess::READ);
- if (f) {
-
- while (!f->eof_reached()) {
- String l = f->get_line();
-
- if (l.begins_with("//CHUNK_")) {
- String text = l.replace_first("//CHUNK_", "");
- int begin_pos = text.find("_BEGIN");
- if (begin_pos != -1) {
- text = text.substr(0, begin_pos);
- text = text.to_upper(); //just in case
-
- String end_marker = "//CHUNK_" + text + "_END";
- size_t pos = f->get_position();
- bool found = false;
- while (!f->eof_reached()) {
- l = f->get_line();
- if (l.begins_with(end_marker)) {
- found = true;
- break;
- }
- }
-
- new_file += "//CHUNK_" + text + "_BEGIN\n";
-
- if (!found) {
- ERR_PRINTS("No end marker found in build.gradle for chunk: " + text);
- f->seek(pos);
- } else {
-
- //add chunk lines
- if (gradle_sections.has(text)) {
- for (List<String>::Element *E = gradle_sections[text].front(); E; E = E->next()) {
- new_file += E->get() + "\n";
- }
- }
- new_file += end_marker + "\n";
- }
- } else {
- new_file += l + "\n"; //pass line by
- }
- } else if (l.begins_with("//DIR_")) {
- String text = l.replace_first("//DIR_", "");
- int begin_pos = text.find("_BEGIN");
- if (begin_pos != -1) {
- text = text.substr(0, begin_pos);
- text = text.to_upper(); //just in case
-
- String end_marker = "//DIR_" + text + "_END";
- size_t pos = f->get_position();
- bool found = false;
- while (!f->eof_reached()) {
- l = f->get_line();
- if (l.begins_with(end_marker)) {
- found = true;
- break;
- }
- }
-
- new_file += "//DIR_" + text + "_BEGIN\n";
-
- if (!found) {
- ERR_PRINTS("No end marker found in build.gradle for dir: " + text);
- f->seek(pos);
- } else {
- //add chunk lines
- if (directory_paths.has(text)) {
- for (List<String>::Element *E = directory_paths[text].front(); E; E = E->next()) {
- new_file += ",'" + E->get().replace("'", "\'") + "'";
- new_file += "\n";
- }
- }
- new_file += end_marker + "\n";
- }
- } else {
- new_file += l + "\n"; //pass line by
- }
-
- } else {
- new_file += l + "\n";
- }
- }
- }
- }
-
- FileAccessRef f = FileAccess::open("res://android/build/build.gradle", FileAccess::WRITE);
- f->store_string(new_file);
- f->close();
- }
-
- { //fix manifest
-
- String new_file;
- {
- FileAccessRef f = FileAccess::open("res://android/build/AndroidManifest.xml", FileAccess::READ);
- if (f) {
-
- while (!f->eof_reached()) {
- String l = f->get_line();
-
- if (l.begins_with("<!--CHUNK_")) {
- String text = l.replace_first("<!--CHUNK_", "");
- int begin_pos = text.find("_BEGIN-->");
- if (begin_pos != -1) {
- text = text.substr(0, begin_pos);
- text = text.to_upper(); //just in case
-
- String end_marker = "<!--CHUNK_" + text + "_END-->";
- size_t pos = f->get_position();
- bool found = false;
- while (!f->eof_reached()) {
- l = f->get_line();
- if (l.begins_with(end_marker)) {
- found = true;
- break;
- }
- }
-
- new_file += "<!--CHUNK_" + text + "_BEGIN-->\n";
-
- if (!found) {
- ERR_PRINTS("No end marker found in AndroidManifest.xml for chunk: " + text);
- f->seek(pos);
- } else {
- //add chunk lines
- if (manifest_sections.has(text)) {
- for (List<String>::Element *E = manifest_sections[text].front(); E; E = E->next()) {
- new_file += E->get() + "\n";
- }
- }
- new_file += end_marker + "\n";
- }
- } else {
- new_file += l + "\n"; //pass line by
- }
-
- } else if (l.strip_edges().begins_with("<application")) {
- String last_tag = "android:icon=\"@mipmap/icon\"";
- int last_tag_pos = l.find(last_tag);
- if (last_tag_pos == -1) {
- ERR_PRINTS("Not adding application attributes as the expected tag was not found in '<application': " + last_tag);
- new_file += l + "\n";
- } else {
- String base = l.substr(0, last_tag_pos + last_tag.length());
- if (manifest_sections.has("application_attribs")) {
- for (List<String>::Element *E = manifest_sections["application_attribs"].front(); E; E = E->next()) {
- String to_add = E->get().strip_edges();
- base += " " + to_add + " ";
- }
- }
- base += ">\n";
- new_file += base;
- }
- } else {
- new_file += l + "\n";
- }
- }
- }
- }
-
- FileAccessRef f = FileAccess::open("res://android/build/AndroidManifest.xml", FileAccess::WRITE);
- f->store_string(new_file);
- f->close();
- }
- }
-
virtual Error export_project(const Ref<EditorExportPreset> &p_preset, bool p_debug, const String &p_path, int p_flags = 0) {
ExportNotifier notifier(*this, p_preset, p_debug, p_path, p_flags);
@@ -2046,8 +1779,6 @@ public:
ERR_FAIL_COND_V_MSG(sdk_path == "", ERR_UNCONFIGURED, "Android SDK path must be configured in Editor Settings at 'export/android/custom_build_sdk_path'.");
- _update_custom_build_project();
-
OS::get_singleton()->set_environment("ANDROID_HOME", sdk_path); //set and overwrite if required
String build_command;
@@ -2058,14 +1789,18 @@ public:
#endif
String build_path = ProjectSettings::get_singleton()->get_resource_path().plus_file("android/build");
+ String plugins_dir = ProjectSettings::get_singleton()->get_resource_path().plus_file("android/plugins");
build_command = build_path.plus_file(build_command);
String package_name = get_package_name(p_preset->get("package/unique_name"));
+ String plugins = p_preset->get("custom_template/plugins");
List<String> cmdline;
cmdline.push_back("build");
cmdline.push_back("-Pexport_package_name=" + package_name); // argument to specify the package name.
+ cmdline.push_back("-Pcustom_template_plugins_dir=" + plugins_dir); // argument to specify the plugins directory.
+ cmdline.push_back("-Pcustom_template_plugins=" + plugins); // argument to specify the list of plugins to enable.
cmdline.push_back("-p"); // argument to specify the start directory.
cmdline.push_back(build_path); // start directory.
/*{ used for debug
@@ -2119,7 +1854,7 @@ public:
FileAccess *src_f = NULL;
zlib_filefunc_def io = zipio_create_io_from_file(&src_f);
- if (ep.step("Creating APK", 0)) {
+ if (ep.step("Creating APK...", 0)) {
return ERR_SKIP;
}
@@ -2281,7 +2016,7 @@ public:
ret = unzGoToNextFile(pkg);
}
- if (ep.step("Adding Files...", 1)) {
+ if (ep.step("Adding files...", 1)) {
CLEANUP_AND_RETURN(ERR_SKIP);
}
Error err = OK;
@@ -2581,7 +2316,6 @@ public:
run_icon.instance();
run_icon->create_from_image(img);
- device_lock = Mutex::create();
devices_changed = true;
quit_request = false;
device_thread = Thread::create(_device_poll_thread, this);
@@ -2590,7 +2324,6 @@ public:
~EditorExportPlatformAndroid() {
quit_request = true;
Thread::wait_to_finish(device_thread);
- memdelete(device_lock);
memdelete(device_thread);
}
};
diff --git a/platform/android/java/app/AndroidManifest.xml b/platform/android/java/app/AndroidManifest.xml
index 7e9ce70d80..cc480d1c84 100644
--- a/platform/android/java/app/AndroidManifest.xml
+++ b/platform/android/java/app/AndroidManifest.xml
@@ -6,28 +6,21 @@
android:versionName="1.0"
android:installLocation="auto" >
- <!-- Adding custom text to the manifest is fine, but do it outside the custom USER and APPLICATION BEGIN/END comments, -->
- <!-- as that gets rewritten. -->
-
<supports-screens
android:smallScreens="true"
android:normalScreens="true"
android:largeScreens="true"
android:xlargeScreens="true" />
- <!-- glEsVersion is modified by the exporter, changing this value here has no effect. -->
<uses-feature
android:glEsVersion="0x00020000"
android:required="true" />
-<!-- Custom user permissions XML added by add-ons. It's recommended to add them from the export preset, though. -->
-<!--CHUNK_USER_PERMISSIONS_BEGIN-->
-<!--CHUNK_USER_PERMISSIONS_END-->
-
- <!-- Any tag in this line after android:icon will be erased when doing custom builds. -->
- <!-- If you want to add tags manually, do before it. -->
- <!-- WARNING: This should stay on a single line until the parsing code is improved. See GH-32414. -->
- <application android:label="@string/godot_project_name_string" android:allowBackup="false" tools:ignore="GoogleAppIndexingWarning" android:icon="@mipmap/icon" >
+ <application
+ android:label="@string/godot_project_name_string"
+ android:allowBackup="false"
+ tools:ignore="GoogleAppIndexingWarning"
+ android:icon="@mipmap/icon" >
<!-- The following metadata values are replaced when Godot exports, modifying them here has no effect. -->
<!-- Do these changes in the export preset. Adding new ones is fine. -->
@@ -37,6 +30,11 @@
android:name="xr_mode_metadata_name"
android:value="xr_mode_metadata_value" />
+ <!-- Metadata populated at export time and used by Godot to figure out which plugins must be enabled. -->
+ <meta-data
+ android:name="custom_template_plugins"
+ android:value="custom_template_plugins_value"/>
+
<activity
android:name=".GodotApp"
android:label="@string/godot_project_name_string"
@@ -53,10 +51,6 @@
</intent-filter>
</activity>
-<!-- Custom application XML added by add-ons. -->
-<!--CHUNK_APPLICATION_BEGIN-->
-<!--CHUNK_APPLICATION_END-->
-
</application>
</manifest>
diff --git a/platform/android/java/app/build.gradle b/platform/android/java/app/build.gradle
index 2e4f2ffab0..1a3bb77670 100644
--- a/platform/android/java/app/build.gradle
+++ b/platform/android/java/app/build.gradle
@@ -1,7 +1,4 @@
// Gradle build config for Godot Engine's Android port.
-//
-// Do not remove/modify comments ending with BEGIN/END, they are used to inject
-// addon-specific configuration.
apply from: 'config.gradle'
buildscript {
@@ -10,13 +7,10 @@ buildscript {
repositories {
google()
jcenter()
-//CHUNK_BUILDSCRIPT_REPOSITORIES_BEGIN
-//CHUNK_BUILDSCRIPT_REPOSITORIES_END
}
dependencies {
classpath libraries.androidGradlePlugin
-//CHUNK_BUILDSCRIPT_DEPENDENCIES_BEGIN
-//CHUNK_BUILDSCRIPT_DEPENDENCIES_END
+ classpath libraries.kotlinGradlePlugin
}
}
@@ -27,24 +21,35 @@ allprojects {
mavenCentral()
google()
jcenter()
-//CHUNK_ALLPROJECTS_REPOSITORIES_BEGIN
-//CHUNK_ALLPROJECTS_REPOSITORIES_END
}
}
dependencies {
implementation libraries.supportCoreUtils
+ implementation libraries.kotlinStdLib
+ implementation libraries.v4Support
if (rootProject.findProject(":lib")) {
implementation project(":lib")
+ } else if (rootProject.findProject(":godot:lib")) {
+ implementation project(":godot:lib")
} else {
// Custom build mode. In this scenario this project is the only one around and the Godot
// library is available through the pre-generated godot-lib.*.aar android archive files.
debugImplementation fileTree(dir: 'libs/debug', include: ['*.jar', '*.aar'])
releaseImplementation fileTree(dir: 'libs/release', include: ['*.jar', '*.aar'])
}
-//CHUNK_DEPENDENCIES_BEGIN
-//CHUNK_DEPENDENCIES_END
+
+ // Godot prebuilt plugins
+ implementation fileTree(dir: 'libs/plugins', include: ["GodotPayment*.aar"])
+
+ // Godot user plugins dependencies
+ String pluginsDir = getGodotPluginsDirectory()
+ String[] pluginsBinaries = getGodotPluginsBinaries()
+ if (pluginsDir != null && !pluginsDir.isEmpty() &&
+ pluginsBinaries != null && pluginsBinaries.size() > 0) {
+ implementation fileTree(dir: pluginsDir, include: pluginsBinaries)
+ }
}
android {
@@ -56,8 +61,6 @@ android {
applicationId getExportPackageName()
minSdkVersion versions.minSdk
targetSdkVersion versions.targetSdk
-//CHUNK_ANDROID_DEFAULTCONFIG_BEGIN
-//CHUNK_ANDROID_DEFAULTCONFIG_END
}
lintOptions {
@@ -68,6 +71,7 @@ android {
packagingOptions {
exclude 'META-INF/LICENSE'
exclude 'META-INF/NOTICE'
+ doNotStrip '**/*.so'
}
// Both signing and zip-aligning will be done at export time
@@ -79,37 +83,13 @@ android {
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
- java.srcDirs = [
- 'src'
-//DIR_SRC_BEGIN
-//DIR_SRC_END
- ]
- res.srcDirs = [
- 'res'
-//DIR_RES_BEGIN
-//DIR_RES_END
- ]
- aidl.srcDirs = [
- 'aidl'
-//DIR_AIDL_BEGIN
-//DIR_AIDL_END
- ]
- assets.srcDirs = [
- 'assets'
-//DIR_ASSETS_BEGIN
-//DIR_ASSETS_END
- ]
+ java.srcDirs = ['src']
+ res.srcDirs = ['res']
+ aidl.srcDirs = ['aidl']
+ assets.srcDirs = ['assets']
}
- debug.jniLibs.srcDirs = [
- 'libs/debug'
-//DIR_JNI_DEBUG_BEGIN
-//DIR_JNI_DEBUG_END
- ]
- release.jniLibs.srcDirs = [
- 'libs/release'
-//DIR_JNI_RELEASE_BEGIN
-//DIR_JNI_RELEASE_END
- ]
+ debug.jniLibs.srcDirs = ['libs/debug']
+ release.jniLibs.srcDirs = ['libs/release']
}
applicationVariants.all { variant ->
@@ -118,6 +98,3 @@ android {
}
}
}
-
-//CHUNK_GLOBAL_BEGIN
-//CHUNK_GLOBAL_END
diff --git a/platform/android/java/app/config.gradle b/platform/android/java/app/config.gradle
index 5550d3099d..eaaefcbccb 100644
--- a/platform/android/java/app/config.gradle
+++ b/platform/android/java/app/config.gradle
@@ -1,24 +1,66 @@
ext.versions = [
- androidGradlePlugin : '3.4.2',
- compileSdk : 28,
- minSdk : 18,
- targetSdk : 28,
- buildTools : '28.0.3',
- supportCoreUtils : '28.0.0'
+ androidGradlePlugin: '3.6.0',
+ compileSdk : 29,
+ minSdk : 18,
+ targetSdk : 29,
+ buildTools : '29.0.1',
+ supportCoreUtils : '28.0.0',
+ kotlinVersion : '1.3.61',
+ v4Support : '28.0.0'
]
ext.libraries = [
- androidGradlePlugin : "com.android.tools.build:gradle:$versions.androidGradlePlugin",
- supportCoreUtils : "com.android.support:support-core-utils:$versions.supportCoreUtils"
+ androidGradlePlugin: "com.android.tools.build:gradle:$versions.androidGradlePlugin",
+ supportCoreUtils : "com.android.support:support-core-utils:$versions.supportCoreUtils",
+ kotlinGradlePlugin : "org.jetbrains.kotlin:kotlin-gradle-plugin:$versions.kotlinVersion",
+ kotlinStdLib : "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$versions.kotlinVersion",
+ v4Support : "com.android.support:support-v4:$versions.v4Support"
]
ext.getExportPackageName = { ->
- // Retrieve the app id from the project property set by the Godot build command.
- String appId = project.hasProperty("export_package_name") ? project.property("export_package_name") : ""
- // Check if the app id is valid, otherwise use the default.
- if (appId == null || appId.isEmpty()) {
- appId = "com.godot.game"
- }
- return appId
+ // Retrieve the app id from the project property set by the Godot build command.
+ String appId = project.hasProperty("export_package_name") ? project.property("export_package_name") : ""
+ // Check if the app id is valid, otherwise use the default.
+ if (appId == null || appId.isEmpty()) {
+ appId = "com.godot.game"
+ }
+ return appId
+}
+
+/**
+ * Parse the project properties for the 'custom_template_plugins' property and return
+ * their binaries for inclusion in the build dependencies.
+ *
+ * The listed plugins must have their binaries in the project plugins directory.
+ */
+ext.getGodotPluginsBinaries = { ->
+ String[] binDeps = []
+
+ // Retrieve the list of enabled plugins.
+ if (project.hasProperty("custom_template_plugins")) {
+ String pluginsList = project.property("custom_template_plugins")
+ if (pluginsList != null && !pluginsList.trim().isEmpty()) {
+ for (String plugin : pluginsList.split(",")) {
+ binDeps += plugin.trim() + "*.aar"
+ }
+ }
+ }
+
+ return binDeps
+}
+
+/**
+ * Parse the project properties for the 'custom_template_plugins_dir' property and return
+ * its value.
+ *
+ * The returned value is the directory containing user plugins.
+ */
+ext.getGodotPluginsDirectory = { ->
+ // The plugins directory is provided by the 'custom_template_plugins_dir' property.
+ String pluginsDir = project.hasProperty("custom_template_plugins_dir")
+ ? project.property("custom_template_plugins_dir")
+ : ""
+
+ return pluginsDir
}
diff --git a/platform/android/java/build.gradle b/platform/android/java/build.gradle
index 2052017888..865b61956c 100644
--- a/platform/android/java/build.gradle
+++ b/platform/android/java/build.gradle
@@ -9,6 +9,7 @@ buildscript {
}
dependencies {
classpath libraries.androidGradlePlugin
+ classpath libraries.kotlinGradlePlugin
}
}
@@ -24,7 +25,7 @@ ext {
sconsExt = org.gradle.internal.os.OperatingSystem.current().isWindows() ? ".bat" : ""
supportedAbis = ["armv7", "arm64v8", "x86", "x86_64"]
- supportedTargets = ['release':"release", 'debug':"release_debug"]
+ supportedTargets = ["release", "debug"]
// Used by gradle to specify which architecture to build for by default when running `./gradlew build`.
// This command is usually used by Android Studio.
@@ -64,10 +65,10 @@ task copyReleaseBinaryToBin(type: Copy) {
}
/**
- * Copy the Godot android library archive debug file into the app debug libs directory.
+ * Copy the Godot android library archive debug file into the app module debug libs directory.
* Depends on the library build task to ensure the AAR file is generated prior to copying.
*/
-task copyDebugAAR(type: Copy) {
+task copyDebugAARToAppModule(type: Copy) {
dependsOn ':lib:assembleDebug'
from('lib/build/outputs/aar')
into('app/libs/debug')
@@ -75,16 +76,45 @@ task copyDebugAAR(type: Copy) {
}
/**
- * Copy the Godot android library archive release file into the app release libs directory.
+ * Copy the Godot android library archive debug file into the root bin directory.
* Depends on the library build task to ensure the AAR file is generated prior to copying.
*/
-task copyReleaseAAR(type: Copy) {
+task copyDebugAARToBin(type: Copy) {
+ dependsOn ':lib:assembleDebug'
+ from('lib/build/outputs/aar')
+ into(binDir)
+ include('godot-lib.debug.aar')
+}
+
+/**
+ * Copy the Godot android library archive release file into the app module release libs directory.
+ * Depends on the library build task to ensure the AAR file is generated prior to copying.
+ */
+task copyReleaseAARToAppModule(type: Copy) {
dependsOn ':lib:assembleRelease'
from('lib/build/outputs/aar')
into('app/libs/release')
include('godot-lib.release.aar')
}
+task copyGodotPaymentPluginToAppModule(type: Copy) {
+ dependsOn ':plugins:godotpayment:assembleRelease'
+ from('plugins/godotpayment/build/outputs/aar')
+ into('app/libs/plugins')
+ include('GodotPayment.release.aar')
+}
+
+/**
+ * Copy the Godot android library archive release file into the root bin directory.
+ * Depends on the library build task to ensure the AAR file is generated prior to copying.
+ */
+task copyReleaseAARToBin(type: Copy) {
+ dependsOn ':lib:assembleRelease'
+ from('lib/build/outputs/aar')
+ into(binDir)
+ include('godot-lib.release.aar')
+}
+
/**
* Generate Godot custom build template by zipping the source files from the app directory, as well
* as the AAR files generated by 'copyDebugAAR' and 'copyReleaseAAR'.
@@ -95,7 +125,7 @@ task zipCustomBuild(type: Zip) {
doFirst {
logger.lifecycle("Generating Godot custom build template")
}
- from(fileTree(dir: 'app', excludes: ['**/build/**', '**/.gradle/**', '**/*.iml']), fileTree(dir: '.', includes: ['gradle.properties','gradlew', 'gradlew.bat', 'gradle/**']))
+ from(fileTree(dir: 'app', excludes: ['**/build/**', '**/.gradle/**', '**/*.iml']), fileTree(dir: '.', includes: ['gradle.properties', 'gradlew', 'gradlew.bat', 'gradle/**']))
include '**/*'
archiveName 'android_source.zip'
destinationDir(file(binDir))
@@ -106,23 +136,28 @@ task zipCustomBuild(type: Zip) {
*/
task generateGodotTemplates(type: GradleBuild) {
// We exclude these gradle tasks so we can run the scons command manually.
- for (String buildType : supportedTargets.keySet()) {
+ for (String buildType : supportedTargets) {
startParameter.excludedTaskNames += ":lib:" + getSconsTaskName(buildType)
}
- tasks = []
+ tasks = ["copyGodotPaymentPluginToAppModule"]
// Only build the apks and aar files for which we have native shared libraries.
- for (String target : supportedTargets.keySet()) {
+ for (String target : supportedTargets) {
File targetLibs = new File("lib/libs/" + target)
- if (targetLibs != null && targetLibs.isDirectory()) {
- File[] targetLibsContents = targetLibs.listFiles()
- if (targetLibsContents != null && targetLibsContents.length > 0) {
- // Copy the generated aar library files to the custom build directory.
- tasks += "copy" + target.capitalize() + "AAR"
- // Copy the prebuilt binary templates to the bin directory.
- tasks += "copy" + target.capitalize() + "BinaryToBin"
- }
+ if (targetLibs != null
+ && targetLibs.isDirectory()
+ && targetLibs.listFiles() != null
+ && targetLibs.listFiles().length > 0) {
+ String capitalizedTarget = target.capitalize()
+ // Copy the generated aar library files to the custom build directory.
+ tasks += "copy" + capitalizedTarget + "AARToAppModule"
+ // Copy the generated aar library files to the bin directory.
+ tasks += "copy" + capitalizedTarget + "AARToBin"
+ // Copy the prebuilt binary templates to the bin directory.
+ tasks += "copy" + capitalizedTarget + "BinaryToBin"
+ } else {
+ logger.lifecycle("No native shared libs for target $target. Skipping build.")
}
}
@@ -133,20 +168,28 @@ task generateGodotTemplates(type: GradleBuild) {
* Clean the generated artifacts.
*/
task cleanGodotTemplates(type: Delete) {
- // Delete the generated native libs
- delete("lib/libs")
+ // Delete the generated native libs
+ delete("lib/libs")
+
+ // Delete the library generated AAR files
+ delete("lib/build/outputs/aar")
+
+ // Delete the godotpayment libs directory contents
+ delete("plugins/godotpayment/libs")
- // Delete the library generated AAR files
- delete("lib/build/outputs/aar")
+ // Delete the generated godotpayment aar
+ delete("plugins/godotpayment/build/outputs/aar")
- // Delete the app libs directory contents
- delete("app/libs")
+ // Delete the app libs directory contents
+ delete("app/libs")
- // Delete the generated binary apks
- delete("app/build/outputs/apk")
+ // Delete the generated binary apks
+ delete("app/build/outputs/apk")
- // Delete the Godot templates in the Godot bin directory
- delete("$binDir/android_debug.apk")
- delete("$binDir/android_release.apk")
- delete("$binDir/android_source.zip")
+ // Delete the Godot templates in the Godot bin directory
+ delete("$binDir/android_debug.apk")
+ delete("$binDir/android_release.apk")
+ delete("$binDir/android_source.zip")
+ delete("$binDir/godot-lib.debug.aar")
+ delete("$binDir/godot-lib.release.aar")
}
diff --git a/platform/android/java/gradle/wrapper/gradle-wrapper.properties b/platform/android/java/gradle/wrapper/gradle-wrapper.properties
index bf50265715..f56b0f6a5e 100644
--- a/platform/android/java/gradle/wrapper/gradle-wrapper.properties
+++ b/platform/android/java/gradle/wrapper/gradle-wrapper.properties
@@ -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
diff --git a/platform/android/java/lib/build.gradle b/platform/android/java/lib/build.gradle
index eb97484b9c..062f91e08e 100644
--- a/platform/android/java/lib/build.gradle
+++ b/platform/android/java/lib/build.gradle
@@ -2,6 +2,8 @@ apply plugin: 'com.android.library'
dependencies {
implementation libraries.supportCoreUtils
+ implementation libraries.kotlinStdLib
+ implementation libraries.v4Support
}
def pathToRootDir = "../../../../"
@@ -24,6 +26,7 @@ android {
packagingOptions {
exclude 'META-INF/LICENSE'
exclude 'META-INF/NOTICE'
+ doNotStrip '**/*.so'
}
sourceSets {
@@ -54,7 +57,7 @@ android {
// files is only setup for editing support.
gradle.startParameter.excludedTaskNames += taskPrefix + "externalNativeBuild" + buildType
- def releaseTarget = supportedTargets[buildType.toLowerCase()]
+ def releaseTarget = buildType.toLowerCase()
if (releaseTarget == null || releaseTarget == "") {
throw new GradleException("Invalid build type: " + buildType)
}
diff --git a/platform/android/java/lib/src/org/godotengine/godot/Godot.java b/platform/android/java/lib/src/org/godotengine/godot/Godot.java
index 2f6a93fbb1..4e605f9950 100644
--- a/platform/android/java/lib/src/org/godotengine/godot/Godot.java
+++ b/platform/android/java/lib/src/org/godotengine/godot/Godot.java
@@ -61,8 +61,11 @@ import android.os.Messenger;
import android.os.VibrationEffect;
import android.os.Vibrator;
import android.provider.Settings.Secure;
+import android.support.annotation.CallSuper;
import android.support.annotation.Keep;
+import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
+import android.support.v4.app.FragmentActivity;
import android.view.Display;
import android.view.KeyEvent;
import android.view.MotionEvent;
@@ -87,22 +90,19 @@ import com.google.android.vending.expansion.downloader.IStub;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;
-import java.lang.reflect.Method;
import java.security.MessageDigest;
-import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
import java.util.Locale;
-import javax.microedition.khronos.opengles.GL10;
import org.godotengine.godot.input.GodotEditText;
-import org.godotengine.godot.payments.PaymentsManager;
+import org.godotengine.godot.plugin.GodotPlugin;
+import org.godotengine.godot.plugin.GodotPluginRegistry;
import org.godotengine.godot.utils.GodotNetUtils;
import org.godotengine.godot.utils.PermissionsUtil;
import org.godotengine.godot.xr.XRMode;
-public abstract class Godot extends Activity implements SensorEventListener, IDownloaderClient {
+public abstract class Godot extends FragmentActivity implements SensorEventListener, IDownloaderClient {
- static final int MAX_SINGLETONS = 64;
private IStub mDownloaderClientStub;
private TextView mStatusText;
private TextView mProgressFraction;
@@ -126,8 +126,7 @@ public abstract class Godot extends Activity implements SensorEventListener, IDo
private boolean activityResumed;
private int mState;
- // Used to dispatch events to the main thread.
- private final Handler mainThreadHandler = new Handler(Looper.getMainLooper());
+ private GodotPluginRegistry pluginRegistry;
static private Intent mCurrentIntent;
@@ -154,83 +153,6 @@ public abstract class Godot extends Activity implements SensorEventListener, IDo
mPauseButton.setText(stringResourceID);
}
- static public class SingletonBase {
-
- protected void registerClass(String p_name, String[] p_methods) {
-
- GodotLib.singleton(p_name, this);
-
- Class clazz = getClass();
- Method[] methods = clazz.getDeclaredMethods();
- for (Method method : methods) {
- boolean found = false;
-
- for (String s : p_methods) {
- if (s.equals(method.getName())) {
- found = true;
- break;
- }
- }
- if (!found)
- continue;
-
- List<String> ptr = new ArrayList<String>();
-
- Class[] paramTypes = method.getParameterTypes();
- for (Class c : paramTypes) {
- ptr.add(c.getName());
- }
-
- String[] pt = new String[ptr.size()];
- ptr.toArray(pt);
-
- GodotLib.method(p_name, method.getName(), method.getReturnType().getName(), pt);
- }
-
- Godot.singletons[Godot.singleton_count++] = this;
- }
-
- /**
- * Invoked once during the Godot Android initialization process after creation of the
- * {@link GodotView} view.
- * <p>
- * This method should be overridden by descendants of this class that would like to add
- * their view/layout to the Godot view hierarchy.
- *
- * @return the view to be included; null if no views should be included.
- */
- @Nullable
- protected View onMainCreateView(Activity activity) {
- return null;
- }
-
- protected void onMainActivityResult(int requestCode, int resultCode, Intent data) {
- }
-
- protected void onMainRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) {
- }
-
- protected void onMainPause() {}
- protected void onMainResume() {}
- protected void onMainDestroy() {}
- protected boolean onMainBackPressed() { return false; }
-
- protected void onGLDrawFrame(GL10 gl) {}
- protected void onGLSurfaceChanged(GL10 gl, int width, int height) {} // singletons will always miss first onGLSurfaceChanged call
- //protected void onGLSurfaceCreated(GL10 gl, EGLConfig config) {} // singletons won't be ready until first GodotLib.step()
-
- public void registerMethods() {}
- }
-
- /*
- protected List<SingletonBase> singletons = new ArrayList<SingletonBase>();
- protected void instanceSingleton(SingletonBase s) {
-
- s.registerMethods();
- singletons.add(s);
- }
- */
-
private String[] command_line;
private boolean use_apk_expansion;
@@ -246,35 +168,27 @@ public abstract class Godot extends Activity implements SensorEventListener, IDo
public static GodotIO io;
public static GodotNetUtils netUtils;
- static SingletonBase[] singletons = new SingletonBase[MAX_SINGLETONS];
- static int singleton_count = 0;
-
public interface ResultCallback {
public void callback(int requestCode, int resultCode, Intent data);
}
public ResultCallback result_callback;
- private PaymentsManager mPaymentsManager = null;
-
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
- if (requestCode == PaymentsManager.REQUEST_CODE_FOR_PURCHASE) {
- mPaymentsManager.processPurchaseResponse(resultCode, data);
- } else if (result_callback != null) {
+ if (result_callback != null) {
result_callback.callback(requestCode, resultCode, data);
result_callback = null;
- };
-
- for (int i = 0; i < singleton_count; i++) {
+ }
- singletons[i].onMainActivityResult(requestCode, resultCode, data);
+ for (GodotPlugin plugin : pluginRegistry.getAllPlugins()) {
+ plugin.onMainActivityResult(requestCode, resultCode, data);
}
- };
+ }
@Override
public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) {
- for (int i = 0; i < singleton_count; i++) {
- singletons[i].onMainRequestPermissionsResult(requestCode, permissions, grantResults);
+ for (GodotPlugin plugin : pluginRegistry.getAllPlugins()) {
+ plugin.onMainRequestPermissionsResult(requestCode, permissions, grantResults);
}
for (int i = 0; i < permissions.length; i++) {
@@ -283,12 +197,20 @@ public abstract class Godot extends Activity implements SensorEventListener, IDo
};
/**
+ * Invoked on the GL thread when the Godot main loop has started.
+ */
+ @CallSuper
+ protected void onGLGodotMainLoopStarted() {
+ for (GodotPlugin plugin : pluginRegistry.getAllPlugins()) {
+ plugin.onGLGodotMainLoopStarted();
+ }
+ }
+
+ /**
* Used by the native code (java_godot_lib_jni.cpp) to complete initialization of the GLSurfaceView view and renderer.
*/
@Keep
private void onVideoInit() {
- boolean use_gl3 = getGLESVersionCode() >= 0x00030000;
-
final FrameLayout layout = new FrameLayout(this);
layout.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
setContentView(layout);
@@ -299,19 +221,18 @@ public abstract class Godot extends Activity implements SensorEventListener, IDo
// ...add to FrameLayout
layout.addView(edittext);
- mView = new GodotView(this, xrMode, use_gl3, use_32_bits, use_debug_opengl);
+ mView = new GodotView(this, xrMode, use_32_bits, use_debug_opengl);
layout.addView(mView, new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
edittext.setView(mView);
io.setEdit(edittext);
- final Godot godot = this;
mView.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
@Override
public void onGlobalLayout() {
Point fullSize = new Point();
- godot.getWindowManager().getDefaultDisplay().getSize(fullSize);
+ getWindowManager().getDefaultDisplay().getSize(fullSize);
Rect gameSize = new Rect();
- godot.mView.getWindowVisibleDisplayFrame(gameSize);
+ mView.getWindowVisibleDisplayFrame(gameSize);
final int keyboardHeight = fullSize.y - gameSize.bottom;
GodotLib.setVirtualKeyboardHeight(keyboardHeight);
@@ -323,23 +244,23 @@ public abstract class Godot extends Activity implements SensorEventListener, IDo
@Override
public void run() {
GodotLib.setup(current_command_line);
- setKeepScreenOn("True".equals(GodotLib.getGlobal("display/window/energy_saving/keep_screen_on")));
- // The Godot Android plugins are setup on completion of GodotLib.setup
- mainThreadHandler.post(new Runnable() {
- @Override
- public void run() {
- // Include the non-null views returned in the Godot view hierarchy.
- for (int i = 0; i < singleton_count; i++) {
- View view = singletons[i].onMainCreateView(Godot.this);
- if (view != null) {
- layout.addView(view);
- }
- }
- }
- });
+ // Must occur after GodotLib.setup has completed.
+ for (GodotPlugin plugin : pluginRegistry.getAllPlugins()) {
+ plugin.onGLRegisterPluginWithGodotNative();
+ }
+
+ setKeepScreenOn("True".equals(GodotLib.getGlobal("display/window/energy_saving/keep_screen_on")));
}
});
+
+ // Include the returned non-null views in the Godot view hierarchy.
+ for (GodotPlugin plugin : pluginRegistry.getAllPlugins()) {
+ View pluginView = plugin.onMainCreateView(this);
+ if (pluginView != null) {
+ layout.addView(pluginView);
+ }
+ }
}
public void setKeepScreenOn(final boolean p_enabled) {
@@ -519,8 +440,6 @@ public abstract class Godot extends Activity implements SensorEventListener, IDo
result_callback = null;
- mPaymentsManager = PaymentsManager.createManager(this).initService();
-
godot_initialized = true;
}
@@ -537,6 +456,7 @@ public abstract class Godot extends Activity implements SensorEventListener, IDo
Window window = getWindow();
window.addFlags(WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON);
mClipboard = (ClipboardManager)getSystemService(Context.CLIPBOARD_SERVICE);
+ pluginRegistry = GodotPluginRegistry.initializePluginRegistry(this);
//check for apk expansion API
if (true) {
@@ -676,9 +596,8 @@ public abstract class Godot extends Activity implements SensorEventListener, IDo
@Override
protected void onDestroy() {
- if (mPaymentsManager != null) mPaymentsManager.destroy();
- for (int i = 0; i < singleton_count; i++) {
- singletons[i].onMainDestroy();
+ for (GodotPlugin plugin : pluginRegistry.getAllPlugins()) {
+ plugin.onMainDestroy();
}
GodotLib.ondestroy(this);
@@ -705,8 +624,8 @@ public abstract class Godot extends Activity implements SensorEventListener, IDo
mSensorManager.unregisterListener(this);
- for (int i = 0; i < singleton_count; i++) {
- singletons[i].onMainPause();
+ for (GodotPlugin plugin : pluginRegistry.getAllPlugins()) {
+ plugin.onMainPause();
}
}
@@ -757,9 +676,8 @@ public abstract class Godot extends Activity implements SensorEventListener, IDo
View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY);
}
- for (int i = 0; i < singleton_count; i++) {
-
- singletons[i].onMainResume();
+ for (GodotPlugin plugin : pluginRegistry.getAllPlugins()) {
+ plugin.onMainResume();
}
}
@@ -852,8 +770,8 @@ public abstract class Godot extends Activity implements SensorEventListener, IDo
public void onBackPressed() {
boolean shouldQuit = true;
- for (int i = 0; i < singleton_count; i++) {
- if (singletons[i].onMainBackPressed()) {
+ for (GodotPlugin plugin : pluginRegistry.getAllPlugins()) {
+ if (plugin.onMainBackPressed()) {
shouldQuit = false;
}
}
@@ -868,6 +786,17 @@ public abstract class Godot extends Activity implements SensorEventListener, IDo
}
}
+ /**
+ * Queue a runnable to be run on the GL thread.
+ * <p>
+ * This must be called after the GL thread has started.
+ */
+ public final void runOnGLThread(@NonNull Runnable action) {
+ if (mView != null) {
+ mView.queueEvent(action);
+ }
+ }
+
private void forceQuit() {
System.exit(0);
}
@@ -992,8 +921,8 @@ public abstract class Godot extends Activity implements SensorEventListener, IDo
int keyCode;
if ((keyCode = cc[i]) != 0) {
// Simulate key down and up...
- GodotLib.key(0, keyCode, true);
- GodotLib.key(0, keyCode, false);
+ GodotLib.key(0, 0, keyCode, true);
+ GodotLib.key(0, 0, keyCode, false);
}
}
}
@@ -1001,10 +930,6 @@ public abstract class Godot extends Activity implements SensorEventListener, IDo
return true;
}
- public PaymentsManager getPaymentsManager() {
- return mPaymentsManager;
- }
-
public boolean requestPermission(String p_name) {
return PermissionsUtil.requestPermission(p_name, this);
}
diff --git a/platform/android/java/lib/src/org/godotengine/godot/GodotLib.java b/platform/android/java/lib/src/org/godotengine/godot/GodotLib.java
index e0b46673ba..89a65aea24 100644
--- a/platform/android/java/lib/src/org/godotengine/godot/GodotLib.java
+++ b/platform/android/java/lib/src/org/godotengine/godot/GodotLib.java
@@ -136,7 +136,7 @@ public class GodotLib {
/**
* Forward regular key events from the main thread to the GL thread.
*/
- public static native void key(int p_scancode, int p_unicode_char, boolean p_pressed);
+ public static native void key(int p_keycode, int p_scancode, int p_unicode_char, boolean p_pressed);
/**
* Forward game device's key events from the main thread to the GL thread.
@@ -176,22 +176,6 @@ public class GodotLib {
public static native void audio();
/**
- * Used to setup a {@link org.godotengine.godot.Godot.SingletonBase} instance.
- * @param p_name Name of the instance.
- * @param p_object Reference to the singleton instance.
- */
- public static native void singleton(String p_name, Object p_object);
-
- /**
- * Used to complete registration of the {@link org.godotengine.godot.Godot.SingletonBase} instance's methods.
- * @param p_sname Name of the instance
- * @param p_name Name of the method to register
- * @param p_ret Return type of the registered method
- * @param p_params Method parameters types
- */
- public static native void method(String p_sname, String p_name, String p_ret, String[] p_params);
-
- /**
* Used to access Godot global properties.
* @param p_key Property key
* @return String value of the property
diff --git a/platform/android/java/lib/src/org/godotengine/godot/GodotRenderer.java b/platform/android/java/lib/src/org/godotengine/godot/GodotRenderer.java
index 26fa033f12..ee9a2aee4f 100644
--- a/platform/android/java/lib/src/org/godotengine/godot/GodotRenderer.java
+++ b/platform/android/java/lib/src/org/godotengine/godot/GodotRenderer.java
@@ -30,9 +30,12 @@
package org.godotengine.godot;
+import android.content.Context;
import android.opengl.GLSurfaceView;
import javax.microedition.khronos.egl.EGLConfig;
import javax.microedition.khronos.opengles.GL10;
+import org.godotengine.godot.plugin.GodotPlugin;
+import org.godotengine.godot.plugin.GodotPluginRegistry;
import org.godotengine.godot.utils.GLUtils;
/**
@@ -40,8 +43,13 @@ import org.godotengine.godot.utils.GLUtils;
*/
class GodotRenderer implements GLSurfaceView.Renderer {
+ private final GodotPluginRegistry pluginRegistry;
private boolean activityJustResumed = false;
+ GodotRenderer() {
+ this.pluginRegistry = GodotPluginRegistry.getPluginRegistry();
+ }
+
public void onDrawFrame(GL10 gl) {
if (activityJustResumed) {
GodotLib.onRendererResumed();
@@ -49,21 +57,23 @@ class GodotRenderer implements GLSurfaceView.Renderer {
}
GodotLib.step();
- for (int i = 0; i < Godot.singleton_count; i++) {
- Godot.singletons[i].onGLDrawFrame(gl);
+ for (GodotPlugin plugin : pluginRegistry.getAllPlugins()) {
+ plugin.onGLDrawFrame(gl);
}
}
public void onSurfaceChanged(GL10 gl, int width, int height) {
-
GodotLib.resize(width, height);
- for (int i = 0; i < Godot.singleton_count; i++) {
- Godot.singletons[i].onGLSurfaceChanged(gl, width, height);
+ for (GodotPlugin plugin : pluginRegistry.getAllPlugins()) {
+ plugin.onGLSurfaceChanged(gl, width, height);
}
}
public void onSurfaceCreated(GL10 gl, EGLConfig config) {
GodotLib.newcontext(GLUtils.use_32);
+ for (GodotPlugin plugin : pluginRegistry.getAllPlugins()) {
+ plugin.onGLSurfaceCreated(gl, config);
+ }
}
void onActivityResumed() {
diff --git a/platform/android/java/lib/src/org/godotengine/godot/GodotView.java b/platform/android/java/lib/src/org/godotengine/godot/GodotView.java
index f938583082..8d3c2ae319 100644
--- a/platform/android/java/lib/src/org/godotengine/godot/GodotView.java
+++ b/platform/android/java/lib/src/org/godotengine/godot/GodotView.java
@@ -73,9 +73,8 @@ public class GodotView extends GLSurfaceView {
private final GestureDetector detector;
private final GodotRenderer godotRenderer;
- public GodotView(Godot activity, XRMode xrMode, boolean p_use_gl3, boolean p_use_32_bits, boolean p_use_debug_opengl) {
+ public GodotView(Godot activity, XRMode xrMode, boolean p_use_32_bits, boolean p_use_debug_opengl) {
super(activity);
- GLUtils.use_gl3 = p_use_gl3;
GLUtils.use_32 = p_use_32_bits;
GLUtils.use_debug_opengl = p_use_debug_opengl;
diff --git a/platform/android/java/lib/src/org/godotengine/godot/input/GodotEditText.java b/platform/android/java/lib/src/org/godotengine/godot/input/GodotEditText.java
index 44998aa6c0..e901b4b36d 100644
--- a/platform/android/java/lib/src/org/godotengine/godot/input/GodotEditText.java
+++ b/platform/android/java/lib/src/org/godotengine/godot/input/GodotEditText.java
@@ -123,7 +123,7 @@ public class GodotEditText extends EditText {
}
private void setMaxInputLength(EditText p_edit_text, int p_max_input_length) {
- if (p_max_input_length >= 0) {
+ if (p_max_input_length > 0) {
InputFilter[] filters = new InputFilter[1];
filters[0] = new InputFilter.LengthFilter(p_max_input_length);
p_edit_text.setFilters(filters);
diff --git a/platform/android/java/lib/src/org/godotengine/godot/input/GodotInputHandler.java b/platform/android/java/lib/src/org/godotengine/godot/input/GodotInputHandler.java
index b2b88088e8..e00ca86c41 100644
--- a/platform/android/java/lib/src/org/godotengine/godot/input/GodotInputHandler.java
+++ b/platform/android/java/lib/src/org/godotengine/godot/input/GodotInputHandler.java
@@ -98,11 +98,12 @@ public class GodotInputHandler implements InputDeviceListener {
});
}
} else {
+ final int scanCode = event.getScanCode();
final int chr = event.getUnicodeChar(0);
queueEvent(new Runnable() {
@Override
public void run() {
- GodotLib.key(keyCode, chr, false);
+ GodotLib.key(keyCode, scanCode, chr, false);
}
});
};
@@ -143,11 +144,12 @@ public class GodotInputHandler implements InputDeviceListener {
});
}
} else {
+ final int scanCode = event.getScanCode();
final int chr = event.getUnicodeChar(0);
queueEvent(new Runnable() {
@Override
public void run() {
- GodotLib.key(keyCode, chr, true);
+ GodotLib.key(keyCode, scanCode, chr, true);
}
});
};
diff --git a/platform/android/java/lib/src/org/godotengine/godot/input/GodotTextInputWrapper.java b/platform/android/java/lib/src/org/godotengine/godot/input/GodotTextInputWrapper.java
index 3a154f1bf3..18f2d57661 100644
--- a/platform/android/java/lib/src/org/godotengine/godot/input/GodotTextInputWrapper.java
+++ b/platform/android/java/lib/src/org/godotengine/godot/input/GodotTextInputWrapper.java
@@ -91,8 +91,8 @@ public class GodotTextInputWrapper implements TextWatcher, OnEditorActionListene
@Override
public void run() {
for (int i = 0; i < count; ++i) {
- GodotLib.key(KeyEvent.KEYCODE_DEL, 0, true);
- GodotLib.key(KeyEvent.KEYCODE_DEL, 0, false);
+ GodotLib.key(KeyEvent.KEYCODE_DEL, KeyEvent.KEYCODE_DEL, 0, true);
+ GodotLib.key(KeyEvent.KEYCODE_DEL, KeyEvent.KEYCODE_DEL, 0, false);
}
}
});
@@ -110,8 +110,13 @@ public class GodotTextInputWrapper implements TextWatcher, OnEditorActionListene
@Override
public void run() {
for (int i = 0; i < count; ++i) {
- GodotLib.key(0, newChars[i], true);
- GodotLib.key(0, newChars[i], false);
+ int key = newChars[i];
+ if (key == '\n') {
+ // Return keys are handled through action events
+ continue;
+ }
+ GodotLib.key(0, 0, key, true);
+ GodotLib.key(0, 0, key, false);
}
}
});
@@ -127,15 +132,20 @@ public class GodotTextInputWrapper implements TextWatcher, OnEditorActionListene
public void run() {
for (int i = 0; i < characters.length(); i++) {
final int ch = characters.codePointAt(i);
- GodotLib.key(0, ch, true);
- GodotLib.key(0, ch, false);
+ GodotLib.key(0, 0, ch, true);
+ GodotLib.key(0, 0, ch, false);
}
}
});
}
- if (pActionID == EditorInfo.IME_ACTION_DONE) {
+ if (pActionID == EditorInfo.IME_NULL) {
+ // Enter key has been pressed
+ GodotLib.key(KeyEvent.KEYCODE_ENTER, KeyEvent.KEYCODE_ENTER, 0, true);
+ GodotLib.key(KeyEvent.KEYCODE_ENTER, KeyEvent.KEYCODE_ENTER, 0, false);
+
this.mView.requestFocus();
+ return true;
}
return false;
}
diff --git a/platform/android/java/lib/src/org/godotengine/godot/plugin/GodotPlugin.java b/platform/android/java/lib/src/org/godotengine/godot/plugin/GodotPlugin.java
new file mode 100644
index 0000000000..d5bf4fc70e
--- /dev/null
+++ b/platform/android/java/lib/src/org/godotengine/godot/plugin/GodotPlugin.java
@@ -0,0 +1,256 @@
+/*************************************************************************/
+/* GodotPlugin.java */
+/*************************************************************************/
+/* This file is part of: */
+/* GODOT ENGINE */
+/* https://godotengine.org */
+/*************************************************************************/
+/* Copyright (c) 2007-2019 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2014-2019 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. */
+/*************************************************************************/
+
+package org.godotengine.godot.plugin;
+
+import android.app.Activity;
+import android.content.Intent;
+import android.support.annotation.NonNull;
+import android.support.annotation.Nullable;
+import android.view.View;
+import java.lang.reflect.Method;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+import java.util.Set;
+import javax.microedition.khronos.egl.EGLConfig;
+import javax.microedition.khronos.opengles.GL10;
+import org.godotengine.godot.Godot;
+
+/**
+ * Base class for the Godot Android plugins.
+ * <p>
+ * A Godot Android plugin is a regular Android library packaged as an aar archive file with the following caveats:
+ * <p>
+ * - The library must have a dependency on the Godot Android library (godot-lib.aar).
+ * A stable version is available for each release.
+ * <p>
+ * - The library must include a <meta-data> tag in its manifest file setup as follow:
+ * <meta-data android:name="org.godotengine.plugin.v1.[PluginName]" android:value="[plugin.init.ClassFullName]" />
+ * Where:
+ * - 'PluginName' is the name of the plugin.
+ * - 'plugin.init.ClassFullName' is the full name (package + class name) of the plugin class
+ * extending {@link GodotPlugin}.
+ *
+ * A plugin can also define and provide c/c++ gdnative libraries and nativescripts for the target
+ * app/game to leverage.
+ * The shared library for the gdnative library will be automatically bundled by the aar build
+ * system.
+ * Godot '*.gdnlib' and '*.gdns' resource files must however be manually defined in the project
+ * 'assets' directory. The recommended path for these resources in the 'assets' directory should be:
+ * 'godot/plugin/v1/[PluginName]/'
+ */
+public abstract class GodotPlugin {
+
+ private final Godot godot;
+
+ public GodotPlugin(Godot godot) {
+ this.godot = godot;
+ }
+
+ /**
+ * Provides access to the Godot engine.
+ */
+ protected Godot getGodot() {
+ return godot;
+ }
+
+ /**
+ * Register the plugin with Godot native code.
+ */
+ public final void onGLRegisterPluginWithGodotNative() {
+ nativeRegisterSingleton(getPluginName());
+
+ Class clazz = getClass();
+ Method[] methods = clazz.getDeclaredMethods();
+ for (Method method : methods) {
+ boolean found = false;
+
+ for (String s : getPluginMethods()) {
+ if (s.equals(method.getName())) {
+ found = true;
+ break;
+ }
+ }
+ if (!found)
+ continue;
+
+ List<String> ptr = new ArrayList<String>();
+
+ Class[] paramTypes = method.getParameterTypes();
+ for (Class c : paramTypes) {
+ ptr.add(c.getName());
+ }
+
+ String[] pt = new String[ptr.size()];
+ ptr.toArray(pt);
+
+ nativeRegisterMethod(getPluginName(), method.getName(), method.getReturnType().getName(), pt);
+ }
+
+ // Get the list of gdnative libraries to register.
+ Set<String> gdnativeLibrariesPaths = getPluginGDNativeLibrariesPaths();
+ if (!gdnativeLibrariesPaths.isEmpty()) {
+ nativeRegisterGDNativeLibraries(gdnativeLibrariesPaths.toArray(new String[0]));
+ }
+ }
+
+ /**
+ * Invoked once during the Godot Android initialization process after creation of the
+ * {@link org.godotengine.godot.GodotView} view.
+ * <p>
+ * This method should be overridden by descendants of this class that would like to add
+ * their view/layout to the Godot view hierarchy.
+ *
+ * @return the view to be included; null if no views should be included.
+ */
+ @Nullable
+ public View onMainCreateView(Activity activity) {
+ return null;
+ }
+
+ /**
+ * @see Activity#onActivityResult(int, int, Intent)
+ */
+ public void onMainActivityResult(int requestCode, int resultCode, Intent data) {
+ }
+
+ /**
+ * @see Activity#onRequestPermissionsResult(int, String[], int[])
+ */
+ public void onMainRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) {
+ }
+
+ /**
+ * @see Activity#onPause()
+ */
+ public void onMainPause() {}
+
+ /**
+ * @see Activity#onResume()
+ */
+ public void onMainResume() {}
+
+ /**
+ * @see Activity#onDestroy()
+ */
+ public void onMainDestroy() {}
+
+ /**
+ * @see Activity#onBackPressed()
+ */
+ public boolean onMainBackPressed() { return false; }
+
+ /**
+ * Invoked on the GL thread when the Godot main loop has started.
+ */
+ public void onGLGodotMainLoopStarted() {}
+
+ /**
+ * Invoked once per frame on the GL thread after the frame is drawn.
+ */
+ public void onGLDrawFrame(GL10 gl) {}
+
+ /**
+ * Called on the GL thread after the surface is created and whenever the OpenGL ES surface size
+ * changes.
+ */
+ public void onGLSurfaceChanged(GL10 gl, int width, int height) {}
+
+ /**
+ * Called on the GL thread when the surface is created or recreated.
+ */
+ public void onGLSurfaceCreated(GL10 gl, EGLConfig config) {}
+
+ /**
+ * Returns the name of the plugin.
+ * <p>
+ * This value must match the one listed in the plugin '<meta-data>' manifest entry.
+ */
+ @NonNull
+ public abstract String getPluginName();
+
+ /**
+ * Returns the list of methods to be exposed to Godot.
+ */
+ @NonNull
+ public abstract List<String> getPluginMethods();
+
+ /**
+ * Returns the paths for the plugin's gdnative libraries.
+ *
+ * The paths must be relative to the 'assets' directory and point to a '*.gdnlib' file.
+ */
+ @NonNull
+ protected Set<String> getPluginGDNativeLibrariesPaths() {
+ return Collections.emptySet();
+ }
+
+ /**
+ * Runs the specified action on the UI thread. If the current thread is the UI
+ * thread, then the action is executed immediately. If the current thread is
+ * not the UI thread, the action is posted to the event queue of the UI thread.
+ *
+ * @param action the action to run on the UI thread
+ */
+ protected void runOnUiThread(Runnable action) {
+ godot.runOnUiThread(action);
+ }
+
+ /**
+ * Queue the specified action to be run on the GL thread.
+ *
+ * @param action the action to run on the GL thread
+ */
+ protected void runOnGLThread(Runnable action) {
+ godot.runOnGLThread(action);
+ }
+
+ /**
+ * Used to setup a {@link GodotPlugin} instance.
+ * @param p_name Name of the instance.
+ */
+ private native void nativeRegisterSingleton(String p_name);
+
+ /**
+ * Used to complete registration of the {@link GodotPlugin} instance's methods.
+ * @param p_sname Name of the instance
+ * @param p_name Name of the method to register
+ * @param p_ret Return type of the registered method
+ * @param p_params Method parameters types
+ */
+ private native void nativeRegisterMethod(String p_sname, String p_name, String p_ret, String[] p_params);
+
+ /**
+ * Used to register gdnative libraries bundled by the plugin.
+ * @param gdnlibPaths Paths to the libraries relative to the 'assets' directory.
+ */
+ private native void nativeRegisterGDNativeLibraries(String[] gdnlibPaths);
+}
diff --git a/platform/android/java/lib/src/org/godotengine/godot/plugin/GodotPluginRegistry.java b/platform/android/java/lib/src/org/godotengine/godot/plugin/GodotPluginRegistry.java
new file mode 100644
index 0000000000..b6d949b7bf
--- /dev/null
+++ b/platform/android/java/lib/src/org/godotengine/godot/plugin/GodotPluginRegistry.java
@@ -0,0 +1,199 @@
+/*************************************************************************/
+/* GodotPluginRegistry.java */
+/*************************************************************************/
+/* This file is part of: */
+/* GODOT ENGINE */
+/* https://godotengine.org */
+/*************************************************************************/
+/* Copyright (c) 2007-2019 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2014-2019 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. */
+/*************************************************************************/
+
+package org.godotengine.godot.plugin;
+
+import android.content.pm.ApplicationInfo;
+import android.content.pm.PackageManager;
+import android.os.Bundle;
+import android.support.annotation.Nullable;
+import android.text.TextUtils;
+import android.util.Log;
+import java.lang.reflect.Constructor;
+import java.lang.reflect.InvocationTargetException;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.HashSet;
+import java.util.Set;
+import java.util.concurrent.ConcurrentHashMap;
+import org.godotengine.godot.Godot;
+
+/**
+ * Registry used to load and access the registered Godot Android plugins.
+ */
+public final class GodotPluginRegistry {
+
+ private static final String TAG = GodotPluginRegistry.class.getSimpleName();
+
+ private static final String GODOT_PLUGIN_V1_NAME_PREFIX = "org.godotengine.plugin.v1.";
+
+ /**
+ * Name for the metadata containing the list of Godot plugins to enable.
+ */
+ private static final String GODOT_ENABLED_PLUGINS_LABEL = "custom_template_plugins";
+
+ private static GodotPluginRegistry instance;
+ private final ConcurrentHashMap<String, GodotPlugin> registry;
+
+ private GodotPluginRegistry(Godot godot) {
+ registry = new ConcurrentHashMap<>();
+ loadPlugins(godot);
+ }
+
+ /**
+ * Retrieve the plugin tied to the given plugin name.
+ * @param pluginName Name of the plugin
+ * @return {@link GodotPlugin} handle if it exists, null otherwise.
+ */
+ @Nullable
+ public GodotPlugin getPlugin(String pluginName) {
+ return registry.get(pluginName);
+ }
+
+ /**
+ * Retrieve the full set of loaded plugins.
+ */
+ public Collection<GodotPlugin> getAllPlugins() {
+ return registry.values();
+ }
+
+ /**
+ * Parse the manifest file and load all included Godot Android plugins.
+ * <p>
+ * A plugin manifest entry is a '<meta-data>' tag setup as described in the {@link GodotPlugin}
+ * documentation.
+ *
+ * @param godot Godot instance
+ * @return A singleton instance of {@link GodotPluginRegistry}. This ensures that only one instance
+ * of each Godot Android plugins is available at runtime.
+ */
+ public static GodotPluginRegistry initializePluginRegistry(Godot godot) {
+ if (instance == null) {
+ instance = new GodotPluginRegistry(godot);
+ }
+
+ return instance;
+ }
+
+ /**
+ * Return the plugin registry if it's initialized.
+ * Throws a {@link IllegalStateException} exception if not.
+ *
+ * @throws IllegalStateException if {@link GodotPluginRegistry#initializePluginRegistry(Godot)} has not been called prior to calling this method.
+ */
+ public static GodotPluginRegistry getPluginRegistry() throws IllegalStateException {
+ if (instance == null) {
+ throw new IllegalStateException("Plugin registry hasn't been initialized.");
+ }
+
+ return instance;
+ }
+
+ private void loadPlugins(Godot godot) {
+ try {
+ ApplicationInfo appInfo = godot
+ .getPackageManager()
+ .getApplicationInfo(godot.getPackageName(), PackageManager.GET_META_DATA);
+ Bundle metaData = appInfo.metaData;
+ if (metaData == null || metaData.isEmpty()) {
+ return;
+ }
+
+ // When using the Godot editor for building and exporting the apk, this is used to check
+ // which plugins to enable since the custom build template may contain prebuilt plugins.
+ // When using a custom process to generate the apk, the metadata is not needed since
+ // it's assumed that the developer is aware of the dependencies included in the apk.
+ final Set<String> enabledPluginsSet;
+ if (metaData.containsKey(GODOT_ENABLED_PLUGINS_LABEL)) {
+ String enabledPlugins = metaData.getString(GODOT_ENABLED_PLUGINS_LABEL, "");
+ String[] enabledPluginsList = enabledPlugins.split(",");
+ if (enabledPluginsList.length == 0) {
+ // No plugins to enable. Aborting early.
+ return;
+ }
+
+ enabledPluginsSet = new HashSet<>();
+ for (String enabledPlugin : enabledPluginsList) {
+ enabledPluginsSet.add(enabledPlugin.trim());
+ }
+ } else {
+ enabledPluginsSet = null;
+ }
+
+ int godotPluginV1NamePrefixLength = GODOT_PLUGIN_V1_NAME_PREFIX.length();
+ for (String metaDataName : metaData.keySet()) {
+ // Parse the meta-data looking for entry with the Godot plugin name prefix.
+ if (metaDataName.startsWith(GODOT_PLUGIN_V1_NAME_PREFIX)) {
+ String pluginName = metaDataName.substring(godotPluginV1NamePrefixLength).trim();
+ if (enabledPluginsSet != null && !enabledPluginsSet.contains(pluginName)) {
+ Log.w(TAG, "Plugin " + pluginName + " is listed in the dependencies but is not enabled.");
+ continue;
+ }
+
+ // Retrieve the plugin class full name.
+ String pluginHandleClassFullName = metaData.getString(metaDataName);
+ if (!TextUtils.isEmpty(pluginHandleClassFullName)) {
+ try {
+ // Attempt to create the plugin init class via reflection.
+ @SuppressWarnings("unchecked")
+ Class<GodotPlugin> pluginClass = (Class<GodotPlugin>)Class
+ .forName(pluginHandleClassFullName);
+ Constructor<GodotPlugin> pluginConstructor = pluginClass
+ .getConstructor(Godot.class);
+ GodotPlugin pluginHandle = pluginConstructor.newInstance(godot);
+
+ // Load the plugin initializer into the registry using the plugin name
+ // as key.
+ if (!pluginName.equals(pluginHandle.getPluginName())) {
+ Log.w(TAG,
+ "Meta-data plugin name does not match the value returned by the plugin handle: " + pluginName + " =/= " + pluginHandle.getPluginName());
+ }
+ registry.put(pluginName, pluginHandle);
+ } catch (ClassNotFoundException e) {
+ Log.w(TAG, "Unable to load Godot plugin " + pluginName, e);
+ } catch (IllegalAccessException e) {
+ Log.w(TAG, "Unable to load Godot plugin " + pluginName, e);
+ } catch (InstantiationException e) {
+ Log.w(TAG, "Unable to load Godot plugin " + pluginName, e);
+ } catch (NoSuchMethodException e) {
+ Log.w(TAG, "Unable to load Godot plugin " + pluginName, e);
+ } catch (InvocationTargetException e) {
+ Log.w(TAG, "Unable to load Godot plugin " + pluginName, e);
+ }
+ } else {
+ Log.w(TAG, "Invalid plugin loader class for " + pluginName);
+ }
+ }
+ }
+ } catch (PackageManager.NameNotFoundException e) {
+ Log.e(TAG, "Unable load Godot Android plugins from the manifest file.", e);
+ }
+ }
+}
diff --git a/platform/android/java/lib/src/org/godotengine/godot/utils/GLUtils.java b/platform/android/java/lib/src/org/godotengine/godot/utils/GLUtils.java
index bbf876ea1f..9d29551f89 100644
--- a/platform/android/java/lib/src/org/godotengine/godot/utils/GLUtils.java
+++ b/platform/android/java/lib/src/org/godotengine/godot/utils/GLUtils.java
@@ -44,7 +44,6 @@ public class GLUtils {
public static final boolean DEBUG = false;
- public static boolean use_gl3 = false;
public static boolean use_32 = false;
public static boolean use_debug_opengl = false;
diff --git a/platform/uwp/power_uwp.cpp b/platform/android/java/lib/src/org/godotengine/godot/vulkan/VkRenderer.kt
index c6b4359392..67faad8ddd 100644
--- a/platform/uwp/power_uwp.cpp
+++ b/platform/android/java/lib/src/org/godotengine/godot/vulkan/VkRenderer.kt
@@ -1,5 +1,5 @@
/*************************************************************************/
-/* power_uwp.cpp */
+/* VkRenderer.kt */
/*************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
@@ -28,50 +28,72 @@
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/
-#include "power_uwp.h"
+@file:JvmName("VkRenderer")
+package org.godotengine.godot.vulkan
-PowerUWP::PowerUWP() :
- nsecs_left(-1),
- percent_left(-1),
- power_state(OS::POWERSTATE_UNKNOWN) {
-}
+import android.view.Surface
-PowerUWP::~PowerUWP() {
-}
+/**
+ * Responsible to setting up and driving the Vulkan rendering logic.
+ *
+ * <h3>Threading</h3>
+ * The renderer will be called on a separate thread, so that rendering
+ * performance is decoupled from the UI thread. Clients typically need to
+ * communicate with the renderer from the UI thread, because that's where
+ * input events are received. Clients can communicate using any of the
+ * standard Java techniques for cross-thread communication, or they can
+ * use the [VkSurfaceView.queueOnVkThread] convenience method.
+ *
+ * @see [VkSurfaceView.startRenderer]
+ */
+internal class VkRenderer {
-bool PowerUWP::UpdatePowerInfo() {
- // TODO, WinRT: Battery info is available on at least one WinRT platform (Windows Phone 8). Implement UpdatePowerInfo as appropriate. */
- /* Notes from SDL:
- - the Win32 function, GetSystemPowerStatus, is not available for use on WinRT
- - Windows Phone 8 has a 'Battery' class, which is documented as available for C++
- - More info on WP8's Battery class can be found at http://msdn.microsoft.com/library/windowsphone/develop/jj207231
- */
- return false;
-}
+ /**
+ * Called when the surface is created and signals the beginning of rendering.
+ */
+ fun onVkSurfaceCreated(surface: Surface) {
+ nativeOnVkSurfaceCreated(surface)
+ }
-OS::PowerState PowerUWP::get_power_state() {
- if (UpdatePowerInfo()) {
- return power_state;
- } else {
- WARN_PRINT("Power management is not implemented on this platform, defaulting to POWERSTATE_UNKNOWN");
- return OS::POWERSTATE_UNKNOWN;
+ /**
+ * Called after the surface is created and whenever its size changes.
+ */
+ fun onVkSurfaceChanged(surface: Surface, width: Int, height: Int) {
+ nativeOnVkSurfaceChanged(surface, width, height)
}
-}
-int PowerUWP::get_power_seconds_left() {
- if (UpdatePowerInfo()) {
- return nsecs_left;
- } else {
- WARN_PRINT("Power management is not implemented on this platform, defaulting to -1");
- return -1;
+ /**
+ * Called to draw the current frame.
+ */
+ fun onVkDrawFrame() {
+ nativeOnVkDrawFrame()
}
-}
-int PowerUWP::get_power_percent_left() {
- if (UpdatePowerInfo()) {
- return percent_left;
- } else {
- WARN_PRINT("Power management is not implemented on this platform, defaulting to -1");
- return -1;
+ /**
+ * Called when the rendering thread is resumed.
+ */
+ fun onVkResume() {
+ nativeOnVkResume()
}
+
+ /**
+ * Called when the rendering thread is paused.
+ */
+ fun onVkPause() {
+ nativeOnVkPause()
+ }
+
+ /**
+ * Called when the rendering thread is destroyed and used as signal to tear down the Vulkan logic.
+ */
+ fun onVkDestroy() {
+ nativeOnVkDestroy()
+ }
+
+ private external fun nativeOnVkSurfaceCreated(surface: Surface)
+ private external fun nativeOnVkSurfaceChanged(surface: Surface, width: Int, height: Int)
+ private external fun nativeOnVkResume()
+ private external fun nativeOnVkDrawFrame()
+ private external fun nativeOnVkPause()
+ private external fun nativeOnVkDestroy()
}
diff --git a/platform/android/java/lib/src/org/godotengine/godot/vulkan/VkSurfaceView.kt b/platform/android/java/lib/src/org/godotengine/godot/vulkan/VkSurfaceView.kt
new file mode 100644
index 0000000000..1c594f3201
--- /dev/null
+++ b/platform/android/java/lib/src/org/godotengine/godot/vulkan/VkSurfaceView.kt
@@ -0,0 +1,136 @@
+/*************************************************************************/
+/* VkSurfaceView.kt */
+/*************************************************************************/
+/* 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. */
+/*************************************************************************/
+
+@file:JvmName("VkSurfaceView")
+package org.godotengine.godot.vulkan
+
+import android.content.Context
+import android.view.SurfaceHolder
+import android.view.SurfaceView
+
+/**
+ * An implementation of SurfaceView that uses the dedicated surface for
+ * displaying Vulkan rendering.
+ * <p>
+ * A [VkSurfaceView] provides the following features:
+ * <p>
+ * <ul>
+ * <li>Manages a surface, which is a special piece of memory that can be
+ * composited into the Android view system.
+ * <li>Accepts a user-provided [VkRenderer] object that does the actual rendering.
+ * <li>Renders on a dedicated [VkThread] thread to decouple rendering performance from the
+ * UI thread.
+ * </ul>
+ */
+internal class VkSurfaceView(context: Context) : SurfaceView(context), SurfaceHolder.Callback {
+
+ companion object {
+ fun checkState(expression: Boolean, errorMessage: Any) {
+ check(expression) { errorMessage.toString() }
+ }
+ }
+
+ /**
+ * Thread used to drive the vulkan logic.
+ */
+ private val vkThread: VkThread by lazy {
+ VkThread(this, renderer)
+ }
+
+ /**
+ * Performs the actual rendering.
+ */
+ private lateinit var renderer: VkRenderer
+
+ init {
+ isClickable = true
+ holder.addCallback(this)
+ }
+
+ /**
+ * Set the [VkRenderer] associated with the view, and starts the thread that will drive the vulkan
+ * rendering.
+ *
+ * This method should be called once and only once in the life-cycle of [VkSurfaceView].
+ */
+ fun startRenderer(renderer: VkRenderer) {
+ checkState(!this::renderer.isInitialized, "startRenderer must only be invoked once")
+ this.renderer = renderer
+ vkThread.start()
+ }
+
+ /**
+ * Queues a runnable to be run on the Vulkan rendering thread.
+ *
+ * Must not be called before a [VkRenderer] has been set.
+ */
+ fun queueOnVkThread(runnable: Runnable) {
+ vkThread.queueEvent(runnable)
+ }
+
+ /**
+ * Resumes the rendering thread.
+ *
+ * Must not be called before a [VkRenderer] has been set.
+ */
+ fun onResume() {
+ vkThread.onResume()
+ }
+
+ /**
+ * Pauses the rendering thread.
+ *
+ * Must not be called before a [VkRenderer] has been set.
+ */
+ fun onPause() {
+ vkThread.onPause()
+ }
+
+ /**
+ * Tear down the rendering thread.
+ *
+ * Must not be called before a [VkRenderer] has been set.
+ */
+ fun onDestroy() {
+ vkThread.blockingExit()
+ }
+
+ override fun surfaceChanged(holder: SurfaceHolder, format: Int, width: Int, height: Int) {
+ vkThread.onSurfaceChanged(width, height)
+ }
+
+ override fun surfaceDestroyed(holder: SurfaceHolder) {
+ vkThread.onSurfaceDestroyed()
+ }
+
+ override fun surfaceCreated(holder: SurfaceHolder) {
+ vkThread.onSurfaceCreated()
+ }
+}
diff --git a/platform/android/java/lib/src/org/godotengine/godot/vulkan/VkThread.kt b/platform/android/java/lib/src/org/godotengine/godot/vulkan/VkThread.kt
new file mode 100644
index 0000000000..2e332840bf
--- /dev/null
+++ b/platform/android/java/lib/src/org/godotengine/godot/vulkan/VkThread.kt
@@ -0,0 +1,230 @@
+/*************************************************************************/
+/* VkThread.kt */
+/*************************************************************************/
+/* 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. */
+/*************************************************************************/
+
+@file:JvmName("VkThread")
+package org.godotengine.godot.vulkan
+
+import android.util.Log
+import java.util.concurrent.locks.ReentrantLock
+import kotlin.concurrent.withLock
+
+/**
+ * Thread implementation for the [VkSurfaceView] onto which the vulkan logic is ran.
+ *
+ * The implementation is modeled after [android.opengl.GLSurfaceView]'s GLThread.
+ */
+internal class VkThread(private val vkSurfaceView: VkSurfaceView, private val vkRenderer: VkRenderer) : Thread(TAG) {
+
+ companion object {
+ private val TAG = VkThread::class.java.simpleName
+ }
+
+ /**
+ * Used to run events scheduled on the thread.
+ */
+ private val eventQueue = ArrayList<Runnable>()
+
+ /**
+ * Used to synchronize interaction with other threads (e.g: main thread).
+ */
+ private val lock = ReentrantLock()
+ private val lockCondition = lock.newCondition()
+
+ private var shouldExit = false
+ private var exited = false
+ private var rendererInitialized = false
+ private var rendererResumed = false
+ private var resumed = false
+ private var hasSurface = false
+ private var width = 0
+ private var height = 0
+
+ /**
+ * Determine when drawing can occur on the thread. This usually occurs after the
+ * [android.view.Surface] is available, the app is in a resumed state.
+ */
+ private val readyToDraw
+ get() = hasSurface && resumed
+
+ private fun threadExiting() {
+ lock.withLock {
+ exited = true
+ lockCondition.signalAll()
+ }
+ }
+
+ /**
+ * Queue an event on the [VkThread].
+ */
+ fun queueEvent(event: Runnable) {
+ lock.withLock {
+ eventQueue.add(event)
+ lockCondition.signalAll()
+ }
+ }
+
+ /**
+ * Request the thread to exit and block until it's done.
+ */
+ fun blockingExit() {
+ lock.withLock {
+ shouldExit = true
+ lockCondition.signalAll()
+ while (!exited) {
+ try {
+ Log.i(TAG, "Waiting on exit for $name")
+ lockCondition.await()
+ } catch (ex: InterruptedException) {
+ currentThread().interrupt()
+ }
+ }
+ }
+ }
+
+ /**
+ * Invoked when the app resumes.
+ */
+ fun onResume() {
+ lock.withLock {
+ resumed = true
+ lockCondition.signalAll()
+ }
+ }
+
+ /**
+ * Invoked when the app pauses.
+ */
+ fun onPause() {
+ lock.withLock {
+ resumed = false
+ lockCondition.signalAll()
+ }
+ }
+
+ /**
+ * Invoked when the [android.view.Surface] has been created.
+ */
+ fun onSurfaceCreated() {
+ // This is a no op because surface creation will always be followed by surfaceChanged()
+ // which provide all the needed information.
+ }
+
+ /**
+ * Invoked following structural updates to [android.view.Surface].
+ */
+ fun onSurfaceChanged(width: Int, height: Int) {
+ lock.withLock {
+ hasSurface = true
+ this.width = width
+ this.height = height
+ lockCondition.signalAll()
+ }
+ }
+
+ /**
+ * Invoked when the [android.view.Surface] is no longer available.
+ */
+ fun onSurfaceDestroyed() {
+ lock.withLock {
+ hasSurface = false
+ lockCondition.signalAll()
+ }
+ }
+
+ /**
+ * Thread loop modeled after [android.opengl.GLSurfaceView]'s GLThread.
+ */
+ override fun run() {
+ try {
+ while (true) {
+ var event: Runnable? = null
+ lock.withLock {
+ while (true) {
+ // Code path for exiting the thread loop.
+ if (shouldExit) {
+ vkRenderer.onVkDestroy()
+ return
+ }
+
+ // Check for events and execute them outside of the loop if found to avoid
+ // blocking the thread lifecycle by holding onto the lock.
+ if (eventQueue.isNotEmpty()) {
+ event = eventQueue.removeAt(0)
+ break;
+ }
+
+ if (readyToDraw) {
+ if (!rendererResumed) {
+ rendererResumed = true
+ vkRenderer.onVkResume()
+
+ if (!rendererInitialized) {
+ rendererInitialized = true
+ vkRenderer.onVkSurfaceCreated(vkSurfaceView.holder.surface)
+ }
+
+ vkRenderer.onVkSurfaceChanged(vkSurfaceView.holder.surface, width, height)
+ }
+
+ // Break out of the loop so drawing can occur without holding onto the lock.
+ break;
+ } else if (rendererResumed) {
+ // If we aren't ready to draw but are resumed, that means we either lost a surface
+ // or the app was paused.
+ rendererResumed = false
+ vkRenderer.onVkPause()
+ }
+ // We only reach this state if we are not ready to draw and have no queued events, so
+ // we wait.
+ // On state change, the thread will be awoken using the [lock] and [lockCondition], and
+ // we will resume execution.
+ lockCondition.await()
+ }
+ }
+
+ // Run queued event.
+ if (event != null) {
+ event?.run()
+ continue
+ }
+
+ // Draw only when there no more queued events.
+ vkRenderer.onVkDrawFrame()
+ }
+ } catch (ex: InterruptedException) {
+ Log.i(TAG, ex.message)
+ } catch (ex: IllegalStateException) {
+ Log.i(TAG, ex.message)
+ } finally {
+ threadExiting()
+ }
+ }
+
+}
diff --git a/platform/android/java/lib/src/org/godotengine/godot/xr/regular/RegularConfigChooser.java b/platform/android/java/lib/src/org/godotengine/godot/xr/regular/RegularConfigChooser.java
index ce4defd7a7..8409e37f8f 100644
--- a/platform/android/java/lib/src/org/godotengine/godot/xr/regular/RegularConfigChooser.java
+++ b/platform/android/java/lib/src/org/godotengine/godot/xr/regular/RegularConfigChooser.java
@@ -45,6 +45,8 @@ public class RegularConfigChooser implements GLSurfaceView.EGLConfigChooser {
private int[] mValue = new int[1];
+ // FIXME: Add support for Vulkan.
+
/* This EGL config specification is used to specify 2.0 rendering.
* We use a minimum size of 4 bits for red/green/blue, but will
* perform actual matching in chooseConfig() below.
@@ -59,15 +61,6 @@ public class RegularConfigChooser implements GLSurfaceView.EGLConfigChooser {
EGL10.EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT,
EGL10.EGL_NONE
};
- private static int[] s_configAttribs3 = {
- EGL10.EGL_RED_SIZE, 4,
- EGL10.EGL_GREEN_SIZE, 4,
- EGL10.EGL_BLUE_SIZE, 4,
- // EGL10.EGL_DEPTH_SIZE, 16,
- // EGL10.EGL_STENCIL_SIZE, EGL10.EGL_DONT_CARE,
- EGL10.EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT, //apparently there is no EGL_OPENGL_ES3_BIT
- EGL10.EGL_NONE
- };
public RegularConfigChooser(int r, int g, int b, int a, int depth, int stencil) {
mRedSize = r;
@@ -83,7 +76,7 @@ public class RegularConfigChooser implements GLSurfaceView.EGLConfigChooser {
/* Get the number of minimally matching EGL configurations
*/
int[] num_config = new int[1];
- egl.eglChooseConfig(display, GLUtils.use_gl3 ? s_configAttribs3 : s_configAttribs2, null, 0, num_config);
+ egl.eglChooseConfig(display, s_configAttribs2, null, 0, num_config);
int numConfigs = num_config[0];
@@ -94,7 +87,7 @@ public class RegularConfigChooser implements GLSurfaceView.EGLConfigChooser {
/* Allocate then read the array of minimally matching EGL configs
*/
EGLConfig[] configs = new EGLConfig[numConfigs];
- egl.eglChooseConfig(display, GLUtils.use_gl3 ? s_configAttribs3 : s_configAttribs2, configs, numConfigs, num_config);
+ egl.eglChooseConfig(display, s_configAttribs2, configs, numConfigs, num_config);
if (GLUtils.DEBUG) {
GLUtils.printConfigs(egl, display, configs);
diff --git a/platform/android/java/lib/src/org/godotengine/godot/xr/regular/RegularContextFactory.java b/platform/android/java/lib/src/org/godotengine/godot/xr/regular/RegularContextFactory.java
index 22bd4ced87..f2b4c95a2c 100644
--- a/platform/android/java/lib/src/org/godotengine/godot/xr/regular/RegularContextFactory.java
+++ b/platform/android/java/lib/src/org/godotengine/godot/xr/regular/RegularContextFactory.java
@@ -52,24 +52,17 @@ public class RegularContextFactory implements GLSurfaceView.EGLContextFactory {
public EGLContext createContext(EGL10 egl, EGLDisplay display, EGLConfig eglConfig) {
String driver_name = GodotLib.getGlobal("rendering/quality/driver/driver_name");
- if (GLUtils.use_gl3 && !driver_name.equals("GLES3")) {
- GLUtils.use_gl3 = false;
- }
- if (GLUtils.use_gl3)
- Log.w(TAG, "creating OpenGL ES 3.0 context :");
- else
- Log.w(TAG, "creating OpenGL ES 2.0 context :");
+ // FIXME: Add support for Vulkan.
+ Log.w(TAG, "creating OpenGL ES 2.0 context :");
GLUtils.checkEglError(TAG, "Before eglCreateContext", egl);
EGLContext context;
if (GLUtils.use_debug_opengl) {
int[] attrib_list2 = { EGL_CONTEXT_CLIENT_VERSION, 2, _EGL_CONTEXT_FLAGS_KHR, _EGL_CONTEXT_OPENGL_DEBUG_BIT_KHR, EGL10.EGL_NONE };
- int[] attrib_list3 = { EGL_CONTEXT_CLIENT_VERSION, 3, _EGL_CONTEXT_FLAGS_KHR, _EGL_CONTEXT_OPENGL_DEBUG_BIT_KHR, EGL10.EGL_NONE };
- context = egl.eglCreateContext(display, eglConfig, EGL10.EGL_NO_CONTEXT, GLUtils.use_gl3 ? attrib_list3 : attrib_list2);
+ context = egl.eglCreateContext(display, eglConfig, EGL10.EGL_NO_CONTEXT, attrib_list2);
} else {
int[] attrib_list2 = { EGL_CONTEXT_CLIENT_VERSION, 2, EGL10.EGL_NONE };
- int[] attrib_list3 = { EGL_CONTEXT_CLIENT_VERSION, 3, EGL10.EGL_NONE };
- context = egl.eglCreateContext(display, eglConfig, EGL10.EGL_NO_CONTEXT, GLUtils.use_gl3 ? attrib_list3 : attrib_list2);
+ context = egl.eglCreateContext(display, eglConfig, EGL10.EGL_NO_CONTEXT, attrib_list2);
}
GLUtils.checkEglError(TAG, "After eglCreateContext", egl);
return context;
diff --git a/platform/android/java/plugins/godotpayment/build.gradle b/platform/android/java/plugins/godotpayment/build.gradle
new file mode 100644
index 0000000000..4f376c4587
--- /dev/null
+++ b/platform/android/java/plugins/godotpayment/build.gradle
@@ -0,0 +1,31 @@
+apply plugin: 'com.android.library'
+
+android {
+ compileSdkVersion versions.compileSdk
+ buildToolsVersion versions.buildTools
+
+ defaultConfig {
+ minSdkVersion versions.minSdk
+ targetSdkVersion versions.targetSdk
+ }
+
+ libraryVariants.all { variant ->
+ variant.outputs.all { output ->
+ output.outputFileName = "GodotPayment.${variant.name}.aar"
+ }
+ }
+
+}
+
+dependencies {
+ implementation libraries.supportCoreUtils
+ implementation libraries.v4Support
+
+ if (rootProject.findProject(":lib")) {
+ compileOnly project(":lib")
+ } else if (rootProject.findProject(":godot:lib")) {
+ compileOnly project(":godot:lib")
+ } else {
+ compileOnly fileTree(dir: 'libs', include: ['godot-lib*.aar'])
+ }
+}
diff --git a/platform/android/java/plugins/godotpayment/src/main/AndroidManifest.xml b/platform/android/java/plugins/godotpayment/src/main/AndroidManifest.xml
new file mode 100644
index 0000000000..61afa03799
--- /dev/null
+++ b/platform/android/java/plugins/godotpayment/src/main/AndroidManifest.xml
@@ -0,0 +1,11 @@
+<manifest xmlns:android="http://schemas.android.com/apk/res/android"
+ package="org.godotengine.godot.plugin.payment">
+
+ <application>
+
+ <meta-data
+ android:name="org.godotengine.plugin.v1.GodotPayment"
+ android:value="org.godotengine.godot.plugin.payment.GodotPayment" />
+
+ </application>
+</manifest>
diff --git a/platform/android/java/lib/aidl/com/android/vending/billing/IInAppBillingService.aidl b/platform/android/java/plugins/godotpayment/src/main/aidl/com/android/vending/billing/IInAppBillingService.aidl
index 0f2bcae338..0f2bcae338 100644
--- a/platform/android/java/lib/aidl/com/android/vending/billing/IInAppBillingService.aidl
+++ b/platform/android/java/plugins/godotpayment/src/main/aidl/com/android/vending/billing/IInAppBillingService.aidl
diff --git a/platform/android/java/lib/src/org/godotengine/godot/payments/ConsumeTask.java b/platform/android/java/plugins/godotpayment/src/main/java/org/godotengine/godot/plugin/payment/ConsumeTask.java
index 95cc48f536..c15bc232ce 100644
--- a/platform/android/java/lib/src/org/godotengine/godot/payments/ConsumeTask.java
+++ b/platform/android/java/plugins/godotpayment/src/main/java/org/godotengine/godot/plugin/payment/ConsumeTask.java
@@ -28,7 +28,7 @@
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/
-package org.godotengine.godot.payments;
+package org.godotengine.godot.plugin.payment;
import android.content.Context;
import android.os.AsyncTask;
diff --git a/platform/android/java/lib/src/org/godotengine/godot/GodotPaymentV3.java b/platform/android/java/plugins/godotpayment/src/main/java/org/godotengine/godot/plugin/payment/GodotPayment.java
index 93265d509f..c7d0a5de65 100644
--- a/platform/android/java/lib/src/org/godotengine/godot/GodotPaymentV3.java
+++ b/platform/android/java/plugins/godotpayment/src/main/java/org/godotengine/godot/plugin/payment/GodotPayment.java
@@ -1,5 +1,5 @@
/*************************************************************************/
-/* GodotPaymentV3.java */
+/* GodotPayment.java */
/*************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
@@ -28,29 +28,53 @@
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/
-package org.godotengine.godot;
+package org.godotengine.godot.plugin.payment;
-import android.app.Activity;
+import android.content.Intent;
+import android.support.annotation.NonNull;
import android.util.Log;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
-import org.godotengine.godot.payments.PaymentsManager;
+import org.godotengine.godot.Dictionary;
+import org.godotengine.godot.Godot;
+import org.godotengine.godot.GodotLib;
+import org.godotengine.godot.plugin.GodotPlugin;
import org.json.JSONException;
import org.json.JSONObject;
-public class GodotPaymentV3 extends Godot.SingletonBase {
+public class GodotPayment extends GodotPlugin {
- private Godot activity;
private Integer purchaseCallbackId = 0;
private String accessToken;
private String purchaseValidationUrlPrefix;
private String transactionId;
- private PaymentsManager mPaymentManager;
- private Dictionary mSkuDetails = new Dictionary();
+ private final PaymentsManager mPaymentManager;
+ private final Dictionary mSkuDetails = new Dictionary();
+
+ public GodotPayment(Godot godot) {
+ super(godot);
+ mPaymentManager = new PaymentsManager(godot, this);
+ mPaymentManager.initService();
+ }
+
+ @Override
+ public void onMainActivityResult(int requestCode, int resultCode, Intent data) {
+ if (requestCode == PaymentsManager.REQUEST_CODE_FOR_PURCHASE) {
+ mPaymentManager.processPurchaseResponse(resultCode, data);
+ }
+ }
+
+ @Override
+ public void onMainDestroy() {
+ super.onMainDestroy();
+ if (mPaymentManager != null) {
+ mPaymentManager.destroy();
+ }
+ }
public void purchase(final String sku, final String transactionId) {
- activity.runOnUiThread(new Runnable() {
+ runOnUiThread(new Runnable() {
@Override
public void run() {
mPaymentManager.requestPurchase(sku, transactionId);
@@ -58,21 +82,8 @@ public class GodotPaymentV3 extends Godot.SingletonBase {
});
}
- static public Godot.SingletonBase initialize(Activity p_activity) {
-
- return new GodotPaymentV3(p_activity);
- }
-
- public GodotPaymentV3(Activity p_activity) {
-
- registerClass("GodotPayments", new String[] { "purchase", "setPurchaseCallbackId", "setPurchaseValidationUrlPrefix", "setTransactionId", "getSignature", "consumeUnconsumedPurchases", "requestPurchased", "setAutoConsume", "consume", "querySkuDetails", "isConnected" });
- activity = (Godot)p_activity;
- mPaymentManager = activity.getPaymentsManager();
- mPaymentManager.setBaseSingleton(this);
- }
-
public void consumeUnconsumedPurchases() {
- activity.runOnUiThread(new Runnable() {
+ runOnUiThread(new Runnable() {
@Override
public void run() {
mPaymentManager.consumeUnconsumedPurchases();
@@ -149,7 +160,7 @@ public class GodotPaymentV3 extends Godot.SingletonBase {
// request purchased items are not consumed
public void requestPurchased() {
- activity.runOnUiThread(new Runnable() {
+ runOnUiThread(new Runnable() {
@Override
public void run() {
mPaymentManager.requestPurchased();
@@ -227,4 +238,18 @@ public class GodotPaymentV3 extends Godot.SingletonBase {
public void errorSkuDetail(String errorMessage) {
GodotLib.calldeferred(purchaseCallbackId, "sku_details_error", new Object[] { errorMessage });
}
+
+ @NonNull
+ @Override
+ public String getPluginName() {
+ return "GodotPayment";
+ }
+
+ @NonNull
+ @Override
+ public List<String> getPluginMethods() {
+ return Arrays.asList("purchase", "setPurchaseCallbackId", "setPurchaseValidationUrlPrefix",
+ "setTransactionId", "getSignature", "consumeUnconsumedPurchases", "requestPurchased",
+ "setAutoConsume", "consume", "querySkuDetails", "isConnected");
+ }
}
diff --git a/platform/android/java/lib/src/org/godotengine/godot/payments/HandlePurchaseTask.java b/platform/android/java/plugins/godotpayment/src/main/java/org/godotengine/godot/plugin/payment/HandlePurchaseTask.java
index 23d693cc8c..fe5685288b 100644
--- a/platform/android/java/lib/src/org/godotengine/godot/payments/HandlePurchaseTask.java
+++ b/platform/android/java/plugins/godotpayment/src/main/java/org/godotengine/godot/plugin/payment/HandlePurchaseTask.java
@@ -28,7 +28,7 @@
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/
-package org.godotengine.godot.payments;
+package org.godotengine.godot.plugin.payment;
import android.app.Activity;
import android.content.Intent;
diff --git a/platform/android/java/lib/src/org/godotengine/godot/payments/PaymentsCache.java b/platform/android/java/plugins/godotpayment/src/main/java/org/godotengine/godot/plugin/payment/PaymentsCache.java
index 84a7eda6e0..d5919e3d9d 100644
--- a/platform/android/java/lib/src/org/godotengine/godot/payments/PaymentsCache.java
+++ b/platform/android/java/plugins/godotpayment/src/main/java/org/godotengine/godot/plugin/payment/PaymentsCache.java
@@ -28,11 +28,10 @@
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/
-package org.godotengine.godot.payments;
+package org.godotengine.godot.plugin.payment;
import android.content.Context;
import android.content.SharedPreferences;
-import android.util.Log;
public class PaymentsCache {
diff --git a/platform/android/java/lib/src/org/godotengine/godot/payments/PaymentsManager.java b/platform/android/java/plugins/godotpayment/src/main/java/org/godotengine/godot/plugin/payment/PaymentsManager.java
index 90b958266b..bded1f452f 100644
--- a/platform/android/java/lib/src/org/godotengine/godot/payments/PaymentsManager.java
+++ b/platform/android/java/plugins/godotpayment/src/main/java/org/godotengine/godot/plugin/payment/PaymentsManager.java
@@ -28,7 +28,7 @@
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/
-package org.godotengine.godot.payments;
+package org.godotengine.godot.plugin.payment;
import android.app.Activity;
import android.content.ComponentName;
@@ -43,7 +43,6 @@ import android.util.Log;
import com.android.vending.billing.IInAppBillingService;
import java.util.ArrayList;
import java.util.Arrays;
-import org.godotengine.godot.GodotPaymentV3;
import org.json.JSONException;
import org.json.JSONObject;
@@ -53,20 +52,13 @@ public class PaymentsManager {
public static final int REQUEST_CODE_FOR_PURCHASE = 0x1001;
private static boolean auto_consume = true;
- private Activity activity;
+ private final Activity activity;
+ private final GodotPayment godotPayment;
IInAppBillingService mService;
- public void setActivity(Activity activity) {
- this.activity = activity;
- }
-
- public static PaymentsManager createManager(Activity activity) {
- PaymentsManager manager = new PaymentsManager(activity);
- return manager;
- }
-
- private PaymentsManager(Activity activity) {
+ PaymentsManager(Activity activity, GodotPayment godotPayment) {
this.activity = activity;
+ this.godotPayment = godotPayment;
}
public PaymentsManager initService() {
@@ -90,9 +82,9 @@ public class PaymentsManager {
public void onServiceDisconnected(ComponentName name) {
mService = null;
- // At this stage, godotPaymentV3 might not have been initialized yet.
- if (godotPaymentV3 != null) {
- godotPaymentV3.callbackDisconnected();
+ // At this stage, godotPayment might not have been initialized yet.
+ if (godotPayment != null) {
+ godotPayment.callbackDisconnected();
}
}
@@ -100,9 +92,9 @@ public class PaymentsManager {
public void onServiceConnected(ComponentName name, IBinder service) {
mService = IInAppBillingService.Stub.asInterface(service);
- // At this stage, godotPaymentV3 might not have been initialized yet.
- if (godotPaymentV3 != null) {
- godotPaymentV3.callbackConnected();
+ // At this stage, godotPayment might not have been initialized yet.
+ if (godotPayment != null) {
+ godotPayment.callbackConnected();
}
}
};
@@ -111,17 +103,17 @@ public class PaymentsManager {
new PurchaseTask(mService, activity) {
@Override
protected void error(String message) {
- godotPaymentV3.callbackFail(message);
+ godotPayment.callbackFail(message);
}
@Override
protected void canceled() {
- godotPaymentV3.callbackCancel();
+ godotPayment.callbackCancel();
}
@Override
protected void alreadyOwned() {
- godotPaymentV3.callbackAlreadyOwned(sku);
+ godotPayment.callbackAlreadyOwned(sku);
}
}
.purchase(sku, transactionId);
@@ -135,19 +127,19 @@ public class PaymentsManager {
new ReleaseAllConsumablesTask(mService, activity) {
@Override
protected void success(String sku, String receipt, String signature, String token) {
- godotPaymentV3.callbackSuccessProductMassConsumed(receipt, signature, sku);
+ godotPayment.callbackSuccessProductMassConsumed(receipt, signature, sku);
}
@Override
protected void error(String message) {
Log.d("godot", "consumeUnconsumedPurchases :" + message);
- godotPaymentV3.callbackFailConsume(message);
+ godotPayment.callbackFailConsume(message);
}
@Override
protected void notRequired() {
Log.d("godot", "callbackSuccessNoUnconsumedPurchases :");
- godotPaymentV3.callbackSuccessNoUnconsumedPurchases();
+ godotPayment.callbackSuccessNoUnconsumedPurchases();
}
}
.consumeItAll();
@@ -168,7 +160,7 @@ public class PaymentsManager {
final ArrayList<String> mySignatures = bundle.getStringArrayList("INAPP_DATA_SIGNATURE_LIST");
if (myPurchases == null || myPurchases.size() == 0) {
- godotPaymentV3.callbackPurchased("", "", "");
+ godotPayment.callbackPurchased("", "", "");
return;
}
@@ -186,7 +178,7 @@ public class PaymentsManager {
pc.setConsumableFlag("block", sku, true);
pc.setConsumableValue("token", sku, token);
- godotPaymentV3.callbackPurchased(receipt, signature, sku);
+ godotPayment.callbackPurchased(receipt, signature, sku);
} catch (JSONException e) {
}
}
@@ -203,7 +195,7 @@ public class PaymentsManager {
new HandlePurchaseTask(activity) {
@Override
protected void success(final String sku, final String signature, final String ticket) {
- godotPaymentV3.callbackSuccess(ticket, signature, sku);
+ godotPayment.callbackSuccess(ticket, signature, sku);
if (auto_consume) {
new ConsumeTask(mService, activity) {
@@ -213,7 +205,7 @@ public class PaymentsManager {
@Override
protected void error(String message) {
- godotPaymentV3.callbackFail(message);
+ godotPayment.callbackFail(message);
}
}
.consume(sku);
@@ -222,12 +214,12 @@ public class PaymentsManager {
@Override
protected void error(String message) {
- godotPaymentV3.callbackFail(message);
+ godotPayment.callbackFail(message);
}
@Override
protected void canceled() {
- godotPaymentV3.callbackCancel();
+ godotPayment.callbackCancel();
}
}
.handlePurchaseRequest(resultCode, data);
@@ -235,19 +227,19 @@ public class PaymentsManager {
public void validatePurchase(String purchaseToken, final String sku) {
- new ValidateTask(activity, godotPaymentV3) {
+ new ValidateTask(activity, godotPayment) {
@Override
protected void success() {
new ConsumeTask(mService, activity) {
@Override
protected void success(String ticket) {
- godotPaymentV3.callbackSuccess(ticket, null, sku);
+ godotPayment.callbackSuccess(ticket, null, sku);
}
@Override
protected void error(String message) {
- godotPaymentV3.callbackFail(message);
+ godotPayment.callbackFail(message);
}
}
.consume(sku);
@@ -255,12 +247,12 @@ public class PaymentsManager {
@Override
protected void error(String message) {
- godotPaymentV3.callbackFail(message);
+ godotPayment.callbackFail(message);
}
@Override
protected void canceled() {
- godotPaymentV3.callbackCancel();
+ godotPayment.callbackCancel();
}
}
.validatePurchase(sku);
@@ -274,12 +266,12 @@ public class PaymentsManager {
new ConsumeTask(mService, activity) {
@Override
protected void success(String ticket) {
- godotPaymentV3.callbackSuccessProductMassConsumed(ticket, "", sku);
+ godotPayment.callbackSuccessProductMassConsumed(ticket, "", sku);
}
@Override
protected void error(String message) {
- godotPaymentV3.callbackFailConsume(message);
+ godotPayment.callbackFailConsume(message);
}
}
.consume(sku);
@@ -387,9 +379,9 @@ public class PaymentsManager {
if (!skuDetails.containsKey("DETAILS_LIST")) {
int response = getResponseCodeFromBundle(skuDetails);
if (response != BILLING_RESPONSE_RESULT_OK) {
- godotPaymentV3.errorSkuDetail(getResponseDesc(response));
+ godotPayment.errorSkuDetail(getResponseDesc(response));
} else {
- godotPaymentV3.errorSkuDetail("No error but no detail list.");
+ godotPayment.errorSkuDetail("No error but no detail list.");
}
return;
}
@@ -398,22 +390,16 @@ public class PaymentsManager {
for (String thisResponse : responseList) {
Log.d("godot", "response = " + thisResponse);
- godotPaymentV3.addSkuDetail(thisResponse);
+ godotPayment.addSkuDetail(thisResponse);
}
} catch (RemoteException e) {
e.printStackTrace();
- godotPaymentV3.errorSkuDetail("RemoteException error!");
+ godotPayment.errorSkuDetail("RemoteException error!");
}
}
- godotPaymentV3.completeSkuDetail();
+ godotPayment.completeSkuDetail();
}
}))
.start();
}
-
- private GodotPaymentV3 godotPaymentV3;
-
- public void setBaseSingleton(GodotPaymentV3 godotPaymentV3) {
- this.godotPaymentV3 = godotPaymentV3;
- }
}
diff --git a/platform/android/java/lib/src/org/godotengine/godot/payments/PurchaseTask.java b/platform/android/java/plugins/godotpayment/src/main/java/org/godotengine/godot/plugin/payment/PurchaseTask.java
index 09c9349124..eecd1d2151 100644
--- a/platform/android/java/lib/src/org/godotengine/godot/payments/PurchaseTask.java
+++ b/platform/android/java/plugins/godotpayment/src/main/java/org/godotengine/godot/plugin/payment/PurchaseTask.java
@@ -28,7 +28,7 @@
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/
-package org.godotengine.godot.payments;
+package org.godotengine.godot.plugin.payment;
import android.app.Activity;
import android.app.PendingIntent;
diff --git a/platform/android/java/lib/src/org/godotengine/godot/payments/ReleaseAllConsumablesTask.java b/platform/android/java/plugins/godotpayment/src/main/java/org/godotengine/godot/plugin/payment/ReleaseAllConsumablesTask.java
index a101780511..b7bd638feb 100644
--- a/platform/android/java/lib/src/org/godotengine/godot/payments/ReleaseAllConsumablesTask.java
+++ b/platform/android/java/plugins/godotpayment/src/main/java/org/godotengine/godot/plugin/payment/ReleaseAllConsumablesTask.java
@@ -28,7 +28,7 @@
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/
-package org.godotengine.godot.payments;
+package org.godotengine.godot.plugin.payment;
import android.content.Context;
import android.os.AsyncTask;
diff --git a/platform/android/java/lib/src/org/godotengine/godot/payments/ValidateTask.java b/platform/android/java/plugins/godotpayment/src/main/java/org/godotengine/godot/plugin/payment/ValidateTask.java
index dbb6b8a783..179cc08ed1 100644
--- a/platform/android/java/lib/src/org/godotengine/godot/payments/ValidateTask.java
+++ b/platform/android/java/plugins/godotpayment/src/main/java/org/godotengine/godot/plugin/payment/ValidateTask.java
@@ -28,13 +28,12 @@
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/
-package org.godotengine.godot.payments;
+package org.godotengine.godot.plugin.payment;
import android.app.Activity;
import android.app.ProgressDialog;
import android.os.AsyncTask;
import java.lang.ref.WeakReference;
-import org.godotengine.godot.GodotPaymentV3;
import org.godotengine.godot.utils.HttpRequester;
import org.godotengine.godot.utils.RequestParams;
import org.json.JSONException;
@@ -43,7 +42,7 @@ import org.json.JSONObject;
abstract public class ValidateTask {
private Activity context;
- private GodotPaymentV3 godotPaymentsV3;
+ private GodotPayment godotPayments;
private ProgressDialog dialog;
private String mSku;
@@ -80,9 +79,9 @@ abstract public class ValidateTask {
}
}
- public ValidateTask(Activity context, GodotPaymentV3 godotPaymentsV3) {
+ public ValidateTask(Activity context, GodotPayment godotPayments) {
this.context = context;
- this.godotPaymentsV3 = godotPaymentsV3;
+ this.godotPayments = godotPayments;
}
public void validatePurchase(final String sku) {
@@ -96,7 +95,7 @@ abstract public class ValidateTask {
private String doInBackground(String... params) {
PaymentsCache pc = new PaymentsCache(context);
- String url = godotPaymentsV3.getPurchaseValidationUrlPrefix();
+ String url = godotPayments.getPurchaseValidationUrlPrefix();
RequestParams param = new RequestParams();
param.setUrl(url);
param.put("ticket", pc.getConsumableValue("ticket", mSku));
diff --git a/platform/android/java/settings.gradle b/platform/android/java/settings.gradle
index f6921c70aa..9536d3de6d 100644
--- a/platform/android/java/settings.gradle
+++ b/platform/android/java/settings.gradle
@@ -3,3 +3,4 @@ rootProject.name = "Godot"
include ':app'
include ':lib'
+include ':plugins:godotpayment'
diff --git a/platform/android/java_class_wrapper.cpp b/platform/android/java_class_wrapper.cpp
index fe2fd89710..13550c4b11 100644
--- a/platform/android/java_class_wrapper.cpp
+++ b/platform/android/java_class_wrapper.cpp
@@ -32,9 +32,9 @@
#include "string_android.h"
#include "thread_jandroid.h"
-bool JavaClass::_call_method(JavaObject *p_instance, const StringName &p_method, const Variant **p_args, int p_argcount, Variant::CallError &r_error, Variant &ret) {
+bool JavaClass::_call_method(JavaObject *p_instance, const StringName &p_method, const Variant **p_args, int p_argcount, Callable::CallError &r_error, Variant &ret) {
- Map<StringName, List<MethodInfo> >::Element *M = methods.find(p_method);
+ Map<StringName, List<MethodInfo>>::Element *M = methods.find(p_method);
if (!M)
return false;
@@ -44,20 +44,20 @@ bool JavaClass::_call_method(JavaObject *p_instance, const StringName &p_method,
for (List<MethodInfo>::Element *E = M->get().front(); E; E = E->next()) {
if (!p_instance && !E->get()._static) {
- r_error.error = Variant::CallError::CALL_ERROR_INSTANCE_IS_NULL;
+ r_error.error = Callable::CallError::CALL_ERROR_INSTANCE_IS_NULL;
continue;
}
int pc = E->get().param_types.size();
if (pc > p_argcount) {
- r_error.error = Variant::CallError::CALL_ERROR_TOO_FEW_ARGUMENTS;
+ r_error.error = Callable::CallError::CALL_ERROR_TOO_FEW_ARGUMENTS;
r_error.argument = pc;
continue;
}
if (pc < p_argcount) {
- r_error.error = Variant::CallError::CALL_ERROR_TOO_MANY_ARGUMENTS;
+ r_error.error = Callable::CallError::CALL_ERROR_TOO_MANY_ARGUMENTS;
r_error.argument = pc;
continue;
}
@@ -97,7 +97,7 @@ bool JavaClass::_call_method(JavaObject *p_instance, const StringName &p_method,
case ARG_TYPE_DOUBLE: {
if (!p_args[i]->is_num())
- arg_expected = Variant::REAL;
+ arg_expected = Variant::FLOAT;
} break;
case ARG_TYPE_STRING: {
@@ -141,7 +141,7 @@ bool JavaClass::_call_method(JavaObject *p_instance, const StringName &p_method,
}
if (arg_expected != Variant::NIL) {
- r_error.error = Variant::CallError::CALL_ERROR_INVALID_ARGUMENT;
+ r_error.error = Callable::CallError::CALL_ERROR_INVALID_ARGUMENT;
r_error.argument = i;
r_error.expected = arg_expected;
valid = false;
@@ -158,7 +158,7 @@ bool JavaClass::_call_method(JavaObject *p_instance, const StringName &p_method,
if (!method)
return true; //no version convinces
- r_error.error = Variant::CallError::CALL_OK;
+ r_error.error = Callable::CallError::CALL_OK;
jvalue *argv = NULL;
@@ -405,7 +405,7 @@ bool JavaClass::_call_method(JavaObject *p_instance, const StringName &p_method,
}
}
- r_error.error = Variant::CallError::CALL_OK;
+ r_error.error = Callable::CallError::CALL_OK;
bool success = true;
switch (method->return_type) {
@@ -501,7 +501,7 @@ bool JavaClass::_call_method(JavaObject *p_instance, const StringName &p_method,
if (!_convert_object_to_variant(env, obj, ret, method->return_type)) {
ret = Variant();
- r_error.error = Variant::CallError::CALL_ERROR_INVALID_METHOD;
+ r_error.error = Callable::CallError::CALL_ERROR_INVALID_METHOD;
success = false;
}
env->DeleteLocalRef(obj);
@@ -517,7 +517,7 @@ bool JavaClass::_call_method(JavaObject *p_instance, const StringName &p_method,
return success;
}
-Variant JavaClass::call(const StringName &p_method, const Variant **p_args, int p_argcount, Variant::CallError &r_error) {
+Variant JavaClass::call(const StringName &p_method, const Variant **p_args, int p_argcount, Callable::CallError &r_error) {
Variant ret;
bool found = _call_method(NULL, p_method, p_args, p_argcount, r_error, ret);
@@ -533,7 +533,7 @@ JavaClass::JavaClass() {
/////////////////////
-Variant JavaObject::call(const StringName &p_method, const Variant **p_args, int p_argcount, Variant::CallError &r_error) {
+Variant JavaObject::call(const StringName &p_method, const Variant **p_args, int p_argcount, Callable::CallError &r_error) {
return Variant();
}
diff --git a/platform/android/java_godot_lib_jni.cpp b/platform/android/java_godot_lib_jni.cpp
index dedb2ee114..0b1d070441 100644
--- a/platform/android/java_godot_lib_jni.cpp
+++ b/platform/android/java_godot_lib_jni.cpp
@@ -33,14 +33,15 @@
#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"
#include "file_access_jandroid.h"
+#include "jni_utils.h"
#include "main/input_default.h"
#include "main/main.h"
#include "net_socket_android.h"
@@ -54,544 +55,6 @@ static OS_Android *os_android = NULL;
static GodotJavaWrapper *godot_java = NULL;
static GodotIOJavaWrapper *godot_io_java = NULL;
-struct jvalret {
-
- jobject obj;
- jvalue val;
- jvalret() { obj = NULL; }
-};
-
-jvalret _variant_to_jvalue(JNIEnv *env, Variant::Type p_type, const Variant *p_arg, bool force_jobject = false) {
-
- jvalret v;
-
- switch (p_type) {
-
- case Variant::BOOL: {
-
- if (force_jobject) {
- jclass bclass = env->FindClass("java/lang/Boolean");
- jmethodID ctor = env->GetMethodID(bclass, "<init>", "(Z)V");
- jvalue val;
- val.z = (bool)(*p_arg);
- jobject obj = env->NewObjectA(bclass, ctor, &val);
- v.val.l = obj;
- v.obj = obj;
- env->DeleteLocalRef(bclass);
- } else {
- v.val.z = *p_arg;
- };
- } break;
- case Variant::INT: {
-
- if (force_jobject) {
-
- jclass bclass = env->FindClass("java/lang/Integer");
- jmethodID ctor = env->GetMethodID(bclass, "<init>", "(I)V");
- jvalue val;
- val.i = (int)(*p_arg);
- jobject obj = env->NewObjectA(bclass, ctor, &val);
- v.val.l = obj;
- v.obj = obj;
- env->DeleteLocalRef(bclass);
-
- } else {
- v.val.i = *p_arg;
- };
- } break;
- case Variant::REAL: {
-
- if (force_jobject) {
-
- jclass bclass = env->FindClass("java/lang/Double");
- jmethodID ctor = env->GetMethodID(bclass, "<init>", "(D)V");
- jvalue val;
- val.d = (double)(*p_arg);
- jobject obj = env->NewObjectA(bclass, ctor, &val);
- v.val.l = obj;
- v.obj = obj;
- env->DeleteLocalRef(bclass);
-
- } else {
- v.val.f = *p_arg;
- };
- } break;
- case Variant::STRING: {
-
- String s = *p_arg;
- jstring jStr = env->NewStringUTF(s.utf8().get_data());
- v.val.l = jStr;
- v.obj = jStr;
- } break;
- case Variant::POOL_STRING_ARRAY: {
-
- PoolVector<String> sarray = *p_arg;
- jobjectArray arr = env->NewObjectArray(sarray.size(), env->FindClass("java/lang/String"), env->NewStringUTF(""));
-
- for (int j = 0; j < sarray.size(); j++) {
-
- jstring str = env->NewStringUTF(sarray[j].utf8().get_data());
- env->SetObjectArrayElement(arr, j, str);
- env->DeleteLocalRef(str);
- }
- v.val.l = arr;
- v.obj = arr;
-
- } break;
-
- case Variant::DICTIONARY: {
-
- Dictionary dict = *p_arg;
- jclass dclass = env->FindClass("org/godotengine/godot/Dictionary");
- jmethodID ctor = env->GetMethodID(dclass, "<init>", "()V");
- jobject jdict = env->NewObject(dclass, ctor);
-
- Array keys = dict.keys();
-
- jobjectArray jkeys = env->NewObjectArray(keys.size(), env->FindClass("java/lang/String"), env->NewStringUTF(""));
- for (int j = 0; j < keys.size(); j++) {
- jstring str = env->NewStringUTF(String(keys[j]).utf8().get_data());
- env->SetObjectArrayElement(jkeys, j, str);
- env->DeleteLocalRef(str);
- };
-
- jmethodID set_keys = env->GetMethodID(dclass, "set_keys", "([Ljava/lang/String;)V");
- jvalue val;
- val.l = jkeys;
- env->CallVoidMethodA(jdict, set_keys, &val);
- env->DeleteLocalRef(jkeys);
-
- jobjectArray jvalues = env->NewObjectArray(keys.size(), env->FindClass("java/lang/Object"), NULL);
-
- for (int j = 0; j < keys.size(); j++) {
- Variant var = dict[keys[j]];
- jvalret v = _variant_to_jvalue(env, var.get_type(), &var, true);
- env->SetObjectArrayElement(jvalues, j, v.val.l);
- if (v.obj) {
- env->DeleteLocalRef(v.obj);
- }
- };
-
- jmethodID set_values = env->GetMethodID(dclass, "set_values", "([Ljava/lang/Object;)V");
- val.l = jvalues;
- env->CallVoidMethodA(jdict, set_values, &val);
- env->DeleteLocalRef(jvalues);
- env->DeleteLocalRef(dclass);
-
- v.val.l = jdict;
- v.obj = jdict;
- } break;
-
- case Variant::POOL_INT_ARRAY: {
-
- PoolVector<int> array = *p_arg;
- jintArray arr = env->NewIntArray(array.size());
- PoolVector<int>::Read r = array.read();
- env->SetIntArrayRegion(arr, 0, array.size(), r.ptr());
- v.val.l = arr;
- v.obj = arr;
-
- } break;
- case Variant::POOL_BYTE_ARRAY: {
- PoolVector<uint8_t> array = *p_arg;
- jbyteArray arr = env->NewByteArray(array.size());
- PoolVector<uint8_t>::Read r = array.read();
- env->SetByteArrayRegion(arr, 0, array.size(), reinterpret_cast<const signed char *>(r.ptr()));
- v.val.l = arr;
- v.obj = arr;
-
- } break;
- case Variant::POOL_REAL_ARRAY: {
-
- PoolVector<float> array = *p_arg;
- jfloatArray arr = env->NewFloatArray(array.size());
- PoolVector<float>::Read r = array.read();
- env->SetFloatArrayRegion(arr, 0, array.size(), r.ptr());
- v.val.l = arr;
- v.obj = arr;
-
- } break;
- default: {
-
- v.val.i = 0;
- } break;
- }
- return v;
-}
-
-String _get_class_name(JNIEnv *env, jclass cls, bool *array) {
-
- jclass cclass = env->FindClass("java/lang/Class");
- jmethodID getName = env->GetMethodID(cclass, "getName", "()Ljava/lang/String;");
- jstring clsName = (jstring)env->CallObjectMethod(cls, getName);
-
- if (array) {
- jmethodID isArray = env->GetMethodID(cclass, "isArray", "()Z");
- jboolean isarr = env->CallBooleanMethod(cls, isArray);
- (*array) = isarr ? true : false;
- }
- String name = jstring_to_string(clsName, env);
- env->DeleteLocalRef(clsName);
-
- return name;
-}
-
-Variant _jobject_to_variant(JNIEnv *env, jobject obj) {
-
- if (obj == NULL) {
- return Variant();
- }
-
- jclass c = env->GetObjectClass(obj);
- bool array;
- String name = _get_class_name(env, c, &array);
-
- if (name == "java.lang.String") {
-
- return jstring_to_string((jstring)obj, env);
- };
-
- if (name == "[Ljava.lang.String;") {
-
- jobjectArray arr = (jobjectArray)obj;
- int stringCount = env->GetArrayLength(arr);
- PoolVector<String> sarr;
-
- for (int i = 0; i < stringCount; i++) {
- jstring string = (jstring)env->GetObjectArrayElement(arr, i);
- sarr.push_back(jstring_to_string(string, env));
- env->DeleteLocalRef(string);
- }
-
- return sarr;
- };
-
- if (name == "java.lang.Boolean") {
-
- jmethodID boolValue = env->GetMethodID(c, "booleanValue", "()Z");
- bool ret = env->CallBooleanMethod(obj, boolValue);
- return ret;
- };
-
- if (name == "java.lang.Integer" || name == "java.lang.Long") {
-
- jclass nclass = env->FindClass("java/lang/Number");
- jmethodID longValue = env->GetMethodID(nclass, "longValue", "()J");
- jlong ret = env->CallLongMethod(obj, longValue);
- return ret;
- };
-
- if (name == "[I") {
-
- jintArray arr = (jintArray)obj;
- 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();
- return sarr;
- };
-
- if (name == "[B") {
-
- jbyteArray arr = (jbyteArray)obj;
- int fCount = env->GetArrayLength(arr);
- PoolVector<uint8_t> sarr;
- sarr.resize(fCount);
-
- PoolVector<uint8_t>::Write w = sarr.write();
- env->GetByteArrayRegion(arr, 0, fCount, reinterpret_cast<signed char *>(w.ptr()));
- w.release();
- return sarr;
- };
-
- if (name == "java.lang.Float" || name == "java.lang.Double") {
-
- jclass nclass = env->FindClass("java/lang/Number");
- jmethodID doubleValue = env->GetMethodID(nclass, "doubleValue", "()D");
- double ret = env->CallDoubleMethod(obj, doubleValue);
- return ret;
- };
-
- if (name == "[D") {
-
- jdoubleArray arr = (jdoubleArray)obj;
- int fCount = env->GetArrayLength(arr);
- PoolRealArray sarr;
- sarr.resize(fCount);
-
- PoolRealArray::Write w = sarr.write();
-
- for (int i = 0; i < fCount; i++) {
-
- double n;
- env->GetDoubleArrayRegion(arr, i, 1, &n);
- w.ptr()[i] = n;
- };
- return sarr;
- };
-
- if (name == "[F") {
-
- jfloatArray arr = (jfloatArray)obj;
- int fCount = env->GetArrayLength(arr);
- PoolRealArray sarr;
- sarr.resize(fCount);
-
- PoolRealArray::Write w = sarr.write();
-
- for (int i = 0; i < fCount; i++) {
-
- float n;
- env->GetFloatArrayRegion(arr, i, 1, &n);
- w.ptr()[i] = n;
- };
- return sarr;
- };
-
- if (name == "[Ljava.lang.Object;") {
-
- jobjectArray arr = (jobjectArray)obj;
- int objCount = env->GetArrayLength(arr);
- Array varr;
-
- for (int i = 0; i < objCount; i++) {
- jobject jobj = env->GetObjectArrayElement(arr, i);
- Variant v = _jobject_to_variant(env, jobj);
- varr.push_back(v);
- env->DeleteLocalRef(jobj);
- }
-
- return varr;
- };
-
- if (name == "java.util.HashMap" || name == "org.godotengine.godot.Dictionary") {
-
- Dictionary ret;
- jclass oclass = c;
- jmethodID get_keys = env->GetMethodID(oclass, "get_keys", "()[Ljava/lang/String;");
- jobjectArray arr = (jobjectArray)env->CallObjectMethod(obj, get_keys);
-
- PoolStringArray keys = _jobject_to_variant(env, arr);
- env->DeleteLocalRef(arr);
-
- jmethodID get_values = env->GetMethodID(oclass, "get_values", "()[Ljava/lang/Object;");
- arr = (jobjectArray)env->CallObjectMethod(obj, get_values);
-
- Array vals = _jobject_to_variant(env, arr);
- env->DeleteLocalRef(arr);
-
- for (int i = 0; i < keys.size(); i++) {
-
- ret[keys[i]] = vals[i];
- };
-
- return ret;
- };
-
- env->DeleteLocalRef(c);
-
- return Variant();
-}
-
-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;
- }
-};
-
-struct TST {
-
- int a;
- TST() {
-
- a = 5;
- }
-};
-
-TST tst;
-
static bool initialized = false;
static int step = 0;
@@ -600,20 +63,16 @@ static Vector3 accelerometer;
static Vector3 gravity;
static Vector3 magnetometer;
static Vector3 gyroscope;
-static HashMap<String, JNISingleton *> jni_singletons;
-// virtual Error native_video_play(String p_path);
-// virtual bool native_video_is_playing();
-// virtual void native_video_pause();
-// virtual void native_video_stop();
+extern "C" {
-JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_setVirtualKeyboardHeight(JNIEnv *env, jobject obj, jint p_height) {
+JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_setVirtualKeyboardHeight(JNIEnv *env, jclass clazz, jint p_height) {
if (godot_io_java) {
godot_io_java->set_vk_height(p_height);
}
}
-JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_initialize(JNIEnv *env, jobject obj, jobject activity, jobject p_asset_manager, jboolean p_use_apk_expansion) {
+JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_initialize(JNIEnv *env, jclass clazz, jobject activity, jobject p_asset_manager, jboolean p_use_apk_expansion) {
initialized = true;
@@ -646,7 +105,7 @@ JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_initialize(JNIEnv *en
godot_java->on_video_init(env);
}
-JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_ondestroy(JNIEnv *env, jobject obj, jobject activity) {
+JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_ondestroy(JNIEnv *env, jclass clazz, jobject activity) {
// lets cleanup
if (godot_io_java) {
delete godot_io_java;
@@ -659,47 +118,7 @@ JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_ondestroy(JNIEnv *env
}
}
-static void _initialize_java_modules() {
-
- if (!ProjectSettings::get_singleton()->has_setting("android/modules")) {
- return;
- }
-
- String modules = ProjectSettings::get_singleton()->get("android/modules");
- modules = modules.strip_edges();
- if (modules == String()) {
- return;
- }
- Vector<String> mods = modules.split(",", false);
-
- if (mods.size()) {
- jobject cls = godot_java->get_class_loader();
-
- // TODO create wrapper for class loader
-
- JNIEnv *env = ThreadAndroid::get_env();
- jclass classLoader = env->FindClass("java/lang/ClassLoader");
- jmethodID findClass = env->GetMethodID(classLoader, "loadClass", "(Ljava/lang/String;)Ljava/lang/Class;");
-
- for (int i = 0; i < mods.size(); i++) {
-
- String m = mods[i];
-
- print_line("Loading Android module: " + m);
- jstring strClassName = env->NewStringUTF(m.utf8().get_data());
- jclass singletonClass = (jclass)env->CallObjectMethod(cls, findClass, strClassName);
- ERR_CONTINUE_MSG(!singletonClass, "Couldn't find singleton for class: " + m + ".");
-
- jmethodID initialize = env->GetStaticMethodID(singletonClass, "initialize", "(Landroid/app/Activity;)Lorg/godotengine/godot/Godot$SingletonBase;");
- ERR_CONTINUE_MSG(!initialize, "Couldn't find proper initialize function 'public static Godot.SingletonBase Class::initialize(Activity p_activity)' initializer for singleton class: " + m + ".");
-
- jobject obj = env->CallStaticObjectMethod(singletonClass, initialize, godot_java->get_activity());
- env->NewGlobalRef(obj);
- }
- }
-}
-
-JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_setup(JNIEnv *env, jobject obj, jobjectArray p_cmdline) {
+JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_setup(JNIEnv *env, jclass clazz, jobjectArray p_cmdline) {
ThreadAndroid::setup_thread();
const char **cmdline = NULL;
@@ -739,16 +158,15 @@ JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_setup(JNIEnv *env, jo
}
java_class_wrapper = memnew(JavaClassWrapper(godot_java->get_activity()));
- _initialize_java_modules();
}
-JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_resize(JNIEnv *env, jobject obj, jint width, jint height) {
+JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_resize(JNIEnv *env, jclass clazz, jint width, jint height) {
if (os_android)
os_android->set_display_size(Size2(width, height));
}
-JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_newcontext(JNIEnv *env, jobject obj, bool p_32_bits) {
+JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_newcontext(JNIEnv *env, jclass clazz, jboolean p_32_bits) {
if (os_android) {
if (step == 0) {
@@ -763,14 +181,14 @@ JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_newcontext(JNIEnv *en
}
}
-JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_back(JNIEnv *env, jobject obj) {
+JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_back(JNIEnv *env, jclass clazz) {
if (step == 0)
return;
os_android->main_loop_request_go_back();
}
-JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_step(JNIEnv *env, jobject obj) {
+JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_step(JNIEnv *env, jclass clazz) {
if (step == -1)
return;
@@ -789,6 +207,7 @@ JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_step(JNIEnv *env, job
}
os_android->main_loop_begin();
+ godot_java->on_gl_godot_main_loop_started(env);
++step;
}
@@ -803,7 +222,7 @@ JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_step(JNIEnv *env, job
}
}
-JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_touch(JNIEnv *env, jobject obj, jint ev, jint pointer, jint count, jintArray positions) {
+JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_touch(JNIEnv *env, jclass clazz, jint ev, jint pointer, jint count, jintArray positions) {
if (step == 0)
return;
@@ -827,282 +246,28 @@ JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_touch(JNIEnv *env, jo
*/
}
-JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_hover(JNIEnv *env, jobject obj, jint p_type, jint p_x, jint p_y) {
+JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_hover(JNIEnv *env, jclass clazz, jint p_type, jint p_x, jint p_y) {
if (step == 0)
return;
os_android->process_hover(p_type, Point2(p_x, p_y));
}
-JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_doubletap(JNIEnv *env, jobject obj, jint p_x, jint p_y) {
+JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_doubletap(JNIEnv *env, jclass clazz, jint p_x, jint p_y) {
if (step == 0)
return;
os_android->process_double_tap(Point2(p_x, p_y));
}
-JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_scroll(JNIEnv *env, jobject obj, jint p_x, jint p_y) {
+JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_scroll(JNIEnv *env, jclass clazz, jint p_x, jint p_y) {
if (step == 0)
return;
os_android->process_scroll(Point2(p_x, p_y));
}
-/*
- * 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;
-}
-
-JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_joybutton(JNIEnv *env, jobject obj, jint p_device, jint p_button, jboolean p_pressed) {
+JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_joybutton(JNIEnv *env, jclass clazz, jint p_device, jint p_button, jboolean p_pressed) {
if (step == 0)
return;
@@ -1115,7 +280,7 @@ JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_joybutton(JNIEnv *env
os_android->process_joy_event(jevent);
}
-JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_joyaxis(JNIEnv *env, jobject obj, jint p_device, jint p_axis, jfloat p_value) {
+JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_joyaxis(JNIEnv *env, jclass clazz, jint p_device, jint p_axis, jfloat p_value) {
if (step == 0)
return;
@@ -1128,7 +293,7 @@ JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_joyaxis(JNIEnv *env,
os_android->process_joy_event(jevent);
}
-JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_joyhat(JNIEnv *env, jobject obj, jint p_device, jint p_hat_x, jint p_hat_y) {
+JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_joyhat(JNIEnv *env, jclass clazz, jint p_device, jint p_hat_x, jint p_hat_y) {
if (step == 0)
return;
@@ -1153,58 +318,59 @@ JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_joyhat(JNIEnv *env, j
os_android->process_joy_event(jevent);
}
-JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_joyconnectionchanged(JNIEnv *env, jobject obj, jint p_device, jboolean p_connected, jstring p_name) {
+JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_joyconnectionchanged(JNIEnv *env, jclass clazz, jint p_device, jboolean p_connected, jstring p_name) {
if (os_android) {
String name = jstring_to_string(p_name, env);
os_android->joy_connection_changed(p_device, p_connected, name);
}
}
-JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_key(JNIEnv *env, jobject obj, jint p_scancode, jint p_unicode_char, jboolean p_pressed) {
+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) {
if (step == 0)
return;
Ref<InputEventKey> ievent;
ievent.instance();
int val = p_unicode_char;
- int scancode = android_get_keysym(p_scancode);
- ievent->set_scancode(scancode);
+ 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);
ievent->set_unicode(val);
ievent->set_pressed(p_pressed);
if (val == '\n') {
- ievent->set_scancode(KEY_ENTER);
+ ievent->set_keycode(KEY_ENTER);
} else if (val == 61448) {
- ievent->set_scancode(KEY_BACKSPACE);
+ ievent->set_keycode(KEY_BACKSPACE);
ievent->set_unicode(KEY_BACKSPACE);
} else if (val == 61453) {
- ievent->set_scancode(KEY_ENTER);
+ ievent->set_keycode(KEY_ENTER);
ievent->set_unicode(KEY_ENTER);
- } else if (p_scancode == 4) {
-
+ } else if (p_keycode == 4) {
os_android->main_loop_request_go_back();
}
os_android->process_event(ievent);
}
-JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_accelerometer(JNIEnv *env, jobject obj, jfloat x, jfloat y, jfloat z) {
+JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_accelerometer(JNIEnv *env, jclass clazz, jfloat x, jfloat y, jfloat z) {
accelerometer = Vector3(x, y, z);
}
-JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_gravity(JNIEnv *env, jobject obj, jfloat x, jfloat y, jfloat z) {
+JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_gravity(JNIEnv *env, jclass clazz, jfloat x, jfloat y, jfloat z) {
gravity = Vector3(x, y, z);
}
-JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_magnetometer(JNIEnv *env, jobject obj, jfloat x, jfloat y, jfloat z) {
+JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_magnetometer(JNIEnv *env, jclass clazz, jfloat x, jfloat y, jfloat z) {
magnetometer = Vector3(x, y, z);
}
-JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_gyroscope(JNIEnv *env, jobject obj, jfloat x, jfloat y, jfloat z) {
+JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_gyroscope(JNIEnv *env, jclass clazz, jfloat x, jfloat y, jfloat z) {
gyroscope = Vector3(x, y, z);
}
-JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_focusin(JNIEnv *env, jobject obj) {
+JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_focusin(JNIEnv *env, jclass clazz) {
if (step == 0)
return;
@@ -1212,7 +378,7 @@ JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_focusin(JNIEnv *env,
os_android->main_loop_focusin();
}
-JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_focusout(JNIEnv *env, jobject obj) {
+JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_focusout(JNIEnv *env, jclass clazz) {
if (step == 0)
return;
@@ -1220,134 +386,22 @@ JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_focusout(JNIEnv *env,
os_android->main_loop_focusout();
}
-JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_audio(JNIEnv *env, jobject obj) {
+JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_audio(JNIEnv *env, jclass clazz) {
ThreadAndroid::setup_thread();
AudioDriverAndroid::thread_func(env);
}
-JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_singleton(JNIEnv *env, jobject obj, jstring name, jobject p_object) {
-
- String singname = jstring_to_string(name, env);
- JNISingleton *s = memnew(JNISingleton);
- s->set_instance(env->NewGlobalRef(p_object));
- jni_singletons[singname] = s;
-
- Engine::get_singleton()->add_singleton(Engine::Singleton(singname, s));
- ProjectSettings::get_singleton()->set(singname, s);
-}
-
-static Variant::Type get_jni_type(const String &p_type) {
-
- static struct {
- const char *name;
- Variant::Type type;
- } _type_to_vtype[] = {
- { "void", Variant::NIL },
- { "boolean", Variant::BOOL },
- { "int", Variant::INT },
- { "float", Variant::REAL },
- { "double", Variant::REAL },
- { "java.lang.String", Variant::STRING },
- { "[I", Variant::POOL_INT_ARRAY },
- { "[B", Variant::POOL_BYTE_ARRAY },
- { "[F", Variant::POOL_REAL_ARRAY },
- { "[Ljava.lang.String;", Variant::POOL_STRING_ARRAY },
- { "org.godotengine.godot.Dictionary", Variant::DICTIONARY },
- { NULL, Variant::NIL }
- };
-
- int idx = 0;
-
- while (_type_to_vtype[idx].name) {
-
- if (p_type == _type_to_vtype[idx].name)
- return _type_to_vtype[idx].type;
-
- idx++;
- }
-
- return Variant::NIL;
-}
-
-static const char *get_jni_sig(const String &p_type) {
-
- static struct {
- const char *name;
- const char *sig;
- } _type_to_vtype[] = {
- { "void", "V" },
- { "boolean", "Z" },
- { "int", "I" },
- { "float", "F" },
- { "double", "D" },
- { "java.lang.String", "Ljava/lang/String;" },
- { "org.godotengine.godot.Dictionary", "Lorg/godotengine/godot/Dictionary;" },
- { "[I", "[I" },
- { "[B", "[B" },
- { "[F", "[F" },
- { "[Ljava.lang.String;", "[Ljava/lang/String;" },
- { NULL, "V" }
- };
-
- int idx = 0;
-
- while (_type_to_vtype[idx].name) {
-
- if (p_type == _type_to_vtype[idx].name)
- return _type_to_vtype[idx].sig;
-
- idx++;
- }
-
- return "Ljava/lang/Object;";
-}
-
-JNIEXPORT jstring JNICALL Java_org_godotengine_godot_GodotLib_getGlobal(JNIEnv *env, jobject obj, jstring path) {
+JNIEXPORT jstring JNICALL Java_org_godotengine_godot_GodotLib_getGlobal(JNIEnv *env, jclass clazz, jstring path) {
String js = jstring_to_string(path, env);
return env->NewStringUTF(ProjectSettings::get_singleton()->get(js).operator String().utf8().get_data());
}
-JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_method(JNIEnv *env, jobject obj, jstring sname, jstring name, jstring ret, jobjectArray args) {
-
- String singname = jstring_to_string(sname, env);
-
- ERR_FAIL_COND(!jni_singletons.has(singname));
-
- JNISingleton *s = jni_singletons.get(singname);
+JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_callobject(JNIEnv *env, jclass clazz, jint ID, jstring method, jobjectArray params) {
- String mname = jstring_to_string(name, env);
- String retval = jstring_to_string(ret, env);
- Vector<Variant::Type> types;
- String cs = "(";
-
- int stringCount = env->GetArrayLength(args);
-
- for (int i = 0; i < stringCount; i++) {
-
- jstring string = (jstring)env->GetObjectArrayElement(args, i);
- const String rawString = jstring_to_string(string, env);
- types.push_back(get_jni_type(rawString));
- cs += get_jni_sig(rawString);
- }
-
- cs += ")";
- cs += get_jni_sig(retval);
- jclass cls = env->GetObjectClass(s->get_instance());
- jmethodID mid = env->GetMethodID(cls, mname.ascii().get_data(), cs.ascii().get_data());
- if (!mid) {
-
- print_line("Failed getting method ID " + mname);
- }
-
- s->add_method(mname, mid, types, get_jni_type(retval));
-}
-
-JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_callobject(JNIEnv *env, jobject p_obj, jint ID, jstring method, jobjectArray params) {
-
- Object *obj = ObjectDB::get_instance(ID);
+ Object *obj = ObjectDB::get_instance(ObjectID((uint64_t)ID));
ERR_FAIL_COND(!obj);
int res = env->PushLocalFrame(16);
@@ -1370,16 +424,16 @@ JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_callobject(JNIEnv *en
env->DeleteLocalRef(obj);
};
- Variant::CallError err;
+ Callable::CallError err;
obj->call(str_method, (const Variant **)vptr, count, err);
// something
env->PopLocalFrame(NULL);
}
-JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_calldeferred(JNIEnv *env, jobject p_obj, jint ID, jstring method, jobjectArray params) {
+JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_calldeferred(JNIEnv *env, jclass clazz, jint ID, jstring method, jobjectArray params) {
- Object *obj = ObjectDB::get_instance(ID);
+ Object *obj = ObjectDB::get_instance(ObjectID((uint64_t)ID));
ERR_FAIL_COND(!obj);
int res = env->PushLocalFrame(16);
@@ -1403,7 +457,7 @@ JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_calldeferred(JNIEnv *
env->PopLocalFrame(NULL);
}
-JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_requestPermissionResult(JNIEnv *env, jobject p_obj, jstring p_permission, jboolean p_result) {
+JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_requestPermissionResult(JNIEnv *env, jclass clazz, jstring p_permission, jboolean p_result) {
String permission = jstring_to_string(p_permission, env);
if (permission == "android.permission.RECORD_AUDIO" && p_result) {
AudioDriver::get_singleton()->capture_start();
@@ -1431,3 +485,4 @@ JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_onRendererPaused(JNIE
os_android->get_main_loop()->notification(MainLoop::NOTIFICATION_APP_PAUSED);
}
}
+}
diff --git a/platform/android/java_godot_lib_jni.h b/platform/android/java_godot_lib_jni.h
index 71d4547f65..a7a5970440 100644
--- a/platform/android/java_godot_lib_jni.h
+++ b/platform/android/java_godot_lib_jni.h
@@ -37,36 +37,34 @@
// These functions can be called from within JAVA and are the means by which our JAVA implementation calls back into our C++ code.
// See java/src/org/godotengine/godot/GodotLib.java for the JAVA side of this (yes that's why we have the long names)
extern "C" {
-JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_initialize(JNIEnv *env, jobject obj, jobject activity, jobject p_asset_manager, jboolean p_use_apk_expansion);
-JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_ondestroy(JNIEnv *env, jobject obj, jobject activity);
-JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_setup(JNIEnv *env, jobject obj, jobjectArray p_cmdline);
-JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_resize(JNIEnv *env, jobject obj, jint width, jint height);
-JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_newcontext(JNIEnv *env, jobject obj, bool p_32_bits);
-JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_step(JNIEnv *env, jobject obj);
-JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_back(JNIEnv *env, jobject obj);
-JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_touch(JNIEnv *env, jobject obj, jint ev, jint pointer, jint count, jintArray positions);
-JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_hover(JNIEnv *env, jobject obj, jint p_type, jint p_x, jint p_y);
-JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_doubletap(JNIEnv *env, jobject obj, jint p_x, jint p_y);
-JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_scroll(JNIEnv *env, jobject obj, jint p_x, jint p_y);
-JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_key(JNIEnv *env, jobject obj, jint p_scancode, jint p_unicode_char, jboolean p_pressed);
-JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_joybutton(JNIEnv *env, jobject obj, jint p_device, jint p_button, jboolean p_pressed);
-JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_joyaxis(JNIEnv *env, jobject obj, jint p_device, jint p_axis, jfloat p_value);
-JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_joyhat(JNIEnv *env, jobject obj, jint p_device, jint p_hat_x, jint p_hat_y);
-JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_joyconnectionchanged(JNIEnv *env, jobject obj, jint p_device, jboolean p_connected, jstring p_name);
-JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_audio(JNIEnv *env, jobject obj);
-JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_accelerometer(JNIEnv *env, jobject obj, jfloat x, jfloat y, jfloat z);
-JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_gravity(JNIEnv *env, jobject obj, jfloat x, jfloat y, jfloat z);
-JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_magnetometer(JNIEnv *env, jobject obj, jfloat x, jfloat y, jfloat z);
-JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_gyroscope(JNIEnv *env, jobject obj, jfloat x, jfloat y, jfloat z);
-JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_focusin(JNIEnv *env, jobject obj);
-JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_focusout(JNIEnv *env, jobject obj);
-JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_singleton(JNIEnv *env, jobject obj, jstring name, jobject p_object);
-JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_method(JNIEnv *env, jobject obj, jstring sname, jstring name, jstring ret, jobjectArray args);
-JNIEXPORT jstring JNICALL Java_org_godotengine_godot_GodotLib_getGlobal(JNIEnv *env, jobject obj, jstring path);
-JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_callobject(JNIEnv *env, jobject p_obj, jint ID, jstring method, jobjectArray params);
-JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_calldeferred(JNIEnv *env, jobject p_obj, jint ID, jstring method, jobjectArray params);
-JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_setVirtualKeyboardHeight(JNIEnv *env, jobject obj, jint p_height);
-JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_requestPermissionResult(JNIEnv *env, jobject p_obj, jstring p_permission, jboolean p_result);
+JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_initialize(JNIEnv *env, jclass clazz, jobject activity, jobject p_asset_manager, jboolean p_use_apk_expansion);
+JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_ondestroy(JNIEnv *env, jclass clazz, jobject activity);
+JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_setup(JNIEnv *env, jclass clazz, jobjectArray p_cmdline);
+JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_resize(JNIEnv *env, jclass clazz, jint width, jint height);
+JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_newcontext(JNIEnv *env, jclass clazz, jboolean p_32_bits);
+JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_step(JNIEnv *env, jclass clazz);
+JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_back(JNIEnv *env, jclass clazz);
+JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_touch(JNIEnv *env, jclass clazz, jint ev, jint pointer, jint count, jintArray positions);
+JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_hover(JNIEnv *env, jclass clazz, jint p_type, jint p_x, jint p_y);
+JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_doubletap(JNIEnv *env, jclass clazz, jint p_x, jint p_y);
+JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_scroll(JNIEnv *env, jclass clazz, jint p_x, jint p_y);
+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);
+JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_joybutton(JNIEnv *env, jclass clazz, jint p_device, jint p_button, jboolean p_pressed);
+JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_joyaxis(JNIEnv *env, jclass clazz, jint p_device, jint p_axis, jfloat p_value);
+JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_joyhat(JNIEnv *env, jclass clazz, jint p_device, jint p_hat_x, jint p_hat_y);
+JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_joyconnectionchanged(JNIEnv *env, jclass clazz, jint p_device, jboolean p_connected, jstring p_name);
+JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_audio(JNIEnv *env, jclass clazz);
+JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_accelerometer(JNIEnv *env, jclass clazz, jfloat x, jfloat y, jfloat z);
+JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_gravity(JNIEnv *env, jclass clazz, jfloat x, jfloat y, jfloat z);
+JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_magnetometer(JNIEnv *env, jclass clazz, jfloat x, jfloat y, jfloat z);
+JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_gyroscope(JNIEnv *env, jclass clazz, jfloat x, jfloat y, jfloat z);
+JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_focusin(JNIEnv *env, jclass clazz);
+JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_focusout(JNIEnv *env, jclass clazz);
+JNIEXPORT jstring JNICALL Java_org_godotengine_godot_GodotLib_getGlobal(JNIEnv *env, jclass clazz, jstring path);
+JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_callobject(JNIEnv *env, jclass clazz, jint ID, jstring method, jobjectArray params);
+JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_calldeferred(JNIEnv *env, jclass clazz, jint ID, jstring method, jobjectArray params);
+JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_setVirtualKeyboardHeight(JNIEnv *env, jclass clazz, jint p_height);
+JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_requestPermissionResult(JNIEnv *env, jclass clazz, jstring p_permission, jboolean p_result);
JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_onRendererResumed(JNIEnv *env, jclass clazz);
JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_onRendererPaused(JNIEnv *env, jclass clazz);
}
diff --git a/platform/android/java_godot_wrapper.cpp b/platform/android/java_godot_wrapper.cpp
index 893b786c0b..7b677c186e 100644
--- a/platform/android/java_godot_wrapper.cpp
+++ b/platform/android/java_godot_wrapper.cpp
@@ -66,6 +66,7 @@ GodotJavaWrapper::GodotJavaWrapper(JNIEnv *p_env, jobject p_godot_instance) {
_is_activity_resumed = p_env->GetMethodID(cls, "isActivityResumed", "()Z");
_vibrate = p_env->GetMethodID(cls, "vibrate", "(I)V");
_get_input_fallback_mapping = p_env->GetMethodID(cls, "getInputFallbackMapping", "()Ljava/lang/String;");
+ _on_gl_godot_main_loop_started = p_env->GetMethodID(cls, "onGLGodotMainLoopStarted", "()V");
}
GodotJavaWrapper::~GodotJavaWrapper() {
@@ -99,13 +100,6 @@ jobject GodotJavaWrapper::get_class_loader() {
}
}
-void GodotJavaWrapper::gfx_init(bool gl2) {
- // beats me what this once did, there was no code,
- // but we're getting false if our GLES3 driver is initialised
- // and true for our GLES2 driver
- // Maybe we're supposed to communicate this back or store it?
-}
-
void GodotJavaWrapper::on_video_init(JNIEnv *p_env) {
if (_on_video_init)
if (p_env == NULL)
@@ -114,6 +108,15 @@ void GodotJavaWrapper::on_video_init(JNIEnv *p_env) {
p_env->CallVoidMethod(godot_instance, _on_video_init);
}
+void GodotJavaWrapper::on_gl_godot_main_loop_started(JNIEnv *p_env) {
+ if (_on_gl_godot_main_loop_started) {
+ if (p_env == NULL) {
+ p_env = ThreadAndroid::get_env();
+ }
+ }
+ p_env->CallVoidMethod(godot_instance, _on_gl_godot_main_loop_started);
+}
+
void GodotJavaWrapper::restart(JNIEnv *p_env) {
if (_restart)
if (p_env == NULL)
diff --git a/platform/android/java_godot_wrapper.h b/platform/android/java_godot_wrapper.h
index 655f5170bf..cdab2ecc9c 100644
--- a/platform/android/java_godot_wrapper.h
+++ b/platform/android/java_godot_wrapper.h
@@ -61,6 +61,7 @@ private:
jmethodID _is_activity_resumed = 0;
jmethodID _vibrate = 0;
jmethodID _get_input_fallback_mapping = 0;
+ jmethodID _on_gl_godot_main_loop_started = 0;
public:
GodotJavaWrapper(JNIEnv *p_env, jobject p_godot_instance);
@@ -71,8 +72,8 @@ public:
jobject get_class_loader();
- void gfx_init(bool gl2);
void on_video_init(JNIEnv *p_env = NULL);
+ void on_gl_godot_main_loop_started(JNIEnv *p_env = NULL);
void restart(JNIEnv *p_env = NULL);
void force_quit(JNIEnv *p_env = NULL);
void set_keep_screen_on(bool p_enabled);
diff --git a/platform/android/jni_utils.cpp b/platform/android/jni_utils.cpp
new file mode 100644
index 0000000000..3fa4e80884
--- /dev/null
+++ b/platform/android/jni_utils.cpp
@@ -0,0 +1,434 @@
+/*************************************************************************/
+/* jni_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 "jni_utils.h"
+
+jvalret _variant_to_jvalue(JNIEnv *env, Variant::Type p_type, const Variant *p_arg, bool force_jobject) {
+
+ jvalret v;
+
+ switch (p_type) {
+
+ case Variant::BOOL: {
+
+ if (force_jobject) {
+ jclass bclass = env->FindClass("java/lang/Boolean");
+ jmethodID ctor = env->GetMethodID(bclass, "<init>", "(Z)V");
+ jvalue val;
+ val.z = (bool)(*p_arg);
+ jobject obj = env->NewObjectA(bclass, ctor, &val);
+ v.val.l = obj;
+ v.obj = obj;
+ env->DeleteLocalRef(bclass);
+ } else {
+ v.val.z = *p_arg;
+ };
+ } break;
+ case Variant::INT: {
+
+ if (force_jobject) {
+
+ jclass bclass = env->FindClass("java/lang/Integer");
+ jmethodID ctor = env->GetMethodID(bclass, "<init>", "(I)V");
+ jvalue val;
+ val.i = (int)(*p_arg);
+ jobject obj = env->NewObjectA(bclass, ctor, &val);
+ v.val.l = obj;
+ v.obj = obj;
+ env->DeleteLocalRef(bclass);
+
+ } else {
+ v.val.i = *p_arg;
+ };
+ } break;
+ case Variant::FLOAT: {
+
+ if (force_jobject) {
+
+ jclass bclass = env->FindClass("java/lang/Double");
+ jmethodID ctor = env->GetMethodID(bclass, "<init>", "(D)V");
+ jvalue val;
+ val.d = (double)(*p_arg);
+ jobject obj = env->NewObjectA(bclass, ctor, &val);
+ v.val.l = obj;
+ v.obj = obj;
+ env->DeleteLocalRef(bclass);
+
+ } else {
+ v.val.f = *p_arg;
+ };
+ } break;
+ case Variant::STRING: {
+
+ String s = *p_arg;
+ jstring jStr = env->NewStringUTF(s.utf8().get_data());
+ v.val.l = jStr;
+ v.obj = jStr;
+ } break;
+ case Variant::PACKED_STRING_ARRAY: {
+
+ Vector<String> sarray = *p_arg;
+ jobjectArray arr = env->NewObjectArray(sarray.size(), env->FindClass("java/lang/String"), env->NewStringUTF(""));
+
+ for (int j = 0; j < sarray.size(); j++) {
+
+ jstring str = env->NewStringUTF(sarray[j].utf8().get_data());
+ env->SetObjectArrayElement(arr, j, str);
+ env->DeleteLocalRef(str);
+ }
+ v.val.l = arr;
+ v.obj = arr;
+
+ } break;
+
+ case Variant::DICTIONARY: {
+
+ Dictionary dict = *p_arg;
+ jclass dclass = env->FindClass("org/godotengine/godot/Dictionary");
+ jmethodID ctor = env->GetMethodID(dclass, "<init>", "()V");
+ jobject jdict = env->NewObject(dclass, ctor);
+
+ Array keys = dict.keys();
+
+ jobjectArray jkeys = env->NewObjectArray(keys.size(), env->FindClass("java/lang/String"), env->NewStringUTF(""));
+ for (int j = 0; j < keys.size(); j++) {
+ jstring str = env->NewStringUTF(String(keys[j]).utf8().get_data());
+ env->SetObjectArrayElement(jkeys, j, str);
+ env->DeleteLocalRef(str);
+ };
+
+ jmethodID set_keys = env->GetMethodID(dclass, "set_keys", "([Ljava/lang/String;)V");
+ jvalue val;
+ val.l = jkeys;
+ env->CallVoidMethodA(jdict, set_keys, &val);
+ env->DeleteLocalRef(jkeys);
+
+ jobjectArray jvalues = env->NewObjectArray(keys.size(), env->FindClass("java/lang/Object"), NULL);
+
+ for (int j = 0; j < keys.size(); j++) {
+ Variant var = dict[keys[j]];
+ jvalret v = _variant_to_jvalue(env, var.get_type(), &var, true);
+ env->SetObjectArrayElement(jvalues, j, v.val.l);
+ if (v.obj) {
+ env->DeleteLocalRef(v.obj);
+ }
+ };
+
+ jmethodID set_values = env->GetMethodID(dclass, "set_values", "([Ljava/lang/Object;)V");
+ val.l = jvalues;
+ env->CallVoidMethodA(jdict, set_values, &val);
+ env->DeleteLocalRef(jvalues);
+ env->DeleteLocalRef(dclass);
+
+ v.val.l = jdict;
+ v.obj = jdict;
+ } break;
+
+ case Variant::PACKED_INT32_ARRAY: {
+
+ Vector<int> array = *p_arg;
+ jintArray arr = env->NewIntArray(array.size());
+ const int *r = array.ptr();
+ env->SetIntArrayRegion(arr, 0, array.size(), r);
+ v.val.l = arr;
+ v.obj = arr;
+
+ } break;
+ case Variant::PACKED_BYTE_ARRAY: {
+ Vector<uint8_t> array = *p_arg;
+ jbyteArray arr = env->NewByteArray(array.size());
+ const uint8_t *r = array.ptr();
+ env->SetByteArrayRegion(arr, 0, array.size(), reinterpret_cast<const signed char *>(r));
+ v.val.l = arr;
+ v.obj = arr;
+
+ } break;
+ case Variant::PACKED_FLOAT32_ARRAY: {
+
+ Vector<float> array = *p_arg;
+ jfloatArray arr = env->NewFloatArray(array.size());
+ const float *r = array.ptr();
+ env->SetFloatArrayRegion(arr, 0, array.size(), r);
+ v.val.l = arr;
+ v.obj = arr;
+
+ } break;
+#ifndef _MSC_VER
+#warning This is missing 64 bits arrays, I have no idea how to do it in JNI
+#endif
+
+ default: {
+
+ v.val.i = 0;
+ } break;
+ }
+ return v;
+}
+
+String _get_class_name(JNIEnv *env, jclass cls, bool *array) {
+
+ jclass cclass = env->FindClass("java/lang/Class");
+ jmethodID getName = env->GetMethodID(cclass, "getName", "()Ljava/lang/String;");
+ jstring clsName = (jstring)env->CallObjectMethod(cls, getName);
+
+ if (array) {
+ jmethodID isArray = env->GetMethodID(cclass, "isArray", "()Z");
+ jboolean isarr = env->CallBooleanMethod(cls, isArray);
+ (*array) = isarr ? true : false;
+ }
+ String name = jstring_to_string(clsName, env);
+ env->DeleteLocalRef(clsName);
+
+ return name;
+}
+
+Variant _jobject_to_variant(JNIEnv *env, jobject obj) {
+
+ if (obj == NULL) {
+ return Variant();
+ }
+
+ jclass c = env->GetObjectClass(obj);
+ bool array;
+ String name = _get_class_name(env, c, &array);
+
+ if (name == "java.lang.String") {
+
+ return jstring_to_string((jstring)obj, env);
+ };
+
+ if (name == "[Ljava.lang.String;") {
+
+ jobjectArray arr = (jobjectArray)obj;
+ int stringCount = env->GetArrayLength(arr);
+ Vector<String> sarr;
+
+ for (int i = 0; i < stringCount; i++) {
+ jstring string = (jstring)env->GetObjectArrayElement(arr, i);
+ sarr.push_back(jstring_to_string(string, env));
+ env->DeleteLocalRef(string);
+ }
+
+ return sarr;
+ };
+
+ if (name == "java.lang.Boolean") {
+
+ jmethodID boolValue = env->GetMethodID(c, "booleanValue", "()Z");
+ bool ret = env->CallBooleanMethod(obj, boolValue);
+ return ret;
+ };
+
+ if (name == "java.lang.Integer" || name == "java.lang.Long") {
+
+ jclass nclass = env->FindClass("java/lang/Number");
+ jmethodID longValue = env->GetMethodID(nclass, "longValue", "()J");
+ jlong ret = env->CallLongMethod(obj, longValue);
+ return ret;
+ };
+
+ if (name == "[I") {
+
+ jintArray arr = (jintArray)obj;
+ int fCount = env->GetArrayLength(arr);
+ Vector<int> sarr;
+ sarr.resize(fCount);
+
+ int *w = sarr.ptrw();
+ env->GetIntArrayRegion(arr, 0, fCount, w);
+ return sarr;
+ };
+
+ if (name == "[B") {
+
+ jbyteArray arr = (jbyteArray)obj;
+ int fCount = env->GetArrayLength(arr);
+ Vector<uint8_t> sarr;
+ sarr.resize(fCount);
+
+ uint8_t *w = sarr.ptrw();
+ env->GetByteArrayRegion(arr, 0, fCount, reinterpret_cast<signed char *>(w));
+ return sarr;
+ };
+
+ if (name == "java.lang.Float" || name == "java.lang.Double") {
+
+ jclass nclass = env->FindClass("java/lang/Number");
+ jmethodID doubleValue = env->GetMethodID(nclass, "doubleValue", "()D");
+ double ret = env->CallDoubleMethod(obj, doubleValue);
+ return ret;
+ };
+
+ if (name == "[D") {
+
+ jdoubleArray arr = (jdoubleArray)obj;
+ int fCount = env->GetArrayLength(arr);
+ PackedFloat32Array sarr;
+ sarr.resize(fCount);
+
+ real_t *w = sarr.ptrw();
+
+ for (int i = 0; i < fCount; i++) {
+
+ double n;
+ env->GetDoubleArrayRegion(arr, i, 1, &n);
+ w[i] = n;
+ };
+ return sarr;
+ };
+
+ if (name == "[F") {
+
+ jfloatArray arr = (jfloatArray)obj;
+ int fCount = env->GetArrayLength(arr);
+ PackedFloat32Array sarr;
+ sarr.resize(fCount);
+
+ real_t *w = sarr.ptrw();
+
+ for (int i = 0; i < fCount; i++) {
+
+ float n;
+ env->GetFloatArrayRegion(arr, i, 1, &n);
+ w[i] = n;
+ };
+ return sarr;
+ };
+
+ if (name == "[Ljava.lang.Object;") {
+
+ jobjectArray arr = (jobjectArray)obj;
+ int objCount = env->GetArrayLength(arr);
+ Array varr;
+
+ for (int i = 0; i < objCount; i++) {
+ jobject jobj = env->GetObjectArrayElement(arr, i);
+ Variant v = _jobject_to_variant(env, jobj);
+ varr.push_back(v);
+ env->DeleteLocalRef(jobj);
+ }
+
+ return varr;
+ };
+
+ if (name == "java.util.HashMap" || name == "org.godotengine.godot.Dictionary") {
+
+ Dictionary ret;
+ jclass oclass = c;
+ jmethodID get_keys = env->GetMethodID(oclass, "get_keys", "()[Ljava/lang/String;");
+ jobjectArray arr = (jobjectArray)env->CallObjectMethod(obj, get_keys);
+
+ PackedStringArray keys = _jobject_to_variant(env, arr);
+ env->DeleteLocalRef(arr);
+
+ jmethodID get_values = env->GetMethodID(oclass, "get_values", "()[Ljava/lang/Object;");
+ arr = (jobjectArray)env->CallObjectMethod(obj, get_values);
+
+ Array vals = _jobject_to_variant(env, arr);
+ env->DeleteLocalRef(arr);
+
+ for (int i = 0; i < keys.size(); i++) {
+
+ ret[keys[i]] = vals[i];
+ };
+
+ return ret;
+ };
+
+ env->DeleteLocalRef(c);
+
+ return Variant();
+}
+
+Variant::Type get_jni_type(const String &p_type) {
+
+ static struct {
+ const char *name;
+ Variant::Type type;
+ } _type_to_vtype[] = {
+ { "void", Variant::NIL },
+ { "boolean", Variant::BOOL },
+ { "int", Variant::INT },
+ { "float", Variant::FLOAT },
+ { "double", Variant::FLOAT },
+ { "java.lang.String", Variant::STRING },
+ { "[I", Variant::PACKED_INT32_ARRAY },
+ { "[B", Variant::PACKED_BYTE_ARRAY },
+ { "[F", Variant::PACKED_FLOAT32_ARRAY },
+ { "[Ljava.lang.String;", Variant::PACKED_STRING_ARRAY },
+ { "org.godotengine.godot.Dictionary", Variant::DICTIONARY },
+ { NULL, Variant::NIL }
+ };
+
+ int idx = 0;
+
+ while (_type_to_vtype[idx].name) {
+
+ if (p_type == _type_to_vtype[idx].name)
+ return _type_to_vtype[idx].type;
+
+ idx++;
+ }
+
+ return Variant::NIL;
+}
+
+const char *get_jni_sig(const String &p_type) {
+
+ static struct {
+ const char *name;
+ const char *sig;
+ } _type_to_vtype[] = {
+ { "void", "V" },
+ { "boolean", "Z" },
+ { "int", "I" },
+ { "float", "F" },
+ { "double", "D" },
+ { "java.lang.String", "Ljava/lang/String;" },
+ { "org.godotengine.godot.Dictionary", "Lorg/godotengine/godot/Dictionary;" },
+ { "[I", "[I" },
+ { "[B", "[B" },
+ { "[F", "[F" },
+ { "[Ljava.lang.String;", "[Ljava/lang/String;" },
+ { NULL, "V" }
+ };
+
+ int idx = 0;
+
+ while (_type_to_vtype[idx].name) {
+
+ if (p_type == _type_to_vtype[idx].name)
+ return _type_to_vtype[idx].sig;
+
+ idx++;
+ }
+
+ return "Ljava/lang/Object;";
+}
diff --git a/platform/android/jni_utils.h b/platform/android/jni_utils.h
new file mode 100644
index 0000000000..925340a680
--- /dev/null
+++ b/platform/android/jni_utils.h
@@ -0,0 +1,242 @@
+/*************************************************************************/
+/* jni_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 JNI_UTILS_H
+#define JNI_UTILS_H
+
+#include "string_android.h"
+#include <core/engine.h>
+#include <core/variant.h>
+#include <jni.h>
+
+struct jvalret {
+
+ jobject obj;
+ jvalue val;
+ jvalret() { obj = NULL; }
+};
+
+jvalret _variant_to_jvalue(JNIEnv *env, Variant::Type p_type, const Variant *p_arg, bool force_jobject = false);
+
+String _get_class_name(JNIEnv *env, jclass cls, bool *array);
+
+Variant _jobject_to_variant(JNIEnv *env, jobject obj);
+
+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, Callable::CallError &r_error) {
+
+ ERR_FAIL_COND_V(!instance, Variant());
+
+ r_error.error = Callable::CallError::CALL_OK;
+
+ Map<StringName, MethodData>::Element *E = method_map.find(p_method);
+ if (!E) {
+
+ r_error.error = Callable::CallError::CALL_ERROR_INVALID_METHOD;
+ return Variant();
+ }
+
+ int ac = E->get().argtypes.size();
+ if (ac < p_argcount) {
+
+ r_error.error = Callable::CallError::CALL_ERROR_TOO_FEW_ARGUMENTS;
+ r_error.argument = ac;
+ return Variant();
+ }
+
+ if (ac > p_argcount) {
+
+ r_error.error = Callable::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 = Callable::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::FLOAT: {
+
+ 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::PACKED_STRING_ARRAY: {
+
+ jobjectArray arr = (jobjectArray)env->CallObjectMethodA(instance, E->get().method, v);
+
+ ret = _jobject_to_variant(env, arr);
+
+ env->DeleteLocalRef(arr);
+ } break;
+ case Variant::PACKED_INT32_ARRAY: {
+
+ jintArray arr = (jintArray)env->CallObjectMethodA(instance, E->get().method, v);
+
+ int fCount = env->GetArrayLength(arr);
+ Vector<int> sarr;
+ sarr.resize(fCount);
+
+ int *w = sarr.ptrw();
+ env->GetIntArrayRegion(arr, 0, fCount, w);
+ ret = sarr;
+ env->DeleteLocalRef(arr);
+ } break;
+ case Variant::PACKED_FLOAT32_ARRAY: {
+
+ jfloatArray arr = (jfloatArray)env->CallObjectMethodA(instance, E->get().method, v);
+
+ int fCount = env->GetArrayLength(arr);
+ Vector<float> sarr;
+ sarr.resize(fCount);
+
+ float *w = sarr.ptrw();
+ env->GetFloatArrayRegion(arr, 0, fCount, w);
+ ret = sarr;
+ env->DeleteLocalRef(arr);
+ } break;
+
+#ifndef _MSC_VER
+#warning This is missing 64 bits arrays, I have no idea how to do it in JNI
+#endif
+ 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
diff --git a/platform/android/os_android.cpp b/platform/android/os_android.cpp
index 44c5b5d6b4..8021d6dd07 100644
--- a/platform/android/os_android.cpp
+++ b/platform/android/os_android.cpp
@@ -32,8 +32,9 @@
#include "core/io/file_access_buffered_fa.h"
#include "core/project_settings.h"
+#if defined(OPENGL_ENABLED)
#include "drivers/gles2/rasterizer_gles2.h"
-#include "drivers/gles3/rasterizer_gles3.h"
+#endif
#include "drivers/unix/dir_access_unix.h"
#include "drivers/unix/file_access_unix.h"
#include "file_access_android.h"
@@ -67,8 +68,6 @@ int OS_Android::get_video_driver_count() const {
const char *OS_Android::get_video_driver_name(int p_driver) const {
switch (p_driver) {
- case VIDEO_DRIVER_GLES3:
- return "GLES3";
case VIDEO_DRIVER_GLES2:
return "GLES2";
}
@@ -92,7 +91,7 @@ void OS_Android::initialize_core() {
FileAccess::make_default<FileAccessUnix>(FileAccess::ACCESS_RESOURCES);
else {
#ifdef USE_JAVA_FILE_ACCESS
- FileAccess::make_default<FileAccessBufferedFA<FileAccessJAndroid> >(FileAccess::ACCESS_RESOURCES);
+ FileAccess::make_default<FileAccessBufferedFA<FileAccessJAndroid>>(FileAccess::ACCESS_RESOURCES);
#else
//FileAccess::make_default<FileAccessBufferedFA<FileAccessAndroid> >(FileAccess::ACCESS_RESOURCES);
FileAccess::make_default<FileAccessAndroid>(FileAccess::ACCESS_RESOURCES);
@@ -123,46 +122,27 @@ int OS_Android::get_current_video_driver() const {
Error OS_Android::initialize(const VideoMode &p_desired, int p_video_driver, int p_audio_driver) {
- bool use_gl3 = godot_java->get_gles_version_code() >= 0x00030000;
- use_gl3 = use_gl3 && (GLOBAL_GET("rendering/quality/driver/driver_name") == "GLES3");
- bool gl_initialization_error = false;
-
- while (true) {
- if (use_gl3) {
- if (RasterizerGLES3::is_viable() == OK) {
- godot_java->gfx_init(false);
- RasterizerGLES3::register_config();
- RasterizerGLES3::make_current();
- break;
- } else {
- if (GLOBAL_GET("rendering/quality/driver/fallback_to_gles2")) {
- p_video_driver = VIDEO_DRIVER_GLES2;
- use_gl3 = false;
- continue;
- } else {
- gl_initialization_error = true;
- break;
- }
- }
+ // FIXME: Add Vulkan support. Readd fallback code from Vulkan to GLES2?
+
+#if defined(OPENGL_ENABLED)
+ if (video_driver_index == VIDEO_DRIVER_GLES2) {
+ bool gl_initialization_error = false;
+
+ if (RasterizerGLES2::is_viable() == OK) {
+ RasterizerGLES2::register_config();
+ RasterizerGLES2::make_current();
} else {
- if (RasterizerGLES2::is_viable() == OK) {
- godot_java->gfx_init(true);
- RasterizerGLES2::register_config();
- RasterizerGLES2::make_current();
- break;
- } else {
- gl_initialization_error = true;
- break;
- }
+ gl_initialization_error = true;
}
- }
- if (gl_initialization_error) {
- OS::get_singleton()->alert("Your device does not support any of the supported OpenGL versions.\n"
- "Please try updating your Android version.",
- "Unable to initialize Video driver");
- return ERR_UNAVAILABLE;
+ if (gl_initialization_error) {
+ OS::get_singleton()->alert("Your device does not support any of the supported OpenGL versions.\n"
+ "Please try updating your Android version.",
+ "Unable to initialize video driver");
+ return ERR_UNAVAILABLE;
+ }
}
+#endif
video_driver_index = p_video_driver;
@@ -178,8 +158,6 @@ Error OS_Android::initialize(const VideoMode &p_desired, int p_video_driver, int
input = memnew(InputDefault);
input->set_fallback_mapping(godot_java->get_input_fallback_mapping());
- //power_manager = memnew(PowerAndroid);
-
return OK;
}
@@ -507,9 +485,8 @@ void OS_Android::process_double_tap(Point2 p_pos) {
ev.instance();
ev->set_position(p_pos);
ev->set_global_position(p_pos);
- ev->set_pressed(true);
+ ev->set_pressed(false);
ev->set_doubleclick(true);
- ev->set_button_index(1);
input->parse_input_event(ev);
}
@@ -751,7 +728,6 @@ void OS_Android::vibrate_handheld(int p_duration_ms) {
bool OS_Android::_check_internal_feature_support(const String &p_feature) {
if (p_feature == "mobile") {
- //TODO support etc2 only if GLES3 driver is selected
return true;
}
#if defined(__aarch64__)
@@ -783,6 +759,8 @@ OS_Android::OS_Android(GodotJavaWrapper *p_godot_java, GodotIOJavaWrapper *p_god
//rasterizer = NULL;
use_gl2 = false;
+ visual_server = NULL;
+
godot_java = p_godot_java;
godot_io_java = p_godot_io_java;
diff --git a/platform/android/os_android.h b/platform/android/os_android.h
index c2f9a0992f..ec6ffe5438 100644
--- a/platform/android/os_android.h
+++ b/platform/android/os_android.h
@@ -37,7 +37,6 @@
#include "core/os/main_loop.h"
#include "drivers/unix/os_unix.h"
#include "main/input_default.h"
-//#include "power_android.h"
#include "servers/audio_server.h"
#include "servers/visual/rasterizer.h"
@@ -93,8 +92,6 @@ private:
GodotJavaWrapper *godot_java;
GodotIOJavaWrapper *godot_io_java;
- //PowerAndroid *power_manager_func;
-
int video_driver_index;
public:
diff --git a/platform/android/plugin/godot_plugin_jni.cpp b/platform/android/plugin/godot_plugin_jni.cpp
new file mode 100644
index 0000000000..7413236e5d
--- /dev/null
+++ b/platform/android/plugin/godot_plugin_jni.cpp
@@ -0,0 +1,115 @@
+/*************************************************************************/
+/* godot_plugin_jni.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 "godot_plugin_jni.h"
+
+#include <core/engine.h>
+#include <core/error_macros.h>
+#include <core/project_settings.h>
+#include <platform/android/jni_utils.h>
+#include <platform/android/string_android.h>
+
+static HashMap<String, JNISingleton *> jni_singletons;
+
+extern "C" {
+
+JNIEXPORT void JNICALL Java_org_godotengine_godot_plugin_GodotPlugin_nativeRegisterSingleton(JNIEnv *env, jobject obj, jstring name) {
+
+ String singname = jstring_to_string(name, env);
+ JNISingleton *s = memnew(JNISingleton);
+ s->set_instance(env->NewGlobalRef(obj));
+ jni_singletons[singname] = s;
+
+ Engine::get_singleton()->add_singleton(Engine::Singleton(singname, s));
+ ProjectSettings::get_singleton()->set(singname, s);
+}
+
+JNIEXPORT void JNICALL Java_org_godotengine_godot_plugin_GodotPlugin_nativeRegisterMethod(JNIEnv *env, jobject obj, jstring sname, jstring name, jstring ret, jobjectArray args) {
+
+ String singname = jstring_to_string(sname, env);
+
+ ERR_FAIL_COND(!jni_singletons.has(singname));
+
+ JNISingleton *s = jni_singletons.get(singname);
+
+ String mname = jstring_to_string(name, env);
+ String retval = jstring_to_string(ret, env);
+ Vector<Variant::Type> types;
+ String cs = "(";
+
+ int stringCount = env->GetArrayLength(args);
+
+ for (int i = 0; i < stringCount; i++) {
+
+ jstring string = (jstring)env->GetObjectArrayElement(args, i);
+ const String rawString = jstring_to_string(string, env);
+ types.push_back(get_jni_type(rawString));
+ cs += get_jni_sig(rawString);
+ }
+
+ cs += ")";
+ cs += get_jni_sig(retval);
+ jclass cls = env->GetObjectClass(s->get_instance());
+ jmethodID mid = env->GetMethodID(cls, mname.ascii().get_data(), cs.ascii().get_data());
+ if (!mid) {
+
+ print_line("Failed getting method ID " + mname);
+ }
+
+ s->add_method(mname, mid, types, get_jni_type(retval));
+}
+
+JNIEXPORT void JNICALL Java_org_godotengine_godot_plugin_GodotPlugin_nativeRegisterGDNativeLibraries(JNIEnv *env, jobject obj, jobjectArray gdnlib_paths) {
+ int gdnlib_count = env->GetArrayLength(gdnlib_paths);
+ if (gdnlib_count == 0) {
+ return;
+ }
+
+ // Retrieve the current list of gdnative libraries.
+ Array singletons = Array();
+ if (ProjectSettings::get_singleton()->has_setting("gdnative/singletons")) {
+ singletons = ProjectSettings::get_singleton()->get("gdnative/singletons");
+ }
+
+ // Insert the libraries provided by the plugin
+ for (int i = 0; i < gdnlib_count; i++) {
+ jstring relative_path = (jstring)env->GetObjectArrayElement(gdnlib_paths, i);
+
+ String path = "res://" + jstring_to_string(relative_path, env);
+ if (!singletons.has(path)) {
+ singletons.push_back(path);
+ }
+ env->DeleteLocalRef(relative_path);
+ }
+
+ // Insert the updated list back into project settings.
+ ProjectSettings::get_singleton()->set("gdnative/singletons", singletons);
+}
+}
diff --git a/platform/android/plugin/godot_plugin_jni.h b/platform/android/plugin/godot_plugin_jni.h
new file mode 100644
index 0000000000..0d613d3bfe
--- /dev/null
+++ b/platform/android/plugin/godot_plugin_jni.h
@@ -0,0 +1,43 @@
+/*************************************************************************/
+/* godot_plugin_jni.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 GODOT_PLUGIN_JNI_H
+#define GODOT_PLUGIN_JNI_H
+
+#include <android/log.h>
+#include <jni.h>
+
+extern "C" {
+JNIEXPORT void JNICALL Java_org_godotengine_godot_plugin_GodotPlugin_nativeRegisterSingleton(JNIEnv *env, jobject obj, jstring name);
+JNIEXPORT void JNICALL Java_org_godotengine_godot_plugin_GodotPlugin_nativeRegisterMethod(JNIEnv *env, jobject obj, jstring sname, jstring name, jstring ret, jobjectArray args);
+JNIEXPORT void JNICALL Java_org_godotengine_godot_plugin_GodotPlugin_nativeRegisterGDNativeLibraries(JNIEnv *env, jobject obj, jobjectArray gdnlib_paths);
+}
+
+#endif // GODOT_PLUGIN_JNI_H
diff --git a/platform/android/power_android.cpp b/platform/android/power_android.cpp
deleted file mode 100644
index b0a90312e5..0000000000
--- a/platform/android/power_android.cpp
+++ /dev/null
@@ -1,255 +0,0 @@
-/*************************************************************************/
-/* power_android.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. */
-/*************************************************************************/
-
-/*
-Adapted from corresponding SDL 2.0 code.
-*/
-
-/*
- Simple DirectMedia Layer
- Copyright (C) 1997-2017 Sam Lantinga <slouken@libsdl.org>
-
- This software is provided 'as-is', without any express or implied
- warranty. In no event will the authors be held liable for any damages
- arising from the use of this software.
-
- Permission is granted to anyone to use this software for any purpose,
- including commercial applications, and to alter it and redistribute it
- freely, subject to the following restrictions:
-
- 1. The origin of this software must not be misrepresented; you must not
- claim that you wrote the original software. If you use this software
- in a product, an acknowledgment in the product documentation would be
- appreciated but is not required.
- 2. Altered source versions must be plainly marked as such, and must not be
- misrepresented as being the original software.
- 3. This notice may not be removed or altered from any source distribution.
-*/
-
-#include "power_android.h"
-
-#include "core/error_macros.h"
-
-static void LocalReferenceHolder_Cleanup(struct LocalReferenceHolder *refholder) {
- if (refholder->m_env) {
- JNIEnv *env = refholder->m_env;
- (*env)->PopLocalFrame(env, NULL);
- --s_active;
- }
-}
-
-static struct LocalReferenceHolder LocalReferenceHolder_Setup(const char *func) {
- struct LocalReferenceHolder refholder;
- refholder.m_env = NULL;
- refholder.m_func = func;
- return refholder;
-}
-
-static bool LocalReferenceHolder_Init(struct LocalReferenceHolder *refholder, JNIEnv *env) {
- const int capacity = 16;
- if ((*env)->PushLocalFrame(env, capacity) < 0) {
- return false;
- }
- ++s_active;
- refholder->m_env = env;
- return true;
-}
-
-static SDL_bool LocalReferenceHolder_IsActive(void) {
- return s_active > 0;
-}
-
-ANativeWindow *Android_JNI_GetNativeWindow(void) {
- ANativeWindow *anw;
- jobject s;
- JNIEnv *env = Android_JNI_GetEnv();
-
- s = (*env)->CallStaticObjectMethod(env, mActivityClass, midGetNativeSurface);
- anw = ANativeWindow_fromSurface(env, s);
- (*env)->DeleteLocalRef(env, s);
-
- return anw;
-}
-
-/*
- * CODE CHUNK IMPORTED FROM SDL 2.0
- * returns 0 on success or -1 on error (others undefined then)
- * returns truthy or falsy value in plugged, charged and battery
- * returns the value in seconds and percent or -1 if not available
- */
-int Android_JNI_GetPowerInfo(int *plugged, int *charged, int *battery, int *seconds, int *percent) {
- env = Android_JNI_GetEnv();
- refs = LocalReferenceHolder_Setup(__FUNCTION__);
-
- if (!LocalReferenceHolder_Init(&refs, env)) {
- LocalReferenceHolder_Cleanup(&refs);
- return -1;
- }
- mid = (*env)->GetStaticMethodID(env, mActivityClass, "getContext", "()Landroid/content/Context;");
- context = (*env)->CallStaticObjectMethod(env, mActivityClass, mid);
- action = (*env)->NewStringUTF(env, "android.intent.action.BATTERY_CHANGED");
- cls = (*env)->FindClass(env, "android/content/IntentFilter");
- mid = (*env)->GetMethodID(env, cls, "<init>", "(Ljava/lang/String;)V");
- filter = (*env)->NewObject(env, cls, mid, action);
- (*env)->DeleteLocalRef(env, action);
- mid = (*env)->GetMethodID(env, mActivityClass, "registerReceiver", "(Landroid/content/BroadcastReceiver;Landroid/content/IntentFilter;)Landroid/content/Intent;");
- intent = (*env)->CallObjectMethod(env, context, mid, NULL, filter);
- (*env)->DeleteLocalRef(env, filter);
- cls = (*env)->GetObjectClass(env, intent);
- imid = (*env)->GetMethodID(env, cls, "getIntExtra", "(Ljava/lang/String;I)I");
-// Watch out for C89 scoping rules because of the macro
-#define GET_INT_EXTRA(var, key) \
- int var; \
- iname = (*env)->NewStringUTF(env, key); \
- var = (*env)->CallIntMethod(env, intent, imid, iname, -1); \
- (*env)->DeleteLocalRef(env, iname);
- bmid = (*env)->GetMethodID(env, cls, "getBooleanExtra", "(Ljava/lang/String;Z)Z");
-// Watch out for C89 scoping rules because of the macro
-#define GET_BOOL_EXTRA(var, key) \
- int var; \
- bname = (*env)->NewStringUTF(env, key); \
- var = (*env)->CallBooleanMethod(env, intent, bmid, bname, JNI_FALSE); \
- (*env)->DeleteLocalRef(env, bname);
- if (plugged) {
- // Watch out for C89 scoping rules because of the macro
- GET_INT_EXTRA(plug, "plugged") // == BatteryManager.EXTRA_PLUGGED (API 5)
- if (plug == -1) {
- LocalReferenceHolder_Cleanup(&refs);
- return -1;
- }
- // 1 == BatteryManager.BATTERY_PLUGGED_AC
- // 2 == BatteryManager.BATTERY_PLUGGED_USB
- *plugged = (0 < plug) ? 1 : 0;
- }
- if (charged) {
- // Watch out for C89 scoping rules because of the macro
- GET_INT_EXTRA(status, "status") // == BatteryManager.EXTRA_STATUS (API 5)
- if (status == -1) {
- LocalReferenceHolder_Cleanup(&refs);
- return -1;
- }
- // 5 == BatteryManager.BATTERY_STATUS_FULL
- *charged = (status == 5) ? 1 : 0;
- }
- if (battery) {
- GET_BOOL_EXTRA(present, "present") // == BatteryManager.EXTRA_PRESENT (API 5)
- *battery = present ? 1 : 0;
- }
- if (seconds) {
- *seconds = -1; // not possible
- }
- if (percent) {
- int level;
- int scale;
- // Watch out for C89 scoping rules because of the macro
- {
- GET_INT_EXTRA(level_temp, "level") // == BatteryManager.EXTRA_LEVEL (API 5)
- level = level_temp;
- }
- // Watch out for C89 scoping rules because of the macro
- {
- GET_INT_EXTRA(scale_temp, "scale") // == BatteryManager.EXTRA_SCALE (API 5)
- scale = scale_temp;
- }
- if ((level == -1) || (scale == -1)) {
- LocalReferenceHolder_Cleanup(&refs);
- return -1;
- }
- *percent = level * 100 / scale;
- }
- (*env)->DeleteLocalRef(env, intent);
- LocalReferenceHolder_Cleanup(&refs);
-
- return 0;
-}
-
-bool PowerAndroid::GetPowerInfo_Android() {
- int battery;
- int plugged;
- int charged;
-
- if (Android_JNI_GetPowerInfo(&plugged, &charged, &battery, &this->nsecs_left, &this->percent_left) != -1) {
- if (plugged) {
- if (charged) {
- this->power_state = OS::POWERSTATE_CHARGED;
- } else if (battery) {
- this->power_state = OS::POWERSTATE_CHARGING;
- } else {
- this->power_state = OS::POWERSTATE_NO_BATTERY;
- this->nsecs_left = -1;
- this->percent_left = -1;
- }
- } else {
- this->power_state = OS::POWERSTATE_ON_BATTERY;
- }
- } else {
- this->power_state = OS::POWERSTATE_UNKNOWN;
- this->nsecs_left = -1;
- this->percent_left = -1;
- }
-
- return true;
-}
-
-OS::PowerState PowerAndroid::get_power_state() {
- if (GetPowerInfo_Android()) {
- return power_state;
- } else {
- WARN_PRINT("Power management is not implemented on this platform, defaulting to POWERSTATE_UNKNOWN");
- return OS::POWERSTATE_UNKNOWN;
- }
-}
-
-int PowerAndroid::get_power_seconds_left() {
- if (GetPowerInfo_Android()) {
- return nsecs_left;
- } else {
- WARN_PRINT("Power management is not implemented on this platform, defaulting to -1");
- return -1;
- }
-}
-
-int PowerAndroid::get_power_percent_left() {
- if (GetPowerInfo_Android()) {
- return percent_left;
- } else {
- WARN_PRINT("Power management is not implemented on this platform, defaulting to -1");
- return -1;
- }
-}
-
-PowerAndroid::PowerAndroid() :
- nsecs_left(-1),
- percent_left(-1),
- power_state(OS::POWERSTATE_UNKNOWN) {
-}
-
-PowerAndroid::~PowerAndroid() {
-}
diff --git a/platform/android/power_android.h b/platform/android/power_android.h
deleted file mode 100644
index 9f77f3fc6b..0000000000
--- a/platform/android/power_android.h
+++ /dev/null
@@ -1,80 +0,0 @@
-/*************************************************************************/
-/* power_android.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 POWER_ANDROID_H
-#define POWER_ANDROID_H
-
-#include "core/os/os.h"
-
-#include <android/native_window_jni.h>
-
-class PowerAndroid {
-
- struct LocalReferenceHolder {
- JNIEnv *m_env;
- const char *m_func;
- };
-
-private:
- static struct LocalReferenceHolder refs;
- static JNIEnv *env;
- static jmethodID mid;
- static jobject context;
- static jstring action;
- static jclass cls;
- static jobject filter;
- static jobject intent;
- static jstring iname;
- static jmethodID imid;
- static jstring bname;
- static jmethodID bmid;
-
- int nsecs_left;
- int percent_left;
- OS::PowerState power_state;
-
- bool GetPowerInfo_Android();
- bool UpdatePowerInfo();
-
-public:
- static int s_active;
-
- PowerAndroid();
- virtual ~PowerAndroid();
- static bool LocalReferenceHolder_Init(struct LocalReferenceHolder *refholder, JNIEnv *env);
- static struct LocalReferenceHolder LocalReferenceHolder_Setup(const char *func);
- static void LocalReferenceHolder_Cleanup(struct LocalReferenceHolder *refholder);
-
- OS::PowerState get_power_state();
- int get_power_seconds_left();
- int get_power_percent_left();
-};
-
-#endif // POWER_ANDROID_H
diff --git a/platform/android/vulkan/vk_renderer_jni.cpp b/platform/android/vulkan/vk_renderer_jni.cpp
new file mode 100644
index 0000000000..3026e7daad
--- /dev/null
+++ b/platform/android/vulkan/vk_renderer_jni.cpp
@@ -0,0 +1,58 @@
+/*************************************************************************/
+/* vk_renderer_jni.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 "vk_renderer_jni.h"
+
+extern "C" {
+
+JNIEXPORT void JNICALL Java_org_godotengine_godot_vulkan_VkRenderer_nativeOnVkSurfaceCreated(JNIEnv *env, jobject obj, jobject j_surface) {
+ // TODO: complete
+}
+
+JNIEXPORT void JNICALL Java_org_godotengine_godot_vulkan_VkRenderer_nativeOnVkSurfaceChanged(JNIEnv *env, jobject object, jobject j_surface, jint width, jint height) {
+ // TODO: complete
+}
+
+JNIEXPORT void JNICALL Java_org_godotengine_godot_vulkan_VkRenderer_nativeOnVkResume(JNIEnv *env, jobject obj) {
+ // TODO: complete
+}
+
+JNIEXPORT void JNICALL Java_org_godotengine_godot_vulkan_VkRenderer_nativeOnVkDrawFrame(JNIEnv *env, jobject obj) {
+ // TODO: complete
+}
+
+JNIEXPORT void JNICALL Java_org_godotengine_godot_vulkan_VkRenderer_nativeOnVkPause(JNIEnv *env, jobject obj) {
+ // TODO: complete
+}
+
+JNIEXPORT void JNICALL Java_org_godotengine_godot_vulkan_VkRenderer_nativeOnVkDestroy(JNIEnv *env, jobject obj) {
+ // TODO: complete
+}
+}
diff --git a/platform/android/vulkan/vk_renderer_jni.h b/platform/android/vulkan/vk_renderer_jni.h
new file mode 100644
index 0000000000..017766fea2
--- /dev/null
+++ b/platform/android/vulkan/vk_renderer_jni.h
@@ -0,0 +1,46 @@
+/*************************************************************************/
+/* vk_renderer_jni.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 VK_RENDERER_JNI_H
+#define VK_RENDERER_JNI_H
+
+#include <android/log.h>
+#include <jni.h>
+
+extern "C" {
+JNIEXPORT void JNICALL Java_org_godotengine_godot_vulkan_VkRenderer_nativeOnVkSurfaceCreated(JNIEnv *env, jobject obj, jobject j_surface);
+JNIEXPORT void JNICALL Java_org_godotengine_godot_vulkan_VkRenderer_nativeOnVkSurfaceChanged(JNIEnv *env, jobject object, jobject j_surface, jint width, jint height);
+JNIEXPORT void JNICALL Java_org_godotengine_godot_vulkan_VkRenderer_nativeOnVkResume(JNIEnv *env, jobject obj);
+JNIEXPORT void JNICALL Java_org_godotengine_godot_vulkan_VkRenderer_nativeOnVkDrawFrame(JNIEnv *env, jobject obj);
+JNIEXPORT void JNICALL Java_org_godotengine_godot_vulkan_VkRenderer_nativeOnVkPause(JNIEnv *env, jobject obj);
+JNIEXPORT void JNICALL Java_org_godotengine_godot_vulkan_VkRenderer_nativeOnVkDestroy(JNIEnv *env, jobject obj);
+}
+
+#endif // VK_RENDERER_JNI_H
diff --git a/platform/haiku/audio_driver_media_kit.cpp b/platform/haiku/audio_driver_media_kit.cpp
index b7f6b57244..0a5df14743 100644
--- a/platform/haiku/audio_driver_media_kit.cpp
+++ b/platform/haiku/audio_driver_media_kit.cpp
@@ -67,7 +67,6 @@ Error AudioDriverMediaKit::init() {
ERR_FAIL_COND_V(player == NULL, ERR_CANT_OPEN);
}
- mutex = Mutex::create();
player->Start();
return OK;
@@ -108,14 +107,14 @@ void AudioDriverMediaKit::lock() {
if (!mutex)
return;
- mutex->lock();
+ mutex.lock();
}
void AudioDriverMediaKit::unlock() {
if (!mutex)
return;
- mutex->unlock();
+ mutex.unlock();
}
void AudioDriverMediaKit::finish() {
@@ -124,15 +123,9 @@ void AudioDriverMediaKit::finish() {
if (samples_in) {
memdelete_arr(samples_in);
};
-
- if (mutex) {
- memdelete(mutex);
- mutex = NULL;
- }
}
AudioDriverMediaKit::AudioDriverMediaKit() {
- mutex = NULL;
player = NULL;
}
diff --git a/platform/haiku/audio_driver_media_kit.h b/platform/haiku/audio_driver_media_kit.h
index 06a362a89e..8272780fa7 100644
--- a/platform/haiku/audio_driver_media_kit.h
+++ b/platform/haiku/audio_driver_media_kit.h
@@ -40,7 +40,7 @@
#include <SoundPlayer.h>
class AudioDriverMediaKit : public AudioDriver {
- Mutex *mutex;
+ Mutex mutex;
BSoundPlayer *player;
static int32_t *samples_in;
diff --git a/platform/haiku/haiku_direct_window.cpp b/platform/haiku/haiku_direct_window.cpp
index 3c2b7f8d10..2d7efe6b61 100644
--- a/platform/haiku/haiku_direct_window.cpp
+++ b/platform/haiku/haiku_direct_window.cpp
@@ -273,7 +273,8 @@ void HaikuDirectWindow::HandleKeyboardEvent(BMessage *message) {
event.instance();
GetKeyModifierState(event, modifiers);
event->set_pressed(message->what == B_KEY_DOWN);
- event->set_scancode(KeyMappingHaiku::get_keysym(raw_char, key));
+ event->set_keycode(KeyMappingHaiku::get_keysym(raw_char, key));
+ event->set_physical_keycode(KeyMappingHaiku::get_keysym(raw_char, key));
event->set_echo(message->HasInt32("be:key_repeat"));
event->set_unicode(0);
@@ -283,8 +284,9 @@ void HaikuDirectWindow::HandleKeyboardEvent(BMessage *message) {
}
//make it consistent across platforms.
- if (event->get_scancode() == KEY_BACKTAB) {
- event->set_scancode(KEY_TAB);
+ if (event->get_keycode() == KEY_BACKTAB) {
+ event->set_keycode(KEY_TAB);
+ event->set_physical_keycode(KEY_TAB);
event->set_shift(true);
}
diff --git a/platform/haiku/os_haiku.cpp b/platform/haiku/os_haiku.cpp
index 80ab9c6aa1..a082ba53f9 100644
--- a/platform/haiku/os_haiku.cpp
+++ b/platform/haiku/os_haiku.cpp
@@ -28,10 +28,9 @@
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/
-#include "drivers/gles3/rasterizer_gles3.h"
-
#include "os_haiku.h"
+#include "drivers/gles2/rasterizer_gles2.h"
#include "main/main.h"
#include "servers/physics/physics_server_sw.h"
#include "servers/visual/visual_server_raster.h"
@@ -78,7 +77,7 @@ int OS_Haiku::get_video_driver_count() const {
}
const char *OS_Haiku::get_video_driver_name(int p_driver) const {
- return "GLES3";
+ return "GLES2";
}
int OS_Haiku::get_current_video_driver() const {
@@ -112,9 +111,9 @@ Error OS_Haiku::initialize(const VideoMode &p_desired, int p_video_driver, int p
context_gl->initialize();
context_gl->make_current();
context_gl->set_use_vsync(current_video_mode.use_vsync);
- RasterizerGLES3::register_config();
- RasterizerGLES3::make_current();
-
+ // FIXME: That's not how the rasterizer setup should happen.
+ RasterizerGLES2::register_config();
+ RasterizerGLES2::make_current();
#endif
visual_server = memnew(VisualServerRaster);
@@ -361,18 +360,3 @@ String OS_Haiku::get_cache_path() const {
return get_config_path();
}
}
-
-OS::PowerState OS_Haiku::get_power_state() {
- WARN_PRINT("Power management is not implemented on this platform, defaulting to POWERSTATE_UNKNOWN");
- return OS::POWERSTATE_UNKNOWN;
-}
-
-int OS_Haiku::get_power_seconds_left() {
- WARN_PRINT("Power management is not implemented on this platform, defaulting to -1");
- return -1;
-}
-
-int OS_Haiku::get_power_percent_left() {
- WARN_PRINT("Power management is not implemented on this platform, defaulting to -1");
- return -1;
-}
diff --git a/platform/haiku/os_haiku.h b/platform/haiku/os_haiku.h
index c99147198d..fc8cb77a91 100644
--- a/platform/haiku/os_haiku.h
+++ b/platform/haiku/os_haiku.h
@@ -113,10 +113,6 @@ public:
virtual void get_fullscreen_mode_list(List<VideoMode> *p_list, int p_screen = 0) const;
virtual String get_executable_path() const;
- virtual OS::PowerState get_power_state();
- virtual int get_power_seconds_left();
- virtual int get_power_percent_left();
-
virtual bool _check_internal_feature_support(const String &p_feature);
virtual String get_config_path() const;
diff --git a/platform/haiku/platform_config.h b/platform/haiku/platform_config.h
index 2df3c05f36..f2d5418adf 100644
--- a/platform/haiku/platform_config.h
+++ b/platform/haiku/platform_config.h
@@ -33,5 +33,4 @@
// for ifaddrs.h needed in drivers/unix/ip_unix.cpp
#define _BSD_SOURCE 1
-#define GLES3_INCLUDE_H "thirdparty/glad/glad/glad.h"
#define GLES2_INCLUDE_H "thirdparty/glad/glad/glad.h"
diff --git a/platform/iphone/SCsub b/platform/iphone/SCsub
index fa1b124561..1f82f51888 100644
--- a/platform/iphone/SCsub
+++ b/platform/iphone/SCsub
@@ -14,6 +14,7 @@ iphone_lib = [
'in_app_store.mm',
'icloud.mm',
'ios.mm',
+ 'vulkan_context_iphone.mm',
]
env_ios = env.Clone()
diff --git a/platform/iphone/app_delegate.h b/platform/iphone/app_delegate.h
index b4454aab11..27552d781a 100644
--- a/platform/iphone/app_delegate.h
+++ b/platform/iphone/app_delegate.h
@@ -28,13 +28,22 @@
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/
+#if defined(OPENGL_ENABLED)
#import "gl_view.h"
+#endif
#import "view_controller.h"
#import <UIKit/UIKit.h>
#import <CoreMotion/CoreMotion.h>
-@interface AppDelegate : NSObject <UIApplicationDelegate, GLViewDelegate> {
+// FIXME: Add support for both GLES2 and Vulkan when GLES2 is implemented again,
+// so it can't be done with compilation time branching.
+//#if defined(OPENGL_ENABLED)
+//@interface AppDelegate : NSObject <UIApplicationDelegate, GLViewDelegate> {
+//#endif
+#if defined(VULKAN_ENABLED)
+@interface AppDelegate : NSObject <UIApplicationDelegate> {
+#endif
//@property (strong, nonatomic) UIWindow *window;
ViewController *view_controller;
bool is_focus_out;
diff --git a/platform/iphone/app_delegate.mm b/platform/iphone/app_delegate.mm
index 4de321fa04..0ac8bb7a56 100644
--- a/platform/iphone/app_delegate.mm
+++ b/platform/iphone/app_delegate.mm
@@ -32,7 +32,9 @@
#include "core/project_settings.h"
#include "drivers/coreaudio/audio_driver_coreaudio.h"
+#if defined(OPENGL_ENABLED)
#import "gl_view.h"
+#endif
#include "main/main.h"
#include "os_iphone.h"
@@ -412,10 +414,12 @@ static void on_focus_in(ViewController *view_controller, bool *is_focus_out) {
OS::VideoMode _get_video_mode() {
int backingWidth;
int backingHeight;
+#if defined(OPENGL_ENABLED)
glGetRenderbufferParameterivOES(GL_RENDERBUFFER_OES,
GL_RENDERBUFFER_WIDTH_OES, &backingWidth);
glGetRenderbufferParameterivOES(GL_RENDERBUFFER_OES,
GL_RENDERBUFFER_HEIGHT_OES, &backingHeight);
+#endif
OS::VideoMode vm;
vm.fullscreen = true;
@@ -426,7 +430,7 @@ OS::VideoMode _get_video_mode() {
};
static int frame_count = 0;
-- (void)drawView:(GLView *)view;
+- (void)drawView:(UIView *)view;
{
switch (frame_count) {
@@ -634,6 +638,7 @@ static int frame_count = 0;
return FALSE;
};
+#if defined(OPENGL_ENABLED)
// WARNING: We must *always* create the GLView after we have constructed the
// OS with iphone_main. This allows the GLView to access project settings so
// it can properly initialize the OpenGL context
@@ -642,7 +647,6 @@ static int frame_count = 0;
view_controller = [[ViewController alloc] init];
view_controller.view = glView;
- window.rootViewController = view_controller;
_set_keep_screen_on(bool(GLOBAL_DEF("display/window/energy_saving/keep_screen_on", true)) ? YES : NO);
glView.useCADisplayLink =
@@ -650,6 +654,13 @@ static int frame_count = 0;
printf("cadisaplylink: %d", glView.useCADisplayLink);
glView.animationInterval = 1.0 / kRenderingFrequency;
[glView startAnimation];
+#endif
+
+#if defined(VULKAN_ENABLED)
+ view_controller = [[ViewController alloc] init];
+#endif
+
+ window.rootViewController = view_controller;
// Show the window
[window makeKeyAndVisible];
diff --git a/platform/iphone/detect.py b/platform/iphone/detect.py
index f646b8b1d5..e01950c1db 100644
--- a/platform/iphone/detect.py
+++ b/platform/iphone/detect.py
@@ -23,6 +23,7 @@ def get_opts():
return [
('IPHONEPATH', 'Path to iPhone toolchain', '/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain'),
('IPHONESDK', 'Path to the iPhone SDK', ''),
+ BoolVariable('use_static_mvk', 'Link MoltenVK statically as Level-0 driver (better portability) or use Vulkan ICD loader (enables validation layers)', False),
BoolVariable('game_center', 'Support for game center', True),
BoolVariable('store_kit', 'Support for in-app store', True),
BoolVariable('icloud', 'Support for iCloud', True),
@@ -149,7 +150,7 @@ def configure(env):
'-framework', 'Foundation',
'-framework', 'GameController',
'-framework', 'MediaPlayer',
- '-framework', 'OpenGLES',
+ '-framework', 'Metal',
'-framework', 'QuartzCore',
'-framework', 'Security',
'-framework', 'SystemConfiguration',
@@ -170,11 +171,18 @@ def configure(env):
env.Append(CPPDEFINES=['ICLOUD_ENABLED'])
env.Prepend(CPPPATH=['$IPHONESDK/usr/include',
- '$IPHONESDK/System/Library/Frameworks/OpenGLES.framework/Headers',
'$IPHONESDK/System/Library/Frameworks/AudioUnit.framework/Headers',
])
env['ENV']['CODESIGN_ALLOCATE'] = '/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/codesign_allocate'
env.Prepend(CPPPATH=['#platform/iphone'])
- env.Append(CPPDEFINES=['IPHONE_ENABLED', 'UNIX_ENABLED', 'GLES_ENABLED', 'COREAUDIO_ENABLED'])
+ env.Append(CPPDEFINES=['IPHONE_ENABLED', 'UNIX_ENABLED', 'COREAUDIO_ENABLED'])
+
+ env.Append(CPPDEFINES=['VULKAN_ENABLED'])
+ env.Append(LINKFLAGS=['-framework', 'IOSurface'])
+ if (env['use_static_mvk']):
+ env.Append(LINKFLAGS=['-framework', 'MoltenVK'])
+ env['builtin_vulkan'] = False
+ elif not env['builtin_vulkan']:
+ env.Append(LIBS=['vulkan'])
diff --git a/platform/iphone/export/export.cpp b/platform/iphone/export/export.cpp
index b606d570c2..08f3c3f91f 100644
--- a/platform/iphone/export/export.cpp
+++ b/platform/iphone/export/export.cpp
@@ -29,6 +29,7 @@
/*************************************************************************/
#include "export.h"
+#include "core/io/image_loader.h"
#include "core/io/marshalls.h"
#include "core/io/resource_saver.h"
#include "core/io/zip_io.h"
@@ -39,6 +40,7 @@
#include "editor/editor_export.h"
#include "editor/editor_node.h"
#include "editor/editor_settings.h"
+#include "main/splash.gen.h"
#include "platform/iphone/logo.gen.h"
#include "string.h"
@@ -55,6 +57,7 @@ class EditorExportPlatformIOS : public EditorExportPlatform {
typedef Error (*FileHandler)(String p_file, void *p_userdata);
static Error _walk_dir_recursive(DirAccess *p_da, FileHandler p_handler, void *p_userdata);
static Error _codesign(String p_file, void *p_userdata);
+ void _blend_and_rotate(Ref<Image> &p_dst, Ref<Image> &p_src, bool p_rot);
struct IOSConfigData {
String pkg_name;
@@ -134,7 +137,7 @@ protected:
public:
virtual String get_name() const { return "iOS"; }
virtual String get_os_name() const { return "iOS"; }
- virtual Ref<Texture> get_logo() const { return logo; }
+ virtual Ref<Texture2D> get_logo() const { return logo; }
virtual List<String> get_binary_extensions(const Ref<EditorExportPreset> &p_preset) const {
List<String> list;
@@ -164,11 +167,9 @@ void EditorExportPlatformIOS::get_preset_features(const Ref<EditorExportPreset>
String driver = ProjectSettings::get_singleton()->get("rendering/quality/driver/driver_name");
if (driver == "GLES2") {
r_features->push_back("etc");
- } else if (driver == "GLES3") {
+ } else if (driver == "Vulkan") {
+ // FIXME: Review if this is correct.
r_features->push_back("etc2");
- if (ProjectSettings::get_singleton()->get("rendering/quality/driver/fallback_to_gles2")) {
- r_features->push_back("etc");
- }
}
Vector<String> architectures = _get_preset_architectures(p_preset);
@@ -187,21 +188,24 @@ Vector<EditorExportPlatformIOS::ExportArchitecture> EditorExportPlatformIOS::_ge
struct LoadingScreenInfo {
const char *preset_key;
const char *export_name;
+ int width;
+ int height;
+ bool rotate;
};
static const LoadingScreenInfo loading_screen_infos[] = {
- { "landscape_launch_screens/iphone_2436x1125", "Default-Landscape-X.png" },
- { "landscape_launch_screens/iphone_2208x1242", "Default-Landscape-736h@3x.png" },
- { "landscape_launch_screens/ipad_1024x768", "Default-Landscape.png" },
- { "landscape_launch_screens/ipad_2048x1536", "Default-Landscape@2x.png" },
-
- { "portrait_launch_screens/iphone_640x960", "Default-480h@2x.png" },
- { "portrait_launch_screens/iphone_640x1136", "Default-568h@2x.png" },
- { "portrait_launch_screens/iphone_750x1334", "Default-667h@2x.png" },
- { "portrait_launch_screens/iphone_1125x2436", "Default-Portrait-X.png" },
- { "portrait_launch_screens/ipad_768x1024", "Default-Portrait.png" },
- { "portrait_launch_screens/ipad_1536x2048", "Default-Portrait@2x.png" },
- { "portrait_launch_screens/iphone_1242x2208", "Default-Portrait-736h@3x.png" }
+ { "landscape_launch_screens/iphone_2436x1125", "Default-Landscape-X.png", 2436, 1125, false },
+ { "landscape_launch_screens/iphone_2208x1242", "Default-Landscape-736h@3x.png", 2208, 1242, false },
+ { "landscape_launch_screens/ipad_1024x768", "Default-Landscape.png", 1024, 768, false },
+ { "landscape_launch_screens/ipad_2048x1536", "Default-Landscape@2x.png", 2048, 1536, false },
+
+ { "portrait_launch_screens/iphone_640x960", "Default-480h@2x.png", 640, 960, true },
+ { "portrait_launch_screens/iphone_640x1136", "Default-568h@2x.png", 640, 1136, true },
+ { "portrait_launch_screens/iphone_750x1334", "Default-667h@2x.png", 750, 1334, true },
+ { "portrait_launch_screens/iphone_1125x2436", "Default-Portrait-X.png", 1125, 2436, true },
+ { "portrait_launch_screens/ipad_768x1024", "Default-Portrait.png", 768, 1024, true },
+ { "portrait_launch_screens/ipad_1536x2048", "Default-Portrait@2x.png", 1536, 2048, true },
+ { "portrait_launch_screens/iphone_1242x2208", "Default-Portrait-736h@3x.png", 1242, 2208, true }
};
void EditorExportPlatformIOS::get_export_options(List<ExportOption> *r_options) {
@@ -247,6 +251,8 @@ void EditorExportPlatformIOS::get_export_options(List<ExportOption> *r_options)
r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "orientation/landscape_right"), true));
r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "orientation/portrait_upside_down"), true));
+ r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "icons/generate_missing"), false));
+
r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "required_icons/iphone_120x120", PROPERTY_HINT_FILE, "*.png"), "")); // Home screen on iPhone/iPod Touch with retina display
r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "required_icons/ipad_76x76", PROPERTY_HINT_FILE, "*.png"), "")); // Home screen on iPad
r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "required_icons/app_store_1024x1024", PROPERTY_HINT_FILE, "*.png"), "")); // App Store
@@ -257,6 +263,8 @@ void EditorExportPlatformIOS::get_export_options(List<ExportOption> *r_options)
r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "optional_icons/spotlight_40x40", PROPERTY_HINT_FILE, "*.png"), "")); // Spotlight
r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "optional_icons/spotlight_80x80", PROPERTY_HINT_FILE, "*.png"), "")); // Spotlight on devices with retina display
+ r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "launch_screens/generate_missing"), false));
+
for (uint64_t i = 0; i < sizeof(loading_screen_infos) / sizeof(loading_screen_infos[0]); ++i) {
r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, loading_screen_infos[i].preset_key, PROPERTY_HINT_FILE, "*.png"), ""));
}
@@ -402,7 +410,7 @@ void EditorExportPlatformIOS::_fix_config_file(const Ref<EditorExportPreset> &p_
}
String EditorExportPlatformIOS::_get_additional_plist_content() {
- Vector<Ref<EditorExportPlugin> > export_plugins = EditorExport::get_singleton()->get_export_plugins();
+ Vector<Ref<EditorExportPlugin>> export_plugins = EditorExport::get_singleton()->get_export_plugins();
String result;
for (int i = 0; i < export_plugins.size(); ++i) {
result += export_plugins[i]->get_ios_plist_content();
@@ -411,7 +419,7 @@ String EditorExportPlatformIOS::_get_additional_plist_content() {
}
String EditorExportPlatformIOS::_get_linker_flags() {
- Vector<Ref<EditorExportPlugin> > export_plugins = EditorExport::get_singleton()->get_export_plugins();
+ Vector<Ref<EditorExportPlugin>> export_plugins = EditorExport::get_singleton()->get_export_plugins();
String result;
for (int i = 0; i < export_plugins.size(); ++i) {
String flags = export_plugins[i]->get_ios_linker_flags();
@@ -426,7 +434,7 @@ String EditorExportPlatformIOS::_get_linker_flags() {
}
String EditorExportPlatformIOS::_get_cpp_code() {
- Vector<Ref<EditorExportPlugin> > export_plugins = EditorExport::get_singleton()->get_export_plugins();
+ Vector<Ref<EditorExportPlugin>> export_plugins = EditorExport::get_singleton()->get_export_plugins();
String result;
for (int i = 0; i < export_plugins.size(); ++i) {
result += export_plugins[i]->get_ios_cpp_code();
@@ -434,6 +442,36 @@ String EditorExportPlatformIOS::_get_cpp_code() {
return result;
}
+void EditorExportPlatformIOS::_blend_and_rotate(Ref<Image> &p_dst, Ref<Image> &p_src, bool p_rot) {
+
+ ERR_FAIL_COND(p_dst.is_null());
+ ERR_FAIL_COND(p_src.is_null());
+
+ int sw = p_rot ? p_src->get_height() : p_src->get_width();
+ int sh = p_rot ? p_src->get_width() : p_src->get_height();
+
+ int x_pos = (p_dst->get_width() - sw) / 2;
+ int y_pos = (p_dst->get_height() - sh) / 2;
+
+ int xs = (x_pos >= 0) ? 0 : -x_pos;
+ int ys = (y_pos >= 0) ? 0 : -y_pos;
+
+ if (sw + x_pos > p_dst->get_width()) sw = p_dst->get_width() - x_pos;
+ if (sh + y_pos > p_dst->get_height()) sh = p_dst->get_height() - y_pos;
+
+ for (int y = ys; y < sh; y++) {
+ for (int x = xs; x < sw; x++) {
+ Color sc = p_rot ? p_src->get_pixel(p_src->get_width() - y - 1, x) : p_src->get_pixel(x, y);
+ Color dc = p_dst->get_pixel(x_pos + x, y_pos + y);
+ dc.r = (double)(sc.a * sc.r + dc.a * (1.0 - sc.a) * dc.r);
+ dc.g = (double)(sc.a * sc.g + dc.a * (1.0 - sc.a) * dc.g);
+ dc.b = (double)(sc.a * sc.b + dc.a * (1.0 - sc.a) * dc.b);
+ dc.a = (double)(sc.a + dc.a * (1.0 - sc.a));
+ p_dst->set_pixel(x_pos + x, y_pos + y, dc);
+ }
+ }
+}
+
struct IconInfo {
const char *preset_key;
const char *idiom;
@@ -448,8 +486,8 @@ static const IconInfo icon_infos[] = {
{ "required_icons/iphone_120x120", "iphone", "Icon-120.png", "120", "2x", "60x60", true },
{ "required_icons/iphone_120x120", "iphone", "Icon-120.png", "120", "3x", "40x40", true },
- { "required_icons/ipad_76x76", "ipad", "Icon-76.png", "76", "1x", "76x76", false },
- { "required_icons/app_store_1024x1024", "ios-marketing", "Icon-1024.png", "1024", "1x", "1024x1024", false },
+ { "required_icons/ipad_76x76", "ipad", "Icon-76.png", "76", "1x", "76x76", true },
+ { "required_icons/app_store_1024x1024", "ios-marketing", "Icon-1024.png", "1024", "1x", "1024x1024", true },
{ "optional_icons/iphone_180x180", "iphone", "Icon-180.png", "180", "3x", "60x60", false },
@@ -473,20 +511,56 @@ Error EditorExportPlatformIOS::_export_icons(const Ref<EditorExportPreset> &p_pr
for (uint64_t i = 0; i < (sizeof(icon_infos) / sizeof(icon_infos[0])); ++i) {
IconInfo info = icon_infos[i];
+ int side_size = String(info.actual_size_side).to_int();
String icon_path = p_preset->get(info.preset_key);
if (icon_path.length() == 0) {
- if (info.is_required) {
- ERR_PRINT("Required icon is not specified in the preset");
+ if ((bool)p_preset->get("icons/generate_missing")) {
+ // Resize main app icon
+ icon_path = ProjectSettings::get_singleton()->get("application/config/icon");
+ Ref<Image> img = memnew(Image);
+ Error err = ImageLoader::load_image(icon_path, img);
+ if (err != OK) {
+ ERR_PRINT("Invalid icon (" + String(info.preset_key) + "): '" + icon_path + "'.");
+ return ERR_UNCONFIGURED;
+ }
+ img->resize(side_size, side_size);
+ err = img->save_png(p_iconset_dir + info.export_name);
+ if (err) {
+ String err_str = String("Failed to export icon(" + String(info.preset_key) + "): '" + icon_path + "'.");
+ ERR_PRINT(err_str.utf8().get_data());
+ return err;
+ }
+ } else {
+ if (info.is_required) {
+ String err_str = String("Required icon (") + info.preset_key + ") is not specified in the preset.";
+ ERR_PRINT(err_str);
+ return ERR_UNCONFIGURED;
+ } else {
+ String err_str = String("Icon (") + info.preset_key + ") is not specified in the preset.";
+ WARN_PRINT(err_str);
+ }
+ continue;
+ }
+ } else {
+ // Load custom icon
+ Ref<Image> img = memnew(Image);
+ Error err = ImageLoader::load_image(icon_path, img);
+ if (err != OK) {
+ ERR_PRINT("Invalid icon (" + String(info.preset_key) + "): '" + icon_path + "'.");
return ERR_UNCONFIGURED;
}
- continue;
- }
- Error err = da->copy(icon_path, p_iconset_dir + info.export_name);
- if (err) {
- memdelete(da);
- String err_str = String("Failed to export icon: ") + icon_path;
- ERR_PRINT(err_str.utf8().get_data());
- return err;
+ if (img->get_width() != side_size || img->get_height() != side_size) {
+ ERR_PRINT("Invalid icon size (" + String(info.preset_key) + "): '" + icon_path + "'.");
+ return ERR_UNCONFIGURED;
+ }
+
+ err = da->copy(icon_path, p_iconset_dir + info.export_name);
+ if (err) {
+ memdelete(da);
+ String err_str = String("Failed to export icon(" + String(info.preset_key) + "): '" + icon_path + "'.");
+ ERR_PRINT(err_str.utf8().get_data());
+ return err;
+ }
}
sizes += String(info.actual_size_side) + "\n";
if (i > 0) {
@@ -525,13 +599,72 @@ Error EditorExportPlatformIOS::_export_loading_screens(const Ref<EditorExportPre
LoadingScreenInfo info = loading_screen_infos[i];
String loading_screen_file = p_preset->get(info.preset_key);
if (loading_screen_file.size() > 0) {
- Error err = da->copy(loading_screen_file, p_dest_dir + info.export_name);
+ // Load custom loading screens
+ Ref<Image> img = memnew(Image);
+ Error err = ImageLoader::load_image(loading_screen_file, img);
+ if (err != OK) {
+ ERR_PRINT("Invalid loading screen (" + String(info.preset_key) + "): '" + loading_screen_file + "'.");
+ return ERR_UNCONFIGURED;
+ }
+ if (img->get_width() != info.width || img->get_height() != info.height) {
+ ERR_PRINT("Invalid loading screen size (" + String(info.preset_key) + "): '" + loading_screen_file + "'.");
+ return ERR_UNCONFIGURED;
+ }
+ err = da->copy(loading_screen_file, p_dest_dir + info.export_name);
if (err) {
memdelete(da);
String err_str = String("Failed to export loading screen (") + info.preset_key + ") from path '" + loading_screen_file + "'.";
ERR_PRINT(err_str.utf8().get_data());
return err;
}
+ } else if ((bool)p_preset->get("launch_screens/generate_missing")) {
+ // Generate loading screen from the splash screen
+ Color boot_bg_color = ProjectSettings::get_singleton()->get("application/boot_splash/bg_color");
+ String boot_logo_path = ProjectSettings::get_singleton()->get("application/boot_splash/image");
+ bool boot_logo_scale = ProjectSettings::get_singleton()->get("application/boot_splash/fullsize");
+
+ Ref<Image> img = memnew(Image);
+ img->create(info.width, info.height, false, Image::FORMAT_RGBA8);
+ img->fill(boot_bg_color);
+
+ Ref<Image> img_bs;
+
+ if (boot_logo_path.length() > 0) {
+ img_bs = Ref<Image>(memnew(Image));
+ ImageLoader::load_image(boot_logo_path, img_bs);
+ }
+ if (!img_bs.is_valid()) {
+ img_bs = Ref<Image>(memnew(Image(boot_splash_png)));
+ }
+ if (img_bs.is_valid()) {
+ float aspect_ratio = (float)img_bs->get_width() / (float)img_bs->get_height();
+ if (info.rotate) {
+ if (boot_logo_scale) {
+ if (info.width * aspect_ratio <= info.height) {
+ img_bs->resize(info.width * aspect_ratio, info.width);
+ } else {
+ img_bs->resize(info.height, info.height / aspect_ratio);
+ }
+ }
+ } else {
+ if (boot_logo_scale) {
+ if (info.height * aspect_ratio <= info.width) {
+ img_bs->resize(info.height * aspect_ratio, info.height);
+ } else {
+ img_bs->resize(info.width, info.width / aspect_ratio);
+ }
+ }
+ }
+ _blend_and_rotate(img, img_bs, info.rotate);
+ }
+ Error err = img->save_png(p_dest_dir + info.export_name);
+ if (err) {
+ String err_str = String("Failed to export loading screen (") + info.preset_key + ") from splash screen.";
+ WARN_PRINT(err_str.utf8().get_data());
+ }
+ } else {
+ String err_str = String("No loading screen (") + info.preset_key + ") specified.";
+ WARN_PRINT(err_str.utf8().get_data());
}
}
memdelete(da);
@@ -643,7 +776,7 @@ struct ExportLibsData {
};
void EditorExportPlatformIOS::_add_assets_to_project(const Ref<EditorExportPreset> &p_preset, Vector<uint8_t> &p_project_data, const Vector<IOSExportAsset> &p_additional_assets) {
- Vector<Ref<EditorExportPlugin> > export_plugins = EditorExport::get_singleton()->get_export_plugins();
+ Vector<Ref<EditorExportPlugin>> export_plugins = EditorExport::get_singleton()->get_export_plugins();
Vector<String> frameworks;
for (int i = 0; i < export_plugins.size(); ++i) {
Vector<String> plugin_frameworks = export_plugins[i]->get_ios_frameworks();
@@ -787,7 +920,7 @@ Error EditorExportPlatformIOS::_export_additional_assets(const String &p_out_dir
}
Error EditorExportPlatformIOS::_export_additional_assets(const String &p_out_dir, const Vector<SharedObject> &p_libraries, Vector<IOSExportAsset> &r_exported_assets) {
- Vector<Ref<EditorExportPlugin> > export_plugins = EditorExport::get_singleton()->get_export_plugins();
+ Vector<Ref<EditorExportPlugin>> export_plugins = EditorExport::get_singleton()->get_export_plugins();
for (int i = 0; i < export_plugins.size(); i++) {
Vector<String> frameworks = export_plugins[i]->get_ios_frameworks();
Error err = _export_additional_assets(p_out_dir, frameworks, true, r_exported_assets);
@@ -1030,7 +1163,7 @@ Error EditorExportPlatformIOS::export_project(const Ref<EditorExportPreset> &p_p
print_line("Creating " + dir_name);
Error dir_err = tmp_app_path->make_dir_recursive(dir_name);
if (dir_err) {
- ERR_PRINTS("Can't create '" + dir_name + "'.");
+ ERR_PRINT("Can't create '" + dir_name + "'.");
unzClose(src_pkg_zip);
memdelete(tmp_app_path);
return ERR_CANT_CREATE;
@@ -1040,7 +1173,7 @@ Error EditorExportPlatformIOS::export_project(const Ref<EditorExportPreset> &p_p
/* write the file */
FileAccess *f = FileAccess::open(file, FileAccess::WRITE);
if (!f) {
- ERR_PRINTS("Can't write '" + file + "'.");
+ ERR_PRINT("Can't write '" + file + "'.");
unzClose(src_pkg_zip);
memdelete(tmp_app_path);
return ERR_CANT_CREATE;
@@ -1064,7 +1197,7 @@ Error EditorExportPlatformIOS::export_project(const Ref<EditorExportPreset> &p_p
unzClose(src_pkg_zip);
if (!found_library) {
- ERR_PRINTS("Requested template library '" + library_to_use + "' not found. It might be missing from your template archive.");
+ ERR_PRINT("Requested template library '" + library_to_use + "' not found. It might be missing from your template archive.");
memdelete(tmp_app_path);
return ERR_FILE_NOT_FOUND;
}
@@ -1093,7 +1226,7 @@ Error EditorExportPlatformIOS::export_project(const Ref<EditorExportPreset> &p_p
String project_file_name = dest_dir + binary_name + ".xcodeproj/project.pbxproj";
FileAccess *f = FileAccess::open(project_file_name, FileAccess::WRITE);
if (!f) {
- ERR_PRINTS("Can't write '" + project_file_name + "'.");
+ ERR_PRINT("Can't write '" + project_file_name + "'.");
return ERR_CANT_CREATE;
};
f->store_buffer(project_file_data.ptr(), project_file_data.size());
diff --git a/platform/iphone/game_center.mm b/platform/iphone/game_center.mm
index 696f61f954..99d539d4ff 100644
--- a/platform/iphone/game_center.mm
+++ b/platform/iphone/game_center.mm
@@ -198,11 +198,11 @@ void GameCenter::request_achievement_descriptions() {
ret["type"] = "achievement_descriptions";
if (error == nil) {
ret["result"] = "ok";
- PoolStringArray names;
- PoolStringArray titles;
- PoolStringArray unachieved_descriptions;
- PoolStringArray achieved_descriptions;
- PoolIntArray maximum_points;
+ PackedStringArray names;
+ PackedStringArray titles;
+ PackedStringArray unachieved_descriptions;
+ PackedStringArray achieved_descriptions;
+ PackedInt32Array maximum_points;
Array hidden;
Array replayable;
@@ -253,8 +253,8 @@ void GameCenter::request_achievements() {
ret["type"] = "achievements";
if (error == nil) {
ret["result"] = "ok";
- PoolStringArray names;
- PoolRealArray percentages;
+ PackedStringArray names;
+ PackedFloat32Array percentages;
for (int i = 0; i < [achievements count]; i++) {
diff --git a/platform/iphone/gl_view.mm b/platform/iphone/gl_view.mm
index e8d737d9c3..ede60a502d 100644
--- a/platform/iphone/gl_view.mm
+++ b/platform/iphone/gl_view.mm
@@ -47,7 +47,6 @@
@end
*/
-bool gles3_available = true;
int gl_view_base_fb;
static String keyboard_text;
static GLView *_instance = NULL;
@@ -284,20 +283,11 @@ static void clear_touches() {
kEAGLColorFormatRGBA8,
kEAGLDrawablePropertyColorFormat,
nil];
- bool fallback_gl2 = false;
- // Create a GL ES 3 context based on the gl driver from project settings
- if (GLOBAL_GET("rendering/quality/driver/driver_name") == "GLES3") {
- context = [[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES3];
- NSLog(@"Setting up an OpenGL ES 3.0 context. Based on Project Settings \"rendering/quality/driver/driver_name\"");
- if (!context && GLOBAL_GET("rendering/quality/driver/fallback_to_gles2")) {
- gles3_available = false;
- fallback_gl2 = true;
- NSLog(@"Failed to create OpenGL ES 3.0 context. Falling back to OpenGL ES 2.0");
- }
- }
+
+ // FIXME: Add Vulkan support via MoltenVK. Add fallback code back?
// Create GL ES 2 context
- if (GLOBAL_GET("rendering/quality/driver/driver_name") == "GLES2" || fallback_gl2) {
+ if (GLOBAL_GET("rendering/quality/driver/driver_name") == "GLES2") {
context = [[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES2];
NSLog(@"Setting up an OpenGL ES 2.0 context.");
if (!context) {
diff --git a/platform/iphone/icloud.mm b/platform/iphone/icloud.mm
index f846043dde..251f78f2da 100644
--- a/platform/iphone/icloud.mm
+++ b/platform/iphone/icloud.mm
@@ -80,13 +80,13 @@ Variant nsobject_to_variant(NSObject *object) {
const char *str = [(NSString *)object UTF8String];
return String::utf8(str != NULL ? str : "");
} else if ([object isKindOfClass:[NSData class]]) {
- PoolByteArray ret;
+ PackedByteArray ret;
NSData *data = (NSData *)object;
if ([data length] > 0) {
ret.resize([data length]);
{
- PoolByteArray::Write w = ret.write();
- copymem(w.ptr(), [data bytes], [data length]);
+ // PackedByteArray::Write w = ret.write();
+ copymem((void *)ret.ptr(), [data bytes], [data length]);
}
}
return ret;
@@ -184,10 +184,10 @@ NSObject *variant_to_nsobject(Variant v) {
[result addObject:value];
}
return result;
- } else if (v.get_type() == Variant::POOL_BYTE_ARRAY) {
- PoolByteArray arr = v;
- PoolByteArray::Read r = arr.read();
- NSData *result = [NSData dataWithBytes:r.ptr() length:arr.size()];
+ } else if (v.get_type() == Variant::PACKED_BYTE_ARRAY) {
+ PackedByteArray arr = v;
+ // PackedByteArray::Read r = arr.read();
+ NSData *result = [NSData dataWithBytes:arr.ptr() length:arr.size()];
return result;
}
WARN_PRINT(String("Could not add unsupported type to iCloud: '" + Variant::get_type_name(v.get_type()) + "'").utf8().get_data());
@@ -315,7 +315,7 @@ ICloud::ICloud() {
Dictionary ret;
ret["type"] = "key_value_changed";
- //PoolStringArray result_keys;
+ //PackedStringArray result_keys;
//Array result_values;
Dictionary keyValues;
String reason = "";
diff --git a/platform/iphone/in_app_store.mm b/platform/iphone/in_app_store.mm
index 855ab195b0..a8a887824f 100644
--- a/platform/iphone/in_app_store.mm
+++ b/platform/iphone/in_app_store.mm
@@ -85,12 +85,12 @@ void InAppStore::_bind_methods() {
Dictionary ret;
ret["type"] = "product_info";
ret["result"] = "ok";
- PoolStringArray titles;
- PoolStringArray descriptions;
- PoolRealArray prices;
- PoolStringArray ids;
- PoolStringArray localized_prices;
- PoolStringArray currency_codes;
+ PackedStringArray titles;
+ PackedStringArray descriptions;
+ PackedFloat32Array prices;
+ PackedStringArray ids;
+ PackedStringArray localized_prices;
+ PackedStringArray currency_codes;
for (NSUInteger i = 0; i < [products count]; i++) {
@@ -113,7 +113,7 @@ void InAppStore::_bind_methods() {
ret["localized_prices"] = localized_prices;
ret["currency_codes"] = currency_codes;
- PoolStringArray invalid_ids;
+ PackedStringArray invalid_ids;
for (NSString *ipid in response.invalidProductIdentifiers) {
@@ -133,7 +133,7 @@ Error InAppStore::request_product_info(Variant p_params) {
Dictionary params = p_params;
ERR_FAIL_COND_V(!params.has("product_ids"), ERR_INVALID_PARAMETER);
- PoolStringArray pids = params["product_ids"];
+ PackedStringArray pids = params["product_ids"];
printf("************ request product info! %i\n", pids.size());
NSMutableArray *array = [[[NSMutableArray alloc] initWithCapacity:pids.size()] autorelease];
diff --git a/platform/iphone/os_iphone.cpp b/platform/iphone/os_iphone.cpp
index 7a699f9b50..497f2f747d 100644
--- a/platform/iphone/os_iphone.cpp
+++ b/platform/iphone/os_iphone.cpp
@@ -32,8 +32,16 @@
#include "os_iphone.h"
+#if defined(OPENGL_ENABLED)
#include "drivers/gles2/rasterizer_gles2.h"
-#include "drivers/gles3/rasterizer_gles3.h"
+#endif
+
+#if defined(VULKAN_ENABLED)
+#include "servers/visual/rasterizer_rd/rasterizer_rd.h"
+// #import <QuartzCore/CAMetalLayer.h>
+#include <vulkan/vulkan_metal.h>
+#endif
+
#include "servers/visual/visual_server_raster.h"
#include "servers/visual/visual_server_wrap_mt.h"
@@ -57,8 +65,6 @@ int OSIPhone::get_video_driver_count() const {
const char *OSIPhone::get_video_driver_name(int p_driver) const {
switch (p_driver) {
- case VIDEO_DRIVER_GLES3:
- return "GLES3";
case VIDEO_DRIVER_GLES2:
return "GLES2";
}
@@ -94,7 +100,6 @@ String OSIPhone::get_unique_id() const {
void OSIPhone::initialize_core() {
OS_Unix::initialize_core();
- SemaphoreIphone::make_default();
set_data_dir(data_dir);
};
@@ -103,62 +108,44 @@ int OSIPhone::get_current_video_driver() const {
return video_driver_index;
}
-extern bool gles3_available; // from gl_view.mm
-
Error OSIPhone::initialize(const VideoMode &p_desired, int p_video_driver, int p_audio_driver) {
+ video_driver_index = p_video_driver;
- bool use_gl3 = GLOBAL_GET("rendering/quality/driver/driver_name") == "GLES3";
+#if defined(OPENGL_ENABLED)
bool gl_initialization_error = false;
- while (true) {
- if (use_gl3) {
- if (RasterizerGLES3::is_viable() == OK && gles3_available) {
- RasterizerGLES3::register_config();
- RasterizerGLES3::make_current();
- break;
- } else {
- if (GLOBAL_GET("rendering/quality/driver/fallback_to_gles2")) {
- p_video_driver = VIDEO_DRIVER_GLES2;
- use_gl3 = false;
- continue;
- } else {
- gl_initialization_error = true;
- break;
- }
- }
- } else {
- if (RasterizerGLES2::is_viable() == OK) {
- RasterizerGLES2::register_config();
- RasterizerGLES2::make_current();
- break;
- } else {
- gl_initialization_error = true;
- break;
- }
- }
+ // FIXME: Add Vulkan support via MoltenVK. Add fallback code back?
+
+ if (RasterizerGLES2::is_viable() == OK) {
+ RasterizerGLES2::register_config();
+ RasterizerGLES2::make_current();
+ } else {
+ gl_initialization_error = true;
}
if (gl_initialization_error) {
OS::get_singleton()->alert("Your device does not support any of the supported OpenGL versions.",
- "Unable to initialize Video driver");
+ "Unable to initialize video driver");
return ERR_UNAVAILABLE;
}
+#endif
+
+#if defined(VULKAN_ENABLED)
+ RasterizerRD::make_current();
+#endif
- video_driver_index = p_video_driver;
visual_server = memnew(VisualServerRaster);
// FIXME: Reimplement threaded rendering
if (get_render_thread_mode() != RENDER_THREAD_UNSAFE) {
visual_server = memnew(VisualServerWrapMT(visual_server, false));
}
-
visual_server->init();
//visual_server->cursor_set_visible(false, 0);
+#if defined(OPENGL_ENABLED)
// reset this to what it should be, it will have been set to 0 after visual_server->init() is called
- if (use_gl3)
- RasterizerStorageGLES3::system_fbo = gl_view_base_fb;
- else
- RasterizerStorageGLES2::system_fbo = gl_view_base_fb;
+ RasterizerStorageGLES2::system_fbo = gl_view_base_fb;
+#endif
AudioDriverManager::initialize(p_audio_driver);
@@ -223,7 +210,8 @@ void OSIPhone::key(uint32_t p_key, bool p_pressed) {
ev.instance();
ev->set_echo(false);
ev->set_pressed(p_pressed);
- ev->set_scancode(p_key);
+ ev->set_keycode(p_key);
+ ev->set_physical_keycode(p_key);
ev->set_unicode(p_key);
queue_event(ev);
};
@@ -465,9 +453,10 @@ bool OSIPhone::can_draw() const {
};
int OSIPhone::set_base_framebuffer(int p_fb) {
-
+#if defined(OPENGL_ENABLED)
// gl_view_base_fb has not been updated yet
- RasterizerStorageGLES3::system_fbo = p_fb;
+ RasterizerStorageGLES2::system_fbo = p_fb;
+#endif
return 0;
};
diff --git a/platform/iphone/os_iphone.h b/platform/iphone/os_iphone.h
index d2d96181f5..f42679e754 100644
--- a/platform/iphone/os_iphone.h
+++ b/platform/iphone/os_iphone.h
@@ -46,6 +46,11 @@
#include "servers/visual/rasterizer.h"
#include "servers/visual_server.h"
+#if defined(VULKAN_ENABLED)
+#include "drivers/vulkan/rendering_device_vulkan.h"
+#include "platform/iphone/vulkan_context_iphone.h"
+#endif
+
class OSIPhone : public OS_Unix {
private:
@@ -74,6 +79,10 @@ private:
MainLoop *main_loop;
+#if defined(VULKAN_ENABLED)
+ VulkanContextIPhone *context_vulkan;
+ RenderingDeviceVulkan *rendering_device_vulkan;
+#endif
VideoMode video_mode;
virtual int get_video_driver_count() const;
diff --git a/platform/iphone/platform_config.h b/platform/iphone/platform_config.h
index d39c64eed6..bc190ba956 100644
--- a/platform/iphone/platform_config.h
+++ b/platform/iphone/platform_config.h
@@ -31,7 +31,6 @@
#include <alloca.h>
#define GLES2_INCLUDE_H <ES2/gl.h>
-#define GLES3_INCLUDE_H <ES3/gl.h>
#define PLATFORM_REFCOUNT
diff --git a/platform/iphone/semaphore_iphone.cpp b/platform/iphone/semaphore_iphone.cpp
deleted file mode 100644
index 0c1d4d2d5c..0000000000
--- a/platform/iphone/semaphore_iphone.cpp
+++ /dev/null
@@ -1,112 +0,0 @@
-/*************************************************************************/
-/* semaphore_iphone.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 "semaphore_iphone.h"
-
-#include <fcntl.h>
-#include <unistd.h>
-
-void cgsem_init(cgsem_t *);
-void cgsem_post(cgsem_t *);
-void cgsem_wait(cgsem_t *);
-void cgsem_destroy(cgsem_t *);
-
-void cgsem_init(cgsem_t *cgsem) {
- int flags, fd, i;
-
- pipe(cgsem->pipefd);
-
- /* Make the pipes FD_CLOEXEC to allow them to close should we call
- * execv on restart. */
- for (i = 0; i < 2; i++) {
- fd = cgsem->pipefd[i];
- flags = fcntl(fd, F_GETFD, 0);
- flags |= FD_CLOEXEC;
- fcntl(fd, F_SETFD, flags);
- }
-}
-
-void cgsem_post(cgsem_t *cgsem) {
- const char buf = 1;
-
- write(cgsem->pipefd[1], &buf, 1);
-}
-
-void cgsem_wait(cgsem_t *cgsem) {
- char buf;
-
- read(cgsem->pipefd[0], &buf, 1);
-}
-
-void cgsem_destroy(cgsem_t *cgsem) {
- close(cgsem->pipefd[1]);
- close(cgsem->pipefd[0]);
-}
-
-#include "core/os/memory.h"
-
-#include <errno.h>
-
-Error SemaphoreIphone::wait() {
-
- cgsem_wait(&sem);
- return OK;
-}
-
-Error SemaphoreIphone::post() {
-
- cgsem_post(&sem);
-
- return OK;
-}
-int SemaphoreIphone::get() const {
-
- return 0;
-}
-
-Semaphore *SemaphoreIphone::create_semaphore_iphone() {
-
- return memnew(SemaphoreIphone);
-}
-
-void SemaphoreIphone::make_default() {
-
- create_func = create_semaphore_iphone;
-}
-
-SemaphoreIphone::SemaphoreIphone() {
-
- cgsem_init(&sem);
-}
-
-SemaphoreIphone::~SemaphoreIphone() {
-
- cgsem_destroy(&sem);
-}
diff --git a/platform/uwp/power_uwp.h b/platform/iphone/vulkan_context_iphone.h
index 5e28cf65e5..200057e14d 100644
--- a/platform/uwp/power_uwp.h
+++ b/platform/iphone/vulkan_context_iphone.h
@@ -1,5 +1,5 @@
/*************************************************************************/
-/* power_uwp.h */
+/* vulkan_context_osx.h */
/*************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
@@ -28,29 +28,21 @@
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/
-#ifndef POWER_UWP_H
-#define POWER_UWP_H
+#ifndef VULKAN_CONTEXT_IPHONE_H
+#define VULKAN_CONTEXT_IPHONE_H
-#include "core/os/dir_access.h"
-#include "core/os/file_access.h"
-#include "core/os/os.h"
+#include "drivers/vulkan/vulkan_context.h"
+// #import <UIKit/UIKit.h>
-class PowerUWP {
+class VulkanContextIPhone : public VulkanContext {
-private:
- int nsecs_left;
- int percent_left;
- OS::PowerState power_state;
-
- bool UpdatePowerInfo();
+ virtual const char *_get_platform_surface_extension() const;
public:
- PowerUWP();
- virtual ~PowerUWP();
+ int window_create(void *p_window, int p_width, int p_height);
- OS::PowerState get_power_state();
- int get_power_seconds_left();
- int get_power_percent_left();
+ VulkanContextIPhone();
+ ~VulkanContextIPhone();
};
-#endif // POWER_UWP_H
+#endif // VULKAN_CONTEXT_IPHONE_H
diff --git a/platform/iphone/vulkan_context_iphone.mm b/platform/iphone/vulkan_context_iphone.mm
new file mode 100644
index 0000000000..f49b85c097
--- /dev/null
+++ b/platform/iphone/vulkan_context_iphone.mm
@@ -0,0 +1,56 @@
+/*************************************************************************/
+/* vulkan_context_osx.mm */
+/*************************************************************************/
+/* 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 "vulkan_context_iphone.h"
+#include <vulkan/vulkan_ios.h>
+
+const char *VulkanContextIPhone::_get_platform_surface_extension() const {
+ return VK_MVK_IOS_SURFACE_EXTENSION_NAME;
+}
+
+int VulkanContextIPhone::window_create(void *p_window, int p_width, int p_height) {
+
+ VkIOSSurfaceCreateInfoMVK createInfo;
+ createInfo.sType = VK_STRUCTURE_TYPE_MACOS_SURFACE_CREATE_INFO_MVK;
+ createInfo.pNext = NULL;
+ createInfo.flags = 0;
+ createInfo.pView = p_window;
+
+ VkSurfaceKHR surface;
+ VkResult err = vkCreateIOSSurfaceMVK(_get_instance(), &createInfo, NULL, &surface);
+ ERR_FAIL_COND_V(err, -1);
+ return _window_create(surface, p_width, p_height);
+}
+
+VulkanContextIPhone::VulkanContextIPhone() {
+}
+
+VulkanContextIPhone::~VulkanContextIPhone() {
+}
diff --git a/platform/javascript/SCsub b/platform/javascript/SCsub
index 85a633442e..d3cd8f76b7 100644
--- a/platform/javascript/SCsub
+++ b/platform/javascript/SCsub
@@ -10,8 +10,11 @@ javascript_files = [
'os_javascript.cpp',
]
-build = env.add_program(['#bin/godot${PROGSUFFIX}.js', '#bin/godot${PROGSUFFIX}.wasm'], javascript_files);
-js, wasm = build
+build_targets = ['#bin/godot${PROGSUFFIX}.js', '#bin/godot${PROGSUFFIX}.wasm']
+if env['threads_enabled']:
+ build_targets.append('#bin/godot${PROGSUFFIX}.worker.js')
+
+build = env.add_program(build_targets, javascript_files)
js_libraries = [
'http_request.js',
@@ -27,18 +30,38 @@ for module in js_modules:
env.Append(LINKFLAGS=['--pre-js', env.File(module).path])
env.Depends(build, js_modules)
-wrapper_start = env.File('pre.js')
-wrapper_end = env.File('engine.js')
-js_wrapped = env.Textfile('#bin/godot', [wrapper_start, js, wrapper_end], TEXTFILESUFFIX='${PROGSUFFIX}.wrapped.js')
+engine = [
+ 'engine/preloader.js',
+ 'engine/loader.js',
+ 'engine/utils.js',
+ 'engine/engine.js',
+]
+externs = [
+ env.File('#platform/javascript/engine/externs.js')
+]
+js_engine = env.CreateEngineFile('#bin/godot${PROGSUFFIX}.engine.js', engine, externs)
+env.Depends(js_engine, externs)
+
+wrap_list = [
+ build[0],
+ js_engine,
+]
+js_wrapped = env.Textfile('#bin/godot', [env.File(f) for f in wrap_list], TEXTFILESUFFIX='${PROGSUFFIX}.wrapped.js')
zip_dir = env.Dir('#bin/.javascript_zip')
-zip_files = env.InstallAs([
+out_files = [
zip_dir.File('godot.js'),
zip_dir.File('godot.wasm'),
zip_dir.File('godot.html')
-], [
+]
+in_files = [
js_wrapped,
- wasm,
+ build[1],
'#misc/dist/html/full-size.html'
-])
+]
+if env['threads_enabled']:
+ in_files.append(build[2])
+ out_files.append(zip_dir.File('godot.worker.js'))
+
+zip_files = env.InstallAs(out_files, in_files)
env.Zip('#bin/godot', zip_files, ZIPROOT=zip_dir, ZIPSUFFIX='${PROGSUFFIX}${ZIPSUFFIX}', ZIPCOMSTR='Archving $SOURCES as $TARGET')
diff --git a/platform/javascript/audio_driver_javascript.cpp b/platform/javascript/audio_driver_javascript.cpp
index f1bc7c4382..d63c6a40a5 100644
--- a/platform/javascript/audio_driver_javascript.cpp
+++ b/platform/javascript/audio_driver_javascript.cpp
@@ -69,31 +69,37 @@ void AudioDriverJavaScript::process_capture(float sample) {
Error AudioDriverJavaScript::init() {
/* clang-format off */
- EM_ASM({
- _audioDriver_audioContext = new (window.AudioContext || window.webkitAudioContext);
- _audioDriver_audioInput = null;
- _audioDriver_inputStream = null;
- _audioDriver_scriptNode = null;
+ _driver_id = EM_ASM_INT({
+ return Module.IDHandler.add({
+ 'context': new (window.AudioContext || window.webkitAudioContext),
+ 'input': null,
+ 'stream': null,
+ 'script': null
+ });
});
/* clang-format on */
int channel_count = get_total_channels_by_speaker_mode(get_speaker_mode());
/* clang-format off */
buffer_length = EM_ASM_INT({
- var CHANNEL_COUNT = $0;
+ var ref = Module.IDHandler.get($0);
+ var ctx = ref['context'];
+ var CHANNEL_COUNT = $1;
- var channelCount = _audioDriver_audioContext.destination.channelCount;
+ var channelCount = ctx.destination.channelCount;
+ var script = null;
try {
// Try letting the browser recommend a buffer length.
- _audioDriver_scriptNode = _audioDriver_audioContext.createScriptProcessor(0, 2, channelCount);
+ script = ctx.createScriptProcessor(0, 2, channelCount);
} catch (e) {
// ...otherwise, default to 4096.
- _audioDriver_scriptNode = _audioDriver_audioContext.createScriptProcessor(4096, 2, channelCount);
+ script = ctx.createScriptProcessor(4096, 2, channelCount);
}
- _audioDriver_scriptNode.connect(_audioDriver_audioContext.destination);
+ script.connect(ctx.destination);
+ ref['script'] = script;
- return _audioDriver_scriptNode.bufferSize;
- }, channel_count);
+ return script.bufferSize;
+ }, _driver_id, channel_count);
/* clang-format on */
if (!buffer_length) {
return FAILED;
@@ -112,11 +118,12 @@ void AudioDriverJavaScript::start() {
/* clang-format off */
EM_ASM({
- var INTERNAL_BUFFER_PTR = $0;
+ const ref = Module.IDHandler.get($0);
+ var INTERNAL_BUFFER_PTR = $1;
var audioDriverMixFunction = cwrap('audio_driver_js_mix');
var audioDriverProcessCapture = cwrap('audio_driver_process_capture', null, ['number']);
- _audioDriver_scriptNode.onaudioprocess = function(audioProcessingEvent) {
+ ref['script'].onaudioprocess = function(audioProcessingEvent) {
audioDriverMixFunction();
var input = audioProcessingEvent.inputBuffer;
@@ -133,7 +140,7 @@ void AudioDriverJavaScript::start() {
}
}
- if (_audioDriver_audioInput) {
+ if (ref['input']) {
var inputDataL = input.getChannelData(0);
var inputDataR = input.getChannelData(1);
for (var i = 0; i < inputDataL.length; i++) {
@@ -142,34 +149,37 @@ void AudioDriverJavaScript::start() {
}
}
};
- }, internal_buffer);
+ }, _driver_id, internal_buffer);
/* clang-format on */
}
void AudioDriverJavaScript::resume() {
/* clang-format off */
EM_ASM({
- if (_audioDriver_audioContext.resume)
- _audioDriver_audioContext.resume();
- });
+ const ref = Module.IDHandler.get($0);
+ if (ref && ref['context'] && ref['context'].resume)
+ ref['context'].resume();
+ }, _driver_id);
/* clang-format on */
}
int AudioDriverJavaScript::get_mix_rate() const {
/* clang-format off */
- return EM_ASM_INT_V({
- return _audioDriver_audioContext.sampleRate;
- });
+ return EM_ASM_INT({
+ const ref = Module.IDHandler.get($0);
+ return ref && ref['context'] ? ref['context'].sampleRate : 0;
+ }, _driver_id);
/* clang-format on */
}
AudioDriver::SpeakerMode AudioDriverJavaScript::get_speaker_mode() const {
/* clang-format off */
- return get_speaker_mode_by_total_channels(EM_ASM_INT_V({
- return _audioDriver_audioContext.destination.channelCount;
- }));
+ return get_speaker_mode_by_total_channels(EM_ASM_INT({
+ const ref = Module.IDHandler.get($0);
+ return ref && ref['context'] ? ref['context'].destination.channelCount : 0;
+ }, _driver_id));
/* clang-format on */
}
@@ -184,16 +194,15 @@ void AudioDriverJavaScript::finish() {
/* clang-format off */
EM_ASM({
- _audioDriver_audioContext = null;
- _audioDriver_audioInput = null;
- _audioDriver_scriptNode = null;
- });
+ Module.IDHandler.remove($0);
+ }, _driver_id);
/* clang-format on */
if (internal_buffer) {
memdelete_arr(internal_buffer);
internal_buffer = NULL;
}
+ _driver_id = 0;
}
Error AudioDriverJavaScript::capture_start() {
@@ -203,9 +212,10 @@ Error AudioDriverJavaScript::capture_start() {
/* clang-format off */
EM_ASM({
function gotMediaInput(stream) {
- _audioDriver_inputStream = stream;
- _audioDriver_audioInput = _audioDriver_audioContext.createMediaStreamSource(stream);
- _audioDriver_audioInput.connect(_audioDriver_scriptNode);
+ var ref = Module.IDHandler.get($0);
+ ref['stream'] = stream;
+ ref['input'] = ref['context'].createMediaStreamSource(stream);
+ ref['input'].connect(ref['script']);
}
function gotMediaInputError(e) {
@@ -219,7 +229,7 @@ Error AudioDriverJavaScript::capture_start() {
navigator.getUserMedia = navigator.webkitGetUserMedia || navigator.mozGetUserMedia;
navigator.getUserMedia({"audio": true}, gotMediaInput, gotMediaInputError);
}
- });
+ }, _driver_id);
/* clang-format on */
return OK;
@@ -229,20 +239,21 @@ Error AudioDriverJavaScript::capture_stop() {
/* clang-format off */
EM_ASM({
- if (_audioDriver_inputStream) {
- const tracks = _audioDriver_inputStream.getTracks();
+ var ref = Module.IDHandler.get($0);
+ if (ref['stream']) {
+ const tracks = ref['stream'].getTracks();
for (var i = 0; i < tracks.length; i++) {
tracks[i].stop();
}
- _audioDriver_inputStream = null;
+ ref['stream'] = null;
}
- if (_audioDriver_audioInput) {
- _audioDriver_audioInput.disconnect();
- _audioDriver_audioInput = null;
+ if (ref['input']) {
+ ref['input'].disconnect();
+ ref['input'] = null;
}
- });
+ }, _driver_id);
/* clang-format on */
input_buffer.clear();
@@ -252,7 +263,9 @@ Error AudioDriverJavaScript::capture_stop() {
AudioDriverJavaScript::AudioDriverJavaScript() {
+ _driver_id = 0;
internal_buffer = NULL;
+ buffer_length = 0;
singleton = this;
}
diff --git a/platform/javascript/audio_driver_javascript.h b/platform/javascript/audio_driver_javascript.h
index 2bb97ba192..f6f2dacd4e 100644
--- a/platform/javascript/audio_driver_javascript.h
+++ b/platform/javascript/audio_driver_javascript.h
@@ -37,6 +37,7 @@ class AudioDriverJavaScript : public AudioDriver {
float *internal_buffer;
+ int _driver_id;
int buffer_length;
public:
diff --git a/platform/javascript/detect.py b/platform/javascript/detect.py
index 7bf3e1bc1d..fb02752aa7 100644
--- a/platform/javascript/detect.py
+++ b/platform/javascript/detect.py
@@ -1,5 +1,6 @@
import os
+from emscripten_helpers import parse_config, run_closure_compiler, create_engine_file
def is_active():
return True
@@ -18,6 +19,8 @@ def get_opts():
return [
# eval() can be a security concern, so it can be disabled.
BoolVariable('javascript_eval', 'Enable JavaScript eval interface', True),
+ BoolVariable('threads_enabled', 'Enable WebAssembly Threads support (limited browser support)', False),
+ BoolVariable('use_closure_compiler', 'Use closure compiler to minimize Javascript code', False),
]
@@ -37,7 +40,7 @@ def configure(env):
## Build type
- if env['target'] != 'debug':
+ if env['target'] == 'release':
# Use -Os to prioritize optimizing for reduced file size. This is
# particularly valuable for the web platform because it directly
# decreases download time.
@@ -46,38 +49,55 @@ def configure(env):
# run-time performance.
env.Append(CCFLAGS=['-Os'])
env.Append(LINKFLAGS=['-Os'])
- if env['target'] == 'release_debug':
- env.Append(CPPDEFINES=['DEBUG_ENABLED'])
- # Retain function names for backtraces at the cost of file size.
- env.Append(LINKFLAGS=['--profiling-funcs'])
- else:
+ elif env['target'] == 'release_debug':
+ env.Append(CCFLAGS=['-Os'])
+ env.Append(LINKFLAGS=['-Os'])
+ env.Append(CPPDEFINES=['DEBUG_ENABLED'])
+ # Retain function names for backtraces at the cost of file size.
+ env.Append(LINKFLAGS=['--profiling-funcs'])
+ else: # 'debug'
env.Append(CPPDEFINES=['DEBUG_ENABLED'])
env.Append(CCFLAGS=['-O1', '-g'])
env.Append(LINKFLAGS=['-O1', '-g'])
env.Append(LINKFLAGS=['-s', 'ASSERTIONS=1'])
- ## Compiler configuration
+ if env['tools']:
+ if not env['threads_enabled']:
+ raise RuntimeError("Threads must be enabled to build the editor. Please add the 'threads_enabled=yes' option")
+ # Tools need more memory. Initial stack memory in bytes. See `src/settings.js` in emscripten repository (will be renamed to INITIAL_MEMORY).
+ env.Append(LINKFLAGS=['-s', 'TOTAL_MEMORY=33554432'])
+ else:
+ # Disable exceptions and rtti on non-tools (template) builds
+ # These flags help keep the file size down.
+ env.Append(CCFLAGS=['-fno-exceptions', '-fno-rtti'])
+ # Don't use dynamic_cast, necessary with no-rtti.
+ env.Append(CPPDEFINES=['NO_SAFE_CAST'])
+ ## Copy env variables.
env['ENV'] = os.environ
- em_config_file = os.getenv('EM_CONFIG') or os.path.expanduser('~/.emscripten')
- if not os.path.exists(em_config_file):
- raise RuntimeError("Emscripten configuration file '%s' does not exist" % em_config_file)
- with open(em_config_file) as f:
- em_config = {}
- try:
- # Emscripten configuration file is a Python file with simple assignments.
- exec(f.read(), em_config)
- except StandardError as e:
- raise RuntimeError("Emscripten configuration file '%s' is invalid:\n%s" % (em_config_file, e))
- if 'BINARYEN_ROOT' in em_config and os.path.isdir(os.path.join(em_config.get('BINARYEN_ROOT'), 'emscripten')):
- # New style, emscripten path as a subfolder of BINARYEN_ROOT
- env.PrependENVPath('PATH', os.path.join(em_config.get('BINARYEN_ROOT'), 'emscripten'))
- elif 'EMSCRIPTEN_ROOT' in em_config:
- # Old style (but can be there as a result from previous activation, so do last)
- env.PrependENVPath('PATH', em_config.get('EMSCRIPTEN_ROOT'))
- else:
- raise RuntimeError("'BINARYEN_ROOT' or 'EMSCRIPTEN_ROOT' missing in Emscripten configuration file '%s'" % em_config_file)
+ # LTO
+ if env['use_lto']:
+ env.Append(CCFLAGS=['-s', 'WASM_OBJECT_FILES=0'])
+ env.Append(LINKFLAGS=['-s', 'WASM_OBJECT_FILES=0'])
+ env.Append(LINKFLAGS=['--llvm-lto', '1'])
+
+ # Closure compiler
+ if env['use_closure_compiler']:
+ # For emscripten support code.
+ env.Append(LINKFLAGS=['--closure', '1'])
+ # Register builder for our Engine files
+ jscc = env.Builder(generator=run_closure_compiler, suffix='.cc.js', src_suffix='.js')
+ env.Append(BUILDERS = {'BuildJS' : jscc})
+
+ # Add method that joins/compiles our Engine files.
+ env.AddMethod(create_engine_file, "CreateEngineFile")
+
+ # Closure compiler extern and support for ecmascript specs (const, let, etc).
+ env['ENV']['EMCC_CLOSURE_ARGS'] = '--language_in ECMASCRIPT6'
+
+ em_config = parse_config()
+ env.PrependENVPath('PATH', em_config['EMCC_ROOT'])
env['CC'] = 'emcc'
env['CXX'] = 'em++'
@@ -104,39 +124,31 @@ def configure(env):
env['LIBPREFIXES'] = ['$LIBPREFIX']
env['LIBSUFFIXES'] = ['$LIBSUFFIX']
- ## Compile flags
-
env.Prepend(CPPPATH=['#platform/javascript'])
env.Append(CPPDEFINES=['JAVASCRIPT_ENABLED', 'UNIX_ENABLED'])
- # No multi-threading (SharedArrayBuffer) available yet,
- # once feasible also consider memory buffer size issues.
- env.Append(CPPDEFINES=['NO_THREADS'])
-
- # Disable exceptions and rtti on non-tools (template) builds
- if not env['tools']:
- # These flags help keep the file size down.
- env.Append(CCFLAGS=['-fno-exceptions', '-fno-rtti'])
- # Don't use dynamic_cast, necessary with no-rtti.
- env.Append(CPPDEFINES=['NO_SAFE_CAST'])
-
if env['javascript_eval']:
env.Append(CPPDEFINES=['JAVASCRIPT_EVAL_ENABLED'])
- ## Link flags
+ # Thread support (via SharedArrayBuffer).
+ if env['threads_enabled']:
+ env.Append(CPPDEFINES=['PTHREAD_NO_RENAME'])
+ env.Append(CCFLAGS=['-s', 'USE_PTHREADS=1'])
+ env.Append(LINKFLAGS=['-s', 'USE_PTHREADS=1'])
+ env.Append(LINKFLAGS=['-s', 'PTHREAD_POOL_SIZE=4'])
+ env.Append(LINKFLAGS=['-s', 'WASM_MEM_MAX=2048MB'])
+ else:
+ env.Append(CPPDEFINES=['NO_THREADS'])
+
+ # Reduce code size by generating less support code (e.g. skip NodeJS support).
+ env.Append(LINKFLAGS=['-s', 'ENVIRONMENT=web,worker'])
# We use IDBFS in javascript_main.cpp. Since Emscripten 1.39.1 it needs to
# be linked explicitly.
env.Append(LIBS=['idbfs.js'])
env.Append(LINKFLAGS=['-s', 'BINARYEN=1'])
-
- # This needs to be defined for Emscripten using 'fastcomp' (default pre-1.39.0)
- # and undefined if using 'upstream'. And to make things simple, earlier
- # Emscripten versions didn't include 'fastcomp' in their path, so we check
- # against the presence of 'upstream' to conditionally add the flag.
- if not "upstream" in em_config['EMSCRIPTEN_ROOT']:
- env.Append(LINKFLAGS=['-s', 'BINARYEN_TRAP_MODE=\'clamp\''])
+ env.Append(LINKFLAGS=['-s', 'MODULARIZE=1', '-s', 'EXPORT_NAME="Godot"'])
# Allow increasing memory buffer size during runtime. This is efficient
# when using WebAssembly (in comparison to asm.js) and works well for
@@ -148,8 +160,5 @@ def configure(env):
env.Append(LINKFLAGS=['-s', 'INVOKE_RUN=0'])
- # TODO: Reevaluate usage of this setting now that engine.js manages engine runtime.
- env.Append(LINKFLAGS=['-s', 'NO_EXIT_RUNTIME=1'])
-
- #adding flag due to issue with emscripten 1.38.41 callMain method https://github.com/emscripten-core/emscripten/blob/incoming/ChangeLog.md#v13841-08072019
- env.Append(LINKFLAGS=['-s', 'EXTRA_EXPORTED_RUNTIME_METHODS=["callMain"]'])
+ # callMain for manual start, FS for preloading.
+ env.Append(LINKFLAGS=['-s', 'EXTRA_EXPORTED_RUNTIME_METHODS=["callMain", "FS"]'])
diff --git a/platform/javascript/dom_keys.inc b/platform/javascript/dom_keys.inc
index 25e88f99d1..fd9df765d2 100644
--- a/platform/javascript/dom_keys.inc
+++ b/platform/javascript/dom_keys.inc
@@ -218,7 +218,7 @@
#define DOM_VK_PA1 0xFD
#define DOM_VK_WIN_OEM_CLEAR 0xFE
-int dom2godot_scancode(int dom_keycode) {
+int dom2godot_keycode(int dom_keycode) {
if (DOM_VK_0 <= dom_keycode && dom_keycode <= DOM_VK_Z) {
// ASCII intersection
diff --git a/platform/javascript/emscripten_helpers.py b/platform/javascript/emscripten_helpers.py
new file mode 100644
index 0000000000..bda5b40a74
--- /dev/null
+++ b/platform/javascript/emscripten_helpers.py
@@ -0,0 +1,37 @@
+import os
+
+def parse_config():
+ em_config_file = os.getenv('EM_CONFIG') or os.path.expanduser('~/.emscripten')
+ if not os.path.exists(em_config_file):
+ raise RuntimeError("Emscripten configuration file '%s' does not exist" % em_config_file)
+
+ normalized = {}
+ em_config = {}
+ with open(em_config_file) as f:
+ try:
+ # Emscripten configuration file is a Python file with simple assignments.
+ exec(f.read(), em_config)
+ except StandardError as e:
+ raise RuntimeError("Emscripten configuration file '%s' is invalid:\n%s" % (em_config_file, e))
+ normalized['EMCC_ROOT'] = em_config.get('EMSCRIPTEN_ROOT')
+ normalized['NODE_JS'] = em_config.get('NODE_JS')
+ normalized['CLOSURE_BIN'] = os.path.join(normalized['EMCC_ROOT'], 'node_modules', '.bin', 'google-closure-compiler')
+ return normalized
+
+
+def run_closure_compiler(target, source, env, for_signature):
+ cfg = parse_config()
+ cmd = [cfg['NODE_JS'], cfg['CLOSURE_BIN']]
+ cmd.extend(['--compilation_level', 'ADVANCED_OPTIMIZATIONS'])
+ for f in env['JSEXTERNS']:
+ cmd.extend(['--externs', f.get_abspath()])
+ for f in source:
+ cmd.extend(['--js', f.get_abspath()])
+ cmd.extend(['--js_output_file', target[0].get_abspath()])
+ return ' '.join(cmd)
+
+
+def create_engine_file(env, target, source, externs):
+ if env['use_closure_compiler']:
+ return env.BuildJS(target, source, JSEXTERNS=externs)
+ return env.Textfile(target, [env.File(s) for s in source])
diff --git a/platform/javascript/engine.js b/platform/javascript/engine.js
deleted file mode 100644
index 1f78aa672d..0000000000
--- a/platform/javascript/engine.js
+++ /dev/null
@@ -1,413 +0,0 @@
- // The following is concatenated with generated code, and acts as the end
- // of a wrapper for said code. See pre.js for the other part of the
- // wrapper.
- exposedLibs['PATH'] = PATH;
- exposedLibs['FS'] = FS;
- return Module;
- },
-};
-
-(function() {
- var engine = Engine;
-
- var DOWNLOAD_ATTEMPTS_MAX = 4;
-
- var basePath = null;
- var wasmFilenameExtensionOverride = null;
- var engineLoadPromise = null;
-
- var loadingFiles = {};
-
- function getPathLeaf(path) {
-
- while (path.endsWith('/'))
- path = path.slice(0, -1);
- return path.slice(path.lastIndexOf('/') + 1);
- }
-
- function getBasePath(path) {
-
- if (path.endsWith('/'))
- path = path.slice(0, -1);
- if (path.lastIndexOf('.') > path.lastIndexOf('/'))
- path = path.slice(0, path.lastIndexOf('.'));
- return path;
- }
-
- function getBaseName(path) {
-
- return getPathLeaf(getBasePath(path));
- }
-
- Engine = function Engine() {
-
- this.rtenv = null;
-
- var LIBS = {};
-
- var initPromise = null;
- var unloadAfterInit = true;
-
- var preloadedFiles = [];
-
- var resizeCanvasOnStart = true;
- var progressFunc = null;
- var preloadProgressTracker = {};
- var lastProgress = { loaded: 0, total: 0 };
-
- var canvas = null;
- var executableName = null;
- var locale = null;
- var stdout = null;
- var stderr = null;
-
- this.init = function(newBasePath) {
-
- if (!initPromise) {
- initPromise = Engine.load(newBasePath).then(
- instantiate.bind(this)
- );
- requestAnimationFrame(animateProgress);
- if (unloadAfterInit)
- initPromise.then(Engine.unloadEngine);
- }
- return initPromise;
- };
-
- function instantiate(wasmBuf) {
-
- var rtenvProps = {
- engine: this,
- ENV: {},
- };
- if (typeof stdout === 'function')
- rtenvProps.print = stdout;
- if (typeof stderr === 'function')
- rtenvProps.printErr = stderr;
- rtenvProps.instantiateWasm = function(imports, onSuccess) {
- WebAssembly.instantiate(wasmBuf, imports).then(function(result) {
- onSuccess(result.instance);
- });
- return {};
- };
-
- return new Promise(function(resolve, reject) {
- rtenvProps.onRuntimeInitialized = resolve;
- rtenvProps.onAbort = reject;
- rtenvProps.thisProgram = executableName;
- rtenvProps.engine.rtenv = Engine.RuntimeEnvironment(rtenvProps, LIBS);
- });
- }
-
- this.preloadFile = function(pathOrBuffer, destPath) {
-
- if (pathOrBuffer instanceof ArrayBuffer) {
- pathOrBuffer = new Uint8Array(pathOrBuffer);
- } else if (ArrayBuffer.isView(pathOrBuffer)) {
- pathOrBuffer = new Uint8Array(pathOrBuffer.buffer);
- }
- if (pathOrBuffer instanceof Uint8Array) {
- preloadedFiles.push({
- path: destPath,
- buffer: pathOrBuffer
- });
- return Promise.resolve();
- } else if (typeof pathOrBuffer === 'string') {
- return loadPromise(pathOrBuffer, preloadProgressTracker).then(function(xhr) {
- preloadedFiles.push({
- path: destPath || pathOrBuffer,
- buffer: xhr.response
- });
- });
- } else {
- throw Promise.reject("Invalid object for preloading");
- }
- };
-
- this.start = function() {
-
- return this.init().then(
- Function.prototype.apply.bind(synchronousStart, this, arguments)
- );
- };
-
- this.startGame = function(execName, mainPack) {
-
- executableName = execName;
- var mainArgs = [ '--main-pack', mainPack ];
-
- return Promise.all([
- // Load from directory,
- this.init(getBasePath(mainPack)),
- // ...but write to root where the engine expects it.
- this.preloadFile(mainPack, getPathLeaf(mainPack))
- ]).then(
- Function.prototype.apply.bind(synchronousStart, this, mainArgs)
- );
- };
-
- function synchronousStart() {
-
- if (canvas instanceof HTMLCanvasElement) {
- this.rtenv.canvas = canvas;
- } else {
- var firstCanvas = document.getElementsByTagName('canvas')[0];
- if (firstCanvas instanceof HTMLCanvasElement) {
- this.rtenv.canvas = firstCanvas;
- } else {
- throw new Error("No canvas found");
- }
- }
-
- var actualCanvas = this.rtenv.canvas;
- // canvas can grab focus on click
- if (actualCanvas.tabIndex < 0) {
- actualCanvas.tabIndex = 0;
- }
- // necessary to calculate cursor coordinates correctly
- actualCanvas.style.padding = 0;
- actualCanvas.style.borderWidth = 0;
- actualCanvas.style.borderStyle = 'none';
- // disable right-click context menu
- actualCanvas.addEventListener('contextmenu', function(ev) {
- ev.preventDefault();
- }, false);
- // until context restoration is implemented
- actualCanvas.addEventListener('webglcontextlost', function(ev) {
- alert("WebGL context lost, please reload the page");
- ev.preventDefault();
- }, false);
-
- if (locale) {
- this.rtenv.locale = locale;
- } else {
- this.rtenv.locale = navigator.languages ? navigator.languages[0] : navigator.language;
- }
- this.rtenv.locale = this.rtenv.locale.split('.')[0];
- this.rtenv.resizeCanvasOnStart = resizeCanvasOnStart;
-
- preloadedFiles.forEach(function(file) {
- var dir = LIBS.PATH.dirname(file.path);
- try {
- LIBS.FS.stat(dir);
- } catch (e) {
- if (e.code !== 'ENOENT') {
- throw e;
- }
- LIBS.FS.mkdirTree(dir);
- }
- // With memory growth, canOwn should be false.
- LIBS.FS.createDataFile(file.path, null, new Uint8Array(file.buffer), true, true, false);
- }, this);
-
- preloadedFiles = null;
- initPromise = null;
- this.rtenv.callMain(arguments);
- }
-
- this.setProgressFunc = function(func) {
- progressFunc = func;
- };
-
- this.setResizeCanvasOnStart = function(enabled) {
- resizeCanvasOnStart = enabled;
- };
-
- function animateProgress() {
-
- var loaded = 0;
- var total = 0;
- var totalIsValid = true;
- var progressIsFinal = true;
-
- [loadingFiles, preloadProgressTracker].forEach(function(tracker) {
- Object.keys(tracker).forEach(function(file) {
- if (!tracker[file].final)
- progressIsFinal = false;
- if (!totalIsValid || tracker[file].total === 0) {
- totalIsValid = false;
- total = 0;
- } else {
- total += tracker[file].total;
- }
- loaded += tracker[file].loaded;
- });
- });
- if (loaded !== lastProgress.loaded || total !== lastProgress.total) {
- lastProgress.loaded = loaded;
- lastProgress.total = total;
- if (typeof progressFunc === 'function')
- progressFunc(loaded, total);
- }
- if (!progressIsFinal)
- requestAnimationFrame(animateProgress);
- }
-
- this.setCanvas = function(elem) {
- canvas = elem;
- };
-
- this.setExecutableName = function(newName) {
-
- executableName = newName;
- };
-
- this.setLocale = function(newLocale) {
-
- locale = newLocale;
- };
-
- this.setUnloadAfterInit = function(enabled) {
-
- if (enabled && !unloadAfterInit && initPromise) {
- initPromise.then(Engine.unloadEngine);
- }
- unloadAfterInit = enabled;
- };
-
- this.setStdoutFunc = function(func) {
-
- var print = function(text) {
- if (arguments.length > 1) {
- text = Array.prototype.slice.call(arguments).join(" ");
- }
- func(text);
- };
- if (this.rtenv)
- this.rtenv.print = print;
- stdout = print;
- };
-
- this.setStderrFunc = function(func) {
-
- var printErr = function(text) {
- if (arguments.length > 1)
- text = Array.prototype.slice.call(arguments).join(" ");
- func(text);
- };
- if (this.rtenv)
- this.rtenv.printErr = printErr;
- stderr = printErr;
- };
-
-
- }; // Engine()
-
- Engine.RuntimeEnvironment = engine.RuntimeEnvironment;
-
- Engine.isWebGLAvailable = function(majorVersion = 1) {
-
- var testContext = false;
- try {
- var testCanvas = document.createElement('canvas');
- if (majorVersion === 1) {
- testContext = testCanvas.getContext('webgl') || testCanvas.getContext('experimental-webgl');
- } else if (majorVersion === 2) {
- testContext = testCanvas.getContext('webgl2') || testCanvas.getContext('experimental-webgl2');
- }
- } catch (e) {}
- return !!testContext;
- };
-
- Engine.setWebAssemblyFilenameExtension = function(override) {
-
- if (String(override).length === 0) {
- throw new Error('Invalid WebAssembly filename extension override');
- }
- wasmFilenameExtensionOverride = String(override);
- }
-
- Engine.load = function(newBasePath) {
-
- if (newBasePath !== undefined) basePath = getBasePath(newBasePath);
- if (engineLoadPromise === null) {
- if (typeof WebAssembly !== 'object')
- return Promise.reject(new Error("Browser doesn't support WebAssembly"));
- // TODO cache/retrieve module to/from idb
- engineLoadPromise = loadPromise(basePath + '.' + (wasmFilenameExtensionOverride || 'wasm')).then(function(xhr) {
- return xhr.response;
- });
- engineLoadPromise = engineLoadPromise.catch(function(err) {
- engineLoadPromise = null;
- throw err;
- });
- }
- return engineLoadPromise;
- };
-
- Engine.unload = function() {
- engineLoadPromise = null;
- };
-
- function loadPromise(file, tracker) {
- if (tracker === undefined)
- tracker = loadingFiles;
- return new Promise(function(resolve, reject) {
- loadXHR(resolve, reject, file, tracker);
- });
- }
-
- function loadXHR(resolve, reject, file, tracker) {
-
- var xhr = new XMLHttpRequest;
- xhr.open('GET', file);
- if (!file.endsWith('.js')) {
- xhr.responseType = 'arraybuffer';
- }
- ['loadstart', 'progress', 'load', 'error', 'abort'].forEach(function(ev) {
- xhr.addEventListener(ev, onXHREvent.bind(xhr, resolve, reject, file, tracker));
- });
- xhr.send();
- }
-
- function onXHREvent(resolve, reject, file, tracker, ev) {
-
- if (this.status >= 400) {
-
- if (this.status < 500 || ++tracker[file].attempts >= DOWNLOAD_ATTEMPTS_MAX) {
- reject(new Error("Failed loading file '" + file + "': " + this.statusText));
- this.abort();
- return;
- } else {
- setTimeout(loadXHR.bind(null, resolve, reject, file, tracker), 1000);
- }
- }
-
- switch (ev.type) {
- case 'loadstart':
- if (tracker[file] === undefined) {
- tracker[file] = {
- total: ev.total,
- loaded: ev.loaded,
- attempts: 0,
- final: false,
- };
- }
- break;
-
- case 'progress':
- tracker[file].loaded = ev.loaded;
- tracker[file].total = ev.total;
- break;
-
- case 'load':
- tracker[file].final = true;
- resolve(this);
- break;
-
- case 'error':
- if (++tracker[file].attempts >= DOWNLOAD_ATTEMPTS_MAX) {
- tracker[file].final = true;
- reject(new Error("Failed loading file '" + file + "'"));
- } else {
- setTimeout(loadXHR.bind(null, resolve, reject, file, tracker), 1000);
- }
- break;
-
- case 'abort':
- tracker[file].final = true;
- reject(new Error("Loading file '" + file + "' was aborted."));
- break;
- }
- }
-})();
diff --git a/platform/javascript/engine/engine.js b/platform/javascript/engine/engine.js
new file mode 100644
index 0000000000..6d7509377f
--- /dev/null
+++ b/platform/javascript/engine/engine.js
@@ -0,0 +1,184 @@
+Function('return this')()['Engine'] = (function() {
+
+ var unloadAfterInit = true;
+ var canvas = null;
+ var resizeCanvasOnStart = false;
+ var customLocale = 'en_US';
+ var wasmExt = '.wasm';
+
+ var preloader = new Preloader();
+ var loader = new Loader();
+ var rtenv = null;
+
+ var executableName = '';
+ var loadPath = '';
+ var loadPromise = null;
+ var initPromise = null;
+ var stderr = null;
+ var stdout = null;
+ var progressFunc = null;
+
+ function load(basePath) {
+ if (loadPromise == null) {
+ loadPath = basePath;
+ loadPromise = preloader.loadPromise(basePath + wasmExt);
+ preloader.setProgressFunc(progressFunc);
+ requestAnimationFrame(preloader.animateProgress);
+ }
+ return loadPromise;
+ };
+
+ function unload() {
+ loadPromise = null;
+ };
+
+ /** @constructor */
+ function Engine() {};
+
+ Engine.prototype.init = /** @param {string=} basePath */ function(basePath) {
+ if (initPromise) {
+ return initPromise;
+ }
+ if (!loadPromise) {
+ if (!basePath) {
+ initPromise = Promise.reject(new Error("A base path must be provided when calling `init` and the engine is not loaded."));
+ return initPromise;
+ }
+ load(basePath);
+ }
+ var config = {}
+ if (typeof stdout === 'function')
+ config.print = stdout;
+ if (typeof stderr === 'function')
+ config.printErr = stderr;
+ initPromise = loader.init(loadPromise, loadPath, config).then(function() {
+ return new Promise(function(resolve, reject) {
+ rtenv = loader.env;
+ if (unloadAfterInit) {
+ loadPromise = null;
+ }
+ resolve();
+ });
+ });
+ return initPromise;
+ };
+
+ /** @type {function(string, string):Object} */
+ Engine.prototype.preloadFile = function(file, path) {
+ return preloader.preload(file, path);
+ };
+
+ /** @type {function(...string):Object} */
+ Engine.prototype.start = function() {
+ // Start from arguments.
+ var args = [];
+ for (var i = 0; i < arguments.length; i++) {
+ args.push(arguments[i]);
+ }
+ var me = this;
+ return new Promise(function(resolve, reject) {
+ return me.init().then(function() {
+ if (!(canvas instanceof HTMLCanvasElement)) {
+ canvas = Utils.findCanvas();
+ }
+ rtenv['locale'] = customLocale;
+ rtenv['canvas'] = canvas;
+ rtenv['thisProgram'] = executableName;
+ rtenv['resizeCanvasOnStart'] = resizeCanvasOnStart;
+ loader.start(preloader.preloadedFiles, args).then(function() {
+ loader = null;
+ initPromise = null;
+ resolve();
+ });
+ });
+ });
+ };
+
+ Engine.prototype.startGame = function(execName, mainPack) {
+ // Start and init with execName as loadPath if not inited.
+ executableName = execName;
+ var me = this;
+ return Promise.all([
+ this.init(execName),
+ this.preloadFile(mainPack, mainPack)
+ ]).then(function() {
+ return me.start('--main-pack', mainPack);
+ });
+ };
+
+ Engine.prototype.setWebAssemblyFilenameExtension = function(override) {
+ if (String(override).length === 0) {
+ throw new Error('Invalid WebAssembly filename extension override');
+ }
+ wasmExt = String(override);
+ };
+
+ Engine.prototype.setUnloadAfterInit = function(enabled) {
+ unloadAfterInit = enabled;
+ };
+
+ Engine.prototype.setCanvas = function(canvasElem) {
+ canvas = canvasElem;
+ };
+
+ Engine.prototype.setCanvasResizedOnStart = function(enabled) {
+ resizeCanvasOnStart = enabled;
+ };
+
+ Engine.prototype.setLocale = function(locale) {
+ customLocale = locale;
+ };
+
+ Engine.prototype.setExecutableName = function(newName) {
+ executableName = newName;
+ };
+
+ Engine.prototype.setProgressFunc = function(func) {
+ progressFunc = func;
+ }
+
+ Engine.prototype.setStdoutFunc = function(func) {
+
+ var print = function(text) {
+ if (arguments.length > 1) {
+ text = Array.prototype.slice.call(arguments).join(" ");
+ }
+ func(text);
+ };
+ if (rtenv)
+ rtenv.print = print;
+ stdout = print;
+ };
+
+ Engine.prototype.setStderrFunc = function(func) {
+
+ var printErr = function(text) {
+ if (arguments.length > 1)
+ text = Array.prototype.slice.call(arguments).join(" ");
+ func(text);
+ };
+ if (rtenv)
+ rtenv.printErr = printErr;
+ stderr = printErr;
+ };
+
+ // Closure compiler exported engine methods.
+ /** @export */
+ Engine['isWebGLAvailable'] = Utils.isWebGLAvailable;
+ Engine['load'] = load;
+ Engine['unload'] = unload;
+ Engine.prototype['init'] = Engine.prototype.init
+ Engine.prototype['preloadFile'] = Engine.prototype.preloadFile
+ Engine.prototype['start'] = Engine.prototype.start
+ Engine.prototype['startGame'] = Engine.prototype.startGame
+ Engine.prototype['setWebAssemblyFilenameExtension'] = Engine.prototype.setWebAssemblyFilenameExtension
+ Engine.prototype['setUnloadAfterInit'] = Engine.prototype.setUnloadAfterInit
+ Engine.prototype['setCanvas'] = Engine.prototype.setCanvas
+ Engine.prototype['setCanvasResizedOnStart'] = Engine.prototype.setCanvasResizedOnStart
+ Engine.prototype['setLocale'] = Engine.prototype.setLocale
+ Engine.prototype['setExecutableName'] = Engine.prototype.setExecutableName
+ Engine.prototype['setProgressFunc'] = Engine.prototype.setProgressFunc
+ Engine.prototype['setStdoutFunc'] = Engine.prototype.setStdoutFunc
+ Engine.prototype['setStderrFunc'] = Engine.prototype.setStderrFunc
+ return Engine;
+})();
diff --git a/platform/javascript/engine/externs.js b/platform/javascript/engine/externs.js
new file mode 100644
index 0000000000..1a94dd15ec
--- /dev/null
+++ b/platform/javascript/engine/externs.js
@@ -0,0 +1,3 @@
+var Godot;
+var WebAssembly = {};
+WebAssembly.instantiate = function(buffer, imports) {};
diff --git a/platform/javascript/engine/loader.js b/platform/javascript/engine/loader.js
new file mode 100644
index 0000000000..d27fbf612e
--- /dev/null
+++ b/platform/javascript/engine/loader.js
@@ -0,0 +1,33 @@
+var Loader = /** @constructor */ function() {
+
+ this.env = null;
+
+ this.init = function(loadPromise, basePath, config) {
+ var me = this;
+ return new Promise(function(resolve, reject) {
+ var cfg = config || {};
+ cfg['locateFile'] = Utils.createLocateRewrite(basePath);
+ cfg['instantiateWasm'] = Utils.createInstantiatePromise(loadPromise);
+ loadPromise = null;
+ Godot(cfg).then(function(module) {
+ me.env = module;
+ resolve();
+ });
+ });
+ }
+
+ this.start = function(preloadedFiles, args) {
+ var me = this;
+ return new Promise(function(resolve, reject) {
+ if (!me.env) {
+ reject(new Error('The engine must be initialized before it can be started'));
+ }
+ preloadedFiles.forEach(function(file) {
+ Utils.copyToFS(me.env['FS'], file.path, file.buffer);
+ });
+ preloadedFiles.length = 0; // Clear memory
+ me.env['callMain'](args);
+ resolve();
+ });
+ }
+};
diff --git a/platform/javascript/engine/preloader.js b/platform/javascript/engine/preloader.js
new file mode 100644
index 0000000000..17918eae38
--- /dev/null
+++ b/platform/javascript/engine/preloader.js
@@ -0,0 +1,139 @@
+var Preloader = /** @constructor */ function() {
+
+ var DOWNLOAD_ATTEMPTS_MAX = 4;
+ var progressFunc = null;
+ var lastProgress = { loaded: 0, total: 0 };
+
+ var loadingFiles = {};
+ this.preloadedFiles = [];
+
+ function loadXHR(resolve, reject, file, tracker) {
+ var xhr = new XMLHttpRequest;
+ xhr.open('GET', file);
+ if (!file.endsWith('.js')) {
+ xhr.responseType = 'arraybuffer';
+ }
+ ['loadstart', 'progress', 'load', 'error', 'abort'].forEach(function(ev) {
+ xhr.addEventListener(ev, onXHREvent.bind(xhr, resolve, reject, file, tracker));
+ });
+ xhr.send();
+ }
+
+ function onXHREvent(resolve, reject, file, tracker, ev) {
+
+ if (this.status >= 400) {
+
+ if (this.status < 500 || ++tracker[file].attempts >= DOWNLOAD_ATTEMPTS_MAX) {
+ reject(new Error("Failed loading file '" + file + "': " + this.statusText));
+ this.abort();
+ return;
+ } else {
+ setTimeout(loadXHR.bind(null, resolve, reject, file, tracker), 1000);
+ }
+ }
+
+ switch (ev.type) {
+ case 'loadstart':
+ if (tracker[file] === undefined) {
+ tracker[file] = {
+ total: ev.total,
+ loaded: ev.loaded,
+ attempts: 0,
+ final: false,
+ };
+ }
+ break;
+
+ case 'progress':
+ tracker[file].loaded = ev.loaded;
+ tracker[file].total = ev.total;
+ break;
+
+ case 'load':
+ tracker[file].final = true;
+ resolve(this);
+ break;
+
+ case 'error':
+ if (++tracker[file].attempts >= DOWNLOAD_ATTEMPTS_MAX) {
+ tracker[file].final = true;
+ reject(new Error("Failed loading file '" + file + "'"));
+ } else {
+ setTimeout(loadXHR.bind(null, resolve, reject, file, tracker), 1000);
+ }
+ break;
+
+ case 'abort':
+ tracker[file].final = true;
+ reject(new Error("Loading file '" + file + "' was aborted."));
+ break;
+ }
+ }
+
+ this.loadPromise = function(file) {
+ return new Promise(function(resolve, reject) {
+ loadXHR(resolve, reject, file, loadingFiles);
+ });
+ }
+
+ this.preload = function(pathOrBuffer, destPath) {
+ if (pathOrBuffer instanceof ArrayBuffer) {
+ pathOrBuffer = new Uint8Array(pathOrBuffer);
+ } else if (ArrayBuffer.isView(pathOrBuffer)) {
+ pathOrBuffer = new Uint8Array(pathOrBuffer.buffer);
+ }
+ if (pathOrBuffer instanceof Uint8Array) {
+ this.preloadedFiles.push({
+ path: destPath,
+ buffer: pathOrBuffer
+ });
+ return Promise.resolve();
+ } else if (typeof pathOrBuffer === 'string') {
+ var me = this;
+ return this.loadPromise(pathOrBuffer).then(function(xhr) {
+ me.preloadedFiles.push({
+ path: destPath || pathOrBuffer,
+ buffer: xhr.response
+ });
+ return Promise.resolve();
+ });
+ } else {
+ throw Promise.reject("Invalid object for preloading");
+ }
+ };
+
+ var animateProgress = function() {
+
+ var loaded = 0;
+ var total = 0;
+ var totalIsValid = true;
+ var progressIsFinal = true;
+
+ Object.keys(loadingFiles).forEach(function(file) {
+ const stat = loadingFiles[file];
+ if (!stat.final) {
+ progressIsFinal = false;
+ }
+ if (!totalIsValid || stat.total === 0) {
+ totalIsValid = false;
+ total = 0;
+ } else {
+ total += stat.total;
+ }
+ loaded += stat.loaded;
+ });
+ if (loaded !== lastProgress.loaded || total !== lastProgress.total) {
+ lastProgress.loaded = loaded;
+ lastProgress.total = total;
+ if (typeof progressFunc === 'function')
+ progressFunc(loaded, total);
+ }
+ if (!progressIsFinal)
+ requestAnimationFrame(animateProgress);
+ }
+ this.animateProgress = animateProgress; // Also exposed to start it.
+
+ this.setProgressFunc = function(callback) {
+ progressFunc = callback;
+ }
+};
diff --git a/platform/javascript/engine/utils.js b/platform/javascript/engine/utils.js
new file mode 100644
index 0000000000..fdff90a923
--- /dev/null
+++ b/platform/javascript/engine/utils.js
@@ -0,0 +1,69 @@
+var Utils = {
+
+ createLocateRewrite: function(execName) {
+ function rw(path) {
+ if (path.endsWith('.worker.js')) {
+ return execName + '.worker.js';
+ } else if (path.endsWith('.js')) {
+ return execName + '.js';
+ } else if (path.endsWith('.wasm')) {
+ return execName + '.wasm';
+ }
+ }
+ return rw;
+ },
+
+ createInstantiatePromise: function(wasmLoader) {
+ function instantiateWasm(imports, onSuccess) {
+ wasmLoader.then(function(xhr) {
+ WebAssembly.instantiate(xhr.response, imports).then(function(result) {
+ onSuccess(result['instance'], result['module']);
+ });
+ });
+ wasmLoader = null;
+ return {};
+ };
+
+ return instantiateWasm;
+ },
+
+ copyToFS: function(fs, path, buffer) {
+ var p = path.lastIndexOf("/");
+ var dir = "/";
+ if (p > 0) {
+ dir = path.slice(0, path.lastIndexOf("/"));
+ }
+ try {
+ fs.stat(dir);
+ } catch (e) {
+ if (e.errno !== 44) { // 'ENOENT', see https://github.com/emscripten-core/emscripten/blob/master/system/lib/libc/musl/arch/emscripten/bits/errno.h
+ throw e;
+ }
+ fs['mkdirTree'](dir);
+ }
+ // With memory growth, canOwn should be false.
+ fs['writeFile'](path, new Uint8Array(buffer), {'flags': 'wx+'});
+ },
+
+ findCanvas: function() {
+ var nodes = document.getElementsByTagName('canvas');
+ if (nodes.length && nodes[0] instanceof HTMLCanvasElement) {
+ return nodes[0];
+ }
+ throw new Error("No canvas found");
+ },
+
+ isWebGLAvailable: function(majorVersion = 1) {
+
+ var testContext = false;
+ try {
+ var testCanvas = document.createElement('canvas');
+ if (majorVersion === 1) {
+ testContext = testCanvas.getContext('webgl') || testCanvas.getContext('experimental-webgl');
+ } else if (majorVersion === 2) {
+ testContext = testCanvas.getContext('webgl2') || testCanvas.getContext('experimental-webgl2');
+ }
+ } catch (e) {}
+ return !!testContext;
+ }
+};
diff --git a/platform/javascript/export/export.cpp b/platform/javascript/export/export.cpp
index 9b93d4f140..da61425747 100644
--- a/platform/javascript/export/export.cpp
+++ b/platform/javascript/export/export.cpp
@@ -86,7 +86,7 @@ public:
ERR_FAIL_COND_MSG(req[0] != "GET" || req[2] != "HTTP/1.1", "Invalid method or HTTP version.");
String filepath = EditorSettings::get_singleton()->get_cache_dir().plus_file("tmp_js_export");
- String basereq = "/tmp_js_export";
+ const String basereq = "/tmp_js_export";
String ctype = "";
if (req[1] == basereq + ".html") {
filepath += ".html";
@@ -94,11 +94,19 @@ public:
} else if (req[1] == basereq + ".js") {
filepath += ".js";
ctype = "application/javascript";
+ } else if (req[1] == basereq + ".worker.js") {
+ filepath += ".worker.js";
+ ctype = "application/javascript";
} else if (req[1] == basereq + ".pck") {
filepath += ".pck";
ctype = "application/octet-stream";
- } else if (req[1] == basereq + ".png") {
- filepath += ".png";
+ } else if (req[1] == basereq + ".png" || req[1] == "/favicon.png") {
+ // Also allow serving the generated favicon for a smoother loading experience.
+ if (req[1] == "/favicon.png") {
+ filepath = EditorSettings::get_singleton()->get_cache_dir().plus_file("favicon.png");
+ } else {
+ filepath += ".png";
+ }
ctype = "image/png";
} else if (req[1] == basereq + ".wasm") {
filepath += ".wasm";
@@ -195,7 +203,7 @@ class EditorExportPlatformJavaScript : public EditorExportPlatform {
private:
Ref<EditorHTTPServer> server;
bool server_quit;
- Mutex *server_lock;
+ Mutex server_lock;
Thread *server_thread;
static void _server_thread_poll(void *data);
@@ -207,7 +215,7 @@ public:
virtual String get_name() const;
virtual String get_os_name() const;
- virtual Ref<Texture> get_logo() const;
+ virtual Ref<Texture2D> get_logo() const;
virtual bool can_export(const Ref<EditorExportPreset> &p_preset, String &r_error, bool &r_missing_templates) const;
virtual List<String> get_binary_extensions(const Ref<EditorExportPreset> &p_preset) const;
@@ -219,7 +227,7 @@ public:
virtual String get_option_tooltip(int p_index) const { return p_index ? TTR("Stop HTTP Server") : TTR("Run exported HTML in the system's default browser."); }
virtual Ref<ImageTexture> get_option_icon(int p_index) const;
virtual Error run(const Ref<EditorExportPreset> &p_preset, int p_option, int p_debug_flags);
- virtual Ref<Texture> get_run_icon() const;
+ virtual Ref<Texture2D> get_run_icon() const;
virtual void get_platform_features(List<String> *r_features) {
@@ -266,11 +274,9 @@ void EditorExportPlatformJavaScript::get_preset_features(const Ref<EditorExportP
String driver = ProjectSettings::get_singleton()->get("rendering/quality/driver/driver_name");
if (driver == "GLES2") {
r_features->push_back("etc");
- } else if (driver == "GLES3") {
+ } else if (driver == "Vulkan") {
+ // FIXME: Review if this is correct.
r_features->push_back("etc2");
- if (ProjectSettings::get_singleton()->get("rendering/quality/driver/fallback_to_gles2")) {
- r_features->push_back("etc");
- }
}
}
}
@@ -295,7 +301,7 @@ String EditorExportPlatformJavaScript::get_os_name() const {
return "HTML5";
}
-Ref<Texture> EditorExportPlatformJavaScript::get_logo() const {
+Ref<Texture2D> EditorExportPlatformJavaScript::get_logo() const {
return logo;
}
@@ -429,6 +435,10 @@ Error EditorExportPlatformJavaScript::export_project(const Ref<EditorExportPrese
} else if (file == "godot.js") {
file = p_path.get_file().get_basename() + ".js";
+ } else if (file == "godot.worker.js") {
+
+ file = p_path.get_file().get_basename() + ".worker.js";
+
} else if (file == "godot.wasm") {
file = p_path.get_file().get_basename() + ".wasm";
@@ -470,11 +480,10 @@ Error EditorExportPlatformJavaScript::export_project(const Ref<EditorExportPrese
}
Ref<Image> splash;
- String splash_path = GLOBAL_GET("application/boot_splash/image");
- splash_path = splash_path.strip_edges();
+ const String splash_path = String(GLOBAL_GET("application/boot_splash/image")).strip_edges();
if (!splash_path.empty()) {
splash.instance();
- Error err = splash->load(splash_path);
+ const Error err = splash->load(splash_path);
if (err) {
EditorNode::get_singleton()->show_warning(TTR("Could not read boot splash image file:") + "\n" + splash_path + "\n" + TTR("Using default boot splash image."));
splash.unref();
@@ -483,11 +492,32 @@ Error EditorExportPlatformJavaScript::export_project(const Ref<EditorExportPrese
if (splash.is_null()) {
splash = Ref<Image>(memnew(Image(boot_splash_png)));
}
- String png_path = p_path.get_base_dir().plus_file(p_path.get_file().get_basename() + ".png");
- if (splash->save_png(png_path) != OK) {
- EditorNode::get_singleton()->show_warning(TTR("Could not write file:") + "\n" + png_path);
+ const String splash_png_path = p_path.get_base_dir().plus_file(p_path.get_file().get_basename() + ".png");
+ if (splash->save_png(splash_png_path) != OK) {
+ EditorNode::get_singleton()->show_warning(TTR("Could not write file:") + "\n" + splash_png_path);
return ERR_FILE_CANT_WRITE;
}
+
+ // Save a favicon that can be accessed without waiting for the project to finish loading.
+ // This way, the favicon can be displayed immediately when loading the page.
+ Ref<Image> favicon;
+ const String favicon_path = String(GLOBAL_GET("application/config/icon")).strip_edges();
+ if (!favicon_path.empty()) {
+ favicon.instance();
+ const Error err = favicon->load(favicon_path);
+ if (err) {
+ favicon.unref();
+ }
+ }
+
+ if (favicon.is_valid()) {
+ const String favicon_png_path = p_path.get_base_dir().plus_file("favicon.png");
+ if (favicon->save_png(favicon_png_path) != OK) {
+ EditorNode::get_singleton()->show_warning(TTR("Could not write file:") + "\n" + favicon_png_path);
+ return ERR_FILE_CANT_WRITE;
+ }
+ }
+
return OK;
}
@@ -508,9 +538,8 @@ bool EditorExportPlatformJavaScript::poll_export() {
menu_options = preset.is_valid();
if (server->is_listening()) {
if (menu_options == 0) {
- server_lock->lock();
+ MutexLock lock(server_lock);
server->stop();
- server_lock->unlock();
} else {
menu_options += 1;
}
@@ -530,29 +559,29 @@ int EditorExportPlatformJavaScript::get_options_count() const {
Error EditorExportPlatformJavaScript::run(const Ref<EditorExportPreset> &p_preset, int p_option, int p_debug_flags) {
if (p_option == 1) {
- server_lock->lock();
+ MutexLock lock(server_lock);
server->stop();
- server_lock->unlock();
return OK;
}
- String basepath = EditorSettings::get_singleton()->get_cache_dir().plus_file("tmp_js_export");
- String path = basepath + ".html";
- Error err = export_project(p_preset, true, path, p_debug_flags);
+ const String basepath = EditorSettings::get_singleton()->get_cache_dir().plus_file("tmp_js_export");
+ Error err = export_project(p_preset, true, basepath + ".html", p_debug_flags);
if (err != OK) {
// Export generates several files, clean them up on failure.
DirAccess::remove_file_or_error(basepath + ".html");
DirAccess::remove_file_or_error(basepath + ".js");
+ DirAccess::remove_file_or_error(basepath + ".worker.js");
DirAccess::remove_file_or_error(basepath + ".pck");
DirAccess::remove_file_or_error(basepath + ".png");
DirAccess::remove_file_or_error(basepath + ".wasm");
+ DirAccess::remove_file_or_error(EditorSettings::get_singleton()->get_cache_dir().plus_file("favicon.png"));
return err;
}
- IP_Address bind_ip;
- uint16_t bind_port = EDITOR_GET("export/web/http_port");
+ const uint16_t bind_port = EDITOR_GET("export/web/http_port");
// Resolve host if needed.
- String bind_host = EDITOR_GET("export/web/http_host");
+ const String bind_host = EDITOR_GET("export/web/http_host");
+ IP_Address bind_ip;
if (bind_host.is_valid_ip_address()) {
bind_ip = bind_host;
} else {
@@ -561,10 +590,12 @@ Error EditorExportPlatformJavaScript::run(const Ref<EditorExportPreset> &p_prese
ERR_FAIL_COND_V_MSG(!bind_ip.is_valid(), ERR_INVALID_PARAMETER, "Invalid editor setting 'export/web/http_host': '" + bind_host + "'. Try using '127.0.0.1'.");
// Restart server.
- server_lock->lock();
- server->stop();
- err = server->listen(bind_port, bind_ip);
- server_lock->unlock();
+ {
+ MutexLock lock(server_lock);
+
+ server->stop();
+ err = server->listen(bind_port, bind_ip);
+ }
ERR_FAIL_COND_V_MSG(err != OK, err, "Unable to start HTTP server.");
OS::get_singleton()->shell_open(String("http://" + bind_host + ":" + itos(bind_port) + "/tmp_js_export.html"));
@@ -573,7 +604,7 @@ Error EditorExportPlatformJavaScript::run(const Ref<EditorExportPreset> &p_prese
return OK;
}
-Ref<Texture> EditorExportPlatformJavaScript::get_run_icon() const {
+Ref<Texture2D> EditorExportPlatformJavaScript::get_run_icon() const {
return run_icon;
}
@@ -582,9 +613,10 @@ void EditorExportPlatformJavaScript::_server_thread_poll(void *data) {
EditorExportPlatformJavaScript *ej = (EditorExportPlatformJavaScript *)data;
while (!ej->server_quit) {
OS::get_singleton()->delay_usec(1000);
- ej->server_lock->lock();
- ej->server->poll();
- ej->server_lock->unlock();
+ {
+ MutexLock lock(ej->server_lock);
+ ej->server->poll();
+ }
}
}
@@ -592,7 +624,6 @@ EditorExportPlatformJavaScript::EditorExportPlatformJavaScript() {
server.instance();
server_quit = false;
- server_lock = Mutex::create();
server_thread = Thread::create(_server_thread_poll, this);
Ref<Image> img = memnew(Image(_javascript_logo));
@@ -616,7 +647,6 @@ EditorExportPlatformJavaScript::~EditorExportPlatformJavaScript() {
server->stop();
server_quit = true;
Thread::wait_to_finish(server_thread);
- memdelete(server_lock);
memdelete(server_thread);
}
diff --git a/platform/javascript/http_client.h.inc b/platform/javascript/http_client.h.inc
index 03e2ce8b8a..ac275aadbc 100644
--- a/platform/javascript/http_client.h.inc
+++ b/platform/javascript/http_client.h.inc
@@ -45,7 +45,7 @@ String password;
int polled_response_code;
String polled_response_header;
-PoolByteArray polled_response;
+PackedByteArray polled_response;
#ifdef DEBUG_ENABLED
bool has_polled;
diff --git a/platform/javascript/http_client_javascript.cpp b/platform/javascript/http_client_javascript.cpp
index 2c2511a3a5..472384cf30 100644
--- a/platform/javascript/http_client_javascript.cpp
+++ b/platform/javascript/http_client_javascript.cpp
@@ -103,13 +103,12 @@ Error HTTPClient::prepare_request(Method p_method, const String &p_url, const Ve
return OK;
}
-Error HTTPClient::request_raw(Method p_method, const String &p_url, const Vector<String> &p_headers, const PoolVector<uint8_t> &p_body) {
+Error HTTPClient::request_raw(Method p_method, const String &p_url, const Vector<String> &p_headers, const Vector<uint8_t> &p_body) {
Error err = prepare_request(p_method, p_url, p_headers);
if (err != OK)
return err;
- PoolByteArray::Read read = p_body.read();
- godot_xhr_send_data(xhr_id, read.ptr(), p_body.size());
+ godot_xhr_send_data(xhr_id, p_body.ptr(), p_body.size());
return OK;
}
@@ -173,18 +172,14 @@ int HTTPClient::get_response_body_length() const {
return polled_response.size();
}
-PoolByteArray HTTPClient::read_response_body_chunk() {
+PackedByteArray HTTPClient::read_response_body_chunk() {
- ERR_FAIL_COND_V(status != STATUS_BODY, PoolByteArray());
+ ERR_FAIL_COND_V(status != STATUS_BODY, PackedByteArray());
int to_read = MIN(read_limit, polled_response.size() - response_read_offset);
- PoolByteArray chunk;
+ PackedByteArray chunk;
chunk.resize(to_read);
- PoolByteArray::Write write = chunk.write();
- PoolByteArray::Read read = polled_response.read();
- memcpy(write.ptr(), read.ptr() + response_read_offset, to_read);
- write = PoolByteArray::Write();
- read = PoolByteArray::Read();
+ memcpy(chunk.ptrw(), polled_response.ptr() + response_read_offset, to_read);
response_read_offset += to_read;
if (response_read_offset == polled_response.size()) {
@@ -263,23 +258,17 @@ Error HTTPClient::poll() {
status = STATUS_BODY;
- PoolByteArray bytes;
+ PackedByteArray bytes;
int len = godot_xhr_get_response_headers_length(xhr_id);
bytes.resize(len + 1);
- PoolByteArray::Write write = bytes.write();
- godot_xhr_get_response_headers(xhr_id, reinterpret_cast<char *>(write.ptr()), len);
- write[len] = 0;
- write = PoolByteArray::Write();
+ godot_xhr_get_response_headers(xhr_id, reinterpret_cast<char *>(bytes.ptrw()), len);
+ bytes.ptrw()[len] = 0;
- PoolByteArray::Read read = bytes.read();
- polled_response_header = String::utf8(reinterpret_cast<const char *>(read.ptr()));
- read = PoolByteArray::Read();
+ polled_response_header = String::utf8(reinterpret_cast<const char *>(bytes.ptr()));
polled_response.resize(godot_xhr_get_response_length(xhr_id));
- write = polled_response.write();
- godot_xhr_get_response(xhr_id, write.ptr(), polled_response.size());
- write = PoolByteArray::Write();
+ godot_xhr_get_response(xhr_id, polled_response.ptrw(), polled_response.size());
break;
}
diff --git a/platform/javascript/id_handler.js b/platform/javascript/id_handler.js
index 3851123ed1..67d29075b8 100644
--- a/platform/javascript/id_handler.js
+++ b/platform/javascript/id_handler.js
@@ -28,7 +28,7 @@
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/
-var IDHandler = function() {
+var IDHandler = /** @constructor */ function() {
var ids = {};
var size = 0;
diff --git a/platform/javascript/javascript_eval.cpp b/platform/javascript/javascript_eval.cpp
index d907222d24..db8050b90e 100644
--- a/platform/javascript/javascript_eval.cpp
+++ b/platform/javascript/javascript_eval.cpp
@@ -33,11 +33,11 @@
#include "api/javascript_eval.h"
#include "emscripten.h"
-extern "C" EMSCRIPTEN_KEEPALIVE uint8_t *resize_poolbytearray_and_open_write(PoolByteArray *p_arr, PoolByteArray::Write *r_write, int p_len) {
+extern "C" EMSCRIPTEN_KEEPALIVE uint8_t *resize_PackedByteArray_and_open_write(PackedByteArray *p_arr, VectorWriteProxy<uint8_t> *r_write, int p_len) {
p_arr->resize(p_len);
- *r_write = p_arr->write();
- return r_write->ptr();
+ *r_write = p_arr->write;
+ return p_arr->ptrw();
}
Variant JavaScript::eval(const String &p_code, bool p_use_global_exec_context) {
@@ -48,8 +48,8 @@ Variant JavaScript::eval(const String &p_code, bool p_use_global_exec_context) {
char *s;
} js_data;
- PoolByteArray arr;
- PoolByteArray::Write arr_write;
+ PackedByteArray arr;
+ VectorWriteProxy<uint8_t> arr_write;
/* clang-format off */
Variant::Type return_type = static_cast<Variant::Type>(EM_ASM_INT({
@@ -81,7 +81,7 @@ Variant JavaScript::eval(const String &p_code, bool p_use_global_exec_context) {
case 'number':
setValue(PTR, eval_ret, 'double');
- return 3; // REAL
+ return 3; // FLOAT
case 'string':
var array_len = lengthBytesUTF8(eval_ret)+1;
@@ -114,9 +114,9 @@ Variant JavaScript::eval(const String &p_code, bool p_use_global_exec_context) {
eval_ret = new Uint8Array(eval_ret);
}
if (eval_ret instanceof Uint8Array) {
- var bytes_ptr = ccall('resize_poolbytearray_and_open_write', 'number', ['number', 'number' ,'number'], [BYTEARRAY_PTR, BYTEARRAY_WRITE_PTR, eval_ret.length]);
+ var bytes_ptr = ccall('resize_PackedByteArray_and_open_write', 'number', ['number', 'number' ,'number'], [BYTEARRAY_PTR, BYTEARRAY_WRITE_PTR, eval_ret.length]);
HEAPU8.set(eval_ret, bytes_ptr);
- return 20; // POOL_BYTE_ARRAY
+ return 20; // PACKED_BYTE_ARRAY
}
break;
}
@@ -128,7 +128,7 @@ Variant JavaScript::eval(const String &p_code, bool p_use_global_exec_context) {
switch (return_type) {
case Variant::BOOL:
return js_data.b;
- case Variant::REAL:
+ case Variant::FLOAT:
return js_data.d;
case Variant::STRING: {
String str = String::utf8(js_data.s);
@@ -137,8 +137,8 @@ Variant JavaScript::eval(const String &p_code, bool p_use_global_exec_context) {
/* clang-format on */
return str;
}
- case Variant::POOL_BYTE_ARRAY:
- arr_write = PoolByteArray::Write();
+ case Variant::PACKED_BYTE_ARRAY:
+ arr_write = VectorWriteProxy<uint8_t>();
return arr;
default:
return Variant();
diff --git a/platform/javascript/os_javascript.cpp b/platform/javascript/os_javascript.cpp
index 632a7df9e8..db90b01f8f 100644
--- a/platform/javascript/os_javascript.cpp
+++ b/platform/javascript/os_javascript.cpp
@@ -31,8 +31,8 @@
#include "os_javascript.h"
#include "core/io/file_access_buffered_fa.h"
-#include "drivers/gles2/rasterizer_gles2.h"
-#include "drivers/gles3/rasterizer_gles3.h"
+//#include "drivers/gles2/rasterizer_gles2.h"
+#include "drivers/dummy/rasterizer_dummy.h"
#include "drivers/unix/dir_access_unix.h"
#include "drivers/unix/file_access_unix.h"
#include "main/main.h"
@@ -220,6 +220,20 @@ void OS_JavaScript::get_fullscreen_mode_list(List<VideoMode> *p_list, int p_scre
p_list->push_back(OS::VideoMode(screen.width, screen.height, true));
}
+bool OS_JavaScript::get_window_per_pixel_transparency_enabled() const {
+ if (!is_layered_allowed()) {
+ return false;
+ }
+ return transparency_enabled;
+}
+
+void OS_JavaScript::set_window_per_pixel_transparency_enabled(bool p_enabled) {
+ if (!is_layered_allowed()) {
+ return;
+ }
+ transparency_enabled = p_enabled;
+}
+
// Keys
template <typename T>
@@ -237,7 +251,8 @@ static Ref<InputEventKey> setup_key_event(const EmscriptenKeyboardEvent *emscrip
ev.instance();
ev->set_echo(emscripten_event->repeat);
dom2godot_mod(emscripten_event, ev);
- ev->set_scancode(dom2godot_scancode(emscripten_event->keyCode));
+ ev->set_keycode(dom2godot_keycode(emscripten_event->keyCode));
+ ev->set_physical_keycode(dom2godot_keycode(emscripten_event->keyCode));
String unicode = String::utf8(emscripten_event->key);
// Check if empty or multi-character (e.g. `CapsLock`).
@@ -257,7 +272,7 @@ EM_BOOL OS_JavaScript::keydown_callback(int p_event_type, const EmscriptenKeyboa
OS_JavaScript *os = get_singleton();
Ref<InputEventKey> ev = setup_key_event(p_event);
ev->set_pressed(true);
- if (ev->get_unicode() == 0 && keycode_has_unicode(ev->get_scancode())) {
+ if (ev->get_unicode() == 0 && keycode_has_unicode(ev->get_keycode())) {
// Defer to keypress event for legacy unicode retrieval.
os->deferred_key_event = ev;
// Do not suppress keypress event.
@@ -282,7 +297,7 @@ EM_BOOL OS_JavaScript::keyup_callback(int p_event_type, const EmscriptenKeyboard
Ref<InputEventKey> ev = setup_key_event(p_event);
ev->set_pressed(false);
get_singleton()->input->parse_input_event(ev);
- return ev->get_scancode() != KEY_UNKNOWN && ev->get_scancode() != 0;
+ return ev->get_keycode() != KEY_UNKNOWN && ev->get_keycode() != 0;
}
// Mouse
@@ -455,7 +470,7 @@ void OS_JavaScript::set_custom_mouse_cursor(const RES &p_cursor, CursorShape p_s
if (p_cursor.is_valid()) {
- Map<CursorShape, Vector<Variant> >::Element *cursor_c = cursors_cache.find(p_shape);
+ Map<CursorShape, Vector<Variant>>::Element *cursor_c = cursors_cache.find(p_shape);
if (cursor_c) {
if (cursor_c->get()[0] == p_cursor && cursor_c->get()[1] == p_hotspot) {
@@ -466,7 +481,7 @@ void OS_JavaScript::set_custom_mouse_cursor(const RES &p_cursor, CursorShape p_s
cursors_cache.erase(p_shape);
}
- Ref<Texture> texture = p_cursor;
+ Ref<Texture2D> texture = p_cursor;
Ref<AtlasTexture> atlas_texture = p_cursor;
Ref<Image> image;
Size2 texture_size;
@@ -523,17 +538,13 @@ void OS_JavaScript::set_custom_mouse_cursor(const RES &p_cursor, CursorShape p_s
png_meta.height = texture_size.height;
png_meta.format = PNG_FORMAT_RGBA;
- PoolByteArray png;
+ PackedByteArray png;
size_t len;
- PoolByteArray::Read r = image->get_data().read();
- ERR_FAIL_COND(!png_image_write_get_memory_size(png_meta, len, 0, r.ptr(), 0, NULL));
+ PackedByteArray data = image->get_data();
+ ERR_FAIL_COND(!png_image_write_get_memory_size(png_meta, len, 0, data.ptr(), 0, NULL));
png.resize(len);
- PoolByteArray::Write w = png.write();
- ERR_FAIL_COND(!png_image_write_to_memory(&png_meta, w.ptr(), &len, 0, r.ptr(), 0, NULL));
- w = PoolByteArray::Write();
-
- r = png.read();
+ ERR_FAIL_COND(!png_image_write_to_memory(&png_meta, png.ptrw(), &len, 0, data.ptr(), 0, NULL));
char *object_url;
/* clang-format off */
@@ -548,9 +559,8 @@ void OS_JavaScript::set_custom_mouse_cursor(const RES &p_cursor, CursorShape p_s
var string_on_wasm_heap = _malloc(length_bytes);
setValue(PTR, string_on_wasm_heap, '*');
stringToUTF8(url, string_on_wasm_heap, length_bytes);
- }, r.ptr(), len, &object_url);
+ }, png.ptr(), len, &object_url);
/* clang-format on */
- r = PoolByteArray::Read();
String url = String::utf8(object_url) + "?" + itos(p_hotspot.x) + " " + itos(p_hotspot.y);
@@ -811,8 +821,6 @@ int OS_JavaScript::get_video_driver_count() const {
const char *OS_JavaScript::get_video_driver_name(int p_driver) const {
switch (p_driver) {
- case VIDEO_DRIVER_GLES3:
- return "GLES3";
case VIDEO_DRIVER_GLES2:
return "GLES2";
}
@@ -879,52 +887,30 @@ int OS_JavaScript::get_current_video_driver() const {
void OS_JavaScript::initialize_core() {
OS_Unix::initialize_core();
- FileAccess::make_default<FileAccessBufferedFA<FileAccessUnix> >(FileAccess::ACCESS_RESOURCES);
+ FileAccess::make_default<FileAccessBufferedFA<FileAccessUnix>>(FileAccess::ACCESS_RESOURCES);
}
Error OS_JavaScript::initialize(const VideoMode &p_desired, int p_video_driver, int p_audio_driver) {
+#if 0
EmscriptenWebGLContextAttributes attributes;
emscripten_webgl_init_context_attributes(&attributes);
- attributes.alpha = false;
+ attributes.alpha = GLOBAL_GET("display/window/per_pixel_transparency/allowed");
attributes.antialias = false;
ERR_FAIL_INDEX_V(p_video_driver, VIDEO_DRIVER_MAX, ERR_INVALID_PARAMETER);
- bool gles3 = true;
- if (p_video_driver == VIDEO_DRIVER_GLES2) {
- gles3 = false;
+ if (p_desired.layered) {
+ set_window_per_pixel_transparency_enabled(true);
}
bool gl_initialization_error = false;
- while (true) {
- if (gles3) {
- if (RasterizerGLES3::is_viable() == OK) {
- attributes.majorVersion = 2;
- RasterizerGLES3::register_config();
- RasterizerGLES3::make_current();
- break;
- } else {
- if (GLOBAL_GET("rendering/quality/driver/fallback_to_gles2")) {
- p_video_driver = VIDEO_DRIVER_GLES2;
- gles3 = false;
- continue;
- } else {
- gl_initialization_error = true;
- break;
- }
- }
- } else {
- if (RasterizerGLES2::is_viable() == OK) {
- attributes.majorVersion = 1;
- RasterizerGLES2::register_config();
- RasterizerGLES2::make_current();
- break;
- } else {
- gl_initialization_error = true;
- break;
- }
- }
+ if (RasterizerGLES2::is_viable() == OK) {
+ attributes.majorVersion = 1;
+ RasterizerGLES2::register_config();
+ RasterizerGLES2::make_current();
+ } else {
+ gl_initialization_error = true;
}
EMSCRIPTEN_WEBGL_CONTEXT_HANDLE ctx = emscripten_webgl_create_context(GODOT_CANVAS_SELECTOR, &attributes);
@@ -933,9 +919,8 @@ Error OS_JavaScript::initialize(const VideoMode &p_desired, int p_video_driver,
}
if (gl_initialization_error) {
- OS::get_singleton()->alert("Your browser does not support any of the supported WebGL versions.\n"
- "Please update your browser version.",
- "Unable to initialize Video driver");
+ OS::get_singleton()->alert("Your browser does not seem to support WebGL. Please update your browser version.",
+ "Unable to initialize video driver");
return ERR_UNAVAILABLE;
}
@@ -950,6 +935,7 @@ Error OS_JavaScript::initialize(const VideoMode &p_desired, int p_video_driver,
if (p_desired.fullscreen) {
/* clang-format off */
EM_ASM({
+ const canvas = Module.canvas;
(canvas.requestFullscreen || canvas.msRequestFullscreen ||
canvas.mozRequestFullScreen || canvas.mozRequestFullscreen ||
canvas.webkitRequestFullscreen
@@ -964,6 +950,8 @@ Error OS_JavaScript::initialize(const VideoMode &p_desired, int p_video_driver,
} else {
set_window_size(get_window_size());
}
+#endif
+ RasterizerDummy::make_current(); // TODO GLES2 in Godot 4.0... or webgpu?
char locale_ptr[16];
/* clang-format off */
@@ -980,7 +968,7 @@ Error OS_JavaScript::initialize(const VideoMode &p_desired, int p_video_driver,
EMSCRIPTEN_RESULT result;
#define EM_CHECK(ev) \
if (result != EMSCRIPTEN_RESULT_SUCCESS) \
- ERR_PRINTS("Error while setting " #ev " callback: Code " + itos(result))
+ ERR_PRINT("Error while setting " #ev " callback: Code " + itos(result));
#define SET_EM_CALLBACK(target, ev, cb) \
result = emscripten_set_##ev##_callback(target, NULL, true, &cb); \
EM_CHECK(ev)
@@ -994,10 +982,10 @@ Error OS_JavaScript::initialize(const VideoMode &p_desired, int p_video_driver,
SET_EM_CALLBACK(GODOT_CANVAS_SELECTOR, mousedown, mouse_button_callback)
SET_EM_CALLBACK(EMSCRIPTEN_EVENT_TARGET_WINDOW, mouseup, mouse_button_callback)
SET_EM_CALLBACK(EMSCRIPTEN_EVENT_TARGET_WINDOW, wheel, wheel_callback)
- SET_EM_CALLBACK(EMSCRIPTEN_EVENT_TARGET_WINDOW, touchstart, touch_press_callback)
- SET_EM_CALLBACK(EMSCRIPTEN_EVENT_TARGET_WINDOW, touchmove, touchmove_callback)
- SET_EM_CALLBACK(EMSCRIPTEN_EVENT_TARGET_WINDOW, touchend, touch_press_callback)
- SET_EM_CALLBACK(EMSCRIPTEN_EVENT_TARGET_WINDOW, touchcancel, touch_press_callback)
+ SET_EM_CALLBACK(GODOT_CANVAS_SELECTOR, touchstart, touch_press_callback)
+ SET_EM_CALLBACK(GODOT_CANVAS_SELECTOR, touchmove, touchmove_callback)
+ SET_EM_CALLBACK(GODOT_CANVAS_SELECTOR, touchend, touch_press_callback)
+ SET_EM_CALLBACK(GODOT_CANVAS_SELECTOR, touchcancel, touch_press_callback)
SET_EM_CALLBACK(GODOT_CANVAS_SELECTOR, keydown, keydown_callback)
SET_EM_CALLBACK(GODOT_CANVAS_SELECTOR, keypress, keypress_callback)
SET_EM_CALLBACK(GODOT_CANVAS_SELECTOR, keyup, keyup_callback)
@@ -1191,17 +1179,14 @@ void OS_JavaScript::set_icon(const Ref<Image> &p_icon) {
png_meta.height = icon->get_height();
png_meta.format = PNG_FORMAT_RGBA;
- PoolByteArray png;
+ PackedByteArray png;
size_t len;
- PoolByteArray::Read r = icon->get_data().read();
- ERR_FAIL_COND(!png_image_write_get_memory_size(png_meta, len, 0, r.ptr(), 0, NULL));
+ PackedByteArray data = icon->get_data();
+ ERR_FAIL_COND(!png_image_write_get_memory_size(png_meta, len, 0, data.ptr(), 0, NULL));
png.resize(len);
- PoolByteArray::Write w = png.write();
- ERR_FAIL_COND(!png_image_write_to_memory(&png_meta, w.ptr(), &len, 0, r.ptr(), 0, NULL));
- w = PoolByteArray::Write();
+ ERR_FAIL_COND(!png_image_write_to_memory(&png_meta, png.ptrw(), &len, 0, data.ptr(), 0, NULL));
- r = png.read();
/* clang-format off */
EM_ASM_ARGS({
var PNG_PTR = $0;
@@ -1217,7 +1202,7 @@ void OS_JavaScript::set_icon(const Ref<Image> &p_icon) {
document.head.appendChild(link);
}
link.href = url;
- }, r.ptr(), len);
+ }, png.ptr(), len);
/* clang-format on */
}
@@ -1257,24 +1242,6 @@ String OS_JavaScript::get_resource_dir() const {
return "/";
}
-OS::PowerState OS_JavaScript::get_power_state() {
-
- WARN_PRINT("Power management is not supported for the HTML5 platform, defaulting to POWERSTATE_UNKNOWN");
- return OS::POWERSTATE_UNKNOWN;
-}
-
-int OS_JavaScript::get_power_seconds_left() {
-
- WARN_PRINT("Power management is not supported for the HTML5 platform, defaulting to -1");
- return -1;
-}
-
-int OS_JavaScript::get_power_percent_left() {
-
- WARN_PRINT("Power management is not supported for the HTML5 platform, defaulting to -1");
- return -1;
-}
-
void OS_JavaScript::file_access_close_callback(const String &p_file, int p_flags) {
OS_JavaScript *os = get_singleton();
@@ -1315,6 +1282,7 @@ OS_JavaScript::OS_JavaScript(int p_argc, char *p_argv[]) {
window_maximized = false;
entering_fullscreen = false;
just_exited_fullscreen = false;
+ transparency_enabled = false;
main_loop = NULL;
diff --git a/platform/javascript/os_javascript.h b/platform/javascript/os_javascript.h
index 5c02a292ee..ed59477914 100644
--- a/platform/javascript/os_javascript.h
+++ b/platform/javascript/os_javascript.h
@@ -46,12 +46,13 @@ class OS_JavaScript : public OS_Unix {
bool window_maximized;
bool entering_fullscreen;
bool just_exited_fullscreen;
+ bool transparency_enabled;
InputDefault *input;
Ref<InputEventKey> deferred_key_event;
CursorShape cursor_shape;
String cursors[CURSOR_MAX];
- Map<CursorShape, Vector<Variant> > cursors_cache;
+ Map<CursorShape, Vector<Variant>> cursors_cache;
Point2 touches[32];
Point2i last_click_pos;
@@ -123,6 +124,9 @@ public:
virtual void set_mouse_mode(MouseMode p_mode);
virtual MouseMode get_mouse_mode() const;
+ virtual bool get_window_per_pixel_transparency_enabled() const;
+ virtual void set_window_per_pixel_transparency_enabled(bool p_enabled);
+
virtual bool has_touchscreen_ui_hint() const;
virtual bool is_joy_known(int p_device);
@@ -156,10 +160,6 @@ public:
virtual String get_resource_dir() const;
virtual String get_user_data_dir() const;
- virtual OS::PowerState get_power_state();
- virtual int get_power_seconds_left();
- virtual int get_power_percent_left();
-
void set_idb_available(bool p_idb_available);
virtual bool is_userfs_persistent() const;
diff --git a/platform/javascript/pre.js b/platform/javascript/pre.js
deleted file mode 100644
index a870e676ea..0000000000
--- a/platform/javascript/pre.js
+++ /dev/null
@@ -1,5 +0,0 @@
-var Engine = {
- RuntimeEnvironment: function(Module, exposedLibs) {
- // The above is concatenated with generated code, and acts as the start of
- // a wrapper for said code. See engine.js for the other part of the
- // wrapper.
diff --git a/platform/osx/SCsub b/platform/osx/SCsub
index e15b4339a7..0a4e0a45e1 100644
--- a/platform/osx/SCsub
+++ b/platform/osx/SCsub
@@ -9,10 +9,10 @@ files = [
'crash_handler_osx.mm',
'os_osx.mm',
'godot_main_osx.mm',
- 'semaphore_osx.cpp',
'dir_access_osx.mm',
'joypad_osx.cpp',
- 'power_osx.cpp',
+ 'vulkan_context_osx.mm',
+ 'context_gl_osx.mm'
]
prog = env.add_program('#bin/godot', files)
diff --git a/platform/osx/power_osx.h b/platform/osx/context_gl_osx.h
index 6f9b213439..6e73c2203a 100644
--- a/platform/osx/power_osx.h
+++ b/platform/osx/context_gl_osx.h
@@ -1,5 +1,5 @@
/*************************************************************************/
-/* power_osx.h */
+/* context_gl_osx.h */
/*************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
@@ -28,32 +28,48 @@
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/
-#ifndef POWER_OSX_H
-#define POWER_OSX_H
+#ifndef CONTEXT_GL_OSX_H
+#define CONTEXT_GL_OSX_H
-#include "core/os/file_access.h"
+#if defined(OPENGL_ENABLED) || defined(GLES_ENABLED)
+
+#include "core/error_list.h"
#include "core/os/os.h"
-#include "dir_access_osx.h"
-#include <CoreFoundation/CoreFoundation.h>
+#include <AppKit/AppKit.h>
+#include <ApplicationServices/ApplicationServices.h>
+#include <CoreVideo/CoreVideo.h>
+
+class ContextGL_OSX {
-class PowerOSX {
+ bool opengl_3_context;
+ bool use_vsync;
-private:
- int nsecs_left;
- int percent_left;
- OS::PowerState power_state;
- void checkps(CFDictionaryRef dict, bool *have_ac, bool *have_battery, bool *charging);
- bool GetPowerInfo_MacOSX(/*PowerState * state, int *seconds, int *percent*/);
- bool UpdatePowerInfo();
+ void *framework;
+ id window_view;
+ NSOpenGLPixelFormat *pixelFormat;
+ NSOpenGLContext *context;
public:
- PowerOSX();
- virtual ~PowerOSX();
+ void release_current();
+
+ void make_current();
+ void update();
+
+ void set_opacity(GLint p_opacity);
+
+ int get_window_width();
+ int get_window_height();
+ void swap_buffers();
+
+ Error initialize();
+
+ void set_use_vsync(bool p_use);
+ bool is_using_vsync() const;
- OS::PowerState get_power_state();
- int get_power_seconds_left();
- int get_power_percent_left();
+ ContextGL_OSX(id p_view, bool p_opengl_3_context);
+ ~ContextGL_OSX();
};
-#endif // POWER_OSX_H
+#endif
+#endif \ No newline at end of file
diff --git a/platform/osx/context_gl_osx.mm b/platform/osx/context_gl_osx.mm
new file mode 100644
index 0000000000..91d1332d24
--- /dev/null
+++ b/platform/osx/context_gl_osx.mm
@@ -0,0 +1,172 @@
+/*************************************************************************/
+/* context_gl_osx.mm */
+/*************************************************************************/
+/* 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 "context_gl_osx.h"
+
+#if defined(OPENGL_ENABLED) || defined(GLES_ENABLED)
+
+void ContextGL_OSX::release_current() {
+
+ [NSOpenGLContext clearCurrentContext];
+}
+
+void ContextGL_OSX::make_current() {
+
+ [context makeCurrentContext];
+}
+
+void ContextGL_OSX::update() {
+
+ [context update];
+}
+
+void ContextGL_OSX::set_opacity(GLint p_opacity) {
+
+ [context setValues:&p_opacity forParameter:NSOpenGLCPSurfaceOpacity];
+}
+
+int ContextGL_OSX::get_window_width() {
+
+ return OS::get_singleton()->get_video_mode().width;
+}
+
+int ContextGL_OSX::get_window_height() {
+
+ return OS::get_singleton()->get_video_mode().height;
+}
+
+void ContextGL_OSX::swap_buffers() {
+
+ [context flushBuffer];
+}
+
+void ContextGL_OSX::set_use_vsync(bool p_use) {
+
+ CGLContextObj ctx = CGLGetCurrentContext();
+ if (ctx) {
+ GLint swapInterval = p_use ? 1 : 0;
+ CGLSetParameter(ctx, kCGLCPSwapInterval, &swapInterval);
+ use_vsync = p_use;
+ }
+}
+
+bool ContextGL_OSX::is_using_vsync() const {
+
+ return use_vsync;
+}
+
+Error ContextGL_OSX::initialize() {
+
+ framework = CFBundleGetBundleWithIdentifier(CFSTR("com.apple.opengl"));
+ ERR_FAIL_COND_V(!framework, ERR_CANT_CREATE);
+
+ unsigned int attributeCount = 0;
+
+ // OS X needs non-zero color size, so set reasonable values
+ int colorBits = 32;
+
+ // Fail if a robustness strategy was requested
+
+#define ADD_ATTR(x) \
+ { attributes[attributeCount++] = x; }
+#define ADD_ATTR2(x, y) \
+ { \
+ ADD_ATTR(x); \
+ ADD_ATTR(y); \
+ }
+
+ // Arbitrary array size here
+ NSOpenGLPixelFormatAttribute attributes[40];
+
+ ADD_ATTR(NSOpenGLPFADoubleBuffer);
+ ADD_ATTR(NSOpenGLPFAClosestPolicy);
+
+ if (!opengl_3_context) {
+ ADD_ATTR2(NSOpenGLPFAOpenGLProfile, NSOpenGLProfileVersionLegacy);
+ } else {
+ //we now need OpenGL 3 or better, maybe even change this to 3_3Core ?
+ ADD_ATTR2(NSOpenGLPFAOpenGLProfile, NSOpenGLProfileVersion3_2Core);
+ }
+
+ ADD_ATTR2(NSOpenGLPFAColorSize, colorBits);
+
+ /*
+ if (fbconfig->alphaBits > 0)
+ ADD_ATTR2(NSOpenGLPFAAlphaSize, fbconfig->alphaBits);
+*/
+
+ ADD_ATTR2(NSOpenGLPFADepthSize, 24);
+
+ ADD_ATTR2(NSOpenGLPFAStencilSize, 8);
+
+ /*
+ if (fbconfig->stereo)
+ ADD_ATTR(NSOpenGLPFAStereo);
+*/
+
+ /*
+ if (fbconfig->samples > 0) {
+ ADD_ATTR2(NSOpenGLPFASampleBuffers, 1);
+ ADD_ATTR2(NSOpenGLPFASamples, fbconfig->samples);
+ }
+*/
+
+ // NOTE: All NSOpenGLPixelFormats on the relevant cards support sRGB
+ // framebuffer, so there's no need (and no way) to request it
+
+ ADD_ATTR(0);
+
+#undef ADD_ATTR
+#undef ADD_ATTR2
+
+ pixelFormat = [[NSOpenGLPixelFormat alloc] initWithAttributes:attributes];
+ ERR_FAIL_COND_V(pixelFormat == nil, ERR_CANT_CREATE);
+
+ context = [[NSOpenGLContext alloc] initWithFormat:pixelFormat shareContext:nil];
+
+ ERR_FAIL_COND_V(context == nil, ERR_CANT_CREATE);
+
+ [context setView:window_view];
+
+ [context makeCurrentContext];
+
+ return OK;
+}
+
+ContextGL_OSX::ContextGL_OSX(id p_view, bool p_opengl_3_context) {
+
+ opengl_3_context = p_opengl_3_context;
+ window_view = p_view;
+ use_vsync = false;
+}
+
+ContextGL_OSX::~ContextGL_OSX() {}
+
+#endif
diff --git a/platform/osx/detect.py b/platform/osx/detect.py
index 7882253e7a..12ca5c10dc 100644
--- a/platform/osx/detect.py
+++ b/platform/osx/detect.py
@@ -1,5 +1,6 @@
import os
import sys
+import subprocess
from methods import detect_darwin_sdk_path
@@ -25,8 +26,12 @@ def get_opts():
return [
('osxcross_sdk', 'OSXCross SDK version', 'darwin14'),
('MACOS_SDK_PATH', 'Path to the macOS SDK', ''),
+ BoolVariable('use_static_mvk', 'Link MoltenVK statically as Level-0 driver (better portability) or use Vulkan ICD loader (enables validation layers)', False),
EnumVariable('debug_symbols', 'Add debugging symbols to release builds', 'yes', ('yes', 'no', 'full')),
BoolVariable('separate_debug_symbols', 'Create a separate file containing debugging symbols', False),
+ BoolVariable('use_ubsan', 'Use LLVM/GCC compiler undefined behavior sanitizer (UBSAN)', False),
+ BoolVariable('use_asan', 'Use LLVM/GCC compiler address sanitizer (ASAN))', False),
+ BoolVariable('use_tsan', 'Use LLVM/GCC compiler thread sanitizer (TSAN))', False),
]
@@ -122,6 +127,21 @@ def configure(env):
env["CC"] = "clang"
env["LINK"] = "clang++"
+ if env['use_ubsan'] or env['use_asan'] or env['use_tsan']:
+ env.extra_suffix += "s"
+
+ if env['use_ubsan']:
+ env.Append(CCFLAGS=['-fsanitize=undefined'])
+ env.Append(LINKFLAGS=['-fsanitize=undefined'])
+
+ if env['use_asan']:
+ env.Append(CCFLAGS=['-fsanitize=address'])
+ env.Append(LINKFLAGS=['-fsanitize=address'])
+
+ if env['use_tsan']:
+ env.Append(CCFLAGS=['-fsanitize=thread'])
+ env.Append(LINKFLAGS=['-fsanitize=thread'])
+
## Dependencies
if env['builtin_libtheora']:
@@ -130,9 +150,19 @@ def configure(env):
## Flags
env.Prepend(CPPPATH=['#platform/osx'])
- env.Append(CPPDEFINES=['OSX_ENABLED', 'UNIX_ENABLED', 'GLES_ENABLED', 'APPLE_STYLE_KEYS', 'COREAUDIO_ENABLED', 'COREMIDI_ENABLED'])
- env.Append(LINKFLAGS=['-framework', 'Cocoa', '-framework', 'Carbon', '-framework', 'OpenGL', '-framework', 'AGL', '-framework', 'AudioUnit', '-framework', 'CoreAudio', '-framework', 'CoreMIDI', '-lz', '-framework', 'IOKit', '-framework', 'ForceFeedback', '-framework', 'AVFoundation', '-framework', 'CoreMedia', '-framework', 'CoreVideo'])
- env.Append(LIBS=['pthread'])
-
- env.Append(CCFLAGS=['-mmacosx-version-min=10.9'])
- env.Append(LINKFLAGS=['-mmacosx-version-min=10.9'])
+ env.Append(CPPDEFINES=['OSX_ENABLED', 'UNIX_ENABLED', 'APPLE_STYLE_KEYS', 'COREAUDIO_ENABLED', 'COREMIDI_ENABLED'])
+ env.Append(LINKFLAGS=['-framework', 'Cocoa', '-framework', 'Carbon', '-framework', 'AudioUnit', '-framework', 'CoreAudio', '-framework', 'CoreMIDI', '-framework', 'IOKit', '-framework', 'ForceFeedback', '-framework', 'CoreVideo', '-framework', 'AVFoundation', '-framework', 'CoreMedia'])
+ env.Append(LIBS=['pthread', 'z'])
+
+ env.Append(CPPDEFINES=['VULKAN_ENABLED'])
+ env.Append(LINKFLAGS=['-framework', 'Metal', '-framework', 'QuartzCore', '-framework', 'IOSurface'])
+ if (env['use_static_mvk']):
+ env.Append(LINKFLAGS=['-framework', 'MoltenVK'])
+ env['builtin_vulkan'] = False
+ elif not env['builtin_vulkan']:
+ env.Append(LIBS=['vulkan'])
+
+ #env.Append(CPPDEFINES=['GLES_ENABLED', 'OPENGL_ENABLED'])
+
+ env.Append(CCFLAGS=['-mmacosx-version-min=10.12'])
+ env.Append(LINKFLAGS=['-mmacosx-version-min=10.12'])
diff --git a/platform/osx/export/export.cpp b/platform/osx/export/export.cpp
index cf38664022..dbe52da912 100644
--- a/platform/osx/export/export.cpp
+++ b/platform/osx/export/export.cpp
@@ -74,7 +74,7 @@ protected:
public:
virtual String get_name() const { return "Mac OSX"; }
virtual String get_os_name() const { return "OSX"; }
- virtual Ref<Texture> get_logo() const { return logo; }
+ virtual Ref<Texture2D> get_logo() const { return logo; }
virtual List<String> get_binary_extensions(const Ref<EditorExportPreset> &p_preset) const {
List<String> list;
@@ -139,7 +139,7 @@ void EditorExportPlatformOSX::get_export_options(List<ExportOption> *r_options)
r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "codesign/timestamp"), true));
r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "codesign/hardened_runtime"), true));
r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "codesign/entitlements", PROPERTY_HINT_GLOBAL_FILE, "*.plist"), ""));
- r_options->push_back(ExportOption(PropertyInfo(Variant::POOL_STRING_ARRAY, "codesign/custom_options"), PoolStringArray()));
+ r_options->push_back(ExportOption(PropertyInfo(Variant::PACKED_STRING_ARRAY, "codesign/custom_options"), PackedStringArray()));
#endif
r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "texture_format/s3tc"), true));
@@ -147,7 +147,7 @@ void EditorExportPlatformOSX::get_export_options(List<ExportOption> *r_options)
r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "texture_format/etc2"), false));
}
-void _rgba8_to_packbits_encode(int p_ch, int p_size, PoolVector<uint8_t> &p_source, Vector<uint8_t> &p_dest) {
+void _rgba8_to_packbits_encode(int p_ch, int p_size, Vector<uint8_t> &p_source, Vector<uint8_t> &p_dest) {
int src_len = p_size * p_size;
@@ -160,11 +160,11 @@ void _rgba8_to_packbits_encode(int p_ch, int p_size, PoolVector<uint8_t> &p_sour
int i = 0;
while (i < src_len) {
- uint8_t cur = p_source.read()[i * 4 + p_ch];
+ uint8_t cur = p_source.ptr()[i * 4 + p_ch];
if (i < src_len - 2) {
- if ((p_source.read()[(i + 1) * 4 + p_ch] == cur) && (p_source.read()[(i + 2) * 4 + p_ch] == cur)) {
+ if ((p_source.ptr()[(i + 1) * 4 + p_ch] == cur) && (p_source.ptr()[(i + 2) * 4 + p_ch] == cur)) {
if (buf_size > 0) {
result.write[res_size++] = (uint8_t)(buf_size - 1);
copymem(&result.write[res_size], &buf, buf_size);
@@ -176,7 +176,7 @@ void _rgba8_to_packbits_encode(int p_ch, int p_size, PoolVector<uint8_t> &p_sour
bool hit_lim = true;
for (int j = 3; j <= lim; j++) {
- if (p_source.read()[(i + j) * 4 + p_ch] != cur) {
+ if (p_source.ptr()[(i + j) * 4 + p_ch] != cur) {
hit_lim = false;
i = i + j - 1;
result.write[res_size++] = (uint8_t)(j - 3 + 0x80);
@@ -278,7 +278,7 @@ void EditorExportPlatformOSX::_make_icon(const Ref<Image> &p_icon, Vector<uint8_
DirAccess::remove_file_or_error(path);
} else {
- PoolVector<uint8_t> src_data = copy->get_data();
+ Vector<uint8_t> src_data = copy->get_data();
//encode 24bit RGB RLE icon
{
@@ -302,7 +302,7 @@ void EditorExportPlatformOSX::_make_icon(const Ref<Image> &p_icon, Vector<uint8_
data.resize(data.size() + len + 8);
for (int j = 0; j < len; j++) {
- data.write[ofs + 8 + j] = src_data.read()[j * 4 + 3];
+ data.write[ofs + 8 + j] = src_data.ptr()[j * 4 + 3];
}
len += 8;
len = BSWAP32(len);
@@ -386,7 +386,7 @@ Error EditorExportPlatformOSX::_code_sign(const Ref<EditorExportPreset> &p_prese
args.push_back(p_preset->get("codesign/entitlements"));
}
- PoolStringArray user_args = p_preset->get("codesign/custom_options");
+ PackedStringArray user_args = p_preset->get("codesign/custom_options");
for (int i = 0; i < user_args.size(); i++) {
String user_arg = user_args[i].strip_edges();
if (!user_arg.empty()) {
@@ -692,7 +692,7 @@ Error EditorExportPlatformOSX::export_project(const Ref<EditorExportPreset> &p_p
unzClose(src_pkg_zip);
if (!found_binary) {
- ERR_PRINTS("Requested template binary '" + binary_to_use + "' not found. It might be missing from your template archive.");
+ ERR_PRINT("Requested template binary '" + binary_to_use + "' not found. It might be missing from your template archive.");
err = ERR_FILE_NOT_FOUND;
}
diff --git a/platform/osx/godot_main_osx.mm b/platform/osx/godot_main_osx.mm
index e6f8cbecf1..eacd2b5cc6 100644
--- a/platform/osx/godot_main_osx.mm
+++ b/platform/osx/godot_main_osx.mm
@@ -36,6 +36,12 @@
#include <unistd.h>
int main(int argc, char **argv) {
+
+#if defined(VULKAN_ENABLED)
+ //MoltenVK - enable full component swizzling support
+ setenv("MVK_CONFIG_FULL_IMAGE_VIEW_SWIZZLE", "1", 1);
+#endif
+
int first_arg = 1;
const char *dbg_arg = "-NSDocumentRevisionsDebugMode";
printf("arguments\n");
diff --git a/platform/osx/joypad_osx.cpp b/platform/osx/joypad_osx.cpp
index 13ece678f3..e9f46fb5a4 100644
--- a/platform/osx/joypad_osx.cpp
+++ b/platform/osx/joypad_osx.cpp
@@ -208,9 +208,8 @@ void joypad::add_hid_elements(CFArrayRef p_array) {
CFArrayApplyFunction(p_array, range, hid_element_added, this);
}
-static void joypad_removed_callback(void *ctx, IOReturn result, void *sender) {
- int id = (intptr_t)ctx;
- self->_device_removed(id);
+static void joypad_removed_callback(void *ctx, IOReturn res, void *sender, IOHIDDeviceRef ioHIDDeviceObject) {
+ self->_device_removed(res, ioHIDDeviceObject);
}
static void joypad_added_callback(void *ctx, IOReturn res, void *sender, IOHIDDeviceRef ioHIDDeviceObject) {
@@ -261,16 +260,15 @@ void JoypadOSX::_device_added(IOReturn p_res, IOHIDDeviceRef p_device) {
#endif
device_list.push_back(new_joypad);
}
- IOHIDDeviceRegisterRemovalCallback(p_device, joypad_removed_callback, (void *)(intptr_t)new_joypad.id);
IOHIDDeviceScheduleWithRunLoop(p_device, CFRunLoopGetCurrent(), GODOT_JOY_LOOP_RUN_MODE);
}
-void JoypadOSX::_device_removed(int p_id) {
+void JoypadOSX::_device_removed(IOReturn p_res, IOHIDDeviceRef p_device) {
- int device = get_joy_index(p_id);
+ int device = get_joy_ref(p_device);
ERR_FAIL_COND(device == -1);
- input->joy_connection_changed(p_id, false, "");
+ input->joy_connection_changed(device_list[device].id, false, "");
device_list.write[device].free();
device_list.remove(device);
}
@@ -516,6 +514,13 @@ int JoypadOSX::get_joy_index(int p_id) const {
return -1;
}
+int JoypadOSX::get_joy_ref(IOHIDDeviceRef p_device) const {
+ for (int i = 0; i < device_list.size(); i++) {
+ if (device_list[i].device_ref == p_device) return i;
+ }
+ return -1;
+}
+
bool JoypadOSX::have_device(IOHIDDeviceRef p_device) const {
for (int i = 0; i < device_list.size(); i++) {
if (device_list[i].device_ref == p_device) {
@@ -558,6 +563,7 @@ void JoypadOSX::config_hid_manager(CFArrayRef p_matching_array) const {
IOHIDManagerSetDeviceMatchingMultiple(hid_manager, p_matching_array);
IOHIDManagerRegisterDeviceMatchingCallback(hid_manager, joypad_added_callback, NULL);
+ IOHIDManagerRegisterDeviceRemovalCallback(hid_manager, joypad_removed_callback, NULL);
IOHIDManagerScheduleWithRunLoop(hid_manager, runloop, GODOT_JOY_LOOP_RUN_MODE);
while (CFRunLoopRunInMode(GODOT_JOY_LOOP_RUN_MODE, 0, TRUE) == kCFRunLoopRunHandledSource) {
diff --git a/platform/osx/joypad_osx.h b/platform/osx/joypad_osx.h
index 388251016b..2c076b3680 100644
--- a/platform/osx/joypad_osx.h
+++ b/platform/osx/joypad_osx.h
@@ -103,6 +103,7 @@ private:
bool configure_joypad(IOHIDDeviceRef p_device_ref, joypad *p_joy);
int get_joy_index(int p_id) const;
+ int get_joy_ref(IOHIDDeviceRef p_device) const;
void poll_joypads() const;
void setup_joypad_objects();
@@ -115,7 +116,7 @@ public:
void process_joypads();
void _device_added(IOReturn p_res, IOHIDDeviceRef p_device);
- void _device_removed(int p_id);
+ void _device_removed(IOReturn p_res, IOHIDDeviceRef p_device);
JoypadOSX();
~JoypadOSX();
diff --git a/platform/osx/os_osx.h b/platform/osx/os_osx.h
index 190dbcf662..e865c3078f 100644
--- a/platform/osx/os_osx.h
+++ b/platform/osx/os_osx.h
@@ -40,12 +40,20 @@
#include "drivers/unix/os_unix.h"
#include "joypad_osx.h"
#include "main/input_default.h"
-#include "power_osx.h"
#include "servers/audio_server.h"
#include "servers/visual/rasterizer.h"
#include "servers/visual/visual_server_wrap_mt.h"
#include "servers/visual_server.h"
+#if defined(OPENGL_ENABLED)
+#include "context_gl_osx.h"
+#endif
+
+#if defined(VULKAN_ENABLED)
+#include "drivers/vulkan/rendering_device_vulkan.h"
+#include "platform/osx/vulkan_context_osx.h"
+#endif
+
#include <AppKit/AppKit.h>
#include <AppKit/NSCursor.h>
#include <ApplicationServices/ApplicationServices.h>
@@ -61,7 +69,8 @@ public:
bool pressed;
bool echo;
bool raw;
- uint32_t scancode;
+ uint32_t keycode;
+ uint32_t physical_keycode;
uint32_t unicode;
};
@@ -69,8 +78,6 @@ public:
int key_event_pos;
bool force_quit;
- // rasterizer seems to no longer be given to visual server, its using GLES3 directly?
- //Rasterizer *rasterizer;
VisualServer *visual_server;
List<String> args;
@@ -93,7 +100,6 @@ public:
void process_events();
void process_key_events();
- void *framework;
// pthread_key_t current;
bool mouse_grab;
Point2 mouse_pos;
@@ -104,14 +110,21 @@ public:
id window_view;
id autoreleasePool;
id cursor;
- NSOpenGLPixelFormat *pixelFormat;
- NSOpenGLContext *context;
+
+#if defined(OPENGL_ENABLED)
+ ContextGL_OSX *context_gles2;
+#endif
+
+#if defined(VULKAN_ENABLED)
+ VulkanContextOSX *context_vulkan;
+ RenderingDeviceVulkan *rendering_device_vulkan;
+#endif
bool layered_window;
CursorShape cursor_shape;
NSCursor *cursors[CURSOR_MAX];
- Map<CursorShape, Vector<Variant> > cursors_cache;
+ Map<CursorShape, Vector<Variant>> cursors_cache;
MouseMode mouse_mode;
String title;
@@ -134,8 +147,6 @@ public:
Size2 min_size;
Size2 max_size;
- PowerOSX *power_manager;
-
CrashHandler crash_handler;
float _mouse_scale(float p_scale) {
@@ -169,7 +180,7 @@ public:
}
};
- Map<String, Vector<GlobalMenuItem> > global_menus;
+ Map<String, Vector<GlobalMenuItem>> global_menus;
void _update_global_menu();
@@ -291,10 +302,6 @@ public:
virtual String get_unique_id() const;
- virtual OS::PowerState get_power_state();
- virtual int get_power_seconds_left();
- virtual int get_power_percent_left();
-
virtual bool _check_internal_feature_support(const String &p_feature);
virtual void _set_use_vsync(bool p_enable);
diff --git a/platform/osx/os_osx.mm b/platform/osx/os_osx.mm
index 6a214b8669..8ba8ca8a33 100644
--- a/platform/osx/os_osx.mm
+++ b/platform/osx/os_osx.mm
@@ -34,11 +34,18 @@
#include "core/print_string.h"
#include "core/version_generated.gen.h"
#include "dir_access_osx.h"
+
+#if defined(OPENGL_ENABLED)
#include "drivers/gles2/rasterizer_gles2.h"
-#include "drivers/gles3/rasterizer_gles3.h"
+#endif
+
+#if defined(VULKAN_ENABLED)
+#include "servers/visual/rasterizer_rd/rasterizer_rd.h"
+#endif
+
#include "main/main.h"
-#include "semaphore_osx.h"
#include "servers/visual/visual_server_raster.h"
+#include "servers/visual/visual_server_wrap_mt.h"
#include <mach-o/dyld.h>
@@ -52,6 +59,9 @@
#include <os/log.h>
#endif
+#import <QuartzCore/CAMetalLayer.h>
+#include <vulkan/vulkan_metal.h>
+
#include <dlfcn.h>
#include <fcntl.h>
#include <libproc.h>
@@ -115,6 +125,20 @@ static Vector2 get_mouse_pos(NSPoint locationInWindow, CGFloat backingScaleFacto
return Vector2(mouse_x, mouse_y);
}
+static NSCursor *cursorFromSelector(SEL selector, SEL fallback = nil) {
+ if ([NSCursor respondsToSelector:selector]) {
+ id object = [NSCursor performSelector:selector];
+ if ([object isKindOfClass:[NSCursor class]]) {
+ return object;
+ }
+ }
+ if (fallback) {
+ // Fallback should be a reasonable default, no need to check.
+ return [NSCursor performSelector:fallback];
+ }
+ return [NSCursor arrowCursor];
+}
+
@interface GodotApplication : NSApplication
@end
@@ -132,7 +156,8 @@ static Vector2 get_mouse_pos(NSPoint locationInWindow, CGFloat backingScaleFacto
get_key_modifier_state([event modifierFlags], k);
k->set_pressed(true);
- k->set_scancode(KEY_PERIOD);
+ k->set_keycode(KEY_PERIOD);
+ k->set_physical_keycode(KEY_PERIOD);
k->set_echo([event isARepeat]);
OS_OSX::singleton->push_input(k);
@@ -246,29 +271,6 @@ static Vector2 get_mouse_pos(NSPoint locationInWindow, CGFloat backingScaleFacto
return NSTerminateCancel;
}
-- (void)applicationDidHide:(NSNotification *)notification {
- /*
- _Godotwindow* window;
- for (window = _Godot.windowListHead; window; window = window->next)
- _GodotInputWindowVisibility(window, GL_FALSE);
-*/
-}
-
-- (void)applicationDidUnhide:(NSNotification *)notification {
- /*
- _Godotwindow* window;
-
- for (window = _Godot.windowListHead; window; window = window->next) {
- if ([window_object isVisible])
- _GodotInputWindowVisibility(window, GL_TRUE);
- }
-*/
-}
-
-- (void)applicationDidChangeScreenParameters:(NSNotification *)notification {
- //_GodotInputMonitorChange();
-}
-
- (void)showAbout:(id)sender {
if (OS_OSX::singleton->get_main_loop())
OS_OSX::singleton->get_main_loop()->notification(MainLoop::NOTIFICATION_WM_ABOUT);
@@ -280,6 +282,8 @@ static Vector2 get_mouse_pos(NSPoint locationInWindow, CGFloat backingScaleFacto
//_Godotwindow* window;
}
+- (void)windowWillClose:(NSNotification *)notification;
+
@end
@implementation GodotWindowDelegate
@@ -292,6 +296,24 @@ static Vector2 get_mouse_pos(NSPoint locationInWindow, CGFloat backingScaleFacto
return NO;
}
+- (void)windowWillClose:(NSNotification *)notification {
+#if defined(VULKAN_ENABLED)
+ if (OS_OSX::singleton->video_driver_index == OS::VIDEO_DRIVER_VULKAN) {
+
+ if (OS_OSX::singleton->rendering_device_vulkan) {
+ OS_OSX::singleton->rendering_device_vulkan->finalize();
+ memdelete(OS_OSX::singleton->rendering_device_vulkan);
+ OS_OSX::singleton->rendering_device_vulkan = NULL;
+ }
+
+ if (OS_OSX::singleton->context_vulkan) {
+ memdelete(OS_OSX::singleton->context_vulkan);
+ OS_OSX::singleton->context_vulkan = NULL;
+ }
+ }
+#endif
+}
+
- (void)windowDidEnterFullScreen:(NSNotification *)notification {
OS_OSX::singleton->zoomed = true;
@@ -322,11 +344,16 @@ static Vector2 get_mouse_pos(NSPoint locationInWindow, CGFloat backingScaleFacto
NSWindow *window = (NSWindow *)[notification object];
CGFloat newBackingScaleFactor = [window backingScaleFactor];
CGFloat oldBackingScaleFactor = [[[notification userInfo] objectForKey:@"NSBackingPropertyOldScaleFactorKey"] doubleValue];
- if (OS_OSX::singleton->is_hidpi_allowed()) {
- [OS_OSX::singleton->window_view setWantsBestResolutionOpenGLSurface:YES];
- } else {
- [OS_OSX::singleton->window_view setWantsBestResolutionOpenGLSurface:NO];
+
+#if defined(OPENGL_ENABLED)
+ if (OS_OSX::singleton->video_driver_index == OS::VIDEO_DRIVER_GLES2) {
+ if (OS_OSX::singleton->is_hidpi_allowed()) {
+ [OS_OSX::singleton->window_view setWantsBestResolutionOpenGLSurface:YES];
+ } else {
+ [OS_OSX::singleton->window_view setWantsBestResolutionOpenGLSurface:NO];
+ }
}
+#endif
if (newBackingScaleFactor != oldBackingScaleFactor) {
//Set new display scale and window size
@@ -338,6 +365,12 @@ static Vector2 get_mouse_pos(NSPoint locationInWindow, CGFloat backingScaleFacto
OS_OSX::singleton->window_size.width = fbRect.size.width * newDisplayScale;
OS_OSX::singleton->window_size.height = fbRect.size.height * newDisplayScale;
+#if defined(VULKAN_ENABLED)
+ if (OS_OSX::singleton->video_driver_index == OS::VIDEO_DRIVER_VULKAN) {
+ CALayer *layer = [OS_OSX::singleton->window_view layer];
+ layer.contentsScale = OS_OSX::singleton->_display_scale();
+ }
+#endif
//Update context
if (OS_OSX::singleton->main_loop) {
//Force window resize event
@@ -347,8 +380,12 @@ static Vector2 get_mouse_pos(NSPoint locationInWindow, CGFloat backingScaleFacto
}
- (void)windowDidResize:(NSNotification *)notification {
- [OS_OSX::singleton->context update];
+#if defined(OPENGL_ENABLED)
+ if (OS_OSX::singleton->video_driver_index == OS::VIDEO_DRIVER_GLES2) {
+ OS_OSX::singleton->context_gles2->update();
+ }
+#endif
const NSRect contentRect = [OS_OSX::singleton->window_view frame];
const NSRect fbRect = contentRect;
@@ -356,6 +393,14 @@ static Vector2 get_mouse_pos(NSPoint locationInWindow, CGFloat backingScaleFacto
OS_OSX::singleton->window_size.width = fbRect.size.width * displayScale;
OS_OSX::singleton->window_size.height = fbRect.size.height * displayScale;
+#if defined(VULKAN_ENABLED)
+ if (OS_OSX::singleton->video_driver_index == OS::VIDEO_DRIVER_VULKAN) {
+ CALayer *layer = [OS_OSX::singleton->window_view layer];
+ layer.contentsScale = OS_OSX::singleton->_display_scale();
+ OS_OSX::singleton->context_vulkan->window_resize(0, OS_OSX::singleton->window_size.width, OS_OSX::singleton->window_size.height);
+ }
+#endif
+
if (OS_OSX::singleton->main_loop) {
Main::force_redraw();
//Event retrieval blocks until resize is over. Call Main::iteration() directly.
@@ -363,15 +408,6 @@ static Vector2 get_mouse_pos(NSPoint locationInWindow, CGFloat backingScaleFacto
Main::iteration();
}
}
-
- /*
- _GodotInputFramebufferSize(window, fbRect.size.width, fbRect.size.height);
- _GodotInputWindowSize(window, contentRect.size.width, contentRect.size.height);
- _GodotInputWindowDamage(window);
-
- if (window->cursorMode == Godot_CURSOR_DISABLED)
- centerCursor(window);
-*/
}
- (void)windowDidMove:(NSNotification *)notification {
@@ -379,17 +415,6 @@ static Vector2 get_mouse_pos(NSPoint locationInWindow, CGFloat backingScaleFacto
if (OS_OSX::singleton->get_main_loop()) {
OS_OSX::singleton->input->release_pressed_events();
}
-
- /*
- [window->nsgl.context update];
-
- int x, y;
- _GodotPlatformGetWindowPos(window, &x, &y);
- _GodotInputWindowPos(window, x, y);
-
- if (window->cursorMode == Godot_CURSOR_DISABLED)
- centerCursor(window);
-*/
}
- (void)windowDidBecomeKey:(NSNotification *)notification {
@@ -436,8 +461,12 @@ static Vector2 get_mouse_pos(NSPoint locationInWindow, CGFloat backingScaleFacto
bool imeInputEventInProgress;
}
- (void)cancelComposition;
+
+- (CALayer *)makeBackingLayer;
+
- (BOOL)wantsUpdateLayer;
- (void)updateLayer;
+
@end
@implementation GodotContentView
@@ -448,12 +477,32 @@ static Vector2 get_mouse_pos(NSPoint locationInWindow, CGFloat backingScaleFacto
}
}
-- (BOOL)wantsUpdateLayer {
- return YES;
+- (CALayer *)makeBackingLayer {
+#if defined(VULKAN_ENABLED)
+ if (OS_OSX::singleton->video_driver_index == OS::VIDEO_DRIVER_VULKAN) {
+ CALayer *layer = [[CAMetalLayer class] layer];
+ layer.contentsScale = OS_OSX::singleton->_display_scale();
+ return layer;
+ }
+#endif
+ return [super makeBackingLayer];
}
- (void)updateLayer {
- [OS_OSX::singleton->context update];
+#if defined(VULKAN_ENABLED)
+ if (OS_OSX::singleton->video_driver_index == OS::VIDEO_DRIVER_VULKAN) {
+ [super updateLayer];
+ }
+#endif
+#if defined(OPENGL_ENABLED)
+ if (OS_OSX::singleton->video_driver_index == OS::VIDEO_DRIVER_GLES2) {
+ OS_OSX::singleton->context_gles2->update();
+ }
+#endif
+}
+
+- (BOOL)wantsUpdateLayer {
+ return YES;
}
- (id)init {
@@ -586,7 +635,8 @@ static const NSRange kEmptyRange = { NSNotFound, 0 };
ke.pressed = true;
ke.echo = false;
ke.raw = false; // IME input event
- ke.scancode = 0;
+ ke.keycode = 0;
+ ke.physical_keycode = 0;
ke.unicode = codepoint;
push_to_key_event_buffer(ke);
@@ -698,7 +748,7 @@ static void _mouseDownEvent(NSEvent *event, int index, int mask, bool pressed) {
const Vector2 pos = get_mouse_pos([event locationInWindow], backingScaleFactor);
mm->set_position(pos);
mm->set_pressure([event pressure]);
- if ([event subtype] == NSTabletPointEventSubtype) {
+ if ([event subtype] == NSEventSubtypeTabletPoint) {
const NSPoint p = [event tilt];
mm->set_tilt(Vector2(p.x, p.y));
}
@@ -1109,7 +1159,8 @@ static int remapKey(unsigned int key, unsigned int state) {
ke.osx_state = [event modifierFlags];
ke.pressed = true;
ke.echo = [event isARepeat];
- ke.scancode = remapKey([event keyCode], [event modifierFlags]);
+ ke.keycode = remapKey([event keyCode], [event modifierFlags]);
+ ke.physical_keycode = translateKey([event keyCode]);
ke.raw = true;
ke.unicode = [characters characterAtIndex:i];
@@ -1121,7 +1172,8 @@ static int remapKey(unsigned int key, unsigned int state) {
ke.osx_state = [event modifierFlags];
ke.pressed = true;
ke.echo = [event isARepeat];
- ke.scancode = remapKey([event keyCode], [event modifierFlags]);
+ ke.keycode = remapKey([event keyCode], [event modifierFlags]);
+ ke.physical_keycode = translateKey([event keyCode]);
ke.raw = false;
ke.unicode = 0;
@@ -1179,7 +1231,8 @@ static int remapKey(unsigned int key, unsigned int state) {
}
ke.osx_state = mod;
- ke.scancode = remapKey(key, mod);
+ ke.keycode = remapKey(key, mod);
+ ke.physical_keycode = translateKey(key);
ke.unicode = 0;
push_to_key_event_buffer(ke);
@@ -1201,7 +1254,8 @@ static int remapKey(unsigned int key, unsigned int state) {
ke.osx_state = [event modifierFlags];
ke.pressed = false;
ke.echo = [event isARepeat];
- ke.scancode = remapKey([event keyCode], [event modifierFlags]);
+ ke.keycode = remapKey([event keyCode], [event modifierFlags]);
+ ke.physical_keycode = translateKey([event keyCode]);
ke.raw = true;
ke.unicode = [characters characterAtIndex:i];
@@ -1213,7 +1267,8 @@ static int remapKey(unsigned int key, unsigned int state) {
ke.osx_state = [event modifierFlags];
ke.pressed = false;
ke.echo = [event isARepeat];
- ke.scancode = remapKey([event keyCode], [event modifierFlags]);
+ ke.keycode = remapKey([event keyCode], [event modifierFlags]);
+ ke.physical_keycode = translateKey([event keyCode]);
ke.raw = true;
ke.unicode = 0;
@@ -1310,7 +1365,7 @@ void OS_OSX::_update_global_menu() {
for (int i = 1; i < [main_menu numberOfItems]; i++) {
[main_menu removeItemAtIndex:i];
}
- for (Map<String, Vector<GlobalMenuItem> >::Element *E = global_menus.front(); E; E = E->next()) {
+ for (Map<String, Vector<GlobalMenuItem>>::Element *E = global_menus.front(); E; E = E->next()) {
if (E->key() != "_dock") {
NSMenu *menu = [[[NSMenu alloc] initWithTitle:[NSString stringWithUTF8String:E->key().utf8().get_data()]] autorelease];
for (int i = 0; i < E->get().size(); i++) {
@@ -1408,8 +1463,6 @@ void OS_OSX::initialize_core() {
DirAccess::make_default<DirAccessOSX>(DirAccess::ACCESS_RESOURCES);
DirAccess::make_default<DirAccessOSX>(DirAccess::ACCESS_USERDATA);
DirAccess::make_default<DirAccessOSX>(DirAccess::ACCESS_FILESYSTEM);
-
- SemaphoreOSX::make_default();
}
static bool keyboard_layout_dirty = true;
@@ -1444,6 +1497,14 @@ Error OS_OSX::initialize(const VideoMode &p_desired, int p_video_driver, int p_a
// Register to be notified on displays arrangement changes
CGDisplayRegisterReconfigurationCallback(displays_arrangement_changed, NULL);
+ //!!!!!!!!!!!!!!!!!!!!!!!!!!
+ //TODO - do Vulkan and GLES2 support checks, driver selection and fallback
+ video_driver_index = p_video_driver;
+ print_verbose("Driver: " + String(get_video_driver_name(video_driver_index)) + " [" + itos(video_driver_index) + "]");
+ //!!!!!!!!!!!!!!!!!!!!!!!!!!
+
+ //Create window
+
window_delegate = [[GodotWindowDelegate alloc] init];
// Don't use accumulation buffer support; it's not accelerated
@@ -1484,14 +1545,20 @@ Error OS_OSX::initialize(const VideoMode &p_desired, int p_video_driver, int p_a
window_size.height = p_desired.height * displayScale;
if (displayScale > 1.0) {
- [window_view setWantsBestResolutionOpenGLSurface:YES];
- //if (current_videomode.resizable)
+#if defined(OPENGL_ENABLED)
+ if (video_driver_index == VIDEO_DRIVER_GLES2) {
+ [window_view setWantsBestResolutionOpenGLSurface:YES];
+ }
+#endif
[window_object setCollectionBehavior:NSWindowCollectionBehaviorFullScreenPrimary];
} else {
- [window_view setWantsBestResolutionOpenGLSurface:NO];
+#if defined(OPENGL_ENABLED)
+ if (video_driver_index == VIDEO_DRIVER_GLES2) {
+ [window_view setWantsBestResolutionOpenGLSurface:NO];
+ }
+#endif
}
- //[window_object setTitle:[NSString stringWithUTF8String:"GodotEnginies"]];
[window_object setContentView:window_view];
[window_object setDelegate:window_delegate];
[window_object setAcceptsMouseMovedEvents:YES];
@@ -1499,77 +1566,51 @@ Error OS_OSX::initialize(const VideoMode &p_desired, int p_video_driver, int p_a
[window_object setRestorable:NO];
- unsigned int attributeCount = 0;
+ // Init context and rendering device
+#if defined(OPENGL_ENABLED)
+ if (video_driver_index == VIDEO_DRIVER_GLES2) {
- // OS X needs non-zero color size, so set reasonable values
- int colorBits = 32;
+ context_gles2 = memnew(ContextGL_OSX(window_view, false));
- // Fail if a robustness strategy was requested
-
-#define ADD_ATTR(x) \
- { attributes[attributeCount++] = x; }
-#define ADD_ATTR2(x, y) \
- { \
- ADD_ATTR(x); \
- ADD_ATTR(y); \
- }
-
- // Arbitrary array size here
- NSOpenGLPixelFormatAttribute attributes[40];
+ if (context_gles2->initialize() != OK) {
+ memdelete(context_gles2);
+ context_gles2 = NULL;
+ ERR_FAIL_V(ERR_UNAVAILABLE);
+ }
- ADD_ATTR(NSOpenGLPFADoubleBuffer);
- ADD_ATTR(NSOpenGLPFAClosestPolicy);
+ context_gles2->set_use_vsync(p_desired.use_vsync);
- if (p_video_driver == VIDEO_DRIVER_GLES2) {
- ADD_ATTR2(NSOpenGLPFAOpenGLProfile, NSOpenGLProfileVersionLegacy);
- } else {
- //we now need OpenGL 3 or better, maybe even change this to 3_3Core ?
- ADD_ATTR2(NSOpenGLPFAOpenGLProfile, NSOpenGLProfileVersion3_2Core);
+ if (RasterizerGLES2::is_viable() == OK) {
+ RasterizerGLES2::register_config();
+ RasterizerGLES2::make_current();
+ } else {
+ memdelete(context_gles2);
+ context_gles2 = NULL;
+ ERR_FAIL_V(ERR_UNAVAILABLE);
+ }
}
+#endif
+#if defined(VULKAN_ENABLED)
+ if (video_driver_index == VIDEO_DRIVER_VULKAN) {
+
+ context_vulkan = memnew(VulkanContextOSX);
+ if (context_vulkan->initialize() != OK) {
+ memdelete(context_vulkan);
+ context_vulkan = NULL;
+ ERR_FAIL_V(ERR_UNAVAILABLE);
+ }
+ if (context_vulkan->window_create(window_view, get_video_mode().width, get_video_mode().height) == -1) {
+ memdelete(context_vulkan);
+ context_vulkan = NULL;
+ ERR_FAIL_V(ERR_UNAVAILABLE);
+ }
- ADD_ATTR2(NSOpenGLPFAColorSize, colorBits);
-
- /*
- if (fbconfig->alphaBits > 0)
- ADD_ATTR2(NSOpenGLPFAAlphaSize, fbconfig->alphaBits);
-*/
-
- ADD_ATTR2(NSOpenGLPFADepthSize, 24);
-
- ADD_ATTR2(NSOpenGLPFAStencilSize, 8);
-
- /*
- if (fbconfig->stereo)
- ADD_ATTR(NSOpenGLPFAStereo);
-*/
+ rendering_device_vulkan = memnew(RenderingDeviceVulkan);
+ rendering_device_vulkan->initialize(context_vulkan);
- /*
- if (fbconfig->samples > 0) {
- ADD_ATTR2(NSOpenGLPFASampleBuffers, 1);
- ADD_ATTR2(NSOpenGLPFASamples, fbconfig->samples);
+ RasterizerRD::make_current();
}
-*/
-
- // NOTE: All NSOpenGLPixelFormats on the relevant cards support sRGB
- // framebuffer, so there's no need (and no way) to request it
-
- ADD_ATTR(0);
-
-#undef ADD_ATTR
-#undef ADD_ATTR2
-
- pixelFormat = [[NSOpenGLPixelFormat alloc] initWithAttributes:attributes];
- ERR_FAIL_COND_V(pixelFormat == nil, ERR_UNAVAILABLE);
-
- context = [[NSOpenGLContext alloc] initWithFormat:pixelFormat shareContext:nil];
-
- ERR_FAIL_COND_V(context == nil, ERR_UNAVAILABLE);
-
- [context setView:window_view];
-
- [context makeCurrentContext];
-
- set_use_vsync(p_desired.use_vsync);
+#endif
[NSApp activateIgnoringOtherApps:YES];
@@ -1580,53 +1621,6 @@ Error OS_OSX::initialize(const VideoMode &p_desired, int p_video_driver, int p_a
if (p_desired.fullscreen)
zoomed = true;
- /*** END OSX INITIALIZATION ***/
-
- bool gles3 = true;
- if (p_video_driver == VIDEO_DRIVER_GLES2) {
- gles3 = false;
- }
-
- bool editor = Engine::get_singleton()->is_editor_hint();
- bool gl_initialization_error = false;
-
- while (true) {
- if (gles3) {
- if (RasterizerGLES3::is_viable() == OK) {
- RasterizerGLES3::register_config();
- RasterizerGLES3::make_current();
- break;
- } else {
- if (GLOBAL_GET("rendering/quality/driver/fallback_to_gles2") || editor) {
- p_video_driver = VIDEO_DRIVER_GLES2;
- gles3 = false;
- continue;
- } else {
- gl_initialization_error = true;
- break;
- }
- }
- } else {
- if (RasterizerGLES2::is_viable() == OK) {
- RasterizerGLES2::register_config();
- RasterizerGLES2::make_current();
- break;
- } else {
- gl_initialization_error = true;
- break;
- }
- }
- }
-
- if (gl_initialization_error) {
- OS::get_singleton()->alert("Your video card driver does not support any of the supported OpenGL versions.\n"
- "Please update your drivers or if you have a very old or integrated GPU upgrade it.",
- "Unable to initialize Video driver");
- return ERR_UNAVAILABLE;
- }
-
- video_driver_index = p_video_driver;
-
visual_server = memnew(VisualServerRaster);
if (get_render_thread_mode() != RENDER_THREAD_UNSAFE) {
visual_server = memnew(VisualServerWrapMT(visual_server, get_render_thread_mode() == RENDER_SEPARATE_THREAD));
@@ -1638,8 +1632,6 @@ Error OS_OSX::initialize(const VideoMode &p_desired, int p_video_driver, int p_a
input = memnew(InputDefault);
joypad_osx = memnew(JoypadOSX);
- power_manager = memnew(PowerOSX);
-
_ensure_user_data_dir();
restore_rect = Rect2(get_window_position(), get_window_size());
@@ -1659,6 +1651,14 @@ void OS_OSX::finalize() {
midi_driver.close();
#endif
+#if defined(OPENGL_ENABLED)
+ if (video_driver_index == VIDEO_DRIVER_GLES2) {
+
+ if (context_gles2)
+ memdelete(context_gles2);
+ }
+#endif
+
CFNotificationCenterRemoveObserver(CFNotificationCenterGetDistributedCenter(), NULL, kTISNotifySelectedKeyboardInputSourceChanged, NULL);
CGDisplayRemoveReconfigurationCallback(displays_arrangement_changed, NULL);
@@ -1670,7 +1670,6 @@ void OS_OSX::finalize() {
cursors_cache.clear();
visual_server->finish();
memdelete(visual_server);
- //memdelete(rasterizer);
}
void OS_OSX::set_main_loop(MainLoop *p_main_loop) {
@@ -1710,42 +1709,39 @@ public:
case ERR_WARNING:
if (NSAppKitVersionNumber >= NSAppKitVersionNumber10_12) {
os_log_info(OS_LOG_DEFAULT,
- "WARNING: %{public}s: %{public}s\nAt: %{public}s:%i.",
- p_function, err_details, p_file, p_line);
+ "WARNING: %{public}s\nat: %{public}s (%{public}s:%i)",
+ err_details, p_function, p_file, p_line);
}
- logf_error("\E[1;33mWARNING: %s: \E[0m\E[1m%s\n", p_function,
- err_details);
- logf_error("\E[0;33m At: %s:%i.\E[0m\n", p_file, p_line);
+ logf_error("\E[1;33mWARNING:\E[0;93m %s\n", err_details);
+ logf_error("\E[0;90m at: %s (%s:%i)\E[0m\n", p_function, p_file, p_line);
break;
case ERR_SCRIPT:
if (NSAppKitVersionNumber >= NSAppKitVersionNumber10_12) {
os_log_error(OS_LOG_DEFAULT,
- "SCRIPT ERROR: %{public}s: %{public}s\nAt: %{public}s:%i.",
- p_function, err_details, p_file, p_line);
+ "SCRIPT ERROR: %{public}s\nat: %{public}s (%{public}s:%i)",
+ err_details, p_function, p_file, p_line);
}
- logf_error("\E[1;35mSCRIPT ERROR: %s: \E[0m\E[1m%s\n", p_function,
- err_details);
- logf_error("\E[0;35m At: %s:%i.\E[0m\n", p_file, p_line);
+ logf_error("\E[1;35mSCRIPT ERROR:\E[0;95m %s\n", err_details);
+ logf_error("\E[0;90m at: %s (%s:%i)\E[0m\n", p_function, p_file, p_line);
break;
case ERR_SHADER:
if (NSAppKitVersionNumber >= NSAppKitVersionNumber10_12) {
os_log_error(OS_LOG_DEFAULT,
- "SHADER ERROR: %{public}s: %{public}s\nAt: %{public}s:%i.",
- p_function, err_details, p_file, p_line);
+ "SHADER ERROR: %{public}s\nat: %{public}s (%{public}s:%i)",
+ err_details, p_function, p_file, p_line);
}
- logf_error("\E[1;36mSHADER ERROR: %s: \E[0m\E[1m%s\n", p_function,
- err_details);
- logf_error("\E[0;36m At: %s:%i.\E[0m\n", p_file, p_line);
+ logf_error("\E[1;36mSHADER ERROR:\E[0;96m %s\n", err_details);
+ logf_error("\E[0;90m at: %s (%s:%i)\E[0m\n", p_function, p_file, p_line);
break;
case ERR_ERROR:
default:
if (NSAppKitVersionNumber >= NSAppKitVersionNumber10_12) {
os_log_error(OS_LOG_DEFAULT,
- "ERROR: %{public}s: %{public}s\nAt: %{public}s:%i.",
- p_function, err_details, p_file, p_line);
+ "ERROR: %{public}s\nat: %{public}s (%{public}s:%i)",
+ err_details, p_function, p_file, p_line);
}
- logf_error("\E[1;31mERROR: %s: \E[0m\E[1m%s\n", p_function, err_details);
- logf_error("\E[0;31m At: %s:%i.\E[0m\n", p_file, p_line);
+ logf_error("\E[1;31mERROR:\E[0;91m %s\n", err_details);
+ logf_error("\E[0;90m at: %s (%s:%i)\E[0m\n", p_function, p_file, p_line);
break;
}
}
@@ -1765,7 +1761,7 @@ void OS_OSX::alert(const String &p_alert, const String &p_title) {
[window addButtonWithTitle:@"OK"];
[window setMessageText:ns_title];
[window setInformativeText:ns_alert];
- [window setAlertStyle:NSWarningAlertStyle];
+ [window setAlertStyle:NSAlertStyleWarning];
// Display it, then release
[window runModal];
@@ -1813,15 +1809,15 @@ void OS_OSX::set_cursor_shape(CursorShape p_shape) {
case CURSOR_BUSY: [[NSCursor arrowCursor] set]; break;
case CURSOR_DRAG: [[NSCursor closedHandCursor] set]; break;
case CURSOR_CAN_DROP: [[NSCursor openHandCursor] set]; break;
- case CURSOR_FORBIDDEN: [[NSCursor arrowCursor] set]; break;
- case CURSOR_VSIZE: [[NSCursor resizeUpDownCursor] set]; break;
- case CURSOR_HSIZE: [[NSCursor resizeLeftRightCursor] set]; break;
- case CURSOR_BDIAGSIZE: [[NSCursor arrowCursor] set]; break;
- case CURSOR_FDIAGSIZE: [[NSCursor arrowCursor] set]; break;
+ case CURSOR_FORBIDDEN: [[NSCursor operationNotAllowedCursor] set]; break;
+ case CURSOR_VSIZE: [cursorFromSelector(@selector(_windowResizeNorthSouthCursor), @selector(resizeUpDownCursor)) set]; break;
+ case CURSOR_HSIZE: [cursorFromSelector(@selector(_windowResizeEastWestCursor), @selector(resizeLeftRightCursor)) set]; break;
+ case CURSOR_BDIAGSIZE: [cursorFromSelector(@selector(_windowResizeNorthEastSouthWestCursor)) set]; break;
+ case CURSOR_FDIAGSIZE: [cursorFromSelector(@selector(_windowResizeNorthWestSouthEastCursor)) set]; break;
case CURSOR_MOVE: [[NSCursor arrowCursor] set]; break;
case CURSOR_VSPLIT: [[NSCursor resizeUpDownCursor] set]; break;
case CURSOR_HSPLIT: [[NSCursor resizeLeftRightCursor] set]; break;
- case CURSOR_HELP: [[NSCursor arrowCursor] set]; break;
+ case CURSOR_HELP: [cursorFromSelector(@selector(_helpCursor)) set]; break;
default: {
};
}
@@ -1839,7 +1835,7 @@ void OS_OSX::set_custom_mouse_cursor(const RES &p_cursor, CursorShape p_shape, c
if (p_cursor.is_valid()) {
- Map<CursorShape, Vector<Variant> >::Element *cursor_c = cursors_cache.find(p_shape);
+ Map<CursorShape, Vector<Variant>>::Element *cursor_c = cursors_cache.find(p_shape);
if (cursor_c) {
if (cursor_c->get()[0] == p_cursor && cursor_c->get()[1] == p_hotspot) {
@@ -1850,7 +1846,7 @@ void OS_OSX::set_custom_mouse_cursor(const RES &p_cursor, CursorShape p_shape, c
cursors_cache.erase(p_shape);
}
- Ref<Texture> texture = p_cursor;
+ Ref<Texture2D> texture = p_cursor;
Ref<AtlasTexture> atlas_texture = p_cursor;
Ref<Image> image;
Size2 texture_size;
@@ -1900,12 +1896,7 @@ void OS_OSX::set_custom_mouse_cursor(const RES &p_cursor, CursorShape p_shape, c
uint8_t *pixels = [imgrep bitmapData];
int len = int(texture_size.width * texture_size.height);
- PoolVector<uint8_t> data = image->get_data();
- PoolVector<uint8_t>::Read r = data.read();
-
- image->lock();
- /* Premultiply the alpha channel */
for (int i = 0; i < len; i++) {
int row_index = floor(i / texture_size.width) + atlas_rect.position.y;
int column_index = (i % int(texture_size.width)) + atlas_rect.position.x;
@@ -1924,8 +1915,6 @@ void OS_OSX::set_custom_mouse_cursor(const RES &p_cursor, CursorShape p_shape, c
pixels[i * 4 + 3] = alpha;
}
- image->unlock();
-
NSImage *nsimage = [[NSImage alloc] initWithSize:NSMakeSize(texture_size.width, texture_size.height)];
[nsimage addRepresentation:imgrep];
@@ -2060,8 +2049,7 @@ void OS_OSX::set_icon(const Ref<Image> &p_icon) {
uint8_t *pixels = [imgrep bitmapData];
int len = img->get_width() * img->get_height();
- PoolVector<uint8_t> data = img->get_data();
- PoolVector<uint8_t>::Read r = data.read();
+ const uint8_t *r = img->get_data().ptr();
/* Premultiply the alpha channel */
for (int i = 0; i < len; i++) {
@@ -2217,13 +2205,19 @@ String OS_OSX::get_clipboard() const {
}
void OS_OSX::release_rendering_thread() {
-
- [NSOpenGLContext clearCurrentContext];
+#if defined(OPENGL_ENABLED)
+ if (video_driver_index == VIDEO_DRIVER_GLES2) {
+ context_gles2->release_current();
+ }
+#endif
}
void OS_OSX::make_rendering_thread() {
-
- [context makeCurrentContext];
+#if defined(OPENGL_ENABLED)
+ if (video_driver_index == VIDEO_DRIVER_GLES2) {
+ context_gles2->make_current();
+ }
+#endif
}
Error OS_OSX::shell_open(String p_uri) {
@@ -2238,7 +2232,16 @@ String OS_OSX::get_locale() const {
}
void OS_OSX::swap_buffers() {
- [context flushBuffer];
+#if defined(OPENGL_ENABLED)
+ if (video_driver_index == VIDEO_DRIVER_GLES2) {
+ context_gles2->swap_buffers();
+ }
+#endif
+#if defined(VULKAN_ENABLED)
+ if (video_driver_index == VIDEO_DRIVER_VULKAN) {
+ context_vulkan->swap_buffers();
+ }
+#endif
}
void OS_OSX::wm_minimized(bool p_minimized) {
@@ -2648,21 +2651,31 @@ void OS_OSX::set_window_per_pixel_transparency_enabled(bool p_enabled) {
if (layered_window != p_enabled) {
if (p_enabled) {
set_borderless_window(true);
- GLint opacity = 0;
[window_object setBackgroundColor:[NSColor clearColor]];
[window_object setOpaque:NO];
[window_object setHasShadow:NO];
- [context setValues:&opacity forParameter:NSOpenGLCPSurfaceOpacity];
+#if defined(OPENGL_ENABLED)
+ if (video_driver_index == VIDEO_DRIVER_GLES2) {
+ context_gles2->set_opacity(0);
+ }
+#endif
layered_window = true;
} else {
- GLint opacity = 1;
[window_object setBackgroundColor:[NSColor colorWithCalibratedWhite:1 alpha:1]];
[window_object setOpaque:YES];
[window_object setHasShadow:YES];
- [context setValues:&opacity forParameter:NSOpenGLCPSurfaceOpacity];
+#if defined(OPENGL_ENABLED)
+ if (video_driver_index == VIDEO_DRIVER_GLES2) {
+ context_gles2->set_opacity(1);
+ }
+#endif
layered_window = false;
}
- [context update];
+#if defined(OPENGL_ENABLED)
+ if (video_driver_index == VIDEO_DRIVER_GLES2) {
+ context_gles2->update();
+ }
+#endif
NSRect frame = [window_object frame];
[window_object setFrame:NSMakeRect(frame.origin.x, frame.origin.y, 1, 1) display:YES];
[window_object setFrame:frame display:YES];
@@ -2836,32 +2849,35 @@ void OS_OSX::process_key_events() {
get_key_modifier_state(ke.osx_state, k);
k->set_pressed(ke.pressed);
k->set_echo(ke.echo);
- k->set_scancode(ke.scancode);
+ k->set_keycode(ke.keycode);
+ k->set_physical_keycode(ke.physical_keycode);
k->set_unicode(ke.unicode);
push_input(k);
} else {
// IME input
- if ((i == 0 && ke.scancode == 0) || (i > 0 && key_event_buffer[i - 1].scancode == 0)) {
+ if ((i == 0 && ke.keycode == 0) || (i > 0 && key_event_buffer[i - 1].keycode == 0)) {
k.instance();
get_key_modifier_state(ke.osx_state, k);
k->set_pressed(ke.pressed);
k->set_echo(ke.echo);
- k->set_scancode(0);
+ k->set_keycode(0);
+ k->set_physical_keycode(0);
k->set_unicode(ke.unicode);
push_input(k);
}
- if (ke.scancode != 0) {
+ if (ke.keycode != 0) {
k.instance();
get_key_modifier_state(ke.osx_state, k);
k->set_pressed(ke.pressed);
k->set_echo(ke.echo);
- k->set_scancode(ke.scancode);
+ k->set_keycode(ke.keycode);
+ k->set_physical_keycode(ke.physical_keycode);
- if (i + 1 < key_event_pos && key_event_buffer[i + 1].scancode == 0) {
+ if (i + 1 < key_event_pos && key_event_buffer[i + 1].keycode == 0) {
k->set_unicode(key_event_buffer[i + 1].unicode);
}
@@ -2917,7 +2933,7 @@ void OS_OSX::run() {
quit = true;
}
} @catch (NSException *exception) {
- ERR_PRINTS("NSException: " + String([exception reason].UTF8String));
+ ERR_PRINT("NSException: " + String([exception reason].UTF8String));
}
};
@@ -2955,25 +2971,13 @@ String OS_OSX::get_joy_guid(int p_device) const {
return input->get_joy_guid_remapped(p_device);
}
-OS::PowerState OS_OSX::get_power_state() {
- return power_manager->get_power_state();
-}
-
-int OS_OSX::get_power_seconds_left() {
- return power_manager->get_power_seconds_left();
-}
-
-int OS_OSX::get_power_percent_left() {
- return power_manager->get_power_percent_left();
-}
-
Error OS_OSX::move_to_trash(const String &p_path) {
NSFileManager *fm = [NSFileManager defaultManager];
NSURL *url = [NSURL fileURLWithPath:@(p_path.utf8().get_data())];
NSError *err;
if (![fm trashItemAtURL:url resultingItemURL:nil error:&err]) {
- ERR_PRINTS("trashItemAtURL error: " + String(err.localizedDescription.UTF8String));
+ ERR_PRINT("trashItemAtURL error: " + String(err.localizedDescription.UTF8String));
return FAILED;
}
@@ -2981,11 +2985,12 @@ Error OS_OSX::move_to_trash(const String &p_path) {
}
void OS_OSX::_set_use_vsync(bool p_enable) {
- CGLContextObj ctx = CGLGetCurrentContext();
- if (ctx) {
- GLint swapInterval = p_enable ? 1 : 0;
- CGLSetParameter(ctx, kCGLCPSwapInterval, &swapInterval);
+#if defined(OPENGL_ENABLED)
+ if (video_driver_index == VIDEO_DRIVER_GLES2) {
+ if (context_gles2)
+ context_gles2->set_use_vsync(p_enable);
}
+#endif
}
OS_OSX *OS_OSX::singleton = NULL;
@@ -3007,16 +3012,6 @@ OS_OSX::OS_OSX() {
CGEventSourceSetLocalEventsSuppressionInterval(eventSource, 0.0);
- /*
- if (pthread_key_create(&_Godot.nsgl.current, NULL) != 0) {
- _GodotInputError(Godot_PLATFORM_ERROR, "NSGL: Failed to create context TLS");
- return GL_FALSE;
- }
-*/
-
- framework = CFBundleGetBundleWithIdentifier(CFSTR("com.apple.opengl"));
- ERR_FAIL_COND(!framework);
-
// Implicitly create shared NSApplication instance
[GodotApplication sharedApplication];
diff --git a/platform/osx/platform_config.h b/platform/osx/platform_config.h
index 046512ae84..155f37ed55 100644
--- a/platform/osx/platform_config.h
+++ b/platform/osx/platform_config.h
@@ -30,6 +30,5 @@
#include <alloca.h>
-#define GLES3_INCLUDE_H "thirdparty/glad/glad/glad.h"
#define GLES2_INCLUDE_H "thirdparty/glad/glad/glad.h"
#define PTHREAD_RENAME_SELF
diff --git a/platform/osx/power_osx.cpp b/platform/osx/power_osx.cpp
deleted file mode 100644
index 6d7667c5e8..0000000000
--- a/platform/osx/power_osx.cpp
+++ /dev/null
@@ -1,252 +0,0 @@
-/*************************************************************************/
-/* power_osx.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. */
-/*************************************************************************/
-
-/*
-Adapted from corresponding SDL 2.0 code.
-*/
-
-/*
- Simple DirectMedia Layer
- Copyright (C) 1997-2017 Sam Lantinga <slouken@libsdl.org>
-
- This software is provided 'as-is', without any express or implied
- warranty. In no event will the authors be held liable for any damages
- arising from the use of this software.
-
- Permission is granted to anyone to use this software for any purpose,
- including commercial applications, and to alter it and redistribute it
- freely, subject to the following restrictions:
-
- 1. The origin of this software must not be misrepresented; you must not
- claim that you wrote the original software. If you use this software
- in a product, an acknowledgment in the product documentation would be
- appreciated but is not required.
- 2. Altered source versions must be plainly marked as such, and must not be
- misrepresented as being the original software.
- 3. This notice may not be removed or altered from any source distribution.
-*/
-
-#include "power_osx.h"
-
-#include <CoreFoundation/CoreFoundation.h>
-#include <IOKit/ps/IOPSKeys.h>
-#include <IOKit/ps/IOPowerSources.h>
-
-// CODE CHUNK IMPORTED FROM SDL 2.0
-
-/* CoreFoundation is so verbose... */
-#define STRMATCH(a, b) (CFStringCompare(a, b, 0) == kCFCompareEqualTo)
-#define GETVAL(k, v) \
- CFDictionaryGetValueIfPresent(dict, CFSTR(k), (const void **)v)
-
-/* Note that AC power sources also include a laptop battery it is charging. */
-void PowerOSX::checkps(CFDictionaryRef dict, bool *have_ac, bool *have_battery, bool *charging) {
- CFStringRef strval; /* don't CFRelease() this. */
- CFBooleanRef bval;
- CFNumberRef numval;
- bool charge = false;
- bool choose = false;
- bool is_ac = false;
- int secs = -1;
- int maxpct = -1;
- int pct = -1;
-
- if ((GETVAL(kIOPSIsPresentKey, &bval)) && (bval == kCFBooleanFalse)) {
- return; /* nothing to see here. */
- }
-
- if (!GETVAL(kIOPSPowerSourceStateKey, &strval)) {
- return;
- }
-
- if (STRMATCH(strval, CFSTR(kIOPSACPowerValue))) {
- is_ac = *have_ac = true;
- } else if (!STRMATCH(strval, CFSTR(kIOPSBatteryPowerValue))) {
- return; /* not a battery? */
- }
-
- if ((GETVAL(kIOPSIsChargingKey, &bval)) && (bval == kCFBooleanTrue)) {
- charge = true;
- }
-
- if (GETVAL(kIOPSMaxCapacityKey, &numval)) {
- SInt32 val = -1;
- CFNumberGetValue(numval, kCFNumberSInt32Type, &val);
- if (val > 0) {
- *have_battery = true;
- maxpct = (int)val;
- }
- }
-
- if (GETVAL(kIOPSMaxCapacityKey, &numval)) {
- SInt32 val = -1;
- CFNumberGetValue(numval, kCFNumberSInt32Type, &val);
- if (val > 0) {
- *have_battery = true;
- maxpct = (int)val;
- }
- }
-
- if (GETVAL(kIOPSTimeToEmptyKey, &numval)) {
- SInt32 val = -1;
- CFNumberGetValue(numval, kCFNumberSInt32Type, &val);
-
- /* Mac OS X reports 0 minutes until empty if you're plugged in. :( */
- if ((val == 0) && (is_ac)) {
- val = -1; /* !!! FIXME: calc from timeToFull and capacity? */
- }
-
- secs = (int)val;
- if (secs > 0) {
- secs *= 60; /* value is in minutes, so convert to seconds. */
- }
- }
-
- if (GETVAL(kIOPSCurrentCapacityKey, &numval)) {
- SInt32 val = -1;
- CFNumberGetValue(numval, kCFNumberSInt32Type, &val);
- pct = (int)val;
- }
-
- if ((pct > 0) && (maxpct > 0)) {
- pct = (int)((((double)pct) / ((double)maxpct)) * 100.0);
- }
-
- if (pct > 100) {
- pct = 100;
- }
-
- /*
- * We pick the battery that claims to have the most minutes left.
- * (failing a report of minutes, we'll take the highest percent.)
- */
- if ((secs < 0) && (nsecs_left < 0)) {
- if ((pct < 0) && (percent_left < 0)) {
- choose = true; /* at least we know there's a battery. */
- }
- if (pct > percent_left) {
- choose = true;
- }
- } else if (secs > nsecs_left) {
- choose = true;
- }
-
- if (choose) {
- nsecs_left = secs;
- percent_left = pct;
- *charging = charge;
- }
-}
-
-#undef GETVAL
-#undef STRMATCH
-
-// CODE CHUNK IMPORTED FROM SDL 2.0
-bool PowerOSX::GetPowerInfo_MacOSX() {
- CFTypeRef blob = IOPSCopyPowerSourcesInfo();
-
- nsecs_left = -1;
- percent_left = -1;
- power_state = OS::POWERSTATE_UNKNOWN;
-
- if (blob != NULL) {
- CFArrayRef list = IOPSCopyPowerSourcesList(blob);
- if (list != NULL) {
- /* don't CFRelease() the list items, or dictionaries! */
- bool have_ac = false;
- bool have_battery = false;
- bool charging = false;
- const CFIndex total = CFArrayGetCount(list);
- CFIndex i;
- for (i = 0; i < total; i++) {
- CFTypeRef ps = (CFTypeRef)CFArrayGetValueAtIndex(list, i);
- CFDictionaryRef dict = IOPSGetPowerSourceDescription(blob, ps);
- if (dict != NULL) {
- checkps(dict, &have_ac, &have_battery, &charging);
- }
- }
-
- if (!have_battery) {
- power_state = OS::POWERSTATE_NO_BATTERY;
- } else if (charging) {
- power_state = OS::POWERSTATE_CHARGING;
- } else if (have_ac) {
- power_state = OS::POWERSTATE_CHARGED;
- } else {
- power_state = OS::POWERSTATE_ON_BATTERY;
- }
-
- CFRelease(list);
- }
- CFRelease(blob);
- }
-
- return true; /* always the definitive answer on Mac OS X. */
-}
-
-bool PowerOSX::UpdatePowerInfo() {
- if (GetPowerInfo_MacOSX()) {
- return true;
- }
- return false;
-}
-
-OS::PowerState PowerOSX::get_power_state() {
- if (UpdatePowerInfo()) {
- return power_state;
- } else {
- return OS::POWERSTATE_UNKNOWN;
- }
-}
-
-int PowerOSX::get_power_seconds_left() {
- if (UpdatePowerInfo()) {
- return nsecs_left;
- } else {
- return -1;
- }
-}
-
-int PowerOSX::get_power_percent_left() {
- if (UpdatePowerInfo()) {
- return percent_left;
- } else {
- return -1;
- }
-}
-
-PowerOSX::PowerOSX() :
- nsecs_left(-1),
- percent_left(-1),
- power_state(OS::POWERSTATE_UNKNOWN) {
-}
-
-PowerOSX::~PowerOSX() {
-}
diff --git a/platform/osx/semaphore_osx.cpp b/platform/osx/semaphore_osx.cpp
deleted file mode 100644
index e75f5103cc..0000000000
--- a/platform/osx/semaphore_osx.cpp
+++ /dev/null
@@ -1,107 +0,0 @@
-/*************************************************************************/
-/* semaphore_osx.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 "semaphore_osx.h"
-
-#include <fcntl.h>
-#include <unistd.h>
-
-void cgsem_init(cgsem_t *cgsem) {
- int flags, fd, i;
-
- pipe(cgsem->pipefd);
-
- /* Make the pipes FD_CLOEXEC to allow them to close should we call
- * execv on restart. */
- for (i = 0; i < 2; i++) {
- fd = cgsem->pipefd[i];
- flags = fcntl(fd, F_GETFD, 0);
- flags |= FD_CLOEXEC;
- fcntl(fd, F_SETFD, flags);
- }
-}
-
-void cgsem_post(cgsem_t *cgsem) {
- const char buf = 1;
-
- write(cgsem->pipefd[1], &buf, 1);
-}
-
-void cgsem_wait(cgsem_t *cgsem) {
- char buf;
-
- read(cgsem->pipefd[0], &buf, 1);
-}
-
-void cgsem_destroy(cgsem_t *cgsem) {
- close(cgsem->pipefd[1]);
- close(cgsem->pipefd[0]);
-}
-
-#include "core/os/memory.h"
-
-#include <errno.h>
-
-Error SemaphoreOSX::wait() {
-
- cgsem_wait(&sem);
- return OK;
-}
-
-Error SemaphoreOSX::post() {
-
- cgsem_post(&sem);
-
- return OK;
-}
-int SemaphoreOSX::get() const {
-
- return 0;
-}
-
-Semaphore *SemaphoreOSX::create_semaphore_osx() {
-
- return memnew(SemaphoreOSX);
-}
-
-void SemaphoreOSX::make_default() {
-
- create_func = create_semaphore_osx;
-}
-
-SemaphoreOSX::SemaphoreOSX() {
-
- cgsem_init(&sem);
-}
-
-SemaphoreOSX::~SemaphoreOSX() {
-
- cgsem_destroy(&sem);
-}
diff --git a/platform/osx/semaphore_osx.h b/platform/osx/vulkan_context_osx.h
index 2348c8efa6..619e91d1f6 100644
--- a/platform/osx/semaphore_osx.h
+++ b/platform/osx/vulkan_context_osx.h
@@ -1,5 +1,5 @@
/*************************************************************************/
-/* semaphore_osx.h */
+/* vulkan_context_osx.h */
/*************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
@@ -28,32 +28,21 @@
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/
-#ifndef SEMAPHORE_OSX_H
-#define SEMAPHORE_OSX_H
+#ifndef VULKAN_DEVICE_OSX_H
+#define VULKAN_DEVICE_OSX_H
-struct cgsem {
- int pipefd[2];
-};
-
-typedef struct cgsem cgsem_t;
-
-#include "core/os/semaphore.h"
+#include "drivers/vulkan/vulkan_context.h"
+#include <AppKit/AppKit.h>
-class SemaphoreOSX : public Semaphore {
+class VulkanContextOSX : public VulkanContext {
- mutable cgsem_t sem;
-
- static Semaphore *create_semaphore_osx();
+ virtual const char *_get_platform_surface_extension() const;
public:
- virtual Error wait();
- virtual Error post();
- virtual int get() const;
-
- static void make_default();
- SemaphoreOSX();
+ int window_create(id p_window, int p_width, int p_height);
- ~SemaphoreOSX();
+ VulkanContextOSX();
+ ~VulkanContextOSX();
};
-#endif // SEMAPHORE_OSX_H
+#endif // VULKAN_DEVICE_OSX_H
diff --git a/platform/iphone/power_iphone.cpp b/platform/osx/vulkan_context_osx.mm
index 36bac8da38..c132bd334a 100644
--- a/platform/iphone/power_iphone.cpp
+++ b/platform/osx/vulkan_context_osx.mm
@@ -1,5 +1,5 @@
/*************************************************************************/
-/* power_iphone.cpp */
+/* vulkan_context_osx.mm */
/*************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
@@ -28,43 +28,29 @@
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/
-#include "power_iphone.h"
+#include "vulkan_context_osx.h"
+#include <vulkan/vulkan_macos.h>
-bool PowerIphone::UpdatePowerInfo() {
- return false;
+const char *VulkanContextOSX::_get_platform_surface_extension() const {
+ return VK_MVK_MACOS_SURFACE_EXTENSION_NAME;
}
-OS::PowerState PowerIphone::get_power_state() {
- if (UpdatePowerInfo()) {
- return power_state;
- } else {
- return OS::POWERSTATE_UNKNOWN;
- }
-}
+int VulkanContextOSX::window_create(id p_window, int p_width, int p_height) {
-int PowerIphone::get_power_seconds_left() {
- if (UpdatePowerInfo()) {
- return nsecs_left;
- } else {
- return -1;
- }
-}
+ VkMacOSSurfaceCreateInfoMVK createInfo;
+ createInfo.sType = VK_STRUCTURE_TYPE_MACOS_SURFACE_CREATE_INFO_MVK;
+ createInfo.pNext = NULL;
+ createInfo.flags = 0;
+ createInfo.pView = p_window;
-int PowerIphone::get_power_percent_left() {
- if (UpdatePowerInfo()) {
- return percent_left;
- } else {
- return -1;
- }
+ VkSurfaceKHR surface;
+ VkResult err = vkCreateMacOSSurfaceMVK(_get_instance(), &createInfo, NULL, &surface);
+ ERR_FAIL_COND_V(err, -1);
+ return _window_create(surface, p_width, p_height);
}
-PowerIphone::PowerIphone() :
- nsecs_left(-1),
- percent_left(-1),
- power_state(OS::POWERSTATE_UNKNOWN) {
- // TODO Auto-generated constructor stub
+VulkanContextOSX::VulkanContextOSX() {
}
-PowerIphone::~PowerIphone() {
- // TODO Auto-generated destructor stub
+VulkanContextOSX::~VulkanContextOSX() {
}
diff --git a/platform/server/SCsub b/platform/server/SCsub
index f977275595..8364164114 100644
--- a/platform/server/SCsub
+++ b/platform/server/SCsub
@@ -10,10 +10,7 @@ common_server = [\
if sys.platform == "darwin":
common_server.append("#platform/osx/crash_handler_osx.mm")
- common_server.append("#platform/osx/power_osx.cpp")
- common_server.append("#platform/osx/semaphore_osx.cpp")
else:
common_server.append("#platform/x11/crash_handler_x11.cpp")
- common_server.append("#platform/x11/power_x11.cpp")
prog = env.add_program('#bin/godot_server', ['godot_server.cpp'] + common_server)
diff --git a/platform/server/detect.py b/platform/server/detect.py
index d82df77957..db9ba8d036 100644
--- a/platform/server/detect.py
+++ b/platform/server/detect.py
@@ -32,6 +32,7 @@ def get_opts():
return [
BoolVariable('use_llvm', 'Use the LLVM compiler', False),
BoolVariable('use_static_cpp', 'Link libgcc and libstdc++ statically for better portability', False),
+ BoolVariable('use_coverage', 'Test Godot coverage', False),
BoolVariable('use_ubsan', 'Use LLVM/GCC compiler undefined behavior sanitizer (UBSAN)', False),
BoolVariable('use_asan', 'Use LLVM/GCC compiler address sanitizer (ASAN))', False),
BoolVariable('use_lsan', 'Use LLVM/GCC compiler leak sanitizer (LSAN))', False),
@@ -99,6 +100,9 @@ def configure(env):
env.Append(CPPDEFINES=['TYPED_METHOD_BIND'])
env.extra_suffix = ".llvm" + env.extra_suffix
+ if env['use_coverage']:
+ env.Append(CCFLAGS=['-ftest-coverage', '-fprofile-arcs'])
+ env.Append(LINKFLAGS=['-ftest-coverage', '-fprofile-arcs'])
if env['use_ubsan'] or env['use_asan'] or env['use_lsan'] or env['use_tsan']:
env.extra_suffix += "s"
@@ -159,6 +163,10 @@ def configure(env):
sys.exit(255)
env.ParseConfig('pkg-config bullet --cflags --libs')
+ if False: # not env['builtin_assimp']:
+ # FIXME: Add min version check
+ env.ParseConfig('pkg-config assimp --cflags --libs')
+
if not env['builtin_enet']:
env.ParseConfig('pkg-config libenet --cflags --libs')
diff --git a/platform/server/os_server.cpp b/platform/server/os_server.cpp
index 498fd01b5e..3257ec261c 100644
--- a/platform/server/os_server.cpp
+++ b/platform/server/os_server.cpp
@@ -31,7 +31,6 @@
#include "os_server.h"
#include "core/print_string.h"
-#include "drivers/dummy/audio_driver_dummy.h"
#include "drivers/dummy/rasterizer_dummy.h"
#include "drivers/dummy/texture_loader_dummy.h"
#include "servers/visual/visual_server_raster.h"
@@ -69,10 +68,6 @@ void OS_Server::initialize_core() {
crash_handler.initialize();
OS_Unix::initialize_core();
-
-#ifdef __APPLE__
- SemaphoreOSX::make_default();
-#endif
}
Error OS_Server::initialize(const VideoMode &p_desired, int p_video_driver, int p_audio_driver) {
@@ -92,12 +87,6 @@ Error OS_Server::initialize(const VideoMode &p_desired, int p_video_driver, int
input = memnew(InputDefault);
-#ifdef __APPLE__
- power_manager = memnew(PowerOSX);
-#else
- power_manager = memnew(PowerX11);
-#endif
-
_ensure_user_data_dir();
resource_loader_dummy.instance();
@@ -117,8 +106,6 @@ void OS_Server::finalize() {
memdelete(input);
- memdelete(power_manager);
-
ResourceLoader::remove_resource_format_loader(resource_loader_dummy);
resource_loader_dummy.unref();
@@ -198,18 +185,6 @@ String OS_Server::get_name() const {
void OS_Server::move_window_to_foreground() {
}
-OS::PowerState OS_Server::get_power_state() {
- return power_manager->get_power_state();
-}
-
-int OS_Server::get_power_seconds_left() {
- return power_manager->get_power_seconds_left();
-}
-
-int OS_Server::get_power_percent_left() {
- return power_manager->get_power_percent_left();
-}
-
bool OS_Server::_check_internal_feature_support(const String &p_feature) {
return p_feature == "pc";
}
diff --git a/platform/server/os_server.h b/platform/server/os_server.h
index 46ca9cb6d1..7584293722 100644
--- a/platform/server/os_server.h
+++ b/platform/server/os_server.h
@@ -36,11 +36,9 @@
#include "main/input_default.h"
#ifdef __APPLE__
#include "platform/osx/crash_handler_osx.h"
-#include "platform/osx/power_osx.h"
#include "platform/osx/semaphore_osx.h"
#else
#include "platform/x11/crash_handler_x11.h"
-#include "platform/x11/power_x11.h"
#endif
#include "servers/audio_server.h"
#include "servers/visual/rasterizer.h"
@@ -63,12 +61,6 @@ class OS_Server : public OS_Unix {
InputDefault *input;
-#ifdef __APPLE__
- PowerOSX *power_manager;
-#else
- PowerX11 *power_manager;
-#endif
-
CrashHandler crash_handler;
int video_driver_index;
@@ -112,9 +104,6 @@ public:
void run();
- virtual OS::PowerState get_power_state();
- virtual int get_power_seconds_left();
- virtual int get_power_percent_left();
virtual bool _check_internal_feature_support(const String &p_feature);
virtual String get_config_path() const;
diff --git a/platform/uwp/SCsub b/platform/uwp/SCsub
index c14290f0c4..620d8c3c3a 100644
--- a/platform/uwp/SCsub
+++ b/platform/uwp/SCsub
@@ -7,7 +7,6 @@ files = [
'#platform/windows/key_mapping_windows.cpp',
'#platform/windows/windows_terminal_logger.cpp',
'joypad_uwp.cpp',
- 'power_uwp.cpp',
'context_egl_uwp.cpp',
'app.cpp',
'os_uwp.cpp',
diff --git a/platform/uwp/app.cpp b/platform/uwp/app.cpp
index a47fe96c1b..ccb4b43373 100644
--- a/platform/uwp/app.cpp
+++ b/platform/uwp/app.cpp
@@ -410,14 +410,16 @@ void App::key_event(Windows::UI::Core::CoreWindow ^ sender, bool p_pressed, Wind
ke.type = OS_UWP::KeyEvent::MessageType::KEY_EVENT_MESSAGE;
ke.unicode = 0;
- ke.scancode = KeyMappingWindows::get_keysym((unsigned int)key_args->VirtualKey);
+ ke.keycode = KeyMappingWindows::get_keysym((unsigned int)key_args->VirtualKey);
+ ke.physical_keycode = KeyMappingWindows::get_scansym((unsigned int)key_args->KeyStatus.ScanCode);
ke.echo = (!p_pressed && !key_args->KeyStatus.IsKeyReleased) || (p_pressed && key_args->KeyStatus.WasKeyDown);
} else {
ke.type = OS_UWP::KeyEvent::MessageType::CHAR_EVENT_MESSAGE;
ke.unicode = char_args->KeyCode;
- ke.scancode = 0;
+ ke.keycode = 0;
+ ke.physical_keycode = 0;
ke.echo = (!p_pressed && !char_args->KeyStatus.IsKeyReleased) || (p_pressed && char_args->KeyStatus.WasKeyDown);
}
diff --git a/platform/uwp/app.h b/platform/uwp/app.h
index 302d9759b3..b7265ad086 100644
--- a/platform/uwp/app.h
+++ b/platform/uwp/app.h
@@ -34,7 +34,6 @@
#include <wrl.h>
-// ANGLE doesn't provide a specific lib for GLES3, so we keep using GLES2
#include "GLES2/gl2.h"
#include "os_uwp.h"
diff --git a/platform/uwp/context_egl_uwp.h b/platform/uwp/context_egl_uwp.h
index 7a41685867..fa61cf50c6 100644
--- a/platform/uwp/context_egl_uwp.h
+++ b/platform/uwp/context_egl_uwp.h
@@ -45,7 +45,7 @@ class ContextEGL_UWP {
public:
enum Driver {
GLES_2_0,
- GLES_3_0,
+ VULKAN, // FIXME: Add Vulkan support.
};
private:
diff --git a/platform/uwp/export/export.cpp b/platform/uwp/export/export.cpp
index 57fb9004b8..533293387d 100644
--- a/platform/uwp/export/export.cpp
+++ b/platform/uwp/export/export.cpp
@@ -1004,7 +1004,7 @@ public:
return list;
}
- virtual Ref<Texture> get_logo() const {
+ virtual Ref<Texture2D> get_logo() const {
return logo;
}
@@ -1176,7 +1176,7 @@ public:
err += TTR("Invalid square 71x71 logo image dimensions (should be 71x71).") + "\n";
}
- if (!p_preset->get("images/square150x150_logo").is_zero() && !_valid_image((Object::cast_to<StreamTexture>((Object *)p_preset->get("images/square150x150_logo"))), 150, 0)) {
+ if (!p_preset->get("images/square150x150_logo").is_zero() && !_valid_image((Object::cast_to<StreamTexture>((Object *)p_preset->get("images/square150x150_logo"))), 150, 150)) {
valid = false;
err += TTR("Invalid square 150x150 logo image dimensions (should be 150x150).") + "\n";
}
@@ -1397,7 +1397,7 @@ public:
}
if (!FileAccess::exists(signtool_path)) {
- ERR_PRINTS("Could not find signtool executable at " + signtool_path + ", aborting.");
+ ERR_PRINT("Could not find signtool executable at " + signtool_path + ", aborting.");
return ERR_FILE_NOT_FOUND;
}
@@ -1418,12 +1418,12 @@ public:
}
if (!FileAccess::exists(cert_path)) {
- ERR_PRINTS("Could not find certificate file at " + cert_path + ", aborting.");
+ ERR_PRINT("Could not find certificate file at " + cert_path + ", aborting.");
return ERR_FILE_NOT_FOUND;
}
if (cert_alg < 0 || cert_alg > 2) {
- ERR_PRINTS("Invalid certificate algorithm " + itos(cert_alg) + ", aborting.");
+ ERR_PRINT("Invalid certificate algorithm " + itos(cert_alg) + ", aborting.");
return ERR_INVALID_DATA;
}
diff --git a/platform/uwp/os_uwp.cpp b/platform/uwp/os_uwp.cpp
index d5047b53ab..4ddb5463d0 100644
--- a/platform/uwp/os_uwp.cpp
+++ b/platform/uwp/os_uwp.cpp
@@ -36,7 +36,6 @@
#include "core/io/marshalls.h"
#include "core/project_settings.h"
#include "drivers/gles2/rasterizer_gles2.h"
-#include "drivers/gles3/rasterizer_gles3.h"
#include "drivers/unix/ip_unix.h"
#include "drivers/windows/dir_access_windows.h"
#include "drivers/windows/file_access_windows.h"
@@ -141,8 +140,6 @@ void OS_UWP::initialize_core() {
//RedirectIOToConsole();
ThreadUWP::make_default();
- SemaphoreWindows::make_default();
- MutexWindows::make_default();
RWLockWindows::make_default();
FileAccess::make_default<FileAccessWindows>(FileAccess::ACCESS_RESOURCES);
@@ -186,71 +183,33 @@ Error OS_UWP::initialize(const VideoMode &p_desired, int p_video_driver, int p_a
main_loop = NULL;
outside = true;
+ // FIXME: Hardcoded for now, add Vulkan support.
+ p_video_driver = VIDEO_DRIVER_GLES2;
ContextEGL_UWP::Driver opengl_api_type = ContextEGL_UWP::GLES_2_0;
- if (p_video_driver == VIDEO_DRIVER_GLES2) {
- opengl_api_type = ContextEGL_UWP::GLES_2_0;
- }
-
bool gl_initialization_error = false;
- gl_context = NULL;
- while (!gl_context) {
- gl_context = memnew(ContextEGL_UWP(window, opengl_api_type));
-
- if (gl_context->initialize() != OK) {
- memdelete(gl_context);
- gl_context = NULL;
-
- if (GLOBAL_GET("rendering/quality/driver/fallback_to_gles2")) {
- if (p_video_driver == VIDEO_DRIVER_GLES2) {
- gl_initialization_error = true;
- break;
- }
-
- p_video_driver = VIDEO_DRIVER_GLES2;
- opengl_api_type = ContextEGL_UWP::GLES_2_0;
- } else {
- gl_initialization_error = true;
- break;
- }
- }
- }
+ gl_context = memnew(ContextEGL_UWP(window, opengl_api_type));
- while (true) {
- if (opengl_api_type == ContextEGL_UWP::GLES_3_0) {
- if (RasterizerGLES3::is_viable() == OK) {
- RasterizerGLES3::register_config();
- RasterizerGLES3::make_current();
- break;
- } else {
- if (GLOBAL_GET("rendering/quality/driver/fallback_to_gles2")) {
- p_video_driver = VIDEO_DRIVER_GLES2;
- opengl_api_type = ContextEGL_UWP::GLES_2_0;
- continue;
- } else {
- gl_initialization_error = true;
- break;
- }
- }
- }
+ if (gl_context->initialize() != OK) {
+ memdelete(gl_context);
+ gl_context = NULL;
+ gl_initialization_error = true;
+ }
- if (opengl_api_type == ContextEGL_UWP::GLES_2_0) {
- if (RasterizerGLES2::is_viable() == OK) {
- RasterizerGLES2::register_config();
- RasterizerGLES2::make_current();
- break;
- } else {
- gl_initialization_error = true;
- break;
- }
+ if (opengl_api_type == ContextEGL_UWP::GLES_2_0) {
+ if (RasterizerGLES2::is_viable() == OK) {
+ RasterizerGLES2::register_config();
+ RasterizerGLES2::make_current();
+ } else {
+ gl_initialization_error = true;
}
}
if (gl_initialization_error) {
OS::get_singleton()->alert("Your video card driver does not support any of the supported OpenGL versions.\n"
"Please update your drivers or if you have a very old or integrated GPU upgrade it.",
- "Unable to initialize Video driver");
+ "Unable to initialize video driver");
return ERR_UNAVAILABLE;
}
@@ -310,8 +269,6 @@ Error OS_UWP::initialize(const VideoMode &p_desired, int p_video_driver, int p_a
AudioDriverManager::initialize(p_audio_driver);
- power_manager = memnew(PowerUWP);
-
managed_object->update_clipboard();
Clipboard::ContentChanged += ref new EventHandler<Platform::Object ^>(managed_object, &ManagedType::on_clipboard_changed);
@@ -647,7 +604,8 @@ void OS_UWP::process_key_events() {
key_event->set_shift(kev.shift);
key_event->set_control(kev.control);
key_event->set_echo(kev.echo);
- key_event->set_scancode(kev.scancode);
+ key_event->set_keycode(kev.keycode);
+ key_event->set_physical_keycode(kev.physical_keycode);
key_event->set_unicode(kev.unicode);
key_event->set_pressed(kev.pressed);
@@ -893,18 +851,6 @@ bool OS_UWP::_check_internal_feature_support(const String &p_feature) {
return p_feature == "pc";
}
-OS::PowerState OS_UWP::get_power_state() {
- return power_manager->get_power_state();
-}
-
-int OS_UWP::get_power_seconds_left() {
- return power_manager->get_power_seconds_left();
-}
-
-int OS_UWP::get_power_percent_left() {
- return power_manager->get_power_percent_left();
-}
-
OS_UWP::OS_UWP() {
key_event_pos = 0;
diff --git a/platform/uwp/os_uwp.h b/platform/uwp/os_uwp.h
index fb43ab382e..ac6e0f3dd5 100644
--- a/platform/uwp/os_uwp.h
+++ b/platform/uwp/os_uwp.h
@@ -39,7 +39,6 @@
#include "drivers/xaudio2/audio_driver_xaudio2.h"
#include "joypad_uwp.h"
#include "main/input_default.h"
-#include "power_uwp.h"
#include "servers/audio_server.h"
#include "servers/visual/rasterizer.h"
#include "servers/visual_server.h"
@@ -62,7 +61,8 @@ public:
bool alt, shift, control;
MessageType type;
bool pressed;
- unsigned int scancode;
+ unsigned int keycode;
+ unsigned int physical_keycode;
unsigned int unicode;
bool echo;
CorePhysicalKeyStatus status;
@@ -102,8 +102,6 @@ private:
AudioDriverXAudio2 audio_driver;
- PowerUWP *power_manager;
-
MouseMode mouse_mode;
bool alt_mem;
bool gr_mem;
@@ -254,10 +252,6 @@ public:
void input_event(const Ref<InputEvent> &p_event);
- virtual OS::PowerState get_power_state();
- virtual int get_power_seconds_left();
- virtual int get_power_percent_left();
-
void queue_key_event(KeyEvent &p_event);
OS_UWP();
diff --git a/platform/windows/SCsub b/platform/windows/SCsub
index 892d734734..8e94c7b35d 100644
--- a/platform/windows/SCsub
+++ b/platform/windows/SCsub
@@ -8,13 +8,13 @@ import platform_windows_builders
common_win = [
"godot_windows.cpp",
- "context_gl_windows.cpp",
"crash_handler_windows.cpp",
"os_windows.cpp",
"key_mapping_windows.cpp",
"joypad_windows.cpp",
- "power_windows.cpp",
- "windows_terminal_logger.cpp"
+ "windows_terminal_logger.cpp",
+ "vulkan_context_win.cpp",
+ "context_gl_windows.cpp"
]
res_file = 'godot_res.rc'
diff --git a/platform/windows/detect.py b/platform/windows/detect.py
index 500736bd3f..cc859c0339 100644
--- a/platform/windows/detect.py
+++ b/platform/windows/detect.py
@@ -1,6 +1,9 @@
import methods
import os
+# To match other platforms
+STACK_SIZE = 8388608
+
def is_active():
return True
@@ -207,7 +210,7 @@ def configure_msvc(env, manual_msvc_config):
else:
print("Missing environment variable: WindowsSdkDir")
- env.AppendUnique(CPPDEFINES = ['WINDOWS_ENABLED', 'OPENGL_ENABLED',
+ env.AppendUnique(CPPDEFINES = ['WINDOWS_ENABLED',
'WASAPI_ENABLED', 'WINMIDI_ENABLED',
'TYPED_METHOD_BIND',
'WIN32', 'MSVC',
@@ -219,10 +222,20 @@ def configure_msvc(env, manual_msvc_config):
## Libs
- LIBS = ['winmm', 'opengl32', 'dsound', 'kernel32', 'ole32', 'oleaut32',
+ LIBS = ['winmm', 'dsound', 'kernel32', 'ole32', 'oleaut32',
'user32', 'gdi32', 'IPHLPAPI', 'Shlwapi', 'wsock32', 'Ws2_32',
- 'shell32', 'advapi32', 'dinput8', 'dxguid', 'imm32', 'bcrypt','Avrt',
+ 'shell32', 'advapi32', 'dinput8', 'dxguid', 'imm32', 'bcrypt', 'Avrt',
'dwmapi']
+
+ env.AppendUnique(CPPDEFINES=['VULKAN_ENABLED'])
+ if not env['builtin_vulkan']:
+ LIBS += ['vulkan']
+ else:
+ LIBS += ['cfgmgr32']
+
+ #env.AppendUnique(CPPDEFINES = ['OPENGL_ENABLED'])
+ LIBS += ['opengl32']
+
env.Append(LINKFLAGS=[p + env["LIBSUFFIX"] for p in LIBS])
if manual_msvc_config:
@@ -249,6 +262,8 @@ def configure_msvc(env, manual_msvc_config):
env['BUILDERS']['ProgramOriginal'] = env['BUILDERS']['Program']
env['BUILDERS']['Program'] = methods.precious_program
+ env.AppendUnique(LINKFLAGS=['/STACK:' + str(STACK_SIZE)])
+
def configure_mingw(env):
# Workaround for MinGW. See:
# http://www.scons.org/wiki/LongCmdLinesOnWin32
@@ -293,12 +308,7 @@ def configure_mingw(env):
## Compiler configuration
- if (os.name == "nt"):
- # Force splitting libmodules.a in multiple chunks to work around
- # issues reaching the linker command line size limit, which also
- # seem to induce huge slowdown for 'ar' (GH-30892).
- env['split_libmodules'] = True
- else:
+ if os.name != "nt":
env["PROGSUFFIX"] = env["PROGSUFFIX"] + ".exe" # for linux cross-compilation
if (env["bits"] == "default"):
@@ -346,13 +356,25 @@ def configure_mingw(env):
env.Append(CCFLAGS=['-flto'])
env.Append(LINKFLAGS=['-flto'])
+ env.Append(LINKFLAGS=['-Wl,--stack,' + str(STACK_SIZE)])
## Compile flags
env.Append(CCFLAGS=['-mwindows'])
- env.Append(CPPDEFINES=['WINDOWS_ENABLED', 'OPENGL_ENABLED', 'WASAPI_ENABLED', 'WINMIDI_ENABLED'])
+
+ env.Append(CPPDEFINES=['WINDOWS_ENABLED', 'WASAPI_ENABLED', 'WINMIDI_ENABLED'])
env.Append(CPPDEFINES=[('WINVER', env['target_win_version']), ('_WIN32_WINNT', env['target_win_version'])])
- env.Append(LIBS=['mingw32', 'opengl32', 'dsound', 'ole32', 'd3d9', 'winmm', 'gdi32', 'iphlpapi', 'shlwapi', 'wsock32', 'ws2_32', 'kernel32', 'oleaut32', 'dinput8', 'dxguid', 'ksuser', 'imm32', 'bcrypt', 'avrt', 'uuid', 'dwmapi'])
+ env.Append(LIBS=['mingw32', 'dsound', 'ole32', 'd3d9', 'winmm', 'gdi32', 'iphlpapi', 'shlwapi', 'wsock32', 'ws2_32', 'kernel32', 'oleaut32', 'dinput8', 'dxguid', 'ksuser', 'imm32', 'bcrypt', 'avrt', 'uuid', 'dwmapi'])
+
+ env.Append(CPPDEFINES=['VULKAN_ENABLED'])
+ if not env['builtin_vulkan']:
+ env.Append(LIBS=['vulkan'])
+ else:
+ env.Append(LIBS=['cfgmgr32'])
+
+ ## TODO !!! Reenable when OpenGLES Rendering Device is implemented !!!
+ #env.Append(CPPDEFINES=['OPENGL_ENABLED'])
+ env.Append(LIBS=['opengl32'])
env.Append(CPPDEFINES=['MINGW_ENABLED', ('MINGW_HAS_SECURE_API', 1)])
diff --git a/platform/windows/export/export.cpp b/platform/windows/export/export.cpp
index 34d66ecd79..78a3fc8f79 100644
--- a/platform/windows/export/export.cpp
+++ b/platform/windows/export/export.cpp
@@ -85,7 +85,7 @@ void EditorExportPlatformWindows::get_export_options(List<ExportOption> *r_optio
r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "codesign/timestamp_server_url"), ""));
r_options->push_back(ExportOption(PropertyInfo(Variant::INT, "codesign/digest_algorithm", PROPERTY_HINT_ENUM, "SHA1,SHA256"), 1));
r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "codesign/description"), ""));
- r_options->push_back(ExportOption(PropertyInfo(Variant::POOL_STRING_ARRAY, "codesign/custom_options"), PoolStringArray()));
+ r_options->push_back(ExportOption(PropertyInfo(Variant::PACKED_STRING_ARRAY, "codesign/custom_options"), PackedStringArray()));
r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "application/icon", PROPERTY_HINT_FILE, "*.ico"), ""));
r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "application/file_version", PROPERTY_HINT_PLACEHOLDER_TEXT, "1.0.0"), ""));
@@ -105,7 +105,7 @@ void EditorExportPlatformWindows::_rcedit_add_data(const Ref<EditorExportPreset>
}
if (!FileAccess::exists(rcedit_path)) {
- ERR_PRINTS("Could not find rcedit executable at " + rcedit_path + ", no icon or app information data will be included.");
+ ERR_PRINT("Could not find rcedit executable at " + rcedit_path + ", no icon or app information data will be included.");
return;
}
@@ -114,7 +114,7 @@ void EditorExportPlatformWindows::_rcedit_add_data(const Ref<EditorExportPreset>
String wine_path = EditorSettings::get_singleton()->get("export/windows/wine");
if (wine_path != String() && !FileAccess::exists(wine_path)) {
- ERR_PRINTS("Could not find wine executable at " + wine_path + ", no icon or app information data will be included.");
+ ERR_PRINT("Could not find wine executable at " + wine_path + ", no icon or app information data will be included.");
return;
}
@@ -188,7 +188,7 @@ Error EditorExportPlatformWindows::_code_sign(const Ref<EditorExportPreset> &p_p
#ifdef WINDOWS_ENABLED
String signtool_path = EditorSettings::get_singleton()->get("export/windows/signtool");
if (signtool_path != String() && !FileAccess::exists(signtool_path)) {
- ERR_PRINTS("Could not find signtool executable at " + signtool_path + ", aborting.");
+ ERR_PRINT("Could not find signtool executable at " + signtool_path + ", aborting.");
return ERR_FILE_NOT_FOUND;
}
if (signtool_path == String()) {
@@ -197,7 +197,7 @@ Error EditorExportPlatformWindows::_code_sign(const Ref<EditorExportPreset> &p_p
#else
String signtool_path = EditorSettings::get_singleton()->get("export/windows/osslsigncode");
if (signtool_path != String() && !FileAccess::exists(signtool_path)) {
- ERR_PRINTS("Could not find osslsigncode executable at " + signtool_path + ", aborting.");
+ ERR_PRINT("Could not find osslsigncode executable at " + signtool_path + ", aborting.");
return ERR_FILE_NOT_FOUND;
}
if (signtool_path == String()) {
@@ -297,7 +297,7 @@ Error EditorExportPlatformWindows::_code_sign(const Ref<EditorExportPreset> &p_p
}
//user options
- PoolStringArray user_args = p_preset->get("codesign/custom_options");
+ PackedStringArray user_args = p_preset->get("codesign/custom_options");
for (int i = 0; i < user_args.size(); i++) {
String user_arg = user_args[i].strip_edges();
if (!user_arg.empty()) {
diff --git a/platform/windows/key_mapping_windows.cpp b/platform/windows/key_mapping_windows.cpp
index c76b31ca9c..da63e92622 100644
--- a/platform/windows/key_mapping_windows.cpp
+++ b/platform/windows/key_mapping_windows.cpp
@@ -238,6 +238,104 @@ VK_PA1 (0xFD)
VK_OEM_CLEAR (0xFE)
*/
+static _WinTranslatePair _scancode_to_keycode[] = {
+
+ { KEY_ESCAPE, 0x01 },
+ { KEY_1, 0x02 },
+ { KEY_2, 0x03 },
+ { KEY_3, 0x04 },
+ { KEY_4, 0x05 },
+ { KEY_5, 0x06 },
+ { KEY_6, 0x07 },
+ { KEY_7, 0x08 },
+ { KEY_8, 0x09 },
+ { KEY_9, 0x0A },
+ { KEY_0, 0x0B },
+ { KEY_MINUS, 0x0C },
+ { KEY_EQUAL, 0x0D },
+ { KEY_BACKSPACE, 0x0E },
+ { KEY_TAB, 0x0F },
+ { KEY_Q, 0x10 },
+ { KEY_W, 0x11 },
+ { KEY_E, 0x12 },
+ { KEY_R, 0x13 },
+ { KEY_T, 0x14 },
+ { KEY_Y, 0x15 },
+ { KEY_U, 0x16 },
+ { KEY_I, 0x17 },
+ { KEY_O, 0x18 },
+ { KEY_P, 0x19 },
+ { KEY_BRACELEFT, 0x1A },
+ { KEY_BRACERIGHT, 0x1B },
+ { KEY_ENTER, 0x1C },
+ { KEY_CONTROL, 0x1D },
+ { KEY_A, 0x1E },
+ { KEY_S, 0x1F },
+ { KEY_D, 0x20 },
+ { KEY_F, 0x21 },
+ { KEY_G, 0x22 },
+ { KEY_H, 0x23 },
+ { KEY_J, 0x24 },
+ { KEY_K, 0x25 },
+ { KEY_L, 0x26 },
+ { KEY_SEMICOLON, 0x27 },
+ { KEY_APOSTROPHE, 0x28 },
+ { KEY_QUOTELEFT, 0x29 },
+ { KEY_SHIFT, 0x2A },
+ { KEY_BACKSLASH, 0x2B },
+ { KEY_Z, 0x2C },
+ { KEY_X, 0x2D },
+ { KEY_C, 0x2E },
+ { KEY_V, 0x2F },
+ { KEY_B, 0x30 },
+ { KEY_N, 0x31 },
+ { KEY_M, 0x32 },
+ { KEY_COMMA, 0x33 },
+ { KEY_PERIOD, 0x34 },
+ { KEY_SLASH, 0x35 },
+ { KEY_SHIFT, 0x36 },
+ { KEY_PRINT, 0x37 },
+ { KEY_ALT, 0x38 },
+ { KEY_SPACE, 0x39 },
+ { KEY_CAPSLOCK, 0x3A },
+ { KEY_F1, 0x3B },
+ { KEY_F2, 0x3C },
+ { KEY_F3, 0x3D },
+ { KEY_F4, 0x3E },
+ { KEY_F5, 0x3F },
+ { KEY_F6, 0x40 },
+ { KEY_F7, 0x41 },
+ { KEY_F8, 0x42 },
+ { KEY_F9, 0x43 },
+ { KEY_F10, 0x44 },
+ { KEY_NUMLOCK, 0x45 },
+ { KEY_SCROLLLOCK, 0x46 },
+ { KEY_HOME, 0x47 },
+ { KEY_UP, 0x48 },
+ { KEY_PAGEUP, 0x49 },
+ { KEY_KP_SUBTRACT, 0x4A },
+ { KEY_LEFT, 0x4B },
+ { KEY_KP_5, 0x4C },
+ { KEY_RIGHT, 0x4D },
+ { KEY_KP_ADD, 0x4E },
+ { KEY_END, 0x4F },
+ { KEY_DOWN, 0x50 },
+ { KEY_PAGEDOWN, 0x51 },
+ { KEY_INSERT, 0x52 },
+ { KEY_DELETE, 0x53 },
+ //{ KEY_???, 0x56 }, //NON US BACKSLASH
+ { KEY_F11, 0x57 },
+ { KEY_F12, 0x58 },
+ { KEY_META, 0x5B },
+ { KEY_META, 0x5C },
+ { KEY_MENU, 0x5D },
+ { KEY_F13, 0x64 },
+ { KEY_F14, 0x65 },
+ { KEY_F15, 0x66 },
+ { KEY_F16, 0x67 },
+ { KEY_UNKNOWN, 0 }
+};
+
unsigned int KeyMappingWindows::get_keysym(unsigned int p_code) {
for (int i = 0; _vk_to_keycode[i].keysym != KEY_UNKNOWN; i++) {
@@ -251,3 +349,69 @@ unsigned int KeyMappingWindows::get_keysym(unsigned int p_code) {
return KEY_UNKNOWN;
}
+
+unsigned int KeyMappingWindows::get_scansym(unsigned int p_code, bool p_extended) {
+ unsigned int keycode = KEY_UNKNOWN;
+ for (int i = 0; _scancode_to_keycode[i].keysym != KEY_UNKNOWN; i++) {
+
+ if (_scancode_to_keycode[i].keycode == p_code) {
+ keycode = _scancode_to_keycode[i].keysym;
+ break;
+ }
+ }
+
+ if (p_extended) {
+ switch (keycode) {
+ case KEY_ENTER: {
+ keycode = KEY_KP_ENTER;
+ } break;
+ case KEY_SLASH: {
+ keycode = KEY_KP_DIVIDE;
+ } break;
+ case KEY_CAPSLOCK: {
+ keycode = KEY_KP_ADD;
+ } break;
+ }
+ } else {
+ switch (keycode) {
+ case KEY_NUMLOCK: {
+ keycode = KEY_PAUSE;
+ } break;
+ case KEY_HOME: {
+ keycode = KEY_KP_7;
+ } break;
+ case KEY_UP: {
+ keycode = KEY_KP_8;
+ } break;
+ case KEY_PAGEUP: {
+ keycode = KEY_KP_9;
+ } break;
+ case KEY_LEFT: {
+ keycode = KEY_KP_4;
+ } break;
+ case KEY_RIGHT: {
+ keycode = KEY_KP_6;
+ } break;
+ case KEY_END: {
+ keycode = KEY_KP_1;
+ } break;
+ case KEY_DOWN: {
+ keycode = KEY_KP_2;
+ } break;
+ case KEY_PAGEDOWN: {
+ keycode = KEY_KP_3;
+ } break;
+ case KEY_INSERT: {
+ keycode = KEY_KP_0;
+ } break;
+ case KEY_DELETE: {
+ keycode = KEY_KP_PERIOD;
+ } break;
+ case KEY_PRINT: {
+ keycode = KEY_KP_MULTIPLY;
+ } break;
+ }
+ }
+
+ return keycode;
+}
diff --git a/platform/windows/key_mapping_windows.h b/platform/windows/key_mapping_windows.h
index 0f9bdecde1..3361ad397f 100644
--- a/platform/windows/key_mapping_windows.h
+++ b/platform/windows/key_mapping_windows.h
@@ -43,6 +43,7 @@ class KeyMappingWindows {
public:
static unsigned int get_keysym(unsigned int p_code);
+ static unsigned int get_scansym(unsigned int p_code, bool p_extended);
};
#endif // KEY_MAPPING_WINDOWS_H
diff --git a/platform/windows/os_windows.cpp b/platform/windows/os_windows.cpp
index a6977a7a86..041a5bffa6 100755..100644
--- a/platform/windows/os_windows.cpp
+++ b/platform/windows/os_windows.cpp
@@ -33,15 +33,22 @@
#include "os_windows.h"
+#include "core/debugger/engine_debugger.h"
+#include "core/debugger/script_debugger.h"
#include "core/io/marshalls.h"
#include "core/version_generated.gen.h"
+
+#if defined(OPENGL_ENABLED)
#include "drivers/gles2/rasterizer_gles2.h"
-#include "drivers/gles3/rasterizer_gles3.h"
+#endif
+
+#if defined(VULKAN_ENABLED)
+#include "servers/visual/rasterizer_rd/rasterizer_rd.h"
+#endif
+
#include "drivers/windows/dir_access_windows.h"
#include "drivers/windows/file_access_windows.h"
-#include "drivers/windows/mutex_windows.h"
#include "drivers/windows/rw_lock_windows.h"
-#include "drivers/windows/semaphore_windows.h"
#include "drivers/windows/thread_windows.h"
#include "joypad_windows.h"
#include "lang_table.h"
@@ -188,13 +195,13 @@ void RedirectIOToConsole() {
}
BOOL WINAPI HandlerRoutine(_In_ DWORD dwCtrlType) {
- if (ScriptDebugger::get_singleton() == NULL)
+ if (!EngineDebugger::is_active())
return FALSE;
switch (dwCtrlType) {
case CTRL_C_EVENT:
- ScriptDebugger::get_singleton()->set_depth(-1);
- ScriptDebugger::get_singleton()->set_lines_left(1);
+ EngineDebugger::get_script_debugger()->set_depth(-1);
+ EngineDebugger::get_script_debugger()->set_lines_left(1);
return TRUE;
default:
return FALSE;
@@ -221,8 +228,6 @@ void OS_Windows::initialize_core() {
borderless = false;
ThreadWindows::make_default();
- SemaphoreWindows::make_default();
- MutexWindows::make_default();
RWLockWindows::make_default();
FileAccess::make_default<FileAccessWindows>(FileAccess::ACCESS_RESOURCES);
@@ -701,7 +706,7 @@ LRESULT OS_Windows::WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
break;
}
}
- FALLTHROUGH;
+ [[fallthrough]];
case WM_MBUTTONDOWN:
case WM_MBUTTONUP:
case WM_RBUTTONDOWN:
@@ -893,6 +898,11 @@ LRESULT OS_Windows::WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
preserve_window_size = false;
set_window_size(Size2(video_mode.width, video_mode.height));
}
+#if defined(VULKAN_ENABLED)
+ if (video_driver_index == VIDEO_DRIVER_VULKAN) {
+ context_vulkan->window_resize(0, video_mode.width, video_mode.height);
+ }
+#endif
}
if (wParam == SIZE_MAXIMIZED) {
@@ -971,7 +981,7 @@ LRESULT OS_Windows::WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
if (wParam==VK_WIN) TODO wtf is this?
meta_mem=uMsg==WM_KEYDOWN;
*/
- FALLTHROUGH;
+ [[fallthrough]];
}
case WM_CHAR: {
@@ -1122,7 +1132,8 @@ void OS_Windows::process_key_events() {
k->set_control(ke.control);
k->set_metakey(ke.meta);
k->set_pressed(true);
- k->set_scancode(KeyMappingWindows::get_keysym(ke.wParam));
+ k->set_keycode(KeyMappingWindows::get_keysym(ke.wParam));
+ k->set_physical_keycode(KeyMappingWindows::get_scansym((ke.lParam >> 16) & 0xFF, ke.lParam & (1 << 24)));
k->set_unicode(ke.wParam);
if (k->get_unicode() && gr_mem) {
k->set_alt(false);
@@ -1152,11 +1163,13 @@ void OS_Windows::process_key_events() {
if ((ke.lParam & (1 << 24)) && (ke.wParam == VK_RETURN)) {
// Special case for Numpad Enter key
- k->set_scancode(KEY_KP_ENTER);
+ k->set_keycode(KEY_KP_ENTER);
} else {
- k->set_scancode(KeyMappingWindows::get_keysym(ke.wParam));
+ k->set_keycode(KeyMappingWindows::get_keysym(ke.wParam));
}
+ k->set_physical_keycode(KeyMappingWindows::get_scansym((ke.lParam >> 16) & 0xFF, ke.lParam & (1 << 24)));
+
if (i + 1 < key_event_pos && key_event_buffer[i + 1].uMsg == WM_CHAR) {
k->set_unicode(key_event_buffer[i + 1].wParam);
}
@@ -1416,78 +1429,58 @@ Error OS_Windows::initialize(const VideoMode &p_desired, int p_video_driver, int
SetWindowPos(hWnd, video_mode.always_on_top ? HWND_TOPMOST : HWND_NOTOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE);
}
-#if defined(OPENGL_ENABLED)
-
- bool gles3_context = true;
- if (p_video_driver == VIDEO_DRIVER_GLES2) {
- gles3_context = false;
- }
-
- bool editor = Engine::get_singleton()->is_editor_hint();
- bool gl_initialization_error = false;
-
- gl_context = NULL;
- while (!gl_context) {
- gl_context = memnew(ContextGL_Windows(hWnd, gles3_context));
+ //!!!!!!!!!!!!!!!!!!!!!!!!!!
+ //TODO - do Vulkan and GLES2 support checks, driver selection and fallback
+ video_driver_index = p_video_driver;
+ print_verbose("Driver: " + String(get_video_driver_name(video_driver_index)) + " [" + itos(video_driver_index) + "]");
+ //!!!!!!!!!!!!!!!!!!!!!!!!!!
- if (gl_context->initialize() != OK) {
- memdelete(gl_context);
- gl_context = NULL;
+ // Init context and rendering device
+#if defined(OPENGL_ENABLED)
+ if (video_driver_index == VIDEO_DRIVER_GLES2) {
- if (GLOBAL_GET("rendering/quality/driver/fallback_to_gles2") || editor) {
- if (p_video_driver == VIDEO_DRIVER_GLES2) {
- gl_initialization_error = true;
- break;
- }
+ context_gles2 = memnew(ContextGL_Windows(hWnd, false));
- p_video_driver = VIDEO_DRIVER_GLES2;
- gles3_context = false;
- } else {
- gl_initialization_error = true;
- break;
- }
+ if (context_gles2->initialize() != OK) {
+ memdelete(context_gles2);
+ context_gles2 = NULL;
+ ERR_FAIL_V(ERR_UNAVAILABLE);
}
- }
- while (true) {
- if (gles3_context) {
- if (RasterizerGLES3::is_viable() == OK) {
- RasterizerGLES3::register_config();
- RasterizerGLES3::make_current();
- break;
- } else {
- if (GLOBAL_GET("rendering/quality/driver/fallback_to_gles2") || editor) {
- p_video_driver = VIDEO_DRIVER_GLES2;
- gles3_context = false;
- continue;
- } else {
- gl_initialization_error = true;
- break;
- }
- }
+ context_gles2->set_use_vsync(video_mode.use_vsync);
+ set_vsync_via_compositor(video_mode.vsync_via_compositor);
+
+ if (RasterizerGLES2::is_viable() == OK) {
+ RasterizerGLES2::register_config();
+ RasterizerGLES2::make_current();
} else {
- if (RasterizerGLES2::is_viable() == OK) {
- RasterizerGLES2::register_config();
- RasterizerGLES2::make_current();
- break;
- } else {
- gl_initialization_error = true;
- break;
- }
+ memdelete(context_gles2);
+ context_gles2 = NULL;
+ ERR_FAIL_V(ERR_UNAVAILABLE);
}
}
+#endif
+#if defined(VULKAN_ENABLED)
+ if (video_driver_index == VIDEO_DRIVER_VULKAN) {
+
+ context_vulkan = memnew(VulkanContextWindows);
+ if (context_vulkan->initialize() != OK) {
+ memdelete(context_vulkan);
+ context_vulkan = NULL;
+ ERR_FAIL_V(ERR_UNAVAILABLE);
+ }
+ if (context_vulkan->window_create(hWnd, hInstance, get_video_mode().width, get_video_mode().height) == -1) {
+ memdelete(context_vulkan);
+ context_vulkan = NULL;
+ ERR_FAIL_V(ERR_UNAVAILABLE);
+ }
- if (gl_initialization_error) {
- OS::get_singleton()->alert("Your video card driver does not support any of the supported OpenGL versions.\n"
- "Please update your drivers or if you have a very old or integrated GPU upgrade it.",
- "Unable to initialize Video driver");
- return ERR_UNAVAILABLE;
- }
-
- video_driver_index = p_video_driver;
+ //temporary
+ rendering_device_vulkan = memnew(RenderingDeviceVulkan);
+ rendering_device_vulkan->initialize(context_vulkan);
- gl_context->set_use_vsync(video_mode.use_vsync);
- set_vsync_via_compositor(video_mode.vsync_via_compositor);
+ RasterizerRD::make_current();
+ }
#endif
visual_server = memnew(VisualServerRaster);
@@ -1500,8 +1493,6 @@ Error OS_Windows::initialize(const VideoMode &p_desired, int p_video_driver, int
input = memnew(InputDefault);
joypad = memnew(JoypadWindows(input, &hWnd));
- power_manager = memnew(PowerWindows);
-
AudioDriverManager::initialize(p_audio_driver);
TRACKMOUSEEVENT tme;
@@ -1660,9 +1651,25 @@ void OS_Windows::finalize() {
cursors_cache.clear();
visual_server->finish();
memdelete(visual_server);
-#ifdef OPENGL_ENABLED
- if (gl_context)
- memdelete(gl_context);
+
+#if defined(OPENGL_ENABLED)
+ if (video_driver_index == VIDEO_DRIVER_GLES2) {
+
+ if (context_gles2)
+ memdelete(context_gles2);
+ }
+#endif
+#if defined(VULKAN_ENABLED)
+ if (video_driver_index == VIDEO_DRIVER_VULKAN) {
+
+ if (rendering_device_vulkan) {
+ rendering_device_vulkan->finalize();
+ memdelete(rendering_device_vulkan);
+ }
+
+ if (context_vulkan)
+ memdelete(context_vulkan);
+ }
#endif
if (user_proc) {
@@ -1964,6 +1971,11 @@ void OS_Windows::set_window_size(const Size2 p_size) {
video_mode.width = w;
video_mode.height = h;
+#if defined(VULKAN_ENABLED)
+ if (video_driver_index == VIDEO_DRIVER_VULKAN) {
+ context_vulkan->window_resize(0, video_mode.width, video_mode.height);
+ }
+#endif
if (video_mode.fullscreen) {
return;
@@ -2506,7 +2518,7 @@ void OS_Windows::set_custom_mouse_cursor(const RES &p_cursor, CursorShape p_shap
if (p_cursor.is_valid()) {
- Map<CursorShape, Vector<Variant> >::Element *cursor_c = cursors_cache.find(p_shape);
+ Map<CursorShape, Vector<Variant>>::Element *cursor_c = cursors_cache.find(p_shape);
if (cursor_c) {
if (cursor_c->get()[0] == p_cursor && cursor_c->get()[1] == p_hotspot) {
@@ -2517,7 +2529,7 @@ void OS_Windows::set_custom_mouse_cursor(const RES &p_cursor, CursorShape p_shap
cursors_cache.erase(p_shape);
}
- Ref<Texture> texture = p_cursor;
+ Ref<Texture2D> texture = p_cursor;
Ref<AtlasTexture> atlas_texture = p_cursor;
Ref<Image> image;
Size2 texture_size;
@@ -2556,7 +2568,6 @@ void OS_Windows::set_custom_mouse_cursor(const RES &p_cursor, CursorShape p_shap
// Create the BITMAP with alpha channel
COLORREF *buffer = (COLORREF *)memalloc(sizeof(COLORREF) * image_size);
- image->lock();
for (UINT index = 0; index < image_size; index++) {
int row_index = floor(index / texture_size.width) + atlas_rect.position.y;
int column_index = (index % int(texture_size.width)) + atlas_rect.position.x;
@@ -2568,7 +2579,6 @@ void OS_Windows::set_custom_mouse_cursor(const RES &p_cursor, CursorShape p_shap
*(buffer + index) = image->get_pixel(column_index, row_index).to_argb32();
}
- image->unlock();
// Using 4 channels, so 4 * 8 bits
HBITMAP bitmap = CreateBitmap(texture_size.width, texture_size.height, 1, 4 * 8, buffer);
@@ -2713,7 +2723,7 @@ Error OS_Windows::execute(const String &p_path, const List<String> &p_arguments,
if (p_pipe_mutex) {
p_pipe_mutex->lock();
}
- (*r_pipe) += buf;
+ (*r_pipe) += String::utf8(buf);
if (p_pipe_mutex) {
p_pipe_mutex->unlock();
}
@@ -2854,7 +2864,7 @@ void OS_Windows::set_native_icon(const String &p_filename) {
ERR_FAIL_COND_MSG(big_icon_index == -1, "No valid icons found!");
if (small_icon_index == -1) {
- WARN_PRINTS("No small icon found, reusing " + itos(big_icon_width) + "x" + itos(big_icon_width) + " @" + itos(big_icon_cc) + " icon!");
+ WARN_PRINT("No small icon found, reusing " + itos(big_icon_width) + "x" + itos(big_icon_width) + " @" + itos(big_icon_cc) + " icon!");
small_icon_index = big_icon_index;
small_icon_cc = big_icon_cc;
}
@@ -2923,7 +2933,7 @@ void OS_Windows::set_icon(const Ref<Image> &p_icon) {
encode_uint32(0, &icon_bmp[36]);
uint8_t *wr = &icon_bmp[40];
- PoolVector<uint8_t>::Read r = icon->get_data().read();
+ const uint8_t *r = icon->get_data().ptr();
for (int i = 0; i < h; i++) {
@@ -3121,18 +3131,32 @@ OS::LatinKeyboardVariant OS_Windows::get_latin_keyboard_variant() const {
}
void OS_Windows::release_rendering_thread() {
-
- gl_context->release_current();
+#if defined(OPENGL_ENABLED)
+ if (video_driver_index == VIDEO_DRIVER_GLES2) {
+ context_gles2->release_current();
+ }
+#endif
}
void OS_Windows::make_rendering_thread() {
-
- gl_context->make_current();
+#if defined(OPENGL_ENABLED)
+ if (video_driver_index == VIDEO_DRIVER_GLES2) {
+ context_gles2->make_current();
+ }
+#endif
}
void OS_Windows::swap_buffers() {
-
- gl_context->swap_buffers();
+#if defined(OPENGL_ENABLED)
+ if (video_driver_index == VIDEO_DRIVER_GLES2) {
+ context_gles2->swap_buffers();
+ }
+#endif
+#if defined(VULKAN_ENABLED)
+ if (video_driver_index == VIDEO_DRIVER_VULKAN) {
+ context_vulkan->swap_buffers();
+ }
+#endif
}
void OS_Windows::force_process_input() {
@@ -3299,29 +3323,12 @@ String OS_Windows::get_joy_guid(int p_device) const {
}
void OS_Windows::_set_use_vsync(bool p_enable) {
-
- if (gl_context)
- gl_context->set_use_vsync(p_enable);
-}
-/*
-bool OS_Windows::is_vsync_enabled() const {
-
- if (gl_context)
- return gl_context->is_using_vsync();
-
- return true;
-}*/
-
-OS::PowerState OS_Windows::get_power_state() {
- return power_manager->get_power_state();
-}
-
-int OS_Windows::get_power_seconds_left() {
- return power_manager->get_power_seconds_left();
-}
-
-int OS_Windows::get_power_percent_left() {
- return power_manager->get_power_percent_left();
+#if defined(OPENGL_ENABLED)
+ if (video_driver_index == VIDEO_DRIVER_GLES2) {
+ if (context_gles2)
+ context_gles2->set_use_vsync(p_enable);
+ }
+#endif
}
bool OS_Windows::_check_internal_feature_support(const String &p_feature) {
@@ -3363,7 +3370,7 @@ Error OS_Windows::move_to_trash(const String &p_path) {
delete[] from;
if (ret) {
- ERR_PRINTS("SHFileOperation error: " + itos(ret));
+ ERR_PRINT("SHFileOperation error: " + itos(ret));
return FAILED;
}
diff --git a/platform/windows/os_windows.h b/platform/windows/os_windows.h
index cf16295a70..8506aa7b20 100644
--- a/platform/windows/os_windows.h
+++ b/platform/windows/os_windows.h
@@ -31,7 +31,6 @@
#ifndef OS_WINDOWS_H
#define OS_WINDOWS_H
-#include "context_gl_windows.h"
#include "core/os/input.h"
#include "core/os/os.h"
#include "core/project_settings.h"
@@ -41,7 +40,6 @@
#include "drivers/winmidi/midi_driver_winmidi.h"
#include "key_mapping_windows.h"
#include "main/input_default.h"
-#include "power_windows.h"
#include "servers/audio_server.h"
#include "servers/visual/rasterizer.h"
#include "servers/visual_server.h"
@@ -49,6 +47,15 @@
#include "drivers/xaudio2/audio_driver_xaudio2.h"
#endif
+#if defined(OPENGL_ENABLED)
+#include "context_gl_windows.h"
+#endif
+
+#if defined(VULKAN_ENABLED)
+#include "drivers/vulkan/rendering_device_vulkan.h"
+#include "platform/windows/vulkan_context_win.h"
+#endif
+
#include <fcntl.h>
#include <io.h>
#include <stdio.h>
@@ -170,9 +177,16 @@ class OS_Windows : public OS {
bool outside;
int old_x, old_y;
Point2i center;
+
#if defined(OPENGL_ENABLED)
- ContextGL_Windows *gl_context;
+ ContextGL_Windows *context_gles2;
+#endif
+
+#if defined(VULKAN_ENABLED)
+ VulkanContextWindows *context_vulkan;
+ RenderingDeviceVulkan *rendering_device_vulkan;
#endif
+
VisualServer *visual_server;
int pressrc;
HINSTANCE hInstance; // Holds The Instance Of The Application
@@ -218,14 +232,12 @@ class OS_Windows : public OS {
HCURSOR cursors[CURSOR_MAX] = { NULL };
CursorShape cursor_shape;
- Map<CursorShape, Vector<Variant> > cursors_cache;
+ Map<CursorShape, Vector<Variant>> cursors_cache;
InputDefault *input;
JoypadWindows *joypad;
Map<int, Vector2> touch_state;
- PowerWindows *power_manager;
-
int video_driver_index;
#ifdef WASAPI_ENABLED
AudioDriverWASAPI driver_wasapi;
@@ -418,10 +430,6 @@ public:
virtual void _set_use_vsync(bool p_enable);
//virtual bool is_vsync_enabled() const;
- virtual OS::PowerState get_power_state();
- virtual int get_power_seconds_left();
- virtual int get_power_percent_left();
-
virtual bool _check_internal_feature_support(const String &p_feature);
void disable_crash_handler();
diff --git a/platform/windows/platform_config.h b/platform/windows/platform_config.h
index 04653ee56c..290decac5f 100644
--- a/platform/windows/platform_config.h
+++ b/platform/windows/platform_config.h
@@ -29,8 +29,5 @@
/*************************************************************************/
#include <malloc.h>
-//#else
-//#include <alloca.h>
-//#endif
-#define GLES3_INCLUDE_H "thirdparty/glad/glad/glad.h"
+
#define GLES2_INCLUDE_H "thirdparty/glad/glad/glad.h"
diff --git a/platform/windows/power_windows.cpp b/platform/windows/power_windows.cpp
deleted file mode 100644
index aea06da413..0000000000
--- a/platform/windows/power_windows.cpp
+++ /dev/null
@@ -1,131 +0,0 @@
-/*************************************************************************/
-/* power_windows.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. */
-/*************************************************************************/
-
-/*
-Adapted from corresponding SDL 2.0 code.
-*/
-
-/*
- Simple DirectMedia Layer
- Copyright (C) 1997-2017 Sam Lantinga <slouken@libsdl.org>
-
- This software is provided 'as-is', without any express or implied
- warranty. In no event will the authors be held liable for any damages
- arising from the use of this software.
-
- Permission is granted to anyone to use this software for any purpose,
- including commercial applications, and to alter it and redistribute it
- freely, subject to the following restrictions:
-
- 1. The origin of this software must not be misrepresented; you must not
- claim that you wrote the original software. If you use this software
- in a product, an acknowledgment in the product documentation would be
- appreciated but is not required.
- 2. Altered source versions must be plainly marked as such, and must not be
- misrepresented as being the original software.
- 3. This notice may not be removed or altered from any source distribution.
-*/
-
-#include "power_windows.h"
-
-// CODE CHUNK IMPORTED FROM SDL 2.0
-
-bool PowerWindows::GetPowerInfo_Windows() {
- SYSTEM_POWER_STATUS status;
- bool need_details = FALSE;
-
- /* This API should exist back to Win95. */
- if (!GetSystemPowerStatus(&status)) {
- /* !!! FIXME: push GetLastError() into GetError() */
- power_state = OS::POWERSTATE_UNKNOWN;
- } else if (status.BatteryFlag == 0xFF) { /* unknown state */
- power_state = OS::POWERSTATE_UNKNOWN;
- } else if (status.BatteryFlag & (1 << 7)) { /* no battery */
- power_state = OS::POWERSTATE_NO_BATTERY;
- } else if (status.BatteryFlag & (1 << 3)) { /* charging */
- power_state = OS::POWERSTATE_CHARGING;
- need_details = TRUE;
- } else if (status.ACLineStatus == 1) {
- power_state = OS::POWERSTATE_CHARGED; /* on AC, not charging. */
- need_details = TRUE;
- } else {
- power_state = OS::POWERSTATE_ON_BATTERY; /* not on AC. */
- need_details = TRUE;
- }
-
- percent_left = -1;
- nsecs_left = -1;
- if (need_details) {
- const int pct = (int)status.BatteryLifePercent;
- const int secs = (int)status.BatteryLifeTime;
-
- if (pct != 255) { /* 255 == unknown */
- percent_left = (pct > 100) ? 100 : pct; /* clamp between 0%, 100% */
- }
- if (secs != (int)0xFFFFFFFF) { /* ((DWORD)-1) == unknown */
- nsecs_left = secs;
- }
- }
-
- return TRUE; /* always the definitive answer on Windows. */
-}
-
-OS::PowerState PowerWindows::get_power_state() {
- if (GetPowerInfo_Windows()) {
- return power_state;
- } else {
- return OS::POWERSTATE_UNKNOWN;
- }
-}
-
-int PowerWindows::get_power_seconds_left() {
- if (GetPowerInfo_Windows()) {
- return nsecs_left;
- } else {
- return -1;
- }
-}
-
-int PowerWindows::get_power_percent_left() {
- if (GetPowerInfo_Windows()) {
- return percent_left;
- } else {
- return -1;
- }
-}
-
-PowerWindows::PowerWindows() :
- nsecs_left(-1),
- percent_left(-1),
- power_state(OS::POWERSTATE_UNKNOWN) {
-}
-
-PowerWindows::~PowerWindows() {
-}
diff --git a/platform/windows/vulkan_context_win.cpp b/platform/windows/vulkan_context_win.cpp
new file mode 100644
index 0000000000..20e1b46682
--- /dev/null
+++ b/platform/windows/vulkan_context_win.cpp
@@ -0,0 +1,57 @@
+/*************************************************************************/
+/* vulkan_context_win.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 "vulkan_context_win.h"
+#include <vulkan/vulkan_win32.h>
+
+const char *VulkanContextWindows::_get_platform_surface_extension() const {
+ return VK_KHR_WIN32_SURFACE_EXTENSION_NAME;
+}
+
+int VulkanContextWindows::window_create(HWND p_window, HINSTANCE p_instance, int p_width, int p_height) {
+
+ VkWin32SurfaceCreateInfoKHR createInfo;
+ createInfo.sType = VK_STRUCTURE_TYPE_WIN32_SURFACE_CREATE_INFO_KHR;
+ createInfo.pNext = NULL;
+ createInfo.flags = 0;
+ createInfo.hinstance = p_instance;
+ createInfo.hwnd = p_window;
+
+ VkSurfaceKHR surface;
+ VkResult err = vkCreateWin32SurfaceKHR(_get_instance(), &createInfo, NULL, &surface);
+ ERR_FAIL_COND_V(err, -1);
+ return _window_create(surface, p_width, p_height);
+}
+
+VulkanContextWindows::VulkanContextWindows() {
+}
+
+VulkanContextWindows::~VulkanContextWindows() {
+}
diff --git a/platform/windows/power_windows.h b/platform/windows/vulkan_context_win.h
index 80d86a12c5..1289f2a299 100644
--- a/platform/windows/power_windows.h
+++ b/platform/windows/vulkan_context_win.h
@@ -1,5 +1,5 @@
/*************************************************************************/
-/* power_windows.h */
+/* vulkan_context_win.h */
/*************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
@@ -28,31 +28,21 @@
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/
-#ifndef POWER_WINDOWS_H
-#define POWER_WINDOWS_H
-
-#include "core/os/dir_access.h"
-#include "core/os/file_access.h"
-#include "core/os/os.h"
+#ifndef VULKAN_DEVICE_WIN_H
+#define VULKAN_DEVICE_WIN_H
+#include "drivers/vulkan/vulkan_context.h"
#include <windows.h>
-class PowerWindows {
-
-private:
- int nsecs_left;
- int percent_left;
- OS::PowerState power_state;
+class VulkanContextWindows : public VulkanContext {
- bool GetPowerInfo_Windows();
+ virtual const char *_get_platform_surface_extension() const;
public:
- PowerWindows();
- virtual ~PowerWindows();
+ int window_create(HWND p_window, HINSTANCE p_instance, int p_width, int p_height);
- OS::PowerState get_power_state();
- int get_power_seconds_left();
- int get_power_percent_left();
+ VulkanContextWindows();
+ ~VulkanContextWindows();
};
-#endif // POWER_WINDOWS_H
+#endif // VULKAN_DEVICE_WIN_H
diff --git a/platform/windows/windows_terminal_logger.cpp b/platform/windows/windows_terminal_logger.cpp
index 8eb6adc27b..520b654b94 100644
--- a/platform/windows/windows_terminal_logger.cpp
+++ b/platform/windows/windows_terminal_logger.cpp
@@ -85,7 +85,6 @@ void WindowsTerminalLogger::log_error(const char *p_function, const char *p_file
CONSOLE_SCREEN_BUFFER_INFO sbi; //original
GetConsoleScreenBufferInfo(hCon, &sbi);
- WORD current_fg = sbi.wAttributes & (FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE | FOREGROUND_INTENSITY);
WORD current_bg = sbi.wAttributes & (BACKGROUND_RED | BACKGROUND_GREEN | BACKGROUND_BLUE | BACKGROUND_INTENSITY);
uint32_t basecol = 0;
@@ -98,53 +97,34 @@ void WindowsTerminalLogger::log_error(const char *p_function, const char *p_file
basecol |= current_bg;
- if (p_rationale && p_rationale[0]) {
-
- SetConsoleTextAttribute(hCon, basecol | FOREGROUND_INTENSITY);
- switch (p_type) {
- case ERR_ERROR: logf("ERROR: "); break;
- case ERR_WARNING: logf("WARNING: "); break;
- case ERR_SCRIPT: logf("SCRIPT ERROR: "); break;
- case ERR_SHADER: logf("SHADER ERROR: "); break;
- }
-
- SetConsoleTextAttribute(hCon, current_fg | current_bg | FOREGROUND_INTENSITY);
- logf("%s\n", p_rationale);
+ SetConsoleTextAttribute(hCon, basecol | FOREGROUND_INTENSITY);
+ switch (p_type) {
+ case ERR_ERROR: logf("ERROR:"); break;
+ case ERR_WARNING: logf("WARNING:"); break;
+ case ERR_SCRIPT: logf("SCRIPT ERROR:"); break;
+ case ERR_SHADER: logf("SHADER ERROR:"); break;
+ }
- SetConsoleTextAttribute(hCon, basecol);
- switch (p_type) {
- case ERR_ERROR: logf(" At: "); break;
- case ERR_WARNING: logf(" At: "); break;
- case ERR_SCRIPT: logf(" At: "); break;
- case ERR_SHADER: logf(" At: "); break;
- }
+ SetConsoleTextAttribute(hCon, basecol);
+ if (p_rationale && p_rationale[0]) {
+ logf(" %s\n", p_rationale);
+ } else {
+ logf(" %s\n", p_code);
+ }
- SetConsoleTextAttribute(hCon, current_fg | current_bg);
- logf("%s:%i\n", p_file, p_line);
+ // `FOREGROUND_INTENSITY` alone results in gray text.
+ SetConsoleTextAttribute(hCon, FOREGROUND_INTENSITY);
+ switch (p_type) {
+ case ERR_ERROR: logf(" at: "); break;
+ case ERR_WARNING: logf(" at: "); break;
+ case ERR_SCRIPT: logf(" at: "); break;
+ case ERR_SHADER: logf(" at: "); break;
+ }
+ if (p_rationale && p_rationale[0]) {
+ logf("(%s:%i)\n", p_file, p_line);
} else {
-
- SetConsoleTextAttribute(hCon, basecol | FOREGROUND_INTENSITY);
- switch (p_type) {
- case ERR_ERROR: logf("ERROR: %s: ", p_function); break;
- case ERR_WARNING: logf("WARNING: %s: ", p_function); break;
- case ERR_SCRIPT: logf("SCRIPT ERROR: %s: ", p_function); break;
- case ERR_SHADER: logf("SCRIPT ERROR: %s: ", p_function); break;
- }
-
- SetConsoleTextAttribute(hCon, current_fg | current_bg | FOREGROUND_INTENSITY);
- logf("%s\n", p_code);
-
- SetConsoleTextAttribute(hCon, basecol);
- switch (p_type) {
- case ERR_ERROR: logf(" At: "); break;
- case ERR_WARNING: logf(" At: "); break;
- case ERR_SCRIPT: logf(" At: "); break;
- case ERR_SHADER: logf(" At: "); break;
- }
-
- SetConsoleTextAttribute(hCon, current_fg | current_bg);
- logf("%s:%i\n", p_file, p_line);
+ logf("%s (%s:%i)\n", p_function, p_file, p_line);
}
SetConsoleTextAttribute(hCon, sbi.wAttributes);
diff --git a/platform/x11/SCsub b/platform/x11/SCsub
index 3d5aa15208..2268e4cc3d 100644
--- a/platform/x11/SCsub
+++ b/platform/x11/SCsub
@@ -7,11 +7,11 @@ import platform_x11_builders
common_x11 = [
"context_gl_x11.cpp",
+ "vulkan_context_x11.cpp",
"crash_handler_x11.cpp",
"os_x11.cpp",
"key_mapping_x11.cpp",
"joypad_linux.cpp",
- "power_x11.cpp",
"detect_prime.cpp"
]
diff --git a/platform/x11/context_gl_x11.cpp b/platform/x11/context_gl_x11.cpp
index 3b88af28e4..5442af3bef 100644
--- a/platform/x11/context_gl_x11.cpp
+++ b/platform/x11/context_gl_x11.cpp
@@ -166,29 +166,11 @@ Error ContextGL_X11::initialize() {
int (*oldHandler)(Display *, XErrorEvent *) = XSetErrorHandler(&ctxErrorHandler);
switch (context_type) {
- case OLDSTYLE: {
-
- p->glx_context = glXCreateContext(x11_display, vi, 0, GL_TRUE);
- ERR_FAIL_COND_V(!p->glx_context, ERR_UNCONFIGURED);
- } break;
case GLES_2_0_COMPATIBLE: {
p->glx_context = glXCreateNewContext(x11_display, fbconfig, GLX_RGBA_TYPE, 0, true);
ERR_FAIL_COND_V(!p->glx_context, ERR_UNCONFIGURED);
} break;
- case GLES_3_0_COMPATIBLE: {
-
- static int context_attribs[] = {
- GLX_CONTEXT_MAJOR_VERSION_ARB, 3,
- GLX_CONTEXT_MINOR_VERSION_ARB, 3,
- GLX_CONTEXT_PROFILE_MASK_ARB, GLX_CONTEXT_CORE_PROFILE_BIT_ARB,
- GLX_CONTEXT_FLAGS_ARB, GLX_CONTEXT_FORWARD_COMPATIBLE_BIT_ARB /*|GLX_CONTEXT_DEBUG_BIT_ARB*/,
- None
- };
-
- p->glx_context = glXCreateContextAttribsARB(x11_display, fbconfig, NULL, true, context_attribs);
- ERR_FAIL_COND_V(ctxErrorOccurred || !p->glx_context, ERR_UNCONFIGURED);
- } break;
}
swa.colormap = XCreateColormap(x11_display, RootWindow(x11_display, vi->screen), vi->visual, AllocNone);
diff --git a/platform/x11/context_gl_x11.h b/platform/x11/context_gl_x11.h
index 5e5ccc5c86..2c0643c95a 100644
--- a/platform/x11/context_gl_x11.h
+++ b/platform/x11/context_gl_x11.h
@@ -45,15 +45,12 @@ class ContextGL_X11 {
public:
enum ContextType {
- OLDSTYLE,
GLES_2_0_COMPATIBLE,
- GLES_3_0_COMPATIBLE
};
private:
ContextGL_X11_Private *p;
OS::VideoMode default_video_mode;
- //::Colormap x11_colormap;
::Display *x11_display;
::Window &x11_window;
bool double_buffer;
diff --git a/platform/x11/detect.py b/platform/x11/detect.py
index bd5e5e0812..9a9ab86068 100644
--- a/platform/x11/detect.py
+++ b/platform/x11/detect.py
@@ -1,7 +1,6 @@
import os
import platform
import sys
-from methods import get_compiler_version, using_gcc, using_clang
def is_active():
@@ -61,6 +60,7 @@ def get_opts():
BoolVariable('use_lld', 'Use the LLD linker', False),
BoolVariable('use_thinlto', 'Use ThinLTO', False),
BoolVariable('use_static_cpp', 'Link libgcc and libstdc++ statically for better portability', False),
+ BoolVariable('use_coverage', 'Test Godot coverage', False),
BoolVariable('use_ubsan', 'Use LLVM/GCC compiler undefined behavior sanitizer (UBSAN)', False),
BoolVariable('use_asan', 'Use LLVM/GCC compiler address sanitizer (ASAN))', False),
BoolVariable('use_lsan', 'Use LLVM/GCC compiler leak sanitizer (LSAN))', False),
@@ -141,6 +141,10 @@ def configure(env):
print("Using LLD with GCC is not supported yet, try compiling with 'use_llvm=yes'.")
sys.exit(255)
+ if env['use_coverage']:
+ env.Append(CCFLAGS=['-ftest-coverage', '-fprofile-arcs'])
+ env.Append(LINKFLAGS=['-ftest-coverage', '-fprofile-arcs'])
+
if env['use_ubsan'] or env['use_asan'] or env['use_lsan'] or env['use_tsan']:
env.extra_suffix += "s"
@@ -179,18 +183,10 @@ def configure(env):
env.Append(CCFLAGS=['-pipe'])
env.Append(LINKFLAGS=['-pipe'])
- # Check for gcc version >= 6 before adding -no-pie
- if using_gcc(env):
- version = get_compiler_version(env)
- if version != None and version[0] >= '6':
- env.Append(CCFLAGS=['-fpie'])
- env.Append(LINKFLAGS=['-no-pie'])
- # Do the same for clang should be fine with Clang 4 and higher
- if using_clang(env):
- version = get_compiler_version(env)
- if version != None and version[0] >= '4':
- env.Append(CCFLAGS=['-fpie'])
- env.Append(LINKFLAGS=['-no-pie'])
+ # -fpie and -no-pie is supported on GCC 6+ and Clang 4+, both below our
+ # minimal requirements.
+ env.Append(CCFLAGS=['-fpie'])
+ env.Append(LINKFLAGS=['-no-pie'])
## Dependencies
@@ -229,6 +225,10 @@ def configure(env):
sys.exit(255)
env.ParseConfig('pkg-config bullet --cflags --libs')
+ if False: # not env['builtin_assimp']:
+ # FIXME: Add min version check
+ env.ParseConfig('pkg-config assimp --cflags --libs')
+
if not env['builtin_enet']:
env.ParseConfig('pkg-config libenet --cflags --libs')
@@ -318,8 +318,19 @@ def configure(env):
env.ParseConfig('pkg-config zlib --cflags --libs')
env.Prepend(CPPPATH=['#platform/x11'])
- env.Append(CPPDEFINES=['X11_ENABLED', 'UNIX_ENABLED', 'OPENGL_ENABLED', 'GLES_ENABLED'])
- env.Append(LIBS=['GL', 'pthread'])
+ env.Append(CPPDEFINES=['X11_ENABLED', 'UNIX_ENABLED'])
+
+ env.Append(CPPDEFINES=['VULKAN_ENABLED'])
+ if not env['builtin_vulkan']:
+ env.ParseConfig('pkg-config vulkan --cflags --libs')
+ if not env['builtin_glslang']:
+ # No pkgconfig file for glslang so far
+ env.Append(LIBS=['glslang', 'SPIRV'])
+
+ #env.Append(CPPDEFINES=['OPENGL_ENABLED'])
+ env.Append(LIBS=['GL'])
+
+ env.Append(LIBS=['pthread'])
if (platform.system() == "Linux"):
env.Append(LIBS=['dl'])
diff --git a/platform/x11/detect_prime.cpp b/platform/x11/detect_prime.cpp
index 98a51ff27c..a0e5f835c0 100644
--- a/platform/x11/detect_prime.cpp
+++ b/platform/x11/detect_prime.cpp
@@ -62,6 +62,7 @@ vendor vendormap[] = {
{ "NVIDIA Corporation", 30 },
{ "X.Org", 30 },
{ "Intel Open Source Technology Center", 20 },
+ { "Intel", 20 },
{ "nouveau", 10 },
{ "Mesa Project", 0 },
{ NULL, 0 }
diff --git a/platform/x11/joypad_linux.cpp b/platform/x11/joypad_linux.cpp
index a64a25aeee..a9fe7275c2 100644
--- a/platform/x11/joypad_linux.cpp
+++ b/platform/x11/joypad_linux.cpp
@@ -83,7 +83,6 @@ void JoypadLinux::Joypad::reset() {
JoypadLinux::JoypadLinux(InputDefault *in) {
exit_udev = false;
input = in;
- joy_mutex = Mutex::create();
joy_thread = Thread::create(joy_thread_func, this);
}
@@ -91,7 +90,6 @@ JoypadLinux::~JoypadLinux() {
exit_udev = true;
Thread::wait_to_finish(joy_thread);
memdelete(joy_thread);
- memdelete(joy_mutex);
close_joypad();
}
@@ -137,9 +135,8 @@ void JoypadLinux::enumerate_joypads(udev *p_udev) {
String devnode_str = devnode;
if (devnode_str.find(ignore_str) == -1) {
- joy_mutex->lock();
+ MutexLock lock(joy_mutex);
open_joypad(devnode);
- joy_mutex->unlock();
}
}
udev_device_unref(dev);
@@ -176,7 +173,7 @@ void JoypadLinux::monitor_joypads(udev *p_udev) {
if (dev && udev_device_get_devnode(dev) != 0) {
- joy_mutex->lock();
+ MutexLock lock(joy_mutex);
String action = udev_device_get_action(dev);
const char *devnode = udev_device_get_devnode(dev);
if (devnode) {
@@ -192,7 +189,6 @@ void JoypadLinux::monitor_joypads(udev *p_udev) {
}
udev_device_unref(dev);
- joy_mutex->unlock();
}
}
usleep(50000);
@@ -204,15 +200,17 @@ void JoypadLinux::monitor_joypads(udev *p_udev) {
void JoypadLinux::monitor_joypads() {
while (!exit_udev) {
- joy_mutex->lock();
- for (int i = 0; i < 32; i++) {
- char fname[64];
- sprintf(fname, "/dev/input/event%d", i);
- if (attached_devices.find(fname) == -1) {
- open_joypad(fname);
+ {
+ MutexLock lock(joy_mutex);
+
+ for (int i = 0; i < 32; i++) {
+ char fname[64];
+ sprintf(fname, "/dev/input/event%d", i);
+ if (attached_devices.find(fname) == -1) {
+ open_joypad(fname);
+ }
}
}
- joy_mutex->unlock();
usleep(1000000); // 1s
}
}
@@ -457,7 +455,7 @@ InputDefault::JoyAxis JoypadLinux::axis_correct(const input_absinfo *p_abs, int
void JoypadLinux::process_joypads() {
- if (joy_mutex->try_lock() != OK) {
+ if (joy_mutex.try_lock() != OK) {
return;
}
for (int i = 0; i < JOYPADS_MAX; i++) {
@@ -548,6 +546,6 @@ void JoypadLinux::process_joypads() {
}
}
}
- joy_mutex->unlock();
+ joy_mutex.unlock();
}
#endif
diff --git a/platform/x11/joypad_linux.h b/platform/x11/joypad_linux.h
index e5638899bf..d5719b6dbe 100644
--- a/platform/x11/joypad_linux.h
+++ b/platform/x11/joypad_linux.h
@@ -72,7 +72,7 @@ private:
};
bool exit_udev;
- Mutex *joy_mutex;
+ Mutex joy_mutex;
Thread *joy_thread;
InputDefault *input;
Joypad joypads[JOYPADS_MAX];
diff --git a/platform/x11/key_mapping_x11.cpp b/platform/x11/key_mapping_x11.cpp
index 54e1e1d357..78bd2b71a0 100644
--- a/platform/x11/key_mapping_x11.cpp
+++ b/platform/x11/key_mapping_x11.cpp
@@ -180,6 +180,140 @@ static _XTranslatePair _xkeysym_to_keycode[] = {
{ 0, 0 }
};
+struct _TranslatePair {
+
+ unsigned int keysym;
+ unsigned int keycode;
+};
+
+static _TranslatePair _scancode_to_keycode[] = {
+
+ { KEY_ESCAPE, 0x09 },
+ { KEY_1, 0x0A },
+ { KEY_2, 0x0B },
+ { KEY_3, 0x0C },
+ { KEY_4, 0x0D },
+ { KEY_5, 0x0E },
+ { KEY_6, 0x0F },
+ { KEY_7, 0x10 },
+ { KEY_8, 0x11 },
+ { KEY_9, 0x12 },
+ { KEY_0, 0x13 },
+ { KEY_MINUS, 0x14 },
+ { KEY_EQUAL, 0x15 },
+ { KEY_BACKSPACE, 0x16 },
+ { KEY_TAB, 0x17 },
+ { KEY_Q, 0x18 },
+ { KEY_W, 0x19 },
+ { KEY_E, 0x1A },
+ { KEY_R, 0x1B },
+ { KEY_T, 0x1C },
+ { KEY_Y, 0x1D },
+ { KEY_U, 0x1E },
+ { KEY_I, 0x1F },
+ { KEY_O, 0x20 },
+ { KEY_P, 0x21 },
+ { KEY_BRACELEFT, 0x22 },
+ { KEY_BRACERIGHT, 0x23 },
+ { KEY_ENTER, 0x24 },
+ { KEY_CONTROL, 0x25 },
+ { KEY_A, 0x26 },
+ { KEY_S, 0x27 },
+ { KEY_D, 0x28 },
+ { KEY_F, 0x29 },
+ { KEY_G, 0x2A },
+ { KEY_H, 0x2B },
+ { KEY_J, 0x2C },
+ { KEY_K, 0x2D },
+ { KEY_L, 0x2E },
+ { KEY_SEMICOLON, 0x2F },
+ { KEY_APOSTROPHE, 0x30 },
+ { KEY_QUOTELEFT, 0x31 },
+ { KEY_SHIFT, 0x32 },
+ { KEY_BACKSLASH, 0x33 },
+ { KEY_Z, 0x34 },
+ { KEY_X, 0x35 },
+ { KEY_C, 0x36 },
+ { KEY_V, 0x37 },
+ { KEY_B, 0x38 },
+ { KEY_N, 0x39 },
+ { KEY_M, 0x3A },
+ { KEY_COMMA, 0x3B },
+ { KEY_PERIOD, 0x3C },
+ { KEY_SLASH, 0x3D },
+ { KEY_SHIFT, 0x3E },
+ { KEY_KP_MULTIPLY, 0x3F },
+ { KEY_ALT, 0x40 },
+ { KEY_SPACE, 0x41 },
+ { KEY_CAPSLOCK, 0x42 },
+ { KEY_F1, 0x43 },
+ { KEY_F2, 0x44 },
+ { KEY_F3, 0x45 },
+ { KEY_F4, 0x46 },
+ { KEY_F5, 0x47 },
+ { KEY_F6, 0x48 },
+ { KEY_F7, 0x49 },
+ { KEY_F8, 0x4A },
+ { KEY_F9, 0x4B },
+ { KEY_F10, 0x4C },
+ { KEY_NUMLOCK, 0x4D },
+ { KEY_SCROLLLOCK, 0x4E },
+ { KEY_KP_7, 0x4F },
+ { KEY_KP_8, 0x50 },
+ { KEY_KP_9, 0x51 },
+ { KEY_KP_SUBTRACT, 0x52 },
+ { KEY_KP_4, 0x53 },
+ { KEY_KP_5, 0x54 },
+ { KEY_KP_6, 0x55 },
+ { KEY_KP_ADD, 0x56 },
+ { KEY_KP_1, 0x57 },
+ { KEY_KP_2, 0x58 },
+ { KEY_KP_3, 0x59 },
+ { KEY_KP_0, 0x5A },
+ { KEY_KP_PERIOD, 0x5B },
+ //{ KEY_???, 0x5E }, //NON US BACKSLASH
+ { KEY_F11, 0x5F },
+ { KEY_F12, 0x60 },
+ { KEY_KP_ENTER, 0x68 },
+ { KEY_CONTROL, 0x69 },
+ { KEY_KP_DIVIDE, 0x6A },
+ { KEY_PRINT, 0x6B },
+ { KEY_ALT, 0x6C },
+ { KEY_ENTER, 0x6D },
+ { KEY_HOME, 0x6E },
+ { KEY_UP, 0x6F },
+ { KEY_PAGEUP, 0x70 },
+ { KEY_LEFT, 0x71 },
+ { KEY_RIGHT, 0x72 },
+ { KEY_END, 0x73 },
+ { KEY_DOWN, 0x74 },
+ { KEY_PAGEDOWN, 0x75 },
+ { KEY_INSERT, 0x76 },
+ { KEY_DELETE, 0x77 },
+ { KEY_VOLUMEMUTE, 0x79 },
+ { KEY_VOLUMEDOWN, 0x7A },
+ { KEY_VOLUMEUP, 0x7B },
+ { KEY_PAUSE, 0x7F },
+ { KEY_SUPER_L, 0x85 },
+ { KEY_SUPER_R, 0x86 },
+ { KEY_MENU, 0x87 },
+ { KEY_UNKNOWN, 0 }
+};
+
+unsigned int KeyMappingX11::get_scancode(unsigned int p_code) {
+
+ unsigned int keycode = KEY_UNKNOWN;
+ for (int i = 0; _scancode_to_keycode[i].keysym != KEY_UNKNOWN; i++) {
+
+ if (_scancode_to_keycode[i].keycode == p_code) {
+ keycode = _scancode_to_keycode[i].keysym;
+ break;
+ }
+ }
+
+ return keycode;
+}
+
unsigned int KeyMappingX11::get_keycode(KeySym p_keysym) {
// kinda bruteforce.. could optimize.
diff --git a/platform/x11/key_mapping_x11.h b/platform/x11/key_mapping_x11.h
index e99bf1694b..10db43bcc4 100644
--- a/platform/x11/key_mapping_x11.h
+++ b/platform/x11/key_mapping_x11.h
@@ -45,6 +45,7 @@ class KeyMappingX11 {
public:
static unsigned int get_keycode(KeySym p_keysym);
+ static unsigned int get_scancode(unsigned int p_code);
static KeySym get_keysym(unsigned int p_code);
static unsigned int get_unicode_from_keysym(KeySym p_keysym);
static KeySym get_keysym_from_unicode(unsigned int p_unicode);
diff --git a/platform/x11/os_x11.cpp b/platform/x11/os_x11.cpp
index 57c7b0594c..e1f7691cf6 100644
--- a/platform/x11/os_x11.cpp
+++ b/platform/x11/os_x11.cpp
@@ -33,10 +33,17 @@
#include "core/os/dir_access.h"
#include "core/print_string.h"
-#include "drivers/gles2/rasterizer_gles2.h"
-#include "drivers/gles3/rasterizer_gles3.h"
#include "errno.h"
#include "key_mapping_x11.h"
+
+#if defined(OPENGL_ENABLED)
+#include "drivers/gles2/rasterizer_gles2.h"
+#endif
+
+#if defined(VULKAN_ENABLED)
+#include "servers/visual/rasterizer_rd/rasterizer_rd.h"
+#endif
+
#include "servers/visual/visual_server_raster.h"
#include "servers/visual/visual_server_wrap_mt.h"
@@ -230,137 +237,131 @@ Error OS_X11::initialize(const VideoMode &p_desired, int p_video_driver, int p_a
XFree(imvalret);
}
-/*
- char* windowid = getenv("GODOT_WINDOWID");
- if (windowid) {
-
- //freopen("/home/punto/stdout", "w", stdout);
- //reopen("/home/punto/stderr", "w", stderr);
- x11_window = atol(windowid);
-
- XWindowAttributes xwa;
- XGetWindowAttributes(x11_display,x11_window,&xwa);
-
- current_videomode.width = xwa.width;
- current_videomode.height = xwa.height;
- };
- */
-
-// maybe contextgl wants to be in charge of creating the window
-#if defined(OPENGL_ENABLED)
- if (getenv("DRI_PRIME") == NULL) {
- int use_prime = -1;
+ //!!!!!!!!!!!!!!!!!!!!!!!!!!
+ //TODO - do Vulkan and GLES2 support checks, driver selection and fallback
+ video_driver_index = p_video_driver;
+#ifndef _MSC_VER
+#warning Forcing vulkan video driver because OpenGL not implemented yet
+#endif
+ video_driver_index = VIDEO_DRIVER_VULKAN;
- if (getenv("PRIMUS_DISPLAY") ||
- getenv("PRIMUS_libGLd") ||
- getenv("PRIMUS_libGLa") ||
- getenv("PRIMUS_libGL") ||
- getenv("PRIMUS_LOAD_GLOBAL") ||
- getenv("BUMBLEBEE_SOCKET")) {
+ print_verbose("Driver: " + String(get_video_driver_name(video_driver_index)) + " [" + itos(video_driver_index) + "]");
+ //!!!!!!!!!!!!!!!!!!!!!!!!!!
- print_verbose("Optirun/primusrun detected. Skipping GPU detection");
- use_prime = 0;
- }
+ //Create window
- if (getenv("LD_LIBRARY_PATH")) {
- String ld_library_path(getenv("LD_LIBRARY_PATH"));
- Vector<String> libraries = ld_library_path.split(":");
+ long visualMask = VisualScreenMask;
+ int numberOfVisuals;
+ XVisualInfo vInfoTemplate = {};
+ vInfoTemplate.screen = DefaultScreen(x11_display);
+ XVisualInfo *visualInfo = XGetVisualInfo(x11_display, visualMask, &vInfoTemplate, &numberOfVisuals);
- for (int i = 0; i < libraries.size(); ++i) {
- if (FileAccess::exists(libraries[i] + "/libGL.so.1") ||
- FileAccess::exists(libraries[i] + "/libGL.so")) {
+ Colormap colormap = XCreateColormap(x11_display, RootWindow(x11_display, vInfoTemplate.screen), visualInfo->visual, AllocNone);
- print_verbose("Custom libGL override detected. Skipping GPU detection");
- use_prime = 0;
- }
- }
- }
+ XSetWindowAttributes windowAttributes = {};
+ windowAttributes.colormap = colormap;
+ windowAttributes.background_pixel = 0xFFFFFFFF;
+ windowAttributes.border_pixel = 0;
+ windowAttributes.event_mask = KeyPressMask | KeyReleaseMask | StructureNotifyMask | ExposureMask;
- if (use_prime == -1) {
- print_verbose("Detecting GPUs, set DRI_PRIME in the environment to override GPU detection logic.");
- use_prime = detect_prime();
- }
+ unsigned long valuemask = CWBorderPixel | CWColormap | CWEventMask;
+ x11_window = XCreateWindow(x11_display, RootWindow(x11_display, visualInfo->screen), 0, 0, OS::get_singleton()->get_video_mode().width, OS::get_singleton()->get_video_mode().height, 0, visualInfo->depth, InputOutput, visualInfo->visual, valuemask, &windowAttributes);
- if (use_prime) {
- print_line("Found discrete GPU, setting DRI_PRIME=1 to use it.");
- print_line("Note: Set DRI_PRIME=0 in the environment to disable Godot from using the discrete GPU.");
- setenv("DRI_PRIME", "1", 1);
- }
- }
+ //set_class_hint(x11_display, x11_window);
+ XMapWindow(x11_display, x11_window);
+ XFlush(x11_display);
- ContextGL_X11::ContextType opengl_api_type = ContextGL_X11::GLES_3_0_COMPATIBLE;
+ XSync(x11_display, False);
+ //XSetErrorHandler(oldHandler);
- if (p_video_driver == VIDEO_DRIVER_GLES2) {
- opengl_api_type = ContextGL_X11::GLES_2_0_COMPATIBLE;
- }
+ XFree(visualInfo);
- bool editor = Engine::get_singleton()->is_editor_hint();
- bool gl_initialization_error = false;
+ // Init context and rendering device
+#if defined(OPENGL_ENABLED)
+ if (video_driver_index == VIDEO_DRIVER_GLES2) {
+ if (getenv("DRI_PRIME") == NULL) {
+ int use_prime = -1;
+
+ if (getenv("PRIMUS_DISPLAY") ||
+ getenv("PRIMUS_libGLd") ||
+ getenv("PRIMUS_libGLa") ||
+ getenv("PRIMUS_libGL") ||
+ getenv("PRIMUS_LOAD_GLOBAL") ||
+ getenv("BUMBLEBEE_SOCKET")) {
+
+ print_verbose("Optirun/primusrun detected. Skipping GPU detection");
+ use_prime = 0;
+ }
- context_gl = NULL;
- while (!context_gl) {
- context_gl = memnew(ContextGL_X11(x11_display, x11_window, current_videomode, opengl_api_type));
+ if (getenv("LD_LIBRARY_PATH")) {
+ String ld_library_path(getenv("LD_LIBRARY_PATH"));
+ Vector<String> libraries = ld_library_path.split(":");
- if (context_gl->initialize() != OK) {
- memdelete(context_gl);
- context_gl = NULL;
+ for (int i = 0; i < libraries.size(); ++i) {
+ if (FileAccess::exists(libraries[i] + "/libGL.so.1") ||
+ FileAccess::exists(libraries[i] + "/libGL.so")) {
- if (GLOBAL_GET("rendering/quality/driver/fallback_to_gles2") || editor) {
- if (p_video_driver == VIDEO_DRIVER_GLES2) {
- gl_initialization_error = true;
- break;
+ print_verbose("Custom libGL override detected. Skipping GPU detection");
+ use_prime = 0;
+ }
}
+ }
- p_video_driver = VIDEO_DRIVER_GLES2;
- opengl_api_type = ContextGL_X11::GLES_2_0_COMPATIBLE;
- } else {
- gl_initialization_error = true;
- break;
+ if (use_prime == -1) {
+ print_verbose("Detecting GPUs, set DRI_PRIME in the environment to override GPU detection logic.");
+ use_prime = detect_prime();
}
- }
- }
- while (true) {
- if (opengl_api_type == ContextGL_X11::GLES_3_0_COMPATIBLE) {
- if (RasterizerGLES3::is_viable() == OK) {
- RasterizerGLES3::register_config();
- RasterizerGLES3::make_current();
- break;
- } else {
- if (GLOBAL_GET("rendering/quality/driver/fallback_to_gles2") || editor) {
- p_video_driver = VIDEO_DRIVER_GLES2;
- opengl_api_type = ContextGL_X11::GLES_2_0_COMPATIBLE;
- continue;
- } else {
- gl_initialization_error = true;
- break;
- }
+ if (use_prime) {
+ print_line("Found discrete GPU, setting DRI_PRIME=1 to use it.");
+ print_line("Note: Set DRI_PRIME=0 in the environment to disable Godot from using the discrete GPU.");
+ setenv("DRI_PRIME", "1", 1);
}
}
- if (opengl_api_type == ContextGL_X11::GLES_2_0_COMPATIBLE) {
- if (RasterizerGLES2::is_viable() == OK) {
- RasterizerGLES2::register_config();
- RasterizerGLES2::make_current();
- break;
- } else {
- gl_initialization_error = true;
- break;
- }
+ ContextGL_X11::ContextType opengl_api_type = ContextGL_X11::GLES_2_0_COMPATIBLE;
+
+ context_gles2 = memnew(ContextGL_X11(x11_display, x11_window, current_videomode, opengl_api_type));
+
+ if (context_gles2->initialize() != OK) {
+ memdelete(context_gles2);
+ context_gles2 = NULL;
+ ERR_FAIL_V(ERR_UNAVAILABLE);
}
- }
- if (gl_initialization_error) {
- OS::get_singleton()->alert("Your video card driver does not support any of the supported OpenGL versions.\n"
- "Please update your drivers or if you have a very old or integrated GPU upgrade it.",
- "Unable to initialize Video driver");
- return ERR_UNAVAILABLE;
+ context_gles2->set_use_vsync(current_videomode.use_vsync);
+
+ if (RasterizerGLES2::is_viable() == OK) {
+ RasterizerGLES2::register_config();
+ RasterizerGLES2::make_current();
+ } else {
+ memdelete(context_gles2);
+ context_gles2 = NULL;
+ ERR_FAIL_V(ERR_UNAVAILABLE);
+ }
}
+#endif
+#if defined(VULKAN_ENABLED)
+ if (video_driver_index == VIDEO_DRIVER_VULKAN) {
- video_driver_index = p_video_driver;
+ context_vulkan = memnew(VulkanContextX11);
+ if (context_vulkan->initialize() != OK) {
+ memdelete(context_vulkan);
+ context_vulkan = NULL;
+ ERR_FAIL_V(ERR_UNAVAILABLE);
+ }
+ if (context_vulkan->window_create(x11_window, x11_display, get_video_mode().width, get_video_mode().height) == -1) {
+ memdelete(context_vulkan);
+ context_vulkan = NULL;
+ ERR_FAIL_V(ERR_UNAVAILABLE);
+ }
- context_gl->set_use_vsync(current_videomode.use_vsync);
+ //temporary
+ rendering_device_vulkan = memnew(RenderingDeviceVulkan);
+ rendering_device_vulkan->initialize(context_vulkan);
+ RasterizerRD::make_current();
+ }
#endif
visual_server = memnew(VisualServerRaster);
@@ -526,19 +527,73 @@ Error OS_X11::initialize(const VideoMode &p_desired, int p_video_driver, int p_a
"watch",
"left_ptr_watch",
"fleur",
- "hand1",
- "X_cursor",
- "sb_v_double_arrow",
- "sb_h_double_arrow",
+ "dnd-move",
+ "crossed_circle",
+ "v_double_arrow",
+ "h_double_arrow",
"size_bdiag",
"size_fdiag",
- "hand1",
- "sb_v_double_arrow",
- "sb_h_double_arrow",
+ "move",
+ "row_resize",
+ "col_resize",
"question_arrow"
};
img[i] = XcursorLibraryLoadImage(cursor_file[i], cursor_theme, cursor_size);
+ if (!img[i]) {
+ const char *fallback = NULL;
+
+ switch (i) {
+ case CURSOR_POINTING_HAND:
+ fallback = "pointer";
+ break;
+ case CURSOR_CROSS:
+ fallback = "crosshair";
+ break;
+ case CURSOR_WAIT:
+ fallback = "wait";
+ break;
+ case CURSOR_BUSY:
+ fallback = "progress";
+ break;
+ case CURSOR_DRAG:
+ fallback = "grabbing";
+ break;
+ case CURSOR_CAN_DROP:
+ fallback = "hand1";
+ break;
+ case CURSOR_FORBIDDEN:
+ fallback = "forbidden";
+ break;
+ case CURSOR_VSIZE:
+ fallback = "ns-resize";
+ break;
+ case CURSOR_HSIZE:
+ fallback = "ew-resize";
+ break;
+ case CURSOR_BDIAGSIZE:
+ fallback = "fd_double_arrow";
+ break;
+ case CURSOR_FDIAGSIZE:
+ fallback = "bd_double_arrow";
+ break;
+ case CURSOR_MOVE:
+ img[i] = img[CURSOR_DRAG];
+ break;
+ case CURSOR_VSPLIT:
+ fallback = "sb_v_double_arrow";
+ break;
+ case CURSOR_HSPLIT:
+ fallback = "sb_h_double_arrow";
+ break;
+ case CURSOR_HELP:
+ fallback = "help";
+ break;
+ }
+ if (fallback != NULL) {
+ img[i] = XcursorLibraryLoadImage(fallback, cursor_theme, cursor_size);
+ }
+ }
if (img[i]) {
cursors[i] = XcursorImageLoadCursor(x11_display, img[i]);
} else {
@@ -604,8 +659,6 @@ Error OS_X11::initialize(const VideoMode &p_desired, int p_video_driver, int p_a
#endif
_ensure_user_data_dir();
- power_manager = memnew(PowerX11);
-
if (p_desired.layered) {
set_window_per_pixel_transparency_enabled(true);
}
@@ -669,14 +722,8 @@ bool OS_X11::refresh_device_info() {
int range_max_x = 0;
int range_max_y = 0;
int pressure_resolution = 0;
- int pressure_min = 0;
- int pressure_max = 0;
int tilt_resolution_x = 0;
int tilt_resolution_y = 0;
- int tilt_range_min_x = 0;
- int tilt_range_min_y = 0;
- int tilt_range_max_x = 0;
- int tilt_range_max_y = 0;
for (int j = 0; j < dev->num_classes; j++) {
#ifdef TOUCH_ENABLED
if (dev->classes[j]->type == XITouchClass && ((XITouchClassInfo *)dev->classes[j])->mode == XIDirectTouch) {
@@ -697,17 +744,14 @@ bool OS_X11::refresh_device_info() {
range_max_y = class_info->max;
absolute_mode = true;
} else if (class_info->number == VALUATOR_PRESSURE && class_info->mode == XIModeAbsolute) {
- pressure_resolution = class_info->resolution;
- pressure_min = class_info->min;
- pressure_max = class_info->max;
+ pressure_resolution = (class_info->max - class_info->min);
+ if (pressure_resolution == 0) pressure_resolution = 1;
} else if (class_info->number == VALUATOR_TILTX && class_info->mode == XIModeAbsolute) {
- tilt_resolution_x = class_info->resolution;
- tilt_range_min_x = class_info->min;
- tilt_range_max_x = class_info->max;
+ tilt_resolution_x = (class_info->max - class_info->min);
+ if (tilt_resolution_x == 0) tilt_resolution_x = 1;
} else if (class_info->number == VALUATOR_TILTY && class_info->mode == XIModeAbsolute) {
- tilt_resolution_y = class_info->resolution;
- tilt_range_min_y = class_info->min;
- tilt_range_max_y = class_info->max;
+ tilt_resolution_y = (class_info->max - class_info->min);
+ if (tilt_resolution_y == 0) tilt_resolution_y = 1;
}
}
}
@@ -728,15 +772,6 @@ bool OS_X11::refresh_device_info() {
print_verbose("XInput: Absolute pointing device: " + String(dev->name));
}
- if (pressure_resolution <= 0) {
- pressure_resolution = (pressure_max - pressure_min);
- }
- if (tilt_resolution_x <= 0) {
- tilt_resolution_x = (tilt_range_max_x - tilt_range_min_x);
- }
- if (tilt_resolution_y <= 0) {
- tilt_resolution_y = (tilt_range_max_y - tilt_range_min_y);
- }
xi.pressure = 0;
xi.pen_devices[dev->deviceid] = Vector3(pressure_resolution, tilt_resolution_x, tilt_resolution_y);
}
@@ -832,9 +867,26 @@ void OS_X11::finalize() {
cursors_cache.clear();
visual_server->finish();
memdelete(visual_server);
- //memdelete(rasterizer);
- memdelete(power_manager);
+#if defined(OPENGL_ENABLED)
+ if (video_driver_index == VIDEO_DRIVER_GLES2) {
+
+ if (context_gles2)
+ memdelete(context_gles2);
+ }
+#endif
+#if defined(VULKAN_ENABLED)
+ if (video_driver_index == VIDEO_DRIVER_VULKAN) {
+
+ if (rendering_device_vulkan) {
+ rendering_device_vulkan->finalize();
+ memdelete(rendering_device_vulkan);
+ }
+
+ if (context_vulkan)
+ memdelete(context_vulkan);
+ }
+#endif
if (xrandr_handle)
dlclose(xrandr_handle);
@@ -842,9 +894,6 @@ void OS_X11::finalize() {
XUnmapWindow(x11_display, x11_window);
XDestroyWindow(x11_display, x11_window);
-#if defined(OPENGL_ENABLED)
- memdelete(context_gl);
-#endif
for (int i = 0; i < CURSOR_MAX; i++) {
if (cursors[i] != None)
XFreeCursor(x11_display, cursors[i]);
@@ -1429,11 +1478,15 @@ void OS_X11::set_window_fullscreen(bool p_enabled) {
set_window_maximized(true);
}
set_wm_fullscreen(p_enabled);
- if (!p_enabled && !current_videomode.always_on_top) {
+ if (!p_enabled && current_videomode.always_on_top) {
// Restore
set_window_maximized(false);
}
-
+ if (!p_enabled) {
+ set_window_position(last_position_before_fs);
+ } else {
+ last_position_before_fs = get_window_position();
+ }
current_videomode.fullscreen = p_enabled;
}
@@ -1835,6 +1888,8 @@ void OS_X11::handle_key_event(XKeyEvent *p_event, bool p_echo) {
if (status == XLookupChars) {
bool keypress = xkeyevent->type == KeyPress;
unsigned int keycode = KeyMappingX11::get_keycode(keysym_keycode);
+ unsigned int physical_keycode = KeyMappingX11::get_scancode(xkeyevent->keycode);
+
if (keycode >= 'a' && keycode <= 'z')
keycode -= 'a' - 'A';
@@ -1843,23 +1898,29 @@ void OS_X11::handle_key_event(XKeyEvent *p_event, bool p_echo) {
for (int i = 0; i < tmp.length(); i++) {
Ref<InputEventKey> k;
k.instance();
- if (keycode == 0 && tmp[i] == 0) {
+ if (physical_keycode == 0 && keycode == 0 && tmp[i] == 0) {
continue;
}
+ if (keycode == 0)
+ keycode = physical_keycode;
+
get_key_modifier_state(xkeyevent->state, k);
k->set_unicode(tmp[i]);
k->set_pressed(keypress);
- k->set_scancode(keycode);
+ k->set_keycode(keycode);
+
+ k->set_physical_keycode(physical_keycode);
k->set_echo(false);
- if (k->get_scancode() == KEY_BACKTAB) {
+ if (k->get_keycode() == KEY_BACKTAB) {
//make it consistent across platforms.
- k->set_scancode(KEY_TAB);
+ k->set_keycode(KEY_TAB);
+ k->set_physical_keycode(KEY_TAB);
k->set_shift(true);
}
@@ -1889,6 +1950,7 @@ void OS_X11::handle_key_event(XKeyEvent *p_event, bool p_echo) {
// keysym, so it works in all platforms the same.
unsigned int keycode = KeyMappingX11::get_keycode(keysym_keycode);
+ unsigned int physical_keycode = KeyMappingX11::get_scancode(xkeyevent->keycode);
/* Phase 3, obtain a unicode character from the keysym */
@@ -1908,9 +1970,12 @@ void OS_X11::handle_key_event(XKeyEvent *p_event, bool p_echo) {
bool keypress = xkeyevent->type == KeyPress;
- if (keycode == 0 && unicode == 0)
+ if (physical_keycode == 0 && keycode == 0 && unicode == 0)
return;
+ if (keycode == 0)
+ keycode = physical_keycode;
+
/* Phase 5, determine modifier mask */
// No problems here, except I had no way to
@@ -1947,8 +2012,10 @@ void OS_X11::handle_key_event(XKeyEvent *p_event, bool p_echo) {
// is correct, but the xorg developers are
// not very helpful today.
- ::Time tresh = ABSDIFF(peek_event.xkey.time, xkeyevent->time);
- if (peek_event.type == KeyPress && tresh < 5) {
+#define ABSDIFF(x, y) (((x) < (y)) ? ((y) - (x)) : ((x) - (y)))
+ ::Time threshold = ABSDIFF(peek_event.xkey.time, xkeyevent->time);
+#undef ABSDIFF
+ if (peek_event.type == KeyPress && threshold < 5) {
KeySym rk;
XLookupString((XKeyEvent *)&peek_event, str, 256, &rk, NULL);
if (rk == keysym_keycode) {
@@ -1972,37 +2039,39 @@ void OS_X11::handle_key_event(XKeyEvent *p_event, bool p_echo) {
if (keycode >= 'a' && keycode <= 'z')
keycode -= 'a' - 'A';
- k->set_scancode(keycode);
+ k->set_keycode(keycode);
+ k->set_physical_keycode(physical_keycode);
k->set_unicode(unicode);
k->set_echo(p_echo);
- if (k->get_scancode() == KEY_BACKTAB) {
+ if (k->get_keycode() == KEY_BACKTAB) {
//make it consistent across platforms.
- k->set_scancode(KEY_TAB);
+ k->set_keycode(KEY_TAB);
+ k->set_physical_keycode(KEY_TAB);
k->set_shift(true);
}
//don't set mod state if modifier keys are released by themselves
//else event.is_action() will not work correctly here
if (!k->is_pressed()) {
- if (k->get_scancode() == KEY_SHIFT)
+ if (k->get_keycode() == KEY_SHIFT)
k->set_shift(false);
- else if (k->get_scancode() == KEY_CONTROL)
+ else if (k->get_keycode() == KEY_CONTROL)
k->set_control(false);
- else if (k->get_scancode() == KEY_ALT)
+ else if (k->get_keycode() == KEY_ALT)
k->set_alt(false);
- else if (k->get_scancode() == KEY_META)
+ else if (k->get_keycode() == KEY_META)
k->set_metakey(false);
}
- bool last_is_pressed = Input::get_singleton()->is_key_pressed(k->get_scancode());
+ bool last_is_pressed = Input::get_singleton()->is_key_pressed(k->get_keycode());
if (k->is_pressed()) {
if (last_is_pressed) {
k->set_echo(true);
}
}
- //printf("key: %x\n",k->get_scancode());
+ //printf("key: %x\n",k->get_keycode());
input->accumulate_input_event(k);
}
@@ -2082,6 +2151,12 @@ void OS_X11::_window_changed(XEvent *event) {
current_videomode.width = event->xconfigure.width;
current_videomode.height = event->xconfigure.height;
+
+#if defined(VULKAN_ENABLED)
+ if (video_driver_index == VIDEO_DRIVER_VULKAN) {
+ context_vulkan->window_resize(0, current_videomode.width, current_videomode.height);
+ }
+#endif
}
void OS_X11::process_xevents() {
@@ -2959,7 +3034,7 @@ void OS_X11::set_custom_mouse_cursor(const RES &p_cursor, CursorShape p_shape, c
if (p_cursor.is_valid()) {
- Map<CursorShape, Vector<Variant> >::Element *cursor_c = cursors_cache.find(p_shape);
+ Map<CursorShape, Vector<Variant>>::Element *cursor_c = cursors_cache.find(p_shape);
if (cursor_c) {
if (cursor_c->get()[0] == p_cursor && cursor_c->get()[1] == p_hotspot) {
@@ -2970,7 +3045,7 @@ void OS_X11::set_custom_mouse_cursor(const RES &p_cursor, CursorShape p_shape, c
cursors_cache.erase(p_shape);
}
- Ref<Texture> texture = p_cursor;
+ Ref<Texture2D> texture = p_cursor;
Ref<AtlasTexture> atlas_texture = p_cursor;
Ref<Image> image;
Size2 texture_size;
@@ -3017,8 +3092,6 @@ void OS_X11::set_custom_mouse_cursor(const RES &p_cursor, CursorShape p_shape, c
// allocate memory to contain the whole file
cursor_image->pixels = (XcursorPixel *)memalloc(size);
- image->lock();
-
for (XcursorPixel index = 0; index < image_size; index++) {
int row_index = floor(index / texture_size.width) + atlas_rect.position.y;
int column_index = (index % int(texture_size.width)) + atlas_rect.position.x;
@@ -3031,8 +3104,6 @@ void OS_X11::set_custom_mouse_cursor(const RES &p_cursor, CursorShape p_shape, c
*(cursor_image->pixels + index) = image->get_pixel(column_index, row_index).to_argb32();
}
- image->unlock();
-
ERR_FAIL_COND(cursor_image->pixels == NULL);
// Save it for a further usage
@@ -3066,24 +3137,33 @@ void OS_X11::set_custom_mouse_cursor(const RES &p_cursor, CursorShape p_shape, c
}
void OS_X11::release_rendering_thread() {
-
#if defined(OPENGL_ENABLED)
- context_gl->release_current();
+ if (video_driver_index == VIDEO_DRIVER_GLES2) {
+ context_gles2->release_current();
+ }
#endif
}
void OS_X11::make_rendering_thread() {
-
#if defined(OPENGL_ENABLED)
- context_gl->make_current();
+ if (video_driver_index == VIDEO_DRIVER_GLES2) {
+ context_gles2->make_current();
+ }
#endif
}
void OS_X11::swap_buffers() {
-
#if defined(OPENGL_ENABLED)
- context_gl->swap_buffers();
+ if (video_driver_index == VIDEO_DRIVER_GLES2) {
+ context_gles2->swap_buffers();
+ }
#endif
+ /* not needed for now
+#if defined(VULKAN_ENABLED)
+ if (video_driver_index == VIDEO_DRIVER_VULKAN) {
+ context_vulkan->swap_buffers();
+ }
+#endif*/
}
void OS_X11::alert(const String &p_alert, const String &p_title) {
@@ -3201,10 +3281,10 @@ void OS_X11::set_icon(const Ref<Image> &p_icon) {
pd.write[0] = w;
pd.write[1] = h;
- PoolVector<uint8_t>::Read r = img->get_data().read();
+ const uint8_t *r = img->get_data().ptr();
long *wr = &pd.write[2];
- uint8_t const *pr = r.ptr();
+ uint8_t const *pr = r;
for (int i = 0; i < w * h; i++) {
long v = 0;
@@ -3271,19 +3351,13 @@ String OS_X11::get_joy_guid(int p_device) const {
void OS_X11::_set_use_vsync(bool p_enable) {
#if defined(OPENGL_ENABLED)
- if (context_gl)
- context_gl->set_use_vsync(p_enable);
+ if (video_driver_index == VIDEO_DRIVER_GLES2) {
+ if (context_gles2)
+ context_gles2->set_use_vsync(p_enable);
+ }
#endif
}
-/*
-bool OS_X11::is_vsync_enabled() const {
- if (context_gl)
- return context_gl->is_using_vsync();
-
- return true;
-}
-*/
void OS_X11::set_context(int p_context) {
XClassHint *classHint = XAllocClassHint();
@@ -3323,18 +3397,6 @@ void OS_X11::set_context(int p_context) {
}
}
-OS::PowerState OS_X11::get_power_state() {
- return power_manager->get_power_state();
-}
-
-int OS_X11::get_power_seconds_left() {
- return power_manager->get_power_seconds_left();
-}
-
-int OS_X11::get_power_percent_left() {
- return power_manager->get_power_percent_left();
-}
-
void OS_X11::disable_crash_handler() {
crash_handler.disable();
}
@@ -3402,7 +3464,7 @@ Error OS_X11::move_to_trash(const String &p_path) {
// Issue an error if none of the previous locations is appropriate for the trash can.
if (trash_can == "") {
- ERR_PRINTS("move_to_trash: Could not determine the trash can location");
+ ERR_PRINT("move_to_trash: Could not determine the trash can location");
return FAILED;
}
@@ -3413,7 +3475,7 @@ Error OS_X11::move_to_trash(const String &p_path) {
// Issue an error if trash can is not created proprely.
if (err != OK) {
- ERR_PRINTS("move_to_trash: Could not create the trash can \"" + trash_can + "\"");
+ ERR_PRINT("move_to_trash: Could not create the trash can \"" + trash_can + "\"");
return err;
}
@@ -3427,7 +3489,7 @@ Error OS_X11::move_to_trash(const String &p_path) {
// Issue an error if "mv" failed to move the given resource to the trash can.
if (err != OK || retval != 0) {
- ERR_PRINTS("move_to_trash: Could not move the resource \"" + p_path + "\" to the trash can \"" + trash_can + "\"");
+ ERR_PRINT("move_to_trash: Could not move the resource \"" + p_path + "\" to the trash can \"" + trash_can + "\"");
return FAILED;
}
@@ -3502,4 +3564,5 @@ OS_X11::OS_X11() {
window_focused = true;
xim_style = 0L;
mouse_mode = MOUSE_MODE_VISIBLE;
+ last_position_before_fs = Vector2();
}
diff --git a/platform/x11/os_x11.h b/platform/x11/os_x11.h
index 01e5aac3df..997a6cc053 100644
--- a/platform/x11/os_x11.h
+++ b/platform/x11/os_x11.h
@@ -31,7 +31,6 @@
#ifndef OS_X11_H
#define OS_X11_H
-#include "context_gl_x11.h"
#include "core/os/input.h"
#include "crash_handler_x11.h"
#include "drivers/alsa/audio_driver_alsa.h"
@@ -40,11 +39,18 @@
#include "drivers/unix/os_unix.h"
#include "joypad_linux.h"
#include "main/input_default.h"
-#include "power_x11.h"
#include "servers/audio_server.h"
#include "servers/visual/rasterizer.h"
#include "servers/visual_server.h"
-//#include "servers/visual/visual_server_wrap_mt.h"
+
+#if defined(OPENGL_ENABLED)
+#include "context_gl_x11.h"
+#endif
+
+#if defined(VULKAN_ENABLED)
+#include "drivers/vulkan/rendering_device_vulkan.h"
+#include "platform/x11/vulkan_context_x11.h"
+#endif
#include <X11/Xcursor/Xcursor.h>
#include <X11/Xlib.h>
@@ -92,8 +98,13 @@ class OS_X11 : public OS_Unix {
int xdnd_version;
#if defined(OPENGL_ENABLED)
- ContextGL_X11 *context_gl;
+ ContextGL_X11 *context_gles2;
+#endif
+#if defined(VULKAN_ENABLED)
+ VulkanContextX11 *context_vulkan;
+ RenderingDeviceVulkan *rendering_device_vulkan;
#endif
+
//Rasterizer *rasterizer;
VisualServer *visual_server;
VideoMode current_videomode;
@@ -115,6 +126,7 @@ class OS_X11 : public OS_Unix {
// IME
bool im_active;
Vector2 im_position;
+ Vector2 last_position_before_fs;
Size2 min_size;
Size2 max_size;
@@ -167,7 +179,7 @@ class OS_X11 : public OS_Unix {
Cursor cursors[CURSOR_MAX];
Cursor null_cursor;
CursorShape current_cursor;
- Map<CursorShape, Vector<Variant> > cursors_cache;
+ Map<CursorShape, Vector<Variant>> cursors_cache;
InputDefault *input;
@@ -187,8 +199,6 @@ class OS_X11 : public OS_Unix {
AudioDriverPulseAudio driver_pulseaudio;
#endif
- PowerX11 *power_manager;
-
bool layered_window;
CrashHandler crash_handler;
@@ -310,10 +320,6 @@ public:
virtual void _set_use_vsync(bool p_enable);
//virtual bool is_vsync_enabled() const;
- virtual OS::PowerState get_power_state();
- virtual int get_power_seconds_left();
- virtual int get_power_percent_left();
-
virtual bool _check_internal_feature_support(const String &p_feature);
virtual void force_process_input();
diff --git a/platform/x11/platform_config.h b/platform/x11/platform_config.h
index c905ddb236..ac30519132 100644
--- a/platform/x11/platform_config.h
+++ b/platform/x11/platform_config.h
@@ -36,5 +36,4 @@
#define PTHREAD_BSD_SET_NAME
#endif
-#define GLES3_INCLUDE_H "thirdparty/glad/glad/glad.h"
#define GLES2_INCLUDE_H "thirdparty/glad/glad/glad.h"
diff --git a/platform/x11/power_x11.cpp b/platform/x11/power_x11.cpp
deleted file mode 100644
index 5ac5e8e87b..0000000000
--- a/platform/x11/power_x11.cpp
+++ /dev/null
@@ -1,577 +0,0 @@
-/*************************************************************************/
-/* power_x11.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. */
-/*************************************************************************/
-
-/*
-Adapted from corresponding SDL 2.0 code.
-*/
-
-/*
- Simple DirectMedia Layer
- Copyright (C) 1997-2017 Sam Lantinga <slouken@libsdl.org>
-
- This software is provided 'as-is', without any express or implied
- warranty. In no event will the authors be held liable for any damages
- arising from the use of this software.
-
- Permission is granted to anyone to use this software for any purpose,
- including commercial applications, and to alter it and redistribute it
- freely, subject to the following restrictions:
-
- 1. The origin of this software must not be misrepresented; you must not
- claim that you wrote the original software. If you use this software
- in a product, an acknowledgment in the product documentation would be
- appreciated but is not required.
- 2. Altered source versions must be plainly marked as such, and must not be
- misrepresented as being the original software.
- 3. This notice may not be removed or altered from any source distribution.
-*/
-
-#include "power_x11.h"
-
-#include <stdio.h>
-#include <unistd.h>
-
-#include "core/error_macros.h"
-#include <dirent.h>
-#include <fcntl.h>
-#include <sys/stat.h>
-#include <sys/types.h>
-
-// CODE CHUNK IMPORTED FROM SDL 2.0
-
-static const char *proc_apm_path = "/proc/apm";
-static const char *proc_acpi_battery_path = "/proc/acpi/battery";
-static const char *proc_acpi_ac_adapter_path = "/proc/acpi/ac_adapter";
-static const char *sys_class_power_supply_path = "/sys/class/power_supply";
-
-FileAccessRef PowerX11::open_power_file(const char *base, const char *node, const char *key) {
- String path = String(base) + String("/") + String(node) + String("/") + String(key);
- FileAccessRef f = FileAccess::open(path, FileAccess::READ);
- return f;
-}
-
-bool PowerX11::read_power_file(const char *base, const char *node, const char *key, char *buf, size_t buflen) {
- ssize_t br = 0;
- FileAccessRef fd = open_power_file(base, node, key);
- if (!fd) {
- return false;
- }
- br = fd->get_buffer(reinterpret_cast<uint8_t *>(buf), buflen - 1);
- fd->close();
- if (br < 0) {
- return false;
- }
- buf[br] = '\0'; // null-terminate the string
- return true;
-}
-
-bool PowerX11::make_proc_acpi_key_val(char **_ptr, char **_key, char **_val) {
- char *ptr = *_ptr;
-
- while (*ptr == ' ') {
- ptr++; /* skip whitespace. */
- }
-
- if (*ptr == '\0') {
- return false; /* EOF. */
- }
-
- *_key = ptr;
-
- while ((*ptr != ':') && (*ptr != '\0')) {
- ptr++;
- }
-
- if (*ptr == '\0') {
- return false; /* (unexpected) EOF. */
- }
-
- *(ptr++) = '\0'; /* terminate the key. */
-
- while (*ptr == ' ') {
- ptr++; /* skip whitespace. */
- }
-
- if (*ptr == '\0') {
- return false; /* (unexpected) EOF. */
- }
-
- *_val = ptr;
-
- while ((*ptr != '\n') && (*ptr != '\0')) {
- ptr++;
- }
-
- if (*ptr != '\0') {
- *(ptr++) = '\0'; /* terminate the value. */
- }
-
- *_ptr = ptr; /* store for next time. */
- return true;
-}
-
-void PowerX11::check_proc_acpi_battery(const char *node, bool *have_battery, bool *charging) {
- const char *base = proc_acpi_battery_path;
- char info[1024];
- char state[1024];
- char *ptr = NULL;
- char *key = NULL;
- char *val = NULL;
- bool charge = false;
- bool choose = false;
- int maximum = -1;
- int remaining = -1;
- int secs = -1;
- int pct = -1;
-
- if (!read_power_file(base, node, "state", state, sizeof(state))) {
- return;
- } else {
- if (!read_power_file(base, node, "info", info, sizeof(info)))
- return;
- }
-
- ptr = &state[0];
- while (make_proc_acpi_key_val(&ptr, &key, &val)) {
- if (String(key) == "present") {
- if (String(val) == "yes") {
- *have_battery = true;
- }
- } else if (String(key) == "charging state") {
- /* !!! FIXME: what exactly _does_ charging/discharging mean? */
- if (String(val) == "charging/discharging") {
- charge = true;
- } else if (String(val) == "charging") {
- charge = true;
- }
- } else if (String(key) == "remaining capacity") {
- String sval = val;
- const int cvt = sval.to_int();
- remaining = cvt;
- }
- }
-
- ptr = &info[0];
- while (make_proc_acpi_key_val(&ptr, &key, &val)) {
- if (String(key) == "design capacity") {
- String sval = val;
- const int cvt = sval.to_int();
- maximum = cvt;
- }
- }
-
- if ((maximum >= 0) && (remaining >= 0)) {
- pct = (int)((((float)remaining) / ((float)maximum)) * 100.0f);
- if (pct < 0) {
- pct = 0;
- } else if (pct > 100) {
- pct = 100;
- }
- }
-
- /* !!! FIXME: calculate (secs). */
-
- /*
- * We pick the battery that claims to have the most minutes left.
- * (failing a report of minutes, we'll take the highest percent.)
- */
- // -- GODOT start --
- //if ((secs < 0) && (this->nsecs_left < 0)) {
- if (this->nsecs_left < 0) {
- // -- GODOT end --
- if ((pct < 0) && (this->percent_left < 0)) {
- choose = true; /* at least we know there's a battery. */
- }
- if (pct > this->percent_left) {
- choose = true;
- }
- } else if (secs > this->nsecs_left) {
- choose = true;
- }
-
- if (choose) {
- this->nsecs_left = secs;
- this->percent_left = pct;
- *charging = charge;
- }
-}
-
-void PowerX11::check_proc_acpi_ac_adapter(const char *node, bool *have_ac) {
- const char *base = proc_acpi_ac_adapter_path;
- char state[256];
- char *ptr = NULL;
- char *key = NULL;
- char *val = NULL;
-
- if (!read_power_file(base, node, "state", state, sizeof(state))) {
- return;
- }
-
- ptr = &state[0];
- while (make_proc_acpi_key_val(&ptr, &key, &val)) {
- String skey = key;
- if (skey == "state") {
- String sval = val;
- if (sval == "on-line") {
- *have_ac = true;
- }
- }
- }
-}
-
-bool PowerX11::GetPowerInfo_Linux_proc_acpi() {
- String node;
- DirAccess *dirp = DirAccess::create(DirAccess::ACCESS_FILESYSTEM);
- bool have_battery = false;
- bool have_ac = false;
- bool charging = false;
-
- this->nsecs_left = -1;
- this->percent_left = -1;
- this->power_state = OS::POWERSTATE_UNKNOWN;
-
- dirp->change_dir(proc_acpi_battery_path);
- Error err = dirp->list_dir_begin();
-
- if (err != OK) {
- return false; /* can't use this interface. */
- } else {
- node = dirp->get_next();
- while (node != "") {
- check_proc_acpi_battery(node.utf8().get_data(), &have_battery, &charging /*, seconds, percent*/);
- node = dirp->get_next();
- }
- }
- dirp->change_dir(proc_acpi_ac_adapter_path);
- err = dirp->list_dir_begin();
- if (err != OK) {
- return false; /* can't use this interface. */
- } else {
- node = dirp->get_next();
- while (node != "") {
- check_proc_acpi_ac_adapter(node.utf8().get_data(), &have_ac);
- node = dirp->get_next();
- }
- }
-
- if (!have_battery) {
- this->power_state = OS::POWERSTATE_NO_BATTERY;
- } else if (charging) {
- this->power_state = OS::POWERSTATE_CHARGING;
- } else if (have_ac) {
- this->power_state = OS::POWERSTATE_CHARGED;
- } else {
- this->power_state = OS::POWERSTATE_ON_BATTERY;
- }
-
- memdelete(dirp);
- return true; /* definitive answer. */
-}
-
-bool PowerX11::next_string(char **_ptr, char **_str) {
- char *ptr = *_ptr;
- char *str = *_str;
-
- while (*ptr == ' ') { /* skip any spaces... */
- ptr++;
- }
-
- if (*ptr == '\0') {
- return false;
- }
-
- str = ptr;
- while ((*ptr != ' ') && (*ptr != '\n') && (*ptr != '\0'))
- ptr++;
-
- if (*ptr != '\0')
- *(ptr++) = '\0';
-
- *_str = str;
- *_ptr = ptr;
- return true;
-}
-
-bool PowerX11::int_string(char *str, int *val) {
- String sval = str;
- *val = sval.to_int();
- return (*str != '\0');
-}
-
-/* http://lxr.linux.no/linux+v2.6.29/drivers/char/apm-emulation.c */
-bool PowerX11::GetPowerInfo_Linux_proc_apm() {
- bool need_details = false;
- int ac_status = 0;
- int battery_status = 0;
- int battery_flag = 0;
- int battery_percent = 0;
- int battery_time = 0;
- FileAccessRef fd = FileAccess::open(proc_apm_path, FileAccess::READ);
- char buf[128];
- char *ptr = &buf[0];
- char *str = NULL;
- ssize_t br;
-
- if (!fd) {
- return false; /* can't use this interface. */
- }
-
- br = fd->get_buffer(reinterpret_cast<uint8_t *>(buf), sizeof(buf) - 1);
- fd->close();
-
- if (br < 0) {
- return false;
- }
-
- buf[br] = '\0'; /* null-terminate the string. */
- if (!next_string(&ptr, &str)) { /* driver version */
- return false;
- }
- if (!next_string(&ptr, &str)) { /* BIOS version */
- return false;
- }
- if (!next_string(&ptr, &str)) { /* APM flags */
- return false;
- }
-
- if (!next_string(&ptr, &str)) { /* AC line status */
- return false;
- } else if (!int_string(str, &ac_status)) {
- return false;
- }
-
- if (!next_string(&ptr, &str)) { /* battery status */
- return false;
- } else if (!int_string(str, &battery_status)) {
- return false;
- }
- if (!next_string(&ptr, &str)) { /* battery flag */
- return false;
- } else if (!int_string(str, &battery_flag)) {
- return false;
- }
- if (!next_string(&ptr, &str)) { /* remaining battery life percent */
- return false;
- }
- String sstr = str;
- if (sstr[sstr.length() - 1] == '%') {
- sstr[sstr.length() - 1] = '\0';
- }
- if (!int_string(str, &battery_percent)) {
- return false;
- }
-
- if (!next_string(&ptr, &str)) { /* remaining battery life time */
- return false;
- } else if (!int_string(str, &battery_time)) {
- return false;
- }
-
- if (!next_string(&ptr, &str)) { /* remaining battery life time units */
- return false;
- } else if (String(str) == "min") {
- battery_time *= 60;
- }
-
- if (battery_flag == 0xFF) { /* unknown state */
- this->power_state = OS::POWERSTATE_UNKNOWN;
- } else if (battery_flag & (1 << 7)) { /* no battery */
- this->power_state = OS::POWERSTATE_NO_BATTERY;
- } else if (battery_flag & (1 << 3)) { /* charging */
- this->power_state = OS::POWERSTATE_CHARGING;
- need_details = true;
- } else if (ac_status == 1) {
- this->power_state = OS::POWERSTATE_CHARGED; /* on AC, not charging. */
- need_details = true;
- } else {
- this->power_state = OS::POWERSTATE_ON_BATTERY;
- need_details = true;
- }
-
- this->percent_left = -1;
- this->nsecs_left = -1;
- if (need_details) {
- const int pct = battery_percent;
- const int secs = battery_time;
-
- if (pct >= 0) { /* -1 == unknown */
- this->percent_left = (pct > 100) ? 100 : pct; /* clamp between 0%, 100% */
- }
- if (secs >= 0) { /* -1 == unknown */
- this->nsecs_left = secs;
- }
- }
-
- return true;
-}
-
-/* !!! FIXME: implement d-bus queries to org.freedesktop.UPower. */
-
-bool PowerX11::GetPowerInfo_Linux_sys_class_power_supply(/*PowerState *state, int *seconds, int *percent*/) {
- const char *base = sys_class_power_supply_path;
- String name;
-
- DirAccess *dirp = DirAccess::create(DirAccess::ACCESS_FILESYSTEM);
- dirp->change_dir(base);
- Error err = dirp->list_dir_begin();
-
- if (err != OK) {
- return false;
- }
-
- this->power_state = OS::POWERSTATE_NO_BATTERY; /* assume we're just plugged in. */
- this->nsecs_left = -1;
- this->percent_left = -1;
-
- name = dirp->get_next();
-
- while (name != "") {
- bool choose = false;
- char str[64];
- OS::PowerState st;
- int secs;
- int pct;
-
- if ((name == ".") || (name == "..")) {
- name = dirp->get_next();
- continue; //skip these, of course.
- } else {
- if (!read_power_file(base, name.utf8().get_data(), "type", str, sizeof(str))) {
- name = dirp->get_next();
- continue; // Don't know _what_ we're looking at. Give up on it.
- } else {
- if (String(str) != "Battery\n") {
- name = dirp->get_next();
- continue; // we don't care about UPS and such.
- }
- }
- }
-
- /* some drivers don't offer this, so if it's not explicitly reported assume it's present. */
- if (read_power_file(base, name.utf8().get_data(), "present", str, sizeof(str)) && (String(str) == "0\n")) {
- st = OS::POWERSTATE_NO_BATTERY;
- } else if (!read_power_file(base, name.utf8().get_data(), "status", str, sizeof(str))) {
- st = OS::POWERSTATE_UNKNOWN; /* uh oh */
- } else if (String(str) == "Charging\n") {
- st = OS::POWERSTATE_CHARGING;
- } else if (String(str) == "Discharging\n") {
- st = OS::POWERSTATE_ON_BATTERY;
- } else if ((String(str) == "Full\n") || (String(str) == "Not charging\n")) {
- st = OS::POWERSTATE_CHARGED;
- } else {
- st = OS::POWERSTATE_UNKNOWN; /* uh oh */
- }
-
- if (!read_power_file(base, name.utf8().get_data(), "capacity", str, sizeof(str))) {
- pct = -1;
- } else {
- pct = String(str).to_int();
- pct = (pct > 100) ? 100 : pct; /* clamp between 0%, 100% */
- }
-
- if (!read_power_file(base, name.utf8().get_data(), "time_to_empty_now", str, sizeof(str))) {
- secs = -1;
- } else {
- secs = String(str).to_int();
- secs = (secs <= 0) ? -1 : secs; /* 0 == unknown */
- }
-
- /*
- * We pick the battery that claims to have the most minutes left.
- * (failing a report of minutes, we'll take the highest percent.)
- */
- if ((secs < 0) && (this->nsecs_left < 0)) {
- if ((pct < 0) && (this->percent_left < 0)) {
- choose = true; /* at least we know there's a battery. */
- } else if (pct > this->percent_left) {
- choose = true;
- }
- } else if (secs > this->nsecs_left) {
- choose = true;
- }
-
- if (choose) {
- this->nsecs_left = secs;
- this->percent_left = pct;
- this->power_state = st;
- }
-
- name = dirp->get_next();
- }
-
- memdelete(dirp);
- return true; /* don't look any further*/
-}
-
-bool PowerX11::UpdatePowerInfo() {
- if (GetPowerInfo_Linux_sys_class_power_supply()) { // try method 1
- return true;
- }
- if (GetPowerInfo_Linux_proc_acpi()) { // try further
- return true;
- }
- if (GetPowerInfo_Linux_proc_apm()) { // try even further
- return true;
- }
- return false;
-}
-
-PowerX11::PowerX11() :
- nsecs_left(-1),
- percent_left(-1),
- power_state(OS::POWERSTATE_UNKNOWN) {
-}
-
-PowerX11::~PowerX11() {
-}
-
-OS::PowerState PowerX11::get_power_state() {
- if (UpdatePowerInfo()) {
- return power_state;
- } else {
- return OS::POWERSTATE_UNKNOWN;
- }
-}
-
-int PowerX11::get_power_seconds_left() {
- if (UpdatePowerInfo()) {
- return nsecs_left;
- } else {
- return -1;
- }
-}
-
-int PowerX11::get_power_percent_left() {
- if (UpdatePowerInfo()) {
- return percent_left;
- } else {
- return -1;
- }
-}
diff --git a/platform/x11/power_x11.h b/platform/x11/power_x11.h
deleted file mode 100644
index 76f20c68e8..0000000000
--- a/platform/x11/power_x11.h
+++ /dev/null
@@ -1,66 +0,0 @@
-/*************************************************************************/
-/* power_x11.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 POWER_X11_H
-#define POWER_X11_H
-
-#include "core/os/dir_access.h"
-#include "core/os/file_access.h"
-#include "core/os/os.h"
-
-class PowerX11 {
-
-private:
- int nsecs_left;
- int percent_left;
- OS::PowerState power_state;
-
- FileAccessRef open_power_file(const char *base, const char *node, const char *key);
- bool read_power_file(const char *base, const char *node, const char *key, char *buf, size_t buflen);
- bool make_proc_acpi_key_val(char **_ptr, char **_key, char **_val);
- void check_proc_acpi_battery(const char *node, bool *have_battery, bool *charging);
- void check_proc_acpi_ac_adapter(const char *node, bool *have_ac);
- bool GetPowerInfo_Linux_proc_acpi();
- bool next_string(char **_ptr, char **_str);
- bool int_string(char *str, int *val);
- bool GetPowerInfo_Linux_proc_apm();
- bool GetPowerInfo_Linux_sys_class_power_supply();
- bool UpdatePowerInfo();
-
-public:
- PowerX11();
- virtual ~PowerX11();
-
- OS::PowerState get_power_state();
- int get_power_seconds_left();
- int get_power_percent_left();
-};
-
-#endif // POWER_X11_H
diff --git a/platform/x11/vulkan_context_x11.cpp b/platform/x11/vulkan_context_x11.cpp
new file mode 100644
index 0000000000..602dbc77a2
--- /dev/null
+++ b/platform/x11/vulkan_context_x11.cpp
@@ -0,0 +1,57 @@
+/*************************************************************************/
+/* vulkan_context_x11.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 "vulkan_context_x11.h"
+#include <vulkan/vulkan_xlib.h>
+
+const char *VulkanContextX11::_get_platform_surface_extension() const {
+ return VK_KHR_XLIB_SURFACE_EXTENSION_NAME;
+}
+
+int VulkanContextX11::window_create(::Window p_window, Display *p_display, int p_width, int p_height) {
+
+ VkXlibSurfaceCreateInfoKHR createInfo;
+ createInfo.sType = VK_STRUCTURE_TYPE_XLIB_SURFACE_CREATE_INFO_KHR;
+ createInfo.pNext = NULL;
+ createInfo.flags = 0;
+ createInfo.dpy = p_display;
+ createInfo.window = p_window;
+
+ VkSurfaceKHR surface;
+ VkResult err = vkCreateXlibSurfaceKHR(_get_instance(), &createInfo, NULL, &surface);
+ ERR_FAIL_COND_V(err, -1);
+ return _window_create(surface, p_width, p_height);
+}
+
+VulkanContextX11::VulkanContextX11() {
+}
+
+VulkanContextX11::~VulkanContextX11() {
+}
diff --git a/platform/iphone/semaphore_iphone.h b/platform/x11/vulkan_context_x11.h
index 9356c65f1e..573f994ea6 100644
--- a/platform/iphone/semaphore_iphone.h
+++ b/platform/x11/vulkan_context_x11.h
@@ -1,5 +1,5 @@
/*************************************************************************/
-/* semaphore_iphone.h */
+/* vulkan_context_x11.h */
/*************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
@@ -28,32 +28,21 @@
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/
-#ifndef SEMAPHORE_IPHONE_H
-#define SEMAPHORE_IPHONE_H
+#ifndef VULKAN_DEVICE_X11_H
+#define VULKAN_DEVICE_X11_H
-struct cgsem {
- int pipefd[2];
-};
-
-typedef struct cgsem cgsem_t;
-
-#include "core/os/semaphore.h"
+#include "drivers/vulkan/vulkan_context.h"
+#include <X11/Xlib.h>
-class SemaphoreIphone : public Semaphore {
+class VulkanContextX11 : public VulkanContext {
- mutable cgsem_t sem;
-
- static Semaphore *create_semaphore_iphone();
+ virtual const char *_get_platform_surface_extension() const;
public:
- virtual Error wait();
- virtual Error post();
- virtual int get() const;
-
- static void make_default();
- SemaphoreIphone();
+ int window_create(::Window p_window, Display *p_display, int p_width, int p_height);
- ~SemaphoreIphone();
+ VulkanContextX11();
+ ~VulkanContextX11();
};
-#endif // SEMAPHORE_IPHONE_H
+#endif // VULKAN_DEVICE_X11_H