summaryrefslogtreecommitdiff
path: root/platform/javascript
diff options
context:
space:
mode:
Diffstat (limited to 'platform/javascript')
-rw-r--r--platform/javascript/api/api.cpp2
-rw-r--r--platform/javascript/api/javascript_eval.h2
-rw-r--r--platform/javascript/detect.py5
-rw-r--r--platform/javascript/dom_keys.inc2
-rw-r--r--platform/javascript/engine.js3
-rw-r--r--platform/javascript/export/export.cpp10
-rw-r--r--platform/javascript/http_client_javascript.cpp8
-rw-r--r--platform/javascript/javascript_eval.cpp3
-rw-r--r--platform/javascript/javascript_main.cpp2
-rw-r--r--platform/javascript/os_javascript.cpp113
-rw-r--r--platform/javascript/os_javascript.h7
-rw-r--r--platform/javascript/pre.js3
12 files changed, 126 insertions, 34 deletions
diff --git a/platform/javascript/api/api.cpp b/platform/javascript/api/api.cpp
index b377ca4e52..c7a6d53561 100644
--- a/platform/javascript/api/api.cpp
+++ b/platform/javascript/api/api.cpp
@@ -29,7 +29,7 @@
/*************************************************************************/
#include "api.h"
-#include "engine.h"
+#include "core/engine.h"
#include "javascript_eval.h"
static JavaScript *javascript_eval;
diff --git a/platform/javascript/api/javascript_eval.h b/platform/javascript/api/javascript_eval.h
index 05f7c9f38a..49d5309737 100644
--- a/platform/javascript/api/javascript_eval.h
+++ b/platform/javascript/api/javascript_eval.h
@@ -31,7 +31,7 @@
#ifndef JAVASCRIPT_EVAL_H
#define JAVASCRIPT_EVAL_H
-#include "object.h"
+#include "core/object.h"
class JavaScript : public Object {
private:
diff --git a/platform/javascript/detect.py b/platform/javascript/detect.py
index fc909f6619..cf85c3df7f 100644
--- a/platform/javascript/detect.py
+++ b/platform/javascript/detect.py
@@ -25,7 +25,6 @@ def get_opts():
def get_flags():
return [
('tools', False),
- ('module_theora_enabled', False),
# Disabling the mbedtls module reduces file size.
# The module has little use due to the limited networking functionality
# in this platform. For the available networking methods, the browser
@@ -129,6 +128,10 @@ def configure(env):
# us since we don't know requirements at compile-time.
env.Append(LINKFLAGS=['-s', 'ALLOW_MEMORY_GROWTH=1'])
+ # Since we use both memory growth and MEMFS preloading,
+ # this avoids unecessary copying on start-up.
+ env.Append(LINKFLAGS=['--no-heap-copy'])
+
# This setting just makes WebGL 2 APIs available, it does NOT disable WebGL 1.
env.Append(LINKFLAGS=['-s', 'USE_WEBGL2=1'])
diff --git a/platform/javascript/dom_keys.inc b/platform/javascript/dom_keys.inc
index dc8d67d52b..a30818decc 100644
--- a/platform/javascript/dom_keys.inc
+++ b/platform/javascript/dom_keys.inc
@@ -28,7 +28,7 @@
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/
-#include "os/keyboard.h"
+#include "core/os/keyboard.h"
// https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/keyCode#Constants_for_keyCode_value
#define DOM_VK_CANCEL 0x03
diff --git a/platform/javascript/engine.js b/platform/javascript/engine.js
index c3ef5bbbb5..91458eb4c3 100644
--- a/platform/javascript/engine.js
+++ b/platform/javascript/engine.js
@@ -1,3 +1,6 @@
+ // 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;
diff --git a/platform/javascript/export/export.cpp b/platform/javascript/export/export.cpp
index a7f0084562..7a325e81dd 100644
--- a/platform/javascript/export/export.cpp
+++ b/platform/javascript/export/export.cpp
@@ -28,9 +28,9 @@
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/
+#include "core/io/zip_io.h"
#include "editor/editor_node.h"
#include "editor_export.h"
-#include "io/zip_io.h"
#include "main/splash.gen.h"
#include "platform/javascript/logo.gen.h"
#include "platform/javascript/run_icon.gen.h"
@@ -58,7 +58,7 @@ public:
virtual Ref<Texture> get_logo() const;
virtual bool can_export(const Ref<EditorExportPreset> &p_preset, String &r_error, bool &r_missing_templates) const;
- virtual String get_binary_extension(const Ref<EditorExportPreset> &p_preset) const;
+ virtual List<String> get_binary_extensions(const Ref<EditorExportPreset> &p_preset) const;
virtual Error export_project(const Ref<EditorExportPreset> &p_preset, bool p_debug, const String &p_path, int p_flags = 0);
virtual bool poll_devices();
@@ -174,9 +174,11 @@ bool EditorExportPlatformJavaScript::can_export(const Ref<EditorExportPreset> &p
return valid;
}
-String EditorExportPlatformJavaScript::get_binary_extension(const Ref<EditorExportPreset> &p_preset) const {
+List<String> EditorExportPlatformJavaScript::get_binary_extensions(const Ref<EditorExportPreset> &p_preset) const {
- return "html";
+ List<String> list;
+ list.push_back("html");
+ return list;
}
Error EditorExportPlatformJavaScript::export_project(const Ref<EditorExportPreset> &p_preset, bool p_debug, const String &p_path, int p_flags) {
diff --git a/platform/javascript/http_client_javascript.cpp b/platform/javascript/http_client_javascript.cpp
index 8d90e01ae1..ccf4f8a11b 100644
--- a/platform/javascript/http_client_javascript.cpp
+++ b/platform/javascript/http_client_javascript.cpp
@@ -28,8 +28,8 @@
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/
+#include "core/io/http_client.h"
#include "http_request.h"
-#include "io/http_client.h"
Error HTTPClient::connect_to_host(const String &p_host, int p_port, bool p_ssl, bool p_verify_host) {
@@ -237,7 +237,7 @@ Error HTTPClient::poll() {
case STATUS_CONNECTION_ERROR:
return ERR_CONNECTION_ERROR;
- case STATUS_REQUESTING:
+ case STATUS_REQUESTING: {
#ifdef DEBUG_ENABLED
if (!has_polled) {
@@ -281,6 +281,10 @@ Error HTTPClient::poll() {
godot_xhr_get_response(xhr_id, write.ptr(), polled_response.size());
write = PoolByteArray::Write();
break;
+ }
+
+ default:
+ ERR_FAIL_V(ERR_BUG);
}
return OK;
}
diff --git a/platform/javascript/javascript_eval.cpp b/platform/javascript/javascript_eval.cpp
index 07b4c192e6..9b8174cc71 100644
--- a/platform/javascript/javascript_eval.cpp
+++ b/platform/javascript/javascript_eval.cpp
@@ -140,8 +140,9 @@ Variant JavaScript::eval(const String &p_code, bool p_use_global_exec_context) {
case Variant::POOL_BYTE_ARRAY:
arr_write = PoolByteArray::Write();
return arr;
+ default:
+ return Variant();
}
- return Variant();
}
#endif // JAVASCRIPT_EVAL_ENABLED
diff --git a/platform/javascript/javascript_main.cpp b/platform/javascript/javascript_main.cpp
index 3829e8d406..ec60571402 100644
--- a/platform/javascript/javascript_main.cpp
+++ b/platform/javascript/javascript_main.cpp
@@ -28,7 +28,7 @@
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/
-#include "io/resource_loader.h"
+#include "core/io/resource_loader.h"
#include "main/main.h"
#include "os_javascript.h"
diff --git a/platform/javascript/os_javascript.cpp b/platform/javascript/os_javascript.cpp
index 80699b0d32..9250ca4903 100644
--- a/platform/javascript/os_javascript.cpp
+++ b/platform/javascript/os_javascript.cpp
@@ -30,15 +30,16 @@
#include "os_javascript.h"
-#include "gles2/rasterizer_gles2.h"
-#include "gles3/rasterizer_gles3.h"
-#include "io/file_access_buffered_fa.h"
+#include "core/io/file_access_buffered_fa.h"
+#include "drivers/gles2/rasterizer_gles2.h"
+#include "drivers/gles3/rasterizer_gles3.h"
+#include "drivers/unix/dir_access_unix.h"
+#include "drivers/unix/file_access_unix.h"
#include "main/main.h"
#include "servers/visual/visual_server_raster.h"
-#include "unix/dir_access_unix.h"
-#include "unix/file_access_unix.h"
#include <emscripten.h>
+#include <png.h>
#include <stdlib.h>
#include "dom_keys.inc"
@@ -120,14 +121,14 @@ void OS_JavaScript::set_window_size(const Size2 p_size) {
emscripten_exit_soft_fullscreen();
window_maximized = false;
}
- emscripten_set_canvas_size(p_size.x, p_size.y);
+ emscripten_set_canvas_element_size(NULL, p_size.x, p_size.y);
}
}
Size2 OS_JavaScript::get_window_size() const {
- int canvas[3];
- emscripten_get_canvas_size(canvas, canvas + 1, canvas + 2);
+ int canvas[2];
+ emscripten_get_canvas_element_size(NULL, canvas, canvas + 1);
return Size2(canvas[0], canvas[1]);
}
@@ -377,15 +378,13 @@ static void set_css_cursor(const char *p_cursor) {
/* clang-format on */
}
-static const char *get_css_cursor() {
+static bool is_css_cursor_hidden() {
- char cursor[16];
/* clang-format off */
- EM_ASM_INT({
- stringToUTF8(Module.canvas.style.cursor ? Module.canvas.style.cursor : 'auto', $0, 16);
- }, cursor);
+ return EM_ASM_INT({
+ return Module.canvas.style.cursor === 'none';
+ });
/* clang-format on */
- return cursor;
}
void OS_JavaScript::set_cursor_shape(CursorShape p_shape) {
@@ -429,7 +428,7 @@ void OS_JavaScript::set_mouse_mode(OS::MouseMode p_mode) {
OS::MouseMode OS_JavaScript::get_mouse_mode() const {
- if (String::utf8(get_css_cursor()) == "none")
+ if (is_css_cursor_hidden())
return MOUSE_MODE_HIDDEN;
EmscriptenPointerlockChangeEvent ev;
@@ -565,8 +564,11 @@ void OS_JavaScript::process_joypads() {
int joypad_count = emscripten_get_num_gamepads();
for (int joypad = 0; joypad < joypad_count; joypad++) {
EmscriptenGamepadEvent state;
- emscripten_get_gamepad_status(joypad, &state);
- if (state.connected) {
+ EMSCRIPTEN_RESULT query_result = emscripten_get_gamepad_status(joypad, &state);
+ // Chromium reserves gamepads slots, so NO_DATA is an expected result.
+ ERR_CONTINUE(query_result != EMSCRIPTEN_RESULT_SUCCESS &&
+ query_result != EMSCRIPTEN_RESULT_NO_DATA);
+ if (query_result == EMSCRIPTEN_RESULT_SUCCESS && state.connected) {
int button_count = MIN(state.numButtons, 18);
int axis_count = MIN(state.numAxes, 8);
@@ -705,7 +707,7 @@ Error OS_JavaScript::initialize(const VideoMode &p_desired, int p_video_driver,
video_driver_index = p_video_driver;
video_mode = p_desired;
- // Can't fulfil fullscreen request during start-up due to browser security.
+ // Can't fulfill fullscreen request during start-up due to browser security.
video_mode.fullscreen = false;
/* clang-format off */
if (EM_ASM_INT_V({ return Module.resizeCanvasOnStart })) {
@@ -831,13 +833,13 @@ bool OS_JavaScript::main_loop_iterate() {
strategy.canvasResizedCallback = NULL;
emscripten_enter_soft_fullscreen(NULL, &strategy);
} else {
- emscripten_set_canvas_size(windowed_size.width, windowed_size.height);
+ emscripten_set_canvas_element_size(NULL, windowed_size.width, windowed_size.height);
}
just_exited_fullscreen = false;
}
- int canvas[3];
- emscripten_get_canvas_size(canvas, canvas + 1, canvas + 2);
+ int canvas[2];
+ emscripten_get_canvas_element_size(NULL, canvas, canvas + 1);
video_mode.width = canvas[0];
video_mode.height = canvas[1];
if (!window_maximized && !video_mode.fullscreen && !just_exited_fullscreen && !entering_fullscreen) {
@@ -860,6 +862,24 @@ void OS_JavaScript::finalize() {
// Miscellaneous
+Error OS_JavaScript::execute(const String &p_path, const List<String> &p_arguments, bool p_blocking, ProcessID *r_child_id, String *r_pipe, int *r_exitcode, bool read_stderr) {
+
+ ERR_EXPLAIN("OS::execute() is not available on the HTML5 platform");
+ ERR_FAIL_V(ERR_UNAVAILABLE);
+}
+
+Error OS_JavaScript::kill(const ProcessID &p_pid) {
+
+ ERR_EXPLAIN("OS::kill() is not available on the HTML5 platform");
+ ERR_FAIL_V(ERR_UNAVAILABLE);
+}
+
+int OS_JavaScript::get_process_id() const {
+
+ ERR_EXPLAIN("OS::get_process_id() is not available on the HTML5 platform");
+ ERR_FAIL_V(0);
+}
+
extern "C" EMSCRIPTEN_KEEPALIVE void send_notification(int p_notification) {
if (p_notification == MainLoop::NOTIFICATION_WM_MOUSE_ENTER || p_notification == MainLoop::NOTIFICATION_WM_MOUSE_EXIT) {
@@ -909,6 +929,57 @@ void OS_JavaScript::set_window_title(const String &p_title) {
/* clang-format on */
}
+void OS_JavaScript::set_icon(const Ref<Image> &p_icon) {
+
+ ERR_FAIL_COND(p_icon.is_null());
+ Ref<Image> icon = p_icon;
+ if (icon->is_compressed()) {
+ icon = icon->duplicate();
+ ERR_FAIL_COND(icon->decompress() != OK)
+ }
+ if (icon->get_format() != Image::FORMAT_RGBA8) {
+ if (icon == p_icon)
+ icon = icon->duplicate();
+ icon->convert(Image::FORMAT_RGBA8);
+ }
+
+ png_image png_meta;
+ memset(&png_meta, 0, sizeof png_meta);
+ png_meta.version = PNG_IMAGE_VERSION;
+ png_meta.width = icon->get_width();
+ png_meta.height = icon->get_height();
+ png_meta.format = PNG_FORMAT_RGBA;
+
+ PoolByteArray 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));
+
+ 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();
+ /* clang-format off */
+ EM_ASM_ARGS({
+ var PNG_PTR = $0;
+ var PNG_LEN = $1;
+
+ var png = new Blob([HEAPU8.slice(PNG_PTR, PNG_PTR + PNG_LEN)], { type: "image/png" });
+ var url = URL.createObjectURL(png);
+ var link = document.getElementById('-gd-engine-icon');
+ if (link === null) {
+ link = document.createElement('link');
+ link.rel = 'icon';
+ link.id = '-gd-engine-icon';
+ document.head.appendChild(link);
+ }
+ link.href = url;
+ }, r.ptr(), len);
+ /* clang-format on */
+}
+
String OS_JavaScript::get_executable_path() const {
return OS::get_executable_path();
diff --git a/platform/javascript/os_javascript.h b/platform/javascript/os_javascript.h
index f40fb8fc7e..79dac5940f 100644
--- a/platform/javascript/os_javascript.h
+++ b/platform/javascript/os_javascript.h
@@ -32,10 +32,10 @@
#define OS_JAVASCRIPT_H
#include "audio_driver_javascript.h"
+#include "drivers/unix/os_unix.h"
#include "main/input_default.h"
#include "servers/audio_server.h"
#include "servers/visual/rasterizer.h"
-#include "unix/os_unix.h"
#include <emscripten/html5.h>
@@ -133,8 +133,13 @@ public:
void run_async();
bool main_loop_iterate();
+ virtual Error execute(const String &p_path, const List<String> &p_arguments, bool p_blocking, ProcessID *r_child_id = NULL, String *r_pipe = NULL, int *r_exitcode = NULL, bool read_stderr = false);
+ virtual Error kill(const ProcessID &p_pid);
+ virtual int get_process_id() const;
+
virtual void alert(const String &p_alert, const String &p_title = "ALERT!");
virtual void set_window_title(const String &p_title);
+ virtual void set_icon(const Ref<Image> &p_icon);
String get_executable_path() const;
virtual Error shell_open(String p_uri);
virtual String get_name();
diff --git a/platform/javascript/pre.js b/platform/javascript/pre.js
index 02194bc75e..a870e676ea 100644
--- a/platform/javascript/pre.js
+++ b/platform/javascript/pre.js
@@ -1,2 +1,5 @@
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.