Skip to content

Commit

Permalink
Avoid frame pointers in _physics_process to get the demo running
Browse files Browse the repository at this point in the history
  • Loading branch information
georgewsinger committed Aug 10, 2021
1 parent e49cc7f commit 9782b7b
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 27 deletions.
1 change: 0 additions & 1 deletion SConstruct
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,6 @@ elif env['platform'] in ('x11', 'linux'):
else:
env.Append(CCFLAGS = ['-fPIC', '-g','-O3', '-std=c++17'])
env.Append(CXXFLAGS='-std=c++0x')
env.Append(CXXFLAGS=["-fpermissive"])
env.Append(LINKFLAGS = ['-Wl,-R,\'$$ORIGIN\''])
if env['bits'] == '64':
leapsdk_lib = 'libLeap.so' # leapsdk_lib # + 'lib/x64/libLeap.so'
Expand Down
57 changes: 34 additions & 23 deletions src/gdlm_sensor.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include "gdlm_sensor.h"
#include <iostream>

#define PI 3.14159265359f

Expand Down Expand Up @@ -60,7 +61,6 @@ GDLMSensor::GDLMSensor() {
arvr = false;
keep_last_hand = true;
smooth_factor = 0.5;
last_frame = NULL;
last_device = NULL;
last_frame_id = 0;
keep_hands_for_frames = 60;
Expand Down Expand Up @@ -123,7 +123,7 @@ GDLMSensor::~GDLMSensor() {
}

// and clear this JIC
last_frame = NULL;
last_frame = Leap::Frame();

// finally clean up hands, note that we don't need to free our scenes because they will be removed by Godot.
while (hand_nodes.size() > 0) {
Expand Down Expand Up @@ -207,9 +207,9 @@ bool GDLMSensor::wait_for_connection(int timeout, int waittime) {
}

//const LEAP_TRACKING_EVENT *GDLMSensor::get_last_frame() {
Leap::Frame *GDLMSensor::get_last_frame() {
Leap::Frame GDLMSensor::get_last_frame() {
//const LEAP_TRACKING_EVENT *ret;
Leap::Frame *ret;
Leap::Frame ret;

// lock();
ret = last_frame;
Expand All @@ -219,7 +219,7 @@ Leap::Frame *GDLMSensor::get_last_frame() {
}

//void GDLMSensor::set_last_frame(const LEAP_TRACKING_EVENT *p_frame) {
void GDLMSensor::set_last_frame(Leap::Frame *p_frame) {
void GDLMSensor::set_last_frame(Leap::Frame p_frame) {
// lock();
last_frame = p_frame;
// unlock();
Expand Down Expand Up @@ -678,7 +678,7 @@ void GDLMSensor::_physics_process(float delta) {
//LEAP_TRACKING_EVENT *interpolated_frame = NULL;
//const LEAP_TRACKING_EVENT *frame = NULL;
printf("_physics_process\n");
Leap::Frame * frame;
Leap::Frame frame;
uint64_t arvr_frame_usec;

// We're getting our measurements in mm, want them in m
Expand Down Expand Up @@ -738,27 +738,27 @@ void GDLMSensor::_physics_process(float delta) {
}
}
*/
frame = &controller.frame();
last_frame = &controller.frame(); //hack
frame = controller.frame();
last_frame = controller.frame(); //hack

} else {
// ok lets process our last frame. Note that leap motion says it caches these so I'm assuming they
// are valid for a few frames.
frame = get_last_frame();
}

auto numHands = controller.frame().hands().count();
printf ("numHands: %d\n", numHands);
frame = controller.frame(); //haaack
// was everything above successful?
if (frame == NULL) {
// we don't have a frame yet, or we failed upstairs..
return;
//} else if (!arvr && (last_frame_id == frame->info.frame_id)) {
} else if (!arvr && (last_frame_id == frame->id())) {
if (!arvr && (last_frame_id == frame.id())) {
// we already parsed this, no need to do this. In ARVR we may need to do more
printf("physics process returning early2\n");
return;
}

//last_frame_id = frame->info.frame_id;
last_frame_id = frame->id();
last_frame_id = frame.id();

// Lets process our frames...

Expand All @@ -773,23 +773,23 @@ void GDLMSensor::_physics_process(float delta) {

// process the hands we're getting from leap motion
//for (uint32_t h = 0; h < frame->nHands; h++) {
for (uint32_t h = 0; h < frame->hands().count(); h++) {
for (uint32_t h = 0; h < frame.hands().count(); h++) {
//LEAP_HAND *hand = &frame->pHands[h];
Leap::Hand *hand = &frame->hands()[h];
Leap::Hand hand = frame.hands()[h];
//int type = hand->type == eLeapHandType_Left ? 0 : 1;
int type = hand->isLeft() ? 0 : 1;
int type = hand.isLeft() ? 0 : 1;

// see if we already have a scene for this hand
//hand_data *hd = find_hand_by_id(type, hand->id);
hand_data *hd = find_hand_by_id(type, hand->id());
hand_data *hd = find_hand_by_id(type, hand.id());
if (hd == NULL) {
// nope? then see if we can find a hand we lost tracking for
hd = find_unused_hand(type);
}
if (hd == NULL) {
// nope? time to get a new hand
//hd = new_hand(type, hand->id);
hd = new_hand(type, hand->id());
hd = new_hand(type, hand.id());
if (hd != NULL) {
hand_nodes.push_back(hd);
}
Expand All @@ -799,11 +799,11 @@ void GDLMSensor::_physics_process(float delta) {
hd->active_this_frame = true;
hd->unused_frames = 0;
//hd->leap_id = hand->id;
hd->leap_id = hand->id();
hd->leap_id = hand.id();

// and update
update_hand_data(hd, hand);
update_hand_position(hd, hand);
update_hand_data(hd, &hand);
update_hand_position(hd, &hand);

// should make sure hand is visible
}
Expand Down Expand Up @@ -986,10 +986,21 @@ void GDLMSensor::handleTrackingEvent(const LEAP_TRACKING_EVENT *tracking_event)
}
*/
void GDLMListener::onFrame(const Leap::Controller &controller) {
/*
printf("LeapMotion - onFrame\n");
// Leap::Frame frame = controller->frame();
// GDLMSensor *sensor = (GDLMSensor *)controller;
// sensor->set_last_frame(&frame);
// Get the most recent frame and report some basic information
const Leap::Frame frame = controller.frame();
std::cout << "Frame id: " << frame.id()
<< ", timestamp: " << frame.timestamp()
<< ", hands: " << frame.hands().count()
<< ", extended fingers: " << frame.fingers().extended().count()
<< ", tools: " << frame.tools().count()
<< ", gestures: " << frame.gestures().count() << std::endl;
*/

}

/*
Expand Down Expand Up @@ -1188,4 +1199,4 @@ void GDLMSensor::lm_main(GDLMSensor *p_sensor) {
}
}
}
*/
*/
6 changes: 3 additions & 3 deletions src/gdlm_sensor.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ class GDLMSensor : public Spatial {
//LEAP_CLOCK_REBASER clock_synchronizer;

//const LEAP_TRACKING_EVENT *last_frame;
Leap::Frame *last_frame;
Leap::Frame last_frame;

//LEAP_DEVICE_INFO *last_device;
Leap::Device *last_device;
Expand Down Expand Up @@ -121,9 +121,9 @@ class GDLMSensor : public Spatial {
//void unlock();

//const LEAP_TRACKING_EVENT *get_last_frame();
Leap::Frame *get_last_frame();
Leap::Frame get_last_frame();
//void set_last_frame(const LEAP_TRACKING_EVENT *p_frame);
void set_last_frame(Leap::Frame *p_frame);
void set_last_frame(Leap::Frame p_frame);
//const LEAP_DEVICE_INFO *get_last_device();
const Leap::Device *get_last_device();
//void set_last_device(const LEAP_DEVICE_INFO *p_device);
Expand Down

0 comments on commit 9782b7b

Please sign in to comment.