[Web] Rename JavaScript platform to Web.
Also rename export name from "HTML5" to "Web".
This commit is contained in:
parent
223e083d36
commit
d20b32186f
120 changed files with 547 additions and 548 deletions
|
|
@ -1,12 +1,12 @@
|
|||
# HTML5 platform port
|
||||
# Web platform port
|
||||
|
||||
This folder contains the C++ and JavaScript code for the HTML5/WebAssembly platform port,
|
||||
This folder contains the C++ and JavaScript code for the Web platform port,
|
||||
compiled using [Emscripten](https://emscripten.org/).
|
||||
|
||||
It also contains a ESLint linting setup (see [`package.json`](package.json)).
|
||||
|
||||
See also [`misc/dist/html`](/misc/dist/html) folder for additional files used by
|
||||
this platform such as the HTML5 shell.
|
||||
this platform such as the html shell (web page).
|
||||
|
||||
## Documentation
|
||||
|
||||
|
|
@ -2,14 +2,14 @@
|
|||
|
||||
Import("env")
|
||||
|
||||
javascript_files = [
|
||||
"audio_driver_javascript.cpp",
|
||||
"display_server_javascript.cpp",
|
||||
"http_client_javascript.cpp",
|
||||
web_files = [
|
||||
"audio_driver_web.cpp",
|
||||
"display_server_web.cpp",
|
||||
"http_client_web.cpp",
|
||||
"javascript_singleton.cpp",
|
||||
"javascript_main.cpp",
|
||||
"os_javascript.cpp",
|
||||
"api/javascript_tools_editor_plugin.cpp",
|
||||
"web_main.cpp",
|
||||
"os_web.cpp",
|
||||
"api/web_tools_editor_plugin.cpp",
|
||||
]
|
||||
|
||||
sys_env = env.Clone()
|
||||
|
|
@ -52,14 +52,14 @@ if env["gdnative_enabled"]:
|
|||
# Force exporting the standard library (printf, malloc, etc.)
|
||||
sys_env["ENV"]["EMCC_FORCE_STDLIBS"] = "libc,libc++,libc++abi"
|
||||
# The main emscripten runtime, with exported standard libraries.
|
||||
sys = sys_env.Program(build_targets, ["javascript_runtime.cpp"])
|
||||
sys = sys_env.Program(build_targets, ["web_runtime.cpp"])
|
||||
|
||||
# The side library, containing all Godot code.
|
||||
wasm_env = env.Clone()
|
||||
wasm_env.Append(CPPDEFINES=["WASM_GDNATIVE"]) # So that OS knows it can run GDNative libraries.
|
||||
wasm_env.Append(CCFLAGS=["-s", "SIDE_MODULE=2"])
|
||||
wasm_env.Append(LINKFLAGS=["-s", "SIDE_MODULE=2"])
|
||||
wasm = wasm_env.add_program("#bin/godot.side${PROGSUFFIX}.wasm", javascript_files)
|
||||
wasm = wasm_env.add_program("#bin/godot.side${PROGSUFFIX}.wasm", web_files)
|
||||
build = sys + [wasm[0]]
|
||||
else:
|
||||
build_targets = ["#bin/godot${PROGSUFFIX}.js", "#bin/godot${PROGSUFFIX}.wasm"]
|
||||
|
|
@ -67,7 +67,7 @@ else:
|
|||
build_targets.append("#bin/godot${PROGSUFFIX}.worker.js")
|
||||
# We use IDBFS. Since Emscripten 1.39.1 it needs to be linked explicitly.
|
||||
sys_env.Append(LIBS=["idbfs.js"])
|
||||
build = sys_env.Program(build_targets, javascript_files + ["javascript_runtime.cpp"])
|
||||
build = sys_env.Program(build_targets, web_files + ["web_runtime.cpp"])
|
||||
|
||||
sys_env.Depends(build[0], sys_env["JS_LIBS"])
|
||||
sys_env.Depends(build[0], sys_env["JS_PRE"])
|
||||
|
|
@ -78,7 +78,7 @@ engine = [
|
|||
"js/engine/config.js",
|
||||
"js/engine/engine.js",
|
||||
]
|
||||
externs = [env.File("#platform/javascript/js/engine/engine.externs.js")]
|
||||
externs = [env.File("#platform/web/js/engine/engine.externs.js")]
|
||||
js_engine = env.CreateEngineFile("#bin/godot${PROGSUFFIX}.engine.js", engine, externs)
|
||||
env.Depends(js_engine, externs)
|
||||
|
||||
|
|
@ -31,20 +31,20 @@
|
|||
#include "api.h"
|
||||
#include "core/config/engine.h"
|
||||
#include "javascript_singleton.h"
|
||||
#include "javascript_tools_editor_plugin.h"
|
||||
#include "web_tools_editor_plugin.h"
|
||||
|
||||
static JavaScript *javascript_eval;
|
||||
static JavaScript *javascript_singleton;
|
||||
|
||||
void register_javascript_api() {
|
||||
JavaScriptToolsEditorPlugin::initialize();
|
||||
void register_web_api() {
|
||||
WebToolsEditorPlugin::initialize();
|
||||
GDREGISTER_ABSTRACT_CLASS(JavaScriptObject);
|
||||
GDREGISTER_ABSTRACT_CLASS(JavaScript);
|
||||
javascript_eval = memnew(JavaScript);
|
||||
Engine::get_singleton()->add_singleton(Engine::Singleton("JavaScript", javascript_eval));
|
||||
javascript_singleton = memnew(JavaScript);
|
||||
Engine::get_singleton()->add_singleton(Engine::Singleton("JavaScript", javascript_singleton));
|
||||
}
|
||||
|
||||
void unregister_javascript_api() {
|
||||
memdelete(javascript_eval);
|
||||
void unregister_web_api() {
|
||||
memdelete(javascript_singleton);
|
||||
}
|
||||
|
||||
JavaScript *JavaScript::singleton = nullptr;
|
||||
|
|
@ -76,7 +76,7 @@ void JavaScript::_bind_methods() {
|
|||
ADD_SIGNAL(MethodInfo("pwa_update_available"));
|
||||
}
|
||||
|
||||
#if !defined(JAVASCRIPT_ENABLED) || !defined(JAVASCRIPT_EVAL_ENABLED)
|
||||
#if !defined(WEB_ENABLED) || !defined(JAVASCRIPT_EVAL_ENABLED)
|
||||
Variant JavaScript::eval(const String &p_code, bool p_use_global_exec_context) {
|
||||
return Variant();
|
||||
}
|
||||
|
|
@ -104,7 +104,7 @@ Variant JavaScript::_create_object_bind(const Variant **p_args, int p_argcount,
|
|||
return Ref<JavaScriptObject>();
|
||||
}
|
||||
#endif
|
||||
#if !defined(JAVASCRIPT_ENABLED)
|
||||
#if !defined(WEB_ENABLED)
|
||||
bool JavaScript::pwa_needs_update() const {
|
||||
return false;
|
||||
}
|
||||
|
|
@ -28,10 +28,10 @@
|
|||
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
||||
/*************************************************************************/
|
||||
|
||||
#ifndef JAVASCRIPT_API_H
|
||||
#define JAVASCRIPT_API_H
|
||||
#ifndef WEB_API_H
|
||||
#define WEB_API_H
|
||||
|
||||
void register_javascript_api();
|
||||
void unregister_javascript_api();
|
||||
void register_web_api();
|
||||
void unregister_web_api();
|
||||
|
||||
#endif // JAVASCRIPT_API_H
|
||||
#endif // WEB_API_H
|
||||
|
|
@ -1,5 +1,5 @@
|
|||
/*************************************************************************/
|
||||
/* javascript_tools_editor_plugin.cpp */
|
||||
/* web_tools_editor_plugin.cpp */
|
||||
/*************************************************************************/
|
||||
/* This file is part of: */
|
||||
/* GODOT ENGINE */
|
||||
|
|
@ -28,8 +28,8 @@
|
|||
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
||||
/*************************************************************************/
|
||||
|
||||
#if defined(TOOLS_ENABLED) && defined(JAVASCRIPT_ENABLED)
|
||||
#include "javascript_tools_editor_plugin.h"
|
||||
#if defined(TOOLS_ENABLED) && defined(WEB_ENABLED)
|
||||
#include "web_tools_editor_plugin.h"
|
||||
|
||||
#include "core/config/engine.h"
|
||||
#include "core/config/project_settings.h"
|
||||
|
|
@ -40,24 +40,24 @@
|
|||
|
||||
#include <emscripten/emscripten.h>
|
||||
|
||||
// JavaScript functions defined in library_godot_editor_tools.js
|
||||
// Web functions defined in library_godot_editor_tools.js
|
||||
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);
|
||||
}
|
||||
|
||||
static void _javascript_editor_init_callback() {
|
||||
EditorNode::get_singleton()->add_editor_plugin(memnew(JavaScriptToolsEditorPlugin));
|
||||
static void _web_editor_init_callback() {
|
||||
EditorNode::get_singleton()->add_editor_plugin(memnew(WebToolsEditorPlugin));
|
||||
}
|
||||
|
||||
void JavaScriptToolsEditorPlugin::initialize() {
|
||||
EditorNode::add_init_callback(_javascript_editor_init_callback);
|
||||
void WebToolsEditorPlugin::initialize() {
|
||||
EditorNode::add_init_callback(_web_editor_init_callback);
|
||||
}
|
||||
|
||||
JavaScriptToolsEditorPlugin::JavaScriptToolsEditorPlugin() {
|
||||
add_tool_menu_item("Download Project Source", callable_mp(this, &JavaScriptToolsEditorPlugin::_download_zip));
|
||||
WebToolsEditorPlugin::WebToolsEditorPlugin() {
|
||||
add_tool_menu_item("Download Project Source", callable_mp(this, &WebToolsEditorPlugin::_download_zip));
|
||||
}
|
||||
|
||||
void JavaScriptToolsEditorPlugin::_download_zip(Variant p_v) {
|
||||
void WebToolsEditorPlugin::_download_zip(Variant p_v) {
|
||||
if (!Engine::get_singleton() || !Engine::get_singleton()->is_editor_hint()) {
|
||||
ERR_PRINT("Downloading the project as a ZIP archive is only available in Editor mode.");
|
||||
return;
|
||||
|
|
@ -95,7 +95,7 @@ void JavaScriptToolsEditorPlugin::_download_zip(Variant p_v) {
|
|||
DirAccess::remove_file_or_error(output_path);
|
||||
}
|
||||
|
||||
void JavaScriptToolsEditorPlugin::_zip_file(String p_path, String p_base_path, zipFile p_zip) {
|
||||
void WebToolsEditorPlugin::_zip_file(String p_path, String p_base_path, zipFile p_zip) {
|
||||
Ref<FileAccess> f = FileAccess::open(p_path, FileAccess::READ);
|
||||
if (f.is_null()) {
|
||||
WARN_PRINT("Unable to open file for zipping: " + p_path);
|
||||
|
|
@ -121,7 +121,7 @@ void JavaScriptToolsEditorPlugin::_zip_file(String p_path, String p_base_path, z
|
|||
zipCloseFileInZip(p_zip);
|
||||
}
|
||||
|
||||
void JavaScriptToolsEditorPlugin::_zip_recursive(String p_path, String p_base_path, zipFile p_zip) {
|
||||
void WebToolsEditorPlugin::_zip_recursive(String p_path, String p_base_path, zipFile p_zip) {
|
||||
Ref<DirAccess> dir = DirAccess::open(p_path);
|
||||
if (dir.is_null()) {
|
||||
WARN_PRINT("Unable to open directory for zipping: " + p_path);
|
||||
|
|
@ -1,5 +1,5 @@
|
|||
/*************************************************************************/
|
||||
/* javascript_tools_editor_plugin.h */
|
||||
/* web_tools_editor_plugin.h */
|
||||
/*************************************************************************/
|
||||
/* This file is part of: */
|
||||
/* GODOT ENGINE */
|
||||
|
|
@ -28,15 +28,15 @@
|
|||
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
||||
/*************************************************************************/
|
||||
|
||||
#ifndef JAVASCRIPT_TOOLS_EDITOR_PLUGIN_H
|
||||
#define JAVASCRIPT_TOOLS_EDITOR_PLUGIN_H
|
||||
#ifndef WEB_TOOLS_EDITOR_PLUGIN_H
|
||||
#define WEB_TOOLS_EDITOR_PLUGIN_H
|
||||
|
||||
#if defined(TOOLS_ENABLED) && defined(JAVASCRIPT_ENABLED)
|
||||
#if defined(TOOLS_ENABLED) && defined(WEB_ENABLED)
|
||||
#include "core/io/zip_io.h"
|
||||
#include "editor/editor_plugin.h"
|
||||
|
||||
class JavaScriptToolsEditorPlugin : public EditorPlugin {
|
||||
GDCLASS(JavaScriptToolsEditorPlugin, EditorPlugin);
|
||||
class WebToolsEditorPlugin : public EditorPlugin {
|
||||
GDCLASS(WebToolsEditorPlugin, EditorPlugin);
|
||||
|
||||
private:
|
||||
void _zip_file(String p_path, String p_base_path, zipFile p_zip);
|
||||
|
|
@ -46,13 +46,13 @@ private:
|
|||
public:
|
||||
static void initialize();
|
||||
|
||||
JavaScriptToolsEditorPlugin();
|
||||
WebToolsEditorPlugin();
|
||||
};
|
||||
#else
|
||||
class JavaScriptToolsEditorPlugin {
|
||||
class WebToolsEditorPlugin {
|
||||
public:
|
||||
static void initialize() {}
|
||||
};
|
||||
#endif
|
||||
|
||||
#endif // JAVASCRIPT_TOOLS_EDITOR_PLUGIN_H
|
||||
#endif // WEB_TOOLS_EDITOR_PLUGIN_H
|
||||
|
|
@ -1,5 +1,5 @@
|
|||
/*************************************************************************/
|
||||
/* audio_driver_javascript.cpp */
|
||||
/* audio_driver_web.cpp */
|
||||
/*************************************************************************/
|
||||
/* This file is part of: */
|
||||
/* GODOT ENGINE */
|
||||
|
|
@ -28,27 +28,27 @@
|
|||
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
||||
/*************************************************************************/
|
||||
|
||||
#include "audio_driver_javascript.h"
|
||||
#include "audio_driver_web.h"
|
||||
|
||||
#include "core/config/project_settings.h"
|
||||
|
||||
#include <emscripten.h>
|
||||
|
||||
AudioDriverJavaScript::AudioContext AudioDriverJavaScript::audio_context;
|
||||
AudioDriverWeb::AudioContext AudioDriverWeb::audio_context;
|
||||
|
||||
bool AudioDriverJavaScript::is_available() {
|
||||
bool AudioDriverWeb::is_available() {
|
||||
return godot_audio_is_available() != 0;
|
||||
}
|
||||
|
||||
void AudioDriverJavaScript::_state_change_callback(int p_state) {
|
||||
AudioDriverJavaScript::audio_context.state = p_state;
|
||||
void AudioDriverWeb::_state_change_callback(int p_state) {
|
||||
AudioDriverWeb::audio_context.state = p_state;
|
||||
}
|
||||
|
||||
void AudioDriverJavaScript::_latency_update_callback(float p_latency) {
|
||||
AudioDriverJavaScript::audio_context.output_latency = p_latency;
|
||||
void AudioDriverWeb::_latency_update_callback(float p_latency) {
|
||||
AudioDriverWeb::audio_context.output_latency = p_latency;
|
||||
}
|
||||
|
||||
void AudioDriverJavaScript::_audio_driver_process(int p_from, int p_samples) {
|
||||
void AudioDriverWeb::_audio_driver_process(int p_from, int p_samples) {
|
||||
int32_t *stream_buffer = reinterpret_cast<int32_t *>(output_rb);
|
||||
const int max_samples = memarr_len(output_rb);
|
||||
|
||||
|
|
@ -74,7 +74,7 @@ void AudioDriverJavaScript::_audio_driver_process(int p_from, int p_samples) {
|
|||
}
|
||||
}
|
||||
|
||||
void AudioDriverJavaScript::_audio_driver_capture(int p_from, int p_samples) {
|
||||
void AudioDriverWeb::_audio_driver_capture(int p_from, int p_samples) {
|
||||
if (get_input_buffer().size() == 0) {
|
||||
return; // Input capture stopped.
|
||||
}
|
||||
|
|
@ -100,7 +100,7 @@ void AudioDriverJavaScript::_audio_driver_capture(int p_from, int p_samples) {
|
|||
}
|
||||
}
|
||||
|
||||
Error AudioDriverJavaScript::init() {
|
||||
Error AudioDriverWeb::init() {
|
||||
int latency = GLOBAL_GET("audio/driver/output_latency");
|
||||
if (!audio_context.inited) {
|
||||
audio_context.mix_rate = GLOBAL_GET("audio/driver/mix_rate");
|
||||
|
|
@ -132,29 +132,29 @@ Error AudioDriverJavaScript::init() {
|
|||
return OK;
|
||||
}
|
||||
|
||||
void AudioDriverJavaScript::start() {
|
||||
void AudioDriverWeb::start() {
|
||||
start(output_rb, memarr_len(output_rb), input_rb, memarr_len(input_rb));
|
||||
}
|
||||
|
||||
void AudioDriverJavaScript::resume() {
|
||||
void AudioDriverWeb::resume() {
|
||||
if (audio_context.state == 0) { // 'suspended'
|
||||
godot_audio_resume();
|
||||
}
|
||||
}
|
||||
|
||||
float AudioDriverJavaScript::get_latency() {
|
||||
float AudioDriverWeb::get_latency() {
|
||||
return audio_context.output_latency + (float(buffer_length) / mix_rate);
|
||||
}
|
||||
|
||||
int AudioDriverJavaScript::get_mix_rate() const {
|
||||
int AudioDriverWeb::get_mix_rate() const {
|
||||
return mix_rate;
|
||||
}
|
||||
|
||||
AudioDriver::SpeakerMode AudioDriverJavaScript::get_speaker_mode() const {
|
||||
AudioDriver::SpeakerMode AudioDriverWeb::get_speaker_mode() const {
|
||||
return get_speaker_mode_by_total_channels(channel_count);
|
||||
}
|
||||
|
||||
void AudioDriverJavaScript::finish() {
|
||||
void AudioDriverWeb::finish() {
|
||||
finish_driver();
|
||||
if (output_rb) {
|
||||
memdelete_arr(output_rb);
|
||||
|
|
@ -166,7 +166,7 @@ void AudioDriverJavaScript::finish() {
|
|||
}
|
||||
}
|
||||
|
||||
Error AudioDriverJavaScript::capture_start() {
|
||||
Error AudioDriverWeb::capture_start() {
|
||||
lock();
|
||||
input_buffer_init(buffer_length);
|
||||
unlock();
|
||||
|
|
@ -176,7 +176,7 @@ Error AudioDriverJavaScript::capture_start() {
|
|||
return OK;
|
||||
}
|
||||
|
||||
Error AudioDriverJavaScript::capture_stop() {
|
||||
Error AudioDriverWeb::capture_stop() {
|
||||
godot_audio_capture_stop();
|
||||
lock();
|
||||
input_buffer.clear();
|
||||
|
|
@ -1,5 +1,5 @@
|
|||
/*************************************************************************/
|
||||
/* audio_driver_javascript.h */
|
||||
/* audio_driver_web.h */
|
||||
/*************************************************************************/
|
||||
/* This file is part of: */
|
||||
/* GODOT ENGINE */
|
||||
|
|
@ -28,8 +28,8 @@
|
|||
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
||||
/*************************************************************************/
|
||||
|
||||
#ifndef AUDIO_DRIVER_JAVASCRIPT_H
|
||||
#define AUDIO_DRIVER_JAVASCRIPT_H
|
||||
#ifndef AUDIO_DRIVER_WEB_H
|
||||
#define AUDIO_DRIVER_WEB_H
|
||||
|
||||
#include "core/os/mutex.h"
|
||||
#include "core/os/thread.h"
|
||||
|
|
@ -37,7 +37,7 @@
|
|||
|
||||
#include "godot_audio.h"
|
||||
|
||||
class AudioDriverJavaScript : public AudioDriver {
|
||||
class AudioDriverWeb : public AudioDriver {
|
||||
private:
|
||||
struct AudioContext {
|
||||
bool inited = false;
|
||||
|
|
@ -58,7 +58,7 @@ private:
|
|||
static void _state_change_callback(int p_state);
|
||||
static void _latency_update_callback(float p_latency);
|
||||
|
||||
static AudioDriverJavaScript *singleton;
|
||||
static AudioDriverWeb *singleton;
|
||||
|
||||
protected:
|
||||
void _audio_driver_process(int p_from = 0, int p_samples = 0);
|
||||
|
|
@ -86,11 +86,11 @@ public:
|
|||
|
||||
static void resume();
|
||||
|
||||
AudioDriverJavaScript() {}
|
||||
AudioDriverWeb() {}
|
||||
};
|
||||
|
||||
#ifdef NO_THREADS
|
||||
class AudioDriverScriptProcessor : public AudioDriverJavaScript {
|
||||
class AudioDriverScriptProcessor : public AudioDriverWeb {
|
||||
private:
|
||||
static void _process_callback();
|
||||
|
||||
|
|
@ -109,7 +109,7 @@ public:
|
|||
AudioDriverScriptProcessor() { singleton = this; }
|
||||
};
|
||||
|
||||
class AudioDriverWorklet : public AudioDriverJavaScript {
|
||||
class AudioDriverWorklet : public AudioDriverWeb {
|
||||
private:
|
||||
static void _process_callback(int p_pos, int p_samples);
|
||||
static void _capture_callback(int p_pos, int p_samples);
|
||||
|
|
@ -129,7 +129,7 @@ public:
|
|||
AudioDriverWorklet() { singleton = this; }
|
||||
};
|
||||
#else
|
||||
class AudioDriverWorklet : public AudioDriverJavaScript {
|
||||
class AudioDriverWorklet : public AudioDriverWeb {
|
||||
private:
|
||||
enum {
|
||||
STATE_LOCK,
|
||||
|
|
@ -158,4 +158,4 @@ public:
|
|||
};
|
||||
#endif
|
||||
|
||||
#endif // AUDIO_DRIVER_JAVASCRIPT_H
|
||||
#endif // AUDIO_DRIVER_WEB_H
|
||||
|
|
@ -18,7 +18,7 @@ def is_active():
|
|||
|
||||
|
||||
def get_name():
|
||||
return "JavaScript"
|
||||
return "Web"
|
||||
|
||||
|
||||
def can_build():
|
||||
|
|
@ -182,8 +182,8 @@ def configure(env):
|
|||
env["LIBPREFIXES"] = ["$LIBPREFIX"]
|
||||
env["LIBSUFFIXES"] = ["$LIBSUFFIX"]
|
||||
|
||||
env.Prepend(CPPPATH=["#platform/javascript"])
|
||||
env.Append(CPPDEFINES=["JAVASCRIPT_ENABLED", "UNIX_ENABLED"])
|
||||
env.Prepend(CPPPATH=["#platform/web"])
|
||||
env.Append(CPPDEFINES=["WEB_ENABLED", "UNIX_ENABLED"])
|
||||
|
||||
if env["opengl3"]:
|
||||
env.AppendUnique(CPPDEFINES=["GLES3_ENABLED"])
|
||||
|
|
@ -1,5 +1,5 @@
|
|||
/*************************************************************************/
|
||||
/* display_server_javascript.cpp */
|
||||
/* display_server_web.cpp */
|
||||
/*************************************************************************/
|
||||
/* This file is part of: */
|
||||
/* GODOT ENGINE */
|
||||
|
|
@ -28,12 +28,12 @@
|
|||
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
||||
/*************************************************************************/
|
||||
|
||||
#include "display_server_javascript.h"
|
||||
#include "display_server_web.h"
|
||||
|
||||
#ifdef GLES3_ENABLED
|
||||
#include "drivers/gles3/rasterizer_gles3.h"
|
||||
#endif
|
||||
#include "platform/javascript/os_javascript.h"
|
||||
#include "platform/web/os_web.h"
|
||||
#include "servers/rendering/dummy/rasterizer_dummy.h"
|
||||
|
||||
#include <emscripten.h>
|
||||
|
|
@ -48,17 +48,17 @@
|
|||
#define DOM_BUTTON_XBUTTON1 3
|
||||
#define DOM_BUTTON_XBUTTON2 4
|
||||
|
||||
DisplayServerJavaScript *DisplayServerJavaScript::get_singleton() {
|
||||
return static_cast<DisplayServerJavaScript *>(DisplayServer::get_singleton());
|
||||
DisplayServerWeb *DisplayServerWeb::get_singleton() {
|
||||
return static_cast<DisplayServerWeb *>(DisplayServer::get_singleton());
|
||||
}
|
||||
|
||||
// Window (canvas)
|
||||
bool DisplayServerJavaScript::check_size_force_redraw() {
|
||||
bool DisplayServerWeb::check_size_force_redraw() {
|
||||
return godot_js_display_size_update() != 0;
|
||||
}
|
||||
|
||||
void DisplayServerJavaScript::fullscreen_change_callback(int p_fullscreen) {
|
||||
DisplayServerJavaScript *display = get_singleton();
|
||||
void DisplayServerWeb::fullscreen_change_callback(int p_fullscreen) {
|
||||
DisplayServerWeb *display = get_singleton();
|
||||
if (p_fullscreen) {
|
||||
display->window_mode = WINDOW_MODE_FULLSCREEN;
|
||||
} else {
|
||||
|
|
@ -67,8 +67,8 @@ void DisplayServerJavaScript::fullscreen_change_callback(int p_fullscreen) {
|
|||
}
|
||||
|
||||
// Drag and drop callback.
|
||||
void DisplayServerJavaScript::drop_files_js_callback(char **p_filev, int p_filec) {
|
||||
DisplayServerJavaScript *ds = get_singleton();
|
||||
void DisplayServerWeb::drop_files_js_callback(char **p_filev, int p_filec) {
|
||||
DisplayServerWeb *ds = get_singleton();
|
||||
if (!ds) {
|
||||
ERR_FAIL_MSG("Unable to drop files because the DisplayServer is not active");
|
||||
}
|
||||
|
|
@ -86,9 +86,9 @@ void DisplayServerJavaScript::drop_files_js_callback(char **p_filev, int p_filec
|
|||
ds->drop_files_callback.callp((const Variant **)&vp, 1, ret, ce);
|
||||
}
|
||||
|
||||
// JavaScript quit request callback.
|
||||
void DisplayServerJavaScript::request_quit_callback() {
|
||||
DisplayServerJavaScript *ds = get_singleton();
|
||||
// Web quit request 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;
|
||||
|
|
@ -100,18 +100,18 @@ void DisplayServerJavaScript::request_quit_callback() {
|
|||
|
||||
// Keys
|
||||
|
||||
void DisplayServerJavaScript::dom2godot_mod(Ref<InputEventWithModifiers> ev, int p_mod) {
|
||||
void DisplayServerWeb::dom2godot_mod(Ref<InputEventWithModifiers> ev, int p_mod) {
|
||||
ev->set_shift_pressed(p_mod & 1);
|
||||
ev->set_alt_pressed(p_mod & 2);
|
||||
ev->set_ctrl_pressed(p_mod & 4);
|
||||
ev->set_meta_pressed(p_mod & 8);
|
||||
}
|
||||
|
||||
void DisplayServerJavaScript::key_callback(int p_pressed, int p_repeat, int p_modifiers) {
|
||||
DisplayServerJavaScript *ds = get_singleton();
|
||||
void DisplayServerWeb::key_callback(int p_pressed, int p_repeat, int p_modifiers) {
|
||||
DisplayServerWeb *ds = get_singleton();
|
||||
JSKeyEvent &key_event = ds->key_event;
|
||||
// Resume audio context after input in case autoplay was denied.
|
||||
OS_JavaScript::get_singleton()->resume_audio();
|
||||
OS_Web::get_singleton()->resume_audio();
|
||||
|
||||
Ref<InputEventKey> ev;
|
||||
ev.instantiate();
|
||||
|
|
@ -133,8 +133,8 @@ void DisplayServerJavaScript::key_callback(int p_pressed, int p_repeat, int p_mo
|
|||
|
||||
// Mouse
|
||||
|
||||
int DisplayServerJavaScript::mouse_button_callback(int p_pressed, int p_button, double p_x, double p_y, int p_modifiers) {
|
||||
DisplayServerJavaScript *ds = get_singleton();
|
||||
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);
|
||||
Ref<InputEventMouseButton> ev;
|
||||
|
|
@ -199,7 +199,7 @@ int DisplayServerJavaScript::mouse_button_callback(int p_pressed, int p_button,
|
|||
|
||||
Input::get_singleton()->parse_input_event(ev);
|
||||
// Resume audio context after input in case autoplay was denied.
|
||||
OS_JavaScript::get_singleton()->resume_audio();
|
||||
OS_Web::get_singleton()->resume_audio();
|
||||
|
||||
// Make sure to flush all events so we can call restricted APIs inside the event.
|
||||
Input::get_singleton()->flush_buffered_events();
|
||||
|
|
@ -209,7 +209,7 @@ int DisplayServerJavaScript::mouse_button_callback(int p_pressed, int p_button,
|
|||
return true;
|
||||
}
|
||||
|
||||
void DisplayServerJavaScript::mouse_move_callback(double p_x, double p_y, double p_rel_x, double p_rel_y, int p_modifiers) {
|
||||
void DisplayServerWeb::mouse_move_callback(double p_x, double p_y, double p_rel_x, double p_rel_y, int p_modifiers) {
|
||||
MouseButton 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 behaviour.
|
||||
|
|
@ -233,7 +233,7 @@ void DisplayServerJavaScript::mouse_move_callback(double p_x, double p_y, double
|
|||
}
|
||||
|
||||
// Cursor
|
||||
const char *DisplayServerJavaScript::godot2dom_cursor(DisplayServer::CursorShape p_shape) {
|
||||
const char *DisplayServerWeb::godot2dom_cursor(DisplayServer::CursorShape p_shape) {
|
||||
switch (p_shape) {
|
||||
case DisplayServer::CURSOR_ARROW:
|
||||
return "default";
|
||||
|
|
@ -274,15 +274,15 @@ const char *DisplayServerJavaScript::godot2dom_cursor(DisplayServer::CursorShape
|
|||
}
|
||||
}
|
||||
|
||||
bool DisplayServerJavaScript::tts_is_speaking() const {
|
||||
bool DisplayServerWeb::tts_is_speaking() const {
|
||||
return godot_js_tts_is_speaking();
|
||||
}
|
||||
|
||||
bool DisplayServerJavaScript::tts_is_paused() const {
|
||||
bool DisplayServerWeb::tts_is_paused() const {
|
||||
return godot_js_tts_is_paused();
|
||||
}
|
||||
|
||||
void DisplayServerJavaScript::update_voices_callback(int p_size, const char **p_voice) {
|
||||
void DisplayServerWeb::update_voices_callback(int p_size, const char **p_voice) {
|
||||
get_singleton()->voices.clear();
|
||||
for (int i = 0; i < p_size; i++) {
|
||||
Vector<String> tokens = String::utf8(p_voice[i]).split(";", true, 2);
|
||||
|
|
@ -296,12 +296,12 @@ void DisplayServerJavaScript::update_voices_callback(int p_size, const char **p_
|
|||
}
|
||||
}
|
||||
|
||||
TypedArray<Dictionary> DisplayServerJavaScript::tts_get_voices() const {
|
||||
TypedArray<Dictionary> DisplayServerWeb::tts_get_voices() const {
|
||||
godot_js_tts_get_voices(update_voices_callback);
|
||||
return voices;
|
||||
}
|
||||
|
||||
void DisplayServerJavaScript::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) {
|
||||
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) {
|
||||
if (p_interrupt) {
|
||||
tts_stop();
|
||||
}
|
||||
|
|
@ -314,18 +314,18 @@ void DisplayServerJavaScript::tts_speak(const String &p_text, const String &p_vo
|
|||
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, DisplayServerJavaScript::_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 DisplayServerJavaScript::tts_pause() {
|
||||
void DisplayServerWeb::tts_pause() {
|
||||
godot_js_tts_pause();
|
||||
}
|
||||
|
||||
void DisplayServerJavaScript::tts_resume() {
|
||||
void DisplayServerWeb::tts_resume() {
|
||||
godot_js_tts_resume();
|
||||
}
|
||||
|
||||
void DisplayServerJavaScript::tts_stop() {
|
||||
void DisplayServerWeb::tts_stop() {
|
||||
for (const KeyValue<int, CharString> &E : utterance_ids) {
|
||||
tts_post_utterance_event(DisplayServer::TTS_UTTERANCE_CANCELED, E.key);
|
||||
}
|
||||
|
|
@ -333,8 +333,8 @@ void DisplayServerJavaScript::tts_stop() {
|
|||
godot_js_tts_stop();
|
||||
}
|
||||
|
||||
void DisplayServerJavaScript::_js_utterance_callback(int p_event, int p_id, int p_pos) {
|
||||
DisplayServerJavaScript *ds = (DisplayServerJavaScript *)DisplayServer::get_singleton();
|
||||
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)) {
|
||||
int pos = 0;
|
||||
if ((TTSUtteranceEvent)p_event == DisplayServer::TTS_UTTERANCE_BOUNDARY) {
|
||||
|
|
@ -358,7 +358,7 @@ void DisplayServerJavaScript::_js_utterance_callback(int p_event, int p_id, int
|
|||
}
|
||||
}
|
||||
|
||||
void DisplayServerJavaScript::cursor_set_shape(CursorShape p_shape) {
|
||||
void DisplayServerWeb::cursor_set_shape(CursorShape p_shape) {
|
||||
ERR_FAIL_INDEX(p_shape, CURSOR_MAX);
|
||||
if (cursor_shape == p_shape) {
|
||||
return;
|
||||
|
|
@ -367,11 +367,11 @@ void DisplayServerJavaScript::cursor_set_shape(CursorShape p_shape) {
|
|||
godot_js_display_cursor_set_shape(godot2dom_cursor(cursor_shape));
|
||||
}
|
||||
|
||||
DisplayServer::CursorShape DisplayServerJavaScript::cursor_get_shape() const {
|
||||
DisplayServer::CursorShape DisplayServerWeb::cursor_get_shape() const {
|
||||
return cursor_shape;
|
||||
}
|
||||
|
||||
void DisplayServerJavaScript::cursor_set_custom_image(const Ref<Resource> &p_cursor, CursorShape p_shape, const Vector2 &p_hotspot) {
|
||||
void DisplayServerWeb::cursor_set_custom_image(const Ref<Resource> &p_cursor, CursorShape p_shape, const Vector2 &p_hotspot) {
|
||||
if (p_cursor.is_valid()) {
|
||||
Ref<Texture2D> texture = p_cursor;
|
||||
Ref<AtlasTexture> atlas_texture = p_cursor;
|
||||
|
|
@ -446,8 +446,8 @@ void DisplayServerJavaScript::cursor_set_custom_image(const Ref<Resource> &p_cur
|
|||
}
|
||||
|
||||
// Mouse mode
|
||||
void DisplayServerJavaScript::mouse_set_mode(MouseMode p_mode) {
|
||||
ERR_FAIL_COND_MSG(p_mode == MOUSE_MODE_CONFINED || p_mode == MOUSE_MODE_CONFINED_HIDDEN, "MOUSE_MODE_CONFINED is not supported for the HTML5 platform.");
|
||||
void DisplayServerWeb::mouse_set_mode(MouseMode p_mode) {
|
||||
ERR_FAIL_COND_MSG(p_mode == MOUSE_MODE_CONFINED || p_mode == MOUSE_MODE_CONFINED_HIDDEN, "MOUSE_MODE_CONFINED is not supported for the Web platform.");
|
||||
if (p_mode == mouse_get_mode()) {
|
||||
return;
|
||||
}
|
||||
|
|
@ -466,7 +466,7 @@ void DisplayServerJavaScript::mouse_set_mode(MouseMode p_mode) {
|
|||
}
|
||||
}
|
||||
|
||||
DisplayServer::MouseMode DisplayServerJavaScript::mouse_get_mode() const {
|
||||
DisplayServer::MouseMode DisplayServerWeb::mouse_get_mode() const {
|
||||
if (godot_js_display_cursor_is_hidden()) {
|
||||
return MOUSE_MODE_HIDDEN;
|
||||
}
|
||||
|
|
@ -477,12 +477,12 @@ DisplayServer::MouseMode DisplayServerJavaScript::mouse_get_mode() const {
|
|||
return MOUSE_MODE_VISIBLE;
|
||||
}
|
||||
|
||||
Point2i DisplayServerJavaScript::mouse_get_position() const {
|
||||
Point2i DisplayServerWeb::mouse_get_position() const {
|
||||
return Input::get_singleton()->get_mouse_position();
|
||||
}
|
||||
|
||||
// Wheel
|
||||
int DisplayServerJavaScript::mouse_wheel_callback(double p_delta_x, double 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();
|
||||
|
|
@ -532,8 +532,8 @@ int DisplayServerJavaScript::mouse_wheel_callback(double p_delta_x, double p_del
|
|||
}
|
||||
|
||||
// Touch
|
||||
void DisplayServerJavaScript::touch_callback(int p_type, int p_count) {
|
||||
DisplayServerJavaScript *ds = get_singleton();
|
||||
void DisplayServerWeb::touch_callback(int p_type, int p_count) {
|
||||
DisplayServerWeb *ds = get_singleton();
|
||||
|
||||
const JSTouchEvent &touch_event = ds->touch_event;
|
||||
for (int i = 0; i < p_count; i++) {
|
||||
|
|
@ -555,7 +555,7 @@ void DisplayServerJavaScript::touch_callback(int p_type, int p_count) {
|
|||
Ref<InputEventScreenTouch> ev;
|
||||
|
||||
// Resume audio context after input in case autoplay was denied.
|
||||
OS_JavaScript::get_singleton()->resume_audio();
|
||||
OS_Web::get_singleton()->resume_audio();
|
||||
|
||||
ev.instantiate();
|
||||
ev->set_index(touch_event.identifier[i]);
|
||||
|
|
@ -571,13 +571,13 @@ void DisplayServerJavaScript::touch_callback(int p_type, int p_count) {
|
|||
}
|
||||
}
|
||||
|
||||
bool DisplayServerJavaScript::screen_is_touchscreen(int p_screen) const {
|
||||
bool DisplayServerWeb::screen_is_touchscreen(int p_screen) const {
|
||||
return godot_js_display_touchscreen_is_available();
|
||||
}
|
||||
|
||||
// Virtual Keyboard
|
||||
void DisplayServerJavaScript::vk_input_text_callback(const char *p_text, int p_cursor) {
|
||||
DisplayServerJavaScript *ds = DisplayServerJavaScript::get_singleton();
|
||||
void DisplayServerWeb::vk_input_text_callback(const char *p_text, int p_cursor) {
|
||||
DisplayServerWeb *ds = DisplayServerWeb::get_singleton();
|
||||
if (!ds || ds->input_text_callback.is_null()) {
|
||||
return;
|
||||
}
|
||||
|
|
@ -604,20 +604,20 @@ void DisplayServerJavaScript::vk_input_text_callback(const char *p_text, int p_c
|
|||
}
|
||||
}
|
||||
|
||||
void DisplayServerJavaScript::virtual_keyboard_show(const String &p_existing_text, const Rect2 &p_screen_rect, VirtualKeyboardType p_type, int p_max_input_length, int p_cursor_start, int p_cursor_end) {
|
||||
void DisplayServerWeb::virtual_keyboard_show(const String &p_existing_text, const Rect2 &p_screen_rect, VirtualKeyboardType p_type, int p_max_input_length, int p_cursor_start, int p_cursor_end) {
|
||||
godot_js_display_vk_show(p_existing_text.utf8().get_data(), p_type, p_cursor_start, p_cursor_end);
|
||||
}
|
||||
|
||||
void DisplayServerJavaScript::virtual_keyboard_hide() {
|
||||
void DisplayServerWeb::virtual_keyboard_hide() {
|
||||
godot_js_display_vk_hide();
|
||||
}
|
||||
|
||||
void DisplayServerJavaScript::window_blur_callback() {
|
||||
void DisplayServerWeb::window_blur_callback() {
|
||||
Input::get_singleton()->release_pressed_events();
|
||||
}
|
||||
|
||||
// Gamepad
|
||||
void DisplayServerJavaScript::gamepad_callback(int p_index, int p_connected, const char *p_id, const char *p_guid) {
|
||||
void DisplayServerWeb::gamepad_callback(int p_index, int p_connected, const char *p_id, const char *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));
|
||||
|
|
@ -626,7 +626,7 @@ void DisplayServerJavaScript::gamepad_callback(int p_index, int p_connected, con
|
|||
}
|
||||
}
|
||||
|
||||
void DisplayServerJavaScript::process_joypads() {
|
||||
void DisplayServerWeb::process_joypads() {
|
||||
Input *input = Input::get_singleton();
|
||||
int32_t pads = godot_js_input_gamepad_sample_count();
|
||||
int32_t s_btns_num = 0;
|
||||
|
|
@ -654,7 +654,7 @@ void DisplayServerJavaScript::process_joypads() {
|
|||
}
|
||||
}
|
||||
|
||||
Vector<String> DisplayServerJavaScript::get_rendering_drivers_func() {
|
||||
Vector<String> DisplayServerWeb::get_rendering_drivers_func() {
|
||||
Vector<String> drivers;
|
||||
#ifdef GLES3_ENABLED
|
||||
drivers.push_back("opengl3");
|
||||
|
|
@ -663,23 +663,23 @@ Vector<String> DisplayServerJavaScript::get_rendering_drivers_func() {
|
|||
}
|
||||
|
||||
// Clipboard
|
||||
void DisplayServerJavaScript::update_clipboard_callback(const char *p_text) {
|
||||
void DisplayServerWeb::update_clipboard_callback(const char *p_text) {
|
||||
get_singleton()->clipboard = String::utf8(p_text);
|
||||
}
|
||||
|
||||
void DisplayServerJavaScript::clipboard_set(const String &p_text) {
|
||||
void DisplayServerWeb::clipboard_set(const String &p_text) {
|
||||
clipboard = p_text;
|
||||
int err = godot_js_display_clipboard_set(p_text.utf8().get_data());
|
||||
ERR_FAIL_COND_MSG(err, "Clipboard API is not supported.");
|
||||
}
|
||||
|
||||
String DisplayServerJavaScript::clipboard_get() const {
|
||||
String DisplayServerWeb::clipboard_get() const {
|
||||
godot_js_display_clipboard_get(update_clipboard_callback);
|
||||
return clipboard;
|
||||
}
|
||||
|
||||
void DisplayServerJavaScript::send_window_event_callback(int p_notification) {
|
||||
DisplayServerJavaScript *ds = get_singleton();
|
||||
void DisplayServerWeb::send_window_event_callback(int p_notification) {
|
||||
DisplayServerWeb *ds = get_singleton();
|
||||
if (!ds) {
|
||||
return;
|
||||
}
|
||||
|
|
@ -695,7 +695,7 @@ void DisplayServerJavaScript::send_window_event_callback(int p_notification) {
|
|||
}
|
||||
}
|
||||
|
||||
void DisplayServerJavaScript::set_icon(const Ref<Image> &p_icon) {
|
||||
void DisplayServerWeb::set_icon(const Ref<Image> &p_icon) {
|
||||
ERR_FAIL_COND(p_icon.is_null());
|
||||
Ref<Image> icon = p_icon;
|
||||
if (icon->is_compressed()) {
|
||||
|
|
@ -727,7 +727,7 @@ void DisplayServerJavaScript::set_icon(const Ref<Image> &p_icon) {
|
|||
godot_js_display_window_icon_set(png.ptr(), len);
|
||||
}
|
||||
|
||||
void DisplayServerJavaScript::_dispatch_input_event(const Ref<InputEvent> &p_event) {
|
||||
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;
|
||||
|
|
@ -738,11 +738,11 @@ void DisplayServerJavaScript::_dispatch_input_event(const Ref<InputEvent> &p_eve
|
|||
}
|
||||
}
|
||||
|
||||
DisplayServer *DisplayServerJavaScript::create_func(const String &p_rendering_driver, WindowMode p_window_mode, VSyncMode p_vsync_mode, uint32_t p_flags, const Size2i &p_resolution, Error &r_error) {
|
||||
return memnew(DisplayServerJavaScript(p_rendering_driver, p_window_mode, p_vsync_mode, p_flags, p_resolution, r_error));
|
||||
DisplayServer *DisplayServerWeb::create_func(const String &p_rendering_driver, WindowMode p_window_mode, VSyncMode p_vsync_mode, uint32_t p_flags, const Size2i &p_resolution, Error &r_error) {
|
||||
return memnew(DisplayServerWeb(p_rendering_driver, p_window_mode, p_vsync_mode, p_flags, p_resolution, r_error));
|
||||
}
|
||||
|
||||
DisplayServerJavaScript::DisplayServerJavaScript(const String &p_rendering_driver, WindowMode p_window_mode, VSyncMode p_vsync_mode, uint32_t p_flags, const Size2i &p_resolution, Error &r_error) {
|
||||
DisplayServerWeb::DisplayServerWeb(const String &p_rendering_driver, WindowMode p_window_mode, VSyncMode p_vsync_mode, uint32_t p_flags, const Size2i &p_resolution, Error &r_error) {
|
||||
r_error = OK; // Always succeeds for now.
|
||||
|
||||
// Ensure the canvas ID.
|
||||
|
|
@ -788,17 +788,17 @@ DisplayServerJavaScript::DisplayServerJavaScript(const String &p_rendering_drive
|
|||
#endif
|
||||
|
||||
// JS Input interface (js/libs/library_godot_input.js)
|
||||
godot_js_input_mouse_button_cb(&DisplayServerJavaScript::mouse_button_callback);
|
||||
godot_js_input_mouse_move_cb(&DisplayServerJavaScript::mouse_move_callback);
|
||||
godot_js_input_mouse_wheel_cb(&DisplayServerJavaScript::mouse_wheel_callback);
|
||||
godot_js_input_touch_cb(&DisplayServerJavaScript::touch_callback, touch_event.identifier, touch_event.coords);
|
||||
godot_js_input_key_cb(&DisplayServerJavaScript::key_callback, key_event.code, key_event.key);
|
||||
godot_js_input_mouse_button_cb(&DisplayServerWeb::mouse_button_callback);
|
||||
godot_js_input_mouse_move_cb(&DisplayServerWeb::mouse_move_callback);
|
||||
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_gamepad_cb(&DisplayServerJavaScript::gamepad_callback);
|
||||
godot_js_input_gamepad_cb(&DisplayServerWeb::gamepad_callback);
|
||||
|
||||
// JS Display interface (js/libs/library_godot_display.js)
|
||||
godot_js_display_fullscreen_cb(&DisplayServerJavaScript::fullscreen_change_callback);
|
||||
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,
|
||||
WINDOW_EVENT_MOUSE_ENTER,
|
||||
|
|
@ -810,7 +810,7 @@ DisplayServerJavaScript::DisplayServerJavaScript(const String &p_rendering_drive
|
|||
Input::get_singleton()->set_event_dispatch_function(_dispatch_input_event);
|
||||
}
|
||||
|
||||
DisplayServerJavaScript::~DisplayServerJavaScript() {
|
||||
DisplayServerWeb::~DisplayServerWeb() {
|
||||
#ifdef GLES3_ENABLED
|
||||
if (webgl_ctx) {
|
||||
emscripten_webgl_commit_frame();
|
||||
|
|
@ -819,7 +819,7 @@ DisplayServerJavaScript::~DisplayServerJavaScript() {
|
|||
#endif
|
||||
}
|
||||
|
||||
bool DisplayServerJavaScript::has_feature(Feature p_feature) const {
|
||||
bool DisplayServerWeb::has_feature(Feature p_feature) const {
|
||||
switch (p_feature) {
|
||||
//case FEATURE_GLOBAL_MENU:
|
||||
//case FEATURE_HIDPI:
|
||||
|
|
@ -846,139 +846,139 @@ bool DisplayServerJavaScript::has_feature(Feature p_feature) const {
|
|||
}
|
||||
}
|
||||
|
||||
void DisplayServerJavaScript::register_javascript_driver() {
|
||||
register_create_function("javascript", create_func, get_rendering_drivers_func);
|
||||
void DisplayServerWeb::register_web_driver() {
|
||||
register_create_function("web", create_func, get_rendering_drivers_func);
|
||||
}
|
||||
|
||||
String DisplayServerJavaScript::get_name() const {
|
||||
return "javascript";
|
||||
String DisplayServerWeb::get_name() const {
|
||||
return "web";
|
||||
}
|
||||
|
||||
int DisplayServerJavaScript::get_screen_count() const {
|
||||
int DisplayServerWeb::get_screen_count() const {
|
||||
return 1;
|
||||
}
|
||||
|
||||
Point2i DisplayServerJavaScript::screen_get_position(int p_screen) const {
|
||||
Point2i DisplayServerWeb::screen_get_position(int p_screen) const {
|
||||
return Point2i(); // TODO offsetX/Y?
|
||||
}
|
||||
|
||||
Size2i DisplayServerJavaScript::screen_get_size(int p_screen) const {
|
||||
Size2i DisplayServerWeb::screen_get_size(int p_screen) const {
|
||||
int size[2];
|
||||
godot_js_display_screen_size_get(size, size + 1);
|
||||
return Size2(size[0], size[1]);
|
||||
}
|
||||
|
||||
Rect2i DisplayServerJavaScript::screen_get_usable_rect(int p_screen) const {
|
||||
Rect2i DisplayServerWeb::screen_get_usable_rect(int p_screen) const {
|
||||
int size[2];
|
||||
godot_js_display_window_size_get(size, size + 1);
|
||||
return Rect2i(0, 0, size[0], size[1]);
|
||||
}
|
||||
|
||||
int DisplayServerJavaScript::screen_get_dpi(int p_screen) const {
|
||||
int DisplayServerWeb::screen_get_dpi(int p_screen) const {
|
||||
return godot_js_display_screen_dpi_get();
|
||||
}
|
||||
|
||||
float DisplayServerJavaScript::screen_get_scale(int p_screen) const {
|
||||
float DisplayServerWeb::screen_get_scale(int p_screen) const {
|
||||
return godot_js_display_pixel_ratio_get();
|
||||
}
|
||||
|
||||
float DisplayServerJavaScript::screen_get_refresh_rate(int p_screen) const {
|
||||
return SCREEN_REFRESH_RATE_FALLBACK; // Javascript doesn't have much of a need for the screen refresh rate, and there's no native way to do so.
|
||||
float DisplayServerWeb::screen_get_refresh_rate(int p_screen) const {
|
||||
return SCREEN_REFRESH_RATE_FALLBACK; // Web doesn't have much of a need for the screen refresh rate, and there's no native way to do so.
|
||||
}
|
||||
|
||||
Vector<DisplayServer::WindowID> DisplayServerJavaScript::get_window_list() const {
|
||||
Vector<DisplayServer::WindowID> DisplayServerWeb::get_window_list() const {
|
||||
Vector<WindowID> ret;
|
||||
ret.push_back(MAIN_WINDOW_ID);
|
||||
return ret;
|
||||
}
|
||||
|
||||
DisplayServerJavaScript::WindowID DisplayServerJavaScript::get_window_at_screen_position(const Point2i &p_position) const {
|
||||
DisplayServerWeb::WindowID DisplayServerWeb::get_window_at_screen_position(const Point2i &p_position) const {
|
||||
return MAIN_WINDOW_ID;
|
||||
}
|
||||
|
||||
void DisplayServerJavaScript::window_attach_instance_id(ObjectID p_instance, WindowID p_window) {
|
||||
void DisplayServerWeb::window_attach_instance_id(ObjectID p_instance, WindowID p_window) {
|
||||
window_attached_instance_id = p_instance;
|
||||
}
|
||||
|
||||
ObjectID DisplayServerJavaScript::window_get_attached_instance_id(WindowID p_window) const {
|
||||
ObjectID DisplayServerWeb::window_get_attached_instance_id(WindowID p_window) const {
|
||||
return window_attached_instance_id;
|
||||
}
|
||||
|
||||
void DisplayServerJavaScript::window_set_rect_changed_callback(const Callable &p_callable, WindowID p_window) {
|
||||
void DisplayServerWeb::window_set_rect_changed_callback(const Callable &p_callable, WindowID p_window) {
|
||||
// Not supported.
|
||||
}
|
||||
|
||||
void DisplayServerJavaScript::window_set_window_event_callback(const Callable &p_callable, WindowID p_window) {
|
||||
void DisplayServerWeb::window_set_window_event_callback(const Callable &p_callable, WindowID p_window) {
|
||||
window_event_callback = p_callable;
|
||||
}
|
||||
|
||||
void DisplayServerJavaScript::window_set_input_event_callback(const Callable &p_callable, WindowID p_window) {
|
||||
void DisplayServerWeb::window_set_input_event_callback(const Callable &p_callable, WindowID p_window) {
|
||||
input_event_callback = p_callable;
|
||||
}
|
||||
|
||||
void DisplayServerJavaScript::window_set_input_text_callback(const Callable &p_callable, WindowID p_window) {
|
||||
void DisplayServerWeb::window_set_input_text_callback(const Callable &p_callable, WindowID p_window) {
|
||||
input_text_callback = p_callable;
|
||||
}
|
||||
|
||||
void DisplayServerJavaScript::window_set_drop_files_callback(const Callable &p_callable, WindowID p_window) {
|
||||
void DisplayServerWeb::window_set_drop_files_callback(const Callable &p_callable, WindowID p_window) {
|
||||
drop_files_callback = p_callable;
|
||||
}
|
||||
|
||||
void DisplayServerJavaScript::window_set_title(const String &p_title, WindowID p_window) {
|
||||
void DisplayServerWeb::window_set_title(const String &p_title, WindowID p_window) {
|
||||
godot_js_display_window_title_set(p_title.utf8().get_data());
|
||||
}
|
||||
|
||||
int DisplayServerJavaScript::window_get_current_screen(WindowID p_window) const {
|
||||
int DisplayServerWeb::window_get_current_screen(WindowID p_window) const {
|
||||
return 1;
|
||||
}
|
||||
|
||||
void DisplayServerJavaScript::window_set_current_screen(int p_screen, WindowID p_window) {
|
||||
void DisplayServerWeb::window_set_current_screen(int p_screen, WindowID p_window) {
|
||||
// Not implemented.
|
||||
}
|
||||
|
||||
Point2i DisplayServerJavaScript::window_get_position(WindowID p_window) const {
|
||||
Point2i DisplayServerWeb::window_get_position(WindowID p_window) const {
|
||||
return Point2i(); // TODO Does this need implementation?
|
||||
}
|
||||
|
||||
void DisplayServerJavaScript::window_set_position(const Point2i &p_position, WindowID p_window) {
|
||||
void DisplayServerWeb::window_set_position(const Point2i &p_position, WindowID p_window) {
|
||||
// Not supported.
|
||||
}
|
||||
|
||||
void DisplayServerJavaScript::window_set_transient(WindowID p_window, WindowID p_parent) {
|
||||
void DisplayServerWeb::window_set_transient(WindowID p_window, WindowID p_parent) {
|
||||
// Not supported.
|
||||
}
|
||||
|
||||
void DisplayServerJavaScript::window_set_max_size(const Size2i p_size, WindowID p_window) {
|
||||
void DisplayServerWeb::window_set_max_size(const Size2i p_size, WindowID p_window) {
|
||||
// Not supported.
|
||||
}
|
||||
|
||||
Size2i DisplayServerJavaScript::window_get_max_size(WindowID p_window) const {
|
||||
Size2i DisplayServerWeb::window_get_max_size(WindowID p_window) const {
|
||||
return Size2i();
|
||||
}
|
||||
|
||||
void DisplayServerJavaScript::window_set_min_size(const Size2i p_size, WindowID p_window) {
|
||||
void DisplayServerWeb::window_set_min_size(const Size2i p_size, WindowID p_window) {
|
||||
// Not supported.
|
||||
}
|
||||
|
||||
Size2i DisplayServerJavaScript::window_get_min_size(WindowID p_window) const {
|
||||
Size2i DisplayServerWeb::window_get_min_size(WindowID p_window) const {
|
||||
return Size2i();
|
||||
}
|
||||
|
||||
void DisplayServerJavaScript::window_set_size(const Size2i p_size, WindowID p_window) {
|
||||
void DisplayServerWeb::window_set_size(const Size2i p_size, WindowID p_window) {
|
||||
godot_js_display_desired_size_set(p_size.x, p_size.y);
|
||||
}
|
||||
|
||||
Size2i DisplayServerJavaScript::window_get_size(WindowID p_window) const {
|
||||
Size2i DisplayServerWeb::window_get_size(WindowID p_window) const {
|
||||
int size[2];
|
||||
godot_js_display_window_size_get(size, size + 1);
|
||||
return Size2i(size[0], size[1]);
|
||||
}
|
||||
|
||||
Size2i DisplayServerJavaScript::window_get_real_size(WindowID p_window) const {
|
||||
Size2i DisplayServerWeb::window_get_real_size(WindowID p_window) const {
|
||||
return window_get_size(p_window);
|
||||
}
|
||||
|
||||
void DisplayServerJavaScript::window_set_mode(WindowMode p_mode, WindowID p_window) {
|
||||
void DisplayServerWeb::window_set_mode(WindowMode p_mode, WindowID p_window) {
|
||||
if (window_mode == p_mode) {
|
||||
return;
|
||||
}
|
||||
|
|
@ -993,65 +993,65 @@ void DisplayServerJavaScript::window_set_mode(WindowMode p_mode, WindowID p_wind
|
|||
case WINDOW_MODE_EXCLUSIVE_FULLSCREEN:
|
||||
case WINDOW_MODE_FULLSCREEN: {
|
||||
int result = godot_js_display_fullscreen_request();
|
||||
ERR_FAIL_COND_MSG(result, "The request was denied. Remember that enabling fullscreen is only possible from an input callback for the HTML5 platform.");
|
||||
ERR_FAIL_COND_MSG(result, "The request was denied. Remember that enabling fullscreen is only possible from an input callback for the Web platform.");
|
||||
} break;
|
||||
case WINDOW_MODE_MAXIMIZED:
|
||||
case WINDOW_MODE_MINIMIZED:
|
||||
WARN_PRINT("WindowMode MAXIMIZED and MINIMIZED are not supported in HTML5 platform.");
|
||||
WARN_PRINT("WindowMode MAXIMIZED and MINIMIZED are not supported in Web platform.");
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
DisplayServerJavaScript::WindowMode DisplayServerJavaScript::window_get_mode(WindowID p_window) const {
|
||||
DisplayServerWeb::WindowMode DisplayServerWeb::window_get_mode(WindowID p_window) const {
|
||||
return window_mode;
|
||||
}
|
||||
|
||||
bool DisplayServerJavaScript::window_is_maximize_allowed(WindowID p_window) const {
|
||||
bool DisplayServerWeb::window_is_maximize_allowed(WindowID p_window) const {
|
||||
return false;
|
||||
}
|
||||
|
||||
void DisplayServerJavaScript::window_set_flag(WindowFlags p_flag, bool p_enabled, WindowID p_window) {
|
||||
void DisplayServerWeb::window_set_flag(WindowFlags p_flag, bool p_enabled, WindowID p_window) {
|
||||
// Not supported.
|
||||
}
|
||||
|
||||
bool DisplayServerJavaScript::window_get_flag(WindowFlags p_flag, WindowID p_window) const {
|
||||
bool DisplayServerWeb::window_get_flag(WindowFlags p_flag, WindowID p_window) const {
|
||||
return false;
|
||||
}
|
||||
|
||||
void DisplayServerJavaScript::window_request_attention(WindowID p_window) {
|
||||
void DisplayServerWeb::window_request_attention(WindowID p_window) {
|
||||
// Not supported.
|
||||
}
|
||||
|
||||
void DisplayServerJavaScript::window_move_to_foreground(WindowID p_window) {
|
||||
void DisplayServerWeb::window_move_to_foreground(WindowID p_window) {
|
||||
// Not supported.
|
||||
}
|
||||
|
||||
bool DisplayServerJavaScript::window_can_draw(WindowID p_window) const {
|
||||
bool DisplayServerWeb::window_can_draw(WindowID p_window) const {
|
||||
return true;
|
||||
}
|
||||
|
||||
bool DisplayServerJavaScript::can_any_window_draw() const {
|
||||
bool DisplayServerWeb::can_any_window_draw() const {
|
||||
return true;
|
||||
}
|
||||
|
||||
void DisplayServerJavaScript::process_events() {
|
||||
void DisplayServerWeb::process_events() {
|
||||
Input::get_singleton()->flush_buffered_events();
|
||||
if (godot_js_input_gamepad_sample() == OK) {
|
||||
process_joypads();
|
||||
}
|
||||
}
|
||||
|
||||
int DisplayServerJavaScript::get_current_video_driver() const {
|
||||
int DisplayServerWeb::get_current_video_driver() const {
|
||||
return 1;
|
||||
}
|
||||
|
||||
bool DisplayServerJavaScript::get_swap_cancel_ok() {
|
||||
bool DisplayServerWeb::get_swap_cancel_ok() {
|
||||
return swap_cancel_ok;
|
||||
}
|
||||
|
||||
void DisplayServerJavaScript::swap_buffers() {
|
||||
void DisplayServerWeb::swap_buffers() {
|
||||
#ifdef GLES3_ENABLED
|
||||
if (webgl_ctx) {
|
||||
emscripten_webgl_commit_frame();
|
||||
|
|
@ -1,5 +1,5 @@
|
|||
/*************************************************************************/
|
||||
/* display_server_javascript.h */
|
||||
/* display_server_web.h */
|
||||
/*************************************************************************/
|
||||
/* This file is part of: */
|
||||
/* GODOT ENGINE */
|
||||
|
|
@ -28,15 +28,15 @@
|
|||
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
||||
/*************************************************************************/
|
||||
|
||||
#ifndef DISPLAY_SERVER_JAVASCRIPT_H
|
||||
#define DISPLAY_SERVER_JAVASCRIPT_H
|
||||
#ifndef DISPLAY_SERVER_WEB_H
|
||||
#define DISPLAY_SERVER_WEB_H
|
||||
|
||||
#include "servers/display_server.h"
|
||||
|
||||
#include <emscripten.h>
|
||||
#include <emscripten/html5.h>
|
||||
|
||||
class DisplayServerJavaScript : public DisplayServer {
|
||||
class DisplayServerWeb : public DisplayServer {
|
||||
private:
|
||||
struct JSTouchEvent {
|
||||
uint32_t identifier[32] = { 0 };
|
||||
|
|
@ -112,7 +112,7 @@ protected:
|
|||
|
||||
public:
|
||||
// Override return type to make writing static callbacks less tedious.
|
||||
static DisplayServerJavaScript *get_singleton();
|
||||
static DisplayServerWeb *get_singleton();
|
||||
|
||||
// utilities
|
||||
bool check_size_force_redraw();
|
||||
|
|
@ -220,9 +220,9 @@ public:
|
|||
virtual bool get_swap_cancel_ok() override;
|
||||
virtual void swap_buffers() override;
|
||||
|
||||
static void register_javascript_driver();
|
||||
DisplayServerJavaScript(const String &p_rendering_driver, WindowMode p_window_mode, VSyncMode p_vsync_mode, uint32_t p_flags, const Size2i &p_resolution, Error &r_error);
|
||||
~DisplayServerJavaScript();
|
||||
static void register_web_driver();
|
||||
DisplayServerWeb(const String &p_rendering_driver, WindowMode p_window_mode, VSyncMode p_vsync_mode, uint32_t p_flags, const Size2i &p_resolution, Error &r_error);
|
||||
~DisplayServerWeb();
|
||||
};
|
||||
|
||||
#endif // DISPLAY_SERVER_JAVASCRIPT_H
|
||||
#endif // DISPLAY_SERVER_WEB_H
|
||||
|
|
@ -39,11 +39,11 @@ def create_engine_file(env, target, source, externs):
|
|||
|
||||
def create_template_zip(env, js, wasm, extra):
|
||||
binary_name = "godot.tools" if env["tools"] else "godot"
|
||||
zip_dir = env.Dir("#bin/.javascript_zip")
|
||||
zip_dir = env.Dir("#bin/.web_zip")
|
||||
in_files = [
|
||||
js,
|
||||
wasm,
|
||||
"#platform/javascript/js/libs/audio.worklet.js",
|
||||
"#platform/web/js/libs/audio.worklet.js",
|
||||
]
|
||||
out_files = [
|
||||
zip_dir.File(binary_name + ".js"),
|
||||
|
|
@ -1,5 +1,5 @@
|
|||
/*************************************************************************/
|
||||
/* export_server.h */
|
||||
/* editor_http_server.h */
|
||||
/*************************************************************************/
|
||||
/* This file is part of: */
|
||||
/* GODOT ENGINE */
|
||||
|
|
@ -28,8 +28,8 @@
|
|||
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
||||
/*************************************************************************/
|
||||
|
||||
#ifndef JAVASCRIPT_EXPORT_SERVER_H
|
||||
#define JAVASCRIPT_EXPORT_SERVER_H
|
||||
#ifndef WEB_EDITOR_HTTP_SERVER_H
|
||||
#define WEB_EDITOR_HTTP_SERVER_H
|
||||
|
||||
#include "core/io/image_loader.h"
|
||||
#include "core/io/stream_peer_ssl.h"
|
||||
|
|
@ -247,4 +247,4 @@ public:
|
|||
}
|
||||
};
|
||||
|
||||
#endif // JAVASCRIPT_EXPORT_SERVER_H
|
||||
#endif // WEB_EDITOR_HTTP_SERVER_H
|
||||
|
|
@ -33,7 +33,7 @@
|
|||
#include "editor/editor_settings.h"
|
||||
#include "export_plugin.h"
|
||||
|
||||
void register_javascript_exporter() {
|
||||
void register_web_exporter() {
|
||||
EDITOR_DEF("export/web/http_host", "localhost");
|
||||
EDITOR_DEF("export/web/http_port", 8060);
|
||||
EDITOR_DEF("export/web/use_ssl", false);
|
||||
|
|
@ -43,7 +43,7 @@ void register_javascript_exporter() {
|
|||
EditorSettings::get_singleton()->add_property_hint(PropertyInfo(Variant::STRING, "export/web/ssl_key", PROPERTY_HINT_GLOBAL_FILE, "*.key"));
|
||||
EditorSettings::get_singleton()->add_property_hint(PropertyInfo(Variant::STRING, "export/web/ssl_certificate", PROPERTY_HINT_GLOBAL_FILE, "*.crt,*.pem"));
|
||||
|
||||
Ref<EditorExportPlatformJavaScript> platform;
|
||||
Ref<EditorExportPlatformWeb> platform;
|
||||
platform.instantiate();
|
||||
EditorExport::get_singleton()->add_export_platform(platform);
|
||||
}
|
||||
|
|
@ -28,9 +28,9 @@
|
|||
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
||||
/*************************************************************************/
|
||||
|
||||
#ifndef JAVASCRIPT_EXPORT_H
|
||||
#define JAVASCRIPT_EXPORT_H
|
||||
#ifndef WEB_EXPORT_H
|
||||
#define WEB_EXPORT_H
|
||||
|
||||
void register_javascript_exporter();
|
||||
void register_web_exporter();
|
||||
|
||||
#endif // JAVASCRIPT_EXPORT_H
|
||||
#endif // WEB_EXPORT_H
|
||||
|
|
@ -33,7 +33,7 @@
|
|||
#include "core/config/project_settings.h"
|
||||
#include "editor/editor_settings.h"
|
||||
|
||||
Error EditorExportPlatformJavaScript::_extract_template(const String &p_template, const String &p_dir, const String &p_name, bool pwa) {
|
||||
Error EditorExportPlatformWeb::_extract_template(const String &p_template, const String &p_dir, const String &p_name, bool pwa) {
|
||||
Ref<FileAccess> io_fa;
|
||||
zlib_filefunc_def io = zipio_create_io(&io_fa);
|
||||
unzFile pkg = unzOpen2(p_template.utf8().get_data(), &io);
|
||||
|
|
@ -89,7 +89,7 @@ Error EditorExportPlatformJavaScript::_extract_template(const String &p_template
|
|||
return OK;
|
||||
}
|
||||
|
||||
Error EditorExportPlatformJavaScript::_write_or_error(const uint8_t *p_content, int p_size, String p_path) {
|
||||
Error EditorExportPlatformWeb::_write_or_error(const uint8_t *p_content, int p_size, String p_path) {
|
||||
Ref<FileAccess> f = FileAccess::open(p_path, FileAccess::WRITE);
|
||||
if (f.is_null()) {
|
||||
add_message(EXPORT_MESSAGE_ERROR, TTR("Export"), vformat(TTR("Could not write file: \"%s\"."), p_path));
|
||||
|
|
@ -99,7 +99,7 @@ Error EditorExportPlatformJavaScript::_write_or_error(const uint8_t *p_content,
|
|||
return OK;
|
||||
}
|
||||
|
||||
void EditorExportPlatformJavaScript::_replace_strings(HashMap<String, String> p_replaces, Vector<uint8_t> &r_template) {
|
||||
void EditorExportPlatformWeb::_replace_strings(HashMap<String, String> p_replaces, Vector<uint8_t> &r_template) {
|
||||
String str_template = String::utf8(reinterpret_cast<const char *>(r_template.ptr()), r_template.size());
|
||||
String out;
|
||||
Vector<String> lines = str_template.split("\n");
|
||||
|
|
@ -117,7 +117,7 @@ void EditorExportPlatformJavaScript::_replace_strings(HashMap<String, String> p_
|
|||
}
|
||||
}
|
||||
|
||||
void EditorExportPlatformJavaScript::_fix_html(Vector<uint8_t> &p_html, const Ref<EditorExportPreset> &p_preset, const String &p_name, bool p_debug, int p_flags, const Vector<SharedObject> p_shared_objects, const Dictionary &p_file_sizes) {
|
||||
void EditorExportPlatformWeb::_fix_html(Vector<uint8_t> &p_html, const Ref<EditorExportPreset> &p_preset, const String &p_name, bool p_debug, int p_flags, const Vector<SharedObject> p_shared_objects, const Dictionary &p_file_sizes) {
|
||||
// Engine.js config
|
||||
Dictionary config;
|
||||
Array libs;
|
||||
|
|
@ -159,7 +159,7 @@ void EditorExportPlatformJavaScript::_fix_html(Vector<uint8_t> &p_html, const Re
|
|||
_replace_strings(replaces, p_html);
|
||||
}
|
||||
|
||||
Error EditorExportPlatformJavaScript::_add_manifest_icon(const String &p_path, const String &p_icon, int p_size, Array &r_arr) {
|
||||
Error EditorExportPlatformWeb::_add_manifest_icon(const String &p_path, const String &p_icon, int p_size, Array &r_arr) {
|
||||
const String name = p_path.get_file().get_basename();
|
||||
const String icon_name = vformat("%s.%dx%d.png", name, p_size, p_size);
|
||||
const String icon_dest = p_path.get_base_dir().plus_file(icon_name);
|
||||
|
|
@ -192,7 +192,7 @@ Error EditorExportPlatformJavaScript::_add_manifest_icon(const String &p_path, c
|
|||
return err;
|
||||
}
|
||||
|
||||
Error EditorExportPlatformJavaScript::_build_pwa(const Ref<EditorExportPreset> &p_preset, const String p_path, const Vector<SharedObject> &p_shared_objects) {
|
||||
Error EditorExportPlatformWeb::_build_pwa(const Ref<EditorExportPreset> &p_preset, const String p_path, const Vector<SharedObject> &p_shared_objects) {
|
||||
String proj_name = ProjectSettings::get_singleton()->get_setting("application/config/name");
|
||||
if (proj_name.is_empty()) {
|
||||
proj_name = "Godot Game";
|
||||
|
|
@ -303,7 +303,7 @@ Error EditorExportPlatformJavaScript::_build_pwa(const Ref<EditorExportPreset> &
|
|||
return OK;
|
||||
}
|
||||
|
||||
void EditorExportPlatformJavaScript::get_preset_features(const Ref<EditorExportPreset> &p_preset, List<String> *r_features) const {
|
||||
void EditorExportPlatformWeb::get_preset_features(const Ref<EditorExportPreset> &p_preset, List<String> *r_features) const {
|
||||
if (p_preset->get("vram_texture_compression/for_desktop")) {
|
||||
r_features->push_back("s3tc");
|
||||
}
|
||||
|
|
@ -326,7 +326,7 @@ void EditorExportPlatformJavaScript::get_preset_features(const Ref<EditorExportP
|
|||
}
|
||||
}
|
||||
|
||||
void EditorExportPlatformJavaScript::get_export_options(List<ExportOption> *r_options) {
|
||||
void EditorExportPlatformWeb::get_export_options(List<ExportOption> *r_options) {
|
||||
r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "custom_template/debug", PROPERTY_HINT_GLOBAL_FILE, "*.zip"), ""));
|
||||
r_options->push_back(ExportOption(PropertyInfo(Variant::STRING, "custom_template/release", PROPERTY_HINT_GLOBAL_FILE, "*.zip"), ""));
|
||||
|
||||
|
|
@ -350,25 +350,25 @@ void EditorExportPlatformJavaScript::get_export_options(List<ExportOption> *r_op
|
|||
r_options->push_back(ExportOption(PropertyInfo(Variant::COLOR, "progressive_web_app/background_color", PROPERTY_HINT_COLOR_NO_ALPHA), Color()));
|
||||
}
|
||||
|
||||
String EditorExportPlatformJavaScript::get_name() const {
|
||||
return "HTML5";
|
||||
String EditorExportPlatformWeb::get_name() const {
|
||||
return "Web";
|
||||
}
|
||||
|
||||
String EditorExportPlatformJavaScript::get_os_name() const {
|
||||
return "HTML5";
|
||||
String EditorExportPlatformWeb::get_os_name() const {
|
||||
return "Web";
|
||||
}
|
||||
|
||||
Ref<Texture2D> EditorExportPlatformJavaScript::get_logo() const {
|
||||
Ref<Texture2D> EditorExportPlatformWeb::get_logo() const {
|
||||
return logo;
|
||||
}
|
||||
|
||||
bool EditorExportPlatformJavaScript::has_valid_export_configuration(const Ref<EditorExportPreset> &p_preset, String &r_error, bool &r_missing_templates) const {
|
||||
bool EditorExportPlatformWeb::has_valid_export_configuration(const Ref<EditorExportPreset> &p_preset, String &r_error, bool &r_missing_templates) const {
|
||||
#ifndef DEV_ENABLED
|
||||
// We don't provide export templates for the HTML5 platform currently as there
|
||||
// We don't provide export templates for the Web platform currently as there
|
||||
// is no suitable renderer to use with them. So we forbid exporting and tell
|
||||
// users why. This is skipped in DEV_ENABLED so that contributors can still test
|
||||
// the pipeline once we start having WebGL or WebGPU support.
|
||||
r_error = "The HTML5 platform is currently not supported in Godot 4.0, as there is no suitable renderer for it.\n";
|
||||
r_error = "The Web platform is currently not supported in Godot 4.0, as there is no suitable renderer for it.\n";
|
||||
return false;
|
||||
#endif
|
||||
|
||||
|
|
@ -403,13 +403,13 @@ bool EditorExportPlatformJavaScript::has_valid_export_configuration(const Ref<Ed
|
|||
return valid;
|
||||
}
|
||||
|
||||
bool EditorExportPlatformJavaScript::has_valid_project_configuration(const Ref<EditorExportPreset> &p_preset, String &r_error) const {
|
||||
bool EditorExportPlatformWeb::has_valid_project_configuration(const Ref<EditorExportPreset> &p_preset, String &r_error) const {
|
||||
#ifndef DEV_ENABLED
|
||||
// We don't provide export templates for the HTML5 platform currently as there
|
||||
// We don't provide export templates for the Web platform currently as there
|
||||
// is no suitable renderer to use with them. So we forbid exporting and tell
|
||||
// users why. This is skipped in DEV_ENABLED so that contributors can still test
|
||||
// the pipeline once we start having WebGL or WebGPU support.
|
||||
r_error = "The HTML5 platform is currently not supported in Godot 4.0, as there is no suitable renderer for it.\n";
|
||||
r_error = "The Web platform is currently not supported in Godot 4.0, as there is no suitable renderer for it.\n";
|
||||
return false;
|
||||
#endif
|
||||
|
||||
|
|
@ -433,13 +433,13 @@ bool EditorExportPlatformJavaScript::has_valid_project_configuration(const Ref<E
|
|||
return valid;
|
||||
}
|
||||
|
||||
List<String> EditorExportPlatformJavaScript::get_binary_extensions(const Ref<EditorExportPreset> &p_preset) const {
|
||||
List<String> EditorExportPlatformWeb::get_binary_extensions(const Ref<EditorExportPreset> &p_preset) const {
|
||||
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) {
|
||||
Error EditorExportPlatformWeb::export_project(const Ref<EditorExportPreset> &p_preset, bool p_debug, const String &p_path, int p_flags) {
|
||||
ExportNotifier notifier(*this, p_preset, p_debug, p_path, p_flags);
|
||||
|
||||
const String custom_debug = p_preset->get("custom_template/debug");
|
||||
|
|
@ -562,7 +562,7 @@ Error EditorExportPlatformJavaScript::export_project(const Ref<EditorExportPrese
|
|||
return OK;
|
||||
}
|
||||
|
||||
bool EditorExportPlatformJavaScript::poll_export() {
|
||||
bool EditorExportPlatformWeb::poll_export() {
|
||||
Ref<EditorExportPreset> preset;
|
||||
|
||||
for (int i = 0; i < EditorExport::get_singleton()->get_export_preset_count(); i++) {
|
||||
|
|
@ -586,15 +586,15 @@ bool EditorExportPlatformJavaScript::poll_export() {
|
|||
return menu_options != prev;
|
||||
}
|
||||
|
||||
Ref<ImageTexture> EditorExportPlatformJavaScript::get_option_icon(int p_index) const {
|
||||
Ref<ImageTexture> EditorExportPlatformWeb::get_option_icon(int p_index) const {
|
||||
return p_index == 1 ? stop_icon : EditorExportPlatform::get_option_icon(p_index);
|
||||
}
|
||||
|
||||
int EditorExportPlatformJavaScript::get_options_count() const {
|
||||
int EditorExportPlatformWeb::get_options_count() const {
|
||||
return menu_options;
|
||||
}
|
||||
|
||||
Error EditorExportPlatformJavaScript::run(const Ref<EditorExportPreset> &p_preset, int p_option, int p_debug_flags) {
|
||||
Error EditorExportPlatformWeb::run(const Ref<EditorExportPreset> &p_preset, int p_option, int p_debug_flags) {
|
||||
if (p_option == 1) {
|
||||
MutexLock lock(server_lock);
|
||||
server->stop();
|
||||
|
|
@ -663,12 +663,12 @@ Error EditorExportPlatformJavaScript::run(const Ref<EditorExportPreset> &p_prese
|
|||
return OK;
|
||||
}
|
||||
|
||||
Ref<Texture2D> EditorExportPlatformJavaScript::get_run_icon() const {
|
||||
Ref<Texture2D> EditorExportPlatformWeb::get_run_icon() const {
|
||||
return run_icon;
|
||||
}
|
||||
|
||||
void EditorExportPlatformJavaScript::_server_thread_poll(void *data) {
|
||||
EditorExportPlatformJavaScript *ej = static_cast<EditorExportPlatformJavaScript *>(data);
|
||||
void EditorExportPlatformWeb::_server_thread_poll(void *data) {
|
||||
EditorExportPlatformWeb *ej = static_cast<EditorExportPlatformWeb *>(data);
|
||||
while (!ej->server_quit) {
|
||||
OS::get_singleton()->delay_usec(6900);
|
||||
{
|
||||
|
|
@ -678,12 +678,12 @@ void EditorExportPlatformJavaScript::_server_thread_poll(void *data) {
|
|||
}
|
||||
}
|
||||
|
||||
EditorExportPlatformJavaScript::EditorExportPlatformJavaScript() {
|
||||
EditorExportPlatformWeb::EditorExportPlatformWeb() {
|
||||
server.instantiate();
|
||||
server_thread.start(_server_thread_poll, this);
|
||||
|
||||
logo = ImageTexture::create_from_image(memnew(Image(_javascript_logo)));
|
||||
run_icon = ImageTexture::create_from_image(memnew(Image(_javascript_run_icon)));
|
||||
logo = ImageTexture::create_from_image(memnew(Image(_web_logo)));
|
||||
run_icon = ImageTexture::create_from_image(memnew(Image(_web_run_icon)));
|
||||
|
||||
Ref<Theme> theme = EditorNode::get_singleton()->get_editor_theme();
|
||||
if (theme.is_valid()) {
|
||||
|
|
@ -693,7 +693,7 @@ EditorExportPlatformJavaScript::EditorExportPlatformJavaScript() {
|
|||
}
|
||||
}
|
||||
|
||||
EditorExportPlatformJavaScript::~EditorExportPlatformJavaScript() {
|
||||
EditorExportPlatformWeb::~EditorExportPlatformWeb() {
|
||||
server->stop();
|
||||
server_quit = true;
|
||||
server_thread.wait_to_finish();
|
||||
|
|
@ -28,8 +28,8 @@
|
|||
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
||||
/*************************************************************************/
|
||||
|
||||
#ifndef JAVASCRIPT_EXPORT_PLUGIN_H
|
||||
#define JAVASCRIPT_EXPORT_PLUGIN_H
|
||||
#ifndef WEB_EXPORT_PLUGIN_H
|
||||
#define WEB_EXPORT_PLUGIN_H
|
||||
|
||||
#include "core/config/project_settings.h"
|
||||
#include "core/io/image_loader.h"
|
||||
|
|
@ -39,13 +39,13 @@
|
|||
#include "editor/editor_node.h"
|
||||
#include "editor/export/editor_export_platform.h"
|
||||
#include "main/splash.gen.h"
|
||||
#include "platform/javascript/logo.gen.h"
|
||||
#include "platform/javascript/run_icon.gen.h"
|
||||
#include "platform/web/logo.gen.h"
|
||||
#include "platform/web/run_icon.gen.h"
|
||||
|
||||
#include "export_server.h"
|
||||
#include "editor_http_server.h"
|
||||
|
||||
class EditorExportPlatformJavaScript : public EditorExportPlatform {
|
||||
GDCLASS(EditorExportPlatformJavaScript, EditorExportPlatform);
|
||||
class EditorExportPlatformWeb : public EditorExportPlatform {
|
||||
GDCLASS(EditorExportPlatformWeb, EditorExportPlatform);
|
||||
|
||||
Ref<ImageTexture> logo;
|
||||
Ref<ImageTexture> run_icon;
|
||||
|
|
@ -141,8 +141,8 @@ public:
|
|||
|
||||
String get_debug_protocol() const override { return "ws://"; }
|
||||
|
||||
EditorExportPlatformJavaScript();
|
||||
~EditorExportPlatformJavaScript();
|
||||
EditorExportPlatformWeb();
|
||||
~EditorExportPlatformWeb();
|
||||
};
|
||||
|
||||
#endif // JAVASCRIPT_EXPORT_PLUGIN_H
|
||||
#endif // WEB_EXPORT_PLUGIN_H
|
||||
|
|
@ -1,5 +1,5 @@
|
|||
/*************************************************************************/
|
||||
/* http_client_javascript.cpp */
|
||||
/* http_client_web.cpp */
|
||||
/*************************************************************************/
|
||||
/* This file is part of: */
|
||||
/* GODOT ENGINE */
|
||||
|
|
@ -28,19 +28,19 @@
|
|||
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
||||
/*************************************************************************/
|
||||
|
||||
#include "http_client_javascript.h"
|
||||
#include "http_client_web.h"
|
||||
|
||||
void HTTPClientJavaScript::_parse_headers(int p_len, const char **p_headers, void *p_ref) {
|
||||
HTTPClientJavaScript *client = static_cast<HTTPClientJavaScript *>(p_ref);
|
||||
void HTTPClientWeb::_parse_headers(int p_len, const char **p_headers, void *p_ref) {
|
||||
HTTPClientWeb *client = static_cast<HTTPClientWeb *>(p_ref);
|
||||
for (int i = 0; i < p_len; i++) {
|
||||
client->response_headers.push_back(String::utf8(p_headers[i]));
|
||||
}
|
||||
}
|
||||
|
||||
Error HTTPClientJavaScript::connect_to_host(const String &p_host, int p_port, bool p_ssl, bool p_verify_host) {
|
||||
Error HTTPClientWeb::connect_to_host(const String &p_host, int p_port, bool p_ssl, bool p_verify_host) {
|
||||
close();
|
||||
if (p_ssl && !p_verify_host) {
|
||||
WARN_PRINT("Disabling HTTPClientJavaScript's host verification is not supported for the HTML5 platform, host will be verified");
|
||||
WARN_PRINT("Disabling HTTPClientWeb's host verification is not supported for the Web platform, host will be verified");
|
||||
}
|
||||
|
||||
port = p_port;
|
||||
|
|
@ -71,17 +71,17 @@ Error HTTPClientJavaScript::connect_to_host(const String &p_host, int p_port, bo
|
|||
return OK;
|
||||
}
|
||||
|
||||
void HTTPClientJavaScript::set_connection(const Ref<StreamPeer> &p_connection) {
|
||||
ERR_FAIL_MSG("Accessing an HTTPClientJavaScript's StreamPeer is not supported for the HTML5 platform.");
|
||||
void HTTPClientWeb::set_connection(const Ref<StreamPeer> &p_connection) {
|
||||
ERR_FAIL_MSG("Accessing an HTTPClientWeb's StreamPeer is not supported for the Web platform.");
|
||||
}
|
||||
|
||||
Ref<StreamPeer> HTTPClientJavaScript::get_connection() const {
|
||||
ERR_FAIL_V_MSG(Ref<RefCounted>(), "Accessing an HTTPClientJavaScript's StreamPeer is not supported for the HTML5 platform.");
|
||||
Ref<StreamPeer> HTTPClientWeb::get_connection() const {
|
||||
ERR_FAIL_V_MSG(Ref<RefCounted>(), "Accessing an HTTPClientWeb's StreamPeer is not supported for the Web platform.");
|
||||
}
|
||||
|
||||
Error HTTPClientJavaScript::request(Method p_method, const String &p_url, const Vector<String> &p_headers, const uint8_t *p_body, int p_body_len) {
|
||||
Error HTTPClientWeb::request(Method p_method, const String &p_url, const Vector<String> &p_headers, const uint8_t *p_body, int p_body_len) {
|
||||
ERR_FAIL_INDEX_V(p_method, METHOD_MAX, ERR_INVALID_PARAMETER);
|
||||
ERR_FAIL_COND_V_MSG(p_method == METHOD_TRACE || p_method == METHOD_CONNECT, ERR_UNAVAILABLE, "HTTP methods TRACE and CONNECT are not supported for the HTML5 platform.");
|
||||
ERR_FAIL_COND_V_MSG(p_method == METHOD_TRACE || p_method == METHOD_CONNECT, ERR_UNAVAILABLE, "HTTP methods TRACE and CONNECT are not supported for the Web platform.");
|
||||
ERR_FAIL_COND_V(status != STATUS_CONNECTED, ERR_INVALID_PARAMETER);
|
||||
ERR_FAIL_COND_V(host.is_empty(), ERR_UNCONFIGURED);
|
||||
ERR_FAIL_COND_V(port < 0, ERR_UNCONFIGURED);
|
||||
|
|
@ -107,7 +107,7 @@ Error HTTPClientJavaScript::request(Method p_method, const String &p_url, const
|
|||
return OK;
|
||||
}
|
||||
|
||||
void HTTPClientJavaScript::close() {
|
||||
void HTTPClientWeb::close() {
|
||||
host = "";
|
||||
port = -1;
|
||||
use_tls = false;
|
||||
|
|
@ -121,23 +121,23 @@ void HTTPClientJavaScript::close() {
|
|||
}
|
||||
}
|
||||
|
||||
HTTPClientJavaScript::Status HTTPClientJavaScript::get_status() const {
|
||||
HTTPClientWeb::Status HTTPClientWeb::get_status() const {
|
||||
return status;
|
||||
}
|
||||
|
||||
bool HTTPClientJavaScript::has_response() const {
|
||||
bool HTTPClientWeb::has_response() const {
|
||||
return response_headers.size() > 0;
|
||||
}
|
||||
|
||||
bool HTTPClientJavaScript::is_response_chunked() const {
|
||||
bool HTTPClientWeb::is_response_chunked() const {
|
||||
return godot_js_fetch_is_chunked(js_id);
|
||||
}
|
||||
|
||||
int HTTPClientJavaScript::get_response_code() const {
|
||||
int HTTPClientWeb::get_response_code() const {
|
||||
return polled_response_code;
|
||||
}
|
||||
|
||||
Error HTTPClientJavaScript::get_response_headers(List<String> *r_response) {
|
||||
Error HTTPClientWeb::get_response_headers(List<String> *r_response) {
|
||||
if (!response_headers.size()) {
|
||||
return ERR_INVALID_PARAMETER;
|
||||
}
|
||||
|
|
@ -148,11 +148,11 @@ Error HTTPClientJavaScript::get_response_headers(List<String> *r_response) {
|
|||
return OK;
|
||||
}
|
||||
|
||||
int64_t HTTPClientJavaScript::get_response_body_length() const {
|
||||
int64_t HTTPClientWeb::get_response_body_length() const {
|
||||
return godot_js_fetch_body_length_get(js_id);
|
||||
}
|
||||
|
||||
PackedByteArray HTTPClientJavaScript::read_response_body_chunk() {
|
||||
PackedByteArray HTTPClientWeb::read_response_body_chunk() {
|
||||
ERR_FAIL_COND_V(status != STATUS_BODY, PackedByteArray());
|
||||
|
||||
if (response_buffer.size() != read_limit) {
|
||||
|
|
@ -177,23 +177,23 @@ PackedByteArray HTTPClientJavaScript::read_response_body_chunk() {
|
|||
return chunk;
|
||||
}
|
||||
|
||||
void HTTPClientJavaScript::set_blocking_mode(bool p_enable) {
|
||||
ERR_FAIL_COND_MSG(p_enable, "HTTPClientJavaScript blocking mode is not supported for the HTML5 platform.");
|
||||
void HTTPClientWeb::set_blocking_mode(bool p_enable) {
|
||||
ERR_FAIL_COND_MSG(p_enable, "HTTPClientWeb blocking mode is not supported for the Web platform.");
|
||||
}
|
||||
|
||||
bool HTTPClientJavaScript::is_blocking_mode_enabled() const {
|
||||
bool HTTPClientWeb::is_blocking_mode_enabled() const {
|
||||
return false;
|
||||
}
|
||||
|
||||
void HTTPClientJavaScript::set_read_chunk_size(int p_size) {
|
||||
void HTTPClientWeb::set_read_chunk_size(int p_size) {
|
||||
read_limit = p_size;
|
||||
}
|
||||
|
||||
int HTTPClientJavaScript::get_read_chunk_size() const {
|
||||
int HTTPClientWeb::get_read_chunk_size() const {
|
||||
return read_limit;
|
||||
}
|
||||
|
||||
Error HTTPClientJavaScript::poll() {
|
||||
Error HTTPClientWeb::poll() {
|
||||
switch (status) {
|
||||
case STATUS_DISCONNECTED:
|
||||
return ERR_UNCONFIGURED;
|
||||
|
|
@ -227,9 +227,9 @@ Error HTTPClientJavaScript::poll() {
|
|||
#ifdef DEBUG_ENABLED
|
||||
// forcing synchronous requests is not possible on the web
|
||||
if (last_polling_frame == Engine::get_singleton()->get_process_frames()) {
|
||||
WARN_PRINT("HTTPClientJavaScript polled multiple times in one frame, "
|
||||
WARN_PRINT("HTTPClientWeb polled multiple times in one frame, "
|
||||
"but request cannot progress more than once per "
|
||||
"frame on the HTML5 platform.");
|
||||
"frame on the Web platform.");
|
||||
}
|
||||
last_polling_frame = Engine::get_singleton()->get_process_frames();
|
||||
#endif
|
||||
|
|
@ -258,15 +258,15 @@ Error HTTPClientJavaScript::poll() {
|
|||
return OK;
|
||||
}
|
||||
|
||||
HTTPClient *HTTPClientJavaScript::_create_func() {
|
||||
return memnew(HTTPClientJavaScript);
|
||||
HTTPClient *HTTPClientWeb::_create_func() {
|
||||
return memnew(HTTPClientWeb);
|
||||
}
|
||||
|
||||
HTTPClient *(*HTTPClient::_create)() = HTTPClientJavaScript::_create_func;
|
||||
HTTPClient *(*HTTPClient::_create)() = HTTPClientWeb::_create_func;
|
||||
|
||||
HTTPClientJavaScript::HTTPClientJavaScript() {
|
||||
HTTPClientWeb::HTTPClientWeb() {
|
||||
}
|
||||
|
||||
HTTPClientJavaScript::~HTTPClientJavaScript() {
|
||||
HTTPClientWeb::~HTTPClientWeb() {
|
||||
close();
|
||||
}
|
||||
|
|
@ -1,5 +1,5 @@
|
|||
/*************************************************************************/
|
||||
/* http_client_javascript.h */
|
||||
/* http_client_web.h */
|
||||
/*************************************************************************/
|
||||
/* This file is part of: */
|
||||
/* GODOT ENGINE */
|
||||
|
|
@ -28,8 +28,8 @@
|
|||
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
||||
/*************************************************************************/
|
||||
|
||||
#ifndef HTTP_CLIENT_JAVASCRIPT_H
|
||||
#define HTTP_CLIENT_JAVASCRIPT_H
|
||||
#ifndef HTTP_CLIENT_WEB_H
|
||||
#define HTTP_CLIENT_WEB_H
|
||||
|
||||
#include "core/io/http_client.h"
|
||||
|
||||
|
|
@ -59,7 +59,7 @@ extern int godot_js_fetch_is_chunked(int p_id);
|
|||
}
|
||||
#endif
|
||||
|
||||
class HTTPClientJavaScript : public HTTPClient {
|
||||
class HTTPClientWeb : public HTTPClient {
|
||||
private:
|
||||
int js_id = 0;
|
||||
Status status = STATUS_DISCONNECTED;
|
||||
|
|
@ -102,8 +102,8 @@ public:
|
|||
void set_read_chunk_size(int p_size) override;
|
||||
int get_read_chunk_size() const override;
|
||||
Error poll() override;
|
||||
HTTPClientJavaScript();
|
||||
~HTTPClientJavaScript();
|
||||
HTTPClientWeb();
|
||||
~HTTPClientWeb();
|
||||
};
|
||||
|
||||
#endif // HTTP_CLIENT_JAVASCRIPT_H
|
||||
#endif // HTTP_CLIENT_WEB_H
|
||||
|
|
@ -31,7 +31,7 @@
|
|||
#include "api/javascript_singleton.h"
|
||||
|
||||
#include "emscripten.h"
|
||||
#include "os_javascript.h"
|
||||
#include "os_web.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);
|
||||
|
|
@ -359,8 +359,8 @@ void JavaScript::download_buffer(Vector<uint8_t> p_arr, const String &p_name, co
|
|||
}
|
||||
|
||||
bool JavaScript::pwa_needs_update() const {
|
||||
return OS_JavaScript::get_singleton()->pwa_needs_update();
|
||||
return OS_Web::get_singleton()->pwa_needs_update();
|
||||
}
|
||||
Error JavaScript::pwa_update() {
|
||||
return OS_JavaScript::get_singleton()->pwa_update();
|
||||
return OS_Web::get_singleton()->pwa_update();
|
||||
}
|
||||
|
|
@ -6,7 +6,7 @@
|
|||
* of `Promises <https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Using_promises>`__.
|
||||
*
|
||||
* @module Engine
|
||||
* @header HTML5 shell class reference
|
||||
* @header Web export JavaScript reference
|
||||
*/
|
||||
const Engine = (function () {
|
||||
const preloader = new Preloader();
|
||||
|
|
@ -536,7 +536,7 @@ const GodotDisplay = {
|
|||
}
|
||||
navigator.clipboard.writeText(text).catch(function (e) {
|
||||
// Setting OS clipboard is only possible from an input callback.
|
||||
GodotRuntime.error('Setting OS clipboard is only possible from an input callback for the HTML5 plafrom. Exception:', e);
|
||||
GodotRuntime.error('Setting OS clipboard is only possible from an input callback for the Web plafrom. Exception:', e);
|
||||
});
|
||||
return 0;
|
||||
},
|
||||
|
Before Width: | Height: | Size: 1.2 KiB After Width: | Height: | Size: 1.2 KiB |
|
|
@ -1,5 +1,5 @@
|
|||
/*************************************************************************/
|
||||
/* os_javascript.cpp */
|
||||
/* os_web.cpp */
|
||||
/*************************************************************************/
|
||||
/* This file is part of: */
|
||||
/* GODOT ENGINE */
|
||||
|
|
@ -28,13 +28,13 @@
|
|||
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
||||
/*************************************************************************/
|
||||
|
||||
#include "os_javascript.h"
|
||||
#include "os_web.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/javascript/display_server_javascript.h"
|
||||
#include "platform/web/display_server_web.h"
|
||||
|
||||
#include "modules/modules_enabled.gen.h" // For websocket.
|
||||
#ifdef MODULE_WEBSOCKET_ENABLED
|
||||
|
|
@ -48,14 +48,14 @@
|
|||
#include "api/javascript_singleton.h"
|
||||
#include "godot_js.h"
|
||||
|
||||
void OS_JavaScript::alert(const String &p_alert, const String &p_title) {
|
||||
void OS_Web::alert(const String &p_alert, const String &p_title) {
|
||||
godot_js_display_alert(p_alert.utf8().get_data());
|
||||
}
|
||||
|
||||
// Lifecycle
|
||||
void OS_JavaScript::initialize() {
|
||||
void OS_Web::initialize() {
|
||||
OS_Unix::initialize_core();
|
||||
DisplayServerJavaScript::register_javascript_driver();
|
||||
DisplayServerWeb::register_web_driver();
|
||||
|
||||
#ifdef MODULE_WEBSOCKET_ENABLED
|
||||
EngineDebugger::register_uri_handler("ws://", RemoteDebuggerPeerWebSocket::create);
|
||||
|
|
@ -63,23 +63,23 @@ void OS_JavaScript::initialize() {
|
|||
#endif
|
||||
}
|
||||
|
||||
void OS_JavaScript::resume_audio() {
|
||||
AudioDriverJavaScript::resume();
|
||||
void OS_Web::resume_audio() {
|
||||
AudioDriverWeb::resume();
|
||||
}
|
||||
|
||||
void OS_JavaScript::set_main_loop(MainLoop *p_main_loop) {
|
||||
void OS_Web::set_main_loop(MainLoop *p_main_loop) {
|
||||
main_loop = p_main_loop;
|
||||
}
|
||||
|
||||
MainLoop *OS_JavaScript::get_main_loop() const {
|
||||
MainLoop *OS_Web::get_main_loop() const {
|
||||
return main_loop;
|
||||
}
|
||||
|
||||
void OS_JavaScript::fs_sync_callback() {
|
||||
void OS_Web::fs_sync_callback() {
|
||||
get_singleton()->idb_is_syncing = false;
|
||||
}
|
||||
|
||||
bool OS_JavaScript::main_loop_iterate() {
|
||||
bool OS_Web::main_loop_iterate() {
|
||||
if (is_userfs_persistent() && idb_needs_sync && !idb_is_syncing) {
|
||||
idb_is_syncing = true;
|
||||
idb_needs_sync = false;
|
||||
|
|
@ -91,16 +91,16 @@ bool OS_JavaScript::main_loop_iterate() {
|
|||
return Main::iteration();
|
||||
}
|
||||
|
||||
void OS_JavaScript::delete_main_loop() {
|
||||
void OS_Web::delete_main_loop() {
|
||||
if (main_loop) {
|
||||
memdelete(main_loop);
|
||||
}
|
||||
main_loop = nullptr;
|
||||
}
|
||||
|
||||
void OS_JavaScript::finalize() {
|
||||
void OS_Web::finalize() {
|
||||
delete_main_loop();
|
||||
for (AudioDriverJavaScript *driver : audio_drivers) {
|
||||
for (AudioDriverWeb *driver : audio_drivers) {
|
||||
memdelete(driver);
|
||||
}
|
||||
audio_drivers.clear();
|
||||
|
|
@ -108,44 +108,44 @@ void OS_JavaScript::finalize() {
|
|||
|
||||
// Miscellaneous
|
||||
|
||||
Error OS_JavaScript::execute(const String &p_path, const List<String> &p_arguments, String *r_pipe, int *r_exitcode, bool read_stderr, Mutex *p_pipe_mutex, bool p_open_console) {
|
||||
Error OS_Web::execute(const String &p_path, const List<String> &p_arguments, String *r_pipe, int *r_exitcode, bool read_stderr, Mutex *p_pipe_mutex, bool p_open_console) {
|
||||
return create_process(p_path, p_arguments);
|
||||
}
|
||||
|
||||
Error OS_JavaScript::create_process(const String &p_path, const List<String> &p_arguments, ProcessID *r_child_id, bool p_open_console) {
|
||||
Error OS_Web::create_process(const String &p_path, const List<String> &p_arguments, ProcessID *r_child_id, bool p_open_console) {
|
||||
Array args;
|
||||
for (const String &E : p_arguments) {
|
||||
args.push_back(E);
|
||||
}
|
||||
String json_args = Variant(args).to_json_string();
|
||||
int failed = godot_js_os_execute(json_args.utf8().get_data());
|
||||
ERR_FAIL_COND_V_MSG(failed, ERR_UNAVAILABLE, "OS::execute() or create_process() must be implemented in JavaScript via 'engine.setOnExecute' if required.");
|
||||
ERR_FAIL_COND_V_MSG(failed, ERR_UNAVAILABLE, "OS::execute() or create_process() must be implemented in Web via 'engine.setOnExecute' if required.");
|
||||
return OK;
|
||||
}
|
||||
|
||||
Error OS_JavaScript::kill(const ProcessID &p_pid) {
|
||||
ERR_FAIL_V_MSG(ERR_UNAVAILABLE, "OS::kill() is not available on the HTML5 platform.");
|
||||
Error OS_Web::kill(const ProcessID &p_pid) {
|
||||
ERR_FAIL_V_MSG(ERR_UNAVAILABLE, "OS::kill() is not available on the Web platform.");
|
||||
}
|
||||
|
||||
int OS_JavaScript::get_process_id() const {
|
||||
ERR_FAIL_V_MSG(0, "OS::get_process_id() is not available on the HTML5 platform.");
|
||||
int OS_Web::get_process_id() const {
|
||||
ERR_FAIL_V_MSG(0, "OS::get_process_id() is not available on the Web platform.");
|
||||
}
|
||||
|
||||
bool OS_JavaScript::is_process_running(const ProcessID &p_pid) const {
|
||||
bool OS_Web::is_process_running(const ProcessID &p_pid) const {
|
||||
return false;
|
||||
}
|
||||
|
||||
int OS_JavaScript::get_processor_count() const {
|
||||
int OS_Web::get_processor_count() const {
|
||||
return godot_js_os_hw_concurrency_get();
|
||||
}
|
||||
|
||||
bool OS_JavaScript::_check_internal_feature_support(const String &p_feature) {
|
||||
bool OS_Web::_check_internal_feature_support(const String &p_feature) {
|
||||
if (p_feature == "html5" || p_feature == "web") {
|
||||
return true;
|
||||
}
|
||||
|
||||
#ifdef JAVASCRIPT_EVAL_ENABLED
|
||||
if (p_feature == "javascript") {
|
||||
if (p_feature == "web") {
|
||||
return true;
|
||||
}
|
||||
#endif
|
||||
|
|
@ -163,42 +163,42 @@ bool OS_JavaScript::_check_internal_feature_support(const String &p_feature) {
|
|||
return false;
|
||||
}
|
||||
|
||||
String OS_JavaScript::get_executable_path() const {
|
||||
String OS_Web::get_executable_path() const {
|
||||
return OS::get_executable_path();
|
||||
}
|
||||
|
||||
Error OS_JavaScript::shell_open(String p_uri) {
|
||||
Error OS_Web::shell_open(String p_uri) {
|
||||
// Open URI in a new tab, browser will deal with it by protocol.
|
||||
godot_js_os_shell_open(p_uri.utf8().get_data());
|
||||
return OK;
|
||||
}
|
||||
|
||||
String OS_JavaScript::get_name() const {
|
||||
return "HTML5";
|
||||
String OS_Web::get_name() const {
|
||||
return "Web";
|
||||
}
|
||||
|
||||
void OS_JavaScript::vibrate_handheld(int p_duration_ms) {
|
||||
void OS_Web::vibrate_handheld(int p_duration_ms) {
|
||||
godot_js_input_vibrate_handheld(p_duration_ms);
|
||||
}
|
||||
|
||||
String OS_JavaScript::get_user_data_dir() const {
|
||||
String OS_Web::get_user_data_dir() const {
|
||||
return "/userfs";
|
||||
}
|
||||
|
||||
String OS_JavaScript::get_cache_path() const {
|
||||
String OS_Web::get_cache_path() const {
|
||||
return "/home/web_user/.cache";
|
||||
}
|
||||
|
||||
String OS_JavaScript::get_config_path() const {
|
||||
String OS_Web::get_config_path() const {
|
||||
return "/home/web_user/.config";
|
||||
}
|
||||
|
||||
String OS_JavaScript::get_data_path() const {
|
||||
String OS_Web::get_data_path() const {
|
||||
return "/home/web_user/.local/share";
|
||||
}
|
||||
|
||||
void OS_JavaScript::file_access_close_callback(const String &p_file, int p_flags) {
|
||||
OS_JavaScript *os = OS_JavaScript::get_singleton();
|
||||
void OS_Web::file_access_close_callback(const String &p_file, int p_flags) {
|
||||
OS_Web *os = OS_Web::get_singleton();
|
||||
if (!(os->is_userfs_persistent() && (p_flags & FileAccess::WRITE))) {
|
||||
return; // FS persistence is not working or we are not writing.
|
||||
}
|
||||
|
|
@ -212,24 +212,24 @@ void OS_JavaScript::file_access_close_callback(const String &p_file, int p_flags
|
|||
}
|
||||
}
|
||||
|
||||
void OS_JavaScript::update_pwa_state_callback() {
|
||||
if (OS_JavaScript::get_singleton()) {
|
||||
OS_JavaScript::get_singleton()->pwa_is_waiting = true;
|
||||
void OS_Web::update_pwa_state_callback() {
|
||||
if (OS_Web::get_singleton()) {
|
||||
OS_Web::get_singleton()->pwa_is_waiting = true;
|
||||
}
|
||||
if (JavaScript::get_singleton()) {
|
||||
JavaScript::get_singleton()->emit_signal("pwa_update_available");
|
||||
}
|
||||
}
|
||||
|
||||
Error OS_JavaScript::pwa_update() {
|
||||
Error OS_Web::pwa_update() {
|
||||
return godot_js_pwa_update() ? FAILED : OK;
|
||||
}
|
||||
|
||||
bool OS_JavaScript::is_userfs_persistent() const {
|
||||
bool OS_Web::is_userfs_persistent() const {
|
||||
return idb_available;
|
||||
}
|
||||
|
||||
Error OS_JavaScript::open_dynamic_library(const String p_path, void *&p_library_handle, bool p_also_set_library_path, String *r_resolved_path) {
|
||||
Error OS_Web::open_dynamic_library(const String p_path, void *&p_library_handle, bool p_also_set_library_path, String *r_resolved_path) {
|
||||
String path = p_path.get_file();
|
||||
p_library_handle = dlopen(path.utf8().get_data(), RTLD_NOW);
|
||||
ERR_FAIL_COND_V_MSG(!p_library_handle, ERR_CANT_OPEN, "Can't open dynamic library: " + p_path + ". Error: " + dlerror());
|
||||
|
|
@ -241,21 +241,21 @@ Error OS_JavaScript::open_dynamic_library(const String p_path, void *&p_library_
|
|||
return OK;
|
||||
}
|
||||
|
||||
OS_JavaScript *OS_JavaScript::get_singleton() {
|
||||
return static_cast<OS_JavaScript *>(OS::get_singleton());
|
||||
OS_Web *OS_Web::get_singleton() {
|
||||
return static_cast<OS_Web *>(OS::get_singleton());
|
||||
}
|
||||
|
||||
void OS_JavaScript::initialize_joypads() {
|
||||
void OS_Web::initialize_joypads() {
|
||||
}
|
||||
|
||||
OS_JavaScript::OS_JavaScript() {
|
||||
OS_Web::OS_Web() {
|
||||
char locale_ptr[16];
|
||||
godot_js_config_locale_get(locale_ptr, 16);
|
||||
setenv("LANG", locale_ptr, true);
|
||||
|
||||
godot_js_pwa_cb(&OS_JavaScript::update_pwa_state_callback);
|
||||
godot_js_pwa_cb(&OS_Web::update_pwa_state_callback);
|
||||
|
||||
if (AudioDriverJavaScript::is_available()) {
|
||||
if (AudioDriverWeb::is_available()) {
|
||||
#ifdef NO_THREADS
|
||||
audio_drivers.push_back(memnew(AudioDriverScriptProcessor));
|
||||
#endif
|
||||
|
|
@ -1,5 +1,5 @@
|
|||
/*************************************************************************/
|
||||
/* os_javascript.h */
|
||||
/* os_web.h */
|
||||
/*************************************************************************/
|
||||
/* This file is part of: */
|
||||
/* GODOT ENGINE */
|
||||
|
|
@ -28,19 +28,19 @@
|
|||
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
||||
/*************************************************************************/
|
||||
|
||||
#ifndef OS_JAVASCRIPT_H
|
||||
#define OS_JAVASCRIPT_H
|
||||
#ifndef OS_WEB_H
|
||||
#define OS_WEB_H
|
||||
|
||||
#include "audio_driver_javascript.h"
|
||||
#include "audio_driver_web.h"
|
||||
#include "core/input/input.h"
|
||||
#include "drivers/unix/os_unix.h"
|
||||
#include "servers/audio_server.h"
|
||||
|
||||
#include <emscripten/html5.h>
|
||||
|
||||
class OS_JavaScript : public OS_Unix {
|
||||
class OS_Web : public OS_Unix {
|
||||
MainLoop *main_loop = nullptr;
|
||||
List<AudioDriverJavaScript *> audio_drivers;
|
||||
List<AudioDriverWeb *> audio_drivers;
|
||||
|
||||
bool idb_is_syncing = false;
|
||||
bool idb_available = false;
|
||||
|
|
@ -65,7 +65,7 @@ protected:
|
|||
|
||||
public:
|
||||
// Override return type to make writing static callbacks less tedious.
|
||||
static OS_JavaScript *get_singleton();
|
||||
static OS_Web *get_singleton();
|
||||
|
||||
bool pwa_needs_update() const { return pwa_is_waiting; }
|
||||
Error pwa_update();
|
||||
|
|
@ -87,7 +87,7 @@ public:
|
|||
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 javascript_main.cpp loop callback instead.
|
||||
// Implemented in web_main.cpp loop callback instead.
|
||||
void add_frame_delay(bool p_can_draw) override {}
|
||||
|
||||
void vibrate_handheld(int p_duration_ms) override;
|
||||
|
|
@ -105,7 +105,7 @@ public:
|
|||
|
||||
void resume_audio();
|
||||
|
||||
OS_JavaScript();
|
||||
OS_Web();
|
||||
};
|
||||
|
||||
#endif // OS_JAVASCRIPT_H
|
||||
#endif // OS_WEB_H
|
||||
|
|
@ -2,7 +2,7 @@
|
|||
"name": "godot",
|
||||
"private": true,
|
||||
"version": "1.0.0",
|
||||
"description": "Development and linting setup for Godot's HTML5 platform code",
|
||||
"description": "Development and linting setup for Godot's Web platform code",
|
||||
"scripts": {
|
||||
"docs": "jsdoc --template js/jsdoc2rst/ js/engine/engine.js js/engine/config.js --destination ''",
|
||||
"lint": "npm run lint:engine && npm run lint:libs && npm run lint:modules && npm run lint:tools",
|
||||
|
|
@ -30,4 +30,4 @@
|
|||
|
||||
#include <alloca.h>
|
||||
|
||||
#define OPENGL_INCLUDE_H "platform/javascript/godot_webgl2.h"
|
||||
#define OPENGL_INCLUDE_H "platform/web/godot_webgl2.h"
|
||||
|
Before Width: | Height: | Size: 290 B After Width: | Height: | Size: 290 B |
|
|
@ -1,5 +1,5 @@
|
|||
/*************************************************************************/
|
||||
/* javascript_main.cpp */
|
||||
/* web_main.cpp */
|
||||
/*************************************************************************/
|
||||
/* This file is part of: */
|
||||
/* GODOT ENGINE */
|
||||
|
|
@ -31,21 +31,21 @@
|
|||
#include "core/config/engine.h"
|
||||
#include "core/io/resource_loader.h"
|
||||
#include "main/main.h"
|
||||
#include "platform/javascript/display_server_javascript.h"
|
||||
#include "platform/javascript/os_javascript.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_JavaScript *os = nullptr;
|
||||
static OS_Web *os = nullptr;
|
||||
static uint64_t target_ticks = 0;
|
||||
|
||||
void exit_callback() {
|
||||
emscripten_cancel_main_loop(); // After this, we can exit!
|
||||
Main::cleanup();
|
||||
int exit_code = OS_JavaScript::get_singleton()->get_exit_code();
|
||||
int exit_code = OS_Web::get_singleton()->get_exit_code();
|
||||
memdelete(os);
|
||||
os = nullptr;
|
||||
emscripten_force_exit(exit_code); // No matter that we call cancel_main_loop, regular "exit" will not work, forcing.
|
||||
|
|
@ -58,7 +58,7 @@ void cleanup_after_sync() {
|
|||
void main_loop_callback() {
|
||||
uint64_t current_ticks = os->get_ticks_usec();
|
||||
|
||||
bool force_draw = DisplayServerJavaScript::get_singleton()->check_size_force_redraw();
|
||||
bool force_draw = DisplayServerWeb::get_singleton()->check_size_force_redraw();
|
||||
if (force_draw) {
|
||||
Main::force_redraw();
|
||||
} else if (current_ticks < target_ticks) {
|
||||
|
|
@ -81,8 +81,8 @@ void main_loop_callback() {
|
|||
}
|
||||
|
||||
/// When calling main, it is assumed FS is setup and synced.
|
||||
extern EMSCRIPTEN_KEEPALIVE int godot_js_main(int argc, char *argv[]) {
|
||||
os = new OS_JavaScript();
|
||||
extern EMSCRIPTEN_KEEPALIVE int godot_web_main(int argc, char *argv[]) {
|
||||
os = new OS_Web();
|
||||
|
||||
// We must override main when testing is enabled
|
||||
TEST_MAIN_OVERRIDE
|
||||
|
|
@ -1,5 +1,5 @@
|
|||
/*************************************************************************/
|
||||
/* javascript_runtime.cpp */
|
||||
/* web_runtime.cpp */
|
||||
/*************************************************************************/
|
||||
/* This file is part of: */
|
||||
/* GODOT ENGINE */
|
||||
|
|
@ -28,8 +28,8 @@
|
|||
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
||||
/*************************************************************************/
|
||||
|
||||
extern int godot_js_main(int argc, char *argv[]);
|
||||
extern int godot_web_main(int argc, char *argv[]);
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
return godot_js_main(argc, argv);
|
||||
return godot_web_main(argc, argv);
|
||||
}
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
# Windows platform port
|
||||
|
||||
This folder contains the C++ and JavaScript code for the Windows platform port.
|
||||
This folder contains the C++ code for the Windows platform port.
|
||||
|
||||
See also [`misc/dist/windows`](/misc/dist/windows) folder for additional files
|
||||
used by this platform.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue