summaryrefslogtreecommitdiffstats
path: root/platform/web
diff options
context:
space:
mode:
Diffstat (limited to 'platform/web')
-rw-r--r--platform/web/api/api.cpp12
-rw-r--r--platform/web/api/web_tools_editor_plugin.cpp6
-rw-r--r--platform/web/api/web_tools_editor_plugin.h6
-rw-r--r--platform/web/audio_driver_web.h4
-rw-r--r--platform/web/display_server_web.cpp27
-rw-r--r--platform/web/display_server_web.h5
-rw-r--r--platform/web/export/export.cpp3
-rw-r--r--platform/web/export/export_plugin.cpp5
-rw-r--r--platform/web/export/export_plugin.h3
-rw-r--r--platform/web/godot_audio.h3
-rw-r--r--platform/web/godot_js.h2
-rw-r--r--platform/web/godot_webgl2.h4
-rw-r--r--platform/web/http_client_web.h2
-rw-r--r--platform/web/javascript_bridge_singleton.cpp4
-rw-r--r--platform/web/js/libs/library_godot_fetch.js5
-rw-r--r--platform/web/os_web.cpp8
-rw-r--r--platform/web/os_web.h1
-rw-r--r--platform/web/web_main.cpp8
18 files changed, 78 insertions, 30 deletions
diff --git a/platform/web/api/api.cpp b/platform/web/api/api.cpp
index a630e3d866..ab7154b0fb 100644
--- a/platform/web/api/api.cpp
+++ b/platform/web/api/api.cpp
@@ -29,10 +29,12 @@
/**************************************************************************/
#include "api.h"
-#include "core/config/engine.h"
+
#include "javascript_bridge_singleton.h"
#include "web_tools_editor_plugin.h"
+#include "core/config/engine.h"
+
static JavaScriptBridge *javascript_bridge_singleton;
void register_web_api() {
@@ -78,6 +80,7 @@ void JavaScriptBridge::_bind_methods() {
}
#if !defined(WEB_ENABLED) || !defined(JAVASCRIPT_EVAL_ENABLED)
+
Variant JavaScriptBridge::eval(const String &p_code, bool p_use_global_exec_context) {
return Variant();
}
@@ -104,16 +107,23 @@ Variant JavaScriptBridge::_create_object_bind(const Variant **p_args, int p_argc
}
return Ref<JavaScriptObject>();
}
+
#endif
+
#if !defined(WEB_ENABLED)
+
bool JavaScriptBridge::pwa_needs_update() const {
return false;
}
+
Error JavaScriptBridge::pwa_update() {
return ERR_UNAVAILABLE;
}
+
void JavaScriptBridge::force_fs_sync() {
}
+
void JavaScriptBridge::download_buffer(Vector<uint8_t> p_arr, const String &p_name, const String &p_mime) {
}
+
#endif
diff --git a/platform/web/api/web_tools_editor_plugin.cpp b/platform/web/api/web_tools_editor_plugin.cpp
index 213204ff33..d39773bde2 100644
--- a/platform/web/api/web_tools_editor_plugin.cpp
+++ b/platform/web/api/web_tools_editor_plugin.cpp
@@ -28,9 +28,10 @@
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/**************************************************************************/
-#if defined(TOOLS_ENABLED) && defined(WEB_ENABLED)
#include "web_tools_editor_plugin.h"
+#if defined(TOOLS_ENABLED) && defined(WEB_ENABLED)
+
#include "core/config/engine.h"
#include "core/config/project_settings.h"
#include "core/io/dir_access.h"
@@ -154,4 +155,5 @@ void WebToolsEditorPlugin::_zip_recursive(String p_path, String p_base_path, zip
cur = dir->get_next();
}
}
-#endif
+
+#endif // TOOLS_ENABLED && WEB_ENABLED
diff --git a/platform/web/api/web_tools_editor_plugin.h b/platform/web/api/web_tools_editor_plugin.h
index fc74899a58..ac0d5e20ec 100644
--- a/platform/web/api/web_tools_editor_plugin.h
+++ b/platform/web/api/web_tools_editor_plugin.h
@@ -32,6 +32,7 @@
#define WEB_TOOLS_EDITOR_PLUGIN_H
#if defined(TOOLS_ENABLED) && defined(WEB_ENABLED)
+
#include "core/io/zip_io.h"
#include "editor/editor_plugin.h"
@@ -48,11 +49,14 @@ public:
WebToolsEditorPlugin();
};
+
#else
+
class WebToolsEditorPlugin {
public:
static void initialize() {}
};
-#endif
+
+#endif // TOOLS_ENABLED && WEB_ENABLED
#endif // WEB_TOOLS_EDITOR_PLUGIN_H
diff --git a/platform/web/audio_driver_web.h b/platform/web/audio_driver_web.h
index be13935bd9..7bfed834e1 100644
--- a/platform/web/audio_driver_web.h
+++ b/platform/web/audio_driver_web.h
@@ -31,12 +31,12 @@
#ifndef AUDIO_DRIVER_WEB_H
#define AUDIO_DRIVER_WEB_H
+#include "godot_audio.h"
+
#include "core/os/mutex.h"
#include "core/os/thread.h"
#include "servers/audio_server.h"
-#include "godot_audio.h"
-
class AudioDriverWeb : public AudioDriver {
private:
struct AudioContext {
diff --git a/platform/web/display_server_web.cpp b/platform/web/display_server_web.cpp
index 28f1914c37..6cb56b404f 100644
--- a/platform/web/display_server_web.cpp
+++ b/platform/web/display_server_web.cpp
@@ -30,18 +30,20 @@
#include "display_server_web.h"
+#include "dom_keys.inc"
+#include "godot_js.h"
+#include "os_web.h"
+
+#include "core/config/project_settings.h"
+#include "servers/rendering/dummy/rasterizer_dummy.h"
+
#ifdef GLES3_ENABLED
#include "drivers/gles3/rasterizer_gles3.h"
#endif
-#include "platform/web/os_web.h"
-#include "servers/rendering/dummy/rasterizer_dummy.h"
#include <emscripten.h>
#include <png.h>
-#include "dom_keys.inc"
-#include "godot_js.h"
-
#define DOM_BUTTON_LEFT 0
#define DOM_BUTTON_MIDDLE 1
#define DOM_BUTTON_RIGHT 2
@@ -298,10 +300,12 @@ const char *DisplayServerWeb::godot2dom_cursor(DisplayServer::CursorShape p_shap
}
bool DisplayServerWeb::tts_is_speaking() const {
+ ERR_FAIL_COND_V_MSG(!tts, false, "Enable the \"audio/general/text_to_speech\" project setting to use text-to-speech.");
return godot_js_tts_is_speaking();
}
bool DisplayServerWeb::tts_is_paused() const {
+ ERR_FAIL_COND_V_MSG(!tts, false, "Enable the \"audio/general/text_to_speech\" project setting to use text-to-speech.");
return godot_js_tts_is_paused();
}
@@ -320,11 +324,13 @@ void DisplayServerWeb::update_voices_callback(int p_size, const char **p_voice)
}
TypedArray<Dictionary> DisplayServerWeb::tts_get_voices() const {
+ ERR_FAIL_COND_V_MSG(!tts, TypedArray<Dictionary>(), "Enable the \"audio/general/text_to_speech\" project setting to use text-to-speech.");
godot_js_tts_get_voices(update_voices_callback);
return voices;
}
void DisplayServerWeb::tts_speak(const String &p_text, const String &p_voice, int p_volume, float p_pitch, float p_rate, int p_utterance_id, bool p_interrupt) {
+ ERR_FAIL_COND_MSG(!tts, "Enable the \"audio/general/text_to_speech\" project setting to use text-to-speech.");
if (p_interrupt) {
tts_stop();
}
@@ -341,14 +347,17 @@ void DisplayServerWeb::tts_speak(const String &p_text, const String &p_voice, in
}
void DisplayServerWeb::tts_pause() {
+ ERR_FAIL_COND_MSG(!tts, "Enable the \"audio/general/text_to_speech\" project setting to use text-to-speech.");
godot_js_tts_pause();
}
void DisplayServerWeb::tts_resume() {
+ ERR_FAIL_COND_MSG(!tts, "Enable the \"audio/general/text_to_speech\" project setting to use text-to-speech.");
godot_js_tts_resume();
}
void DisplayServerWeb::tts_stop() {
+ ERR_FAIL_COND_MSG(!tts, "Enable the \"audio/general/text_to_speech\" project setting to use text-to-speech.");
for (const KeyValue<int, CharString> &E : utterance_ids) {
tts_post_utterance_event(DisplayServer::TTS_UTTERANCE_CANCELED, E.key);
}
@@ -771,6 +780,8 @@ DisplayServer *DisplayServerWeb::create_func(const String &p_rendering_driver, W
DisplayServerWeb::DisplayServerWeb(const String &p_rendering_driver, WindowMode p_window_mode, VSyncMode p_vsync_mode, uint32_t p_flags, const Point2i *p_position, const Size2i &p_resolution, int p_screen, Error &r_error) {
r_error = OK; // Always succeeds for now.
+ tts = GLOBAL_GET("audio/general/text_to_speech");
+
// Ensure the canvas ID.
godot_js_config_canvas_id_get(canvas_id, 256);
@@ -866,7 +877,7 @@ bool DisplayServerWeb::has_feature(Feature p_feature) const {
case FEATURE_VIRTUAL_KEYBOARD:
return godot_js_display_vk_available() != 0;
case FEATURE_TEXT_TO_SPEECH:
- return godot_js_display_tts_available() != 0;
+ return tts && (godot_js_display_tts_available() != 0);
default:
return false;
}
@@ -1070,6 +1081,10 @@ bool DisplayServerWeb::can_any_window_draw() const {
return true;
}
+DisplayServer::VSyncMode DisplayServerWeb::window_get_vsync_mode(WindowID p_vsync_mode) const {
+ return DisplayServer::VSYNC_ENABLED;
+}
+
void DisplayServerWeb::process_events() {
Input::get_singleton()->flush_buffered_events();
if (godot_js_input_gamepad_sample() == OK) {
diff --git a/platform/web/display_server_web.h b/platform/web/display_server_web.h
index 2e50a6bbc8..3b03b102cd 100644
--- a/platform/web/display_server_web.h
+++ b/platform/web/display_server_web.h
@@ -37,6 +37,8 @@
#include <emscripten/html5.h>
class DisplayServerWeb : public DisplayServer {
+ // No need to register with GDCLASS, it's platform-specific and nothing is added.
+
private:
struct JSTouchEvent {
uint32_t identifier[32] = { 0 };
@@ -79,6 +81,7 @@ private:
MouseButton last_click_button_index = MouseButton::NONE;
bool swap_cancel_ok = false;
+ bool tts = false;
// utilities
static void dom2godot_mod(Ref<InputEventWithModifiers> ev, int p_mod, Key p_keycode);
@@ -213,6 +216,8 @@ public:
virtual bool can_any_window_draw() const override;
+ virtual DisplayServer::VSyncMode window_get_vsync_mode(WindowID p_vsync_mode) const override;
+
// events
virtual void process_events() override;
diff --git a/platform/web/export/export.cpp b/platform/web/export/export.cpp
index 80c29024a8..168310c078 100644
--- a/platform/web/export/export.cpp
+++ b/platform/web/export/export.cpp
@@ -30,9 +30,10 @@
#include "export.h"
+#include "export_plugin.h"
+
#include "editor/editor_settings.h"
#include "editor/export/editor_export.h"
-#include "export_plugin.h"
void register_web_exporter_types() {
GDREGISTER_VIRTUAL_CLASS(EditorExportPlatformWeb);
diff --git a/platform/web/export/export_plugin.cpp b/platform/web/export/export_plugin.cpp
index 2fff628c85..a398593f90 100644
--- a/platform/web/export/export_plugin.cpp
+++ b/platform/web/export/export_plugin.cpp
@@ -30,12 +30,13 @@
#include "export_plugin.h"
+#include "../logo_svg.gen.h"
+#include "../run_icon_svg.gen.h"
+
#include "core/config/project_settings.h"
#include "editor/editor_scale.h"
#include "editor/editor_settings.h"
#include "editor/export/editor_export.h"
-#include "platform/web/logo_svg.gen.h"
-#include "platform/web/run_icon_svg.gen.h"
#include "modules/modules_enabled.gen.h" // For svg.
#ifdef MODULE_SVG_ENABLED
diff --git a/platform/web/export/export_plugin.h b/platform/web/export/export_plugin.h
index 334f12d64d..a1d3fed2f3 100644
--- a/platform/web/export/export_plugin.h
+++ b/platform/web/export/export_plugin.h
@@ -31,6 +31,8 @@
#ifndef WEB_EXPORT_PLUGIN_H
#define WEB_EXPORT_PLUGIN_H
+#include "editor_http_server.h"
+
#include "core/config/project_settings.h"
#include "core/io/image_loader.h"
#include "core/io/stream_peer_tls.h"
@@ -38,7 +40,6 @@
#include "core/io/zip_io.h"
#include "editor/editor_node.h"
#include "editor/export/editor_export_platform.h"
-#include "editor_http_server.h"
#include "main/splash.gen.h"
class EditorExportPlatformWeb : public EditorExportPlatform {
diff --git a/platform/web/godot_audio.h b/platform/web/godot_audio.h
index c6f92161fa..a32d5acd97 100644
--- a/platform/web/godot_audio.h
+++ b/platform/web/godot_audio.h
@@ -35,7 +35,8 @@
extern "C" {
#endif
-#include "stddef.h"
+#include <stddef.h>
+#include <stdint.h>
extern int godot_audio_is_available();
extern int godot_audio_has_worklet();
diff --git a/platform/web/godot_js.h b/platform/web/godot_js.h
index 660822e291..3341cf8a67 100644
--- a/platform/web/godot_js.h
+++ b/platform/web/godot_js.h
@@ -35,7 +35,7 @@
extern "C" {
#endif
-#include "stddef.h"
+#include <stddef.h>
// Config
extern void godot_js_config_locale_get(char *p_ptr, int p_ptr_max);
diff --git a/platform/web/godot_webgl2.h b/platform/web/godot_webgl2.h
index fd551ff77d..d2f46e125e 100644
--- a/platform/web/godot_webgl2.h
+++ b/platform/web/godot_webgl2.h
@@ -31,8 +31,8 @@
#ifndef GODOT_WEBGL2_H
#define GODOT_WEBGL2_H
-#include "GLES3/gl3.h"
-#include "webgl/webgl2.h"
+#include <GLES3/gl3.h>
+#include <webgl/webgl2.h>
#define GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_NUM_VIEWS_OVR 0x9630
#define GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_BASE_VIEW_INDEX_OVR 0x9632
diff --git a/platform/web/http_client_web.h b/platform/web/http_client_web.h
index def7837a27..bb9672ab82 100644
--- a/platform/web/http_client_web.h
+++ b/platform/web/http_client_web.h
@@ -37,7 +37,7 @@
extern "C" {
#endif
-#include "stddef.h"
+#include <stddef.h>
typedef enum {
GODOT_JS_FETCH_STATE_REQUESTING = 0,
diff --git a/platform/web/javascript_bridge_singleton.cpp b/platform/web/javascript_bridge_singleton.cpp
index dba630404f..45bce1b480 100644
--- a/platform/web/javascript_bridge_singleton.cpp
+++ b/platform/web/javascript_bridge_singleton.cpp
@@ -30,9 +30,10 @@
#include "api/javascript_bridge_singleton.h"
-#include "emscripten.h"
#include "os_web.h"
+#include <emscripten.h>
+
extern "C" {
extern void godot_js_os_download_buffer(const uint8_t *p_buf, int p_buf_size, const char *p_name, const char *p_mime);
}
@@ -352,6 +353,7 @@ Variant JavaScriptBridge::eval(const String &p_code, bool p_use_global_exec_cont
return Variant();
}
}
+
#endif // JAVASCRIPT_EVAL_ENABLED
void JavaScriptBridge::download_buffer(Vector<uint8_t> p_arr, const String &p_name, const String &p_mime) {
diff --git a/platform/web/js/libs/library_godot_fetch.js b/platform/web/js/libs/library_godot_fetch.js
index b50012c1e2..1bb48bfd6a 100644
--- a/platform/web/js/libs/library_godot_fetch.js
+++ b/platform/web/js/libs/library_godot_fetch.js
@@ -50,17 +50,22 @@ const GodotFetch = {
return;
}
let chunked = false;
+ let bodySize = -1;
response.headers.forEach(function (value, header) {
const v = value.toLowerCase().trim();
const h = header.toLowerCase().trim();
if (h === 'transfer-encoding' && v === 'chunked') {
chunked = true;
}
+ if (h === 'content-length') {
+ bodySize = parseInt(v, 10);
+ }
});
obj.status = response.status;
obj.response = response;
obj.reader = response.body.getReader();
obj.chunked = chunked;
+ obj.bodySize = bodySize;
},
onerror: function (id, err) {
diff --git a/platform/web/os_web.cpp b/platform/web/os_web.cpp
index 0f84e7e841..5115ff50da 100644
--- a/platform/web/os_web.cpp
+++ b/platform/web/os_web.cpp
@@ -30,12 +30,15 @@
#include "os_web.h"
+#include "api/javascript_bridge_singleton.h"
+#include "display_server_web.h"
+#include "godot_js.h"
+
#include "core/config/project_settings.h"
#include "core/debugger/engine_debugger.h"
#include "drivers/unix/dir_access_unix.h"
#include "drivers/unix/file_access_unix.h"
#include "main/main.h"
-#include "platform/web/display_server_web.h"
#include "modules/modules_enabled.gen.h" // For websocket.
@@ -43,9 +46,6 @@
#include <emscripten.h>
#include <stdlib.h>
-#include "api/javascript_bridge_singleton.h"
-#include "godot_js.h"
-
void OS_Web::alert(const String &p_alert, const String &p_title) {
godot_js_display_alert(p_alert.utf8().get_data());
}
diff --git a/platform/web/os_web.h b/platform/web/os_web.h
index 70d8af9db9..b9570f9ca1 100644
--- a/platform/web/os_web.h
+++ b/platform/web/os_web.h
@@ -32,6 +32,7 @@
#define OS_WEB_H
#include "audio_driver_web.h"
+
#include "core/input/input.h"
#include "drivers/unix/os_unix.h"
#include "servers/audio_server.h"
diff --git a/platform/web/web_main.cpp b/platform/web/web_main.cpp
index df97b08b8a..f199f8ffd8 100644
--- a/platform/web/web_main.cpp
+++ b/platform/web/web_main.cpp
@@ -28,17 +28,17 @@
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/**************************************************************************/
+#include "display_server_web.h"
+#include "godot_js.h"
+#include "os_web.h"
+
#include "core/config/engine.h"
#include "core/io/resource_loader.h"
#include "main/main.h"
-#include "platform/web/display_server_web.h"
-#include "platform/web/os_web.h"
#include <emscripten/emscripten.h>
#include <stdlib.h>
-#include "godot_js.h"
-
static OS_Web *os = nullptr;
static uint64_t target_ticks = 0;
static bool main_started = false;