From 25df784f433c49c8c51df5c2e0b4f13c0470563d Mon Sep 17 00:00:00 2001 From: Atlante45 Date: Mon, 15 Dec 2014 10:56:42 -0800 Subject: [PATCH 01/11] Headers cleanup --- interface/src/Application.cpp | 1 + interface/src/Application.h | 20 ++++--------------- interface/src/GLCanvas.cpp | 2 +- interface/src/Menu.cpp | 1 + interface/src/entities/EntityTreeRenderer.h | 3 +++ .../scripting/WindowScriptingInterface.cpp | 1 + interface/src/ui/AddressBarDialog.cpp | 1 + interface/src/ui/AnimationsDialog.cpp | 1 + interface/src/ui/AttachmentsDialog.cpp | 1 + interface/src/ui/ChatWindow.cpp | 4 +++- interface/src/ui/HMDToolsDialog.cpp | 1 + interface/src/ui/MetavoxelEditor.cpp | 1 + interface/src/ui/PreferencesDialog.cpp | 1 + interface/src/ui/ToolWindow.cpp | 1 + 14 files changed, 21 insertions(+), 18 deletions(-) diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index fbe55071e4..d0abc47b85 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -61,6 +61,7 @@ #include #include #include +#include #include #include #include diff --git a/interface/src/Application.h b/interface/src/Application.h index 833f1374ce..c2136f1c57 100644 --- a/interface/src/Application.h +++ b/interface/src/Application.h @@ -12,35 +12,21 @@ #ifndef hifi_Application_h #define hifi_Application_h -#include -#include - #include -#include -#include #include #include -#include #include #include #include #include -#include -#include #include -#include #include #include -#include -#include -#include -#include #include #include #include -#include "MainWindow.h" #include "Audio.h" #include "Camera.h" #include "DatagramProcessor.h" @@ -89,17 +75,19 @@ #include "UndoStackScriptingInterface.h" -class QAction; -class QActionGroup; class QGLWidget; class QKeyEvent; class QMouseEvent; class QSettings; +class QSystemTrayIcon; +class QTouchEvent; class QWheelEvent; class FaceTracker; +class MainWindow; class Node; class ProgramObject; +class ScriptEngine; static const float NODE_ADDED_RED = 0.0f; static const float NODE_ADDED_GREEN = 1.0f; diff --git a/interface/src/GLCanvas.cpp b/interface/src/GLCanvas.cpp index cec3f62b7d..10090de51a 100644 --- a/interface/src/GLCanvas.cpp +++ b/interface/src/GLCanvas.cpp @@ -9,13 +9,13 @@ // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // -#include #include #include #include #include "Application.h" #include "GLCanvas.h" +#include "MainWindow.h" #include "devices/OculusManager.h" const int MSECS_PER_FRAME_WHEN_THROTTLED = 66; diff --git a/interface/src/Menu.cpp b/interface/src/Menu.cpp index 6c2c3966fc..14327bd51a 100644 --- a/interface/src/Menu.cpp +++ b/interface/src/Menu.cpp @@ -32,6 +32,7 @@ #include #include #include +#include #include #include #include diff --git a/interface/src/entities/EntityTreeRenderer.h b/interface/src/entities/EntityTreeRenderer.h index a8695db36d..3d79358536 100644 --- a/interface/src/entities/EntityTreeRenderer.h +++ b/interface/src/entities/EntityTreeRenderer.h @@ -17,6 +17,7 @@ #include #include // for RayToEntityIntersectionResult +#include #include #include #include @@ -27,6 +28,8 @@ #include "renderer/Model.h" +class ScriptEngine; + class EntityScriptDetails { public: QString scriptText; diff --git a/interface/src/scripting/WindowScriptingInterface.cpp b/interface/src/scripting/WindowScriptingInterface.cpp index 591ae87560..d69b1d0ba1 100644 --- a/interface/src/scripting/WindowScriptingInterface.cpp +++ b/interface/src/scripting/WindowScriptingInterface.cpp @@ -17,6 +17,7 @@ #include #include "Application.h" +#include "MainWindow.h" #include "Menu.h" #include "ui/ModelsBrowser.h" diff --git a/interface/src/ui/AddressBarDialog.cpp b/interface/src/ui/AddressBarDialog.cpp index dbc29be71a..3fc915e073 100644 --- a/interface/src/ui/AddressBarDialog.cpp +++ b/interface/src/ui/AddressBarDialog.cpp @@ -12,6 +12,7 @@ #include "AddressBarDialog.h" #include "AddressManager.h" #include "Application.h" +#include "MainWindow.h" const QString ADDRESSBAR_GO_BUTTON_ICON = "images/address-bar-submit.svg"; const QString ADDRESSBAR_GO_BUTTON_ACTIVE_ICON = "images/address-bar-submit-active.svg"; diff --git a/interface/src/ui/AnimationsDialog.cpp b/interface/src/ui/AnimationsDialog.cpp index c5ab826ebb..65e7cadc77 100644 --- a/interface/src/ui/AnimationsDialog.cpp +++ b/interface/src/ui/AnimationsDialog.cpp @@ -22,6 +22,7 @@ #include "AnimationsDialog.h" #include "Application.h" +#include "MainWindow.h" AnimationsDialog::AnimationsDialog() : QDialog(Application::getInstance()->getWindow()) { diff --git a/interface/src/ui/AttachmentsDialog.cpp b/interface/src/ui/AttachmentsDialog.cpp index 44dd2452e6..1209af580d 100644 --- a/interface/src/ui/AttachmentsDialog.cpp +++ b/interface/src/ui/AttachmentsDialog.cpp @@ -20,6 +20,7 @@ #include "Application.h" #include "AttachmentsDialog.h" +#include "MainWindow.h" AttachmentsDialog::AttachmentsDialog() : QDialog(Application::getInstance()->getWindow()) { diff --git a/interface/src/ui/ChatWindow.cpp b/interface/src/ui/ChatWindow.cpp index 747b4ae68d..61ce9f88fc 100644 --- a/interface/src/ui/ChatWindow.cpp +++ b/interface/src/ui/ChatWindow.cpp @@ -16,6 +16,8 @@ #include #include #include +#include "qtimespan.h" + #include #include @@ -23,7 +25,7 @@ #include "Application.h" #include "ChatMessageArea.h" #include "FlowLayout.h" -#include "qtimespan.h" +#include "MainWindow.h" #include "UIUtil.h" #include "XmppClient.h" diff --git a/interface/src/ui/HMDToolsDialog.cpp b/interface/src/ui/HMDToolsDialog.cpp index ab84980d80..23d6d5df2f 100644 --- a/interface/src/ui/HMDToolsDialog.cpp +++ b/interface/src/ui/HMDToolsDialog.cpp @@ -21,6 +21,7 @@ #include +#include "MainWindow.h" #include "Menu.h" #include "devices/OculusManager.h" #include "ui/HMDToolsDialog.h" diff --git a/interface/src/ui/MetavoxelEditor.cpp b/interface/src/ui/MetavoxelEditor.cpp index 97c4c08b41..46f69b0452 100644 --- a/interface/src/ui/MetavoxelEditor.cpp +++ b/interface/src/ui/MetavoxelEditor.cpp @@ -37,6 +37,7 @@ #include #include "Application.h" +#include "MainWindow.h" #include "MetavoxelEditor.h" using namespace std; diff --git a/interface/src/ui/PreferencesDialog.cpp b/interface/src/ui/PreferencesDialog.cpp index 61cc9718b3..318dce977a 100644 --- a/interface/src/ui/PreferencesDialog.cpp +++ b/interface/src/ui/PreferencesDialog.cpp @@ -11,6 +11,7 @@ #include "Application.h" +#include "MainWindow.h" #include "Menu.h" #include "ModelsBrowser.h" #include "PreferencesDialog.h" diff --git a/interface/src/ui/ToolWindow.cpp b/interface/src/ui/ToolWindow.cpp index da1d2c68f4..8774bffc36 100644 --- a/interface/src/ui/ToolWindow.cpp +++ b/interface/src/ui/ToolWindow.cpp @@ -10,6 +10,7 @@ // #include "Application.h" +#include "MainWindow.h" #include "ToolWindow.h" #include "UIUtil.h" From 68430e1346ea1f6014c19cff445b2984a1a697a7 Mon Sep 17 00:00:00 2001 From: Atlante45 Date: Mon, 15 Dec 2014 11:54:33 -0800 Subject: [PATCH 02/11] Moved GLCanvas to DependencyManager --- interface/src/Application.cpp | 76 ++++++++++++++++++++--------------- interface/src/Application.h | 31 +++++++------- interface/src/GLCanvas.h | 10 ++++- 3 files changed, 68 insertions(+), 49 deletions(-) diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index d0abc47b85..eaafcd0eac 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -146,7 +146,6 @@ QString& Application::resourcesPath() { Application::Application(int& argc, char** argv, QElapsedTimer &startup_time) : QApplication(argc, argv), _window(new MainWindow(desktop())), - _glWidget(new GLCanvas()), _toolWindow(NULL), _nodeThread(new QThread(this)), _datagramProcessor(), @@ -195,7 +194,8 @@ Application::Application(int& argc, char** argv, QElapsedTimer &startup_time) : _isVSyncOn(true), _aboutToQuit(false) { - + GLCanvas* glCanvas = DependencyManager::get(); + // read the ApplicationInfo.ini file for Name/Version/Domain information QSettings applicationInfo(Application::resourcesPath() + "info/ApplicationInfo.ini", QSettings::IniFormat); @@ -365,16 +365,16 @@ Application::Application(int& argc, char** argv, QElapsedTimer &startup_time) : ResourceCache::setRequestLimit(3); - _window->setCentralWidget(_glWidget); + _window->setCentralWidget(glCanvas); restoreSizeAndPosition(); _window->setVisible(true); - _glWidget->setFocusPolicy(Qt::StrongFocus); - _glWidget->setFocus(); + glCanvas->setFocusPolicy(Qt::StrongFocus); + glCanvas->setFocus(); // enable mouse tracking; otherwise, we only get drag events - _glWidget->setMouseTracking(true); + glCanvas->setMouseTracking(true); _toolWindow = new ToolWindow(); _toolWindow->setWindowFlags(_toolWindow->windowFlags() | Qt::WindowStaysOnTopHint); @@ -393,7 +393,7 @@ Application::Application(int& argc, char** argv, QElapsedTimer &startup_time) : checkVersion(); - _overlays.init(_glWidget); // do this before scripts load + _overlays.init(glCanvas); // do this before scripts load LocalVoxelsList::getInstance()->addPersistantTree(DOMAIN_TREE_NAME, _voxels.getTree()); LocalVoxelsList::getInstance()->addPersistantTree(CLIPBOARD_TREE_NAME, &_clipboard); @@ -483,8 +483,6 @@ Application::~Application() { Menu::getInstance()->deleteLater(); _myAvatar = NULL; - - delete _glWidget; } void Application::saveSettings() { @@ -624,7 +622,7 @@ void Application::paintGL() { if (OculusManager::isConnected()) { _textureCache.setFrameBufferSize(OculusManager::getRenderTargetSize()); } else { - QSize fbSize = _glWidget->getDeviceSize() * getRenderResolutionScale(); + QSize fbSize = DependencyManager::get()->getDeviceSize() * getRenderResolutionScale(); _textureCache.setFrameBufferSize(fbSize); } @@ -1048,7 +1046,8 @@ void Application::keyPressEvent(QKeyEvent* event) { if (isShifted) { _viewFrustum.setFocalLength(_viewFrustum.getFocalLength() - 0.1f); if (TV3DManager::isConnected()) { - TV3DManager::configureCamera(_myCamera, _glWidget->getDeviceWidth(), _glWidget->getDeviceHeight()); + GLCanvas* glCanvas = DependencyManager::get(); + TV3DManager::configureCamera(_myCamera, glCanvas->getDeviceWidth(), glCanvas->getDeviceHeight()); } } else { _myCamera.setEyeOffsetPosition(_myCamera.getEyeOffsetPosition() + glm::vec3(-0.001, 0, 0)); @@ -1060,7 +1059,8 @@ void Application::keyPressEvent(QKeyEvent* event) { if (isShifted) { _viewFrustum.setFocalLength(_viewFrustum.getFocalLength() + 0.1f); if (TV3DManager::isConnected()) { - TV3DManager::configureCamera(_myCamera, _glWidget->getDeviceWidth(), _glWidget->getDeviceHeight()); + GLCanvas* glCanvas = DependencyManager::get(); + TV3DManager::configureCamera(_myCamera, glCanvas->getDeviceWidth(), glCanvas->getDeviceHeight()); } } else { @@ -1506,7 +1506,7 @@ void Application::idle() { { PerformanceTimer perfTimer("updateGL"); PerformanceWarning warn(showWarnings, "Application::idle()... updateGL()"); - _glWidget->updateGL(); + DependencyManager::get()->updateGL(); } { PerformanceTimer perfTimer("rest"); @@ -1532,13 +1532,14 @@ void Application::idle() { void Application::checkBandwidthMeterClick() { // ... to be called upon button release + GLCanvas* glCanvas = DependencyManager::get(); if (Menu::getInstance()->isOptionChecked(MenuOption::Bandwidth) && Menu::getInstance()->isOptionChecked(MenuOption::Stats) && Menu::getInstance()->isOptionChecked(MenuOption::UserInterface) && glm::compMax(glm::abs(glm::ivec2(getMouseX() - getMouseDragStartedX(), getMouseY() - getMouseDragStartedY()))) <= BANDWIDTH_METER_CLICK_MAX_DRAG_LENGTH - && _bandwidthMeter.isWithinArea(getMouseX(), getMouseY(), _glWidget->width(), _glWidget->height())) { + && _bandwidthMeter.isWithinArea(getMouseX(), getMouseY(), glCanvas->width(), glCanvas->height())) { // The bandwidth meter is visible, the click didn't get dragged too far and // we actually hit the bandwidth meter @@ -1567,7 +1568,8 @@ void Application::setFullscreen(bool fullscreen) { } void Application::setEnable3DTVMode(bool enable3DTVMode) { - resizeGL(_glWidget->getDeviceWidth(),_glWidget->getDeviceHeight()); + GLCanvas* glCanvas = DependencyManager::get(); + resizeGL(glCanvas->getDeviceWidth(), glCanvas->getDeviceHeight()); } void Application::setEnableVRMode(bool enableVRMode) { @@ -1592,7 +1594,8 @@ void Application::setEnableVRMode(bool enableVRMode) { _myCamera.setHmdRotation(glm::quat()); } - resizeGL(_glWidget->getDeviceWidth(), _glWidget->getDeviceHeight()); + GLCanvas* glCanvas = DependencyManager::get(); + resizeGL(glCanvas->getDeviceWidth(), glCanvas->getDeviceHeight()); } void Application::setRenderVoxels(bool voxelRender) { @@ -1654,8 +1657,9 @@ glm::vec3 Application::getMouseVoxelWorldCoordinates(const VoxelDetail& mouseVox bool Application::mouseOnScreen() const { if (OculusManager::isConnected()) { - return getMouseX() >= 0 && getMouseX() <= _glWidget->getDeviceWidth() && - getMouseY() >= 0 && getMouseY() <= _glWidget->getDeviceHeight(); + GLCanvas* glCanvas = DependencyManager::get(); + return getMouseX() >= 0 && getMouseX() <= glCanvas->getDeviceWidth() && + getMouseY() >= 0 && getMouseY() <= glCanvas->getDeviceHeight(); } return true; } @@ -1774,7 +1778,8 @@ void Application::exportVoxels(const VoxelDetail& sourceVoxel) { QString desktopLocation = QStandardPaths::writableLocation(QStandardPaths::DesktopLocation); QString suggestedName = desktopLocation.append("/voxels.svo"); - QString fileNameString = QFileDialog::getSaveFileName(_glWidget, tr("Export Voxels"), suggestedName, + QString fileNameString = QFileDialog::getSaveFileName(DependencyManager::get(), + tr("Export Voxels"), suggestedName, tr("Sparse Voxel Octree Files (*.svo)")); QByteArray fileNameAscii = fileNameString.toLocal8Bit(); const char* fileName = fileNameAscii.data(); @@ -2029,9 +2034,9 @@ void Application::init() { _metavoxels.init(); - _audio.init(_glWidget); - - _rearMirrorTools = new RearMirrorTools(_glWidget, _mirrorViewRect, _settings); + GLCanvas* glCanvas = DependencyManager::get(); + _audio.init(glCanvas); + _rearMirrorTools = new RearMirrorTools(glCanvas, _mirrorViewRect, _settings); connect(_rearMirrorTools, SIGNAL(closeView()), SLOT(closeMirrorView())); connect(_rearMirrorTools, SIGNAL(restoreView()), SLOT(restoreMirrorView())); @@ -2913,8 +2918,9 @@ void Application::updateShadowMap() { } fbo->release(); - - glViewport(0, 0, _glWidget->getDeviceWidth(), _glWidget->getDeviceHeight()); + + GLCanvas* glCanvas = DependencyManager::get(); + glViewport(0, 0, glCanvas->getDeviceWidth(), glCanvas->getDeviceHeight()); } const GLfloat WORLD_AMBIENT_COLOR[] = { 0.525f, 0.525f, 0.6f }; @@ -2944,7 +2950,9 @@ QImage Application::renderAvatarBillboard() { Glower glower; const int BILLBOARD_SIZE = 64; - renderRearViewMirror(QRect(0, _glWidget->getDeviceHeight() - BILLBOARD_SIZE, BILLBOARD_SIZE, BILLBOARD_SIZE), true); + renderRearViewMirror(QRect(0, DependencyManager::get()->getDeviceHeight() - BILLBOARD_SIZE, + BILLBOARD_SIZE, BILLBOARD_SIZE), + true); QImage image(BILLBOARD_SIZE, BILLBOARD_SIZE, QImage::Format_ARGB32); glReadPixels(0, 0, BILLBOARD_SIZE, BILLBOARD_SIZE, GL_BGRA, GL_UNSIGNED_BYTE, image.bits()); @@ -3239,8 +3247,9 @@ void Application::computeOffAxisFrustum(float& left, float& right, float& bottom } glm::vec2 Application::getScaledScreenPoint(glm::vec2 projectedPoint) { - float horizontalScale = _glWidget->getDeviceWidth() / 2.0f; - float verticalScale = _glWidget->getDeviceHeight() / 2.0f; + GLCanvas* glCanvas = DependencyManager::get(); + float horizontalScale = glCanvas->getDeviceWidth() / 2.0f; + float verticalScale = glCanvas->getDeviceHeight() / 2.0f; // -1,-1 is 0,windowHeight // 1,1 is windowWidth,0 @@ -3259,7 +3268,7 @@ glm::vec2 Application::getScaledScreenPoint(glm::vec2 projectedPoint) { // -1,-1 1,-1 glm::vec2 screenPoint((projectedPoint.x + 1.0) * horizontalScale, - ((projectedPoint.y + 1.0) * -verticalScale) + _glWidget->getDeviceHeight()); + ((projectedPoint.y + 1.0) * -verticalScale) + glCanvas->getDeviceHeight()); return screenPoint; } @@ -3570,7 +3579,7 @@ void Application::resetSensors() { QScreen* currentScreen = _window->windowHandle()->screen(); QWindow* mainWindow = _window->windowHandle(); QPoint windowCenter = mainWindow->geometry().center(); - _glWidget->cursor().setPos(currentScreen, windowCenter); + DependencyManager::get()->cursor().setPos(currentScreen, windowCenter); _myAvatar->reset(); @@ -4251,7 +4260,8 @@ void Application::setPreviousScriptLocation(const QString& previousScriptLocatio void Application::loadDialog() { - QString fileNameString = QFileDialog::getOpenFileName(_glWidget, tr("Open Script"), + QString fileNameString = QFileDialog::getOpenFileName(DependencyManager::get(), + tr("Open Script"), getPreviousScriptLocation(), tr("JavaScript Files (*.js)")); if (!fileNameString.isEmpty()) { @@ -4287,7 +4297,7 @@ void Application::loadScriptURLDialog() { void Application::toggleLogDialog() { if (! _logDialog) { - _logDialog = new LogDialog(_glWidget, getLogger()); + _logDialog = new LogDialog(DependencyManager::get(), getLogger()); } if (_logDialog->isVisible()) { @@ -4347,7 +4357,7 @@ void Application::parseVersionXml() { } if (!shouldSkipVersion(latestVersion) && applicationVersion() != latestVersion) { - new UpdateDialog(_glWidget, releaseNotes, latestVersion, downloadUrl); + new UpdateDialog(DependencyManager::get(), releaseNotes, latestVersion, downloadUrl); } sender->deleteLater(); } @@ -4380,7 +4390,7 @@ void Application::takeSnapshot() { } if (!_snapshotShareDialog) { - _snapshotShareDialog = new SnapshotShareDialog(fileName, _glWidget); + _snapshotShareDialog = new SnapshotShareDialog(fileName, DependencyManager::get()); } _snapshotShareDialog->show(); } diff --git a/interface/src/Application.h b/interface/src/Application.h index c2136f1c57..cddaeaad15 100644 --- a/interface/src/Application.h +++ b/interface/src/Application.h @@ -171,46 +171,50 @@ public: void removeVoxel(glm::vec3 position, float scale); glm::vec3 getMouseVoxelWorldCoordinates(const VoxelDetail& mouseVoxel); + bool isThrottleRendering() const { return DependencyManager::get()->isThrottleRendering(); } - GLCanvas* getGLWidget() { return _glWidget; } - bool isThrottleRendering() const { return _glWidget->isThrottleRendering(); } + GLCanvas* getGLWidget() { return DependencyManager::get(); } // TODO: remove MyAvatar* getAvatar() { return _myAvatar; } Audio* getAudio() { return &_audio; } Camera* getCamera() { return &_myCamera; } ViewFrustum* getViewFrustum() { return &_viewFrustum; } ViewFrustum* getDisplayViewFrustum() { return &_displayViewFrustum; } ViewFrustum* getShadowViewFrustum() { return &_shadowViewFrustum; } - VoxelImporter* getVoxelImporter() { return &_voxelImporter; } VoxelSystem* getVoxels() { return &_voxels; } - VoxelTree* getVoxelTree() { return _voxels.getTree(); } const OctreePacketProcessor& getOctreePacketProcessor() const { return _octreeProcessor; } MetavoxelSystem* getMetavoxels() { return &_metavoxels; } EntityTreeRenderer* getEntities() { return &_entities; } - bool getImportSucceded() { return _importSucceded; } VoxelSystem* getSharedVoxelSystem() { return &_sharedVoxelSystem; } + Environment* getEnvironment() { return &_environment; } + PrioVR* getPrioVR() { return &_prioVR; } + QUndoStack* getUndoStack() { return &_undoStack; } + MainWindow* getWindow() { return _window; } + + VoxelImporter* getVoxelImporter() { return &_voxelImporter; } VoxelTree* getClipboard() { return &_clipboard; } EntityTree* getEntityClipboard() { return &_entityClipboard; } EntityTreeRenderer* getEntityClipboardRenderer() { return &_entityClipboardRenderer; } - Environment* getEnvironment() { return &_environment; } + VoxelTree* getVoxelTree() { return _voxels.getTree(); } + bool getImportSucceded() { return _importSucceded; } + bool isMousePressed() const { return _mousePressed; } - bool isMouseHidden() const { return _glWidget->cursor().shape() == Qt::BlankCursor; } + bool isMouseHidden() const { return DependencyManager::get()->cursor().shape() == Qt::BlankCursor; } void setCursorVisible(bool visible); const glm::vec3& getMouseRayOrigin() const { return _mouseRayOrigin; } const glm::vec3& getMouseRayDirection() const { return _mouseRayDirection; } bool mouseOnScreen() const; int getMouseX() const; int getMouseY() const; - int getTrueMouseX() const { return _glWidget->mapFromGlobal(QCursor::pos()).x(); } - int getTrueMouseY() const { return _glWidget->mapFromGlobal(QCursor::pos()).y(); } + int getTrueMouseX() const { return DependencyManager::get()->mapFromGlobal(QCursor::pos()).x(); } + int getTrueMouseY() const { return DependencyManager::get()->mapFromGlobal(QCursor::pos()).y(); } int getMouseDragStartedX() const; int getMouseDragStartedY() const; int getTrueMouseDragStartedX() const { return _mouseDragStartedX; } int getTrueMouseDragStartedY() const { return _mouseDragStartedY; } bool getLastMouseMoveWasSimulated() const { return _lastMouseMoveWasSimulated; } + FaceTracker* getActiveFaceTracker(); - PrioVR* getPrioVR() { return &_prioVR; } BandwidthMeter* getBandwidthMeter() { return &_bandwidthMeter; } - QUndoStack* getUndoStack() { return &_undoStack; } QSystemTrayIcon* getTrayIcon() { return _trayIcon; } ApplicationOverlay& getApplicationOverlay() { return _applicationOverlay; } Overlays& getOverlays() { return _overlays; } @@ -230,7 +234,6 @@ public: void saveSettings(); - MainWindow* getWindow() { return _window; } NodeToOctreeSceneStats* getOcteeSceneStats() { return &_octreeServerSceneStats; } void lockOctreeSceneStats() { _octreeSceneStatsLock.lockForRead(); } void unlockOctreeSceneStats() { _octreeSceneStatsLock.unlock(); } @@ -278,7 +281,8 @@ public: FileLogger* getLogger() { return _logger; } - glm::vec2 getViewportDimensions() const { return glm::vec2(_glWidget->getDeviceWidth(), _glWidget->getDeviceHeight()); } + glm::vec2 getViewportDimensions() const { return glm::vec2(DependencyManager::get()->getDeviceWidth(), + DependencyManager::get()->getDeviceHeight()); } NodeToJurisdictionMap& getVoxelServerJurisdictions() { return _voxelServerJurisdictions; } NodeToJurisdictionMap& getEntityServerJurisdictions() { return _entityServerJurisdictions; } void pasteVoxelsToOctalCode(const unsigned char* octalCodeDestination); @@ -456,7 +460,6 @@ private: int sendNackPackets(); MainWindow* _window; - GLCanvas* _glWidget; // our GLCanvas has a couple extra features ToolWindow* _toolWindow; diff --git a/interface/src/GLCanvas.h b/interface/src/GLCanvas.h index 0d381fa0bf..2b1cd3539d 100644 --- a/interface/src/GLCanvas.h +++ b/interface/src/GLCanvas.h @@ -15,11 +15,12 @@ #include #include +#include + /// customized canvas that simply forwards requests/events to the singleton application -class GLCanvas : public QGLWidget { +class GLCanvas : public QGLWidget, public DependencyManager::Dependency { Q_OBJECT public: - GLCanvas(); bool isThrottleRendering() const; int getDeviceWidth() const; @@ -56,6 +57,11 @@ private slots: void activeChanged(Qt::ApplicationState state); void throttleRender(); bool eventFilter(QObject*, QEvent* event); + +private: + GLCanvas(); + ~GLCanvas(); + friend class DependencyManager; }; #endif // hifi_GLCanvas_h From e5e2eb4e8ae0adc3df0ed238596f30f126b442c1 Mon Sep 17 00:00:00 2001 From: Atlante45 Date: Mon, 15 Dec 2014 16:20:52 -0800 Subject: [PATCH 03/11] Moved GLCanvas in DM and DM to QSharedPointers --- interface/src/Application.cpp | 54 ++++++----- interface/src/Application.h | 1 - interface/src/Camera.cpp | 6 +- interface/src/Menu.cpp | 18 ++-- interface/src/avatar/Head.cpp | 7 +- interface/src/avatar/MyAvatar.cpp | 2 +- interface/src/devices/DdeFaceTracker.h | 4 +- interface/src/devices/Faceshift.h | 4 +- interface/src/devices/OculusManager.cpp | 8 +- interface/src/devices/PrioVR.cpp | 7 +- interface/src/devices/SixenseManager.cpp | 8 +- interface/src/devices/TV3DManager.cpp | 11 ++- interface/src/devices/Visage.cpp | 2 +- interface/src/devices/Visage.h | 4 +- interface/src/renderer/GlowEffect.cpp | 10 +- interface/src/renderer/TextureCache.cpp | 2 +- .../ControllerScriptingInterface.cpp | 6 +- .../scripting/WindowScriptingInterface.cpp | 2 +- interface/src/ui/ApplicationOverlay.cpp | 97 ++++++++++--------- interface/src/ui/MetavoxelEditor.cpp | 2 +- .../src/ui/MetavoxelNetworkSimulator.cpp | 2 +- interface/src/ui/PreferencesDialog.cpp | 7 +- interface/src/ui/Snapshot.cpp | 5 +- interface/src/ui/Stats.cpp | 20 ++-- 24 files changed, 143 insertions(+), 146 deletions(-) diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index eaafcd0eac..4c9fdcaf0f 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -194,7 +194,7 @@ Application::Application(int& argc, char** argv, QElapsedTimer &startup_time) : _isVSyncOn(true), _aboutToQuit(false) { - GLCanvas* glCanvas = DependencyManager::get(); + QSharedPointer glCanvas = DependencyManager::get(); // read the ApplicationInfo.ini file for Name/Version/Domain information QSettings applicationInfo(Application::resourcesPath() + "info/ApplicationInfo.ini", QSettings::IniFormat); @@ -365,7 +365,7 @@ Application::Application(int& argc, char** argv, QElapsedTimer &startup_time) : ResourceCache::setRequestLimit(3); - _window->setCentralWidget(glCanvas); + _window->setCentralWidget(glCanvas.data()); restoreSizeAndPosition(); @@ -393,7 +393,7 @@ Application::Application(int& argc, char** argv, QElapsedTimer &startup_time) : checkVersion(); - _overlays.init(glCanvas); // do this before scripts load + _overlays.init(glCanvas.data()); // do this before scripts load LocalVoxelsList::getInstance()->addPersistantTree(DOMAIN_TREE_NAME, _voxels.getTree()); LocalVoxelsList::getInstance()->addPersistantTree(CLIPBOARD_TREE_NAME, &_clipboard); @@ -442,6 +442,8 @@ void Application::aboutToQuit() { } Application::~Application() { + DependencyManager::get()->setParent(NULL); + _entities.getTree()->setSimulation(NULL); qInstallMessageHandler(NULL); @@ -1046,7 +1048,7 @@ void Application::keyPressEvent(QKeyEvent* event) { if (isShifted) { _viewFrustum.setFocalLength(_viewFrustum.getFocalLength() - 0.1f); if (TV3DManager::isConnected()) { - GLCanvas* glCanvas = DependencyManager::get(); + QSharedPointer glCanvas = DependencyManager::get(); TV3DManager::configureCamera(_myCamera, glCanvas->getDeviceWidth(), glCanvas->getDeviceHeight()); } } else { @@ -1059,7 +1061,7 @@ void Application::keyPressEvent(QKeyEvent* event) { if (isShifted) { _viewFrustum.setFocalLength(_viewFrustum.getFocalLength() + 0.1f); if (TV3DManager::isConnected()) { - GLCanvas* glCanvas = DependencyManager::get(); + QSharedPointer glCanvas = DependencyManager::get(); TV3DManager::configureCamera(_myCamera, glCanvas->getDeviceWidth(), glCanvas->getDeviceHeight()); } @@ -1532,7 +1534,7 @@ void Application::idle() { void Application::checkBandwidthMeterClick() { // ... to be called upon button release - GLCanvas* glCanvas = DependencyManager::get(); + QSharedPointer glCanvas = DependencyManager::get(); if (Menu::getInstance()->isOptionChecked(MenuOption::Bandwidth) && Menu::getInstance()->isOptionChecked(MenuOption::Stats) && Menu::getInstance()->isOptionChecked(MenuOption::UserInterface) && @@ -1568,7 +1570,7 @@ void Application::setFullscreen(bool fullscreen) { } void Application::setEnable3DTVMode(bool enable3DTVMode) { - GLCanvas* glCanvas = DependencyManager::get(); + QSharedPointer glCanvas = DependencyManager::get(); resizeGL(glCanvas->getDeviceWidth(), glCanvas->getDeviceHeight()); } @@ -1594,7 +1596,7 @@ void Application::setEnableVRMode(bool enableVRMode) { _myCamera.setHmdRotation(glm::quat()); } - GLCanvas* glCanvas = DependencyManager::get(); + QSharedPointer glCanvas = DependencyManager::get(); resizeGL(glCanvas->getDeviceWidth(), glCanvas->getDeviceHeight()); } @@ -1657,7 +1659,7 @@ glm::vec3 Application::getMouseVoxelWorldCoordinates(const VoxelDetail& mouseVox bool Application::mouseOnScreen() const { if (OculusManager::isConnected()) { - GLCanvas* glCanvas = DependencyManager::get(); + QSharedPointer glCanvas = DependencyManager::get(); return getMouseX() >= 0 && getMouseX() <= glCanvas->getDeviceWidth() && getMouseY() >= 0 && getMouseY() <= glCanvas->getDeviceHeight(); } @@ -1699,13 +1701,13 @@ int Application::getMouseDragStartedY() const { } FaceTracker* Application::getActiveFaceTracker() { - Faceshift* faceshift = DependencyManager::get(); - Visage* visage = DependencyManager::get(); - DdeFaceTracker* dde = DependencyManager::get(); + QSharedPointer faceshift = DependencyManager::get(); + QSharedPointer visage = DependencyManager::get(); + QSharedPointer dde = DependencyManager::get(); - return (dde->isActive() ? static_cast(dde) : - (faceshift->isActive() ? static_cast(faceshift) : - (visage->isActive() ? static_cast(visage) : NULL))); + return (dde->isActive() ? static_cast(dde.data()) : + (faceshift->isActive() ? static_cast(faceshift.data()) : + (visage->isActive() ? static_cast(visage.data()) : NULL))); } struct SendVoxelsOperationArgs { @@ -1778,7 +1780,7 @@ void Application::exportVoxels(const VoxelDetail& sourceVoxel) { QString desktopLocation = QStandardPaths::writableLocation(QStandardPaths::DesktopLocation); QString suggestedName = desktopLocation.append("/voxels.svo"); - QString fileNameString = QFileDialog::getSaveFileName(DependencyManager::get(), + QString fileNameString = QFileDialog::getSaveFileName(DependencyManager::get().data(), tr("Export Voxels"), suggestedName, tr("Sparse Voxel Octree Files (*.svo)")); QByteArray fileNameAscii = fileNameString.toLocal8Bit(); @@ -2034,9 +2036,9 @@ void Application::init() { _metavoxels.init(); - GLCanvas* glCanvas = DependencyManager::get(); - _audio.init(glCanvas); - _rearMirrorTools = new RearMirrorTools(glCanvas, _mirrorViewRect, _settings); + QSharedPointer glCanvas = DependencyManager::get(); + _audio.init(glCanvas.data()); + _rearMirrorTools = new RearMirrorTools(glCanvas.data(), _mirrorViewRect, _settings); connect(_rearMirrorTools, SIGNAL(closeView()), SLOT(closeMirrorView())); connect(_rearMirrorTools, SIGNAL(restoreView()), SLOT(restoreMirrorView())); @@ -2115,7 +2117,7 @@ void Application::updateMouseRay() { void Application::updateFaceshift() { bool showWarnings = Menu::getInstance()->isOptionChecked(MenuOption::PipelineWarnings); PerformanceWarning warn(showWarnings, "Application::updateFaceshift()"); - Faceshift* faceshift = DependencyManager::get(); + Faceshift* faceshift = DependencyManager::get().data(); // Update faceshift faceshift->update(); @@ -2919,7 +2921,7 @@ void Application::updateShadowMap() { fbo->release(); - GLCanvas* glCanvas = DependencyManager::get(); + QSharedPointer glCanvas = DependencyManager::get(); glViewport(0, 0, glCanvas->getDeviceWidth(), glCanvas->getDeviceHeight()); } @@ -3247,7 +3249,7 @@ void Application::computeOffAxisFrustum(float& left, float& right, float& bottom } glm::vec2 Application::getScaledScreenPoint(glm::vec2 projectedPoint) { - GLCanvas* glCanvas = DependencyManager::get(); + QSharedPointer glCanvas = DependencyManager::get(); float horizontalScale = glCanvas->getDeviceWidth() / 2.0f; float verticalScale = glCanvas->getDeviceHeight() / 2.0f; @@ -4260,7 +4262,7 @@ void Application::setPreviousScriptLocation(const QString& previousScriptLocatio void Application::loadDialog() { - QString fileNameString = QFileDialog::getOpenFileName(DependencyManager::get(), + QString fileNameString = QFileDialog::getOpenFileName(DependencyManager::get().data(), tr("Open Script"), getPreviousScriptLocation(), tr("JavaScript Files (*.js)")); @@ -4297,7 +4299,7 @@ void Application::loadScriptURLDialog() { void Application::toggleLogDialog() { if (! _logDialog) { - _logDialog = new LogDialog(DependencyManager::get(), getLogger()); + _logDialog = new LogDialog(DependencyManager::get().data(), getLogger()); } if (_logDialog->isVisible()) { @@ -4357,7 +4359,7 @@ void Application::parseVersionXml() { } if (!shouldSkipVersion(latestVersion) && applicationVersion() != latestVersion) { - new UpdateDialog(DependencyManager::get(), releaseNotes, latestVersion, downloadUrl); + new UpdateDialog(DependencyManager::get().data(), releaseNotes, latestVersion, downloadUrl); } sender->deleteLater(); } @@ -4390,7 +4392,7 @@ void Application::takeSnapshot() { } if (!_snapshotShareDialog) { - _snapshotShareDialog = new SnapshotShareDialog(fileName, DependencyManager::get()); + _snapshotShareDialog = new SnapshotShareDialog(fileName, DependencyManager::get().data()); } _snapshotShareDialog->show(); } diff --git a/interface/src/Application.h b/interface/src/Application.h index cddaeaad15..31f6d7d50a 100644 --- a/interface/src/Application.h +++ b/interface/src/Application.h @@ -173,7 +173,6 @@ public: glm::vec3 getMouseVoxelWorldCoordinates(const VoxelDetail& mouseVoxel); bool isThrottleRendering() const { return DependencyManager::get()->isThrottleRendering(); } - GLCanvas* getGLWidget() { return DependencyManager::get(); } // TODO: remove MyAvatar* getAvatar() { return _myAvatar; } Audio* getAudio() { return &_audio; } Camera* getCamera() { return &_myCamera; } diff --git a/interface/src/Camera.cpp b/interface/src/Camera.cpp index d069afb96a..181f783af1 100644 --- a/interface/src/Camera.cpp +++ b/interface/src/Camera.cpp @@ -95,10 +95,8 @@ void Camera::setFarClip(float f) { } PickRay Camera::computePickRay(float x, float y) { - float screenWidth = Application::getInstance()->getGLWidget()->width(); - float screenHeight = Application::getInstance()->getGLWidget()->height(); - - return computeViewPickRay(x / screenWidth, y / screenHeight); + QSharedPointer glCanvas = DependencyManager::get(); + return computeViewPickRay(x / glCanvas->width(), y / glCanvas->height()); } PickRay Camera::computeViewPickRay(float xRatio, float yRatio) { diff --git a/interface/src/Menu.cpp b/interface/src/Menu.cpp index 14327bd51a..501da725e4 100644 --- a/interface/src/Menu.cpp +++ b/interface/src/Menu.cpp @@ -436,12 +436,12 @@ Menu::Menu() : MenuOption::Faceshift, 0, true, - DependencyManager::get(), + DependencyManager::get().data(), SLOT(setTCPEnabled(bool))); #endif #ifdef HAVE_VISAGE addCheckableActionToQMenuAndActionHash(avatarDebugMenu, MenuOption::Visage, 0, false, - DependencyManager::get(), SLOT(updateEnabled())); + DependencyManager::get().data(), SLOT(updateEnabled())); #endif addCheckableActionToQMenuAndActionHash(avatarDebugMenu, MenuOption::RenderSkeletonCollisionShapes); @@ -1050,11 +1050,11 @@ void Menu::bumpSettings() { void sendFakeEnterEvent() { QPoint lastCursorPosition = QCursor::pos(); - QGLWidget* glWidget = Application::getInstance()->getGLWidget(); + QSharedPointer glCanvas = DependencyManager::get(); - QPoint windowPosition = glWidget->mapFromGlobal(lastCursorPosition); + QPoint windowPosition = glCanvas->mapFromGlobal(lastCursorPosition); QEnterEvent enterEvent = QEnterEvent(windowPosition, windowPosition, lastCursorPosition); - QCoreApplication::sendEvent(glWidget, &enterEvent); + QCoreApplication::sendEvent(glCanvas.data(), &enterEvent); } const float DIALOG_RATIO_OF_WINDOW = 0.30f; @@ -1302,7 +1302,7 @@ void Menu::toggleLoginMenuItem() { void Menu::bandwidthDetails() { if (! _bandwidthDialog) { - _bandwidthDialog = new BandwidthDialog(Application::getInstance()->getGLWidget(), + _bandwidthDialog = new BandwidthDialog(DependencyManager::get().data(), Application::getInstance()->getBandwidthMeter()); connect(_bandwidthDialog, SIGNAL(closed()), SLOT(bandwidthDetailsClosed())); @@ -1413,7 +1413,7 @@ void Menu::bandwidthDetailsClosed() { void Menu::octreeStatsDetails() { if (!_octreeStatsDialog) { - _octreeStatsDialog = new OctreeStatsDialog(Application::getInstance()->getGLWidget(), + _octreeStatsDialog = new OctreeStatsDialog(DependencyManager::get().data(), Application::getInstance()->getOcteeSceneStats()); connect(_octreeStatsDialog, SIGNAL(closed()), SLOT(octreeStatsDetailsClosed())); _octreeStatsDialog->show(); @@ -1597,7 +1597,7 @@ bool Menu::shouldRenderMesh(float largestDimension, float distanceToCamera) { void Menu::lodTools() { if (!_lodToolsDialog) { - _lodToolsDialog = new LodToolsDialog(Application::getInstance()->getGLWidget()); + _lodToolsDialog = new LodToolsDialog(DependencyManager::get().data()); connect(_lodToolsDialog, SIGNAL(closed()), SLOT(lodToolsClosed())); _lodToolsDialog->show(); if (_hmdToolsDialog) { @@ -1617,7 +1617,7 @@ void Menu::lodToolsClosed() { void Menu::hmdTools(bool showTools) { if (showTools) { if (!_hmdToolsDialog) { - _hmdToolsDialog = new HMDToolsDialog(Application::getInstance()->getGLWidget()); + _hmdToolsDialog = new HMDToolsDialog(DependencyManager::get().data()); connect(_hmdToolsDialog, SIGNAL(closed()), SLOT(hmdToolsClosed())); } _hmdToolsDialog->show(); diff --git a/interface/src/avatar/Head.cpp b/interface/src/avatar/Head.cpp index 42b3c968e1..150b67eb13 100644 --- a/interface/src/avatar/Head.cpp +++ b/interface/src/avatar/Head.cpp @@ -71,20 +71,19 @@ void Head::reset() { } void Head::simulate(float deltaTime, bool isMine, bool billboard) { - if (isMine) { MyAvatar* myAvatar = static_cast(_owningAvatar); // Only use face trackers when not playing back a recording. if (!myAvatar->isPlaying()) { FaceTracker* faceTracker = Application::getInstance()->getActiveFaceTracker(); - DdeFaceTracker* dde = DependencyManager::get(); - Faceshift* faceshift = DependencyManager::get(); + QSharedPointer dde = DependencyManager::get(); + QSharedPointer faceshift = DependencyManager::get(); if ((_isFaceshiftConnected = (faceshift == faceTracker))) { _blendshapeCoefficients = faceTracker->getBlendshapeCoefficients(); } else if (dde->isActive()) { - faceTracker = dde; + faceTracker = dde.data(); _blendshapeCoefficients = faceTracker->getBlendshapeCoefficients(); } } diff --git a/interface/src/avatar/MyAvatar.cpp b/interface/src/avatar/MyAvatar.cpp index 17cda19980..a546560ffd 100644 --- a/interface/src/avatar/MyAvatar.cpp +++ b/interface/src/avatar/MyAvatar.cpp @@ -422,7 +422,7 @@ void MyAvatar::render(const glm::vec3& cameraPosition, RenderMode renderMode, bo } void MyAvatar::renderHeadMouse(int screenWidth, int screenHeight) const { - Faceshift* faceshift = DependencyManager::get(); + QSharedPointer faceshift = DependencyManager::get(); float pixelsPerDegree = screenHeight / Menu::getInstance()->getFieldOfView(); diff --git a/interface/src/devices/DdeFaceTracker.h b/interface/src/devices/DdeFaceTracker.h index d80aa043e4..5ae17729d4 100644 --- a/interface/src/devices/DdeFaceTracker.h +++ b/interface/src/devices/DdeFaceTracker.h @@ -18,8 +18,9 @@ #include "FaceTracker.h" -class DdeFaceTracker : public FaceTracker, public DependencyManager::Dependency { +class DdeFaceTracker : public FaceTracker { Q_OBJECT + SINGLETON_DEPENDENCY public: //initialization @@ -58,7 +59,6 @@ private: DdeFaceTracker(); DdeFaceTracker(const QHostAddress& host, quint16 port); ~DdeFaceTracker(); - friend DependencyManager; float getBlendshapeCoefficient(int index) const; void decodePacket(const QByteArray& buffer); diff --git a/interface/src/devices/Faceshift.h b/interface/src/devices/Faceshift.h index 3cca8f2bb1..73971db49d 100644 --- a/interface/src/devices/Faceshift.h +++ b/interface/src/devices/Faceshift.h @@ -24,8 +24,9 @@ #include "FaceTracker.h" /// Handles interaction with the Faceshift software, which provides head position/orientation and facial features. -class Faceshift : public FaceTracker, public DependencyManager::Dependency { +class Faceshift : public FaceTracker { Q_OBJECT + SINGLETON_DEPENDENCY public: void init(); @@ -89,7 +90,6 @@ private slots: private: Faceshift(); virtual ~Faceshift() {} - friend DependencyManager; float getBlendshapeCoefficient(int index) const; diff --git a/interface/src/devices/OculusManager.cpp b/interface/src/devices/OculusManager.cpp index dfec98c358..99515cb7a9 100644 --- a/interface/src/devices/OculusManager.cpp +++ b/interface/src/devices/OculusManager.cpp @@ -560,8 +560,8 @@ void OculusManager::display(const glm::quat &bodyOrientation, const glm::vec3 &p } // restore our normal viewport - glViewport(0, 0, Application::getInstance()->getGLWidget()->getDeviceWidth(), - Application::getInstance()->getGLWidget()->getDeviceHeight()); + QSharedPointer glCanvas = DependencyManager::get(); + glViewport(0, 0, glCanvas->getDeviceWidth(), glCanvas->getDeviceHeight()); glMatrixMode(GL_PROJECTION); glPopMatrix(); @@ -579,8 +579,8 @@ void OculusManager::display(const glm::quat &bodyOrientation, const glm::vec3 &p void OculusManager::renderDistortionMesh(ovrPosef eyeRenderPose[ovrEye_Count]) { glLoadIdentity(); - gluOrtho2D(0, Application::getInstance()->getGLWidget()->getDeviceWidth(), 0, - Application::getInstance()->getGLWidget()->getDeviceHeight()); + QSharedPointer glCanvas = DependencyManager::get(); + gluOrtho2D(0, glCanvas->getDeviceWidth(), 0, glCanvas->getDeviceHeight()); glDisable(GL_DEPTH_TEST); diff --git a/interface/src/devices/PrioVR.cpp b/interface/src/devices/PrioVR.cpp index d3e985d259..ab7c317c37 100644 --- a/interface/src/devices/PrioVR.cpp +++ b/interface/src/devices/PrioVR.cpp @@ -215,8 +215,9 @@ void PrioVR::renderCalibrationCountdown() { static TextRenderer* textRenderer = TextRenderer::getInstance(MONO_FONT_FAMILY, 18, QFont::Bold, false, TextRenderer::OUTLINE_EFFECT, 2); QByteArray text = "Assume T-Pose in " + QByteArray::number(secondsRemaining) + "..."; - textRenderer->draw((Application::getInstance()->getGLWidget()->width() - - textRenderer->computeWidth(text.constData())) / 2, Application::getInstance()->getGLWidget()->height() / 2, - text); + QSharedPointer glCanvas = DependencyManager::get(); + textRenderer->draw((glCanvas->width() - textRenderer->computeWidth(text.constData())) / 2, + glCanvas->height() / 2, + text); #endif } diff --git a/interface/src/devices/SixenseManager.cpp b/interface/src/devices/SixenseManager.cpp index 7a555eb902..73e4f53289 100644 --- a/interface/src/devices/SixenseManager.cpp +++ b/interface/src/devices/SixenseManager.cpp @@ -461,7 +461,7 @@ void SixenseManager::updateCalibration(const sixenseControllerData* controllers) void SixenseManager::emulateMouse(PalmData* palm, int index) { Application* application = Application::getInstance(); MyAvatar* avatar = application->getAvatar(); - GLCanvas* widget = application->getGLWidget(); + QSharedPointer glCanvas = DependencyManager::get(); QPoint pos; Qt::MouseButton bumperButton; @@ -489,10 +489,10 @@ void SixenseManager::emulateMouse(PalmData* palm, int index) { float yAngle = 0.5f - ((atan2(direction.z, direction.y) + M_PI_2)); // Get the pixel range over which the xAngle and yAngle are scaled - float cursorRange = widget->width() * getCursorPixelRangeMult(); + float cursorRange = glCanvas->width() * getCursorPixelRangeMult(); - pos.setX(widget->width() / 2.0f + cursorRange * xAngle); - pos.setY(widget->height() / 2.0f + cursorRange * yAngle); + pos.setX(glCanvas->width() / 2.0f + cursorRange * xAngle); + pos.setY(glCanvas->height() / 2.0f + cursorRange * yAngle); } diff --git a/interface/src/devices/TV3DManager.cpp b/interface/src/devices/TV3DManager.cpp index d7d7353b24..5c891224a8 100644 --- a/interface/src/devices/TV3DManager.cpp +++ b/interface/src/devices/TV3DManager.cpp @@ -33,10 +33,10 @@ bool TV3DManager::isConnected() { } void TV3DManager::connect() { - Application* app = Application::getInstance(); - int width = app->getGLWidget()->getDeviceWidth(); - int height = app->getGLWidget()->getDeviceHeight(); - Camera& camera = *app->getCamera(); + QSharedPointer glCanvas = DependencyManager::get(); + int width = glCanvas->getDeviceWidth(); + int height = glCanvas->getDeviceHeight(); + Camera& camera = *Application::getInstance()->getCamera(); configureCamera(camera, width, height); } @@ -91,7 +91,8 @@ void TV3DManager::display(Camera& whichCamera) { // left eye portal int portalX = 0; int portalY = 0; - QSize deviceSize = Application::getInstance()->getGLWidget()->getDeviceSize() * + QSharedPointer glCanvas = DependencyManager::get(); + QSize deviceSize = glCanvas->getDeviceSize() * Application::getInstance()->getRenderResolutionScale(); int portalW = deviceSize.width() / 2; int portalH = deviceSize.height(); diff --git a/interface/src/devices/Visage.cpp b/interface/src/devices/Visage.cpp index 51b927df75..a810b1a258 100644 --- a/interface/src/devices/Visage.cpp +++ b/interface/src/devices/Visage.cpp @@ -121,7 +121,7 @@ static const QMultiHash >& getActionUnitNameMap() const float TRANSLATION_SCALE = 20.0f; void Visage::init() { - connect(DependencyManager::get(), SIGNAL(connectionStateChanged()), SLOT(updateEnabled())); + connect(DependencyManager::get().data(), SIGNAL(connectionStateChanged()), SLOT(updateEnabled())); updateEnabled(); } diff --git a/interface/src/devices/Visage.h b/interface/src/devices/Visage.h index 73edddc4d7..38e337aada 100644 --- a/interface/src/devices/Visage.h +++ b/interface/src/devices/Visage.h @@ -26,8 +26,9 @@ namespace VisageSDK { } /// Handles input from the Visage webcam feature tracking software. -class Visage : public FaceTracker, public DependencyManager::Dependency { +class Visage : public FaceTracker { Q_OBJECT + SINGLETON_DEPENDENCY public: void init(); @@ -44,7 +45,6 @@ public slots: private: Visage(); virtual ~Visage(); - friend DependencyManager; #ifdef HAVE_VISAGE VisageSDK::VisageTracker2* _tracker; diff --git a/interface/src/renderer/GlowEffect.cpp b/interface/src/renderer/GlowEffect.cpp index 9e9c1f2ed5..a760889eff 100644 --- a/interface/src/renderer/GlowEffect.cpp +++ b/interface/src/renderer/GlowEffect.cpp @@ -139,15 +139,15 @@ QOpenGLFramebufferObject* GlowEffect::render(bool toTexture) { QOpenGLFramebufferObject* destFBO = toTexture ? Application::getInstance()->getTextureCache()->getSecondaryFramebufferObject() : NULL; + QSharedPointer glCanvas = DependencyManager::get(); if (!Menu::getInstance()->isOptionChecked(MenuOption::EnableGlowEffect) || _isEmpty) { // copy the primary to the screen if (destFBO && QOpenGLFramebufferObject::hasOpenGLFramebufferBlit()) { - QOpenGLFramebufferObject::blitFramebuffer(destFBO, primaryFBO); + QOpenGLFramebufferObject::blitFramebuffer(destFBO, primaryFBO); } else { maybeBind(destFBO); if (!destFBO) { - glViewport(0, 0, Application::getInstance()->getGLWidget()->getDeviceWidth(), - Application::getInstance()->getGLWidget()->getDeviceHeight()); + glViewport(0, 0, glCanvas->getDeviceWidth(), glCanvas->getDeviceHeight()); } glEnable(GL_TEXTURE_2D); glDisable(GL_LIGHTING); @@ -194,9 +194,7 @@ QOpenGLFramebufferObject* GlowEffect::render(bool toTexture) { } maybeBind(destFBO); if (!destFBO) { - glViewport(0, 0, - Application::getInstance()->getGLWidget()->getDeviceWidth(), - Application::getInstance()->getGLWidget()->getDeviceHeight()); + glViewport(0, 0, glCanvas->getDeviceWidth(), glCanvas->getDeviceHeight()); } _addSeparateProgram->bind(); renderFullscreenQuad(); diff --git a/interface/src/renderer/TextureCache.cpp b/interface/src/renderer/TextureCache.cpp index f40f0e3faf..ec07d22647 100644 --- a/interface/src/renderer/TextureCache.cpp +++ b/interface/src/renderer/TextureCache.cpp @@ -352,7 +352,7 @@ QSharedPointer TextureCache::createResource(const QUrl& url, QOpenGLFramebufferObject* TextureCache::createFramebufferObject() { QOpenGLFramebufferObject* fbo = new QOpenGLFramebufferObject(_frameBufferSize); - Application::getInstance()->getGLWidget()->installEventFilter(this); + DependencyManager::get()->installEventFilter(this); glBindTexture(GL_TEXTURE_2D, fbo->texture()); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); diff --git a/interface/src/scripting/ControllerScriptingInterface.cpp b/interface/src/scripting/ControllerScriptingInterface.cpp index bcfe844668..a562236a92 100644 --- a/interface/src/scripting/ControllerScriptingInterface.cpp +++ b/interface/src/scripting/ControllerScriptingInterface.cpp @@ -267,9 +267,9 @@ void ControllerScriptingInterface::releaseJoystick(int joystickIndex) { } } -glm::vec2 ControllerScriptingInterface::getViewportDimensions() const { - GLCanvas* widget = Application::getInstance()->getGLWidget(); - return glm::vec2(widget->width(), widget->height()); +glm::vec2 ControllerScriptingInterface::getViewportDimensions() const { + QSharedPointer glCanvas = DependencyManager::get(); + return glm::vec2(glCanvas->width(), glCanvas->height()); } AbstractInputController* ControllerScriptingInterface::createInputController(const QString& deviceName, const QString& tracker) { diff --git a/interface/src/scripting/WindowScriptingInterface.cpp b/interface/src/scripting/WindowScriptingInterface.cpp index d69b1d0ba1..d84fc97cd8 100644 --- a/interface/src/scripting/WindowScriptingInterface.cpp +++ b/interface/src/scripting/WindowScriptingInterface.cpp @@ -40,7 +40,7 @@ WebWindowClass* WindowScriptingInterface::doCreateWebWindow(const QString& title } QScriptValue WindowScriptingInterface::hasFocus() { - return Application::getInstance()->getGLWidget()->hasFocus(); + return DependencyManager::get()->hasFocus(); } void WindowScriptingInterface::setCursorVisible(bool visible) { diff --git a/interface/src/ui/ApplicationOverlay.cpp b/interface/src/ui/ApplicationOverlay.cpp index f4e0c9769d..c95dc08e79 100644 --- a/interface/src/ui/ApplicationOverlay.cpp +++ b/interface/src/ui/ApplicationOverlay.cpp @@ -145,11 +145,11 @@ void ApplicationOverlay::renderOverlay(bool renderToTexture) { PerformanceWarning warn(Menu::getInstance()->isOptionChecked(MenuOption::PipelineWarnings), "ApplicationOverlay::displayOverlay()"); Application* application = Application::getInstance(); Overlays& overlays = application->getOverlays(); - GLCanvas* glWidget = application->getGLWidget(); + QSharedPointer glCanvas = DependencyManager::get(); MyAvatar* myAvatar = application->getAvatar(); _textureFov = glm::radians(Menu::getInstance()->getOculusUIAngularSize()); - _textureAspectRatio = (float)application->getGLWidget()->getDeviceWidth() / (float)application->getGLWidget()->getDeviceHeight(); + _textureAspectRatio = (float)glCanvas->getDeviceWidth() / (float)glCanvas->getDeviceHeight(); //Handle fading and deactivation/activation of UI if (Menu::getInstance()->isOptionChecked(MenuOption::UserInterface)) { @@ -178,12 +178,12 @@ void ApplicationOverlay::renderOverlay(bool renderToTexture) { glPushMatrix(); { glLoadIdentity(); - gluOrtho2D(0, glWidget->width(), glWidget->height(), 0); + gluOrtho2D(0, glCanvas->width(), glCanvas->height(), 0); renderAudioMeter(); if (Menu::getInstance()->isOptionChecked(MenuOption::HeadMouse)) { - myAvatar->renderHeadMouse(glWidget->width(), glWidget->height()); + myAvatar->renderHeadMouse(glCanvas->width(), glCanvas->height()); } renderStatsAndLogs(); @@ -213,7 +213,7 @@ void ApplicationOverlay::displayOverlayTexture() { if (_alpha == 0.0f) { return; } - GLCanvas* glWidget = Application::getInstance()->getGLWidget(); + QSharedPointer glCanvas = DependencyManager::get(); glEnable(GL_TEXTURE_2D); glActiveTexture(GL_TEXTURE0); @@ -222,16 +222,16 @@ void ApplicationOverlay::displayOverlayTexture() { glMatrixMode(GL_PROJECTION); glPushMatrix(); { glLoadIdentity(); - gluOrtho2D(0, glWidget->getDeviceWidth(), glWidget->getDeviceHeight(), 0); + gluOrtho2D(0, glCanvas->getDeviceWidth(), glCanvas->getDeviceHeight(), 0); glDisable(GL_DEPTH_TEST); glDisable(GL_LIGHTING); glEnable(GL_BLEND); glBegin(GL_QUADS); { glColor4f(1.0f, 1.0f, 1.0f, _alpha); - glTexCoord2f(0, 0); glVertex2i(0, glWidget->getDeviceHeight()); - glTexCoord2f(1, 0); glVertex2i(glWidget->getDeviceWidth(), glWidget->getDeviceHeight()); - glTexCoord2f(1, 1); glVertex2i(glWidget->getDeviceWidth(), 0); + glTexCoord2f(0, 0); glVertex2i(0, glCanvas->getDeviceHeight()); + glTexCoord2f(1, 0); glVertex2i(glCanvas->getDeviceWidth(), glCanvas->getDeviceHeight()); + glTexCoord2f(1, 1); glVertex2i(glCanvas->getDeviceWidth(), 0); glTexCoord2f(0, 1); glVertex2i(0, 0); } glEnd(); } glPopMatrix(); @@ -378,18 +378,19 @@ void ApplicationOverlay::displayOverlayTexture3DTV(Camera& whichCamera, float as glEnd(); + QSharedPointer glCanvas = DependencyManager::get(); if (_crosshairTexture == 0) { - _crosshairTexture = Application::getInstance()->getGLWidget()->bindTexture(QImage(Application::resourcesPath() + "images/sixense-reticle.png")); + _crosshairTexture = glCanvas->bindTexture(QImage(Application::resourcesPath() + "images/sixense-reticle.png")); } //draw the mouse pointer glBindTexture(GL_TEXTURE_2D, _crosshairTexture); - const float reticleSize = 40.0f / application->getGLWidget()->width() * quadWidth; + const float reticleSize = 40.0f / glCanvas->width() * quadWidth; x -= reticleSize / 2.0f; y += reticleSize / 2.0f; - const float mouseX = (application->getMouseX() / (float)application->getGLWidget()->width()) * quadWidth; - const float mouseY = (1.0 - (application->getMouseY() / (float)application->getGLWidget()->height())) * quadHeight; + const float mouseX = (application->getMouseX() / (float)glCanvas->width()) * quadWidth; + const float mouseY = (1.0 - (application->getMouseY() / (float)glCanvas->height())) * quadHeight; glBegin(GL_QUADS); @@ -431,7 +432,7 @@ void ApplicationOverlay::computeOculusPickRay(float x, float y, glm::vec3& origi //Caculate the click location using one of the sixense controllers. Scale is not applied QPoint ApplicationOverlay::getPalmClickLocation(const PalmData *palm) const { Application* application = Application::getInstance(); - GLCanvas* glWidget = application->getGLWidget(); + QSharedPointer glCanvas = DependencyManager::get(); MyAvatar* myAvatar = application->getAvatar(); glm::vec3 tip = myAvatar->getLaserPointerTipPosition(palm); @@ -462,8 +463,8 @@ QPoint ApplicationOverlay::getPalmClickLocation(const PalmData *palm) const { float u = asin(collisionPos.x) / (_textureFov)+0.5f; float v = 1.0 - (asin(collisionPos.y) / (_textureFov)+0.5f); - rv.setX(u * glWidget->width()); - rv.setY(v * glWidget->height()); + rv.setX(u * glCanvas->width()); + rv.setY(v * glCanvas->height()); } } else { //if they did not click on the overlay, just set the coords to INT_MAX @@ -480,8 +481,8 @@ QPoint ApplicationOverlay::getPalmClickLocation(const PalmData *palm) const { ndcSpacePos = glm::vec3(clipSpacePos) / clipSpacePos.w; } - rv.setX(((ndcSpacePos.x + 1.0) / 2.0) * glWidget->width()); - rv.setY((1.0 - ((ndcSpacePos.y + 1.0) / 2.0)) * glWidget->height()); + rv.setX(((ndcSpacePos.x + 1.0) / 2.0) * glCanvas->width()); + rv.setY((1.0 - ((ndcSpacePos.y + 1.0) / 2.0)) * glCanvas->height()); } return rv; } @@ -510,10 +511,11 @@ bool ApplicationOverlay::calculateRayUICollisionPoint(const glm::vec3& position, //Renders optional pointers void ApplicationOverlay::renderPointers() { Application* application = Application::getInstance(); + QSharedPointer glCanvas = DependencyManager::get(); //lazily load crosshair texture if (_crosshairTexture == 0) { - _crosshairTexture = Application::getInstance()->getGLWidget()->bindTexture(QImage(Application::resourcesPath() + "images/sixense-reticle.png")); + _crosshairTexture = glCanvas->bindTexture(QImage(Application::resourcesPath() + "images/sixense-reticle.png")); } glEnable(GL_TEXTURE_2D); @@ -536,7 +538,7 @@ void ApplicationOverlay::renderPointers() { glm::vec2 screenPos = sphericalToScreen(glm::vec2(yaw, -pitch)); position = QPoint(screenPos.x, screenPos.y); - application->getGLWidget()->cursor().setPos(application->getGLWidget()->mapToGlobal(position)); + glCanvas->cursor().setPos(glCanvas->mapToGlobal(position)); } _reticlePosition[MOUSE] = position; @@ -557,7 +559,7 @@ void ApplicationOverlay::renderPointers() { void ApplicationOverlay::renderControllerPointers() { Application* application = Application::getInstance(); - GLCanvas* glWidget = application->getGLWidget(); + QSharedPointer glCanvas = DependencyManager::get(); MyAvatar* myAvatar = application->getAvatar(); //Static variables used for storing controller state @@ -635,14 +637,14 @@ void ApplicationOverlay::renderControllerPointers() { float yAngle = 0.5f - ((atan2(direction.z, direction.y) + M_PI_2)); // Get the pixel range over which the xAngle and yAngle are scaled - float cursorRange = glWidget->width() * SixenseManager::getInstance().getCursorPixelRangeMult(); + float cursorRange = glCanvas->width() * SixenseManager::getInstance().getCursorPixelRangeMult(); - mouseX = (glWidget->width() / 2.0f + cursorRange * xAngle); - mouseY = (glWidget->height() / 2.0f + cursorRange * yAngle); + mouseX = (glCanvas->width() / 2.0f + cursorRange * xAngle); + mouseY = (glCanvas->height() / 2.0f + cursorRange * yAngle); } //If the cursor is out of the screen then don't render it - if (mouseX < 0 || mouseX >= glWidget->width() || mouseY < 0 || mouseY >= glWidget->height()) { + if (mouseX < 0 || mouseX >= glCanvas->width() || mouseY < 0 || mouseY >= glCanvas->height()) { _reticleActive[index] = false; continue; } @@ -702,11 +704,10 @@ void ApplicationOverlay::renderPointersOculus(const glm::vec3& eyePos) { //Renders a small magnification of the currently bound texture at the coordinates void ApplicationOverlay::renderMagnifier(glm::vec2 magPos, float sizeMult, bool showBorder) const { - Application* application = Application::getInstance(); - GLCanvas* glWidget = application->getGLWidget(); + QSharedPointer glCanvas = DependencyManager::get(); - const int widgetWidth = glWidget->width(); - const int widgetHeight = glWidget->height(); + const int widgetWidth = glCanvas->width(); + const int widgetHeight = glCanvas->height(); const float halfWidth = (MAGNIFY_WIDTH / _textureAspectRatio) * sizeMult / 2.0f; const float halfHeight = MAGNIFY_HEIGHT * sizeMult / 2.0f; @@ -760,8 +761,8 @@ void ApplicationOverlay::renderMagnifier(glm::vec2 magPos, float sizeMult, bool void ApplicationOverlay::renderAudioMeter() { Application* application = Application::getInstance(); - - GLCanvas* glWidget = application->getGLWidget(); + + QSharedPointer glCanvas = DependencyManager::get(); Audio* audio = application->getAudio(); // Display a single screen-size quad to create an alpha blended 'collision' flash @@ -769,7 +770,7 @@ void ApplicationOverlay::renderAudioMeter() { float collisionSoundMagnitude = audio->getCollisionSoundMagnitude(); const float VISIBLE_COLLISION_SOUND_MAGNITUDE = 0.5f; if (collisionSoundMagnitude > VISIBLE_COLLISION_SOUND_MAGNITUDE) { - renderCollisionOverlay(glWidget->width(), glWidget->height(), + renderCollisionOverlay(glCanvas->width(), glCanvas->height(), audio->getCollisionSoundMagnitude()); } } @@ -823,14 +824,14 @@ void ApplicationOverlay::renderAudioMeter() { if ((audio->getTimeSinceLastClip() > 0.0f) && (audio->getTimeSinceLastClip() < CLIPPING_INDICATOR_TIME)) { const float MAX_MAGNITUDE = 0.7f; float magnitude = MAX_MAGNITUDE * (1 - audio->getTimeSinceLastClip() / CLIPPING_INDICATOR_TIME); - renderCollisionOverlay(glWidget->width(), glWidget->height(), magnitude, 1.0f); + renderCollisionOverlay(glCanvas->width(), glCanvas->height(), magnitude, 1.0f); } audio->renderToolBox(MIRROR_VIEW_LEFT_PADDING + AUDIO_METER_GAP, audioMeterY, boxed); - audio->renderScope(glWidget->width(), glWidget->height()); + audio->renderScope(glCanvas->width(), glCanvas->height()); - audio->renderStats(WHITE_TEXT, glWidget->width(), glWidget->height()); + audio->renderStats(WHITE_TEXT, glCanvas->width(), glCanvas->height()); glBegin(GL_QUADS); if (isClipping) { @@ -891,8 +892,8 @@ void ApplicationOverlay::renderAudioMeter() { void ApplicationOverlay::renderStatsAndLogs() { Application* application = Application::getInstance(); - - GLCanvas* glWidget = application->getGLWidget(); + + QSharedPointer glCanvas = DependencyManager::get(); const OctreePacketProcessor& octreePacketProcessor = application->getOctreePacketProcessor(); BandwidthMeter* bandwidthMeter = application->getBandwidthMeter(); NodeBounds& nodeBoundsDisplay = application->getNodeBoundsDisplay(); @@ -910,8 +911,8 @@ void ApplicationOverlay::renderStatsAndLogs() { application->getPacketsPerSecond(), application->getBytesPerSecond(), voxelPacketsToProcess); // Bandwidth meter if (Menu::getInstance()->isOptionChecked(MenuOption::Bandwidth)) { - Stats::drawBackground(0x33333399, glWidget->width() - 296, glWidget->height() - 68, 296, 68); - bandwidthMeter->render(glWidget->width(), glWidget->height()); + Stats::drawBackground(0x33333399, glCanvas->width() - 296, glCanvas->height() - 68, 296, 68); + bandwidthMeter->render(glCanvas->width(), glCanvas->height()); } } @@ -924,7 +925,7 @@ void ApplicationOverlay::renderStatsAndLogs() { (Menu::getInstance()->isOptionChecked(MenuOption::Stats) && Menu::getInstance()->isOptionChecked(MenuOption::Bandwidth)) ? 80 : 20; - drawText(glWidget->width() - 100, glWidget->height() - timerBottom, + drawText(glCanvas->width() - 100, glCanvas->height() - timerBottom, 0.30f, 0.0f, 0, frameTimer, WHITE_TEXT); } nodeBoundsDisplay.drawOverlay(); @@ -934,9 +935,9 @@ void ApplicationOverlay::renderDomainConnectionStatusBorder() { NodeList* nodeList = NodeList::getInstance(); if (nodeList && !nodeList->getDomainHandler().isConnected()) { - GLCanvas* glWidget = Application::getInstance()->getGLWidget(); - int right = glWidget->width(); - int bottom = glWidget->height(); + QSharedPointer glCanvas = DependencyManager::get(); + int right = glCanvas->width(); + int bottom = glCanvas->height(); glColor3f(CONNECTION_STATUS_BORDER_COLOR[0], CONNECTION_STATUS_BORDER_COLOR[1], @@ -1071,7 +1072,7 @@ void ApplicationOverlay::TexturedHemisphere::cleanupVBO() { } void ApplicationOverlay::TexturedHemisphere::buildFramebufferObject() { - QSize size = Application::getInstance()->getGLWidget()->getDeviceSize(); + QSize size = DependencyManager::get()->getDeviceSize(); if (_framebufferObject != NULL && size == _framebufferObject->size()) { // Already build return; @@ -1122,7 +1123,7 @@ void ApplicationOverlay::TexturedHemisphere::render() { glm::vec2 ApplicationOverlay::screenToSpherical(glm::vec2 screenPos) const { - QSize screenSize = Application::getInstance()->getGLWidget()->getDeviceSize(); + QSize screenSize = DependencyManager::get()->getDeviceSize(); float yaw = -(screenPos.x / screenSize.width() - 0.5f) * MOUSE_YAW_RANGE; float pitch = (screenPos.y / screenSize.height() - 0.5f) * MOUSE_PITCH_RANGE; @@ -1130,7 +1131,7 @@ glm::vec2 ApplicationOverlay::screenToSpherical(glm::vec2 screenPos) const { } glm::vec2 ApplicationOverlay::sphericalToScreen(glm::vec2 sphericalPos) const { - QSize screenSize = Application::getInstance()->getGLWidget()->getDeviceSize(); + QSize screenSize = DependencyManager::get()->getDeviceSize(); float x = (-sphericalPos.x / MOUSE_YAW_RANGE + 0.5f) * screenSize.width(); float y = (sphericalPos.y / MOUSE_PITCH_RANGE + 0.5f) * screenSize.height(); @@ -1138,7 +1139,7 @@ glm::vec2 ApplicationOverlay::sphericalToScreen(glm::vec2 sphericalPos) const { } glm::vec2 ApplicationOverlay::sphericalToOverlay(glm::vec2 sphericalPos) const { - QSize screenSize = Application::getInstance()->getGLWidget()->getDeviceSize(); + QSize screenSize = DependencyManager::get()->getDeviceSize(); float x = (-sphericalPos.x / (_textureFov * _textureAspectRatio) + 0.5f) * screenSize.width(); float y = (sphericalPos.y / _textureFov + 0.5f) * screenSize.height(); @@ -1146,7 +1147,7 @@ glm::vec2 ApplicationOverlay::sphericalToOverlay(glm::vec2 sphericalPos) const { } glm::vec2 ApplicationOverlay::overlayToSpherical(glm::vec2 overlayPos) const { - QSize screenSize = Application::getInstance()->getGLWidget()->getDeviceSize(); + QSize screenSize = DependencyManager::get()->getDeviceSize(); float yaw = -(overlayPos.x / screenSize.width() - 0.5f) * _textureFov * _textureAspectRatio; float pitch = (overlayPos.y / screenSize.height() - 0.5f) * _textureFov; diff --git a/interface/src/ui/MetavoxelEditor.cpp b/interface/src/ui/MetavoxelEditor.cpp index 46f69b0452..75f2ebf97f 100644 --- a/interface/src/ui/MetavoxelEditor.cpp +++ b/interface/src/ui/MetavoxelEditor.cpp @@ -138,7 +138,7 @@ MetavoxelEditor::MetavoxelEditor() : connect(Application::getInstance()->getMetavoxels(), &MetavoxelSystem::rendering, this, &MetavoxelEditor::renderPreview); - Application::getInstance()->getGLWidget()->installEventFilter(this); + DependencyManager::get()->installEventFilter(this); show(); diff --git a/interface/src/ui/MetavoxelNetworkSimulator.cpp b/interface/src/ui/MetavoxelNetworkSimulator.cpp index aabee97636..7185524d6f 100644 --- a/interface/src/ui/MetavoxelNetworkSimulator.cpp +++ b/interface/src/ui/MetavoxelNetworkSimulator.cpp @@ -21,7 +21,7 @@ const int BYTES_PER_KILOBYTE = 1024; MetavoxelNetworkSimulator::MetavoxelNetworkSimulator() : - QWidget(Application::getInstance()->getGLWidget(), Qt::Dialog) { + QWidget(DependencyManager::get().data(), Qt::Dialog) { setWindowTitle("Metavoxel Network Simulator"); setAttribute(Qt::WA_DeleteOnClose); diff --git a/interface/src/ui/PreferencesDialog.cpp b/interface/src/ui/PreferencesDialog.cpp index 318dce977a..d39266e0fd 100644 --- a/interface/src/ui/PreferencesDialog.cpp +++ b/interface/src/ui/PreferencesDialog.cpp @@ -215,8 +215,8 @@ void PreferencesDialog::savePreferences() { myAvatar->setClampedTargetScale(ui.avatarScaleSpin->value()); Application::getInstance()->getVoxels()->setMaxVoxels(ui.maxVoxelsSpin->value()); - Application::getInstance()->resizeGL(Application::getInstance()->getGLWidget()->width(), - Application::getInstance()->getGLWidget()->height()); + QSharedPointer glCanvas = DependencyManager::get(); + Application::getInstance()->resizeGL(glCanvas->width(), glCanvas->height()); Menu::getInstance()->setRealWorldFieldOfView(ui.realWorldFieldOfViewSpin->value()); @@ -248,8 +248,7 @@ void PreferencesDialog::savePreferences() { Menu::getInstance()->setReceivedAudioStreamSettings(streamSettings); Application::getInstance()->getAudio()->setReceivedAudioStreamSettings(streamSettings); - Application::getInstance()->resizeGL(Application::getInstance()->getGLWidget()->width(), - Application::getInstance()->getGLWidget()->height()); + Application::getInstance()->resizeGL(glCanvas->width(), glCanvas->height()); Application::getInstance()->bumpSettings(); } diff --git a/interface/src/ui/Snapshot.cpp b/interface/src/ui/Snapshot.cpp index d68920a5f5..ddd2b93805 100644 --- a/interface/src/ui/Snapshot.cpp +++ b/interface/src/ui/Snapshot.cpp @@ -83,9 +83,8 @@ QTemporaryFile* Snapshot::saveTempSnapshot() { } QFile* Snapshot::savedFileForSnapshot(bool isTemporary) { - - QGLWidget* widget = Application::getInstance()->getGLWidget(); - QImage shot = widget->grabFrameBuffer(); + QSharedPointer glCanvas = DependencyManager::get(); + QImage shot = glCanvas->grabFrameBuffer(); Avatar* avatar = Application::getInstance()->getAvatar(); diff --git a/interface/src/ui/Stats.cpp b/interface/src/ui/Stats.cpp index 9abb3d1b78..2581866c70 100644 --- a/interface/src/ui/Stats.cpp +++ b/interface/src/ui/Stats.cpp @@ -56,8 +56,8 @@ Stats::Stats(): _metavoxelReceiveProgress(0), _metavoxelReceiveTotal(0) { - GLCanvas* glWidget = Application::getInstance()->getGLWidget(); - resetWidth(glWidget->width(), 0); + QSharedPointer glCanvas = DependencyManager::get(); + resetWidth(glCanvas->width(), 0); } void Stats::toggleExpanded() { @@ -67,7 +67,7 @@ void Stats::toggleExpanded() { // called on mouse click release // check for clicks over stats in order to expand or contract them void Stats::checkClick(int mouseX, int mouseY, int mouseDragStartedX, int mouseDragStartedY, int horizontalOffset) { - GLCanvas* glWidget = Application::getInstance()->getGLWidget(); + QSharedPointer glCanvas = DependencyManager::get(); if (0 != glm::compMax(glm::abs(glm::ivec2(mouseX - mouseDragStartedX, mouseY - mouseDragStartedY)))) { // not worried about dragging on stats @@ -114,7 +114,7 @@ void Stats::checkClick(int mouseX, int mouseY, int mouseDragStartedX, int mouseD // top-right stats click lines = _expanded ? 11 : 3; statsHeight = lines * STATS_PELS_PER_LINE + 10; - statsWidth = glWidget->width() - statsX; + statsWidth = glCanvas->width() - statsX; if (mouseX > statsX && mouseX < statsX + statsWidth && mouseY > statsY && mouseY < statsY + statsHeight) { toggleExpanded(); return; @@ -122,8 +122,8 @@ void Stats::checkClick(int mouseX, int mouseY, int mouseDragStartedX, int mouseD } void Stats::resetWidth(int width, int horizontalOffset) { - GLCanvas* glWidget = Application::getInstance()->getGLWidget(); - int extraSpace = glWidget->width() - horizontalOffset -2 + QSharedPointer glCanvas = DependencyManager::get(); + int extraSpace = glCanvas->width() - horizontalOffset -2 - STATS_GENERAL_MIN_WIDTH - (Menu::getInstance()->isOptionChecked(MenuOption::TestPing) ? STATS_PING_MIN_WIDTH -1 : 0) - STATS_GEO_MIN_WIDTH @@ -147,7 +147,7 @@ void Stats::resetWidth(int width, int horizontalOffset) { _pingStatsWidth += (int) extraSpace / panels; } _geoStatsWidth += (int) extraSpace / panels; - _voxelStatsWidth += glWidget->width() - (_generalStatsWidth + _pingStatsWidth + _geoStatsWidth + 3); + _voxelStatsWidth += glCanvas->width() - (_generalStatsWidth + _pingStatsWidth + _geoStatsWidth + 3); } } @@ -198,7 +198,7 @@ void Stats::display( int bytesPerSecond, int voxelPacketsToProcess) { - GLCanvas* glWidget = Application::getInstance()->getGLWidget(); + QSharedPointer glCanvas = DependencyManager::get(); unsigned int backgroundColor = 0x33333399; int verticalOffset = 0, lines = 0; @@ -210,7 +210,7 @@ void Stats::display( std::stringstream voxelStats; if (_lastHorizontalOffset != horizontalOffset) { - resetWidth(glWidget->width(), horizontalOffset); + resetWidth(glCanvas->width(), horizontalOffset); _lastHorizontalOffset = horizontalOffset; } @@ -478,7 +478,7 @@ void Stats::display( lines = _expanded ? 14 : 3; - drawBackground(backgroundColor, horizontalOffset, 0, glWidget->width() - horizontalOffset, + drawBackground(backgroundColor, horizontalOffset, 0, glCanvas->width() - horizontalOffset, lines * STATS_PELS_PER_LINE + 10); horizontalOffset += 5; From cf6aa563ac30635a11444e69215256446ecf8b6d Mon Sep 17 00:00:00 2001 From: Atlante45 Date: Tue, 16 Dec 2014 13:54:24 -0800 Subject: [PATCH 04/11] DM returns shared pointer --- libraries/shared/src/DependencyManager.cpp | 4 -- libraries/shared/src/DependencyManager.h | 51 ++++++++++------------ 2 files changed, 22 insertions(+), 33 deletions(-) diff --git a/libraries/shared/src/DependencyManager.cpp b/libraries/shared/src/DependencyManager.cpp index c858cb7059..43bb92258e 100644 --- a/libraries/shared/src/DependencyManager.cpp +++ b/libraries/shared/src/DependencyManager.cpp @@ -17,8 +17,4 @@ DependencyManager& DependencyManager::getInstance() { } DependencyManager::~DependencyManager() { - foreach (Dependency* instance, _instanceHash) { - delete instance; - } - _instanceHash.clear(); } \ No newline at end of file diff --git a/libraries/shared/src/DependencyManager.h b/libraries/shared/src/DependencyManager.h index 87c7c7b4a6..455ec38bca 100644 --- a/libraries/shared/src/DependencyManager.h +++ b/libraries/shared/src/DependencyManager.h @@ -12,55 +12,48 @@ #ifndef hifi_DependencyManager_h #define hifi_DependencyManager_h -#include -#include +#include #include -#include + +#define SINGLETON_DEPENDENCY(T)\ +public:\ + typedef QSharedPointer SharedPointer;\ +private:\ + void customDeleter() { delete this; }\ + friend class DependencyManager; + +class QObject; class DependencyManager { public: // Only accessible method. // usage: T* instance = DependencyManager::get(); template - 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; - }; + static QSharedPointer get(); private: static DependencyManager& getInstance(); DependencyManager() {} ~DependencyManager(); - typedef QHash InstanceHash; - static InstanceHash& getInstanceHash() { return getInstance()._instanceHash; } - InstanceHash _instanceHash; + static void noDelete(void*) {} }; template -T* DependencyManager::get() { - const QString& typeId = typeid(T).name(); +QSharedPointer DependencyManager::get() { + static QSharedPointer sharedPointer; + static T* instance = new T(); - // Search the hash for global instance - Dependency* instance = getInstanceHash().value(typeId, NULL); if (instance) { - return dynamic_cast(instance); + if (dynamic_cast(instance)) { // If this is a QOject, call deleteLater for destruction + sharedPointer = QSharedPointer(instance, &T::deleteLater); + } else { // Otherwise use custom deleter to avoid issues between private destructor and QSharedPointer + sharedPointer = QSharedPointer(instance, &T::customDeleter); + } + instance = NULL; } - - // Found no instance in hash so we create one. - T* newInstance = new T(); - instance = dynamic_cast(newInstance); - assert(instance != NULL); // If this triggers, check that T is derived from Dependency - getInstanceHash().insert(typeId, instance); - return newInstance; + return sharedPointer; } #endif // hifi_DependencyManager_h From e8a22f6f0f31d3f2adcc08751492b160490d47ae Mon Sep 17 00:00:00 2001 From: Atlante45 Date: Tue, 16 Dec 2014 13:54:52 -0800 Subject: [PATCH 05/11] Switched to chared pointers and macros --- interface/src/Application.cpp | 3 +-- interface/src/GLCanvas.h | 9 ++++++--- interface/src/devices/DdeFaceTracker.h | 2 +- interface/src/devices/Faceshift.h | 2 +- interface/src/devices/Visage.h | 2 +- 5 files changed, 10 insertions(+), 8 deletions(-) diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index 4c9fdcaf0f..50275fcd1c 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -194,7 +194,7 @@ Application::Application(int& argc, char** argv, QElapsedTimer &startup_time) : _isVSyncOn(true), _aboutToQuit(false) { - QSharedPointer glCanvas = DependencyManager::get(); + GLCanvas::SharedPointer glCanvas = DependencyManager::get(); // read the ApplicationInfo.ini file for Name/Version/Domain information QSettings applicationInfo(Application::resourcesPath() + "info/ApplicationInfo.ini", QSettings::IniFormat); @@ -442,7 +442,6 @@ void Application::aboutToQuit() { } Application::~Application() { - DependencyManager::get()->setParent(NULL); _entities.getTree()->setSimulation(NULL); qInstallMessageHandler(NULL); diff --git a/interface/src/GLCanvas.h b/interface/src/GLCanvas.h index 2b1cd3539d..420bf77467 100644 --- a/interface/src/GLCanvas.h +++ b/interface/src/GLCanvas.h @@ -18,8 +18,10 @@ #include /// customized canvas that simply forwards requests/events to the singleton application -class GLCanvas : public QGLWidget, public DependencyManager::Dependency { +class GLCanvas : public QGLWidget { Q_OBJECT + SINGLETON_DEPENDENCY(GLCanvas) + public: bool isThrottleRendering() const; @@ -60,8 +62,9 @@ private slots: private: GLCanvas(); - ~GLCanvas(); - friend class DependencyManager; + ~GLCanvas() { + qDebug() << "Deleting GLCanvas"; + } }; #endif // hifi_GLCanvas_h diff --git a/interface/src/devices/DdeFaceTracker.h b/interface/src/devices/DdeFaceTracker.h index 5ae17729d4..23a5d1fcc8 100644 --- a/interface/src/devices/DdeFaceTracker.h +++ b/interface/src/devices/DdeFaceTracker.h @@ -20,7 +20,7 @@ class DdeFaceTracker : public FaceTracker { Q_OBJECT - SINGLETON_DEPENDENCY + SINGLETON_DEPENDENCY(DdeFaceTracker) public: //initialization diff --git a/interface/src/devices/Faceshift.h b/interface/src/devices/Faceshift.h index 73971db49d..b6b942dfee 100644 --- a/interface/src/devices/Faceshift.h +++ b/interface/src/devices/Faceshift.h @@ -26,7 +26,7 @@ /// Handles interaction with the Faceshift software, which provides head position/orientation and facial features. class Faceshift : public FaceTracker { Q_OBJECT - SINGLETON_DEPENDENCY + SINGLETON_DEPENDENCY(Faceshift) public: void init(); diff --git a/interface/src/devices/Visage.h b/interface/src/devices/Visage.h index 38e337aada..c12ce3aabd 100644 --- a/interface/src/devices/Visage.h +++ b/interface/src/devices/Visage.h @@ -28,7 +28,7 @@ namespace VisageSDK { /// Handles input from the Visage webcam feature tracking software. class Visage : public FaceTracker { Q_OBJECT - SINGLETON_DEPENDENCY + SINGLETON_DEPENDENCY(Visage) public: void init(); From 4d1529f77bc875a87c10b2006e449425a98bbdb7 Mon Sep 17 00:00:00 2001 From: Atlante45 Date: Tue, 16 Dec 2014 14:02:22 -0800 Subject: [PATCH 06/11] typedefs --- interface/src/Application.cpp | 26 +++++++++---------- interface/src/Camera.cpp | 2 +- interface/src/Menu.cpp | 2 +- interface/src/avatar/Head.cpp | 4 +-- interface/src/avatar/MyAvatar.cpp | 2 +- interface/src/devices/OculusManager.cpp | 4 +-- interface/src/devices/PrioVR.cpp | 2 +- interface/src/devices/SixenseManager.cpp | 2 +- interface/src/devices/TV3DManager.cpp | 4 +-- interface/src/renderer/GlowEffect.cpp | 2 +- .../ControllerScriptingInterface.cpp | 2 +- interface/src/ui/ApplicationOverlay.cpp | 20 +++++++------- interface/src/ui/PreferencesDialog.cpp | 2 +- interface/src/ui/Snapshot.cpp | 2 +- interface/src/ui/Stats.cpp | 8 +++--- 15 files changed, 42 insertions(+), 42 deletions(-) diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index 50275fcd1c..5746f1f670 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -1047,7 +1047,7 @@ void Application::keyPressEvent(QKeyEvent* event) { if (isShifted) { _viewFrustum.setFocalLength(_viewFrustum.getFocalLength() - 0.1f); if (TV3DManager::isConnected()) { - QSharedPointer glCanvas = DependencyManager::get(); + GLCanvas::SharedPointer glCanvas = DependencyManager::get(); TV3DManager::configureCamera(_myCamera, glCanvas->getDeviceWidth(), glCanvas->getDeviceHeight()); } } else { @@ -1060,7 +1060,7 @@ void Application::keyPressEvent(QKeyEvent* event) { if (isShifted) { _viewFrustum.setFocalLength(_viewFrustum.getFocalLength() + 0.1f); if (TV3DManager::isConnected()) { - QSharedPointer glCanvas = DependencyManager::get(); + GLCanvas::SharedPointer glCanvas = DependencyManager::get(); TV3DManager::configureCamera(_myCamera, glCanvas->getDeviceWidth(), glCanvas->getDeviceHeight()); } @@ -1533,7 +1533,7 @@ void Application::idle() { void Application::checkBandwidthMeterClick() { // ... to be called upon button release - QSharedPointer glCanvas = DependencyManager::get(); + GLCanvas::SharedPointer glCanvas = DependencyManager::get(); if (Menu::getInstance()->isOptionChecked(MenuOption::Bandwidth) && Menu::getInstance()->isOptionChecked(MenuOption::Stats) && Menu::getInstance()->isOptionChecked(MenuOption::UserInterface) && @@ -1569,7 +1569,7 @@ void Application::setFullscreen(bool fullscreen) { } void Application::setEnable3DTVMode(bool enable3DTVMode) { - QSharedPointer glCanvas = DependencyManager::get(); + GLCanvas::SharedPointer glCanvas = DependencyManager::get(); resizeGL(glCanvas->getDeviceWidth(), glCanvas->getDeviceHeight()); } @@ -1595,7 +1595,7 @@ void Application::setEnableVRMode(bool enableVRMode) { _myCamera.setHmdRotation(glm::quat()); } - QSharedPointer glCanvas = DependencyManager::get(); + GLCanvas::SharedPointer glCanvas = DependencyManager::get(); resizeGL(glCanvas->getDeviceWidth(), glCanvas->getDeviceHeight()); } @@ -1658,7 +1658,7 @@ glm::vec3 Application::getMouseVoxelWorldCoordinates(const VoxelDetail& mouseVox bool Application::mouseOnScreen() const { if (OculusManager::isConnected()) { - QSharedPointer glCanvas = DependencyManager::get(); + GLCanvas::SharedPointer glCanvas = DependencyManager::get(); return getMouseX() >= 0 && getMouseX() <= glCanvas->getDeviceWidth() && getMouseY() >= 0 && getMouseY() <= glCanvas->getDeviceHeight(); } @@ -1700,9 +1700,9 @@ int Application::getMouseDragStartedY() const { } FaceTracker* Application::getActiveFaceTracker() { - QSharedPointer faceshift = DependencyManager::get(); - QSharedPointer visage = DependencyManager::get(); - QSharedPointer dde = DependencyManager::get(); + Faceshift::SharedPointer faceshift = DependencyManager::get(); + Visage::SharedPointer visage = DependencyManager::get(); + DdeFaceTracker::SharedPointer dde = DependencyManager::get(); return (dde->isActive() ? static_cast(dde.data()) : (faceshift->isActive() ? static_cast(faceshift.data()) : @@ -2035,7 +2035,7 @@ void Application::init() { _metavoxels.init(); - QSharedPointer glCanvas = DependencyManager::get(); + GLCanvas::SharedPointer glCanvas = DependencyManager::get(); _audio.init(glCanvas.data()); _rearMirrorTools = new RearMirrorTools(glCanvas.data(), _mirrorViewRect, _settings); @@ -2116,7 +2116,7 @@ void Application::updateMouseRay() { void Application::updateFaceshift() { bool showWarnings = Menu::getInstance()->isOptionChecked(MenuOption::PipelineWarnings); PerformanceWarning warn(showWarnings, "Application::updateFaceshift()"); - Faceshift* faceshift = DependencyManager::get().data(); + Faceshift::SharedPointer faceshift = DependencyManager::get(); // Update faceshift faceshift->update(); @@ -2920,7 +2920,7 @@ void Application::updateShadowMap() { fbo->release(); - QSharedPointer glCanvas = DependencyManager::get(); + GLCanvas::SharedPointer glCanvas = DependencyManager::get(); glViewport(0, 0, glCanvas->getDeviceWidth(), glCanvas->getDeviceHeight()); } @@ -3248,7 +3248,7 @@ void Application::computeOffAxisFrustum(float& left, float& right, float& bottom } glm::vec2 Application::getScaledScreenPoint(glm::vec2 projectedPoint) { - QSharedPointer glCanvas = DependencyManager::get(); + GLCanvas::SharedPointer glCanvas = DependencyManager::get(); float horizontalScale = glCanvas->getDeviceWidth() / 2.0f; float verticalScale = glCanvas->getDeviceHeight() / 2.0f; diff --git a/interface/src/Camera.cpp b/interface/src/Camera.cpp index 181f783af1..b2fd30a1a6 100644 --- a/interface/src/Camera.cpp +++ b/interface/src/Camera.cpp @@ -95,7 +95,7 @@ void Camera::setFarClip(float f) { } PickRay Camera::computePickRay(float x, float y) { - QSharedPointer glCanvas = DependencyManager::get(); + GLCanvas::SharedPointer glCanvas = DependencyManager::get(); return computeViewPickRay(x / glCanvas->width(), y / glCanvas->height()); } diff --git a/interface/src/Menu.cpp b/interface/src/Menu.cpp index 501da725e4..91f4460410 100644 --- a/interface/src/Menu.cpp +++ b/interface/src/Menu.cpp @@ -1050,7 +1050,7 @@ void Menu::bumpSettings() { void sendFakeEnterEvent() { QPoint lastCursorPosition = QCursor::pos(); - QSharedPointer glCanvas = DependencyManager::get(); + GLCanvas::SharedPointer glCanvas = DependencyManager::get(); QPoint windowPosition = glCanvas->mapFromGlobal(lastCursorPosition); QEnterEvent enterEvent = QEnterEvent(windowPosition, windowPosition, lastCursorPosition); diff --git a/interface/src/avatar/Head.cpp b/interface/src/avatar/Head.cpp index 150b67eb13..9a228899c5 100644 --- a/interface/src/avatar/Head.cpp +++ b/interface/src/avatar/Head.cpp @@ -77,8 +77,8 @@ 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(); - QSharedPointer dde = DependencyManager::get(); - QSharedPointer faceshift = DependencyManager::get(); + DdeFaceTracker::SharedPointer dde = DependencyManager::get(); + Faceshift::SharedPointer faceshift = DependencyManager::get(); if ((_isFaceshiftConnected = (faceshift == faceTracker))) { _blendshapeCoefficients = faceTracker->getBlendshapeCoefficients(); diff --git a/interface/src/avatar/MyAvatar.cpp b/interface/src/avatar/MyAvatar.cpp index a546560ffd..8e40cb8b30 100644 --- a/interface/src/avatar/MyAvatar.cpp +++ b/interface/src/avatar/MyAvatar.cpp @@ -422,7 +422,7 @@ void MyAvatar::render(const glm::vec3& cameraPosition, RenderMode renderMode, bo } void MyAvatar::renderHeadMouse(int screenWidth, int screenHeight) const { - QSharedPointer faceshift = DependencyManager::get(); + Faceshift::SharedPointer faceshift = DependencyManager::get(); float pixelsPerDegree = screenHeight / Menu::getInstance()->getFieldOfView(); diff --git a/interface/src/devices/OculusManager.cpp b/interface/src/devices/OculusManager.cpp index 99515cb7a9..15aa129b93 100644 --- a/interface/src/devices/OculusManager.cpp +++ b/interface/src/devices/OculusManager.cpp @@ -560,7 +560,7 @@ void OculusManager::display(const glm::quat &bodyOrientation, const glm::vec3 &p } // restore our normal viewport - QSharedPointer glCanvas = DependencyManager::get(); + GLCanvas::SharedPointer glCanvas = DependencyManager::get(); glViewport(0, 0, glCanvas->getDeviceWidth(), glCanvas->getDeviceHeight()); glMatrixMode(GL_PROJECTION); @@ -579,7 +579,7 @@ void OculusManager::display(const glm::quat &bodyOrientation, const glm::vec3 &p void OculusManager::renderDistortionMesh(ovrPosef eyeRenderPose[ovrEye_Count]) { glLoadIdentity(); - QSharedPointer glCanvas = DependencyManager::get(); + GLCanvas::SharedPointer glCanvas = DependencyManager::get(); gluOrtho2D(0, glCanvas->getDeviceWidth(), 0, glCanvas->getDeviceHeight()); glDisable(GL_DEPTH_TEST); diff --git a/interface/src/devices/PrioVR.cpp b/interface/src/devices/PrioVR.cpp index ab7c317c37..5ef94339ae 100644 --- a/interface/src/devices/PrioVR.cpp +++ b/interface/src/devices/PrioVR.cpp @@ -215,7 +215,7 @@ void PrioVR::renderCalibrationCountdown() { static TextRenderer* textRenderer = TextRenderer::getInstance(MONO_FONT_FAMILY, 18, QFont::Bold, false, TextRenderer::OUTLINE_EFFECT, 2); QByteArray text = "Assume T-Pose in " + QByteArray::number(secondsRemaining) + "..."; - QSharedPointer glCanvas = DependencyManager::get(); + GLCanvas::SharedPointer glCanvas = DependencyManager::get(); textRenderer->draw((glCanvas->width() - textRenderer->computeWidth(text.constData())) / 2, glCanvas->height() / 2, text); diff --git a/interface/src/devices/SixenseManager.cpp b/interface/src/devices/SixenseManager.cpp index 73e4f53289..e2b4fedd50 100644 --- a/interface/src/devices/SixenseManager.cpp +++ b/interface/src/devices/SixenseManager.cpp @@ -461,7 +461,7 @@ void SixenseManager::updateCalibration(const sixenseControllerData* controllers) void SixenseManager::emulateMouse(PalmData* palm, int index) { Application* application = Application::getInstance(); MyAvatar* avatar = application->getAvatar(); - QSharedPointer glCanvas = DependencyManager::get(); + GLCanvas::SharedPointer glCanvas = DependencyManager::get(); QPoint pos; Qt::MouseButton bumperButton; diff --git a/interface/src/devices/TV3DManager.cpp b/interface/src/devices/TV3DManager.cpp index 5c891224a8..e4723d26a0 100644 --- a/interface/src/devices/TV3DManager.cpp +++ b/interface/src/devices/TV3DManager.cpp @@ -33,7 +33,7 @@ bool TV3DManager::isConnected() { } void TV3DManager::connect() { - QSharedPointer glCanvas = DependencyManager::get(); + GLCanvas::SharedPointer glCanvas = DependencyManager::get(); int width = glCanvas->getDeviceWidth(); int height = glCanvas->getDeviceHeight(); Camera& camera = *Application::getInstance()->getCamera(); @@ -91,7 +91,7 @@ void TV3DManager::display(Camera& whichCamera) { // left eye portal int portalX = 0; int portalY = 0; - QSharedPointer glCanvas = DependencyManager::get(); + GLCanvas::SharedPointer glCanvas = DependencyManager::get(); QSize deviceSize = glCanvas->getDeviceSize() * Application::getInstance()->getRenderResolutionScale(); int portalW = deviceSize.width() / 2; diff --git a/interface/src/renderer/GlowEffect.cpp b/interface/src/renderer/GlowEffect.cpp index a760889eff..9f953eed60 100644 --- a/interface/src/renderer/GlowEffect.cpp +++ b/interface/src/renderer/GlowEffect.cpp @@ -139,7 +139,7 @@ QOpenGLFramebufferObject* GlowEffect::render(bool toTexture) { QOpenGLFramebufferObject* destFBO = toTexture ? Application::getInstance()->getTextureCache()->getSecondaryFramebufferObject() : NULL; - QSharedPointer glCanvas = DependencyManager::get(); + GLCanvas::SharedPointer glCanvas = DependencyManager::get(); if (!Menu::getInstance()->isOptionChecked(MenuOption::EnableGlowEffect) || _isEmpty) { // copy the primary to the screen if (destFBO && QOpenGLFramebufferObject::hasOpenGLFramebufferBlit()) { diff --git a/interface/src/scripting/ControllerScriptingInterface.cpp b/interface/src/scripting/ControllerScriptingInterface.cpp index a562236a92..545de00d7d 100644 --- a/interface/src/scripting/ControllerScriptingInterface.cpp +++ b/interface/src/scripting/ControllerScriptingInterface.cpp @@ -268,7 +268,7 @@ void ControllerScriptingInterface::releaseJoystick(int joystickIndex) { } glm::vec2 ControllerScriptingInterface::getViewportDimensions() const { - QSharedPointer glCanvas = DependencyManager::get(); + GLCanvas::SharedPointer glCanvas = DependencyManager::get(); return glm::vec2(glCanvas->width(), glCanvas->height()); } diff --git a/interface/src/ui/ApplicationOverlay.cpp b/interface/src/ui/ApplicationOverlay.cpp index c95dc08e79..f16777a28d 100644 --- a/interface/src/ui/ApplicationOverlay.cpp +++ b/interface/src/ui/ApplicationOverlay.cpp @@ -145,7 +145,7 @@ void ApplicationOverlay::renderOverlay(bool renderToTexture) { PerformanceWarning warn(Menu::getInstance()->isOptionChecked(MenuOption::PipelineWarnings), "ApplicationOverlay::displayOverlay()"); Application* application = Application::getInstance(); Overlays& overlays = application->getOverlays(); - QSharedPointer glCanvas = DependencyManager::get(); + GLCanvas::SharedPointer glCanvas = DependencyManager::get(); MyAvatar* myAvatar = application->getAvatar(); _textureFov = glm::radians(Menu::getInstance()->getOculusUIAngularSize()); @@ -213,7 +213,7 @@ void ApplicationOverlay::displayOverlayTexture() { if (_alpha == 0.0f) { return; } - QSharedPointer glCanvas = DependencyManager::get(); + GLCanvas::SharedPointer glCanvas = DependencyManager::get(); glEnable(GL_TEXTURE_2D); glActiveTexture(GL_TEXTURE0); @@ -378,7 +378,7 @@ void ApplicationOverlay::displayOverlayTexture3DTV(Camera& whichCamera, float as glEnd(); - QSharedPointer glCanvas = DependencyManager::get(); + GLCanvas::SharedPointer glCanvas = DependencyManager::get(); if (_crosshairTexture == 0) { _crosshairTexture = glCanvas->bindTexture(QImage(Application::resourcesPath() + "images/sixense-reticle.png")); } @@ -432,7 +432,7 @@ void ApplicationOverlay::computeOculusPickRay(float x, float y, glm::vec3& origi //Caculate the click location using one of the sixense controllers. Scale is not applied QPoint ApplicationOverlay::getPalmClickLocation(const PalmData *palm) const { Application* application = Application::getInstance(); - QSharedPointer glCanvas = DependencyManager::get(); + GLCanvas::SharedPointer glCanvas = DependencyManager::get(); MyAvatar* myAvatar = application->getAvatar(); glm::vec3 tip = myAvatar->getLaserPointerTipPosition(palm); @@ -511,7 +511,7 @@ bool ApplicationOverlay::calculateRayUICollisionPoint(const glm::vec3& position, //Renders optional pointers void ApplicationOverlay::renderPointers() { Application* application = Application::getInstance(); - QSharedPointer glCanvas = DependencyManager::get(); + GLCanvas::SharedPointer glCanvas = DependencyManager::get(); //lazily load crosshair texture if (_crosshairTexture == 0) { @@ -559,7 +559,7 @@ void ApplicationOverlay::renderPointers() { void ApplicationOverlay::renderControllerPointers() { Application* application = Application::getInstance(); - QSharedPointer glCanvas = DependencyManager::get(); + GLCanvas::SharedPointer glCanvas = DependencyManager::get(); MyAvatar* myAvatar = application->getAvatar(); //Static variables used for storing controller state @@ -704,7 +704,7 @@ void ApplicationOverlay::renderPointersOculus(const glm::vec3& eyePos) { //Renders a small magnification of the currently bound texture at the coordinates void ApplicationOverlay::renderMagnifier(glm::vec2 magPos, float sizeMult, bool showBorder) const { - QSharedPointer glCanvas = DependencyManager::get(); + GLCanvas::SharedPointer glCanvas = DependencyManager::get(); const int widgetWidth = glCanvas->width(); const int widgetHeight = glCanvas->height(); @@ -762,7 +762,7 @@ void ApplicationOverlay::renderAudioMeter() { Application* application = Application::getInstance(); - QSharedPointer glCanvas = DependencyManager::get(); + GLCanvas::SharedPointer glCanvas = DependencyManager::get(); Audio* audio = application->getAudio(); // Display a single screen-size quad to create an alpha blended 'collision' flash @@ -893,7 +893,7 @@ void ApplicationOverlay::renderStatsAndLogs() { Application* application = Application::getInstance(); - QSharedPointer glCanvas = DependencyManager::get(); + GLCanvas::SharedPointer glCanvas = DependencyManager::get(); const OctreePacketProcessor& octreePacketProcessor = application->getOctreePacketProcessor(); BandwidthMeter* bandwidthMeter = application->getBandwidthMeter(); NodeBounds& nodeBoundsDisplay = application->getNodeBoundsDisplay(); @@ -935,7 +935,7 @@ void ApplicationOverlay::renderDomainConnectionStatusBorder() { NodeList* nodeList = NodeList::getInstance(); if (nodeList && !nodeList->getDomainHandler().isConnected()) { - QSharedPointer glCanvas = DependencyManager::get(); + GLCanvas::SharedPointer glCanvas = DependencyManager::get(); int right = glCanvas->width(); int bottom = glCanvas->height(); diff --git a/interface/src/ui/PreferencesDialog.cpp b/interface/src/ui/PreferencesDialog.cpp index d39266e0fd..7baacd3d5a 100644 --- a/interface/src/ui/PreferencesDialog.cpp +++ b/interface/src/ui/PreferencesDialog.cpp @@ -215,7 +215,7 @@ void PreferencesDialog::savePreferences() { myAvatar->setClampedTargetScale(ui.avatarScaleSpin->value()); Application::getInstance()->getVoxels()->setMaxVoxels(ui.maxVoxelsSpin->value()); - QSharedPointer glCanvas = DependencyManager::get(); + GLCanvas::SharedPointer glCanvas = DependencyManager::get(); Application::getInstance()->resizeGL(glCanvas->width(), glCanvas->height()); Menu::getInstance()->setRealWorldFieldOfView(ui.realWorldFieldOfViewSpin->value()); diff --git a/interface/src/ui/Snapshot.cpp b/interface/src/ui/Snapshot.cpp index ddd2b93805..e3b512adcc 100644 --- a/interface/src/ui/Snapshot.cpp +++ b/interface/src/ui/Snapshot.cpp @@ -83,7 +83,7 @@ QTemporaryFile* Snapshot::saveTempSnapshot() { } QFile* Snapshot::savedFileForSnapshot(bool isTemporary) { - QSharedPointer glCanvas = DependencyManager::get(); + GLCanvas::SharedPointer glCanvas = DependencyManager::get(); QImage shot = glCanvas->grabFrameBuffer(); Avatar* avatar = Application::getInstance()->getAvatar(); diff --git a/interface/src/ui/Stats.cpp b/interface/src/ui/Stats.cpp index 2581866c70..be1fd88445 100644 --- a/interface/src/ui/Stats.cpp +++ b/interface/src/ui/Stats.cpp @@ -56,7 +56,7 @@ Stats::Stats(): _metavoxelReceiveProgress(0), _metavoxelReceiveTotal(0) { - QSharedPointer glCanvas = DependencyManager::get(); + GLCanvas::SharedPointer glCanvas = DependencyManager::get(); resetWidth(glCanvas->width(), 0); } @@ -67,7 +67,7 @@ void Stats::toggleExpanded() { // called on mouse click release // check for clicks over stats in order to expand or contract them void Stats::checkClick(int mouseX, int mouseY, int mouseDragStartedX, int mouseDragStartedY, int horizontalOffset) { - QSharedPointer glCanvas = DependencyManager::get(); + GLCanvas::SharedPointer glCanvas = DependencyManager::get(); if (0 != glm::compMax(glm::abs(glm::ivec2(mouseX - mouseDragStartedX, mouseY - mouseDragStartedY)))) { // not worried about dragging on stats @@ -122,7 +122,7 @@ void Stats::checkClick(int mouseX, int mouseY, int mouseDragStartedX, int mouseD } void Stats::resetWidth(int width, int horizontalOffset) { - QSharedPointer glCanvas = DependencyManager::get(); + GLCanvas::SharedPointer glCanvas = DependencyManager::get(); int extraSpace = glCanvas->width() - horizontalOffset -2 - STATS_GENERAL_MIN_WIDTH - (Menu::getInstance()->isOptionChecked(MenuOption::TestPing) ? STATS_PING_MIN_WIDTH -1 : 0) @@ -198,7 +198,7 @@ void Stats::display( int bytesPerSecond, int voxelPacketsToProcess) { - QSharedPointer glCanvas = DependencyManager::get(); + GLCanvas::SharedPointer glCanvas = DependencyManager::get(); unsigned int backgroundColor = 0x33333399; int verticalOffset = 0, lines = 0; From b2dac6f53fdb8c90f2197589cb5f083ccd5713df Mon Sep 17 00:00:00 2001 From: Atlante45 Date: Tue, 16 Dec 2014 15:32:11 -0800 Subject: [PATCH 07/11] DM users update --- interface/src/Application.cpp | 4 ++-- interface/src/Menu.cpp | 2 +- libraries/animation/src/AnimationCache.h | 4 ++-- libraries/render-utils/src/AmbientOcclusionEffect.h | 5 +++-- libraries/render-utils/src/DeferredLightingEffect.h | 5 +++-- libraries/render-utils/src/GlowEffect.cpp | 9 ++++----- libraries/render-utils/src/GlowEffect.h | 4 ++-- libraries/script-engine/src/ScriptEngine.cpp | 2 +- libraries/shared/src/DependencyManager.h | 2 +- 9 files changed, 19 insertions(+), 18 deletions(-) diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index f677c46269..e7455ef71e 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -2051,7 +2051,7 @@ void Application::init() { DependencyManager::get()->associateWithWidget(glCanvas.data()); // initialize the GlowEffect with our widget - DependencyManager::get()->init(glCanvas, + DependencyManager::get()->init(glCanvas.data(), Menu::getInstance()->isOptionChecked(MenuOption::EnableGlowEffect)); } @@ -4032,7 +4032,7 @@ void Application::registerScriptEngineWithApplicationServices(ScriptEngine* scri scriptEngine->registerGlobalObject("Menu", MenuScriptingInterface::getInstance()); scriptEngine->registerGlobalObject("Settings", SettingsScriptingInterface::getInstance()); scriptEngine->registerGlobalObject("AudioDevice", AudioDeviceScriptingInterface::getInstance()); - scriptEngine->registerGlobalObject("AnimationCache", DependencyManager::get()); + scriptEngine->registerGlobalObject("AnimationCache", DependencyManager::get().data()); scriptEngine->registerGlobalObject("SoundCache", &SoundCache::getInstance()); scriptEngine->registerGlobalObject("Account", AccountScriptingInterface::getInstance()); scriptEngine->registerGlobalObject("Metavoxels", &_metavoxels); diff --git a/interface/src/Menu.cpp b/interface/src/Menu.cpp index 0521615257..f0c2a687a4 100644 --- a/interface/src/Menu.cpp +++ b/interface/src/Menu.cpp @@ -427,7 +427,7 @@ Menu::Menu() : appInstance, SLOT(setRenderVoxels(bool))); addCheckableActionToQMenuAndActionHash(renderOptionsMenu, MenuOption::EnableGlowEffect, 0, true, - DependencyManager::get(), SLOT(toggleGlowEffect(bool))); + DependencyManager::get().data(), SLOT(toggleGlowEffect(bool))); addCheckableActionToQMenuAndActionHash(renderOptionsMenu, MenuOption::Wireframe, Qt::ALT | Qt::Key_W, false); addActionToQMenuAndActionHash(renderOptionsMenu, MenuOption::LodTools, Qt::SHIFT | Qt::Key_L, this, SLOT(lodTools())); diff --git a/libraries/animation/src/AnimationCache.h b/libraries/animation/src/AnimationCache.h index 5f3f305461..4e67014822 100644 --- a/libraries/animation/src/AnimationCache.h +++ b/libraries/animation/src/AnimationCache.h @@ -24,8 +24,9 @@ class Animation; typedef QSharedPointer AnimationPointer; /// Scriptable interface for FBX animation loading. -class AnimationCache : public ResourceCache, public DependencyManager::Dependency { +class AnimationCache : public ResourceCache { Q_OBJECT + SINGLETON_DEPENDENCY(AnimationCache) public: Q_INVOKABLE AnimationPointer getAnimation(const QString& url) { return getAnimation(QUrl(url)); } @@ -38,7 +39,6 @@ protected: private: AnimationCache(QObject* parent = NULL); virtual ~AnimationCache() { } - friend class DependencyManager; }; diff --git a/libraries/render-utils/src/AmbientOcclusionEffect.h b/libraries/render-utils/src/AmbientOcclusionEffect.h index 1ee7269480..421461860d 100644 --- a/libraries/render-utils/src/AmbientOcclusionEffect.h +++ b/libraries/render-utils/src/AmbientOcclusionEffect.h @@ -20,7 +20,9 @@ class ProgramObject; /// A screen space ambient occlusion effect. See John Chapman's tutorial at /// http://john-chapman-graphics.blogspot.co.uk/2013/01/ssao-tutorial.html for reference. -class AmbientOcclusionEffect: public DependencyManager::Dependency { +class AmbientOcclusionEffect { + SINGLETON_DEPENDENCY(AmbientOcclusionEffect) + public: void init(ViewStateInterface* viewState); @@ -29,7 +31,6 @@ public: private: AmbientOcclusionEffect() {} virtual ~AmbientOcclusionEffect() {} - friend class DependencyManager; ProgramObject* _occlusionProgram; int _nearLocation; diff --git a/libraries/render-utils/src/DeferredLightingEffect.h b/libraries/render-utils/src/DeferredLightingEffect.h index 5dcd7d35f4..904f9827ea 100644 --- a/libraries/render-utils/src/DeferredLightingEffect.h +++ b/libraries/render-utils/src/DeferredLightingEffect.h @@ -23,7 +23,9 @@ class PostLightingRenderable; /// Handles deferred lighting for the bits that require it (voxels, metavoxels...) -class DeferredLightingEffect: public DependencyManager::Dependency { +class DeferredLightingEffect { + SINGLETON_DEPENDENCY(DeferredLightingEffect) + public: void init(ViewStateInterface* viewState); @@ -73,7 +75,6 @@ public: private: DeferredLightingEffect() { } virtual ~DeferredLightingEffect() { } - friend class DependencyManager; class LightLocations { public: diff --git a/libraries/render-utils/src/GlowEffect.cpp b/libraries/render-utils/src/GlowEffect.cpp index 62e3a9d691..fb7189f61e 100644 --- a/libraries/render-utils/src/GlowEffect.cpp +++ b/libraries/render-utils/src/GlowEffect.cpp @@ -12,7 +12,6 @@ // include this before QOpenGLFramebufferObject, which includes an earlier version of OpenGL #include -#include #include #include @@ -157,7 +156,6 @@ QOpenGLFramebufferObject* GlowEffect::render(bool toTexture) { QOpenGLFramebufferObject* destFBO = toTexture ? textureCache->getSecondaryFramebufferObject() : NULL; - GLCanvas::SharedPointer glCanvas = DependencyManager::get(); if (!_enabled || _isEmpty) { // copy the primary to the screen if (destFBO && QOpenGLFramebufferObject::hasOpenGLFramebufferBlit()) { @@ -165,7 +163,7 @@ QOpenGLFramebufferObject* GlowEffect::render(bool toTexture) { } else { maybeBind(destFBO); if (!destFBO) { - glViewport(0, 0, glCanvas->getDeviceWidth(), glCanvas->getDeviceHeight()); + glViewport(0, 0, getDeviceWidth(), getDeviceHeight()); } glEnable(GL_TEXTURE_2D); glDisable(GL_LIGHTING); @@ -212,8 +210,9 @@ QOpenGLFramebufferObject* GlowEffect::render(bool toTexture) { } maybeBind(destFBO); if (!destFBO) { - glViewport(0, 0, glCanvas->getDeviceWidth(), glCanvas->getDeviceHeight()); - _addSeparateProgram->bind(); + glViewport(0, 0, getDeviceWidth(), getDeviceHeight()); + } + _addSeparateProgram->bind(); renderFullscreenQuad(); _addSeparateProgram->release(); maybeRelease(destFBO); diff --git a/libraries/render-utils/src/GlowEffect.h b/libraries/render-utils/src/GlowEffect.h index cc3e6e5867..37f29afb62 100644 --- a/libraries/render-utils/src/GlowEffect.h +++ b/libraries/render-utils/src/GlowEffect.h @@ -25,8 +25,9 @@ class QOpenGLFramebufferObject; class ProgramObject; /// A generic full screen glow effect. -class GlowEffect : public QObject, public DependencyManager::Dependency { +class GlowEffect : public QObject { Q_OBJECT + SINGLETON_DEPENDENCY(GlowEffect) public: @@ -60,7 +61,6 @@ public slots: private: GlowEffect(); virtual ~GlowEffect(); - friend class DependencyManager; int getDeviceWidth() const; int getDeviceHeight() const; diff --git a/libraries/script-engine/src/ScriptEngine.cpp b/libraries/script-engine/src/ScriptEngine.cpp index ec5f2bc0e7..6117da9d18 100644 --- a/libraries/script-engine/src/ScriptEngine.cpp +++ b/libraries/script-engine/src/ScriptEngine.cpp @@ -255,7 +255,7 @@ void ScriptEngine::init() { registerGlobalObject("Quat", &_quatLibrary); registerGlobalObject("Vec3", &_vec3Library); registerGlobalObject("Uuid", &_uuidLibrary); - registerGlobalObject("AnimationCache", DependencyManager::get()); + registerGlobalObject("AnimationCache", DependencyManager::get().data()); registerGlobalObject("Voxels", &_voxelsScriptingInterface); diff --git a/libraries/shared/src/DependencyManager.h b/libraries/shared/src/DependencyManager.h index 455ec38bca..d1a1896947 100644 --- a/libraries/shared/src/DependencyManager.h +++ b/libraries/shared/src/DependencyManager.h @@ -46,7 +46,7 @@ QSharedPointer DependencyManager::get() { static T* instance = new T(); if (instance) { - if (dynamic_cast(instance)) { // If this is a QOject, call deleteLater for destruction + if (dynamic_cast(instance) != NULL) { // If this is a QOject, call deleteLater for destruction sharedPointer = QSharedPointer(instance, &T::deleteLater); } else { // Otherwise use custom deleter to avoid issues between private destructor and QSharedPointer sharedPointer = QSharedPointer(instance, &T::customDeleter); From 3f2b5aeca408f5fef82be452dd13c1182eed840e Mon Sep 17 00:00:00 2001 From: Atlante45 Date: Tue, 16 Dec 2014 16:22:59 -0800 Subject: [PATCH 08/11] Cleaner destruction handling --- libraries/shared/src/DependencyManager.h | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/libraries/shared/src/DependencyManager.h b/libraries/shared/src/DependencyManager.h index d1a1896947..06a01058fd 100644 --- a/libraries/shared/src/DependencyManager.h +++ b/libraries/shared/src/DependencyManager.h @@ -20,7 +20,14 @@ public:\ typedef QSharedPointer SharedPointer;\ private:\ - void customDeleter() { delete this; }\ + void customDeleter() {\ + QObject* thisObject = dynamic_cast(this);\ + if (thisObject) {\ + thisObject->deleteLater();\ + } else {\ + delete this;\ + }\ + }\ friend class DependencyManager; class QObject; @@ -42,17 +49,7 @@ private: template QSharedPointer DependencyManager::get() { - static QSharedPointer sharedPointer; - static T* instance = new T(); - - if (instance) { - if (dynamic_cast(instance) != NULL) { // If this is a QOject, call deleteLater for destruction - sharedPointer = QSharedPointer(instance, &T::deleteLater); - } else { // Otherwise use custom deleter to avoid issues between private destructor and QSharedPointer - sharedPointer = QSharedPointer(instance, &T::customDeleter); - } - instance = NULL; - } + static QSharedPointer sharedPointer = QSharedPointer(new T(), &T::customDeleter); return sharedPointer; } From 6304a5e819e1cb06423f85b62e3ea3fa56d83f86 Mon Sep 17 00:00:00 2001 From: Atlante45 Date: Tue, 16 Dec 2014 16:50:15 -0800 Subject: [PATCH 09/11] Unused removed method --- libraries/shared/src/DependencyManager.h | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/libraries/shared/src/DependencyManager.h b/libraries/shared/src/DependencyManager.h index 06a01058fd..fdf8030199 100644 --- a/libraries/shared/src/DependencyManager.h +++ b/libraries/shared/src/DependencyManager.h @@ -42,9 +42,7 @@ public: private: static DependencyManager& getInstance(); DependencyManager() {} - ~DependencyManager(); - - static void noDelete(void*) {} + ~DependencyManager(); }; template From 77bc00e4105f0aae31d64abb817516d8375e0a94 Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Tue, 16 Dec 2014 18:34:39 -0800 Subject: [PATCH 10/11] a simple model for persistent scripts in domain-server --- .../resources/describe-settings.json | 27 +++++++++ domain-server/resources/web/js/settings.js | 8 ++- domain-server/src/DomainServer.cpp | 59 ++++++++++--------- domain-server/src/DomainServer.h | 2 +- 4 files changed, 64 insertions(+), 32 deletions(-) diff --git a/domain-server/resources/describe-settings.json b/domain-server/resources/describe-settings.json index 50de26c518..ae6f116537 100644 --- a/domain-server/resources/describe-settings.json +++ b/domain-server/resources/describe-settings.json @@ -76,6 +76,33 @@ } ] }, + { + "name": "scripts", + "label": "Scripts", + "settings": [ + { + "name": "persistent_scripts", + "type": "table", + "label": "Persistent Scripts", + "help": "Add the URLs for scripts that you would like to ensure are always running in your domain.", + "columns": [ + { + "name": "url", + "label": "Script URL" + }, + { + "name": "num_instances", + "label": "# instances", + "default": 1 + }, + { + "name": "pool", + "label": "Pool" + } + ] + } + ] + }, { "name": "audio_env", "label": "Audio Environment", diff --git a/domain-server/resources/web/js/settings.js b/domain-server/resources/web/js/settings.js index a27965abce..141bd72a26 100644 --- a/domain-server/resources/web/js/settings.js +++ b/domain-server/resources/web/js/settings.js @@ -363,7 +363,8 @@ function makeTableInputs(setting) { _.each(setting.columns, function(col) { html += "\ - \ + \ " }) @@ -389,8 +390,9 @@ function badgeSidebarForDifferences(changedElement) { // badge for any settings we have that are not the same or are not present in initialValues for (var setting in panelJSON) { - if (!_.isEqual(panelJSON[setting], initialPanelJSON[setting]) - && (panelJSON[setting] !== "" || _.has(initialPanelJSON, setting))) { + if ((!_.has(initialPanelJSON, setting) && panelJSON[setting] !== "") || + (!_.isEqual(panelJSON[setting], initialPanelJSON[setting]) + && (panelJSON[setting] !== "" || _.has(initialPanelJSON, setting)))) { badgeValue += 1 } } diff --git a/domain-server/src/DomainServer.cpp b/domain-server/src/DomainServer.cpp index bf9505671b..470b69be01 100644 --- a/domain-server/src/DomainServer.cpp +++ b/domain-server/src/DomainServer.cpp @@ -233,6 +233,9 @@ void DomainServer::setupNodeListAndAssignments(const QUuid& sessionUUID) { parseAssignmentConfigs(parsedTypes); populateDefaultStaticAssignmentsExcludingTypes(parsedTypes); + + // check for scripts the user wants to persist from their domain-server config + populateStaticScriptedAssignmentsFromSettings(); LimitedNodeList* nodeList = LimitedNodeList::createInstance(domainServerPort, domainServerDTLSPort); @@ -451,8 +454,6 @@ void DomainServer::parseAssignmentConfigs(QSet& excludedTypes) if (assignmentType != Assignment::AgentType) { createStaticAssignmentsForType(assignmentType, assignmentList); - } else { - createScriptedAssignmentsFromList(assignmentList); } excludedTypes.insert(assignmentType); @@ -468,35 +469,37 @@ void DomainServer::addStaticAssignmentToAssignmentHash(Assignment* newAssignment _allAssignments.insert(newAssignment->getUUID(), SharedAssignmentPointer(newAssignment)); } -void DomainServer::createScriptedAssignmentsFromList(const QVariantList &configList) { - foreach(const QVariant& configVariant, configList) { - if (configVariant.canConvert(QMetaType::QVariantMap)) { - QVariantMap configMap = configVariant.toMap(); - - // make sure we were passed a URL, otherwise this is an invalid scripted assignment - const QString ASSIGNMENT_URL_KEY = "url"; - QString assignmentURL = configMap[ASSIGNMENT_URL_KEY].toString(); - - if (!assignmentURL.isEmpty()) { - // check the json for a pool - const QString ASSIGNMENT_POOL_KEY = "pool"; - QString assignmentPool = configMap[ASSIGNMENT_POOL_KEY].toString(); - - // check for a number of instances, if not passed then default is 1 - const QString ASSIGNMENT_INSTANCES_KEY = "instances"; - int numInstances = configMap[ASSIGNMENT_INSTANCES_KEY].toInt(); - numInstances = (numInstances == 0 ? 1 : numInstances); - - qDebug() << "Adding a static scripted assignment from" << assignmentURL; - - for (int i = 0; i < numInstances; i++) { +void DomainServer::populateStaticScriptedAssignmentsFromSettings() { + const QString PERSISTENT_SCRIPTS_KEY_PATH = "scripts.persistent_scripts"; + const QVariant* persistentScriptsVariant = valueForKeyPath(_settingsManager.getSettingsMap(), PERSISTENT_SCRIPTS_KEY_PATH); + + if (persistentScriptsVariant) { + QVariantList persistentScriptsList = persistentScriptsVariant->toList(); + foreach(const QVariant& persistentScriptVariant, persistentScriptsList) { + QVariantMap persistentScript = persistentScriptVariant.toMap(); + + const QString PERSISTENT_SCRIPT_URL_KEY = "url"; + const QString PERSISTENT_SCRIPT_NUM_INSTANCES_KEY = "num_instances"; + const QString PERSISTENT_SCRIPT_POOL_KEY = "pool"; + + if (persistentScript.contains(PERSISTENT_SCRIPT_URL_KEY)) { + // check how many instances of this script to add + + int numInstances = persistentScript[PERSISTENT_SCRIPT_NUM_INSTANCES_KEY].toInt(); + QString scriptURL = persistentScript[PERSISTENT_SCRIPT_URL_KEY].toString(); + + QString scriptPool = persistentScript.value(PERSISTENT_SCRIPT_POOL_KEY).toString(); + + qDebug() << "Adding" << numInstances << "of persistent script at URL" << scriptURL << "- pool" << scriptPool; + + for (int i = 0; i < numInstances; ++i) { // add a scripted assignment to the queue for this instance Assignment* scriptAssignment = new Assignment(Assignment::CreateCommand, Assignment::AgentType, - assignmentPool); - scriptAssignment->setPayload(assignmentURL.toUtf8()); - - // scripts passed on CL or via JSON are static - so they are added back to the queue if the node dies + scriptPool); + scriptAssignment->setPayload(scriptURL.toUtf8()); + + // add it to static hash so we know we have to keep giving it back out addStaticAssignmentToAssignmentHash(scriptAssignment); } } diff --git a/domain-server/src/DomainServer.h b/domain-server/src/DomainServer.h index 76ab562f74..f910534eb1 100644 --- a/domain-server/src/DomainServer.h +++ b/domain-server/src/DomainServer.h @@ -100,9 +100,9 @@ private: void parseAssignmentConfigs(QSet& excludedTypes); void addStaticAssignmentToAssignmentHash(Assignment* newAssignment); - void createScriptedAssignmentsFromList(const QVariantList& configList); void createStaticAssignmentsForType(Assignment::Type type, const QVariantList& configList); void populateDefaultStaticAssignmentsExcludingTypes(const QSet& excludedTypes); + void populateStaticScriptedAssignmentsFromSettings(); SharedAssignmentPointer matchingQueuedAssignmentForCheckIn(const QUuid& checkInUUID, NodeType_t nodeType); SharedAssignmentPointer deployableAssignmentForRequest(const Assignment& requestAssignment); From b95eac759e5550330d25474bd52237ab3e1f2b76 Mon Sep 17 00:00:00 2001 From: Ryan Huffman Date: Wed, 17 Dec 2014 08:52:48 -0800 Subject: [PATCH 11/11] Fix minor grid spacing not updating --- examples/libraries/gridTool.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/libraries/gridTool.js b/examples/libraries/gridTool.js index 622822e108..b1c258dc31 100644 --- a/examples/libraries/gridTool.js +++ b/examples/libraries/gridTool.js @@ -195,7 +195,7 @@ Grid = function(opts) { Overlays.editOverlay(gridOverlay, { position: { x: origin.y, y: origin.y, z: -origin.y }, visible: that.visible && that.enabled, - minorGridSpacing: minorGridSpacing, + minorGridWidth: minorGridSpacing, majorGridEvery: majorGridEvery, color: gridColor, alpha: gridAlpha,