summaryrefslogtreecommitdiff
path: root/platform
diff options
context:
space:
mode:
Diffstat (limited to 'platform')
-rw-r--r--platform/iphone/os_iphone.cpp8
-rw-r--r--platform/javascript/os_javascript.cpp121
-rw-r--r--platform/javascript/os_javascript.h5
-rw-r--r--platform/osx/os_osx.h2
-rw-r--r--platform/osx/os_osx.mm53
-rw-r--r--platform/uwp/joypad_uwp.cpp75
-rw-r--r--platform/uwp/joypad_uwp.h8
-rw-r--r--platform/windows/os_windows.cpp4
-rw-r--r--platform/x11/os_x11.cpp4
9 files changed, 190 insertions, 90 deletions
diff --git a/platform/iphone/os_iphone.cpp b/platform/iphone/os_iphone.cpp
index f2c01a5f51..b202a993ff 100644
--- a/platform/iphone/os_iphone.cpp
+++ b/platform/iphone/os_iphone.cpp
@@ -224,11 +224,9 @@ void OSIPhone::mouse_button(int p_idx, int p_x, int p_y, bool p_pressed, bool p_
Ref<InputEventMouseButton> ev;
ev.instance();
- // swaped it for tilted screen
- //ev->get_pos().x = ev.mouse_button.global_x = video_mode.height - p_y;
- //ev->get_pos().y = ev.mouse_button.global_y = p_x;
- ev->set_position(Vector2(video_mode.height - p_y, p_x));
- ev->set_global_position(Vector2(video_mode.height - p_y, p_x));
+
+ ev->set_position(Vector2(p_x, p_y));
+ ev->set_global_position(Vector2(p_x, p_y));
//mouse_list.pressed[p_idx] = p_pressed;
diff --git a/platform/javascript/os_javascript.cpp b/platform/javascript/os_javascript.cpp
index 0708d46196..5513fca809 100644
--- a/platform/javascript/os_javascript.cpp
+++ b/platform/javascript/os_javascript.cpp
@@ -96,30 +96,18 @@ static EM_BOOL _browser_resize_callback(int event_type, const EmscriptenUiEvent
ERR_FAIL_COND_V(event_type != EMSCRIPTEN_EVENT_RESIZE, false);
OS_JavaScript *os = static_cast<OS_JavaScript *>(user_data);
-
- // the order in which _browser_resize_callback and
- // _fullscreen_change_callback are called is browser-dependent,
- // so try adjusting for fullscreen in both
- if (os->is_window_fullscreen() || os->is_window_maximized()) {
-
- OS::VideoMode vm = os->get_video_mode();
- vm.width = ui_event->windowInnerWidth;
- vm.height = ui_event->windowInnerHeight;
- os->set_video_mode(vm);
- emscripten_set_canvas_size(ui_event->windowInnerWidth, ui_event->windowInnerHeight);
- }
+ // The order of the fullscreen change event and the window size change
+ // event varies, even within just one browser, so defer handling
+ os->request_canvas_size_adjustment();
return false;
}
-static Size2 _windowed_size;
-
static EM_BOOL _fullscreen_change_callback(int event_type, const EmscriptenFullscreenChangeEvent *event, void *user_data) {
ERR_FAIL_COND_V(event_type != EMSCRIPTEN_EVENT_FULLSCREENCHANGE, false);
OS_JavaScript *os = static_cast<OS_JavaScript *>(user_data);
String id = String::utf8(event->id);
-
// empty id is canvas
if (id.empty() || id == "canvas") {
@@ -127,18 +115,8 @@ static EM_BOOL _fullscreen_change_callback(int event_type, const EmscriptenFulls
// this event property is the only reliable information on
// browser fullscreen state
vm.fullscreen = event->isFullscreen;
-
- if (event->isFullscreen) {
- vm.width = event->screenWidth;
- vm.height = event->screenHeight;
- os->set_video_mode(vm);
- emscripten_set_canvas_size(vm.width, vm.height);
- } else {
- os->set_video_mode(vm);
- if (!os->is_window_maximized()) {
- os->set_window_size(_windowed_size);
- }
- }
+ os->set_video_mode(vm);
+ os->request_canvas_size_adjustment();
}
return false;
}
@@ -719,14 +697,17 @@ Size2 OS_JavaScript::get_screen_size(int p_screen) const {
void OS_JavaScript::set_window_size(const Size2 p_size) {
- window_maximized = false;
+ windowed_size = p_size;
if (is_window_fullscreen()) {
+ window_maximized = false;
set_window_fullscreen(false);
+ } else if (is_window_maximized()) {
+ set_window_maximized(false);
+ } else {
+ video_mode.width = p_size.x;
+ video_mode.height = p_size.y;
+ emscripten_set_canvas_size(p_size.x, p_size.y);
}
- _windowed_size = p_size;
- video_mode.width = p_size.x;
- video_mode.height = p_size.y;
- emscripten_set_canvas_size(p_size.x, p_size.y);
}
Size2 OS_JavaScript::get_window_size() const {
@@ -739,20 +720,30 @@ Size2 OS_JavaScript::get_window_size() const {
void OS_JavaScript::set_window_maximized(bool p_enabled) {
window_maximized = p_enabled;
- if (p_enabled) {
-
- if (is_window_fullscreen()) {
- // _browser_resize callback will set canvas size
- set_window_fullscreen(false);
- } else {
- /* clang-format off */
- video_mode.width = EM_ASM_INT_V(return window.innerWidth);
- video_mode.height = EM_ASM_INT_V(return window.innerHeight);
- /* clang-format on */
- emscripten_set_canvas_size(video_mode.width, video_mode.height);
- }
- } else {
- set_window_size(_windowed_size);
+ if (is_window_fullscreen()) {
+ set_window_fullscreen(false);
+ return;
+ }
+ // Calling emscripten_enter_soft_fullscreen mutltiple times hides all
+ // page elements except the canvas permanently, so track state
+ if (p_enabled && !soft_fs_enabled) {
+
+ EmscriptenFullscreenStrategy strategy;
+ strategy.scaleMode = EMSCRIPTEN_FULLSCREEN_SCALE_STRETCH;
+ strategy.canvasResolutionScaleMode = EMSCRIPTEN_FULLSCREEN_CANVAS_SCALE_STDDEF;
+ strategy.filteringMode = EMSCRIPTEN_FULLSCREEN_FILTERING_DEFAULT;
+ strategy.canvasResizedCallback = NULL;
+ emscripten_enter_soft_fullscreen(NULL, &strategy);
+ soft_fs_enabled = true;
+ video_mode.width = get_window_size().width;
+ video_mode.height = get_window_size().height;
+ } else if (!p_enabled) {
+
+ emscripten_exit_soft_fullscreen();
+ soft_fs_enabled = false;
+ video_mode.width = windowed_size.width;
+ video_mode.height = windowed_size.height;
+ emscripten_set_canvas_size(video_mode.width, video_mode.height);
}
}
@@ -766,9 +757,17 @@ void OS_JavaScript::set_window_fullscreen(bool p_enable) {
// _browser_resize_callback or _fullscreen_change_callback
EMSCRIPTEN_RESULT result;
if (p_enable) {
- /* clang-format off */
- EM_ASM(Module.requestFullscreen(false, false););
- /* clang-format on */
+ if (window_maximized) {
+ // soft fs during real fs can cause issues
+ set_window_maximized(false);
+ window_maximized = true;
+ }
+ EmscriptenFullscreenStrategy strategy;
+ strategy.scaleMode = EMSCRIPTEN_FULLSCREEN_SCALE_STRETCH;
+ strategy.canvasResolutionScaleMode = EMSCRIPTEN_FULLSCREEN_CANVAS_SCALE_STDDEF;
+ strategy.filteringMode = EMSCRIPTEN_FULLSCREEN_FILTERING_DEFAULT;
+ strategy.canvasResizedCallback = NULL;
+ emscripten_request_fullscreen_strategy(NULL, false, &strategy);
} else {
result = emscripten_exit_fullscreen();
if (result != EMSCRIPTEN_RESULT_SUCCESS) {
@@ -782,6 +781,11 @@ bool OS_JavaScript::is_window_fullscreen() const {
return video_mode.fullscreen;
}
+void OS_JavaScript::request_canvas_size_adjustment() {
+
+ canvas_size_adjustment_requested = true;
+}
+
void OS_JavaScript::get_fullscreen_mode_list(List<VideoMode> *p_list, int p_screen) const {
Size2 screen = get_screen_size();
@@ -841,6 +845,17 @@ bool OS_JavaScript::main_loop_iterate() {
}
}
process_joypads();
+ if (canvas_size_adjustment_requested) {
+
+ if (video_mode.fullscreen || window_maximized) {
+ video_mode.width = get_window_size().width;
+ video_mode.height = get_window_size().height;
+ }
+ if (!video_mode.fullscreen) {
+ set_window_maximized(window_maximized);
+ }
+ canvas_size_adjustment_requested = false;
+ }
return Main::iteration();
}
@@ -857,7 +872,11 @@ void OS_JavaScript::process_accelerometer(const Vector3 &p_accelerometer) {
bool OS_JavaScript::has_touchscreen_ui_hint() const {
- return false; //???
+ /* clang-format off */
+ return EM_ASM_INT_V(
+ return 'ontouchstart' in window;
+ );
+ /* clang-format on */
}
void OS_JavaScript::main_loop_request_quit() {
@@ -980,6 +999,8 @@ OS_JavaScript::OS_JavaScript(const char *p_execpath, GetDataDirFunc p_get_data_d
main_loop = NULL;
gl_extensions = NULL;
window_maximized = false;
+ soft_fs_enabled = false;
+ canvas_size_adjustment_requested = false;
get_data_dir_func = p_get_data_dir_func;
FileAccessUnix::close_notification_func = _close_notification_funcs;
diff --git a/platform/javascript/os_javascript.h b/platform/javascript/os_javascript.h
index 24e96e20dd..13c500b3dc 100644
--- a/platform/javascript/os_javascript.h
+++ b/platform/javascript/os_javascript.h
@@ -59,7 +59,10 @@ class OS_JavaScript : public OS_Unix {
const char *gl_extensions;
InputDefault *input;
+ Vector2 windowed_size;
bool window_maximized;
+ bool soft_fs_enabled;
+ bool canvas_size_adjustment_requested;
VideoMode video_mode;
CursorShape cursor_shape;
MainLoop *main_loop;
@@ -130,6 +133,8 @@ public:
virtual void set_window_fullscreen(bool p_enable);
virtual bool is_window_fullscreen() const;
+ void request_canvas_size_adjustment();
+
virtual String get_name();
virtual MainLoop *get_main_loop() const;
diff --git a/platform/osx/os_osx.h b/platform/osx/os_osx.h
index cb9dd1dd8e..4b5682518f 100644
--- a/platform/osx/os_osx.h
+++ b/platform/osx/os_osx.h
@@ -136,6 +136,8 @@ public:
virtual String get_name();
+ virtual void print_error(const char *p_function, const char *p_file, int p_line, const char *p_code, const char *p_rationale, ErrorType p_type = ERR_ERROR);
+
virtual void alert(const String &p_alert, const String &p_title = "ALERT!");
virtual void set_cursor_shape(CursorShape p_shape);
diff --git a/platform/osx/os_osx.mm b/platform/osx/os_osx.mm
index cfa039c130..a34f6cc5dd 100644
--- a/platform/osx/os_osx.mm
+++ b/platform/osx/os_osx.mm
@@ -44,6 +44,9 @@
#include <IOKit/IOKitLib.h>
#include <IOKit/hid/IOHIDKeys.h>
#include <IOKit/hid/IOHIDLib.h>
+#if MAC_OS_X_VERSION_MAX_ALLOWED >= 101200
+#include <os/log.h>
+#endif
#include <fcntl.h>
#include <libproc.h>
@@ -1017,6 +1020,45 @@ String OS_OSX::get_name() {
return "OSX";
}
+void OS_OSX::print_error(const char *p_function, const char *p_file, int p_line, const char *p_code, const char *p_rationale, ErrorType p_type) {
+
+#if MAC_OS_X_VERSION_MAX_ALLOWED >= 101200
+ if (!_print_error_enabled)
+ return;
+
+ const char *err_details;
+ if (p_rationale && p_rationale[0])
+ err_details = p_rationale;
+ else
+ err_details = p_code;
+
+ switch (p_type) {
+ case ERR_ERROR:
+ os_log_error(OS_LOG_DEFAULT, "ERROR: %{public}s: %{public}s\nAt: %{public}s:%i.", p_function, err_details, p_file, p_line);
+ print("\E[1;31mERROR: %s: \E[0m\E[1m%s\n", p_function, err_details);
+ print("\E[0;31m At: %s:%i.\E[0m\n", p_file, p_line);
+ break;
+ case ERR_WARNING:
+ os_log_info(OS_LOG_DEFAULT, "WARNING: %{public}s: %{public}s\nAt: %{public}s:%i.", p_function, err_details, p_file, p_line);
+ print("\E[1;33mWARNING: %s: \E[0m\E[1m%s\n", p_function, err_details);
+ print("\E[0;33m At: %s:%i.\E[0m\n", p_file, p_line);
+ break;
+ case ERR_SCRIPT:
+ os_log_error(OS_LOG_DEFAULT, "SCRIPT ERROR: %{public}s: %{public}s\nAt: %{public}s:%i.", p_function, err_details, p_file, p_line);
+ print("\E[1;35mSCRIPT ERROR: %s: \E[0m\E[1m%s\n", p_function, err_details);
+ print("\E[0;35m At: %s:%i.\E[0m\n", p_file, p_line);
+ break;
+ case ERR_SHADER:
+ os_log_error(OS_LOG_DEFAULT, "SHADER ERROR: %{public}s: %{public}s\nAt: %{public}s:%i.", p_function, err_details, p_file, p_line);
+ print("\E[1;36mSHADER ERROR: %s: \E[0m\E[1m%s\n", p_function, err_details);
+ print("\E[0;36m At: %s:%i.\E[0m\n", p_file, p_line);
+ break;
+ }
+#else
+ OS_Unix::print_error(p_function, p_file, p_line, p_code, p_rationale, p_type);
+#endif
+}
+
void OS_OSX::alert(const String &p_alert, const String &p_title) {
// Set OS X-compliant variables
NSAlert *window = [[NSAlert alloc] init];
@@ -1081,18 +1123,13 @@ void OS_OSX::warp_mouse_pos(const Point2 &p_to) {
mouse_y = p_to.y;
} else { //set OS position
- /* this code has not been tested, please be a kind soul and fix it if it fails! */
-
//local point in window coords
- NSPoint localPoint = { p_to.x, p_to.y };
-
- NSPoint pointInWindow = [window_view convertPoint:localPoint toView:nil];
- NSRect pointInWindowRect;
- pointInWindowRect.origin = pointInWindow;
+ const NSRect contentRect = [window_view frame];
+ NSRect pointInWindowRect = NSMakeRect(p_to.x / display_scale, contentRect.size.height - (p_to.y / display_scale) - 1, 0, 0);
NSPoint pointOnScreen = [[window_view window] convertRectToScreen:pointInWindowRect].origin;
//point in scren coords
- CGPoint lMouseWarpPos = { pointOnScreen.x, pointOnScreen.y };
+ CGPoint lMouseWarpPos = { pointOnScreen.x, CGDisplayBounds(CGMainDisplayID()).size.height - pointOnScreen.y };
//do the warping
CGEventSourceRef lEventRef = CGEventSourceCreate(kCGEventSourceStateCombinedSessionState);
diff --git a/platform/uwp/joypad_uwp.cpp b/platform/uwp/joypad_uwp.cpp
index 34e36f7b66..f3d4eb99c8 100644
--- a/platform/uwp/joypad_uwp.cpp
+++ b/platform/uwp/joypad_uwp.cpp
@@ -29,6 +29,7 @@
/*************************************************************************/
#include "joypad_uwp.h"
+#include "core/os/os.h"
using namespace Windows::Gaming::Input;
using namespace Windows::Foundation;
@@ -45,27 +46,44 @@ void JoypadUWP::process_controllers() {
for (int i = 0; i < MAX_CONTROLLERS; i++) {
- if (!controllers[i].connected) break;
+ ControllerDevice &joy = controllers[i];
- switch (controllers[i].type) {
+ if (!joy.connected) break;
+
+ switch (joy.type) {
case ControllerType::GAMEPAD_CONTROLLER: {
- GamepadReading reading = ((Gamepad ^)controllers[i].controller_reference)->GetCurrentReading();
+ GamepadReading reading = ((Gamepad ^) joy.controller_reference)->GetCurrentReading();
int button_mask = (int)GamepadButtons::Menu;
for (int j = 0; j < 14; j++) {
- input->joy_button(controllers[i].id, j, (int)reading.Buttons & button_mask);
+ input->joy_button(joy.id, j, (int)reading.Buttons & button_mask);
button_mask *= 2;
}
- input->joy_axis(controllers[i].id, JOY_AXIS_0, axis_correct(reading.LeftThumbstickX));
- input->joy_axis(controllers[i].id, JOY_AXIS_1, axis_correct(reading.LeftThumbstickY, true));
- input->joy_axis(controllers[i].id, JOY_AXIS_2, axis_correct(reading.RightThumbstickX));
- input->joy_axis(controllers[i].id, JOY_AXIS_3, axis_correct(reading.RightThumbstickY, true));
- input->joy_axis(controllers[i].id, JOY_AXIS_4, axis_correct(reading.LeftTrigger, false, true));
- input->joy_axis(controllers[i].id, JOY_AXIS_5, axis_correct(reading.RightTrigger, false, true));
+ input->joy_axis(joy.id, JOY_AXIS_0, axis_correct(reading.LeftThumbstickX));
+ input->joy_axis(joy.id, JOY_AXIS_1, axis_correct(reading.LeftThumbstickY, true));
+ input->joy_axis(joy.id, JOY_AXIS_2, axis_correct(reading.RightThumbstickX));
+ input->joy_axis(joy.id, JOY_AXIS_3, axis_correct(reading.RightThumbstickY, true));
+ input->joy_axis(joy.id, JOY_AXIS_4, axis_correct(reading.LeftTrigger, false, true));
+ input->joy_axis(joy.id, JOY_AXIS_5, axis_correct(reading.RightTrigger, false, true));
+
+ uint64_t timestamp = input->get_joy_vibration_timestamp(joy.id);
+ if (timestamp > joy.ff_timestamp) {
+ Vector2 strength = input->get_joy_vibration_strength(joy.id);
+ float duration = input->get_joy_vibration_duration(joy.id);
+ if (strength.x == 0 && strength.y == 0) {
+ joypad_vibration_stop(i, timestamp);
+ } else {
+ joypad_vibration_start(i, strength.x, strength.y, duration, timestamp);
+ }
+ } else if (joy.vibrating && joy.ff_end_timestamp != 0) {
+ uint64_t current_time = OS::get_singleton()->get_ticks_usec();
+ if (current_time >= joy.ff_end_timestamp)
+ joypad_vibration_stop(i, current_time);
+ }
break;
}
@@ -122,15 +140,7 @@ void JoypadUWP::OnGamepadRemoved(Platform::Object ^ sender, Windows::Gaming::Inp
ERR_FAIL_COND(idx == -1);
- for (int i = idx + 1; i < MAX_CONTROLLERS - 1; i++) {
-
- if (!controllers[i].connected) {
- break;
- }
-
- controllers[i - 1] = controllers[i];
- }
- controllers[MAX_CONTROLLERS - 1] = ControllerDevice();
+ controllers[idx] = ControllerDevice();
input->joy_connection_changed(idx, false, "Xbox Controller");
}
@@ -144,3 +154,30 @@ InputDefault::JoyAxis JoypadUWP::axis_correct(double p_val, bool p_negate, bool
return jx;
}
+
+void JoypadUWP::joypad_vibration_start(int p_device, float p_weak_magnitude, float p_strong_magnitude, float p_duration, uint64_t p_timestamp) {
+ ControllerDevice &joy = controllers[p_device];
+ if (joy.connected) {
+ GamepadVibration vibration;
+ vibration.LeftMotor = p_strong_magnitude;
+ vibration.RightMotor = p_weak_magnitude;
+ ((Gamepad ^) joy.controller_reference)->Vibration = vibration;
+
+ joy.ff_timestamp = p_timestamp;
+ joy.ff_end_timestamp = p_duration == 0 ? 0 : p_timestamp + (uint64_t)(p_duration * 1000000.0);
+ joy.vibrating = true;
+ }
+}
+
+void JoypadUWP::joypad_vibration_stop(int p_device, uint64_t p_timestamp) {
+ ControllerDevice &joy = controllers[p_device];
+ if (joy.connected) {
+ GamepadVibration vibration;
+ vibration.LeftMotor = 0.0;
+ vibration.RightMotor = 0.0;
+ ((Gamepad ^) joy.controller_reference)->Vibration = vibration;
+
+ joy.ff_timestamp = p_timestamp;
+ joy.vibrating = false;
+ }
+}
diff --git a/platform/uwp/joypad_uwp.h b/platform/uwp/joypad_uwp.h
index 7337ffb3ce..c55e1e7ab7 100644
--- a/platform/uwp/joypad_uwp.h
+++ b/platform/uwp/joypad_uwp.h
@@ -62,11 +62,17 @@ private:
int id;
bool connected;
ControllerType type;
+ float ff_timestamp;
+ float ff_end_timestamp;
+ bool vibrating;
ControllerDevice() {
id = -1;
connected = false;
type = ControllerType::GAMEPAD_CONTROLLER;
+ ff_timestamp = 0.0f;
+ ff_end_timestamp = 0.0f;
+ vibrating = false;
}
};
@@ -78,6 +84,8 @@ private:
void OnGamepadRemoved(Platform::Object ^ sender, Windows::Gaming::Input::Gamepad ^ value);
InputDefault::JoyAxis axis_correct(double p_val, bool p_negate = false, bool p_trigger = false) const;
+ void joypad_vibration_start(int p_device, float p_weak_magnitude, float p_strong_magnitude, float p_duration, uint64_t p_timestamp);
+ void joypad_vibration_stop(int p_device, uint64_t p_timestamp);
};
#endif
diff --git a/platform/windows/os_windows.cpp b/platform/windows/os_windows.cpp
index a1677be58e..f72e5ef595 100644
--- a/platform/windows/os_windows.cpp
+++ b/platform/windows/os_windows.cpp
@@ -1192,10 +1192,6 @@ void OS_Windows::finalize() {
main_loop = NULL;
- for (int i = 0; i < get_audio_driver_count(); i++) {
- AudioDriverManager::get_driver(i)->finish();
- }
-
memdelete(joypad);
memdelete(input);
diff --git a/platform/x11/os_x11.cpp b/platform/x11/os_x11.cpp
index 1dde328eda..ade3a0a0c5 100644
--- a/platform/x11/os_x11.cpp
+++ b/platform/x11/os_x11.cpp
@@ -529,10 +529,6 @@ void OS_X11::finalize() {
memdelete(main_loop);
main_loop = NULL;
- for (int i = 0; i < get_audio_driver_count(); i++) {
- AudioDriverManager::get_driver(i)->finish();
- }
-
/*
if (debugger_connection_console) {
memdelete(debugger_connection_console);