summaryrefslogtreecommitdiff
path: root/platform/javascript
diff options
context:
space:
mode:
Diffstat (limited to 'platform/javascript')
-rw-r--r--platform/javascript/SCsub11
-rw-r--r--platform/javascript/detect.py15
-rw-r--r--platform/javascript/engine.js10
-rw-r--r--platform/javascript/export/export.cpp10
-rw-r--r--platform/javascript/javascript_main.cpp2
-rw-r--r--platform/javascript/os_javascript.cpp52
-rw-r--r--platform/javascript/os_javascript.h4
7 files changed, 65 insertions, 39 deletions
diff --git a/platform/javascript/SCsub b/platform/javascript/SCsub
index 05992ebac8..66a8a8d93c 100644
--- a/platform/javascript/SCsub
+++ b/platform/javascript/SCsub
@@ -23,6 +23,7 @@ env.Append(LINKFLAGS=["-s", "EXPORTED_FUNCTIONS=\"['_main','_main_after_fs_sync'
target_dir = env.Dir("#bin")
build = env.add_program(['#bin/godot', target_dir.File('godot' + env['PROGSUFFIX'] + '.wasm')], javascript_objects, PROGSUFFIX=env['PROGSUFFIX'] + '.js');
+js, wasm = build
js_libraries = []
js_libraries.append(env.File('http_request.js'))
@@ -30,12 +31,10 @@ for lib in js_libraries:
env.Append(LINKFLAGS=['--js-library', lib.path])
env.Depends(build, js_libraries)
-prejs = env.File('pre.js')
-postjs = env.File('engine.js')
-env.Append(LINKFLAGS=['--pre-js', prejs.path])
-env.Append(LINKFLAGS=['--post-js', postjs.path])
-env.Depends(build, [prejs, postjs])
+wrapper_start = env.File('pre.js')
+wrapper_end = env.File('engine.js')
+js_final = env.Textfile('#bin/godot', [wrapper_start, js, wrapper_end], TEXTFILESUFFIX=env['PROGSUFFIX'] + '.wrapped.js')
zip_dir = target_dir.Dir('.javascript_zip')
-zip_files = env.InstallAs([zip_dir.File('godot.js'), zip_dir.File('godot.wasm'), zip_dir.File('godot.html')], build + ['#misc/dist/html/default.html'])
+zip_files = env.InstallAs([zip_dir.File('godot.js'), zip_dir.File('godot.wasm'), zip_dir.File('godot.html')], [js_final, wasm, '#misc/dist/html/default.html'])
Zip('#bin/godot', zip_files, ZIPSUFFIX=env['PROGSUFFIX'] + env['ZIPSUFFIX'], ZIPROOT=zip_dir, ZIPCOMSTR="Archving $SOURCES as $TARGET")
diff --git a/platform/javascript/detect.py b/platform/javascript/detect.py
index 8472c3ccab..7e6a1518ed 100644
--- a/platform/javascript/detect.py
+++ b/platform/javascript/detect.py
@@ -28,6 +28,11 @@ 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
+ # manages TLS.
+ ('module_mbedtls_enabled', False),
]
@@ -49,8 +54,14 @@ def configure(env):
## Build type
if (env["target"] == "release"):
- env.Append(CCFLAGS=['-O3'])
- env.Append(LINKFLAGS=['-O3'])
+ # Use -Os to prioritize optimizing for reduced file size. This is
+ # particularly valuable for the web platform because it directly
+ # decreases download time.
+ # -Os reduces file size by around 5 MiB over -O3. -Oz only saves about
+ # 100 KiB over -Os, which does not justify the negative impact on
+ # run-time performance.
+ env.Append(CCFLAGS=['-Os'])
+ env.Append(LINKFLAGS=['-Os'])
elif (env["target"] == "release_debug"):
env.Append(CCFLAGS=['-O2', '-DDEBUG_ENABLED'])
diff --git a/platform/javascript/engine.js b/platform/javascript/engine.js
index dc4bdc7efb..bca1851f40 100644
--- a/platform/javascript/engine.js
+++ b/platform/javascript/engine.js
@@ -138,13 +138,17 @@
}
var actualCanvas = this.rtenv.canvas;
- var context = false;
+ var testContext = false;
+ var testCanvas;
try {
- context = actualCanvas.getContext('webgl2') || actualCanvas.getContext('experimental-webgl2');
+ testCanvas = document.createElement('canvas');
+ testContext = testCanvas.getContext('webgl2') || testCanvas.getContext('experimental-webgl2');
} catch (e) {}
- if (!context) {
+ if (!testContext) {
throw new Error("WebGL 2 not available");
}
+ testCanvas = null;
+ testContext = null;
// canvas can grab focus on click
if (actualCanvas.tabIndex < 0) {
diff --git a/platform/javascript/export/export.cpp b/platform/javascript/export/export.cpp
index 61f55beb4e..d81aa25c32 100644
--- a/platform/javascript/export/export.cpp
+++ b/platform/javascript/export/export.cpp
@@ -71,7 +71,7 @@ public:
virtual void get_platform_features(List<String> *r_features) {
r_features->push_back("web");
- r_features->push_back("JavaScript");
+ r_features->push_back(get_os_name());
}
EditorExportPlatformJavaScript();
@@ -114,9 +114,9 @@ void EditorExportPlatformJavaScript::get_preset_features(const Ref<EditorExportP
void EditorExportPlatformJavaScript::get_export_options(List<ExportOption> *r_options) {
- r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "texture_format/s3tc"), false));
- r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "texture_format/etc"), true));
- r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "texture_format/etc2"), false));
+ r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "texture_format/s3tc"), true));
+ r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "texture_format/etc"), false));
+ r_options->push_back(ExportOption(PropertyInfo(Variant::BOOL, "texture_format/etc2"), true));
r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "html/custom_html_shell", PROPERTY_HINT_GLOBAL_FILE, "html"), ""));
r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "html/head_include", PROPERTY_HINT_MULTILINE_TEXT), ""));
r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "custom_template/release", PROPERTY_HINT_GLOBAL_FILE, "zip"), ""));
@@ -130,7 +130,7 @@ String EditorExportPlatformJavaScript::get_name() const {
String EditorExportPlatformJavaScript::get_os_name() const {
- return "JavaScript";
+ return "HTML5";
}
Ref<Texture> EditorExportPlatformJavaScript::get_logo() const {
diff --git a/platform/javascript/javascript_main.cpp b/platform/javascript/javascript_main.cpp
index b738f37d1b..e85fe0800f 100644
--- a/platform/javascript/javascript_main.cpp
+++ b/platform/javascript/javascript_main.cpp
@@ -65,7 +65,7 @@ int main(int argc, char *argv[]) {
FS.mkdir('/userfs');
FS.mount(IDBFS, {}, '/userfs');
FS.syncfs(true, function(err) {
- Module['ccall']('main_after_fs_sync', null, ['string'], [err ? err.message : ""])
+ ccall('main_after_fs_sync', null, ['string'], [err ? err.message : ""])
});
);
/* clang-format on */
diff --git a/platform/javascript/os_javascript.cpp b/platform/javascript/os_javascript.cpp
index c598557738..e226ab6332 100644
--- a/platform/javascript/os_javascript.cpp
+++ b/platform/javascript/os_javascript.cpp
@@ -81,12 +81,6 @@ void OS_JavaScript::initialize_core() {
FileAccess::make_default<FileAccessBufferedFA<FileAccessUnix> >(FileAccess::ACCESS_RESOURCES);
}
-void OS_JavaScript::set_opengl_extensions(const char *p_gl_extensions) {
-
- ERR_FAIL_COND(!p_gl_extensions);
- gl_extensions = p_gl_extensions;
-}
-
static EM_BOOL _browser_resize_callback(int event_type, const EmscriptenUiEvent *ui_event, void *user_data) {
ERR_FAIL_COND_V(event_type != EMSCRIPTEN_EVENT_RESIZE, false);
@@ -436,16 +430,11 @@ Error OS_JavaScript::initialize(const VideoMode &p_desired, int p_video_driver,
// can't fulfil fullscreen request due to browser security
video_mode.fullscreen = false;
/* clang-format off */
- bool resize_canvas_on_start = EM_ASM_INT_V(
- return Module.resizeCanvasOnStart;
- );
- /* clang-format on */
- if (resize_canvas_on_start) {
+ if (EM_ASM_INT_V({ return Module.resizeCanvasOnStart })) {
+ /* clang-format on */
set_window_size(Size2(video_mode.width, video_mode.height));
} else {
- Size2 canvas_size = get_window_size();
- video_mode.width = canvas_size.width;
- video_mode.height = canvas_size.height;
+ set_window_size(get_window_size());
}
char locale_ptr[16];
@@ -566,7 +555,7 @@ void OS_JavaScript::set_css_cursor(const char *p_cursor) {
/* clang-format off */
EM_ASM_({
- Module.canvas.style.cursor = Module.UTF8ToString($0);
+ Module.canvas.style.cursor = UTF8ToString($0);
}, p_cursor);
/* clang-format on */
}
@@ -576,7 +565,7 @@ const char *OS_JavaScript::get_css_cursor() const {
char cursor[16];
/* clang-format off */
EM_ASM_INT({
- Module.stringToUTF8(Module.canvas.style.cursor ? Module.canvas.style.cursor : 'auto', $0, 16);
+ stringToUTF8(Module.canvas.style.cursor ? Module.canvas.style.cursor : 'auto', $0, 16);
}, cursor);
/* clang-format on */
return cursor;
@@ -782,6 +771,9 @@ void OS_JavaScript::set_cursor_shape(CursorShape p_shape) {
set_css_cursor(godot2dom_cursor(cursor_shape));
}
+void OS_JavaScript::set_custom_mouse_cursor(const RES &p_cursor, CursorShape p_shape, const Vector2 &p_hotspot) {
+}
+
void OS_JavaScript::main_loop_begin() {
if (main_loop)
@@ -789,7 +781,7 @@ void OS_JavaScript::main_loop_begin() {
/* clang-format off */
EM_ASM_ARGS({
- const send_notification = Module.cwrap('send_notification', null, ['number']);
+ const send_notification = cwrap('send_notification', null, ['number']);
const notifs = arguments;
(['mouseover', 'mouseleave', 'focus', 'blur']).forEach(function(event, i) {
Module.canvas.addEventListener(event, send_notification.bind(null, notifs[i]));
@@ -972,7 +964,25 @@ int OS_JavaScript::get_power_percent_left() {
bool OS_JavaScript::_check_internal_feature_support(const String &p_feature) {
- return p_feature == "web" || p_feature == "s3tc"; // TODO check for these features really being available
+ if (p_feature == "HTML5" || p_feature == "web")
+ return true;
+
+#ifdef JAVASCRIPT_EVAL_ENABLED
+ if (p_feature == "JavaScript")
+ return true;
+#endif
+
+ EMSCRIPTEN_WEBGL_CONTEXT_HANDLE ctx = emscripten_webgl_get_current_context();
+ // all extensions are already automatically enabled, this function allows
+ // checking WebGL extension support without inline JavaScript
+ if (p_feature == "s3tc" && emscripten_webgl_enable_extension(ctx, "WEBGL_compressed_texture_s3tc_srgb"))
+ return true;
+ if (p_feature == "etc" && emscripten_webgl_enable_extension(ctx, "WEBGL_compressed_texture_etc1"))
+ return true;
+ if (p_feature == "etc2" && emscripten_webgl_enable_extension(ctx, "WEBGL_compressed_texture_etc"))
+ return true;
+
+ return false;
}
void OS_JavaScript::set_idbfs_available(bool p_idbfs_available) {
@@ -986,9 +996,9 @@ bool OS_JavaScript::is_userfs_persistent() const {
}
OS_JavaScript::OS_JavaScript(const char *p_execpath, GetUserDataDirFunc p_get_user_data_dir_func) {
+
set_cmdline(p_execpath, get_cmdline_args());
main_loop = NULL;
- gl_extensions = NULL;
window_maximized = false;
soft_fs_enabled = false;
canvas_size_adjustment_requested = false;
@@ -998,6 +1008,10 @@ OS_JavaScript::OS_JavaScript(const char *p_execpath, GetUserDataDirFunc p_get_us
idbfs_available = false;
time_to_save_sync = -1;
+
+ Vector<Logger *> loggers;
+ loggers.push_back(memnew(StdLogger));
+ _set_logger(memnew(CompositeLogger(loggers)));
}
OS_JavaScript::~OS_JavaScript() {
diff --git a/platform/javascript/os_javascript.h b/platform/javascript/os_javascript.h
index 2af90ef16b..f0ba9422e8 100644
--- a/platform/javascript/os_javascript.h
+++ b/platform/javascript/os_javascript.h
@@ -52,7 +52,6 @@ class OS_JavaScript : public OS_Unix {
VisualServer *visual_server;
AudioDriverJavaScript audio_driver_javascript;
- const char *gl_extensions;
InputDefault *input;
Vector2 windowed_size;
@@ -128,6 +127,7 @@ public:
virtual bool is_userfs_persistent() const;
virtual void set_cursor_shape(CursorShape p_shape);
+ virtual void set_custom_mouse_cursor(const RES &p_cursor, CursorShape p_shape, const Vector2 &p_hotspot);
void main_loop_begin();
bool main_loop_iterate();
@@ -138,8 +138,6 @@ public:
virtual bool has_touchscreen_ui_hint() const;
- void set_opengl_extensions(const char *p_gl_extensions);
-
virtual Error shell_open(String p_uri);
virtual String get_user_data_dir() const;
String get_executable_path() const;