diff options
author | Bastiaan Olij <mux213@gmail.com> | 2021-03-29 21:15:53 +1100 |
---|---|---|
committer | Bastiaan Olij <mux213@gmail.com> | 2021-03-29 23:01:47 +1100 |
commit | 454c889e616917021379ebff5bde3f458cd68eb2 (patch) | |
tree | f2ffcdd0782015404289558d3b39bcd0d9cbcb50 /modules | |
parent | 02471ba44d4b00af51af7bb3061437c6001d2c88 (diff) |
Change XRPositionalTracker to a reference and better expose it to GDNative
Diffstat (limited to 'modules')
-rw-r--r-- | modules/gdnative/xr/xr_interface_gdnative.cpp | 25 | ||||
-rw-r--r-- | modules/webxr/webxr_interface.h | 2 | ||||
-rw-r--r-- | modules/webxr/webxr_interface_js.cpp | 10 | ||||
-rw-r--r-- | modules/webxr/webxr_interface_js.h | 2 |
4 files changed, 20 insertions, 19 deletions
diff --git a/modules/gdnative/xr/xr_interface_gdnative.cpp b/modules/gdnative/xr/xr_interface_gdnative.cpp index 1d5a9d98f8..122cb5849b 100644 --- a/modules/gdnative/xr/xr_interface_gdnative.cpp +++ b/modules/gdnative/xr/xr_interface_gdnative.cpp @@ -301,7 +301,8 @@ godot_int GDAPI godot_xr_add_controller(char *p_device_name, godot_int p_hand, g Input *input = Input::get_singleton(); ERR_FAIL_NULL_V(input, 0); - XRPositionalTracker *new_tracker = memnew(XRPositionalTracker); + Ref<XRPositionalTracker> new_tracker; + new_tracker.instance(); new_tracker->set_tracker_name(p_device_name); new_tracker->set_tracker_type(XRServer::TRACKER_CONTROLLER); if (p_hand == 1) { @@ -340,8 +341,8 @@ void GDAPI godot_xr_remove_controller(godot_int p_controller_id) { Input *input = Input::get_singleton(); ERR_FAIL_NULL(input); - XRPositionalTracker *remove_tracker = xr_server->find_by_type_and_id(XRServer::TRACKER_CONTROLLER, p_controller_id); - if (remove_tracker != nullptr) { + Ref<XRPositionalTracker> remove_tracker = xr_server->find_by_type_and_id(XRServer::TRACKER_CONTROLLER, p_controller_id); + if (remove_tracker.is_valid()) { // unset our joystick if applicable int joyid = remove_tracker->get_joy_id(); if (joyid != -1) { @@ -351,7 +352,7 @@ void GDAPI godot_xr_remove_controller(godot_int p_controller_id) { // remove our tracker from our server xr_server->remove_tracker(remove_tracker); - memdelete(remove_tracker); + remove_tracker.unref(); } } @@ -359,8 +360,8 @@ void GDAPI godot_xr_set_controller_transform(godot_int p_controller_id, godot_tr XRServer *xr_server = XRServer::get_singleton(); ERR_FAIL_NULL(xr_server); - XRPositionalTracker *tracker = xr_server->find_by_type_and_id(XRServer::TRACKER_CONTROLLER, p_controller_id); - if (tracker != nullptr) { + Ref<XRPositionalTracker> tracker = xr_server->find_by_type_and_id(XRServer::TRACKER_CONTROLLER, p_controller_id); + if (tracker.is_valid()) { Transform *transform = (Transform *)p_transform; if (p_tracks_orientation) { tracker->set_orientation(transform->basis); @@ -378,8 +379,8 @@ void GDAPI godot_xr_set_controller_button(godot_int p_controller_id, godot_int p Input *input = Input::get_singleton(); ERR_FAIL_NULL(input); - XRPositionalTracker *tracker = xr_server->find_by_type_and_id(XRServer::TRACKER_CONTROLLER, p_controller_id); - if (tracker != nullptr) { + Ref<XRPositionalTracker> tracker = xr_server->find_by_type_and_id(XRServer::TRACKER_CONTROLLER, p_controller_id); + if (tracker.is_valid()) { int joyid = tracker->get_joy_id(); if (joyid != -1) { input->joy_button(joyid, p_button, p_is_pressed); @@ -394,8 +395,8 @@ void GDAPI godot_xr_set_controller_axis(godot_int p_controller_id, godot_int p_a Input *input = Input::get_singleton(); ERR_FAIL_NULL(input); - XRPositionalTracker *tracker = xr_server->find_by_type_and_id(XRServer::TRACKER_CONTROLLER, p_controller_id); - if (tracker != nullptr) { + Ref<XRPositionalTracker> tracker = xr_server->find_by_type_and_id(XRServer::TRACKER_CONTROLLER, p_controller_id); + if (tracker.is_valid()) { int joyid = tracker->get_joy_id(); if (joyid != -1) { Input::JoyAxisValue jx; @@ -410,8 +411,8 @@ godot_float GDAPI godot_xr_get_controller_rumble(godot_int p_controller_id) { XRServer *xr_server = XRServer::get_singleton(); ERR_FAIL_NULL_V(xr_server, 0.0); - XRPositionalTracker *tracker = xr_server->find_by_type_and_id(XRServer::TRACKER_CONTROLLER, p_controller_id); - if (tracker != nullptr) { + Ref<XRPositionalTracker> tracker = xr_server->find_by_type_and_id(XRServer::TRACKER_CONTROLLER, p_controller_id); + if (tracker.is_valid()) { return tracker->get_rumble(); } diff --git a/modules/webxr/webxr_interface.h b/modules/webxr/webxr_interface.h index c5b2dc8d73..366235fcd5 100644 --- a/modules/webxr/webxr_interface.h +++ b/modules/webxr/webxr_interface.h @@ -57,7 +57,7 @@ public: virtual void set_requested_reference_space_types(String p_requested_reference_space_types) = 0; virtual String get_requested_reference_space_types() const = 0; virtual String get_reference_space_type() const = 0; - virtual XRPositionalTracker *get_controller(int p_controller_id) const = 0; + virtual Ref<XRPositionalTracker> get_controller(int p_controller_id) const = 0; virtual String get_visibility_state() const = 0; virtual PackedVector3Array get_bounds_geometry() const = 0; }; diff --git a/modules/webxr/webxr_interface_js.cpp b/modules/webxr/webxr_interface_js.cpp index 10076327e2..4dce2c2b23 100644 --- a/modules/webxr/webxr_interface_js.cpp +++ b/modules/webxr/webxr_interface_js.cpp @@ -160,7 +160,7 @@ String WebXRInterfaceJS::get_reference_space_type() const { return reference_space_type; } -XRPositionalTracker *WebXRInterfaceJS::get_controller(int p_controller_id) const { +Ref<XRPositionalTracker> WebXRInterfaceJS::get_controller(int p_controller_id) const { XRServer *xr_server = XRServer::get_singleton(); ERR_FAIL_NULL_V(xr_server, nullptr); @@ -380,10 +380,10 @@ void WebXRInterfaceJS::_update_tracker(int p_controller_id) { XRServer *xr_server = XRServer::get_singleton(); ERR_FAIL_NULL(xr_server); - XRPositionalTracker *tracker = xr_server->find_by_type_and_id(XRServer::TRACKER_CONTROLLER, p_controller_id + 1); + Ref<XRPositionalTracker> tracker = xr_server->find_by_type_and_id(XRServer::TRACKER_CONTROLLER, p_controller_id + 1); if (godot_webxr_is_controller_connected(p_controller_id)) { - if (tracker == nullptr) { - tracker = memnew(XRPositionalTracker); + if (tracker.is_null()) { + tracker.instance(); tracker->set_tracker_type(XRServer::TRACKER_CONTROLLER); // Controller id's 0 and 1 are always the left and right hands. if (p_controller_id < 2) { @@ -423,7 +423,7 @@ void WebXRInterfaceJS::_update_tracker(int p_controller_id) { } free(axes); } - } else if (tracker) { + } else if (tracker.is_valid()) { xr_server->remove_tracker(tracker); } } diff --git a/modules/webxr/webxr_interface_js.h b/modules/webxr/webxr_interface_js.h index 49299b252f..7c841c1911 100644 --- a/modules/webxr/webxr_interface_js.h +++ b/modules/webxr/webxr_interface_js.h @@ -71,7 +71,7 @@ public: virtual String get_requested_reference_space_types() const override; void _set_reference_space_type(String p_reference_space_type); virtual String get_reference_space_type() const override; - virtual XRPositionalTracker *get_controller(int p_controller_id) const override; + virtual Ref<XRPositionalTracker> get_controller(int p_controller_id) const override; virtual String get_visibility_state() const override; virtual PackedVector3Array get_bounds_geometry() const override; |