2017-04-23 12:10:41 +00:00
|
|
|
/*************************************************************************/
|
2020-04-08 14:47:36 +00:00
|
|
|
/* xr_server.cpp */
|
2017-04-23 12:10:41 +00:00
|
|
|
/*************************************************************************/
|
|
|
|
/* This file is part of: */
|
|
|
|
/* GODOT ENGINE */
|
2017-08-27 12:16:55 +00:00
|
|
|
/* https://godotengine.org */
|
2017-04-23 12:10:41 +00:00
|
|
|
/*************************************************************************/
|
2021-01-01 19:13:46 +00:00
|
|
|
/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */
|
|
|
|
/* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */
|
2017-04-23 12:10:41 +00:00
|
|
|
/* */
|
|
|
|
/* 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. */
|
|
|
|
/*************************************************************************/
|
|
|
|
|
2020-04-08 14:47:36 +00:00
|
|
|
#include "xr_server.h"
|
2020-11-07 22:33:38 +00:00
|
|
|
#include "core/config/project_settings.h"
|
2020-04-08 14:47:36 +00:00
|
|
|
#include "xr/xr_interface.h"
|
|
|
|
#include "xr/xr_positional_tracker.h"
|
2017-04-23 12:10:41 +00:00
|
|
|
|
2020-04-08 14:47:36 +00:00
|
|
|
XRServer *XRServer::singleton = nullptr;
|
2017-04-23 12:10:41 +00:00
|
|
|
|
2020-04-08 14:47:36 +00:00
|
|
|
XRServer *XRServer::get_singleton() {
|
2017-04-23 12:10:41 +00:00
|
|
|
return singleton;
|
|
|
|
};
|
|
|
|
|
2020-04-08 14:47:36 +00:00
|
|
|
void XRServer::_bind_methods() {
|
|
|
|
ClassDB::bind_method(D_METHOD("get_world_scale"), &XRServer::get_world_scale);
|
|
|
|
ClassDB::bind_method(D_METHOD("set_world_scale"), &XRServer::set_world_scale);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_reference_frame"), &XRServer::get_reference_frame);
|
|
|
|
ClassDB::bind_method(D_METHOD("center_on_hmd", "rotation_mode", "keep_height"), &XRServer::center_on_hmd);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_hmd_transform"), &XRServer::get_hmd_transform);
|
2017-04-23 12:10:41 +00:00
|
|
|
|
Variant: Added 64-bit packed arrays, renamed Variant::REAL to FLOAT.
- Renames PackedIntArray to PackedInt32Array.
- Renames PackedFloatArray to PackedFloat32Array.
- Adds PackedInt64Array and PackedFloat64Array.
- Renames Variant::REAL to Variant::FLOAT for consistency.
Packed arrays are for storing large amount of data and creating stuff like
meshes, buffers. textures, etc. Forcing them to be 64 is a huge waste of
memory. That said, many users requested the ability to have 64 bits packed
arrays for their games, so this is just an optional added type.
For Variant, the float datatype is always 64 bits, and exposed as `float`.
We still have `real_t` which is the datatype that can change from 32 to 64
bits depending on a compile flag (not entirely working right now, but that's
the idea). It affects math related datatypes and code only.
Neither Variant nor PackedArray make use of real_t, which is only intended
for math precision, so the term is removed from there to keep only float.
2020-02-24 18:20:53 +00:00
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "world_scale"), "set_world_scale", "get_world_scale");
|
2017-04-23 12:10:41 +00:00
|
|
|
|
2021-03-29 10:15:53 +00:00
|
|
|
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);
|
2020-04-08 14:47:36 +00:00
|
|
|
ClassDB::bind_method(D_METHOD("get_interface_count"), &XRServer::get_interface_count);
|
2021-03-29 10:15:53 +00:00
|
|
|
ClassDB::bind_method(D_METHOD("remove_interface", "interface"), &XRServer::remove_interface);
|
2020-04-08 14:47:36 +00:00
|
|
|
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);
|
2021-03-29 10:15:53 +00:00
|
|
|
ClassDB::bind_method(D_METHOD("add_tracker", "tracker"), &XRServer::add_tracker);
|
|
|
|
ClassDB::bind_method(D_METHOD("remove_tracker", "tracker"), &XRServer::remove_tracker);
|
2017-04-23 12:10:41 +00:00
|
|
|
|
2020-04-08 14:47:36 +00:00
|
|
|
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);
|
2017-04-23 12:10:41 +00:00
|
|
|
|
2018-03-23 17:57:58 +00:00
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "primary_interface"), "set_primary_interface", "get_primary_interface");
|
|
|
|
|
2020-04-08 14:47:36 +00:00
|
|
|
ClassDB::bind_method(D_METHOD("get_last_process_usec"), &XRServer::get_last_process_usec);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_last_commit_usec"), &XRServer::get_last_commit_usec);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_last_frame_usec"), &XRServer::get_last_frame_usec);
|
2018-03-15 11:33:55 +00:00
|
|
|
|
2017-08-20 15:45:01 +00:00
|
|
|
BIND_ENUM_CONSTANT(TRACKER_CONTROLLER);
|
|
|
|
BIND_ENUM_CONSTANT(TRACKER_BASESTATION);
|
|
|
|
BIND_ENUM_CONSTANT(TRACKER_ANCHOR);
|
|
|
|
BIND_ENUM_CONSTANT(TRACKER_ANY_KNOWN);
|
2017-10-21 18:58:02 +00:00
|
|
|
BIND_ENUM_CONSTANT(TRACKER_UNKNOWN);
|
2017-08-20 15:45:01 +00:00
|
|
|
BIND_ENUM_CONSTANT(TRACKER_ANY);
|
2017-04-23 12:10:41 +00:00
|
|
|
|
2017-12-21 12:10:44 +00:00
|
|
|
BIND_ENUM_CONSTANT(RESET_FULL_ROTATION);
|
|
|
|
BIND_ENUM_CONSTANT(RESET_BUT_KEEP_TILT);
|
|
|
|
BIND_ENUM_CONSTANT(DONT_RESET_ROTATION);
|
|
|
|
|
2020-02-20 21:58:05 +00:00
|
|
|
ADD_SIGNAL(MethodInfo("interface_added", PropertyInfo(Variant::STRING_NAME, "interface_name")));
|
|
|
|
ADD_SIGNAL(MethodInfo("interface_removed", PropertyInfo(Variant::STRING_NAME, "interface_name")));
|
2017-04-23 12:10:41 +00:00
|
|
|
|
2020-02-20 21:58:05 +00:00
|
|
|
ADD_SIGNAL(MethodInfo("tracker_added", PropertyInfo(Variant::STRING_NAME, "tracker_name"), PropertyInfo(Variant::INT, "type"), PropertyInfo(Variant::INT, "id")));
|
|
|
|
ADD_SIGNAL(MethodInfo("tracker_removed", PropertyInfo(Variant::STRING_NAME, "tracker_name"), PropertyInfo(Variant::INT, "type"), PropertyInfo(Variant::INT, "id")));
|
2017-04-23 12:10:41 +00:00
|
|
|
};
|
|
|
|
|
2020-04-08 14:47:36 +00:00
|
|
|
real_t XRServer::get_world_scale() const {
|
2017-04-23 12:10:41 +00:00
|
|
|
return world_scale;
|
|
|
|
};
|
|
|
|
|
2020-04-08 14:47:36 +00:00
|
|
|
void XRServer::set_world_scale(real_t p_world_scale) {
|
2019-07-07 21:08:51 +00:00
|
|
|
if (p_world_scale < 0.01) {
|
|
|
|
p_world_scale = 0.01;
|
|
|
|
} else if (p_world_scale > 1000.0) {
|
|
|
|
p_world_scale = 1000.0;
|
|
|
|
}
|
2017-04-23 12:10:41 +00:00
|
|
|
|
|
|
|
world_scale = p_world_scale;
|
|
|
|
};
|
|
|
|
|
2020-10-17 05:08:21 +00:00
|
|
|
Transform3D XRServer::get_world_origin() const {
|
2017-04-23 12:10:41 +00:00
|
|
|
return world_origin;
|
|
|
|
};
|
|
|
|
|
2020-10-17 05:08:21 +00:00
|
|
|
void XRServer::set_world_origin(const Transform3D &p_world_origin) {
|
2017-04-23 12:10:41 +00:00
|
|
|
world_origin = p_world_origin;
|
|
|
|
};
|
|
|
|
|
2020-10-17 05:08:21 +00:00
|
|
|
Transform3D XRServer::get_reference_frame() const {
|
2017-04-23 12:10:41 +00:00
|
|
|
return reference_frame;
|
|
|
|
};
|
|
|
|
|
2020-04-08 14:47:36 +00:00
|
|
|
void XRServer::center_on_hmd(RotationMode p_rotation_mode, bool p_keep_height) {
|
2020-04-01 23:20:12 +00:00
|
|
|
if (primary_interface != nullptr) {
|
2017-04-23 12:10:41 +00:00
|
|
|
// clear our current reference frame or we'll end up double adjusting it
|
2020-10-17 05:08:21 +00:00
|
|
|
reference_frame = Transform3D();
|
2017-04-23 12:10:41 +00:00
|
|
|
|
|
|
|
// requesting our EYE_MONO transform should return our current HMD position
|
2021-05-07 13:19:04 +00:00
|
|
|
Transform3D new_reference_frame = primary_interface->get_camera_transform();
|
2017-04-23 12:10:41 +00:00
|
|
|
|
|
|
|
// remove our tilt
|
2017-12-21 12:10:44 +00:00
|
|
|
if (p_rotation_mode == 1) {
|
2017-04-23 12:10:41 +00:00
|
|
|
// take the Y out of our Z
|
|
|
|
new_reference_frame.basis.set_axis(2, Vector3(new_reference_frame.basis.elements[0][2], 0.0, new_reference_frame.basis.elements[2][2]).normalized());
|
|
|
|
|
|
|
|
// Y is straight up
|
|
|
|
new_reference_frame.basis.set_axis(1, Vector3(0.0, 1.0, 0.0));
|
|
|
|
|
|
|
|
// and X is our cross reference
|
|
|
|
new_reference_frame.basis.set_axis(0, new_reference_frame.basis.get_axis(1).cross(new_reference_frame.basis.get_axis(2)).normalized());
|
2017-12-21 12:10:44 +00:00
|
|
|
} else if (p_rotation_mode == 2) {
|
|
|
|
// remove our rotation, we're only interesting in centering on position
|
|
|
|
new_reference_frame.basis = Basis();
|
2017-04-23 12:10:41 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// don't negate our height
|
|
|
|
if (p_keep_height) {
|
|
|
|
new_reference_frame.origin.y = 0.0;
|
|
|
|
};
|
|
|
|
|
|
|
|
reference_frame = new_reference_frame.inverse();
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2020-10-17 05:08:21 +00:00
|
|
|
Transform3D XRServer::get_hmd_transform() {
|
|
|
|
Transform3D hmd_transform;
|
2020-04-01 23:20:12 +00:00
|
|
|
if (primary_interface != nullptr) {
|
2021-05-07 13:19:04 +00:00
|
|
|
hmd_transform = primary_interface->get_camera_transform();
|
2018-03-15 11:33:55 +00:00
|
|
|
};
|
|
|
|
return hmd_transform;
|
|
|
|
};
|
|
|
|
|
2020-04-08 14:47:36 +00:00
|
|
|
void XRServer::add_interface(const Ref<XRInterface> &p_interface) {
|
2017-04-23 12:10:41 +00:00
|
|
|
ERR_FAIL_COND(p_interface.is_null());
|
|
|
|
|
|
|
|
for (int i = 0; i < interfaces.size(); i++) {
|
|
|
|
if (interfaces[i] == p_interface) {
|
|
|
|
ERR_PRINT("Interface was already added");
|
|
|
|
return;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
interfaces.push_back(p_interface);
|
2021-07-17 21:22:52 +00:00
|
|
|
emit_signal(SNAME("interface_added"), p_interface->get_name());
|
2017-04-23 12:10:41 +00:00
|
|
|
};
|
|
|
|
|
2020-04-08 14:47:36 +00:00
|
|
|
void XRServer::remove_interface(const Ref<XRInterface> &p_interface) {
|
2017-04-23 12:10:41 +00:00
|
|
|
ERR_FAIL_COND(p_interface.is_null());
|
|
|
|
|
|
|
|
int idx = -1;
|
|
|
|
for (int i = 0; i < interfaces.size(); i++) {
|
|
|
|
if (interfaces[i] == p_interface) {
|
|
|
|
idx = i;
|
|
|
|
break;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
ERR_FAIL_COND(idx == -1);
|
|
|
|
|
2020-04-08 14:47:36 +00:00
|
|
|
print_verbose("XR: Removed interface" + p_interface->get_name());
|
2017-04-23 12:10:41 +00:00
|
|
|
|
2021-07-17 21:22:52 +00:00
|
|
|
emit_signal(SNAME("interface_removed"), p_interface->get_name());
|
2017-04-23 12:10:41 +00:00
|
|
|
interfaces.remove(idx);
|
|
|
|
};
|
|
|
|
|
2020-04-08 14:47:36 +00:00
|
|
|
int XRServer::get_interface_count() const {
|
2017-04-23 12:10:41 +00:00
|
|
|
return interfaces.size();
|
|
|
|
};
|
|
|
|
|
2020-04-08 14:47:36 +00:00
|
|
|
Ref<XRInterface> XRServer::get_interface(int p_index) const {
|
2020-04-01 23:20:12 +00:00
|
|
|
ERR_FAIL_INDEX_V(p_index, interfaces.size(), nullptr);
|
2017-04-23 12:10:41 +00:00
|
|
|
|
|
|
|
return interfaces[p_index];
|
|
|
|
};
|
|
|
|
|
2020-04-08 14:47:36 +00:00
|
|
|
Ref<XRInterface> XRServer::find_interface(const String &p_name) const {
|
2017-04-23 12:10:41 +00:00
|
|
|
int idx = -1;
|
|
|
|
for (int i = 0; i < interfaces.size(); i++) {
|
|
|
|
if (interfaces[i]->get_name() == p_name) {
|
|
|
|
idx = i;
|
|
|
|
break;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2020-04-01 23:20:12 +00:00
|
|
|
ERR_FAIL_COND_V(idx == -1, nullptr);
|
2017-04-23 12:10:41 +00:00
|
|
|
|
|
|
|
return interfaces[idx];
|
|
|
|
};
|
|
|
|
|
2020-04-08 14:47:36 +00:00
|
|
|
Array XRServer::get_interfaces() const {
|
2017-11-04 00:50:05 +00:00
|
|
|
Array ret;
|
|
|
|
|
|
|
|
for (int i = 0; i < interfaces.size(); i++) {
|
|
|
|
Dictionary iface_info;
|
|
|
|
|
|
|
|
iface_info["id"] = i;
|
|
|
|
iface_info["name"] = interfaces[i]->get_name();
|
|
|
|
|
|
|
|
ret.push_back(iface_info);
|
|
|
|
};
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
};
|
|
|
|
|
2017-04-23 12:10:41 +00:00
|
|
|
/*
|
2018-01-18 20:37:17 +00:00
|
|
|
A little extra info on the tracker ids, these are unique per tracker type so we get some consistency in recognising our trackers, specifically controllers.
|
2017-04-23 12:10:41 +00:00
|
|
|
|
|
|
|
The first controller that is turned of will get ID 1, the second will get ID 2, etc.
|
|
|
|
The magic happens when one of the controllers is turned off, say controller 1 turns off, controller 2 will remain controller 2, controller 3 will remain controller 3.
|
|
|
|
If controller number 1 is turned on again it again gets ID 1 unless another new controller was turned on since.
|
|
|
|
|
|
|
|
The most likely scenario however is a controller that runs out of battery and another controller being used to replace it.
|
|
|
|
Because the controllers are often linked to physical objects, say you're holding a shield in controller 1, your left hand, and a gun in controller 2, your right hand, and controller 1 dies:
|
|
|
|
- using our tracker index would suddenly make the gun disappear and the shield jump into your right hand because controller 2 becomes controller 1.
|
|
|
|
- using this approach the shield disappears or is no longer tracked, but the gun stays firmly in your right hand because that is still controller 2, further more, if controller 1 is replaced the shield will return.
|
|
|
|
*/
|
|
|
|
|
2020-04-08 14:47:36 +00:00
|
|
|
bool XRServer::is_tracker_id_in_use_for_type(TrackerType p_tracker_type, int p_tracker_id) const {
|
2017-04-23 12:10:41 +00:00
|
|
|
for (int i = 0; i < trackers.size(); i++) {
|
2020-04-15 19:22:14 +00:00
|
|
|
if (trackers[i]->get_tracker_type() == p_tracker_type && trackers[i]->get_tracker_id() == p_tracker_id) {
|
2017-04-23 12:10:41 +00:00
|
|
|
return true;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
// all good
|
|
|
|
return false;
|
|
|
|
};
|
|
|
|
|
2020-04-08 14:47:36 +00:00
|
|
|
int XRServer::get_free_tracker_id_for_type(TrackerType p_tracker_type) {
|
2017-12-21 12:10:44 +00:00
|
|
|
// We start checking at 1, 0 means that it's not a controller..
|
|
|
|
// Note that for controller we reserve:
|
|
|
|
// - 1 for the left hand controller and
|
|
|
|
// - 2 for the right hand controller
|
|
|
|
// so we start at 3 :)
|
2020-04-08 14:47:36 +00:00
|
|
|
int tracker_id = p_tracker_type == XRServer::TRACKER_CONTROLLER ? 3 : 1;
|
2017-04-23 12:10:41 +00:00
|
|
|
|
|
|
|
while (is_tracker_id_in_use_for_type(p_tracker_type, tracker_id)) {
|
|
|
|
// try the next one
|
|
|
|
tracker_id++;
|
|
|
|
};
|
|
|
|
|
|
|
|
return tracker_id;
|
|
|
|
};
|
|
|
|
|
2021-03-29 10:15:53 +00:00
|
|
|
void XRServer::add_tracker(Ref<XRPositionalTracker> p_tracker) {
|
|
|
|
ERR_FAIL_COND(p_tracker.is_null());
|
2017-04-23 12:10:41 +00:00
|
|
|
|
|
|
|
trackers.push_back(p_tracker);
|
2021-07-17 21:22:52 +00:00
|
|
|
emit_signal(SNAME("tracker_added"), p_tracker->get_tracker_name(), p_tracker->get_tracker_type(), p_tracker->get_tracker_id());
|
2017-04-23 12:10:41 +00:00
|
|
|
};
|
|
|
|
|
2021-03-29 10:15:53 +00:00
|
|
|
void XRServer::remove_tracker(Ref<XRPositionalTracker> p_tracker) {
|
|
|
|
ERR_FAIL_COND(p_tracker.is_null());
|
2017-04-23 12:10:41 +00:00
|
|
|
|
|
|
|
int idx = -1;
|
|
|
|
for (int i = 0; i < trackers.size(); i++) {
|
|
|
|
if (trackers[i] == p_tracker) {
|
|
|
|
idx = i;
|
|
|
|
break;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
ERR_FAIL_COND(idx == -1);
|
|
|
|
|
2021-07-17 21:22:52 +00:00
|
|
|
emit_signal(SNAME("tracker_removed"), p_tracker->get_tracker_name(), p_tracker->get_tracker_type(), p_tracker->get_tracker_id());
|
2017-04-23 12:10:41 +00:00
|
|
|
trackers.remove(idx);
|
|
|
|
};
|
|
|
|
|
2020-04-08 14:47:36 +00:00
|
|
|
int XRServer::get_tracker_count() const {
|
2017-04-23 12:10:41 +00:00
|
|
|
return trackers.size();
|
|
|
|
};
|
|
|
|
|
2021-03-29 10:15:53 +00:00
|
|
|
Ref<XRPositionalTracker> XRServer::get_tracker(int p_index) const {
|
|
|
|
ERR_FAIL_INDEX_V(p_index, trackers.size(), Ref<XRPositionalTracker>());
|
2017-04-23 12:10:41 +00:00
|
|
|
|
|
|
|
return trackers[p_index];
|
|
|
|
};
|
|
|
|
|
2021-03-29 10:15:53 +00:00
|
|
|
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>());
|
2017-04-23 12:10:41 +00:00
|
|
|
|
|
|
|
for (int i = 0; i < trackers.size(); i++) {
|
2020-04-15 19:22:14 +00:00
|
|
|
if (trackers[i]->get_tracker_type() == p_tracker_type && trackers[i]->get_tracker_id() == p_tracker_id) {
|
2017-04-23 12:10:41 +00:00
|
|
|
return trackers[i];
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2021-03-29 10:15:53 +00:00
|
|
|
return Ref<XRPositionalTracker>();
|
2017-04-23 12:10:41 +00:00
|
|
|
};
|
|
|
|
|
2020-04-08 14:47:36 +00:00
|
|
|
Ref<XRInterface> XRServer::get_primary_interface() const {
|
2017-04-23 12:10:41 +00:00
|
|
|
return primary_interface;
|
|
|
|
};
|
|
|
|
|
2020-04-08 14:47:36 +00:00
|
|
|
void XRServer::set_primary_interface(const Ref<XRInterface> &p_primary_interface) {
|
2021-03-25 13:49:17 +00:00
|
|
|
ERR_FAIL_COND(p_primary_interface.is_null());
|
2017-04-23 12:10:41 +00:00
|
|
|
primary_interface = p_primary_interface;
|
|
|
|
|
2020-04-08 14:47:36 +00:00
|
|
|
print_verbose("XR: Primary interface set to: " + primary_interface->get_name());
|
2017-04-23 12:10:41 +00:00
|
|
|
};
|
|
|
|
|
2020-04-08 14:47:36 +00:00
|
|
|
void XRServer::clear_primary_interface_if(const Ref<XRInterface> &p_primary_interface) {
|
2017-04-23 12:10:41 +00:00
|
|
|
if (primary_interface == p_primary_interface) {
|
2020-04-08 14:47:36 +00:00
|
|
|
print_verbose("XR: Clearing primary interface");
|
2017-04-23 12:10:41 +00:00
|
|
|
primary_interface.unref();
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2020-04-08 14:47:36 +00:00
|
|
|
uint64_t XRServer::get_last_process_usec() {
|
2018-03-15 11:33:55 +00:00
|
|
|
return last_process_usec;
|
|
|
|
};
|
|
|
|
|
2020-04-08 14:47:36 +00:00
|
|
|
uint64_t XRServer::get_last_commit_usec() {
|
2018-03-15 11:33:55 +00:00
|
|
|
return last_commit_usec;
|
|
|
|
};
|
|
|
|
|
2020-04-08 14:47:36 +00:00
|
|
|
uint64_t XRServer::get_last_frame_usec() {
|
2018-03-15 11:33:55 +00:00
|
|
|
return last_frame_usec;
|
|
|
|
};
|
|
|
|
|
2020-04-08 14:47:36 +00:00
|
|
|
void XRServer::_process() {
|
2020-12-04 18:26:24 +00:00
|
|
|
/* called from renderer_viewport.draw_viewports right before we start drawing our viewports */
|
2018-03-15 11:33:55 +00:00
|
|
|
|
|
|
|
/* mark for our frame timing */
|
|
|
|
last_process_usec = OS::get_singleton()->get_ticks_usec();
|
|
|
|
|
|
|
|
/* process all active interfaces */
|
|
|
|
for (int i = 0; i < interfaces.size(); i++) {
|
|
|
|
if (!interfaces[i].is_valid()) {
|
|
|
|
// ignore, not a valid reference
|
|
|
|
} else if (interfaces[i]->is_initialized()) {
|
2018-07-25 01:11:03 +00:00
|
|
|
interfaces.write[i]->process();
|
2018-03-15 11:33:55 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2020-04-08 14:47:36 +00:00
|
|
|
void XRServer::_mark_commit() {
|
2018-03-15 11:33:55 +00:00
|
|
|
/* time this */
|
|
|
|
last_commit_usec = OS::get_singleton()->get_ticks_usec();
|
|
|
|
|
|
|
|
/* now store our difference as we may overwrite last_process_usec before this is accessed */
|
|
|
|
last_frame_usec = last_commit_usec - last_process_usec;
|
|
|
|
};
|
|
|
|
|
2020-04-08 14:47:36 +00:00
|
|
|
XRServer::XRServer() {
|
2017-04-23 12:10:41 +00:00
|
|
|
singleton = this;
|
|
|
|
world_scale = 1.0;
|
|
|
|
};
|
|
|
|
|
2020-04-08 14:47:36 +00:00
|
|
|
XRServer::~XRServer() {
|
2017-04-23 12:10:41 +00:00
|
|
|
primary_interface.unref();
|
|
|
|
|
|
|
|
while (interfaces.size() > 0) {
|
|
|
|
interfaces.remove(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
while (trackers.size() > 0) {
|
|
|
|
trackers.remove(0);
|
|
|
|
}
|
|
|
|
|
2020-04-01 23:20:12 +00:00
|
|
|
singleton = nullptr;
|
2017-04-23 12:10:41 +00:00
|
|
|
};
|