mirror of
https://github.com/overte-org/overte.git
synced 2025-04-08 19:14:59 +02:00
Merge pull request #3965 from Atlante45/dependancy_manager
Dependancy manager
This commit is contained in:
commit
0b85a4cc49
13 changed files with 167 additions and 62 deletions
|
@ -55,6 +55,7 @@
|
|||
#include <AddressManager.h>
|
||||
#include <AccountManager.h>
|
||||
#include <AudioInjector.h>
|
||||
#include <DependencyManager.h>
|
||||
#include <EntityScriptingInterface.h>
|
||||
#include <HFActionEvent.h>
|
||||
#include <HFBackEvent.h>
|
||||
|
@ -76,10 +77,13 @@
|
|||
#include "ModelUploader.h"
|
||||
#include "Util.h"
|
||||
|
||||
#include "devices/DdeFaceTracker.h"
|
||||
#include "devices/Faceshift.h"
|
||||
#include "devices/Leapmotion.h"
|
||||
#include "devices/MIDIManager.h"
|
||||
#include "devices/OculusManager.h"
|
||||
#include "devices/TV3DManager.h"
|
||||
#include "devices/Visage.h"
|
||||
|
||||
#include "renderer/ProgramObject.h"
|
||||
#include "gpu/Batch.h"
|
||||
|
@ -1690,9 +1694,13 @@ int Application::getMouseDragStartedY() const {
|
|||
}
|
||||
|
||||
FaceTracker* Application::getActiveFaceTracker() {
|
||||
return (_dde.isActive() ? static_cast<FaceTracker*>(&_dde) :
|
||||
(_faceshift.isActive() ? static_cast<FaceTracker*>(&_faceshift) :
|
||||
(_visage.isActive() ? static_cast<FaceTracker*>(&_visage) : NULL)));
|
||||
Faceshift* faceshift = DependencyManager::get<Faceshift>();
|
||||
Visage* visage = DependencyManager::get<Visage>();
|
||||
DdeFaceTracker* dde = DependencyManager::get<DdeFaceTracker>();
|
||||
|
||||
return (dde->isActive() ? static_cast<FaceTracker*>(dde) :
|
||||
(faceshift->isActive() ? static_cast<FaceTracker*>(faceshift) :
|
||||
(visage->isActive() ? static_cast<FaceTracker*>(visage) : NULL)));
|
||||
}
|
||||
|
||||
struct SendVoxelsOperationArgs {
|
||||
|
@ -1976,8 +1984,8 @@ void Application::init() {
|
|||
#endif
|
||||
|
||||
// initialize our face trackers after loading the menu settings
|
||||
_faceshift.init();
|
||||
_visage.init();
|
||||
DependencyManager::get<Faceshift>()->init();
|
||||
DependencyManager::get<Visage>()->init();
|
||||
|
||||
Leapmotion::init();
|
||||
|
||||
|
@ -2101,13 +2109,13 @@ void Application::updateMouseRay() {
|
|||
void Application::updateFaceshift() {
|
||||
bool showWarnings = Menu::getInstance()->isOptionChecked(MenuOption::PipelineWarnings);
|
||||
PerformanceWarning warn(showWarnings, "Application::updateFaceshift()");
|
||||
|
||||
Faceshift* faceshift = DependencyManager::get<Faceshift>();
|
||||
// Update faceshift
|
||||
_faceshift.update();
|
||||
faceshift->update();
|
||||
|
||||
// Copy angular velocity if measured by faceshift, to the head
|
||||
if (_faceshift.isActive()) {
|
||||
_myAvatar->getHead()->setAngularVelocity(_faceshift.getHeadAngularVelocity());
|
||||
if (faceshift->isActive()) {
|
||||
_myAvatar->getHead()->setAngularVelocity(faceshift->getHeadAngularVelocity());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -2116,7 +2124,7 @@ void Application::updateVisage() {
|
|||
PerformanceWarning warn(showWarnings, "Application::updateVisage()");
|
||||
|
||||
// Update Visage
|
||||
_visage.update();
|
||||
DependencyManager::get<Visage>()->update();
|
||||
}
|
||||
|
||||
void Application::updateDDE() {
|
||||
|
@ -2124,7 +2132,7 @@ void Application::updateDDE() {
|
|||
PerformanceWarning warn(showWarnings, "Application::updateDDE()");
|
||||
|
||||
// Update Cara
|
||||
_dde.update();
|
||||
DependencyManager::get<DdeFaceTracker>()->update();
|
||||
}
|
||||
|
||||
void Application::updateMyAvatarLookAtPosition() {
|
||||
|
@ -3549,9 +3557,9 @@ void Application::deleteVoxelAt(const VoxelDetail& voxel) {
|
|||
}
|
||||
|
||||
void Application::resetSensors() {
|
||||
_faceshift.reset();
|
||||
_visage.reset();
|
||||
_dde.reset();
|
||||
DependencyManager::get<Faceshift>()->reset();
|
||||
DependencyManager::get<Visage>()->reset();
|
||||
DependencyManager::get<DdeFaceTracker>()->reset();
|
||||
|
||||
OculusManager::reset();
|
||||
|
||||
|
|
|
@ -54,11 +54,8 @@
|
|||
#include "avatar/Avatar.h"
|
||||
#include "avatar/AvatarManager.h"
|
||||
#include "avatar/MyAvatar.h"
|
||||
#include "devices/Faceshift.h"
|
||||
#include "devices/PrioVR.h"
|
||||
#include "devices/SixenseManager.h"
|
||||
#include "devices/Visage.h"
|
||||
#include "devices/DdeFaceTracker.h"
|
||||
#include "entities/EntityTreeRenderer.h"
|
||||
#include "renderer/AmbientOcclusionEffect.h"
|
||||
#include "renderer/DeferredLightingEffect.h"
|
||||
|
@ -100,6 +97,7 @@ class QMouseEvent;
|
|||
class QSettings;
|
||||
class QWheelEvent;
|
||||
|
||||
class FaceTracker;
|
||||
class Node;
|
||||
class ProgramObject;
|
||||
|
||||
|
@ -220,10 +218,7 @@ public:
|
|||
int getMouseDragStartedY() const;
|
||||
int getTrueMouseDragStartedX() const { return _mouseDragStartedX; }
|
||||
int getTrueMouseDragStartedY() const { return _mouseDragStartedY; }
|
||||
bool getLastMouseMoveWasSimulated() const { return _lastMouseMoveWasSimulated;; }
|
||||
Faceshift* getFaceshift() { return &_faceshift; }
|
||||
Visage* getVisage() { return &_visage; }
|
||||
DdeFaceTracker* getDDE() { return &_dde; }
|
||||
bool getLastMouseMoveWasSimulated() const { return _lastMouseMoveWasSimulated; }
|
||||
FaceTracker* getActiveFaceTracker();
|
||||
PrioVR* getPrioVR() { return &_prioVR; }
|
||||
BandwidthMeter* getBandwidthMeter() { return &_bandwidthMeter; }
|
||||
|
@ -532,10 +527,6 @@ private:
|
|||
AvatarManager _avatarManager;
|
||||
MyAvatar* _myAvatar; // TODO: move this and relevant code to AvatarManager (or MyAvatar as the case may be)
|
||||
|
||||
Faceshift _faceshift;
|
||||
Visage _visage;
|
||||
DdeFaceTracker _dde;
|
||||
|
||||
PrioVR _prioVR;
|
||||
|
||||
Camera _myCamera; // My view onto the world
|
||||
|
|
|
@ -31,12 +31,16 @@
|
|||
|
||||
#include <AccountManager.h>
|
||||
#include <AddressManager.h>
|
||||
#include <XmppClient.h>
|
||||
#include <DependencyManager.h>
|
||||
#include <UUID.h>
|
||||
#include <UserActivityLogger.h>
|
||||
#include <XmppClient.h>
|
||||
|
||||
#include "Application.h"
|
||||
#include "AccountManager.h"
|
||||
#include "devices/Faceshift.h"
|
||||
#include "devices/OculusManager.h"
|
||||
#include "devices/Visage.h"
|
||||
#include "Menu.h"
|
||||
#include "scripting/LocationScriptingInterface.h"
|
||||
#include "scripting/MenuScriptingInterface.h"
|
||||
|
@ -49,7 +53,6 @@
|
|||
#include "ui/ModelsBrowser.h"
|
||||
#include "ui/LoginDialog.h"
|
||||
#include "ui/NodeBounds.h"
|
||||
#include "devices/OculusManager.h"
|
||||
|
||||
|
||||
Menu* Menu::_instance = NULL;
|
||||
|
@ -432,12 +435,12 @@ Menu::Menu() :
|
|||
MenuOption::Faceshift,
|
||||
0,
|
||||
true,
|
||||
appInstance->getFaceshift(),
|
||||
DependencyManager::get<Faceshift>(),
|
||||
SLOT(setTCPEnabled(bool)));
|
||||
#endif
|
||||
#ifdef HAVE_VISAGE
|
||||
addCheckableActionToQMenuAndActionHash(avatarDebugMenu, MenuOption::Visage, 0, false,
|
||||
appInstance->getVisage(), SLOT(updateEnabled()));
|
||||
DependencyManager::get<Visage>(), SLOT(updateEnabled()));
|
||||
#endif
|
||||
|
||||
addCheckableActionToQMenuAndActionHash(avatarDebugMenu, MenuOption::RenderSkeletonCollisionShapes);
|
||||
|
|
|
@ -10,6 +10,9 @@
|
|||
|
||||
#include <glm/gtx/quaternion.hpp>
|
||||
|
||||
#include <DependencyManager.h>
|
||||
#include <devices/Faceshift.h>
|
||||
#include <devices/DdeFaceTracker.h>
|
||||
#include <NodeList.h>
|
||||
|
||||
#include "Application.h"
|
||||
|
@ -75,11 +78,13 @@ void Head::simulate(float deltaTime, bool isMine, bool billboard) {
|
|||
// Only use face trackers when not playing back a recording.
|
||||
if (!myAvatar->isPlaying()) {
|
||||
FaceTracker* faceTracker = Application::getInstance()->getActiveFaceTracker();
|
||||
if ((_isFaceshiftConnected = faceTracker)) {
|
||||
DdeFaceTracker* dde = DependencyManager::get<DdeFaceTracker>();
|
||||
Faceshift* faceshift = DependencyManager::get<Faceshift>();
|
||||
|
||||
if ((_isFaceshiftConnected = (faceshift == faceTracker))) {
|
||||
_blendshapeCoefficients = faceTracker->getBlendshapeCoefficients();
|
||||
_isFaceshiftConnected = true;
|
||||
} else if (Application::getInstance()->getDDE()->isActive()) {
|
||||
faceTracker = Application::getInstance()->getDDE();
|
||||
} else if (dde->isActive()) {
|
||||
faceTracker = dde;
|
||||
_blendshapeCoefficients = faceTracker->getBlendshapeCoefficients();
|
||||
}
|
||||
}
|
||||
|
@ -196,14 +201,14 @@ void Head::simulate(float deltaTime, bool isMine, bool billboard) {
|
|||
_mouth2 = glm::mix(_audioJawOpen * MMMM_POWER, _mouth2, MMMM_PERIOD + randFloat() * MMMM_RANDOM_PERIOD);
|
||||
_mouth4 = glm::mix(_audioJawOpen, _mouth4, SMILE_PERIOD + randFloat() * SMILE_RANDOM_PERIOD);
|
||||
|
||||
Application::getInstance()->getFaceshift()->updateFakeCoefficients(_leftEyeBlink,
|
||||
_rightEyeBlink,
|
||||
_browAudioLift,
|
||||
_audioJawOpen,
|
||||
_mouth2,
|
||||
_mouth3,
|
||||
_mouth4,
|
||||
_blendshapeCoefficients);
|
||||
DependencyManager::get<Faceshift>()->updateFakeCoefficients(_leftEyeBlink,
|
||||
_rightEyeBlink,
|
||||
_browAudioLift,
|
||||
_audioJawOpen,
|
||||
_mouth2,
|
||||
_mouth3,
|
||||
_mouth4,
|
||||
_blendshapeCoefficients);
|
||||
} else {
|
||||
_saccade = glm::vec3();
|
||||
}
|
||||
|
|
|
@ -22,6 +22,7 @@
|
|||
|
||||
#include <AccountManager.h>
|
||||
#include <AddressManager.h>
|
||||
#include <DependencyManager.h>
|
||||
#include <GeometryUtil.h>
|
||||
#include <NodeList.h>
|
||||
#include <PacketHeaders.h>
|
||||
|
@ -421,8 +422,7 @@ void MyAvatar::render(const glm::vec3& cameraPosition, RenderMode renderMode, bo
|
|||
}
|
||||
|
||||
void MyAvatar::renderHeadMouse(int screenWidth, int screenHeight) const {
|
||||
|
||||
Faceshift* faceshift = Application::getInstance()->getFaceshift();
|
||||
Faceshift* faceshift = DependencyManager::get<Faceshift>();
|
||||
|
||||
float pixelsPerDegree = screenHeight / Menu::getInstance()->getFieldOfView();
|
||||
|
||||
|
|
|
@ -14,16 +14,14 @@
|
|||
|
||||
#include <QUdpSocket>
|
||||
|
||||
#include <DependencyManager.h>
|
||||
|
||||
#include "FaceTracker.h"
|
||||
|
||||
class DdeFaceTracker : public FaceTracker {
|
||||
class DdeFaceTracker : public FaceTracker, public DependencyManager::Dependency {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
DdeFaceTracker();
|
||||
DdeFaceTracker(const QHostAddress& host, quint16 port);
|
||||
~DdeFaceTracker();
|
||||
|
||||
//initialization
|
||||
void init();
|
||||
void reset();
|
||||
|
@ -57,6 +55,11 @@ private slots:
|
|||
void socketStateChanged(QAbstractSocket::SocketState socketState);
|
||||
|
||||
private:
|
||||
DdeFaceTracker();
|
||||
DdeFaceTracker(const QHostAddress& host, quint16 port);
|
||||
~DdeFaceTracker();
|
||||
friend DependencyManager;
|
||||
|
||||
float getBlendshapeCoefficient(int index) const;
|
||||
void decodePacket(const QByteArray& buffer);
|
||||
|
||||
|
|
|
@ -23,8 +23,8 @@ class FaceTracker : public QObject {
|
|||
Q_OBJECT
|
||||
|
||||
public:
|
||||
|
||||
FaceTracker();
|
||||
virtual ~FaceTracker() {}
|
||||
|
||||
const glm::vec3& getHeadTranslation() const { return _headTranslation; }
|
||||
const glm::quat& getHeadRotation() const { return _headRotation; }
|
||||
|
|
|
@ -14,7 +14,6 @@
|
|||
#include <PerfStat.h>
|
||||
#include <SharedUtil.h>
|
||||
|
||||
#include "Application.h"
|
||||
#include "Faceshift.h"
|
||||
#include "Menu.h"
|
||||
#include "Util.h"
|
||||
|
|
|
@ -19,15 +19,15 @@
|
|||
#include <fsbinarystream.h>
|
||||
#endif
|
||||
|
||||
#include <DependencyManager.h>
|
||||
|
||||
#include "FaceTracker.h"
|
||||
|
||||
/// Handles interaction with the Faceshift software, which provides head position/orientation and facial features.
|
||||
class Faceshift : public FaceTracker {
|
||||
class Faceshift : public FaceTracker, public DependencyManager::Dependency {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
Faceshift();
|
||||
|
||||
void init();
|
||||
|
||||
bool isConnectedOrConnecting() const;
|
||||
|
@ -87,6 +87,9 @@ private slots:
|
|||
void readFromSocket();
|
||||
|
||||
private:
|
||||
Faceshift();
|
||||
virtual ~Faceshift() {}
|
||||
friend DependencyManager;
|
||||
|
||||
float getBlendshapeCoefficient(int index) const;
|
||||
|
||||
|
|
|
@ -11,12 +11,14 @@
|
|||
|
||||
#include <QHash>
|
||||
|
||||
|
||||
#include <DependencyManager.h>
|
||||
#include <FBXReader.h>
|
||||
#include <PerfStat.h>
|
||||
#include <SharedUtil.h>
|
||||
|
||||
#include <FBXReader.h>
|
||||
|
||||
#include "Application.h"
|
||||
#include "Faceshift.h"
|
||||
#include "Visage.h"
|
||||
|
||||
// this has to go after our normal includes, because its definition of HANDLE conflicts with Qt's
|
||||
|
@ -119,7 +121,7 @@ static const QMultiHash<QByteArray, QPair<int, float> >& getActionUnitNameMap()
|
|||
const float TRANSLATION_SCALE = 20.0f;
|
||||
|
||||
void Visage::init() {
|
||||
connect(Application::getInstance()->getFaceshift(), SIGNAL(connectionStateChanged()), SLOT(updateEnabled()));
|
||||
connect(DependencyManager::get<Faceshift>(), SIGNAL(connectionStateChanged()), SLOT(updateEnabled()));
|
||||
updateEnabled();
|
||||
}
|
||||
|
||||
|
@ -171,7 +173,7 @@ void Visage::reset() {
|
|||
void Visage::updateEnabled() {
|
||||
setEnabled(Menu::getInstance()->isOptionChecked(MenuOption::Visage) &&
|
||||
!(Menu::getInstance()->isOptionChecked(MenuOption::Faceshift) &&
|
||||
Application::getInstance()->getFaceshift()->isConnectedOrConnecting()));
|
||||
DependencyManager::get<Faceshift>()->isConnectedOrConnecting()));
|
||||
}
|
||||
|
||||
void Visage::setEnabled(bool enabled) {
|
||||
|
|
|
@ -16,6 +16,8 @@
|
|||
#include <QPair>
|
||||
#include <QVector>
|
||||
|
||||
#include <DependencyManager.h>
|
||||
|
||||
#include "FaceTracker.h"
|
||||
|
||||
namespace VisageSDK {
|
||||
|
@ -24,14 +26,10 @@ namespace VisageSDK {
|
|||
}
|
||||
|
||||
/// Handles input from the Visage webcam feature tracking software.
|
||||
class Visage : public FaceTracker {
|
||||
class Visage : public FaceTracker, public DependencyManager::Dependency {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
|
||||
Visage();
|
||||
virtual ~Visage();
|
||||
|
||||
void init();
|
||||
|
||||
bool isActive() const { return _active; }
|
||||
|
@ -44,6 +42,9 @@ public slots:
|
|||
void updateEnabled();
|
||||
|
||||
private:
|
||||
Visage();
|
||||
virtual ~Visage();
|
||||
friend DependencyManager;
|
||||
|
||||
#ifdef HAVE_VISAGE
|
||||
VisageSDK::VisageTracker2* _tracker;
|
||||
|
|
24
libraries/shared/src/DependencyManager.cpp
Normal file
24
libraries/shared/src/DependencyManager.cpp
Normal file
|
@ -0,0 +1,24 @@
|
|||
//
|
||||
// DependencyManager.cpp
|
||||
//
|
||||
//
|
||||
// Created by Clément Brisset on 12/10/14.
|
||||
// Copyright 2014 High Fidelity, Inc.
|
||||
//
|
||||
// Distributed under the Apache License, Version 2.0.
|
||||
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
||||
//
|
||||
|
||||
#include "DependencyManager.h"
|
||||
|
||||
DependencyManager& DependencyManager::getInstance() {
|
||||
static DependencyManager instance;
|
||||
return instance;
|
||||
}
|
||||
|
||||
DependencyManager::~DependencyManager() {
|
||||
foreach (Dependency* instance, _instanceHash) {
|
||||
delete instance;
|
||||
}
|
||||
_instanceHash.clear();
|
||||
}
|
66
libraries/shared/src/DependencyManager.h
Normal file
66
libraries/shared/src/DependencyManager.h
Normal file
|
@ -0,0 +1,66 @@
|
|||
//
|
||||
// DependencyManager.h
|
||||
//
|
||||
//
|
||||
// Created by Clément Brisset on 12/10/14.
|
||||
// Copyright 2014 High Fidelity, Inc.
|
||||
//
|
||||
// Distributed under the Apache License, Version 2.0.
|
||||
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
||||
//
|
||||
|
||||
#ifndef hifi_DependencyManager_h
|
||||
#define hifi_DependencyManager_h
|
||||
|
||||
#include <QHash>
|
||||
#include <QString>
|
||||
|
||||
#include <typeinfo>
|
||||
#include <assert.h>
|
||||
|
||||
class DependencyManager {
|
||||
public:
|
||||
// Only accessible method.
|
||||
// usage: T* instance = DependencyManager::get<T>();
|
||||
template<typename T>
|
||||
static T* get();
|
||||
|
||||
// Any class T in the DependencyManager needs to subclass Dependency
|
||||
// They also need to have protected constructor(s) and virtual destructor
|
||||
// As well as declare DependencyManager a friend class
|
||||
class Dependency {
|
||||
protected:
|
||||
Dependency() {}
|
||||
virtual ~Dependency() {} // Ensure the proper destruction of the object
|
||||
friend DependencyManager;
|
||||
};
|
||||
|
||||
private:
|
||||
static DependencyManager& getInstance();
|
||||
DependencyManager() {}
|
||||
~DependencyManager();
|
||||
|
||||
typedef QHash<QString, Dependency*> InstanceHash;
|
||||
static InstanceHash& getInstanceHash() { return getInstance()._instanceHash; }
|
||||
InstanceHash _instanceHash;
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
T* DependencyManager::get() {
|
||||
const QString& typeId = typeid(T).name();
|
||||
|
||||
// Search the hash for global instance
|
||||
Dependency* instance = getInstanceHash().value(typeId, NULL);
|
||||
if (instance) {
|
||||
return dynamic_cast<T*>(instance);
|
||||
}
|
||||
|
||||
// Found no instance in hash so we create one.
|
||||
T* newInstance = new T();
|
||||
instance = dynamic_cast<Dependency*>(newInstance);
|
||||
assert(instance != NULL); // If this triggers, check that T is derived from Dependency
|
||||
getInstanceHash().insert(typeId, instance);
|
||||
return newInstance;
|
||||
}
|
||||
|
||||
#endif // hifi_DependencyManager_h
|
Loading…
Reference in a new issue