summaryrefslogtreecommitdiff
path: root/platform
diff options
context:
space:
mode:
Diffstat (limited to 'platform')
-rw-r--r--platform/iphone/tts_ios.h6
-rw-r--r--platform/javascript/api/javascript_tools_editor_plugin.cpp2
-rw-r--r--platform/javascript/detect.py2
-rw-r--r--platform/javascript/godot_webgl2.h37
-rw-r--r--platform/javascript/js/libs/library_godot_display.js1
-rw-r--r--platform/javascript/js/libs/library_godot_os.js4
-rw-r--r--platform/javascript/os_javascript.cpp4
-rw-r--r--platform/javascript/os_javascript.h1
-rw-r--r--platform/javascript/platform_config.h2
-rw-r--r--platform/linuxbsd/crash_handler_linuxbsd.cpp22
-rw-r--r--platform/linuxbsd/joypad_linux.cpp336
-rw-r--r--platform/linuxbsd/joypad_linux.h41
-rw-r--r--platform/osx/crash_handler_osx.mm22
-rw-r--r--platform/osx/dir_access_osx.mm4
-rw-r--r--platform/osx/display_server_osx.h9
-rw-r--r--platform/osx/display_server_osx.mm38
-rw-r--r--platform/osx/gl_manager_osx_legacy.h6
-rw-r--r--platform/osx/joypad_osx.h10
-rw-r--r--platform/osx/key_mapping_osx.mm4
-rw-r--r--platform/osx/tts_osx.h9
-rw-r--r--platform/osx/vulkan_context_osx.h2
-rw-r--r--platform/uwp/os_uwp.cpp4
-rw-r--r--platform/uwp/os_uwp.h1
-rw-r--r--platform/windows/crash_handler_windows.cpp44
-rw-r--r--platform/windows/display_server_windows.cpp12
-rw-r--r--platform/windows/display_server_windows.h1
-rw-r--r--platform/windows/export/export_plugin.cpp17
-rw-r--r--platform/windows/export/export_plugin.h1
-rw-r--r--platform/windows/os_windows.cpp81
-rw-r--r--platform/windows/os_windows.h1
30 files changed, 452 insertions, 272 deletions
diff --git a/platform/iphone/tts_ios.h b/platform/iphone/tts_ios.h
index c7defeb98f..3fac762b62 100644
--- a/platform/iphone/tts_ios.h
+++ b/platform/iphone/tts_ios.h
@@ -31,7 +31,11 @@
#ifndef TTS_IOS_H
#define TTS_IOS_H
-#include <AVFAudio/AVSpeechSynthesis.h>
+#if __has_include(<AVFAudio/AVSpeechSynthesis.h>)
+#import <AVFAudio/AVSpeechSynthesis.h>
+#else
+#import <AVFoundation/AVFoundation.h>
+#endif
#include "core/string/ustring.h"
#include "core/templates/list.h"
diff --git a/platform/javascript/api/javascript_tools_editor_plugin.cpp b/platform/javascript/api/javascript_tools_editor_plugin.cpp
index 31ce71127d..198af61eff 100644
--- a/platform/javascript/api/javascript_tools_editor_plugin.cpp
+++ b/platform/javascript/api/javascript_tools_editor_plugin.cpp
@@ -122,7 +122,7 @@ void JavaScriptToolsEditorPlugin::_zip_file(String p_path, String p_base_path, z
void JavaScriptToolsEditorPlugin::_zip_recursive(String p_path, String p_base_path, zipFile p_zip) {
Ref<DirAccess> dir = DirAccess::open(p_path);
- if (!dir) {
+ if (dir.is_null()) {
WARN_PRINT("Unable to open directory for zipping: " + p_path);
return;
}
diff --git a/platform/javascript/detect.py b/platform/javascript/detect.py
index b6be44fbb2..709104c5ee 100644
--- a/platform/javascript/detect.py
+++ b/platform/javascript/detect.py
@@ -212,6 +212,8 @@ def configure(env):
sys.exit(255)
env.Append(CCFLAGS=["-s", "RELOCATABLE=1"])
env.Append(LINKFLAGS=["-s", "RELOCATABLE=1"])
+ # Weak symbols are broken upstream: https://github.com/emscripten-core/emscripten/issues/12819
+ env.Append(CPPDEFINES=["ZSTD_HAVE_WEAK_SYMBOLS=0"])
env.extra_suffix = ".gdnative" + env.extra_suffix
# Reduce code size by generating less support code (e.g. skip NodeJS support).
diff --git a/platform/javascript/godot_webgl2.h b/platform/javascript/godot_webgl2.h
new file mode 100644
index 0000000000..7c357ff66d
--- /dev/null
+++ b/platform/javascript/godot_webgl2.h
@@ -0,0 +1,37 @@
+/*************************************************************************/
+/* godot_webgl2.h */
+/*************************************************************************/
+/* This file is part of: */
+/* GODOT ENGINE */
+/* https://godotengine.org */
+/*************************************************************************/
+/* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2014-2022 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 */
+/* "Software"), to deal in the Software without restriction, including */
+/* without limitation the rights to use, copy, modify, merge, publish, */
+/* distribute, sublicense, and/or sell copies of the Software, and to */
+/* permit persons to whom the Software is furnished to do so, subject to */
+/* the following conditions: */
+/* */
+/* The above copyright notice and this permission notice shall be */
+/* included in all copies or substantial portions of the Software. */
+/* */
+/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
+/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
+/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
+/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
+/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
+/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
+/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
+/*************************************************************************/
+
+#ifndef GODOT_WEBGL2_H
+#define GODOT_WEBGL2_H
+
+#include "GLES3/gl3.h"
+#include "webgl/webgl2.h"
+
+#endif
diff --git a/platform/javascript/js/libs/library_godot_display.js b/platform/javascript/js/libs/library_godot_display.js
index 54d48643db..5997631bf8 100644
--- a/platform/javascript/js/libs/library_godot_display.js
+++ b/platform/javascript/js/libs/library_godot_display.js
@@ -462,6 +462,7 @@ const GodotDisplay = {
GodotRuntime.setHeapValue(height, window.screen.height * scale, 'i32');
},
+ godot_js_display_window_size_get__sig: 'vii',
godot_js_display_window_size_get: function (p_width, p_height) {
GodotRuntime.setHeapValue(p_width, GodotConfig.canvas.width, 'i32');
GodotRuntime.setHeapValue(p_height, GodotConfig.canvas.height, 'i32');
diff --git a/platform/javascript/js/libs/library_godot_os.js b/platform/javascript/js/libs/library_godot_os.js
index 12d06a8d51..377eec3234 100644
--- a/platform/javascript/js/libs/library_godot_os.js
+++ b/platform/javascript/js/libs/library_godot_os.js
@@ -305,7 +305,9 @@ const GodotOS = {
godot_js_os_hw_concurrency_get__sig: 'i',
godot_js_os_hw_concurrency_get: function () {
- return navigator.hardwareConcurrency || 1;
+ // TODO Godot core needs fixing to avoid spawning too many threads (> 24).
+ const concurrency = navigator.hardwareConcurrency || 1;
+ return concurrency < 2 ? concurrency : 2;
},
godot_js_os_download_buffer__sig: 'viiii',
diff --git a/platform/javascript/os_javascript.cpp b/platform/javascript/os_javascript.cpp
index 79c2b2fefb..1686353229 100644
--- a/platform/javascript/os_javascript.cpp
+++ b/platform/javascript/os_javascript.cpp
@@ -131,6 +131,10 @@ int OS_JavaScript::get_process_id() const {
ERR_FAIL_V_MSG(0, "OS::get_process_id() is not available on the HTML5 platform.");
}
+bool OS_JavaScript::is_process_running(const ProcessID &p_pid) const {
+ return false;
+}
+
int OS_JavaScript::get_processor_count() const {
return godot_js_os_hw_concurrency_get();
}
diff --git a/platform/javascript/os_javascript.h b/platform/javascript/os_javascript.h
index 09497ebc5d..0c672111cc 100644
--- a/platform/javascript/os_javascript.h
+++ b/platform/javascript/os_javascript.h
@@ -79,6 +79,7 @@ public:
Error create_process(const String &p_path, const List<String> &p_arguments, ProcessID *r_child_id = nullptr, bool p_open_console = false) override;
Error kill(const ProcessID &p_pid) override;
int get_process_id() const override;
+ bool is_process_running(const ProcessID &p_pid) const override;
int get_processor_count() const override;
int get_default_thread_pool_size() const override { return 1; }
diff --git a/platform/javascript/platform_config.h b/platform/javascript/platform_config.h
index ba1b0d459e..1970fe0fa0 100644
--- a/platform/javascript/platform_config.h
+++ b/platform/javascript/platform_config.h
@@ -29,3 +29,5 @@
/*************************************************************************/
#include <alloca.h>
+
+#define OPENGL_INCLUDE_H "platform/javascript/godot_webgl2.h"
diff --git a/platform/linuxbsd/crash_handler_linuxbsd.cpp b/platform/linuxbsd/crash_handler_linuxbsd.cpp
index b4ec7924f6..33da094860 100644
--- a/platform/linuxbsd/crash_handler_linuxbsd.cpp
+++ b/platform/linuxbsd/crash_handler_linuxbsd.cpp
@@ -32,6 +32,7 @@
#include "core/config/project_settings.h"
#include "core/os/os.h"
+#include "core/string/print_string.h"
#include "core/version.h"
#include "main/main.h"
@@ -61,21 +62,22 @@ static void handle_crash(int sig) {
msg = proj_settings->get("debug/settings/crash_handler/message");
}
- // Dump the backtrace to stderr with a message to the user
- fprintf(stderr, "\n================================================================\n");
- fprintf(stderr, "%s: Program crashed with signal %d\n", __FUNCTION__, sig);
-
+ // Tell MainLoop about the crash. This can be handled by users too in Node.
if (OS::get_singleton()->get_main_loop()) {
OS::get_singleton()->get_main_loop()->notification(MainLoop::NOTIFICATION_CRASH);
}
+ // Dump the backtrace to stderr with a message to the user
+ print_error("\n================================================================");
+ print_error(vformat("%s: Program crashed with signal %d", __FUNCTION__, sig));
+
// Print the engine version just before, so that people are reminded to include the version in backtrace reports.
if (String(VERSION_HASH).is_empty()) {
- fprintf(stderr, "Engine version: %s\n", VERSION_FULL_NAME);
+ print_error(vformat("Engine version: %s", VERSION_FULL_NAME));
} else {
- fprintf(stderr, "Engine version: %s (%s)\n", VERSION_FULL_NAME, VERSION_HASH);
+ print_error(vformat("Engine version: %s (%s)", VERSION_FULL_NAME, VERSION_HASH));
}
- fprintf(stderr, "Dumping the backtrace. %s\n", msg.utf8().get_data());
+ print_error(vformat("Dumping the backtrace. %s", msg));
char **strings = backtrace_symbols(bt_buffer, size);
if (strings) {
for (size_t i = 1; i < size; i++) {
@@ -117,13 +119,13 @@ static void handle_crash(int sig) {
output = output.substr(0, output.length() - 1);
}
- fprintf(stderr, "[%ld] %s (%s)\n", (long int)i, fname, output.utf8().get_data());
+ print_error(vformat("[%d] %s (%s)", (int64_t)i, fname, output));
}
free(strings);
}
- fprintf(stderr, "-- END OF BACKTRACE --\n");
- fprintf(stderr, "================================================================\n");
+ print_error("-- END OF BACKTRACE --");
+ print_error("================================================================");
// Abort to pass the error to the OS
abort();
diff --git a/platform/linuxbsd/joypad_linux.cpp b/platform/linuxbsd/joypad_linux.cpp
index 22a9518a25..bc018e366b 100644
--- a/platform/linuxbsd/joypad_linux.cpp
+++ b/platform/linuxbsd/joypad_linux.cpp
@@ -65,6 +65,7 @@ void JoypadLinux::Joypad::reset() {
abs_map[i] = -1;
curr_axis[i] = 0;
}
+ events.clear();
}
JoypadLinux::JoypadLinux(Input *in) {
@@ -84,23 +85,26 @@ JoypadLinux::JoypadLinux(Input *in) {
print_verbose("JoypadLinux: udev disabled, parsing /dev/input to detect joypads.");
#endif
input = in;
- joy_thread.start(joy_thread_func, this);
+ monitor_joypads_thread.start(monitor_joypads_thread_func, this);
+ joypad_events_thread.start(joypad_events_thread_func, this);
}
JoypadLinux::~JoypadLinux() {
- exit_monitor.set();
- joy_thread.wait_to_finish();
- close_joypad();
+ monitor_joypads_exit.set();
+ joypad_events_exit.set();
+ monitor_joypads_thread.wait_to_finish();
+ joypad_events_thread.wait_to_finish();
+ close_joypads();
}
-void JoypadLinux::joy_thread_func(void *p_user) {
+void JoypadLinux::monitor_joypads_thread_func(void *p_user) {
if (p_user) {
JoypadLinux *joy = static_cast<JoypadLinux *>(p_user);
- joy->run_joypad_thread();
+ joy->monitor_joypads_thread_run();
}
}
-void JoypadLinux::run_joypad_thread() {
+void JoypadLinux::monitor_joypads_thread_run() {
#ifdef UDEV_ENABLED
if (use_udev) {
udev *_udev = udev_new();
@@ -140,7 +144,6 @@ void JoypadLinux::enumerate_joypads(udev *p_udev) {
if (devnode) {
String devnode_str = devnode;
if (devnode_str.find(ignore_str) == -1) {
- MutexLock lock(joy_mutex);
open_joypad(devnode);
}
}
@@ -156,7 +159,7 @@ void JoypadLinux::monitor_joypads(udev *p_udev) {
udev_monitor_enable_receiving(mon);
int fd = udev_monitor_get_fd(mon);
- while (!exit_monitor.is_set()) {
+ while (!monitor_joypads_exit.is_set()) {
fd_set fds;
struct timeval tv;
int ret;
@@ -175,7 +178,6 @@ void JoypadLinux::monitor_joypads(udev *p_udev) {
dev = udev_monitor_receive_device(mon);
if (dev && udev_device_get_devnode(dev) != nullptr) {
- MutexLock lock(joy_mutex);
String action = udev_device_get_action(dev);
const char *devnode = udev_device_get_devnode(dev);
if (devnode) {
@@ -184,11 +186,10 @@ void JoypadLinux::monitor_joypads(udev *p_udev) {
if (action == "add") {
open_joypad(devnode);
} else if (String(action) == "remove") {
- close_joypad(get_joy_from_path(devnode));
+ close_joypad(devnode);
}
}
}
-
udev_device_unref(dev);
}
}
@@ -199,59 +200,54 @@ void JoypadLinux::monitor_joypads(udev *p_udev) {
#endif
void JoypadLinux::monitor_joypads() {
- while (!exit_monitor.is_set()) {
- {
- MutexLock lock(joy_mutex);
-
- DIR *input_directory;
- input_directory = opendir("/dev/input");
- if (input_directory) {
- struct dirent *current;
- char fname[64];
-
- while ((current = readdir(input_directory)) != nullptr) {
- if (strncmp(current->d_name, "event", 5) != 0) {
- continue;
- }
- sprintf(fname, "/dev/input/%.*s", 16, current->d_name);
- if (attached_devices.find(fname) == -1) {
- open_joypad(fname);
- }
+ while (!monitor_joypads_exit.is_set()) {
+ DIR *input_directory;
+ input_directory = opendir("/dev/input");
+ if (input_directory) {
+ struct dirent *current;
+ char fname[64];
+
+ while ((current = readdir(input_directory)) != nullptr) {
+ if (strncmp(current->d_name, "event", 5) != 0) {
+ continue;
+ }
+ sprintf(fname, "/dev/input/%.*s", 16, current->d_name);
+ if (attached_devices.find(fname) == -1) {
+ open_joypad(fname);
}
}
- closedir(input_directory);
}
- usleep(1000000); // 1s
+ closedir(input_directory);
}
+ usleep(1000000); // 1s
}
-int JoypadLinux::get_joy_from_path(String p_path) const {
+void JoypadLinux::close_joypads() {
for (int i = 0; i < JOYPADS_MAX; i++) {
- if (joypads[i].devpath == p_path) {
- return i;
- }
+ MutexLock lock(joypads_mutex[i]);
+ Joypad &joypad = joypads[i];
+ close_joypad(joypad, i);
}
- return -2;
}
-void JoypadLinux::close_joypad(int p_id) {
- if (p_id == -1) {
- for (int i = 0; i < JOYPADS_MAX; i++) {
- close_joypad(i);
+void JoypadLinux::close_joypad(const char *p_devpath) {
+ for (int i = 0; i < JOYPADS_MAX; i++) {
+ MutexLock lock(joypads_mutex[i]);
+ Joypad &joypad = joypads[i];
+ if (joypads[i].devpath == p_devpath) {
+ close_joypad(joypad, i);
}
- return;
- } else if (p_id < 0) {
- return;
}
+}
- Joypad &joy = joypads[p_id];
-
- if (joy.fd != -1) {
- close(joy.fd);
- joy.fd = -1;
- attached_devices.remove_at(attached_devices.find(joy.devpath));
+void JoypadLinux::close_joypad(Joypad &p_joypad, int p_id) {
+ if (p_joypad.fd != -1) {
+ close(p_joypad.fd);
+ p_joypad.fd = -1;
+ attached_devices.erase(p_joypad.devpath);
input->joy_connection_changed(p_id, false, "");
}
+ p_joypad.events.clear();
}
static String _hex_str(uint8_t p_byte) {
@@ -265,27 +261,25 @@ static String _hex_str(uint8_t p_byte) {
return ret;
}
-void JoypadLinux::setup_joypad_properties(int p_id) {
- Joypad *joy = &joypads[p_id];
-
+void JoypadLinux::setup_joypad_properties(Joypad &p_joypad) {
unsigned long keybit[NBITS(KEY_MAX)] = { 0 };
unsigned long absbit[NBITS(ABS_MAX)] = { 0 };
int num_buttons = 0;
int num_axes = 0;
- if ((ioctl(joy->fd, EVIOCGBIT(EV_KEY, sizeof(keybit)), keybit) < 0) ||
- (ioctl(joy->fd, EVIOCGBIT(EV_ABS, sizeof(absbit)), absbit) < 0)) {
+ if ((ioctl(p_joypad.fd, EVIOCGBIT(EV_KEY, sizeof(keybit)), keybit) < 0) ||
+ (ioctl(p_joypad.fd, EVIOCGBIT(EV_ABS, sizeof(absbit)), absbit) < 0)) {
return;
}
for (int i = BTN_JOYSTICK; i < KEY_MAX; ++i) {
if (test_bit(i, keybit)) {
- joy->key_map[i] = num_buttons++;
+ p_joypad.key_map[i] = num_buttons++;
}
}
for (int i = BTN_MISC; i < BTN_JOYSTICK; ++i) {
if (test_bit(i, keybit)) {
- joy->key_map[i] = num_buttons++;
+ p_joypad.key_map[i] = num_buttons++;
}
}
for (int i = 0; i < ABS_MISC; ++i) {
@@ -295,21 +289,21 @@ void JoypadLinux::setup_joypad_properties(int p_id) {
continue;
}
if (test_bit(i, absbit)) {
- joy->abs_map[i] = num_axes++;
- joy->abs_info[i] = memnew(input_absinfo);
- if (ioctl(joy->fd, EVIOCGABS(i), joy->abs_info[i]) < 0) {
- memdelete(joy->abs_info[i]);
- joy->abs_info[i] = nullptr;
+ p_joypad.abs_map[i] = num_axes++;
+ p_joypad.abs_info[i] = memnew(input_absinfo);
+ if (ioctl(p_joypad.fd, EVIOCGABS(i), p_joypad.abs_info[i]) < 0) {
+ memdelete(p_joypad.abs_info[i]);
+ p_joypad.abs_info[i] = nullptr;
}
}
}
- joy->force_feedback = false;
- joy->ff_effect_timestamp = 0;
+ p_joypad.force_feedback = false;
+ p_joypad.ff_effect_timestamp = 0;
unsigned long ffbit[NBITS(FF_CNT)];
- if (ioctl(joy->fd, EVIOCGBIT(EV_FF, sizeof(ffbit)), ffbit) != -1) {
+ if (ioctl(p_joypad.fd, EVIOCGBIT(EV_FF, sizeof(ffbit)), ffbit) != -1) {
if (test_bit(FF_RUMBLE, ffbit)) {
- joy->force_feedback = true;
+ p_joypad.force_feedback = true;
}
}
}
@@ -353,12 +347,12 @@ void JoypadLinux::open_joypad(const char *p_path) {
return;
}
- joypads[joy_num].reset();
-
- Joypad &joy = joypads[joy_num];
- joy.fd = fd;
- joy.devpath = String(p_path);
- setup_joypad_properties(joy_num);
+ MutexLock lock(joypads_mutex[joy_num]);
+ Joypad &joypad = joypads[joy_num];
+ joypad.reset();
+ joypad.fd = fd;
+ joypad.devpath = String(p_path);
+ setup_joypad_properties(joypad);
sprintf(uid, "%04x%04x", BSWAP16(inpid.bustype), 0);
if (inpid.vendor && inpid.product && inpid.version) {
uint16_t vendor = BSWAP16(inpid.vendor);
@@ -379,13 +373,12 @@ void JoypadLinux::open_joypad(const char *p_path) {
}
}
-void JoypadLinux::joypad_vibration_start(int p_id, float p_weak_magnitude, float p_strong_magnitude, float p_duration, uint64_t p_timestamp) {
- Joypad &joy = joypads[p_id];
- if (!joy.force_feedback || joy.fd == -1 || p_weak_magnitude < 0.f || p_weak_magnitude > 1.f || p_strong_magnitude < 0.f || p_strong_magnitude > 1.f) {
+void JoypadLinux::joypad_vibration_start(Joypad &p_joypad, float p_weak_magnitude, float p_strong_magnitude, float p_duration, uint64_t p_timestamp) {
+ if (!p_joypad.force_feedback || p_joypad.fd == -1 || p_weak_magnitude < 0.f || p_weak_magnitude > 1.f || p_strong_magnitude < 0.f || p_strong_magnitude > 1.f) {
return;
}
- if (joy.ff_effect_id != -1) {
- joypad_vibration_stop(p_id, p_timestamp);
+ if (p_joypad.ff_effect_id != -1) {
+ joypad_vibration_stop(p_joypad, p_timestamp);
}
struct ff_effect effect;
@@ -396,7 +389,7 @@ void JoypadLinux::joypad_vibration_start(int p_id, float p_weak_magnitude, float
effect.replay.length = floor(p_duration * 1000);
effect.replay.delay = 0;
- if (ioctl(joy.fd, EVIOCSFF, &effect) < 0) {
+ if (ioctl(p_joypad.fd, EVIOCSFF, &effect) < 0) {
return;
}
@@ -404,26 +397,25 @@ void JoypadLinux::joypad_vibration_start(int p_id, float p_weak_magnitude, float
play.type = EV_FF;
play.code = effect.id;
play.value = 1;
- if (write(joy.fd, (const void *)&play, sizeof(play)) == -1) {
+ if (write(p_joypad.fd, (const void *)&play, sizeof(play)) == -1) {
print_verbose("Couldn't write to Joypad device.");
}
- joy.ff_effect_id = effect.id;
- joy.ff_effect_timestamp = p_timestamp;
+ p_joypad.ff_effect_id = effect.id;
+ p_joypad.ff_effect_timestamp = p_timestamp;
}
-void JoypadLinux::joypad_vibration_stop(int p_id, uint64_t p_timestamp) {
- Joypad &joy = joypads[p_id];
- if (!joy.force_feedback || joy.fd == -1 || joy.ff_effect_id == -1) {
+void JoypadLinux::joypad_vibration_stop(Joypad &p_joypad, uint64_t p_timestamp) {
+ if (!p_joypad.force_feedback || p_joypad.fd == -1 || p_joypad.ff_effect_id == -1) {
return;
}
- if (ioctl(joy.fd, EVIOCRMFF, joy.ff_effect_id) < 0) {
+ if (ioctl(p_joypad.fd, EVIOCRMFF, p_joypad.ff_effect_id) < 0) {
return;
}
- joy.ff_effect_id = -1;
- joy.ff_effect_timestamp = p_timestamp;
+ p_joypad.ff_effect_id = -1;
+ p_joypad.ff_effect_timestamp = p_timestamp;
}
float JoypadLinux::axis_correct(const input_absinfo *p_abs, int p_value) const {
@@ -433,104 +425,124 @@ float JoypadLinux::axis_correct(const input_absinfo *p_abs, int p_value) const {
return 2.0f * (p_value - min) / (max - min) - 1.0f;
}
-void JoypadLinux::process_joypads() {
- if (joy_mutex.try_lock() != OK) {
- return;
+void JoypadLinux::joypad_events_thread_func(void *p_user) {
+ if (p_user) {
+ JoypadLinux *joy = (JoypadLinux *)p_user;
+ joy->joypad_events_thread_run();
}
+}
+
+void JoypadLinux::joypad_events_thread_run() {
+ while (!joypad_events_exit.is_set()) {
+ bool no_events = true;
+ for (int i = 0; i < JOYPADS_MAX; i++) {
+ MutexLock lock(joypads_mutex[i]);
+ Joypad &joypad = joypads[i];
+ if (joypad.fd == -1) {
+ continue;
+ }
+ input_event event;
+ while (read(joypad.fd, &event, sizeof(event)) > 0) {
+ no_events = false;
+ JoypadEvent joypad_event;
+ joypad_event.type = event.type;
+ joypad_event.code = event.code;
+ joypad_event.value = event.value;
+ joypad.events.push_back(joypad_event);
+ }
+ if (errno != EAGAIN) {
+ close_joypad(joypad, i);
+ }
+ }
+ if (no_events) {
+ usleep(10000); // 10ms
+ }
+ }
+}
+
+void JoypadLinux::process_joypads() {
for (int i = 0; i < JOYPADS_MAX; i++) {
- if (joypads[i].fd == -1) {
+ MutexLock lock(joypads_mutex[i]);
+ Joypad &joypad = joypads[i];
+ if (joypad.fd == -1) {
continue;
}
+ for (uint32_t j = 0; j < joypad.events.size(); j++) {
+ const JoypadEvent &joypad_event = joypad.events[j];
+ // joypad_event may be tainted and out of MAX_KEY range, which will cause
+ // joypad.key_map[joypad_event.code] to crash
+ if (joypad_event.code >= MAX_KEY) {
+ return;
+ }
- input_event events[32];
- Joypad *joy = &joypads[i];
-
- int len;
-
- while ((len = read(joy->fd, events, (sizeof events))) > 0) {
- len /= sizeof(events[0]);
- for (int j = 0; j < len; j++) {
- input_event &ev = events[j];
-
- // ev may be tainted and out of MAX_KEY range, which will cause
- // joy->key_map[ev.code] to crash
- if (ev.code >= MAX_KEY) {
- return;
- }
-
- switch (ev.type) {
- case EV_KEY:
- input->joy_button(i, (JoyButton)joy->key_map[ev.code], ev.value);
- break;
-
- case EV_ABS:
-
- switch (ev.code) {
- case ABS_HAT0X:
- if (ev.value != 0) {
- if (ev.value < 0) {
- joy->dpad = (HatMask)((joy->dpad | HatMask::LEFT) & ~HatMask::RIGHT);
- } else {
- joy->dpad = (HatMask)((joy->dpad | HatMask::RIGHT) & ~HatMask::LEFT);
- }
+ switch (joypad_event.type) {
+ case EV_KEY:
+ input->joy_button(i, (JoyButton)joypad.key_map[joypad_event.code], joypad_event.value);
+ break;
+
+ case EV_ABS:
+ switch (joypad_event.code) {
+ case ABS_HAT0X:
+ if (joypad_event.value != 0) {
+ if (joypad_event.value < 0) {
+ joypad.dpad = (HatMask)((joypad.dpad | HatMask::LEFT) & ~HatMask::RIGHT);
} else {
- joy->dpad &= ~(HatMask::LEFT | HatMask::RIGHT);
+ joypad.dpad = (HatMask)((joypad.dpad | HatMask::RIGHT) & ~HatMask::LEFT);
}
-
- input->joy_hat(i, (HatMask)joy->dpad);
- break;
-
- case ABS_HAT0Y:
- if (ev.value != 0) {
- if (ev.value < 0) {
- joy->dpad = (HatMask)((joy->dpad | HatMask::UP) & ~HatMask::DOWN);
- } else {
- joy->dpad = (HatMask)((joy->dpad | HatMask::DOWN) & ~HatMask::UP);
- }
+ } else {
+ joypad.dpad &= ~(HatMask::LEFT | HatMask::RIGHT);
+ }
+ input->joy_hat(i, (HatMask)joypad.dpad);
+ break;
+
+ case ABS_HAT0Y:
+ if (joypad_event.value != 0) {
+ if (joypad_event.value < 0) {
+ joypad.dpad = (HatMask)((joypad.dpad | HatMask::UP) & ~HatMask::DOWN);
} else {
- joy->dpad &= ~(HatMask::UP | HatMask::DOWN);
+ joypad.dpad = (HatMask)((joypad.dpad | HatMask::DOWN) & ~HatMask::UP);
}
-
- input->joy_hat(i, (HatMask)joy->dpad);
- break;
-
- default:
- if (ev.code >= MAX_ABS) {
- return;
- }
- if (joy->abs_map[ev.code] != -1 && joy->abs_info[ev.code]) {
- float value = axis_correct(joy->abs_info[ev.code], ev.value);
- joy->curr_axis[joy->abs_map[ev.code]] = value;
- }
- break;
- }
- break;
- }
+ } else {
+ joypad.dpad &= ~(HatMask::UP | HatMask::DOWN);
+ }
+ input->joy_hat(i, (HatMask)joypad.dpad);
+ break;
+
+ default:
+ if (joypad_event.code >= MAX_ABS) {
+ return;
+ }
+ if (joypad.abs_map[joypad_event.code] != -1 && joypad.abs_info[joypad_event.code]) {
+ float value = axis_correct(joypad.abs_info[joypad_event.code], joypad_event.value);
+ joypad.curr_axis[joypad.abs_map[joypad_event.code]] = value;
+ }
+ break;
+ }
+ break;
}
}
+ joypad.events.clear();
+
for (int j = 0; j < MAX_ABS; j++) {
- int index = joy->abs_map[j];
+ int index = joypad.abs_map[j];
if (index != -1) {
- input->joy_axis(i, (JoyAxis)index, joy->curr_axis[index]);
+ input->joy_axis(i, (JoyAxis)index, joypad.curr_axis[index]);
}
}
- if (len == 0 || (len < 0 && errno != EAGAIN)) {
- close_joypad(i);
- }
- if (joy->force_feedback) {
+ if (joypad.force_feedback) {
uint64_t timestamp = input->get_joy_vibration_timestamp(i);
- if (timestamp > joy->ff_effect_timestamp) {
+ if (timestamp > joypad.ff_effect_timestamp) {
Vector2 strength = input->get_joy_vibration_strength(i);
float duration = input->get_joy_vibration_duration(i);
if (strength.x == 0 && strength.y == 0) {
- joypad_vibration_stop(i, timestamp);
+ joypad_vibration_stop(joypad, timestamp);
} else {
- joypad_vibration_start(i, strength.x, strength.y, duration, timestamp);
+ joypad_vibration_start(joypad, strength.x, strength.y, duration, timestamp);
}
}
}
}
- joy_mutex.unlock();
}
-#endif
+
+#endif // JOYDEV_ENABLED
diff --git a/platform/linuxbsd/joypad_linux.h b/platform/linuxbsd/joypad_linux.h
index 9177465547..4afc261ce7 100644
--- a/platform/linuxbsd/joypad_linux.h
+++ b/platform/linuxbsd/joypad_linux.h
@@ -35,6 +35,7 @@
#include "core/input/input.h"
#include "core/os/mutex.h"
#include "core/os/thread.h"
+#include "core/templates/local_vector.h"
struct input_absinfo;
@@ -51,6 +52,12 @@ private:
MAX_KEY = 767, // Hack because <linux/input.h> can't be included here
};
+ struct JoypadEvent {
+ uint16_t type;
+ uint16_t code;
+ int32_t value;
+ };
+
struct Joypad {
float curr_axis[MAX_ABS];
int key_map[MAX_KEY];
@@ -65,6 +72,8 @@ private:
int ff_effect_id = 0;
uint64_t ff_effect_timestamp = 0;
+ LocalVector<JoypadEvent> events;
+
~Joypad();
void reset();
};
@@ -72,29 +81,39 @@ private:
#ifdef UDEV_ENABLED
bool use_udev = false;
#endif
- SafeFlag exit_monitor;
- Mutex joy_mutex;
- Thread joy_thread;
Input *input = nullptr;
+
+ SafeFlag monitor_joypads_exit;
+ SafeFlag joypad_events_exit;
+ Thread monitor_joypads_thread;
+ Thread joypad_events_thread;
+
Joypad joypads[JOYPADS_MAX];
+ Mutex joypads_mutex[JOYPADS_MAX];
+
Vector<String> attached_devices;
- static void joy_thread_func(void *p_user);
+ static void monitor_joypads_thread_func(void *p_user);
+ void monitor_joypads_thread_run();
+
+ void open_joypad(const char *p_path);
+ void setup_joypad_properties(Joypad &p_joypad);
- int get_joy_from_path(String p_path) const;
+ void close_joypads();
+ void close_joypad(const char *p_devpath);
+ void close_joypad(Joypad &p_joypad, int p_id);
- void setup_joypad_properties(int p_id);
- void close_joypad(int p_id = -1);
#ifdef UDEV_ENABLED
void enumerate_joypads(struct udev *p_udev);
void monitor_joypads(struct udev *p_udev);
#endif
void monitor_joypads();
- void run_joypad_thread();
- void open_joypad(const char *p_path);
- void joypad_vibration_start(int p_id, float p_weak_magnitude, float p_strong_magnitude, float p_duration, uint64_t p_timestamp);
- void joypad_vibration_stop(int p_id, uint64_t p_timestamp);
+ void joypad_vibration_start(Joypad &p_joypad, float p_weak_magnitude, float p_strong_magnitude, float p_duration, uint64_t p_timestamp);
+ void joypad_vibration_stop(Joypad &p_joypad, uint64_t p_timestamp);
+
+ static void joypad_events_thread_func(void *p_user);
+ void joypad_events_thread_run();
float axis_correct(const input_absinfo *p_abs, int p_value) const;
};
diff --git a/platform/osx/crash_handler_osx.mm b/platform/osx/crash_handler_osx.mm
index 06ed91907c..a798ba3b46 100644
--- a/platform/osx/crash_handler_osx.mm
+++ b/platform/osx/crash_handler_osx.mm
@@ -32,6 +32,7 @@
#include "core/config/project_settings.h"
#include "core/os/os.h"
+#include "core/string/print_string.h"
#include "core/version.h"
#include "main/main.h"
@@ -85,21 +86,22 @@ static void handle_crash(int sig) {
msg = proj_settings->get("debug/settings/crash_handler/message");
}
- // Dump the backtrace to stderr with a message to the user
- fprintf(stderr, "\n================================================================\n");
- fprintf(stderr, "%s: Program crashed with signal %d\n", __FUNCTION__, sig);
-
+ // Tell MainLoop about the crash. This can be handled by users too in Node.
if (OS::get_singleton()->get_main_loop()) {
OS::get_singleton()->get_main_loop()->notification(MainLoop::NOTIFICATION_CRASH);
}
+ // Dump the backtrace to stderr with a message to the user
+ print_error("\n================================================================");
+ print_error(vformat("%s: Program crashed with signal %d", __FUNCTION__, sig));
+
// Print the engine version just before, so that people are reminded to include the version in backtrace reports.
if (String(VERSION_HASH).is_empty()) {
- fprintf(stderr, "Engine version: %s\n", VERSION_FULL_NAME);
+ print_error(vformat("Engine version: %s", VERSION_FULL_NAME));
} else {
- fprintf(stderr, "Engine version: %s (%s)\n", VERSION_FULL_NAME, VERSION_HASH);
+ print_error(vformat("Engine version: %s (%s)", VERSION_FULL_NAME, VERSION_HASH));
}
- fprintf(stderr, "Dumping the backtrace. %s\n", msg.utf8().get_data());
+ print_error(vformat("Dumping the backtrace. %s", msg));
char **strings = backtrace_symbols(bt_buffer, size);
if (strings) {
void *load_addr = (void *)load_address();
@@ -157,13 +159,13 @@ static void handle_crash(int sig) {
}
}
- fprintf(stderr, "[%zu] %s\n", i, output.utf8().get_data());
+ print_error(vformat("[%d] %s", (int64_t)i, output));
}
free(strings);
}
- fprintf(stderr, "-- END OF BACKTRACE --\n");
- fprintf(stderr, "================================================================\n");
+ print_error("-- END OF BACKTRACE --");
+ print_error("================================================================");
// Abort to pass the error to the OS
abort();
diff --git a/platform/osx/dir_access_osx.mm b/platform/osx/dir_access_osx.mm
index d26f35e847..6bafb9470d 100644
--- a/platform/osx/dir_access_osx.mm
+++ b/platform/osx/dir_access_osx.mm
@@ -34,8 +34,8 @@
#include <errno.h>
-#include <AppKit/NSWorkspace.h>
-#include <Foundation/Foundation.h>
+#import <AppKit/NSWorkspace.h>
+#import <Foundation/Foundation.h>
String DirAccessOSX::fix_unicode_name(const char *p_name) const {
String fname;
diff --git a/platform/osx/display_server_osx.h b/platform/osx/display_server_osx.h
index e1e5aea715..538a9bc04c 100644
--- a/platform/osx/display_server_osx.h
+++ b/platform/osx/display_server_osx.h
@@ -45,10 +45,11 @@
#include "platform/osx/vulkan_context_osx.h"
#endif // VULKAN_ENABLED
-#include <AppKit/AppKit.h>
-#include <AppKit/NSCursor.h>
-#include <ApplicationServices/ApplicationServices.h>
-#include <CoreVideo/CoreVideo.h>
+#import <AppKit/AppKit.h>
+#import <AppKit/NSCursor.h>
+#import <ApplicationServices/ApplicationServices.h>
+#import <CoreVideo/CoreVideo.h>
+#import <Foundation/Foundation.h>
#undef BitMap
#undef CursorShape
diff --git a/platform/osx/display_server_osx.mm b/platform/osx/display_server_osx.mm
index 548acba923..a16bd2e8de 100644
--- a/platform/osx/display_server_osx.mm
+++ b/platform/osx/display_server_osx.mm
@@ -45,12 +45,12 @@
#include "main/main.h"
#include "scene/resources/texture.h"
-#include <Carbon/Carbon.h>
-#include <Cocoa/Cocoa.h>
-#include <IOKit/IOCFPlugIn.h>
-#include <IOKit/IOKitLib.h>
-#include <IOKit/hid/IOHIDKeys.h>
-#include <IOKit/hid/IOHIDLib.h>
+#import <Carbon/Carbon.h>
+#import <Cocoa/Cocoa.h>
+#import <IOKit/IOCFPlugIn.h>
+#import <IOKit/IOKitLib.h>
+#import <IOKit/hid/IOHIDKeys.h>
+#import <IOKit/hid/IOHIDLib.h>
#if defined(GLES3_ENABLED)
#include "drivers/gles3/rasterizer_gles3.h"
@@ -146,7 +146,7 @@ DisplayServerOSX::WindowID DisplayServerOSX::_create_window(WindowMode p_mode, V
[wd.window_object setTabbingMode:NSWindowTabbingModeDisallowed];
}
- CALayer *layer = [wd.window_view layer];
+ CALayer *layer = [(NSView *)wd.window_view layer];
if (layer) {
layer.contentsScale = scale;
}
@@ -174,7 +174,7 @@ DisplayServerOSX::WindowID DisplayServerOSX::_create_window(WindowMode p_mode, V
wd.size.width = contentRect.size.width * scale;
wd.size.height = contentRect.size.height * scale;
- CALayer *layer = [wd.window_view layer];
+ CALayer *layer = [(NSView *)wd.window_view layer];
if (layer) {
layer.contentsScale = scale;
}
@@ -209,16 +209,16 @@ void DisplayServerOSX::_update_window_style(WindowData p_wd) {
if (borderless_full) {
// If the window covers up the screen set the level to above the main menu and hide on deactivate.
- [p_wd.window_object setLevel:NSMainMenuWindowLevel + 1];
- [p_wd.window_object setHidesOnDeactivate:YES];
+ [(NSWindow *)p_wd.window_object setLevel:NSMainMenuWindowLevel + 1];
+ [(NSWindow *)p_wd.window_object setHidesOnDeactivate:YES];
} else {
// Reset these when our window is not a borderless window that covers up the screen.
if (p_wd.on_top && !p_wd.fullscreen) {
- [p_wd.window_object setLevel:NSFloatingWindowLevel];
+ [(NSWindow *)p_wd.window_object setLevel:NSFloatingWindowLevel];
} else {
- [p_wd.window_object setLevel:NSNormalWindowLevel];
+ [(NSWindow *)p_wd.window_object setLevel:NSNormalWindowLevel];
}
- [p_wd.window_object setHidesOnDeactivate:NO];
+ [(NSWindow *)p_wd.window_object setHidesOnDeactivate:NO];
}
}
@@ -234,7 +234,7 @@ void DisplayServerOSX::_set_window_per_pixel_transparency_enabled(bool p_enabled
[wd.window_object setBackgroundColor:[NSColor clearColor]];
[wd.window_object setOpaque:NO];
[wd.window_object setHasShadow:NO];
- CALayer *layer = [wd.window_view layer];
+ CALayer *layer = [(NSView *)wd.window_view layer];
if (layer) {
[layer setBackgroundColor:[NSColor clearColor].CGColor];
[layer setOpaque:NO];
@@ -249,7 +249,7 @@ void DisplayServerOSX::_set_window_per_pixel_transparency_enabled(bool p_enabled
[wd.window_object setBackgroundColor:[NSColor colorWithCalibratedWhite:1 alpha:1]];
[wd.window_object setOpaque:YES];
[wd.window_object setHasShadow:YES];
- CALayer *layer = [wd.window_view layer];
+ CALayer *layer = [(NSView *)wd.window_view layer];
if (layer) {
[layer setBackgroundColor:[NSColor colorWithCalibratedWhite:1 alpha:1].CGColor];
[layer setOpaque:YES];
@@ -2256,7 +2256,7 @@ void DisplayServerOSX::window_set_mode(WindowMode p_mode, WindowID p_window) {
} break;
case WINDOW_MODE_EXCLUSIVE_FULLSCREEN:
case WINDOW_MODE_FULLSCREEN: {
- [wd.window_object setLevel:NSNormalWindowLevel];
+ [(NSWindow *)wd.window_object setLevel:NSNormalWindowLevel];
_set_window_per_pixel_transparency_enabled(true, p_window);
if (wd.resize_disabled) { // Restore resize disabled.
[wd.window_object setStyleMask:[wd.window_object styleMask] & ~NSWindowStyleMaskResizable];
@@ -2380,9 +2380,9 @@ void DisplayServerOSX::window_set_flag(WindowFlags p_flag, bool p_enabled, Windo
return;
}
if (p_enabled) {
- [wd.window_object setLevel:NSFloatingWindowLevel];
+ [(NSWindow *)wd.window_object setLevel:NSFloatingWindowLevel];
} else {
- [wd.window_object setLevel:NSNormalWindowLevel];
+ [(NSWindow *)wd.window_object setLevel:NSNormalWindowLevel];
}
} break;
case WINDOW_FLAG_TRANSPARENT: {
@@ -2423,7 +2423,7 @@ bool DisplayServerOSX::window_get_flag(WindowFlags p_flag, WindowID p_window) co
if (wd.fullscreen) {
return wd.on_top;
} else {
- return [wd.window_object level] == NSFloatingWindowLevel;
+ return [(NSWindow *)wd.window_object level] == NSFloatingWindowLevel;
}
} break;
case WINDOW_FLAG_TRANSPARENT: {
diff --git a/platform/osx/gl_manager_osx_legacy.h b/platform/osx/gl_manager_osx_legacy.h
index b5a1b9dd98..76d58de229 100644
--- a/platform/osx/gl_manager_osx_legacy.h
+++ b/platform/osx/gl_manager_osx_legacy.h
@@ -38,9 +38,9 @@
#include "core/templates/local_vector.h"
#include "servers/display_server.h"
-#include <AppKit/AppKit.h>
-#include <ApplicationServices/ApplicationServices.h>
-#include <CoreVideo/CoreVideo.h>
+#import <AppKit/AppKit.h>
+#import <ApplicationServices/ApplicationServices.h>
+#import <CoreVideo/CoreVideo.h>
class GLManager_OSX {
public:
diff --git a/platform/osx/joypad_osx.h b/platform/osx/joypad_osx.h
index b09d5ce34a..3f89048ce6 100644
--- a/platform/osx/joypad_osx.h
+++ b/platform/osx/joypad_osx.h
@@ -32,13 +32,13 @@
#define JOYPADOSX_H
#ifdef MACOS_10_0_4
-#include <IOKit/hidsystem/IOHIDUsageTables.h>
+#import <IOKit/hidsystem/IOHIDUsageTables.h>
#else
-#include <Kernel/IOKit/hidsystem/IOHIDUsageTables.h>
+#import <Kernel/IOKit/hidsystem/IOHIDUsageTables.h>
#endif
-#include <ForceFeedback/ForceFeedback.h>
-#include <ForceFeedback/ForceFeedbackConstants.h>
-#include <IOKit/hid/IOHIDLib.h>
+#import <ForceFeedback/ForceFeedback.h>
+#import <ForceFeedback/ForceFeedbackConstants.h>
+#import <IOKit/hid/IOHIDLib.h>
#include "core/input/input.h"
diff --git a/platform/osx/key_mapping_osx.mm b/platform/osx/key_mapping_osx.mm
index fde9206824..bfec45de58 100644
--- a/platform/osx/key_mapping_osx.mm
+++ b/platform/osx/key_mapping_osx.mm
@@ -30,8 +30,8 @@
#include "key_mapping_osx.h"
-#include <Carbon/Carbon.h>
-#include <Cocoa/Cocoa.h>
+#import <Carbon/Carbon.h>
+#import <Cocoa/Cocoa.h>
bool KeyMappingOSX::is_numpad_key(unsigned int key) {
static const unsigned int table[] = {
diff --git a/platform/osx/tts_osx.h b/platform/osx/tts_osx.h
index 2cf6d21c18..54d419e573 100644
--- a/platform/osx/tts_osx.h
+++ b/platform/osx/tts_osx.h
@@ -37,8 +37,13 @@
#include "core/variant/array.h"
#include "servers/display_server.h"
-#include <AVFAudio/AVSpeechSynthesis.h>
-#include <AppKit/AppKit.h>
+#import <AppKit/AppKit.h>
+
+#if __has_include(<AVFAudio/AVSpeechSynthesis.h>)
+#import <AVFAudio/AVSpeechSynthesis.h>
+#else
+#import <AVFoundation/AVFoundation.h>
+#endif
@interface TTS_OSX : NSObject <AVSpeechSynthesizerDelegate> {
// AVSpeechSynthesizer
diff --git a/platform/osx/vulkan_context_osx.h b/platform/osx/vulkan_context_osx.h
index b78b4eb141..ade0f4a4c9 100644
--- a/platform/osx/vulkan_context_osx.h
+++ b/platform/osx/vulkan_context_osx.h
@@ -32,7 +32,7 @@
#define VULKAN_DEVICE_OSX_H
#include "drivers/vulkan/vulkan_context.h"
-#include <AppKit/AppKit.h>
+#import <AppKit/AppKit.h>
class VulkanContextOSX : public VulkanContext {
virtual const char *_get_platform_surface_extension() const;
diff --git a/platform/uwp/os_uwp.cpp b/platform/uwp/os_uwp.cpp
index f002e47f2d..1614bfdcc3 100644
--- a/platform/uwp/os_uwp.cpp
+++ b/platform/uwp/os_uwp.cpp
@@ -647,6 +647,10 @@ Error OS_UWP::kill(const ProcessID &p_pid) {
return FAILED;
}
+bool OS_UWP::is_process_running(const ProcessID &p_pid) const {
+ return false;
+}
+
Error OS_UWP::set_cwd(const String &p_cwd) {
return FAILED;
}
diff --git a/platform/uwp/os_uwp.h b/platform/uwp/os_uwp.h
index bde65257be..bddf63ff18 100644
--- a/platform/uwp/os_uwp.h
+++ b/platform/uwp/os_uwp.h
@@ -198,6 +198,7 @@ public:
virtual Error execute(const String &p_path, const List<String> &p_arguments, String *r_pipe = nullptr, int *r_exitcode = nullptr, bool read_stderr = false, Mutex *p_pipe_mutex = nullptr, bool p_open_console = false);
virtual Error create_process(const String &p_path, const List<String> &p_arguments, ProcessID *r_child_id = nullptr, bool p_open_console = false);
virtual Error kill(const ProcessID &p_pid);
+ virtual bool is_process_running(const ProcessID &p_pid) const;
virtual bool has_environment(const String &p_var) const;
virtual String get_environment(const String &p_var) const;
diff --git a/platform/windows/crash_handler_windows.cpp b/platform/windows/crash_handler_windows.cpp
index 3b2c6fe9f6..6ce10e6f0f 100644
--- a/platform/windows/crash_handler_windows.cpp
+++ b/platform/windows/crash_handler_windows.cpp
@@ -32,6 +32,7 @@
#include "core/config/project_settings.h"
#include "core/os/os.h"
+#include "core/string/print_string.h"
#include "core/version.h"
#include "main/main.h"
@@ -129,13 +130,28 @@ DWORD CrashHandlerException(EXCEPTION_POINTERS *ep) {
return EXCEPTION_CONTINUE_SEARCH;
}
- fprintf(stderr, "\n================================================================\n");
- fprintf(stderr, "%s: Program crashed\n", __FUNCTION__);
+ String msg;
+ const ProjectSettings *proj_settings = ProjectSettings::get_singleton();
+ if (proj_settings) {
+ msg = proj_settings->get("debug/settings/crash_handler/message");
+ }
+ // Tell MainLoop about the crash. This can be handled by users too in Node.
if (OS::get_singleton()->get_main_loop()) {
OS::get_singleton()->get_main_loop()->notification(MainLoop::NOTIFICATION_CRASH);
}
+ print_error("\n================================================================");
+ print_error(vformat("%s: Program crashed", __FUNCTION__));
+
+ // Print the engine version just before, so that people are reminded to include the version in backtrace reports.
+ if (String(VERSION_HASH).is_empty()) {
+ print_error(vformat("Engine version: %s", VERSION_FULL_NAME));
+ } else {
+ print_error(vformat("Engine version: %s (%s)", VERSION_FULL_NAME, VERSION_HASH));
+ }
+ print_error(vformat("Dumping the backtrace. %s", msg));
+
// Load the symbols:
if (!SymInitialize(process, nullptr, false)) {
return EXCEPTION_CONTINUE_SEARCH;
@@ -174,20 +190,6 @@ DWORD CrashHandlerException(EXCEPTION_POINTERS *ep) {
IMAGE_NT_HEADERS *h = ImageNtHeader(base);
DWORD image_type = h->FileHeader.Machine;
- String msg;
- const ProjectSettings *proj_settings = ProjectSettings::get_singleton();
- if (proj_settings) {
- msg = proj_settings->get("debug/settings/crash_handler/message");
- }
-
- // Print the engine version just before, so that people are reminded to include the version in backtrace reports.
- if (String(VERSION_HASH).is_empty()) {
- fprintf(stderr, "Engine version: %s\n", VERSION_FULL_NAME);
- } else {
- fprintf(stderr, "Engine version: %s (%s)\n", VERSION_FULL_NAME, VERSION_HASH);
- }
- fprintf(stderr, "Dumping the backtrace. %s\n", msg.utf8().get_data());
-
int n = 0;
do {
if (skip_first) {
@@ -197,12 +199,12 @@ DWORD CrashHandlerException(EXCEPTION_POINTERS *ep) {
std::string fnName = symbol(process, frame.AddrPC.Offset).undecorated_name();
if (SymGetLineFromAddr64(process, frame.AddrPC.Offset, &offset_from_symbol, &line)) {
- fprintf(stderr, "[%d] %s (%s:%d)\n", n, fnName.c_str(), line.FileName, line.LineNumber);
+ print_error(vformat("[%d] %s (%s:%d)", n, fnName.c_str(), (char *)line.FileName, (int)line.LineNumber));
} else {
- fprintf(stderr, "[%d] %s\n", n, fnName.c_str());
+ print_error(vformat("[%d] %s", n, fnName.c_str()));
}
} else {
- fprintf(stderr, "[%d] ???\n", n);
+ print_error(vformat("[%d] ???", n));
}
n++;
@@ -213,8 +215,8 @@ DWORD CrashHandlerException(EXCEPTION_POINTERS *ep) {
}
} while (frame.AddrReturn.Offset != 0 && n < 256);
- fprintf(stderr, "-- END OF BACKTRACE --\n");
- fprintf(stderr, "================================================================\n");
+ print_error("-- END OF BACKTRACE --");
+ print_error("================================================================");
SymCleanup(process);
diff --git a/platform/windows/display_server_windows.cpp b/platform/windows/display_server_windows.cpp
index b548277f95..93cab85441 100644
--- a/platform/windows/display_server_windows.cpp
+++ b/platform/windows/display_server_windows.cpp
@@ -1106,6 +1106,10 @@ void DisplayServerWindows::_update_window_style(WindowID p_window, bool p_repain
SetWindowLongPtr(wd.hWnd, GWL_STYLE, style);
SetWindowLongPtr(wd.hWnd, GWL_EXSTYLE, style_ex);
+ if (icon.is_valid()) {
+ set_icon(icon);
+ }
+
SetWindowPos(wd.hWnd, wd.always_on_top ? HWND_TOPMOST : HWND_NOTOPMOST, 0, 0, 0, 0, SWP_FRAMECHANGED | SWP_NOMOVE | SWP_NOSIZE | ((wd.no_focus || wd.is_popup) ? SWP_NOACTIVATE : 0));
if (p_repaint) {
@@ -1895,9 +1899,11 @@ void DisplayServerWindows::set_icon(const Ref<Image> &p_icon) {
_THREAD_SAFE_METHOD_
ERR_FAIL_COND(!p_icon.is_valid());
- Ref<Image> icon = p_icon->duplicate();
- if (icon->get_format() != Image::FORMAT_RGBA8) {
- icon->convert(Image::FORMAT_RGBA8);
+ if (icon != p_icon) {
+ icon = p_icon->duplicate();
+ if (icon->get_format() != Image::FORMAT_RGBA8) {
+ icon->convert(Image::FORMAT_RGBA8);
+ }
}
int w = icon->get_width();
int h = icon->get_height();
diff --git a/platform/windows/display_server_windows.h b/platform/windows/display_server_windows.h
index c039b29c54..febc8a2043 100644
--- a/platform/windows/display_server_windows.h
+++ b/platform/windows/display_server_windows.h
@@ -399,6 +399,7 @@ class DisplayServerWindows : public DisplayServer {
HHOOK mouse_monitor = nullptr;
List<WindowID> popup_list;
uint64_t time_since_popup = 0;
+ Ref<Image> icon;
WindowID _create_window(WindowMode p_mode, VSyncMode p_vsync_mode, uint32_t p_flags, const Rect2i &p_rect);
WindowID window_id_counter = MAIN_WINDOW_ID;
diff --git a/platform/windows/export/export_plugin.cpp b/platform/windows/export/export_plugin.cpp
index b4d8ce64b2..7627a3cba3 100644
--- a/platform/windows/export/export_plugin.cpp
+++ b/platform/windows/export/export_plugin.cpp
@@ -53,21 +53,24 @@ Error EditorExportPlatformWindows::_export_debug_script(const Ref<EditorExportPr
return OK;
}
+Error EditorExportPlatformWindows::modify_template(const Ref<EditorExportPreset> &p_preset, bool p_debug, const String &p_path, int p_flags) {
+ if (p_preset->get("application/modify_resources")) {
+ return _rcedit_add_data(p_preset, p_path);
+ } else {
+ return OK;
+ }
+}
+
Error EditorExportPlatformWindows::export_project(const Ref<EditorExportPreset> &p_preset, bool p_debug, const String &p_path, int p_flags) {
String pck_path = p_path;
if (p_preset->get("binary_format/embed_pck")) {
pck_path = p_path.get_basename() + ".tmp";
}
- Error err = EditorExportPlatformPC::prepare_template(p_preset, p_debug, pck_path, p_flags);
- if (p_preset->get("application/modify_resources") && err == OK) {
- err = _rcedit_add_data(p_preset, pck_path);
- }
- if (err == OK) {
- err = EditorExportPlatformPC::export_project_data(p_preset, p_debug, pck_path, p_flags);
- }
+ Error err = EditorExportPlatformPC::export_project(p_preset, p_debug, pck_path, p_flags);
if (p_preset->get("codesign/enable") && err == OK) {
err = _code_sign(p_preset, pck_path);
}
+
if (p_preset->get("binary_format/embed_pck") && err == OK) {
Ref<DirAccess> tmp_dir = DirAccess::create_for_path(p_path.get_base_dir());
err = tmp_dir->rename(pck_path, p_path);
diff --git a/platform/windows/export/export_plugin.h b/platform/windows/export/export_plugin.h
index c33c7f1f63..b48ee7c985 100644
--- a/platform/windows/export/export_plugin.h
+++ b/platform/windows/export/export_plugin.h
@@ -44,6 +44,7 @@ class EditorExportPlatformWindows : public EditorExportPlatformPC {
public:
virtual Error export_project(const Ref<EditorExportPreset> &p_preset, bool p_debug, const String &p_path, int p_flags = 0) override;
+ virtual Error modify_template(const Ref<EditorExportPreset> &p_preset, bool p_debug, const String &p_path, int p_flags) override;
virtual Error sign_shared_object(const Ref<EditorExportPreset> &p_preset, bool p_debug, const String &p_path) override;
virtual List<String> get_binary_extensions(const Ref<EditorExportPreset> &p_preset) const override;
virtual void get_export_options(List<ExportOption> *r_options) override;
diff --git a/platform/windows/os_windows.cpp b/platform/windows/os_windows.cpp
index 6b4e455197..68e188bbed 100644
--- a/platform/windows/os_windows.cpp
+++ b/platform/windows/os_windows.cpp
@@ -387,6 +387,31 @@ String OS_Windows::_quote_command_line_argument(const String &p_text) const {
return p_text;
}
+static void _append_to_pipe(char *p_bytes, int p_size, String *r_pipe, Mutex *p_pipe_mutex) {
+ // Try to convert from default ANSI code page to Unicode.
+ LocalVector<wchar_t> wchars;
+ int total_wchars = MultiByteToWideChar(CP_ACP, 0, p_bytes, p_size, nullptr, 0);
+ if (total_wchars > 0) {
+ wchars.resize(total_wchars);
+ if (MultiByteToWideChar(CP_ACP, 0, p_bytes, p_size, wchars.ptr(), total_wchars) == 0) {
+ wchars.clear();
+ }
+ }
+
+ if (p_pipe_mutex) {
+ p_pipe_mutex->lock();
+ }
+ if (wchars.is_empty()) {
+ // Let's hope it's compatible with UTF-8.
+ (*r_pipe) += String::utf8(p_bytes, p_size);
+ } else {
+ (*r_pipe) += String(wchars.ptr(), total_wchars);
+ }
+ if (p_pipe_mutex) {
+ p_pipe_mutex->unlock();
+ }
+}
+
Error OS_Windows::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) {
String path = p_path.replace("/", "\\");
String command = _quote_command_line_argument(path);
@@ -435,21 +460,44 @@ Error OS_Windows::execute(const String &p_path, const List<String> &p_arguments,
if (r_pipe) {
CloseHandle(pipe[1]); // Close pipe write handle (only child process is writing).
- char buf[4096];
+
+ LocalVector<char> bytes;
+ int bytes_in_buffer = 0;
+
+ const int CHUNK_SIZE = 4096;
DWORD read = 0;
for (;;) { // Read StdOut and StdErr from pipe.
- bool success = ReadFile(pipe[0], buf, 4096, &read, NULL);
+ bytes.resize(bytes_in_buffer + CHUNK_SIZE);
+ const bool success = ReadFile(pipe[0], bytes.ptr() + bytes_in_buffer, CHUNK_SIZE, &read, NULL);
if (!success || read == 0) {
break;
}
- if (p_pipe_mutex) {
- p_pipe_mutex->lock();
+
+ // Assume that all possible encodings are ASCII-compatible.
+ // Break at newline to allow receiving long output in portions.
+ int newline_index = -1;
+ for (int i = read - 1; i >= 0; i--) {
+ if (bytes[bytes_in_buffer + i] == '\n') {
+ newline_index = i;
+ break;
+ }
}
- (*r_pipe) += String::utf8(buf, read);
- if (p_pipe_mutex) {
- p_pipe_mutex->unlock();
+ if (newline_index == -1) {
+ bytes_in_buffer += read;
+ continue;
}
+
+ const int bytes_to_convert = bytes_in_buffer + (newline_index + 1);
+ _append_to_pipe(bytes.ptr(), bytes_to_convert, r_pipe, p_pipe_mutex);
+
+ bytes_in_buffer = read - (newline_index + 1);
+ memmove(bytes.ptr(), bytes.ptr() + bytes_to_convert, bytes_in_buffer);
+ }
+
+ if (bytes_in_buffer > 0) {
+ _append_to_pipe(bytes.ptr(), bytes_in_buffer, r_pipe, p_pipe_mutex);
}
+
CloseHandle(pipe[0]); // Close pipe read handle.
} else {
WaitForSingleObject(pi.pi.hProcess, INFINITE);
@@ -517,6 +565,25 @@ int OS_Windows::get_process_id() const {
return _getpid();
}
+bool OS_Windows::is_process_running(const ProcessID &p_pid) const {
+ if (!process_map->has(p_pid)) {
+ return false;
+ }
+
+ const PROCESS_INFORMATION &pi = (*process_map)[p_pid].pi;
+
+ DWORD dw_exit_code = 0;
+ if (!GetExitCodeProcess(pi.hProcess, &dw_exit_code)) {
+ return false;
+ }
+
+ if (dw_exit_code != STILL_ACTIVE) {
+ return false;
+ }
+
+ return true;
+}
+
Error OS_Windows::set_cwd(const String &p_cwd) {
if (_wchdir((LPCWSTR)(p_cwd.utf16().get_data())) != 0) {
return ERR_CANT_OPEN;
diff --git a/platform/windows/os_windows.h b/platform/windows/os_windows.h
index 81cc7c3fc1..378438a075 100644
--- a/platform/windows/os_windows.h
+++ b/platform/windows/os_windows.h
@@ -132,6 +132,7 @@ public:
virtual Error create_process(const String &p_path, const List<String> &p_arguments, ProcessID *r_child_id = nullptr, bool p_open_console = false) override;
virtual Error kill(const ProcessID &p_pid) override;
virtual int get_process_id() const override;
+ virtual bool is_process_running(const ProcessID &p_pid) const override;
virtual bool has_environment(const String &p_var) const override;
virtual String get_environment(const String &p_var) const override;