More small changes to try to stabilise this thing

This commit is contained in:
rodolpheh 2023-12-05 23:16:55 +00:00
parent 533e4bb193
commit 3c71fafe52
6 changed files with 63 additions and 36 deletions

View File

@ -12,6 +12,10 @@
using namespace godot;
UltraleapDeviceList::~UltraleapDeviceList() {
UtilityFunctions::print("Destroying device list");
}
bool UltraleapDeviceList::has_device(Ref<UltraleapDevice> device) {
for (int index = 0; index < devices.size(); index++) {
Ref<UltraleapDevice> dev = devices[index];

View File

@ -17,7 +17,9 @@ class UltraleapDeviceList : public Resource {
GDCLASS(UltraleapDeviceList, Resource);
public:
Array devices = Array();
~UltraleapDeviceList();
Array devices;
bool add_device(Ref<UltraleapDevice> device);
bool remove_device(Ref<UltraleapDevice> device);

View File

@ -112,7 +112,7 @@ void UltraleapDigit::_bind_methods() {
"bones",
PROPERTY_HINT_ARRAY_TYPE,
"UltraleapBone",
PROPERTY_USAGE_READ_ONLY | PROPERTY_USAGE_EDITOR
PROPERTY_USAGE_READ_ONLY | PROPERTY_USAGE_EDITOR | PROPERTY_USAGE_NO_INSTANCE_STATE
),
"",
"get_bones"

View File

@ -221,7 +221,7 @@ void UltraleapHand::_bind_methods() {
"digits",
PROPERTY_HINT_ARRAY_TYPE,
"UltraleapDigit",
PROPERTY_USAGE_READ_ONLY | PROPERTY_USAGE_EDITOR
PROPERTY_USAGE_READ_ONLY | PROPERTY_USAGE_EDITOR | PROPERTY_USAGE_NO_INSTANCE_STATE
),
"",
"get_digits"

View File

@ -27,7 +27,7 @@
using namespace godot;
UltraleapHandTracking::UltraleapHandTracking() {
UtilityFunctions::print("Initializing UltraleapHandTracking");
printf("%p : Initializing UltraleapHandTracking\n", this);
#if ANDROID_ENABLED
// Get and store the binder
@ -35,27 +35,33 @@ UltraleapHandTracking::UltraleapHandTracking() {
binder = Engine::get_singleton()->get_singleton("UltraleapBinder");
}
#endif
devices.instantiate();
}
UltraleapHandTracking::~UltraleapHandTracking() {
UtilityFunctions::print("Destroying UltraleapHandTracking");
printf("%p : Destroying UltraleapHandTracking\n", this);
devices = Ref<UltraleapDeviceList>(NULL);
#if ANDROID_ENABLED
binder = NULL;
#endif
UtilityFunctions::print("UltraleapHandTracking destroyed");
printf("%p : UltraleapHandTracking destroyed\n", this);
}
void UltraleapHandTracking::dispose_ultraleap() {
devices->devices.clear();
if (opened && connectionHandle) {
UtilityFunctions::print("Closing the connection");
printf("%p : Closing the connection\n", this);
LeapCloseConnection(connectionHandle);
opened = false;
}
if (connectionHandle) {
UtilityFunctions::print("Destroying the connection");
printf("%p : Destroying the connection\n", this);
LeapDestroyConnection(connectionHandle);
connectionHandle = NULL;
}
@ -68,7 +74,7 @@ void UltraleapHandTracking::dispose_ultraleap() {
}
#endif
UtilityFunctions::print("Ultraleap was disposed of");
printf("%p : Ultraleap was disposed of\n", this);
}
void UltraleapHandTracking::_bind_methods() {
@ -122,7 +128,7 @@ void UltraleapHandTracking::_bind_methods() {
"last_frame",
PROPERTY_HINT_RESOURCE_TYPE,
"UltraleapFrame",
PROPERTY_USAGE_READ_ONLY | PROPERTY_USAGE_EDITOR
PROPERTY_USAGE_READ_ONLY | PROPERTY_USAGE_EDITOR | PROPERTY_USAGE_NO_INSTANCE_STATE
),
"",
"get_last_frame"
@ -148,7 +154,7 @@ void UltraleapHandTracking::_bind_methods() {
"devices_list",
PROPERTY_HINT_ARRAY_TYPE,
"UltraleapDevice",
PROPERTY_USAGE_READ_ONLY | PROPERTY_USAGE_EDITOR
PROPERTY_USAGE_READ_ONLY | PROPERTY_USAGE_EDITOR | PROPERTY_USAGE_NO_INSTANCE_STATE
),
"",
"get_devices"
@ -161,7 +167,7 @@ void UltraleapHandTracking::_bind_methods() {
"devices_primary_device",
PROPERTY_HINT_RESOURCE_TYPE,
"UltraleapDevice",
PROPERTY_USAGE_READ_ONLY | PROPERTY_USAGE_EDITOR
PROPERTY_USAGE_READ_ONLY | PROPERTY_USAGE_EDITOR | PROPERTY_USAGE_NO_INSTANCE_STATE
),
"set_primary_device",
"get_primary_device"
@ -317,7 +323,7 @@ void UltraleapHandTracking::start() {
return;
}
UtilityFunctions::print("Starting the tracking");
printf("%p : Starting the tracking\n", this);
#ifdef ANDROID_ENABLED
if (binder == NULL) {
@ -368,12 +374,12 @@ void UltraleapHandTracking::start() {
void UltraleapHandTracking::stop() {
if (!started) {
UtilityFunctions::print("Tracking already stopped");
printf("%p : Tracking already stopped\n", this);
return;
}
if (is_running || messageLoop.joinable()) {
UtilityFunctions::print("Stopping the tracking thread");
printf("%p : Stopping the tracking thread\n", this);
keep_running = false;
messageLoop.join();
}
@ -382,16 +388,20 @@ void UltraleapHandTracking::stop() {
started = false;
UtilityFunctions::print("Tracking stopped!");
printf("%p : Tracking stopped!\n", this);
}
void UltraleapHandTracking::handle_connection_event(const LEAP_CONNECTION_EVENT *evt) {
call_deferred_thread_group("emit_signal", "connection_status_changed", true);
if (is_inside_tree()) {
call_deferred_thread_group("emit_signal", "connection_status_changed", true);
}
connected = true;
}
void UltraleapHandTracking::handle_connection_lost_event(const LEAP_CONNECTION_LOST_EVENT *event) {
call_deferred_thread_group("emit_signal", "connection_status_changed", true);
if (is_inside_tree()) {
call_deferred_thread_group("emit_signal", "connection_status_changed", true);
}
connected = false;
// TODO: write something more pretty
@ -622,20 +632,22 @@ void UltraleapHandTracking::handle_policy_change_event(const LEAP_POLICY_EVENT*
bool current_map_points_policy = UltraleapTypes::read_policy_flag(flags, UltraleapTypes::PolicyFlag::MapPoints);
bool current_allow_pause_resume_policy = UltraleapTypes::read_policy_flag(flags, UltraleapTypes::PolicyFlag::AllowPauseResume);
if (current_images_policy != previous_images_policy) {
call_deferred_thread_group("emit_signal", "images_policy_changed", current_images_policy);
}
if (is_inside_tree()) {
if (current_images_policy != previous_images_policy) {
call_deferred_thread_group("emit_signal", "images_policy_changed", current_images_policy);
}
if (current_background_frames_policy != previous_background_frames_policy) {
call_deferred_thread_group("emit_signal", "background_frames_policy_changed", current_background_frames_policy);
}
if (current_background_frames_policy != previous_background_frames_policy) {
call_deferred_thread_group("emit_signal", "background_frames_policy_changed", current_background_frames_policy);
}
if (current_map_points_policy != previous_map_points_policy) {
call_deferred_thread_group("emit_signal", "map_points_policy_changed", current_map_points_policy);
}
if (current_map_points_policy != previous_map_points_policy) {
call_deferred_thread_group("emit_signal", "map_points_policy_changed", current_map_points_policy);
}
if (current_allow_pause_resume_policy != previous_allow_pause_resume_policy) {
call_deferred_thread_group("emit_signal", "allow_pause_resume_policy_changed", current_allow_pause_resume_policy);
if (current_allow_pause_resume_policy != previous_allow_pause_resume_policy) {
call_deferred_thread_group("emit_signal", "allow_pause_resume_policy_changed", current_allow_pause_resume_policy);
}
}
policy_flags = flags;
@ -658,7 +670,7 @@ void UltraleapHandTracking::handle_tracking_mode_event(const LEAP_TRACKING_MODE_
}
if (primary_device != NULL && device_id == primary_device->id) {
if (primary_device->tracking_mode != tm) {
if (primary_device->tracking_mode != tm && is_inside_tree()) {
call_deferred_thread_group("emit_signal", "tracking_mode_changed", tm);
}
}
@ -680,7 +692,9 @@ void UltraleapHandTracking::handle_device_event(const LEAP_DEVICE_EVENT* event)
devices->add_device(dev);
}
call_deferred_thread_group("emit_signal", "device_added", dev);
if (is_inside_tree()) {
call_deferred_thread_group("emit_signal", "device_added", dev);
}
}
void UltraleapHandTracking::handle_device_lost_event(const LEAP_DEVICE_EVENT* event) {
@ -692,7 +706,9 @@ void UltraleapHandTracking::handle_device_lost_event(const LEAP_DEVICE_EVENT* ev
primary_device = Variant::NIL;
}
devices->remove_device(dev);
call_deferred_thread_group("emit_signal", "device_removed", dev);
if (is_inside_tree()) {
call_deferred_thread_group("emit_signal", "device_removed", dev);
}
}
else {
UtilityFunctions::print("Device was not in the list");
@ -748,7 +764,8 @@ Ref<UltraleapDevice> UltraleapHandTracking::create_device(LEAP_DEVICE_REF ref) {
LeapGetDeviceInfo(device, &deviceInfo);
Ref<UltraleapDevice> dev = Ref<UltraleapDevice>(memnew(UltraleapDevice));
Ref<UltraleapDevice> dev;
dev.instantiate();
dev->serial = String(deviceInfo.serial);
dev->baseline = deviceInfo.baseline;
dev->id = ref.id;
@ -764,14 +781,18 @@ Ref<UltraleapDevice> UltraleapHandTracking::create_device(LEAP_DEVICE_REF ref) {
}
void UltraleapHandTracking::_notification(int p_what) {
//UtilityFunctions::print(p_what);
if (p_what == Node::NOTIFICATION_ENTER_TREE) {
printf("%p : Entering tree\n", this);
// For now we will also start automatically if we're in the editor, so that we can have data for tool scripts
if (autostart || Engine::get_singleton()->is_editor_hint()) {
//if (autostart || Engine::get_singleton()->is_editor_hint()) {
// Okay very temporarily, we'll just obey to the flag
if (autostart) {
printf("%p : Autostart is ON\n", this);
start();
}
}
else if (p_what == Node::NOTIFICATION_EXIT_TREE) {
printf("%p : Exiting tree\n", this);
stop();
}
}

View File

@ -40,7 +40,7 @@ public:
bool get_interpolate();
void set_interpolate(bool value);
Ref<UltraleapDeviceList> devices = Ref<UltraleapDeviceList>(memnew(UltraleapDeviceList));
Ref<UltraleapDeviceList> devices;
String service_ip = String("127.0.0.1");
uint16_t service_port = 12345;