summaryrefslogtreecommitdiffstats
path: root/platform/web
diff options
context:
space:
mode:
Diffstat (limited to 'platform/web')
-rw-r--r--platform/web/api/api.cpp2
-rw-r--r--platform/web/audio_driver_web.h5
-rw-r--r--platform/web/detect.py19
-rw-r--r--platform/web/display_server_web.cpp258
-rw-r--r--platform/web/display_server_web.h49
-rw-r--r--platform/web/godot_js.h5
-rw-r--r--platform/web/godot_webgl2.h1
-rw-r--r--platform/web/javascript_bridge_singleton.cpp38
-rw-r--r--platform/web/js/engine/config.js4
-rw-r--r--platform/web/js/engine/engine.js4
-rw-r--r--platform/web/js/libs/library_godot_audio.js9
-rw-r--r--platform/web/js/libs/library_godot_display.js40
-rw-r--r--platform/web/js/libs/library_godot_fetch.js7
-rw-r--r--platform/web/js/libs/library_godot_input.js12
-rw-r--r--platform/web/js/libs/library_godot_javascript_singleton.js12
-rw-r--r--platform/web/js/libs/library_godot_os.js13
-rw-r--r--platform/web/js/libs/library_godot_webgl2.js13
-rw-r--r--platform/web/os_web.cpp10
-rw-r--r--platform/web/os_web.h14
-rw-r--r--platform/web/web_main.cpp10
20 files changed, 438 insertions, 87 deletions
diff --git a/platform/web/api/api.cpp b/platform/web/api/api.cpp
index ab7154b0fb..a695091a04 100644
--- a/platform/web/api/api.cpp
+++ b/platform/web/api/api.cpp
@@ -96,7 +96,7 @@ Ref<JavaScriptObject> JavaScriptBridge::create_callback(const Callable &p_callab
Variant JavaScriptBridge::_create_object_bind(const Variant **p_args, int p_argcount, Callable::CallError &r_error) {
if (p_argcount < 1) {
r_error.error = Callable::CallError::CALL_ERROR_TOO_FEW_ARGUMENTS;
- r_error.argument = 0;
+ r_error.expected = 1;
return Ref<JavaScriptObject>();
}
if (p_args[0]->get_type() != Variant::STRING) {
diff --git a/platform/web/audio_driver_web.h b/platform/web/audio_driver_web.h
index 7bfed834e1..12a61746c3 100644
--- a/platform/web/audio_driver_web.h
+++ b/platform/web/audio_driver_web.h
@@ -32,6 +32,7 @@
#define AUDIO_DRIVER_WEB_H
#include "godot_audio.h"
+#include "godot_js.h"
#include "core/os/mutex.h"
#include "core/os/thread.h"
@@ -55,8 +56,8 @@ private:
int mix_rate = 0;
int channel_count = 0;
- static void _state_change_callback(int p_state);
- static void _latency_update_callback(float p_latency);
+ WASM_EXPORT static void _state_change_callback(int p_state);
+ WASM_EXPORT static void _latency_update_callback(float p_latency);
static AudioDriverWeb *singleton;
diff --git a/platform/web/detect.py b/platform/web/detect.py
index 043ddca65d..d306869889 100644
--- a/platform/web/detect.py
+++ b/platform/web/detect.py
@@ -41,6 +41,11 @@ def get_opts():
"dlink_enabled", "Enable WebAssembly dynamic linking (GDExtension support). Produces bigger binaries", False
),
BoolVariable("use_closure_compiler", "Use closure compiler to minimize JavaScript code", False),
+ BoolVariable(
+ "proxy_to_pthread",
+ "Use Emscripten PROXY_TO_PTHREAD option to run the main application code to a separate thread",
+ True,
+ ),
]
@@ -211,6 +216,10 @@ def configure(env: "Environment"):
env.Append(LINKFLAGS=["-Wl,-u,scalbnf"])
if env["dlink_enabled"]:
+ if env["proxy_to_pthread"]:
+ print("GDExtension support requires proxy_to_pthread=no, disabling")
+ env["proxy_to_pthread"] = False
+
if cc_semver < (3, 1, 14):
print("GDExtension support requires emscripten >= 3.1.14, detected: %s.%s.%s" % cc_semver)
sys.exit(255)
@@ -221,6 +230,16 @@ def configure(env: "Environment"):
env.Append(LINKFLAGS=["-fvisibility=hidden"])
env.extra_suffix = ".dlink" + env.extra_suffix
+ # Run the main application in a web worker
+ if env["proxy_to_pthread"]:
+ env.Append(LINKFLAGS=["-s", "PROXY_TO_PTHREAD=1"])
+ env.Append(CPPDEFINES=["PROXY_TO_PTHREAD_ENABLED"])
+ env.Append(LINKFLAGS=["-s", "EXPORTED_RUNTIME_METHODS=['_emscripten_proxy_main']"])
+ # https://github.com/emscripten-core/emscripten/issues/18034#issuecomment-1277561925
+ env.Append(LINKFLAGS=["-s", "TEXTDECODER=0"])
+ # BigInt support to pass object pointers between contexts
+ env.Append(LINKFLAGS=["-s", "WASM_BIGINT"])
+
# Reduce code size by generating less support code (e.g. skip NodeJS support).
env.Append(LINKFLAGS=["-s", "ENVIRONMENT=web,worker"])
diff --git a/platform/web/display_server_web.cpp b/platform/web/display_server_web.cpp
index aac1401f23..022e044185 100644
--- a/platform/web/display_server_web.cpp
+++ b/platform/web/display_server_web.cpp
@@ -35,6 +35,7 @@
#include "os_web.h"
#include "core/config/project_settings.h"
+#include "core/object/callable_method_pointer.h"
#include "scene/resources/atlas_texture.h"
#include "servers/rendering/dummy/rasterizer_dummy.h"
@@ -59,16 +60,26 @@ DisplayServerWeb *DisplayServerWeb::get_singleton() {
bool DisplayServerWeb::check_size_force_redraw() {
bool size_changed = godot_js_display_size_update() != 0;
if (size_changed && !rect_changed_callback.is_null()) {
- Variant size = Rect2i(Point2i(), window_get_size()); // TODO use window_get_position if implemented.
- Variant *vp = &size;
- Variant ret;
- Callable::CallError ce;
- rect_changed_callback.callp((const Variant **)&vp, 1, ret, ce);
+ Size2i window_size = window_get_size();
+ Variant size = Rect2i(Point2i(), window_size); // TODO use window_get_position if implemented.
+ rect_changed_callback.call(size);
+ emscripten_set_canvas_element_size(canvas_id, window_size.x, window_size.y);
}
return size_changed;
}
void DisplayServerWeb::fullscreen_change_callback(int p_fullscreen) {
+#ifdef PROXY_TO_PTHREAD_ENABLED
+ if (!Thread::is_main_thread()) {
+ callable_mp_static(DisplayServerWeb::_fullscreen_change_callback).bind(p_fullscreen).call_deferred();
+ return;
+ }
+#endif
+
+ _fullscreen_change_callback(p_fullscreen);
+}
+
+void DisplayServerWeb::_fullscreen_change_callback(int p_fullscreen) {
DisplayServerWeb *display = get_singleton();
if (p_fullscreen) {
display->window_mode = WINDOW_MODE_FULLSCREEN;
@@ -78,7 +89,23 @@ void DisplayServerWeb::fullscreen_change_callback(int p_fullscreen) {
}
// Drag and drop callback.
-void DisplayServerWeb::drop_files_js_callback(char **p_filev, int p_filec) {
+void DisplayServerWeb::drop_files_js_callback(const char **p_filev, int p_filec) {
+ Vector<String> files;
+ for (int i = 0; i < p_filec; i++) {
+ files.push_back(String::utf8(p_filev[i]));
+ }
+
+#ifdef PROXY_TO_PTHREAD_ENABLED
+ if (!Thread::is_main_thread()) {
+ callable_mp_static(DisplayServerWeb::_drop_files_js_callback).bind(files).call_deferred();
+ return;
+ }
+#endif
+
+ _drop_files_js_callback(files);
+}
+
+void DisplayServerWeb::_drop_files_js_callback(const Vector<String> &p_files) {
DisplayServerWeb *ds = get_singleton();
if (!ds) {
ERR_FAIL_MSG("Unable to drop files because the DisplayServer is not active");
@@ -86,26 +113,26 @@ void DisplayServerWeb::drop_files_js_callback(char **p_filev, int p_filec) {
if (ds->drop_files_callback.is_null()) {
return;
}
- Vector<String> files;
- for (int i = 0; i < p_filec; i++) {
- files.push_back(String::utf8(p_filev[i]));
- }
- Variant v = files;
- Variant *vp = &v;
- Variant ret;
- Callable::CallError ce;
- ds->drop_files_callback.callp((const Variant **)&vp, 1, ret, ce);
+ ds->drop_files_callback.call(p_files);
}
// Web quit request callback.
void DisplayServerWeb::request_quit_callback() {
+#ifdef PROXY_TO_PTHREAD_ENABLED
+ if (!Thread::is_main_thread()) {
+ callable_mp_static(DisplayServerWeb::_request_quit_callback).call_deferred();
+ return;
+ }
+#endif
+
+ _request_quit_callback();
+}
+
+void DisplayServerWeb::_request_quit_callback() {
DisplayServerWeb *ds = get_singleton();
if (ds && !ds->window_event_callback.is_null()) {
Variant event = int(DisplayServer::WINDOW_EVENT_CLOSE_REQUEST);
- Variant *eventp = &event;
- Variant ret;
- Callable::CallError ce;
- ds->window_event_callback.callp((const Variant **)&eventp, 1, ret, ce);
+ ds->window_event_callback.call(event);
}
}
@@ -129,17 +156,32 @@ void DisplayServerWeb::dom2godot_mod(Ref<InputEventWithModifiers> ev, int p_mod,
void DisplayServerWeb::key_callback(int p_pressed, int p_repeat, int p_modifiers) {
DisplayServerWeb *ds = get_singleton();
JSKeyEvent &key_event = ds->key_event;
+
+ const String code = String::utf8(key_event.code);
+ const String key = String::utf8(key_event.key);
+
+#ifdef PROXY_TO_PTHREAD_ENABLED
+ if (!Thread::is_main_thread()) {
+ callable_mp_static(DisplayServerWeb::_key_callback).bind(code, key, p_pressed, p_repeat, p_modifiers).call_deferred();
+ return;
+ }
+#endif
+
+ _key_callback(code, key, p_pressed, p_repeat, p_modifiers);
+}
+
+void DisplayServerWeb::_key_callback(const String &p_key_event_code, const String &p_key_event_key, int p_pressed, int p_repeat, int p_modifiers) {
// Resume audio context after input in case autoplay was denied.
OS_Web::get_singleton()->resume_audio();
char32_t c = 0x00;
- String unicode = String::utf8(key_event.key);
+ String unicode = p_key_event_key;
if (unicode.length() == 1) {
c = unicode[0];
}
- Key keycode = dom_code2godot_scancode(key_event.code, key_event.key, false);
- Key scancode = dom_code2godot_scancode(key_event.code, key_event.key, true);
+ Key keycode = dom_code2godot_scancode(p_key_event_code.utf8().get_data(), p_key_event_key.utf8().get_data(), false);
+ Key scancode = dom_code2godot_scancode(p_key_event_code.utf8().get_data(), p_key_event_key.utf8().get_data(), true);
Ref<InputEventKey> ev;
ev.instantiate();
@@ -160,6 +202,17 @@ void DisplayServerWeb::key_callback(int p_pressed, int p_repeat, int p_modifiers
// Mouse
int DisplayServerWeb::mouse_button_callback(int p_pressed, int p_button, double p_x, double p_y, int p_modifiers) {
+#ifdef PROXY_TO_PTHREAD_ENABLED
+ if (!Thread::is_main_thread()) {
+ callable_mp_static(DisplayServerWeb::_mouse_button_callback).bind(p_pressed, p_button, p_x, p_y, p_modifiers).call_deferred();
+ return true;
+ }
+#endif
+
+ return _mouse_button_callback(p_pressed, p_button, p_x, p_y, p_modifiers);
+}
+
+int DisplayServerWeb::_mouse_button_callback(int p_pressed, int p_button, double p_x, double p_y, int p_modifiers) {
DisplayServerWeb *ds = get_singleton();
Point2 pos(p_x, p_y);
@@ -236,6 +289,17 @@ int DisplayServerWeb::mouse_button_callback(int p_pressed, int p_button, double
}
void DisplayServerWeb::mouse_move_callback(double p_x, double p_y, double p_rel_x, double p_rel_y, int p_modifiers) {
+#ifdef PROXY_TO_PTHREAD_ENABLED
+ if (!Thread::is_main_thread()) {
+ callable_mp_static(DisplayServerWeb::_mouse_move_callback).bind(p_x, p_y, p_rel_x, p_rel_y, p_modifiers).call_deferred();
+ return;
+ }
+#endif
+
+ _mouse_move_callback(p_x, p_y, p_rel_x, p_rel_y, p_modifiers);
+}
+
+void DisplayServerWeb::_mouse_move_callback(double p_x, double p_y, double p_rel_x, double p_rel_y, int p_modifiers) {
BitField<MouseButtonMask> input_mask = Input::get_singleton()->get_mouse_button_mask();
// For motion outside the canvas, only read mouse movement if dragging
// started inside the canvas; imitating desktop app behavior.
@@ -311,9 +375,25 @@ bool DisplayServerWeb::tts_is_paused() const {
}
void DisplayServerWeb::update_voices_callback(int p_size, const char **p_voice) {
- get_singleton()->voices.clear();
+ Vector<String> voices;
for (int i = 0; i < p_size; i++) {
- Vector<String> tokens = String::utf8(p_voice[i]).split(";", true, 2);
+ voices.append(String::utf8(p_voice[i]));
+ }
+
+#ifdef PROXY_TO_PTHREAD_ENABLED
+ if (!Thread::is_main_thread()) {
+ callable_mp_static(DisplayServerWeb::_update_voices_callback).bind(voices).call_deferred();
+ return;
+ }
+#endif
+
+ _update_voices_callback(voices);
+}
+
+void DisplayServerWeb::_update_voices_callback(const Vector<String> &p_voices) {
+ get_singleton()->voices.clear();
+ for (int i = 0; i < p_voices.size(); i++) {
+ Vector<String> tokens = p_voices[i].split(";", true, 2);
if (tokens.size() == 2) {
Dictionary voice_d;
voice_d["name"] = tokens[1];
@@ -344,7 +424,7 @@ void DisplayServerWeb::tts_speak(const String &p_text, const String &p_voice, in
CharString string = p_text.utf8();
utterance_ids[p_utterance_id] = string;
- godot_js_tts_speak(string.get_data(), p_voice.utf8().get_data(), CLAMP(p_volume, 0, 100), CLAMP(p_pitch, 0.f, 2.f), CLAMP(p_rate, 0.1f, 10.f), p_utterance_id, DisplayServerWeb::_js_utterance_callback);
+ godot_js_tts_speak(string.get_data(), p_voice.utf8().get_data(), CLAMP(p_volume, 0, 100), CLAMP(p_pitch, 0.f, 2.f), CLAMP(p_rate, 0.1f, 10.f), p_utterance_id, DisplayServerWeb::js_utterance_callback);
}
void DisplayServerWeb::tts_pause() {
@@ -366,6 +446,17 @@ void DisplayServerWeb::tts_stop() {
godot_js_tts_stop();
}
+void DisplayServerWeb::js_utterance_callback(int p_event, int p_id, int p_pos) {
+#ifdef PROXY_TO_PTHREAD_ENABLED
+ if (!Thread::is_main_thread()) {
+ callable_mp_static(DisplayServerWeb::_js_utterance_callback).bind(p_event, p_id, p_pos).call_deferred();
+ return;
+ }
+#endif
+
+ _js_utterance_callback(p_event, p_id, p_pos);
+}
+
void DisplayServerWeb::_js_utterance_callback(int p_event, int p_id, int p_pos) {
DisplayServerWeb *ds = (DisplayServerWeb *)DisplayServer::get_singleton();
if (ds->utterance_ids.has(p_id)) {
@@ -517,6 +608,17 @@ Point2i DisplayServerWeb::mouse_get_position() const {
// Wheel
int DisplayServerWeb::mouse_wheel_callback(double p_delta_x, double p_delta_y) {
+#ifdef PROXY_TO_PTHREAD_ENABLED
+ if (!Thread::is_main_thread()) {
+ callable_mp_static(DisplayServerWeb::_mouse_wheel_callback).bind(p_delta_x, p_delta_y).call_deferred();
+ return true;
+ }
+#endif
+
+ return _mouse_wheel_callback(p_delta_x, p_delta_y);
+}
+
+int DisplayServerWeb::_mouse_wheel_callback(double p_delta_x, double p_delta_y) {
if (!godot_js_display_canvas_is_focused()) {
if (get_singleton()->cursor_inside_canvas) {
godot_js_display_canvas_focus();
@@ -569,6 +671,17 @@ int DisplayServerWeb::mouse_wheel_callback(double p_delta_x, double p_delta_y) {
// Touch
void DisplayServerWeb::touch_callback(int p_type, int p_count) {
+#ifdef PROXY_TO_PTHREAD_ENABLED
+ if (!Thread::is_main_thread()) {
+ callable_mp_static(DisplayServerWeb::_touch_callback).bind(p_type, p_count).call_deferred();
+ return;
+ }
+#endif
+
+ _touch_callback(p_type, p_count);
+}
+
+void DisplayServerWeb::_touch_callback(int p_type, int p_count) {
DisplayServerWeb *ds = get_singleton();
const JSTouchEvent &touch_event = ds->touch_event;
@@ -613,16 +726,25 @@ bool DisplayServerWeb::is_touchscreen_available() const {
// Virtual Keyboard
void DisplayServerWeb::vk_input_text_callback(const char *p_text, int p_cursor) {
+ String text = p_text;
+
+#ifdef PROXY_TO_PTHREAD_ENABLED
+ if (!Thread::is_main_thread()) {
+ callable_mp_static(DisplayServerWeb::_vk_input_text_callback).bind(text, p_cursor).call_deferred();
+ return;
+ }
+#endif
+
+ _vk_input_text_callback(text, p_cursor);
+}
+
+void DisplayServerWeb::_vk_input_text_callback(const String &p_text, int p_cursor) {
DisplayServerWeb *ds = DisplayServerWeb::get_singleton();
if (!ds || ds->input_text_callback.is_null()) {
return;
}
// Call input_text
- Variant event = String::utf8(p_text);
- Variant *eventp = &event;
- Variant ret;
- Callable::CallError ce;
- ds->input_text_callback.callp((const Variant **)&eventp, 1, ret, ce);
+ ds->input_text_callback.call(p_text);
// Insert key right to reach position.
Input *input = Input::get_singleton();
Ref<InputEventKey> k;
@@ -649,14 +771,39 @@ void DisplayServerWeb::virtual_keyboard_hide() {
}
void DisplayServerWeb::window_blur_callback() {
+#ifdef PROXY_TO_PTHREAD_ENABLED
+ if (!Thread::is_main_thread()) {
+ callable_mp_static(DisplayServerWeb::_window_blur_callback).call_deferred();
+ return;
+ }
+#endif
+
+ _window_blur_callback();
+}
+
+void DisplayServerWeb::_window_blur_callback() {
Input::get_singleton()->release_pressed_events();
}
// Gamepad
void DisplayServerWeb::gamepad_callback(int p_index, int p_connected, const char *p_id, const char *p_guid) {
+ String id = p_id;
+ String guid = p_guid;
+
+#ifdef PROXY_TO_PTHREAD_ENABLED
+ if (!Thread::is_main_thread()) {
+ callable_mp_static(DisplayServerWeb::_gamepad_callback).bind(p_index, p_connected, id, guid).call_deferred();
+ return;
+ }
+#endif
+
+ _gamepad_callback(p_index, p_connected, id, guid);
+}
+
+void DisplayServerWeb::_gamepad_callback(int p_index, int p_connected, const String &p_id, const String &p_guid) {
Input *input = Input::get_singleton();
if (p_connected) {
- input->joy_connection_changed(p_index, true, String::utf8(p_id), String::utf8(p_guid));
+ input->joy_connection_changed(p_index, true, p_id, p_guid);
} else {
input->joy_connection_changed(p_index, false, "");
}
@@ -700,7 +847,20 @@ Vector<String> DisplayServerWeb::get_rendering_drivers_func() {
// Clipboard
void DisplayServerWeb::update_clipboard_callback(const char *p_text) {
- get_singleton()->clipboard = String::utf8(p_text);
+ String text = p_text;
+
+#ifdef PROXY_TO_PTHREAD_ENABLED
+ if (!Thread::is_main_thread()) {
+ callable_mp_static(DisplayServerWeb::_update_clipboard_callback).bind(text).call_deferred();
+ return;
+ }
+#endif
+
+ _update_clipboard_callback(text);
+}
+
+void DisplayServerWeb::_update_clipboard_callback(const String &p_text) {
+ get_singleton()->clipboard = p_text;
}
void DisplayServerWeb::clipboard_set(const String &p_text) {
@@ -715,6 +875,17 @@ String DisplayServerWeb::clipboard_get() const {
}
void DisplayServerWeb::send_window_event_callback(int p_notification) {
+#ifdef PROXY_TO_PTHREAD_ENABLED
+ if (!Thread::is_main_thread()) {
+ callable_mp_static(DisplayServerWeb::_send_window_event_callback).bind(p_notification).call_deferred();
+ return;
+ }
+#endif
+
+ _send_window_event_callback(p_notification);
+}
+
+void DisplayServerWeb::_send_window_event_callback(int p_notification) {
DisplayServerWeb *ds = get_singleton();
if (!ds) {
return;
@@ -724,10 +895,7 @@ void DisplayServerWeb::send_window_event_callback(int p_notification) {
}
if (!ds->window_event_callback.is_null()) {
Variant event = int(p_notification);
- Variant *eventp = &event;
- Variant ret;
- Callable::CallError ce;
- ds->window_event_callback.callp((const Variant **)&eventp, 1, ret, ce);
+ ds->window_event_callback.call(event);
}
}
@@ -770,12 +938,8 @@ void DisplayServerWeb::set_icon(const Ref<Image> &p_icon) {
void DisplayServerWeb::_dispatch_input_event(const Ref<InputEvent> &p_event) {
Callable cb = get_singleton()->input_event_callback;
- if (!cb.is_null()) {
- Variant ev = p_event;
- Variant *evp = &ev;
- Variant ret;
- Callable::CallError ce;
- cb.callp((const Variant **)&evp, 1, ret, ce);
+ if (cb.is_valid()) {
+ cb.call(p_event);
}
}
@@ -836,19 +1000,19 @@ DisplayServerWeb::DisplayServerWeb(const String &p_rendering_driver, WindowMode
godot_js_input_mouse_wheel_cb(&DisplayServerWeb::mouse_wheel_callback);
godot_js_input_touch_cb(&DisplayServerWeb::touch_callback, touch_event.identifier, touch_event.coords);
godot_js_input_key_cb(&DisplayServerWeb::key_callback, key_event.code, key_event.key);
- godot_js_input_paste_cb(update_clipboard_callback);
- godot_js_input_drop_files_cb(drop_files_js_callback);
+ godot_js_input_paste_cb(&DisplayServerWeb::update_clipboard_callback);
+ godot_js_input_drop_files_cb(&DisplayServerWeb::drop_files_js_callback);
godot_js_input_gamepad_cb(&DisplayServerWeb::gamepad_callback);
// JS Display interface (js/libs/library_godot_display.js)
godot_js_display_fullscreen_cb(&DisplayServerWeb::fullscreen_change_callback);
- godot_js_display_window_blur_cb(&window_blur_callback);
- godot_js_display_notification_cb(&send_window_event_callback,
+ godot_js_display_window_blur_cb(&DisplayServerWeb::window_blur_callback);
+ godot_js_display_notification_cb(&DisplayServerWeb::send_window_event_callback,
WINDOW_EVENT_MOUSE_ENTER,
WINDOW_EVENT_MOUSE_EXIT,
WINDOW_EVENT_FOCUS_IN,
WINDOW_EVENT_FOCUS_OUT);
- godot_js_display_vk_cb(&vk_input_text_callback);
+ godot_js_display_vk_cb(&DisplayServerWeb::vk_input_text_callback);
Input::get_singleton()->set_event_dispatch_function(_dispatch_input_event);
}
diff --git a/platform/web/display_server_web.h b/platform/web/display_server_web.h
index a4fd75f33b..51c6ab3c0a 100644
--- a/platform/web/display_server_web.h
+++ b/platform/web/display_server_web.h
@@ -33,6 +33,8 @@
#include "servers/display_server.h"
+#include "godot_js.h"
+
#include <emscripten.h>
#include <emscripten/html5.h>
@@ -88,29 +90,44 @@ private:
static const char *godot2dom_cursor(DisplayServer::CursorShape p_shape);
// events
- static void fullscreen_change_callback(int p_fullscreen);
- static int mouse_button_callback(int p_pressed, int p_button, double p_x, double p_y, int p_modifiers);
- static void mouse_move_callback(double p_x, double p_y, double p_rel_x, double p_rel_y, int p_modifiers);
- static int mouse_wheel_callback(double p_delta_x, double p_delta_y);
- static void touch_callback(int p_type, int p_count);
- static void key_callback(int p_pressed, int p_repeat, int p_modifiers);
- static void vk_input_text_callback(const char *p_text, int p_cursor);
- static void gamepad_callback(int p_index, int p_connected, const char *p_id, const char *p_guid);
- void process_joypads();
+ WASM_EXPORT static void fullscreen_change_callback(int p_fullscreen);
+ static void _fullscreen_change_callback(int p_fullscreen);
+ WASM_EXPORT static int mouse_button_callback(int p_pressed, int p_button, double p_x, double p_y, int p_modifiers);
+ static int _mouse_button_callback(int p_pressed, int p_button, double p_x, double p_y, int p_modifiers);
+ WASM_EXPORT static void mouse_move_callback(double p_x, double p_y, double p_rel_x, double p_rel_y, int p_modifiers);
+ static void _mouse_move_callback(double p_x, double p_y, double p_rel_x, double p_rel_y, int p_modifiers);
+ WASM_EXPORT static int mouse_wheel_callback(double p_delta_x, double p_delta_y);
+ static int _mouse_wheel_callback(double p_delta_x, double p_delta_y);
+ WASM_EXPORT static void touch_callback(int p_type, int p_count);
+ static void _touch_callback(int p_type, int p_count);
+ WASM_EXPORT static void key_callback(int p_pressed, int p_repeat, int p_modifiers);
+ static void _key_callback(const String &p_key_event_code, const String &p_key_event_key, int p_pressed, int p_repeat, int p_modifiers);
+ WASM_EXPORT static void vk_input_text_callback(const char *p_text, int p_cursor);
+ static void _vk_input_text_callback(const String &p_text, int p_cursor);
+ WASM_EXPORT static void gamepad_callback(int p_index, int p_connected, const char *p_id, const char *p_guid);
+ static void _gamepad_callback(int p_index, int p_connected, const String &p_id, const String &p_guid);
+ WASM_EXPORT static void js_utterance_callback(int p_event, int p_id, int p_pos);
static void _js_utterance_callback(int p_event, int p_id, int p_pos);
+ WASM_EXPORT static void request_quit_callback();
+ static void _request_quit_callback();
+ WASM_EXPORT static void window_blur_callback();
+ static void _window_blur_callback();
+ WASM_EXPORT static void update_voices_callback(int p_size, const char **p_voice);
+ static void _update_voices_callback(const Vector<String> &p_voices);
+ WASM_EXPORT static void update_clipboard_callback(const char *p_text);
+ static void _update_clipboard_callback(const String &p_text);
+ WASM_EXPORT static void send_window_event_callback(int p_notification);
+ static void _send_window_event_callback(int p_notification);
+ WASM_EXPORT static void drop_files_js_callback(const char **p_filev, int p_filec);
+ static void _drop_files_js_callback(const Vector<String> &p_files);
+
+ void process_joypads();
static Vector<String> get_rendering_drivers_func();
static DisplayServer *create_func(const String &p_rendering_driver, WindowMode p_window_mode, VSyncMode p_vsync_mode, uint32_t p_flags, const Vector2i *p_position, const Vector2i &p_resolution, int p_screen, Error &r_error);
static void _dispatch_input_event(const Ref<InputEvent> &p_event);
- static void request_quit_callback();
- static void window_blur_callback();
- static void update_voices_callback(int p_size, const char **p_voice);
- static void update_clipboard_callback(const char *p_text);
- static void send_window_event_callback(int p_notification);
- static void drop_files_js_callback(char **p_filev, int p_filec);
-
protected:
int get_current_video_driver() const;
diff --git a/platform/web/godot_js.h b/platform/web/godot_js.h
index 3341cf8a67..031e67e486 100644
--- a/platform/web/godot_js.h
+++ b/platform/web/godot_js.h
@@ -31,11 +31,14 @@
#ifndef GODOT_JS_H
#define GODOT_JS_H
+#define WASM_EXPORT __attribute__((visibility("default")))
+
#ifdef __cplusplus
extern "C" {
#endif
#include <stddef.h>
+#include <stdint.h>
// Config
extern void godot_js_config_locale_get(char *p_ptr, int p_ptr_max);
@@ -67,7 +70,7 @@ extern int godot_js_input_gamepad_sample();
extern int godot_js_input_gamepad_sample_count();
extern int godot_js_input_gamepad_sample_get(int p_idx, float r_btns[16], int32_t *r_btns_num, float r_axes[10], int32_t *r_axes_num, int32_t *r_standard);
extern void godot_js_input_paste_cb(void (*p_callback)(const char *p_text));
-extern void godot_js_input_drop_files_cb(void (*p_callback)(char **p_filev, int p_filec));
+extern void godot_js_input_drop_files_cb(void (*p_callback)(const char **p_filev, int p_filec));
// TTS
extern int godot_js_tts_is_speaking();
diff --git a/platform/web/godot_webgl2.h b/platform/web/godot_webgl2.h
index d2f46e125e..3ade9e4239 100644
--- a/platform/web/godot_webgl2.h
+++ b/platform/web/godot_webgl2.h
@@ -44,6 +44,7 @@ extern "C" {
#endif
void godot_webgl2_glFramebufferTextureMultiviewOVR(GLenum target, GLenum attachment, GLuint texture, GLint level, GLint baseViewIndex, GLsizei numViews);
+void godot_webgl2_glGetBufferSubData(GLenum target, GLintptr offset, GLsizeiptr size, GLvoid *data);
#define glFramebufferTextureMultiviewOVR godot_webgl2_glFramebufferTextureMultiviewOVR
diff --git a/platform/web/javascript_bridge_singleton.cpp b/platform/web/javascript_bridge_singleton.cpp
index 45bce1b480..d72ad8331b 100644
--- a/platform/web/javascript_bridge_singleton.cpp
+++ b/platform/web/javascript_bridge_singleton.cpp
@@ -68,11 +68,12 @@ private:
int _js_id = 0;
Callable _callable;
- static int _variant2js(const void **p_args, int p_pos, godot_js_wrapper_ex *r_val, void **p_lock);
- static void _free_lock(void **p_lock, int p_type);
- static Variant _js2variant(int p_type, godot_js_wrapper_ex *p_val);
- static void *_alloc_variants(int p_size);
- static void _callback(void *p_ref, int p_arg_id, int p_argc);
+ WASM_EXPORT static int _variant2js(const void **p_args, int p_pos, godot_js_wrapper_ex *r_val, void **p_lock);
+ WASM_EXPORT static void _free_lock(void **p_lock, int p_type);
+ WASM_EXPORT static Variant _js2variant(int p_type, godot_js_wrapper_ex *p_val);
+ WASM_EXPORT static void *_alloc_variants(int p_size);
+ WASM_EXPORT static void callback(void *p_ref, int p_arg_id, int p_argc);
+ static void _callback(const JavaScriptObjectImpl *obj, Variant arg);
protected:
bool _set(const StringName &p_name, const Variant &p_value) override;
@@ -163,7 +164,7 @@ void JavaScriptObjectImpl::_get_property_list(List<PropertyInfo> *p_list) const
}
void JavaScriptObjectImpl::_free_lock(void **p_lock, int p_type) {
- ERR_FAIL_COND_MSG(*p_lock == nullptr, "No lock to free!");
+ ERR_FAIL_NULL_MSG(*p_lock, "No lock to free!");
const Variant::Type type = (Variant::Type)p_type;
switch (type) {
case Variant::STRING: {
@@ -245,9 +246,10 @@ Variant JavaScriptObjectImpl::callp(const StringName &p_method, const Variant **
return _js2variant(type, &exchange);
}
-void JavaScriptObjectImpl::_callback(void *p_ref, int p_args_id, int p_argc) {
+void JavaScriptObjectImpl::callback(void *p_ref, int p_args_id, int p_argc) {
const JavaScriptObjectImpl *obj = (JavaScriptObjectImpl *)p_ref;
ERR_FAIL_COND_MSG(obj->_callable.is_null(), "JavaScript callback failed.");
+
Vector<const Variant *> argp;
Array arg_arr;
for (int i = 0; i < p_argc; i++) {
@@ -257,14 +259,24 @@ void JavaScriptObjectImpl::_callback(void *p_ref, int p_args_id, int p_argc) {
arg_arr.push_back(_js2variant(type, &exchange));
}
Variant arg = arg_arr;
- const Variant *argv[1] = { &arg };
- Callable::CallError err;
- Variant ret;
- obj->_callable.callp(argv, 1, ret, err);
+
+#ifdef PROXY_TO_PTHREAD_ENABLED
+ if (!Thread::is_main_thread()) {
+ callable_mp_static(JavaScriptObjectImpl::_callback).bind(obj, arg).call_deferred();
+ return;
+ }
+#endif
+
+ _callback(obj, arg);
+}
+
+void JavaScriptObjectImpl::_callback(const JavaScriptObjectImpl *obj, Variant arg) {
+ obj->_callable.call(arg);
// Set return value
godot_js_wrapper_ex exchange;
void *lock = nullptr;
+ Variant ret;
const Variant *v = &ret;
int type = _variant2js((const void **)&v, 0, &exchange, &lock);
godot_js_wrapper_object_set_cb_ret(type, &exchange);
@@ -276,7 +288,7 @@ void JavaScriptObjectImpl::_callback(void *p_ref, int p_args_id, int p_argc) {
Ref<JavaScriptObject> JavaScriptBridge::create_callback(const Callable &p_callable) {
Ref<JavaScriptObjectImpl> out = memnew(JavaScriptObjectImpl);
out->_callable = p_callable;
- out->_js_id = godot_js_wrapper_create_cb(out.ptr(), JavaScriptObjectImpl::_callback);
+ out->_js_id = godot_js_wrapper_create_cb(out.ptr(), JavaScriptObjectImpl::callback);
return out;
}
@@ -289,7 +301,7 @@ Ref<JavaScriptObject> JavaScriptBridge::get_interface(const String &p_interface)
Variant JavaScriptBridge::_create_object_bind(const Variant **p_args, int p_argcount, Callable::CallError &r_error) {
if (p_argcount < 1) {
r_error.error = Callable::CallError::CALL_ERROR_TOO_FEW_ARGUMENTS;
- r_error.argument = 0;
+ r_error.expected = 1;
return Ref<JavaScriptObject>();
}
if (p_args[0]->get_type() != Variant::STRING) {
diff --git a/platform/web/js/engine/config.js b/platform/web/js/engine/config.js
index 6a30c253fb..0b6626968e 100644
--- a/platform/web/js/engine/config.js
+++ b/platform/web/js/engine/config.js
@@ -292,7 +292,9 @@ const InternalConfig = function (initConfig) { // eslint-disable-line no-unused-
return {};
},
'locateFile': function (path) {
- if (path.endsWith('.worker.js')) {
+ if (!path.startsWith('godot.')) {
+ return path;
+ } else if (path.endsWith('.worker.js')) {
return `${loadPath}.worker.js`;
} else if (path.endsWith('.audio.worklet.js')) {
return `${loadPath}.audio.worklet.js`;
diff --git a/platform/web/js/engine/engine.js b/platform/web/js/engine/engine.js
index fb80bd55e1..3d6720a2fc 100644
--- a/platform/web/js/engine/engine.js
+++ b/platform/web/js/engine/engine.js
@@ -164,6 +164,10 @@ const Engine = (function () {
// Preload GDExtension libraries.
const libs = [];
+ if (me.config.gdextensionLibs.length > 0 && !me.rtenv['loadDynamicLibrary']) {
+ return Promise.reject(new Error('GDExtension libraries are not supported by this engine version. '
+ + 'Enable "Extensions Support" for your export preset and/or build your custom template with "dlink_enabled=yes".'));
+ }
me.config.gdextensionLibs.forEach(function (lib) {
libs.push(me.rtenv['loadDynamicLibrary'](lib, { 'loadAsync': true }));
});
diff --git a/platform/web/js/libs/library_godot_audio.js b/platform/web/js/libs/library_godot_audio.js
index cc86c81096..b54c5cac85 100644
--- a/platform/web/js/libs/library_godot_audio.js
+++ b/platform/web/js/libs/library_godot_audio.js
@@ -159,16 +159,19 @@ const GodotAudio = {
return 1;
},
+ godot_audio_has_worklet__proxy: 'sync',
godot_audio_has_worklet__sig: 'i',
godot_audio_has_worklet: function () {
return (GodotAudio.ctx && GodotAudio.ctx.audioWorklet) ? 1 : 0;
},
+ godot_audio_has_script_processor__proxy: 'sync',
godot_audio_has_script_processor__sig: 'i',
godot_audio_has_script_processor: function () {
return (GodotAudio.ctx && GodotAudio.ctx.createScriptProcessor) ? 1 : 0;
},
+ godot_audio_init__proxy: 'sync',
godot_audio_init__sig: 'iiiii',
godot_audio_init: function (p_mix_rate, p_latency, p_state_change, p_latency_update) {
const statechange = GodotRuntime.get_func(p_state_change);
@@ -179,6 +182,7 @@ const GodotAudio = {
return channels;
},
+ godot_audio_resume__proxy: 'sync',
godot_audio_resume__sig: 'v',
godot_audio_resume: function () {
if (GodotAudio.ctx && GodotAudio.ctx.state !== 'running') {
@@ -358,6 +362,7 @@ const GodotAudioWorklet = {
},
},
+ godot_audio_worklet_create__proxy: 'sync',
godot_audio_worklet_create__sig: 'ii',
godot_audio_worklet_create: function (channels) {
try {
@@ -369,6 +374,7 @@ const GodotAudioWorklet = {
return 0;
},
+ godot_audio_worklet_start__proxy: 'sync',
godot_audio_worklet_start__sig: 'viiiii',
godot_audio_worklet_start: function (p_in_buf, p_in_size, p_out_buf, p_out_size, p_state) {
const out_buffer = GodotRuntime.heapSub(HEAPF32, p_out_buf, p_out_size);
@@ -377,6 +383,7 @@ const GodotAudioWorklet = {
GodotAudioWorklet.start(in_buffer, out_buffer, state);
},
+ godot_audio_worklet_start_no_threads__proxy: 'sync',
godot_audio_worklet_start_no_threads__sig: 'viiiiii',
godot_audio_worklet_start_no_threads: function (p_out_buf, p_out_size, p_out_callback, p_in_buf, p_in_size, p_in_callback) {
const out_callback = GodotRuntime.get_func(p_out_callback);
@@ -465,6 +472,7 @@ const GodotAudioScript = {
},
},
+ godot_audio_script_create__proxy: 'sync',
godot_audio_script_create__sig: 'iii',
godot_audio_script_create: function (buffer_length, channel_count) {
const buf_len = GodotRuntime.getHeapValue(buffer_length, 'i32');
@@ -478,6 +486,7 @@ const GodotAudioScript = {
return 0;
},
+ godot_audio_script_start__proxy: 'sync',
godot_audio_script_start__sig: 'viiiii',
godot_audio_script_start: function (p_in_buf, p_in_size, p_out_buf, p_out_size, p_cb) {
const onprocess = GodotRuntime.get_func(p_cb);
diff --git a/platform/web/js/libs/library_godot_display.js b/platform/web/js/libs/library_godot_display.js
index c60e6899f2..99fc429d8f 100644
--- a/platform/web/js/libs/library_godot_display.js
+++ b/platform/web/js/libs/library_godot_display.js
@@ -345,6 +345,7 @@ const GodotDisplay = {
},
},
+ godot_js_display_is_swap_ok_cancel__proxy: 'sync',
godot_js_display_is_swap_ok_cancel__sig: 'i',
godot_js_display_is_swap_ok_cancel: function () {
const win = (['Windows', 'Win64', 'Win32', 'WinCE']);
@@ -355,16 +356,19 @@ const GodotDisplay = {
return 0;
},
+ godot_js_tts_is_speaking__proxy: 'sync',
godot_js_tts_is_speaking__sig: 'i',
godot_js_tts_is_speaking: function () {
return window.speechSynthesis.speaking;
},
+ godot_js_tts_is_paused__proxy: 'sync',
godot_js_tts_is_paused__sig: 'i',
godot_js_tts_is_paused: function () {
return window.speechSynthesis.paused;
},
+ godot_js_tts_get_voices__proxy: 'sync',
godot_js_tts_get_voices__sig: 'vi',
godot_js_tts_get_voices: function (p_callback) {
const func = GodotRuntime.get_func(p_callback);
@@ -382,6 +386,7 @@ const GodotDisplay = {
}
},
+ godot_js_tts_speak__proxy: 'sync',
godot_js_tts_speak__sig: 'viiiffii',
godot_js_tts_speak: function (p_text, p_voice, p_volume, p_pitch, p_rate, p_utterance_id, p_callback) {
const func = GodotRuntime.get_func(p_callback);
@@ -424,53 +429,63 @@ const GodotDisplay = {
window.speechSynthesis.speak(utterance);
},
+ godot_js_tts_pause__proxy: 'sync',
godot_js_tts_pause__sig: 'v',
godot_js_tts_pause: function () {
window.speechSynthesis.pause();
},
+ godot_js_tts_resume__proxy: 'sync',
godot_js_tts_resume__sig: 'v',
godot_js_tts_resume: function () {
window.speechSynthesis.resume();
},
+ godot_js_tts_stop__proxy: 'sync',
godot_js_tts_stop__sig: 'v',
godot_js_tts_stop: function () {
window.speechSynthesis.cancel();
window.speechSynthesis.resume();
},
+ godot_js_display_alert__proxy: 'sync',
godot_js_display_alert__sig: 'vi',
godot_js_display_alert: function (p_text) {
window.alert(GodotRuntime.parseString(p_text)); // eslint-disable-line no-alert
},
+ godot_js_display_screen_dpi_get__proxy: 'sync',
godot_js_display_screen_dpi_get__sig: 'i',
godot_js_display_screen_dpi_get: function () {
return GodotDisplay.getDPI();
},
+ godot_js_display_pixel_ratio_get__proxy: 'sync',
godot_js_display_pixel_ratio_get__sig: 'f',
godot_js_display_pixel_ratio_get: function () {
return GodotDisplayScreen.getPixelRatio();
},
+ godot_js_display_fullscreen_request__proxy: 'sync',
godot_js_display_fullscreen_request__sig: 'i',
godot_js_display_fullscreen_request: function () {
return GodotDisplayScreen.requestFullscreen();
},
+ godot_js_display_fullscreen_exit__proxy: 'sync',
godot_js_display_fullscreen_exit__sig: 'i',
godot_js_display_fullscreen_exit: function () {
return GodotDisplayScreen.exitFullscreen();
},
+ godot_js_display_desired_size_set__proxy: 'sync',
godot_js_display_desired_size_set__sig: 'vii',
godot_js_display_desired_size_set: function (width, height) {
GodotDisplayScreen.desired_size = [width, height];
GodotDisplayScreen.updateSize();
},
+ godot_js_display_size_update__proxy: 'sync',
godot_js_display_size_update__sig: 'i',
godot_js_display_size_update: function () {
const updated = GodotDisplayScreen.updateSize();
@@ -480,6 +495,7 @@ const GodotDisplay = {
return updated;
},
+ godot_js_display_screen_size_get__proxy: 'sync',
godot_js_display_screen_size_get__sig: 'vii',
godot_js_display_screen_size_get: function (width, height) {
const scale = GodotDisplayScreen.getPixelRatio();
@@ -487,12 +503,14 @@ const GodotDisplay = {
GodotRuntime.setHeapValue(height, window.screen.height * scale, 'i32');
},
+ godot_js_display_window_size_get__proxy: 'sync',
godot_js_display_window_size_get__sig: 'vii',
godot_js_display_window_size_get: function (p_width, p_height) {
GodotRuntime.setHeapValue(p_width, GodotConfig.canvas.width, 'i32');
GodotRuntime.setHeapValue(p_height, GodotConfig.canvas.height, 'i32');
},
+ godot_js_display_has_webgl__proxy: 'sync',
godot_js_display_has_webgl__sig: 'ii',
godot_js_display_has_webgl: function (p_version) {
if (p_version !== 1 && p_version !== 2) {
@@ -507,11 +525,13 @@ const GodotDisplay = {
/*
* Canvas
*/
+ godot_js_display_canvas_focus__proxy: 'sync',
godot_js_display_canvas_focus__sig: 'v',
godot_js_display_canvas_focus: function () {
GodotConfig.canvas.focus();
},
+ godot_js_display_canvas_is_focused__proxy: 'sync',
godot_js_display_canvas_is_focused__sig: 'i',
godot_js_display_canvas_is_focused: function () {
return document.activeElement === GodotConfig.canvas;
@@ -520,6 +540,7 @@ const GodotDisplay = {
/*
* Touchscreen
*/
+ godot_js_display_touchscreen_is_available__proxy: 'sync',
godot_js_display_touchscreen_is_available__sig: 'i',
godot_js_display_touchscreen_is_available: function () {
return 'ontouchstart' in window;
@@ -528,6 +549,7 @@ const GodotDisplay = {
/*
* Clipboard
*/
+ godot_js_display_clipboard_set__proxy: 'sync',
godot_js_display_clipboard_set__sig: 'ii',
godot_js_display_clipboard_set: function (p_text) {
const text = GodotRuntime.parseString(p_text);
@@ -541,6 +563,7 @@ const GodotDisplay = {
return 0;
},
+ godot_js_display_clipboard_get__proxy: 'sync',
godot_js_display_clipboard_get__sig: 'ii',
godot_js_display_clipboard_get: function (callback) {
const func = GodotRuntime.get_func(callback);
@@ -560,11 +583,13 @@ const GodotDisplay = {
/*
* Window
*/
+ godot_js_display_window_title_set__proxy: 'sync',
godot_js_display_window_title_set__sig: 'vi',
godot_js_display_window_title_set: function (p_data) {
document.title = GodotRuntime.parseString(p_data);
},
+ godot_js_display_window_icon_set__proxy: 'sync',
godot_js_display_window_icon_set__sig: 'vii',
godot_js_display_window_icon_set: function (p_ptr, p_len) {
let link = document.getElementById('-gd-engine-icon');
@@ -593,6 +618,7 @@ const GodotDisplay = {
/*
* Cursor
*/
+ godot_js_display_cursor_set_visible__proxy: 'sync',
godot_js_display_cursor_set_visible__sig: 'vi',
godot_js_display_cursor_set_visible: function (p_visible) {
const visible = p_visible !== 0;
@@ -607,16 +633,19 @@ const GodotDisplay = {
}
},
+ godot_js_display_cursor_is_hidden__proxy: 'sync',
godot_js_display_cursor_is_hidden__sig: 'i',
godot_js_display_cursor_is_hidden: function () {
return !GodotDisplayCursor.visible;
},
+ godot_js_display_cursor_set_shape__proxy: 'sync',
godot_js_display_cursor_set_shape__sig: 'vi',
godot_js_display_cursor_set_shape: function (p_string) {
GodotDisplayCursor.set_shape(GodotRuntime.parseString(p_string));
},
+ godot_js_display_cursor_set_custom_shape__proxy: 'sync',
godot_js_display_cursor_set_custom_shape__sig: 'viiiii',
godot_js_display_cursor_set_custom_shape: function (p_shape, p_ptr, p_len, p_hotspot_x, p_hotspot_y) {
const shape = GodotRuntime.parseString(p_shape);
@@ -640,6 +669,7 @@ const GodotDisplay = {
}
},
+ godot_js_display_cursor_lock_set__proxy: 'sync',
godot_js_display_cursor_lock_set__sig: 'vi',
godot_js_display_cursor_lock_set: function (p_lock) {
if (p_lock) {
@@ -649,6 +679,7 @@ const GodotDisplay = {
}
},
+ godot_js_display_cursor_is_locked__proxy: 'sync',
godot_js_display_cursor_is_locked__sig: 'i',
godot_js_display_cursor_is_locked: function () {
return GodotDisplayCursor.isPointerLocked() ? 1 : 0;
@@ -657,6 +688,7 @@ const GodotDisplay = {
/*
* Listeners
*/
+ godot_js_display_fullscreen_cb__proxy: 'sync',
godot_js_display_fullscreen_cb__sig: 'vi',
godot_js_display_fullscreen_cb: function (callback) {
const canvas = GodotConfig.canvas;
@@ -671,6 +703,7 @@ const GodotDisplay = {
GodotEventListeners.add(document, 'webkitfullscreenchange', change_cb, false);
},
+ godot_js_display_window_blur_cb__proxy: 'sync',
godot_js_display_window_blur_cb__sig: 'vi',
godot_js_display_window_blur_cb: function (callback) {
const func = GodotRuntime.get_func(callback);
@@ -679,6 +712,7 @@ const GodotDisplay = {
}, false);
},
+ godot_js_display_notification_cb__proxy: 'sync',
godot_js_display_notification_cb__sig: 'viiiii',
godot_js_display_notification_cb: function (callback, p_enter, p_exit, p_in, p_out) {
const canvas = GodotConfig.canvas;
@@ -691,6 +725,7 @@ const GodotDisplay = {
});
},
+ godot_js_display_setup_canvas__proxy: 'sync',
godot_js_display_setup_canvas__sig: 'viiii',
godot_js_display_setup_canvas: function (p_width, p_height, p_fullscreen, p_hidpi) {
const canvas = GodotConfig.canvas;
@@ -725,6 +760,7 @@ const GodotDisplay = {
/*
* Virtual Keyboard
*/
+ godot_js_display_vk_show__proxy: 'sync',
godot_js_display_vk_show__sig: 'viiii',
godot_js_display_vk_show: function (p_text, p_type, p_start, p_end) {
const text = GodotRuntime.parseString(p_text);
@@ -733,21 +769,25 @@ const GodotDisplay = {
GodotDisplayVK.show(text, p_type, start, end);
},
+ godot_js_display_vk_hide__proxy: 'sync',
godot_js_display_vk_hide__sig: 'v',
godot_js_display_vk_hide: function () {
GodotDisplayVK.hide();
},
+ godot_js_display_vk_available__proxy: 'sync',
godot_js_display_vk_available__sig: 'i',
godot_js_display_vk_available: function () {
return GodotDisplayVK.available();
},
+ godot_js_display_tts_available__proxy: 'sync',
godot_js_display_tts_available__sig: 'i',
godot_js_display_tts_available: function () {
return 'speechSynthesis' in window;
},
+ godot_js_display_vk_cb__proxy: 'sync',
godot_js_display_vk_cb__sig: 'vi',
godot_js_display_vk_cb: function (p_input_cb) {
const input_cb = GodotRuntime.get_func(p_input_cb);
diff --git a/platform/web/js/libs/library_godot_fetch.js b/platform/web/js/libs/library_godot_fetch.js
index 4ef24903e3..00616bc1a5 100644
--- a/platform/web/js/libs/library_godot_fetch.js
+++ b/platform/web/js/libs/library_godot_fetch.js
@@ -125,6 +125,7 @@ const GodotFetch = {
},
},
+ godot_js_fetch_create__proxy: 'sync',
godot_js_fetch_create__sig: 'iiiiiii',
godot_js_fetch_create: function (p_method, p_url, p_headers, p_headers_size, p_body, p_body_size) {
const method = GodotRuntime.parseString(p_method);
@@ -145,6 +146,7 @@ const GodotFetch = {
}), body);
},
+ godot_js_fetch_state_get__proxy: 'sync',
godot_js_fetch_state_get__sig: 'ii',
godot_js_fetch_state_get: function (p_id) {
const obj = IDHandler.get(p_id);
@@ -166,6 +168,7 @@ const GodotFetch = {
return -1;
},
+ godot_js_fetch_http_status_get__proxy: 'sync',
godot_js_fetch_http_status_get__sig: 'ii',
godot_js_fetch_http_status_get: function (p_id) {
const obj = IDHandler.get(p_id);
@@ -175,6 +178,7 @@ const GodotFetch = {
return obj.status;
},
+ godot_js_fetch_read_headers__proxy: 'sync',
godot_js_fetch_read_headers__sig: 'iiii',
godot_js_fetch_read_headers: function (p_id, p_parse_cb, p_ref) {
const obj = IDHandler.get(p_id);
@@ -192,6 +196,7 @@ const GodotFetch = {
return 0;
},
+ godot_js_fetch_read_chunk__proxy: 'sync',
godot_js_fetch_read_chunk__sig: 'iiii',
godot_js_fetch_read_chunk: function (p_id, p_buf, p_buf_size) {
const obj = IDHandler.get(p_id);
@@ -218,6 +223,7 @@ const GodotFetch = {
return p_buf_size - to_read;
},
+ godot_js_fetch_is_chunked__proxy: 'sync',
godot_js_fetch_is_chunked__sig: 'ii',
godot_js_fetch_is_chunked: function (p_id) {
const obj = IDHandler.get(p_id);
@@ -227,6 +233,7 @@ const GodotFetch = {
return obj.chunked ? 1 : 0;
},
+ godot_js_fetch_free__proxy: 'sync',
godot_js_fetch_free__sig: 'vi',
godot_js_fetch_free: function (id) {
GodotFetch.free(id);
diff --git a/platform/web/js/libs/library_godot_input.js b/platform/web/js/libs/library_godot_input.js
index 1b221e78b3..92113e85c9 100644
--- a/platform/web/js/libs/library_godot_input.js
+++ b/platform/web/js/libs/library_godot_input.js
@@ -356,6 +356,7 @@ const GodotInput = {
/*
* Mouse API
*/
+ godot_js_input_mouse_move_cb__proxy: 'sync',
godot_js_input_mouse_move_cb__sig: 'vi',
godot_js_input_mouse_move_cb: function (callback) {
const func = GodotRuntime.get_func(callback);
@@ -374,6 +375,7 @@ const GodotInput = {
GodotEventListeners.add(window, 'mousemove', move_cb, false);
},
+ godot_js_input_mouse_wheel_cb__proxy: 'sync',
godot_js_input_mouse_wheel_cb__sig: 'vi',
godot_js_input_mouse_wheel_cb: function (callback) {
const func = GodotRuntime.get_func(callback);
@@ -385,6 +387,7 @@ const GodotInput = {
GodotEventListeners.add(GodotConfig.canvas, 'wheel', wheel_cb, false);
},
+ godot_js_input_mouse_button_cb__proxy: 'sync',
godot_js_input_mouse_button_cb__sig: 'vi',
godot_js_input_mouse_button_cb: function (callback) {
const func = GodotRuntime.get_func(callback);
@@ -409,6 +412,7 @@ const GodotInput = {
/*
* Touch API
*/
+ godot_js_input_touch_cb__proxy: 'sync',
godot_js_input_touch_cb__sig: 'viii',
godot_js_input_touch_cb: function (callback, ids, coords) {
const func = GodotRuntime.get_func(callback);
@@ -442,6 +446,7 @@ const GodotInput = {
/*
* Key API
*/
+ godot_js_input_key_cb__proxy: 'sync',
godot_js_input_key_cb__sig: 'viii',
godot_js_input_key_cb: function (callback, code, key) {
const func = GodotRuntime.get_func(callback);
@@ -459,23 +464,27 @@ const GodotInput = {
/*
* Gamepad API
*/
+ godot_js_input_gamepad_cb__proxy: 'sync',
godot_js_input_gamepad_cb__sig: 'vi',
godot_js_input_gamepad_cb: function (change_cb) {
const onchange = GodotRuntime.get_func(change_cb);
GodotInputGamepads.init(onchange);
},
+ godot_js_input_gamepad_sample_count__proxy: 'sync',
godot_js_input_gamepad_sample_count__sig: 'i',
godot_js_input_gamepad_sample_count: function () {
return GodotInputGamepads.get_samples().length;
},
+ godot_js_input_gamepad_sample__proxy: 'sync',
godot_js_input_gamepad_sample__sig: 'i',
godot_js_input_gamepad_sample: function () {
GodotInputGamepads.sample();
return 0;
},
+ godot_js_input_gamepad_sample_get__proxy: 'sync',
godot_js_input_gamepad_sample_get__sig: 'iiiiiii',
godot_js_input_gamepad_sample_get: function (p_index, r_btns, r_btns_num, r_axes, r_axes_num, r_standard) {
const sample = GodotInputGamepads.get_sample(p_index);
@@ -502,6 +511,7 @@ const GodotInput = {
/*
* Drag/Drop API
*/
+ godot_js_input_drop_files_cb__proxy: 'sync',
godot_js_input_drop_files_cb__sig: 'vi',
godot_js_input_drop_files_cb: function (callback) {
const func = GodotRuntime.get_func(callback);
@@ -524,6 +534,7 @@ const GodotInput = {
},
/* Paste API */
+ godot_js_input_paste_cb__proxy: 'sync',
godot_js_input_paste_cb__sig: 'vi',
godot_js_input_paste_cb: function (callback) {
const func = GodotRuntime.get_func(callback);
@@ -535,6 +546,7 @@ const GodotInput = {
}, false);
},
+ godot_js_input_vibrate_handheld__proxy: 'sync',
godot_js_input_vibrate_handheld__sig: 'vi',
godot_js_input_vibrate_handheld: function (p_duration_ms) {
if (typeof navigator.vibrate !== 'function') {
diff --git a/platform/web/js/libs/library_godot_javascript_singleton.js b/platform/web/js/libs/library_godot_javascript_singleton.js
index cbe59230ee..b17fde1544 100644
--- a/platform/web/js/libs/library_godot_javascript_singleton.js
+++ b/platform/web/js/libs/library_godot_javascript_singleton.js
@@ -121,6 +121,7 @@ const GodotJSWrapper = {
},
},
+ godot_js_wrapper_interface_get__proxy: 'sync',
godot_js_wrapper_interface_get__sig: 'ii',
godot_js_wrapper_interface_get: function (p_name) {
const name = GodotRuntime.parseString(p_name);
@@ -130,6 +131,7 @@ const GodotJSWrapper = {
return 0;
},
+ godot_js_wrapper_object_get__proxy: 'sync',
godot_js_wrapper_object_get__sig: 'iiii',
godot_js_wrapper_object_get: function (p_id, p_exchange, p_prop) {
const obj = GodotJSWrapper.get_proxied_value(p_id);
@@ -148,6 +150,7 @@ const GodotJSWrapper = {
return GodotJSWrapper.js2variant(obj, p_exchange);
},
+ godot_js_wrapper_object_set__proxy: 'sync',
godot_js_wrapper_object_set__sig: 'viiii',
godot_js_wrapper_object_set: function (p_id, p_name, p_type, p_exchange) {
const obj = GodotJSWrapper.get_proxied_value(p_id);
@@ -162,6 +165,7 @@ const GodotJSWrapper = {
}
},
+ godot_js_wrapper_object_call__proxy: 'sync',
godot_js_wrapper_object_call__sig: 'iiiiiiiii',
godot_js_wrapper_object_call: function (p_id, p_method, p_args, p_argc, p_convert_callback, p_exchange, p_lock, p_free_lock_callback) {
const obj = GodotJSWrapper.get_proxied_value(p_id);
@@ -189,6 +193,7 @@ const GodotJSWrapper = {
}
},
+ godot_js_wrapper_object_unref__proxy: 'sync',
godot_js_wrapper_object_unref__sig: 'vi',
godot_js_wrapper_object_unref: function (p_id) {
const proxy = IDHandler.get(p_id);
@@ -197,6 +202,7 @@ const GodotJSWrapper = {
}
},
+ godot_js_wrapper_create_cb__proxy: 'sync',
godot_js_wrapper_create_cb__sig: 'iii',
godot_js_wrapper_create_cb: function (p_ref, p_func) {
const func = GodotRuntime.get_func(p_func);
@@ -210,7 +216,7 @@ const GodotJSWrapper = {
// This is safe! JavaScript is single threaded (and using it in threads is not a good idea anyway).
GodotJSWrapper.cb_ret = null;
const args = Array.from(arguments);
- const argsProxy = GodotJSWrapper.MyProxy(args);
+ const argsProxy = new GodotJSWrapper.MyProxy(args);
func(p_ref, argsProxy.get_id(), args.length);
argsProxy.unref();
const ret = GodotJSWrapper.cb_ret;
@@ -221,11 +227,13 @@ const GodotJSWrapper = {
return id;
},
+ godot_js_wrapper_object_set_cb_ret__proxy: 'sync',
godot_js_wrapper_object_set_cb_ret__sig: 'vii',
godot_js_wrapper_object_set_cb_ret: function (p_val_type, p_val_ex) {
GodotJSWrapper.cb_ret = GodotJSWrapper.variant2js(p_val_type, p_val_ex);
},
+ godot_js_wrapper_object_getvar__proxy: 'sync',
godot_js_wrapper_object_getvar__sig: 'iiii',
godot_js_wrapper_object_getvar: function (p_id, p_type, p_exchange) {
const obj = GodotJSWrapper.get_proxied_value(p_id);
@@ -244,6 +252,7 @@ const GodotJSWrapper = {
}
},
+ godot_js_wrapper_object_setvar__proxy: 'sync',
godot_js_wrapper_object_setvar__sig: 'iiiiii',
godot_js_wrapper_object_setvar: function (p_id, p_key_type, p_key_ex, p_val_type, p_val_ex) {
const obj = GodotJSWrapper.get_proxied_value(p_id);
@@ -260,6 +269,7 @@ const GodotJSWrapper = {
}
},
+ godot_js_wrapper_create_object__proxy: 'sync',
godot_js_wrapper_create_object__sig: 'iiiiiiii',
godot_js_wrapper_create_object: function (p_object, p_args, p_argc, p_convert_callback, p_exchange, p_lock, p_free_lock_callback) {
const name = GodotRuntime.parseString(p_object);
diff --git a/platform/web/js/libs/library_godot_os.js b/platform/web/js/libs/library_godot_os.js
index 00ae399583..92635cb6ae 100644
--- a/platform/web/js/libs/library_godot_os.js
+++ b/platform/web/js/libs/library_godot_os.js
@@ -91,11 +91,13 @@ const GodotConfig = {
},
},
+ godot_js_config_canvas_id_get__proxy: 'sync',
godot_js_config_canvas_id_get__sig: 'vii',
godot_js_config_canvas_id_get: function (p_ptr, p_ptr_max) {
GodotRuntime.stringToHeap(`#${GodotConfig.canvas.id}`, p_ptr, p_ptr_max);
},
+ godot_js_config_locale_get__proxy: 'sync',
godot_js_config_locale_get__sig: 'vii',
godot_js_config_locale_get: function (p_ptr, p_ptr_max) {
GodotRuntime.stringToHeap(GodotConfig.locale, p_ptr, p_ptr_max);
@@ -266,22 +268,26 @@ const GodotOS = {
},
},
+ godot_js_os_finish_async__proxy: 'sync',
godot_js_os_finish_async__sig: 'vi',
godot_js_os_finish_async: function (p_callback) {
const func = GodotRuntime.get_func(p_callback);
GodotOS.finish_async(func);
},
+ godot_js_os_request_quit_cb__proxy: 'sync',
godot_js_os_request_quit_cb__sig: 'vi',
godot_js_os_request_quit_cb: function (p_callback) {
GodotOS.request_quit = GodotRuntime.get_func(p_callback);
},
+ godot_js_os_fs_is_persistent__proxy: 'sync',
godot_js_os_fs_is_persistent__sig: 'i',
godot_js_os_fs_is_persistent: function () {
return GodotFS.is_persistent();
},
+ godot_js_os_fs_sync__proxy: 'sync',
godot_js_os_fs_sync__sig: 'vi',
godot_js_os_fs_sync: function (callback) {
const func = GodotRuntime.get_func(callback);
@@ -291,6 +297,7 @@ const GodotOS = {
});
},
+ godot_js_os_has_feature__proxy: 'sync',
godot_js_os_has_feature__sig: 'ii',
godot_js_os_has_feature: function (p_ftr) {
const ftr = GodotRuntime.parseString(p_ftr);
@@ -313,6 +320,7 @@ const GodotOS = {
return 0;
},
+ godot_js_os_execute__proxy: 'sync',
godot_js_os_execute__sig: 'ii',
godot_js_os_execute: function (p_json) {
const json_args = GodotRuntime.parseString(p_json);
@@ -324,11 +332,13 @@ const GodotOS = {
return 1;
},
+ godot_js_os_shell_open__proxy: 'sync',
godot_js_os_shell_open__sig: 'vi',
godot_js_os_shell_open: function (p_uri) {
window.open(GodotRuntime.parseString(p_uri), '_blank');
},
+ godot_js_os_hw_concurrency_get__proxy: 'sync',
godot_js_os_hw_concurrency_get__sig: 'i',
godot_js_os_hw_concurrency_get: function () {
// TODO Godot core needs fixing to avoid spawning too many threads (> 24).
@@ -336,6 +346,7 @@ const GodotOS = {
return concurrency < 2 ? concurrency : 2;
},
+ godot_js_os_download_buffer__proxy: 'sync',
godot_js_os_download_buffer__sig: 'viiii',
godot_js_os_download_buffer: function (p_ptr, p_size, p_name, p_mime) {
const buf = GodotRuntime.heapSlice(HEAP8, p_ptr, p_size);
@@ -426,6 +437,7 @@ const GodotPWA = {
},
},
+ godot_js_pwa_cb__proxy: 'sync',
godot_js_pwa_cb__sig: 'vi',
godot_js_pwa_cb: function (p_update_cb) {
if ('serviceWorker' in navigator) {
@@ -434,6 +446,7 @@ const GodotPWA = {
}
},
+ godot_js_pwa_update__proxy: 'sync',
godot_js_pwa_update__sig: 'i',
godot_js_pwa_update: function () {
if ('serviceWorker' in navigator && GodotPWA.hasUpdate) {
diff --git a/platform/web/js/libs/library_godot_webgl2.js b/platform/web/js/libs/library_godot_webgl2.js
index 3c6de4a071..dbaec9f01b 100644
--- a/platform/web/js/libs/library_godot_webgl2.js
+++ b/platform/web/js/libs/library_godot_webgl2.js
@@ -32,6 +32,19 @@ const GodotWebGL2 = {
$GodotWebGL2__deps: ['$GL', '$GodotRuntime'],
$GodotWebGL2: {},
+ // This is implemented as "glGetBufferSubData" in new emscripten versions.
+ // Since we have to support older (pre 2.0.17) emscripten versions, we add this wrapper function instead.
+ godot_webgl2_glGetBufferSubData__proxy: 'sync',
+ godot_webgl2_glGetBufferSubData__sig: 'vippp',
+ godot_webgl2_glGetBufferSubData__deps: ['$GL', 'emscripten_webgl_get_current_context'],
+ godot_webgl2_glGetBufferSubData: function (target, offset, size, data) {
+ const gl_context_handle = _emscripten_webgl_get_current_context(); // eslint-disable-line no-undef
+ const gl = GL.getContext(gl_context_handle);
+ if (gl) {
+ gl.GLctx['getBufferSubData'](target, offset, HEAPU8, data, size);
+ }
+ },
+
godot_webgl2_glFramebufferTextureMultiviewOVR__deps: ['emscripten_webgl_get_current_context'],
godot_webgl2_glFramebufferTextureMultiviewOVR__proxy: 'sync',
godot_webgl2_glFramebufferTextureMultiviewOVR__sig: 'viiiiii',
diff --git a/platform/web/os_web.cpp b/platform/web/os_web.cpp
index f038f0248a..cbdcbf565d 100644
--- a/platform/web/os_web.cpp
+++ b/platform/web/os_web.cpp
@@ -132,6 +132,10 @@ int OS_Web::get_processor_count() const {
return godot_js_os_hw_concurrency_get();
}
+String OS_Web::get_unique_id() const {
+ ERR_FAIL_V_MSG("", "OS::get_unique_id() is not available on the Web platform.");
+}
+
bool OS_Web::_check_internal_feature_support(const String &p_feature) {
if (p_feature == "web") {
return true;
@@ -156,6 +160,12 @@ String OS_Web::get_name() const {
return "Web";
}
+void OS_Web::add_frame_delay(bool p_can_draw) {
+#ifndef PROXY_TO_PTHREAD_ENABLED
+ OS::add_frame_delay(p_can_draw);
+#endif
+}
+
void OS_Web::vibrate_handheld(int p_duration_ms) {
godot_js_input_vibrate_handheld(p_duration_ms);
}
diff --git a/platform/web/os_web.h b/platform/web/os_web.h
index b9570f9ca1..5a48997c17 100644
--- a/platform/web/os_web.h
+++ b/platform/web/os_web.h
@@ -33,6 +33,8 @@
#include "audio_driver_web.h"
+#include "godot_js.h"
+
#include "core/input/input.h"
#include "drivers/unix/os_unix.h"
#include "servers/audio_server.h"
@@ -48,11 +50,11 @@ class OS_Web : public OS_Unix {
bool idb_needs_sync = false;
bool pwa_is_waiting = false;
- static void main_loop_callback();
+ WASM_EXPORT static void main_loop_callback();
- static void file_access_close_callback(const String &p_file, int p_flags);
- static void fs_sync_callback();
- static void update_pwa_state_callback();
+ WASM_EXPORT static void file_access_close_callback(const String &p_file, int p_flags);
+ WASM_EXPORT static void fs_sync_callback();
+ WASM_EXPORT static void update_pwa_state_callback();
protected:
void initialize() override;
@@ -83,14 +85,16 @@ public:
int get_process_id() const override;
bool is_process_running(const ProcessID &p_pid) const override;
int get_processor_count() const override;
+ String get_unique_id() const override;
int get_default_thread_pool_size() const override { return 1; }
String get_executable_path() const override;
Error shell_open(String p_uri) override;
String get_name() const override;
+
// Override default OS implementation which would block the main thread with delay_usec.
// Implemented in web_main.cpp loop callback instead.
- void add_frame_delay(bool p_can_draw) override {}
+ void add_frame_delay(bool p_can_draw) override;
void vibrate_handheld(int p_duration_ms) override;
diff --git a/platform/web/web_main.cpp b/platform/web/web_main.cpp
index f199f8ffd8..ad2a801881 100644
--- a/platform/web/web_main.cpp
+++ b/platform/web/web_main.cpp
@@ -40,7 +40,10 @@
#include <stdlib.h>
static OS_Web *os = nullptr;
+#ifndef PROXY_TO_PTHREAD_ENABLED
static uint64_t target_ticks = 0;
+#endif
+
static bool main_started = false;
static bool shutdown_complete = false;
@@ -63,15 +66,20 @@ void cleanup_after_sync() {
}
void main_loop_callback() {
+#ifndef PROXY_TO_PTHREAD_ENABLED
uint64_t current_ticks = os->get_ticks_usec();
+#endif
bool force_draw = DisplayServerWeb::get_singleton()->check_size_force_redraw();
if (force_draw) {
Main::force_redraw();
+#ifndef PROXY_TO_PTHREAD_ENABLED
} else if (current_ticks < target_ticks) {
return; // Skip frame.
+#endif
}
+#ifndef PROXY_TO_PTHREAD_ENABLED
int max_fps = Engine::get_singleton()->get_max_fps();
if (max_fps > 0) {
if (current_ticks - target_ticks > 1000000) {
@@ -81,6 +89,8 @@ void main_loop_callback() {
}
target_ticks += (uint64_t)(1000000 / max_fps);
}
+#endif
+
if (os->main_loop_iterate()) {
emscripten_cancel_main_loop(); // Cancel current loop and set the cleanup one.
emscripten_set_main_loop(exit_callback, -1, false);