From 456a3c373960e4869258c731a84ec43cf9fa7f23 Mon Sep 17 00:00:00 2001 From: Andrew Meadows Date: Mon, 14 Jul 2014 09:26:42 -0700 Subject: [PATCH] cleanup Leapmotion initialization removes warning about unused variable --- interface/src/Application.cpp | 2 +- interface/src/devices/Leapmotion.cpp | 35 ++++++++++++++-------------- interface/src/devices/Leapmotion.h | 4 +++- 3 files changed, 21 insertions(+), 20 deletions(-) diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index f9dcf12c10..cf0d684a82 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -1722,7 +1722,7 @@ void Application::init() { _faceplus.init(); _visage.init(); - Leapmotion* leap = Leapmotion::create(); + Leapmotion::init(); // fire off an immediate domain-server check in now that settings are loaded NodeList::getInstance()->sendDomainServerCheckIn(); diff --git a/interface/src/devices/Leapmotion.cpp b/interface/src/devices/Leapmotion.cpp index 9aaa49cdc2..7060c5c5e9 100644 --- a/interface/src/devices/Leapmotion.cpp +++ b/interface/src/devices/Leapmotion.cpp @@ -36,27 +36,26 @@ MotionTracker::Index evalJointIndex(bool isRightSide, int finger, int bone) { } } -Leapmotion* Leapmotion::create() { - // check that the Leapmotion hasn't been created yet +// static +void Leapmotion::init() { + DeviceTracker* device = DeviceTracker::getDevice(NAME); + + if (!device) { + // create a new Leapmotion and register it + Leapmotion* leap = new Leapmotion(); + DeviceTracker::registerDevice(NAME, leap); + } +} + +// static +Leapmotion* Leapmotion::getInstance() { DeviceTracker* device = DeviceTracker::getDevice(NAME); if (!device) { - // create a new Leapmotion - Leapmotion* leap = new Leapmotion(); - - // register it - DeviceTracker::registerDevice(NAME, leap); - - return leap; - } - else - { - Leapmotion* leap = dynamic_cast< Leapmotion* > (device); - if (leap) { - return leap; - } - - return NULL; + // create a new Leapmotion and register it + device = new Leapmotion(); + DeviceTracker::registerDevice(NAME, device); } + return dynamic_cast< Leapmotion* > (device); } Leapmotion::Leapmotion() : diff --git a/interface/src/devices/Leapmotion.h b/interface/src/devices/Leapmotion.h index 36cb31d6e4..a0c75da38f 100644 --- a/interface/src/devices/Leapmotion.h +++ b/interface/src/devices/Leapmotion.h @@ -25,8 +25,10 @@ class Leapmotion : public MotionTracker { public: static const Name NAME; + static void init(); + /// Leapmotion MotionTracker factory - static Leapmotion* create(); + static Leapmotion* getInstance(); bool isActive() const { return _active; }