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 /servers | |
parent | 02471ba44d4b00af51af7bb3061437c6001d2c88 (diff) |
Change XRPositionalTracker to a reference and better expose it to GDNative
Diffstat (limited to 'servers')
-rw-r--r-- | servers/xr/xr_positional_tracker.h | 4 | ||||
-rw-r--r-- | servers/xr_server.cpp | 23 | ||||
-rw-r--r-- | servers/xr_server.h | 10 |
3 files changed, 21 insertions, 16 deletions
diff --git a/servers/xr/xr_positional_tracker.h b/servers/xr/xr_positional_tracker.h index 420d818342..a5c6459471 100644 --- a/servers/xr/xr_positional_tracker.h +++ b/servers/xr/xr_positional_tracker.h @@ -43,8 +43,8 @@ This is where potentially additional AR/VR interfaces may be active as there are AR/VR SDKs that solely deal with positional tracking. */ -class XRPositionalTracker : public Object { - GDCLASS(XRPositionalTracker, Object); +class XRPositionalTracker : public Reference { + GDCLASS(XRPositionalTracker, Reference); _THREAD_SAFE_CLASS_ public: diff --git a/servers/xr_server.cpp b/servers/xr_server.cpp index 7087ae4947..5678071857 100644 --- a/servers/xr_server.cpp +++ b/servers/xr_server.cpp @@ -48,12 +48,17 @@ void XRServer::_bind_methods() { ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "world_scale"), "set_world_scale", "get_world_scale"); + ClassDB::bind_method(D_METHOD("add_interface", "interface"), &XRServer::add_interface); + ClassDB::bind_method(D_METHOD("clear_primary_interface_if", "interface"), &XRServer::clear_primary_interface_if); ClassDB::bind_method(D_METHOD("get_interface_count"), &XRServer::get_interface_count); + ClassDB::bind_method(D_METHOD("remove_interface", "interface"), &XRServer::remove_interface); ClassDB::bind_method(D_METHOD("get_interface", "idx"), &XRServer::get_interface); ClassDB::bind_method(D_METHOD("get_interfaces"), &XRServer::get_interfaces); ClassDB::bind_method(D_METHOD("find_interface", "name"), &XRServer::find_interface); ClassDB::bind_method(D_METHOD("get_tracker_count"), &XRServer::get_tracker_count); ClassDB::bind_method(D_METHOD("get_tracker", "idx"), &XRServer::get_tracker); + ClassDB::bind_method(D_METHOD("add_tracker", "tracker"), &XRServer::add_tracker); + ClassDB::bind_method(D_METHOD("remove_tracker", "tracker"), &XRServer::remove_tracker); ClassDB::bind_method(D_METHOD("get_primary_interface"), &XRServer::get_primary_interface); ClassDB::bind_method(D_METHOD("set_primary_interface", "interface"), &XRServer::set_primary_interface); @@ -260,15 +265,15 @@ int XRServer::get_free_tracker_id_for_type(TrackerType p_tracker_type) { return tracker_id; }; -void XRServer::add_tracker(XRPositionalTracker *p_tracker) { - ERR_FAIL_NULL(p_tracker); +void XRServer::add_tracker(Ref<XRPositionalTracker> p_tracker) { + ERR_FAIL_COND(p_tracker.is_null()); trackers.push_back(p_tracker); emit_signal("tracker_added", p_tracker->get_tracker_name(), p_tracker->get_tracker_type(), p_tracker->get_tracker_id()); }; -void XRServer::remove_tracker(XRPositionalTracker *p_tracker) { - ERR_FAIL_NULL(p_tracker); +void XRServer::remove_tracker(Ref<XRPositionalTracker> p_tracker) { + ERR_FAIL_COND(p_tracker.is_null()); int idx = -1; for (int i = 0; i < trackers.size(); i++) { @@ -288,14 +293,14 @@ int XRServer::get_tracker_count() const { return trackers.size(); }; -XRPositionalTracker *XRServer::get_tracker(int p_index) const { - ERR_FAIL_INDEX_V(p_index, trackers.size(), nullptr); +Ref<XRPositionalTracker> XRServer::get_tracker(int p_index) const { + ERR_FAIL_INDEX_V(p_index, trackers.size(), Ref<XRPositionalTracker>()); return trackers[p_index]; }; -XRPositionalTracker *XRServer::find_by_type_and_id(TrackerType p_tracker_type, int p_tracker_id) const { - ERR_FAIL_COND_V(p_tracker_id == 0, nullptr); +Ref<XRPositionalTracker> XRServer::find_by_type_and_id(TrackerType p_tracker_type, int p_tracker_id) const { + ERR_FAIL_COND_V(p_tracker_id == 0, Ref<XRPositionalTracker>()); for (int i = 0; i < trackers.size(); i++) { if (trackers[i]->get_tracker_type() == p_tracker_type && trackers[i]->get_tracker_id() == p_tracker_id) { @@ -303,7 +308,7 @@ XRPositionalTracker *XRServer::find_by_type_and_id(TrackerType p_tracker_type, i }; }; - return nullptr; + return Ref<XRPositionalTracker>(); }; Ref<XRInterface> XRServer::get_primary_interface() const { diff --git a/servers/xr_server.h b/servers/xr_server.h index d3972be838..46243d7fd0 100644 --- a/servers/xr_server.h +++ b/servers/xr_server.h @@ -77,7 +77,7 @@ public: private: Vector<Ref<XRInterface>> interfaces; - Vector<XRPositionalTracker *> trackers; + Vector<Ref<XRPositionalTracker>> trackers; Ref<XRInterface> primary_interface; /* we'll identify one interface as primary, this will be used by our viewports */ @@ -167,11 +167,11 @@ public: */ bool is_tracker_id_in_use_for_type(TrackerType p_tracker_type, int p_tracker_id) const; int get_free_tracker_id_for_type(TrackerType p_tracker_type); - void add_tracker(XRPositionalTracker *p_tracker); - void remove_tracker(XRPositionalTracker *p_tracker); + void add_tracker(Ref<XRPositionalTracker> p_tracker); + void remove_tracker(Ref<XRPositionalTracker> p_tracker); int get_tracker_count() const; - XRPositionalTracker *get_tracker(int p_index) const; - XRPositionalTracker *find_by_type_and_id(TrackerType p_tracker_type, int p_tracker_id) const; + Ref<XRPositionalTracker> get_tracker(int p_index) const; + Ref<XRPositionalTracker> find_by_type_and_id(TrackerType p_tracker_type, int p_tracker_id) const; uint64_t get_last_process_usec(); uint64_t get_last_commit_usec(); |