[HTML5] Fix build (with module_webxr_enabled=no).

The XR API changed a bit, and it's not just a rename, though probably an
easy update for someone who is qualified :).
This commit is contained in:
Fabio Alessandrelli 2021-07-07 16:31:06 +02:00
parent 6ddaebc091
commit 3d8acc7a54
6 changed files with 18 additions and 20 deletions

View File

@ -34,7 +34,6 @@
#include "webrtc_data_channel_js.h" #include "webrtc_data_channel_js.h"
#include "core/io/json.h"
#include "emscripten.h" #include "emscripten.h"
void WebRTCPeerConnectionJS::_on_ice_candidate(void *p_obj, const char *p_mid_name, int p_mline_idx, const char *p_candidate) { void WebRTCPeerConnectionJS::_on_ice_candidate(void *p_obj, const char *p_mid_name, int p_mline_idx, const char *p_candidate) {
@ -100,7 +99,7 @@ Error WebRTCPeerConnectionJS::initialize(Dictionary p_config) {
} }
_conn_state = STATE_NEW; _conn_state = STATE_NEW;
String config = JSON::print(p_config); String config = Variant(p_config).to_json_string();
_js_id = godot_js_rtc_pc_create(config.utf8().get_data(), this, &_on_connection_state_changed, &_on_ice_candidate, &_on_data_channel); _js_id = godot_js_rtc_pc_create(config.utf8().get_data(), this, &_on_connection_state_changed, &_on_ice_candidate, &_on_data_channel);
return _js_id ? OK : FAILED; return _js_id ? OK : FAILED;
} }
@ -108,7 +107,7 @@ Error WebRTCPeerConnectionJS::initialize(Dictionary p_config) {
Ref<WebRTCDataChannel> WebRTCPeerConnectionJS::create_data_channel(String p_channel, Dictionary p_channel_config) { Ref<WebRTCDataChannel> WebRTCPeerConnectionJS::create_data_channel(String p_channel, Dictionary p_channel_config) {
ERR_FAIL_COND_V(_conn_state != STATE_NEW, nullptr); ERR_FAIL_COND_V(_conn_state != STATE_NEW, nullptr);
String config = JSON::print(p_channel_config); String config = Variant(p_channel_config).to_json_string();
int id = godot_js_rtc_pc_datachannel_create(_js_id, p_channel.utf8().get_data(), config.utf8().get_data()); int id = godot_js_rtc_pc_datachannel_create(_js_id, p_channel.utf8().get_data(), config.utf8().get_data());
ERR_FAIL_COND_V(id == 0, nullptr); ERR_FAIL_COND_V(id == 0, nullptr);
return memnew(WebRTCDataChannelJS(id)); return memnew(WebRTCDataChannelJS(id));

View File

@ -202,8 +202,8 @@ int WebXRInterfaceJS::get_capabilities() const {
return XRInterface::XR_STEREO | XRInterface::XR_MONO; return XRInterface::XR_STEREO | XRInterface::XR_MONO;
}; };
bool WebXRInterfaceJS::is_stereo() { uint32_t WebXRInterfaceJS::get_view_count() {
return godot_webxr_get_view_count() == 2; return godot_webxr_get_view_count();
}; };
bool WebXRInterfaceJS::is_initialized() const { bool WebXRInterfaceJS::is_initialized() const {
@ -425,7 +425,7 @@ void WebXRInterfaceJS::_update_tracker(int p_controller_id) {
int *buttons = godot_webxr_get_controller_buttons(p_controller_id); int *buttons = godot_webxr_get_controller_buttons(p_controller_id);
if (buttons) { if (buttons) {
for (int i = 0; i < buttons[0]; i++) { for (int i = 0; i < buttons[0]; i++) {
input->joy_button(p_controller_id + 100, i, *((float *)buttons + (i + 1))); input->joy_button(p_controller_id + 100, (JoyButton)i, *((float *)buttons + (i + 1)));
} }
free(buttons); free(buttons);
} }
@ -436,7 +436,7 @@ void WebXRInterfaceJS::_update_tracker(int p_controller_id) {
Input::JoyAxisValue joy_axis; Input::JoyAxisValue joy_axis;
joy_axis.min = -1; joy_axis.min = -1;
joy_axis.value = *((float *)axes + (i + 1)); joy_axis.value = *((float *)axes + (i + 1));
input->joy_axis(p_controller_id + 100, i, joy_axis); input->joy_axis(p_controller_id + 100, (JoyAxis)i, joy_axis);
} }
free(axes); free(axes);
} }

View File

@ -83,7 +83,7 @@ public:
virtual void uninitialize() override; virtual void uninitialize() override;
virtual Size2 get_render_targetsize() override; virtual Size2 get_render_targetsize() override;
virtual bool is_stereo() override; virtual uint32_t get_view_count() override;
virtual Transform3D get_camera_transform() override; virtual Transform3D get_camera_transform() override;
virtual Transform3D get_transform_for_view(uint32_t p_view, const Transform3D &p_cam_transform) override; virtual Transform3D get_transform_for_view(uint32_t p_view, const Transform3D &p_cam_transform) override;
virtual CameraMatrix get_projection_for_view(uint32_t p_view, real_t p_aspect, real_t p_z_near, real_t p_z_far) override; virtual CameraMatrix get_projection_for_view(uint32_t p_view, real_t p_aspect, real_t p_z_near, real_t p_z_far) override;

View File

@ -229,7 +229,7 @@ EM_BOOL DisplayServerJavaScript::mouse_button_callback(int p_event_type, const E
} }
Input *input = Input::get_singleton(); Input *input = Input::get_singleton();
MouseButton mask = input->get_mouse_button_mask(); int mask = input->get_mouse_button_mask();
MouseButton button_flag = MouseButton(1 << (ev->get_button_index() - 1)); MouseButton button_flag = MouseButton(1 << (ev->get_button_index() - 1));
if (ev->is_pressed()) { if (ev->is_pressed()) {
// Since the event is consumed, focus manually. The containing iframe, // Since the event is consumed, focus manually. The containing iframe,
@ -605,17 +605,17 @@ void DisplayServerJavaScript::process_joypads() {
Input::JoyAxisValue joy_axis; Input::JoyAxisValue joy_axis;
joy_axis.min = 0; joy_axis.min = 0;
joy_axis.value = value; joy_axis.value = value;
int a = b == 6 ? JOY_AXIS_TRIGGER_LEFT : JOY_AXIS_TRIGGER_RIGHT; JoyAxis a = b == 6 ? JOY_AXIS_TRIGGER_LEFT : JOY_AXIS_TRIGGER_RIGHT;
input->joy_axis(idx, a, joy_axis); input->joy_axis(idx, a, joy_axis);
} else { } else {
input->joy_button(idx, b, value); input->joy_button(idx, (JoyButton)b, value);
} }
} }
for (int a = 0; a < s_axes_num; a++) { for (int a = 0; a < s_axes_num; a++) {
Input::JoyAxisValue joy_axis; Input::JoyAxisValue joy_axis;
joy_axis.min = -1; joy_axis.min = -1;
joy_axis.value = s_axes[a]; joy_axis.value = s_axes[a];
input->joy_axis(idx, a, joy_axis); input->joy_axis(idx, (JoyAxis)a, joy_axis);
} }
} }
} }
@ -710,18 +710,18 @@ void DisplayServerJavaScript::_dispatch_input_event(const Ref<InputEvent> &p_eve
} }
} }
DisplayServer *DisplayServerJavaScript::create_func(const String &p_rendering_driver, DisplayServer::WindowMode p_mode, uint32_t p_flags, const Vector2i &p_resolution, Error &r_error) { 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_mode, p_flags, p_resolution, r_error)); return memnew(DisplayServerJavaScript(p_rendering_driver, p_window_mode, p_vsync_mode, p_flags, p_resolution, r_error));
} }
DisplayServerJavaScript::DisplayServerJavaScript(const String &p_rendering_driver, WindowMode p_mode, uint32_t p_flags, const Vector2i &p_resolution, Error &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) {
r_error = OK; // Always succeeds for now. r_error = OK; // Always succeeds for now.
// Ensure the canvas ID. // Ensure the canvas ID.
godot_js_config_canvas_id_get(canvas_id, 256); godot_js_config_canvas_id_get(canvas_id, 256);
// Handle contextmenu, webglcontextlost // Handle contextmenu, webglcontextlost
godot_js_display_setup_canvas(p_resolution.x, p_resolution.y, p_mode == WINDOW_MODE_FULLSCREEN, OS::get_singleton()->is_hidpi_allowed() ? 1 : 0); godot_js_display_setup_canvas(p_resolution.x, p_resolution.y, p_window_mode == WINDOW_MODE_FULLSCREEN, OS::get_singleton()->is_hidpi_allowed() ? 1 : 0);
// Check if it's windows. // Check if it's windows.
swap_cancel_ok = godot_js_display_is_swap_ok_cancel() == 1; swap_cancel_ok = godot_js_display_is_swap_ok_cancel() == 1;

View File

@ -89,7 +89,7 @@ private:
void process_joypads(); void process_joypads();
static Vector<String> get_rendering_drivers_func(); static Vector<String> get_rendering_drivers_func();
static DisplayServer *create_func(const String &p_rendering_driver, DisplayServer::WindowMode p_mode, uint32_t p_flags, const Vector2i &p_resolution, Error &r_error); static DisplayServer *create_func(const String &p_rendering_driver, WindowMode p_window_mode, VSyncMode p_vsync_mode, uint32_t p_flags, const Vector2i &p_resolution, Error &r_error);
static void _dispatch_input_event(const Ref<InputEvent> &p_event); static void _dispatch_input_event(const Ref<InputEvent> &p_event);
@ -201,7 +201,7 @@ public:
void swap_buffers() override; void swap_buffers() override;
static void register_javascript_driver(); static void register_javascript_driver();
DisplayServerJavaScript(const String &p_rendering_driver, WindowMode p_mode, uint32_t p_flags, const Vector2i &p_resolution, Error &r_error); 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(); ~DisplayServerJavaScript();
}; };

View File

@ -31,7 +31,6 @@
#include "os_javascript.h" #include "os_javascript.h"
#include "core/debugger/engine_debugger.h" #include "core/debugger/engine_debugger.h"
#include "core/io/json.h"
#include "drivers/unix/dir_access_unix.h" #include "drivers/unix/dir_access_unix.h"
#include "drivers/unix/file_access_unix.h" #include "drivers/unix/file_access_unix.h"
#include "main/main.h" #include "main/main.h"
@ -115,7 +114,7 @@ Error OS_JavaScript::create_process(const String &p_path, const List<String> &p_
for (const List<String>::Element *E = p_arguments.front(); E; E = E->next()) { for (const List<String>::Element *E = p_arguments.front(); E; E = E->next()) {
args.push_back(E->get()); args.push_back(E->get());
} }
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()); 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 JavaScript via 'engine.setOnExecute' if required.");
return OK; return OK;