summaryrefslogtreecommitdiff
path: root/platform/javascript/os_javascript.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'platform/javascript/os_javascript.cpp')
-rw-r--r--platform/javascript/os_javascript.cpp52
1 files changed, 33 insertions, 19 deletions
diff --git a/platform/javascript/os_javascript.cpp b/platform/javascript/os_javascript.cpp
index 8c976da58e..5da9a96a90 100644
--- a/platform/javascript/os_javascript.cpp
+++ b/platform/javascript/os_javascript.cpp
@@ -5,8 +5,8 @@
/* GODOT ENGINE */
/* https://godotengine.org */
/*************************************************************************/
-/* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */
-/* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md). */
+/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
@@ -31,13 +31,12 @@
#include "os_javascript.h"
#include "core/debugger/engine_debugger.h"
-#include "core/io/json.h"
#include "drivers/unix/dir_access_unix.h"
#include "drivers/unix/file_access_unix.h"
#include "main/main.h"
-#include "modules/modules_enabled.gen.h"
#include "platform/javascript/display_server_javascript.h"
+#include "modules/modules_enabled.gen.h" // For websocket.
#ifdef MODULE_WEBSOCKET_ENABLED
#include "modules/websocket/remote_debugger_peer_websocket.h"
#endif
@@ -48,6 +47,10 @@
#include "godot_js.h"
+void OS_JavaScript::alert(const String &p_alert, const String &p_title) {
+ godot_js_display_alert(p_alert.utf8().get_data());
+}
+
// Lifecycle
void OS_JavaScript::initialize() {
OS_Unix::initialize_core();
@@ -60,9 +63,7 @@ void OS_JavaScript::initialize() {
}
void OS_JavaScript::resume_audio() {
- if (audio_driver_javascript) {
- audio_driver_javascript->resume();
- }
+ AudioDriverJavaScript::resume();
}
void OS_JavaScript::set_main_loop(MainLoop *p_main_loop) {
@@ -98,22 +99,26 @@ void OS_JavaScript::delete_main_loop() {
void OS_JavaScript::finalize() {
delete_main_loop();
- if (audio_driver_javascript) {
- memdelete(audio_driver_javascript);
- audio_driver_javascript = nullptr;
+ for (AudioDriverJavaScript *driver : audio_drivers) {
+ memdelete(driver);
}
+ audio_drivers.clear();
}
// Miscellaneous
-Error OS_JavaScript::execute(const String &p_path, const List<String> &p_arguments, bool p_blocking, ProcessID *r_child_id, String *r_pipe, int *r_exitcode, bool read_stderr, Mutex *p_pipe_mutex) {
+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) {
+ 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) {
Array args;
- for (const List<String>::Element *E = p_arguments.front(); E; E = E->next()) {
- args.push_back(E->get());
+ for (const String &E : p_arguments) {
+ args.push_back(E);
}
- String json_args = JSON::print(args);
+ 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() 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 JavaScript via 'engine.setOnExecute' if required.");
return OK;
}
@@ -125,13 +130,17 @@ 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_JavaScript::get_processor_count() const {
+ return godot_js_os_hw_concurrency_get();
+}
+
bool OS_JavaScript::_check_internal_feature_support(const String &p_feature) {
- if (p_feature == "HTML5" || p_feature == "web") {
+ if (p_feature == "html5" || p_feature == "web") {
return true;
}
#ifdef JAVASCRIPT_EVAL_ENABLED
- if (p_feature == "JavaScript") {
+ if (p_feature == "javascript") {
return true;
}
#endif
@@ -218,8 +227,13 @@ OS_JavaScript::OS_JavaScript() {
setenv("LANG", locale_ptr, true);
if (AudioDriverJavaScript::is_available()) {
- audio_driver_javascript = memnew(AudioDriverJavaScript);
- AudioDriverManager::add_driver(audio_driver_javascript);
+#ifdef NO_THREADS
+ audio_drivers.push_back(memnew(AudioDriverScriptProcessor));
+#endif
+ audio_drivers.push_back(memnew(AudioDriverWorklet));
+ }
+ for (int i = 0; i < audio_drivers.size(); i++) {
+ AudioDriverManager::add_driver(audio_drivers[i]);
}
idb_available = godot_js_os_fs_is_persistent();