From 0041d489ccda8916250f5f5187a3f7a770cddc92 Mon Sep 17 00:00:00 2001 From: Atlante45 Date: Fri, 16 Jan 2015 14:37:38 -0800 Subject: [PATCH 001/167] Move stuf around in Menu for easier cleanup --- interface/src/Menu.cpp | 464 +++++++++++++++++++++-------------------- interface/src/Menu.h | 139 ++++++------ 2 files changed, 308 insertions(+), 295 deletions(-) diff --git a/interface/src/Menu.cpp b/interface/src/Menu.cpp index c96ca9bb6f..686de54894 100644 --- a/interface/src/Menu.cpp +++ b/interface/src/Menu.cpp @@ -757,10 +757,6 @@ void Menu::scanMenu(QMenu* menu, settingsAction modifySetting, QSettings* set) { set->endGroup(); } -bool Menu::getShadowsEnabled() const { - return isOptionChecked(MenuOption::SimpleShadows) || isOptionChecked(MenuOption::CascadedShadows); -} - void Menu::addDisabledActionAndSeparator(QMenu* destinationMenu, const QString& actionName, int menuItemLocation) { QAction* actionBefore = NULL; if (menuItemLocation >= 0 && destinationMenu->actions().size() > menuItemLocation) { @@ -903,6 +899,236 @@ QAction* Menu::getActionForOption(const QString& menuOption) { return _actionHash.value(menuOption); } +QAction* Menu::getActionFromName(const QString& menuName, QMenu* menu) { + QList menuActions; + if (menu) { + menuActions = menu->actions(); + } else { + menuActions = actions(); + } + + foreach (QAction* menuAction, menuActions) { + if (menuName == menuAction->text()) { + return menuAction; + } + } + return NULL; +} + +QMenu* Menu::getSubMenuFromName(const QString& menuName, QMenu* menu) { + QAction* action = getActionFromName(menuName, menu); + if (action) { + return action->menu(); + } + return NULL; +} + +QMenu* Menu::getMenuParent(const QString& menuName, QString& finalMenuPart) { + QStringList menuTree = menuName.split(">"); + QMenu* parent = NULL; + QMenu* menu = NULL; + foreach (QString menuTreePart, menuTree) { + parent = menu; + finalMenuPart = menuTreePart.trimmed(); + menu = getSubMenuFromName(finalMenuPart, parent); + if (!menu) { + break; + } + } + return parent; +} + +QMenu* Menu::getMenu(const QString& menuName) { + QStringList menuTree = menuName.split(">"); + QMenu* parent = NULL; + QMenu* menu = NULL; + int item = 0; + foreach (QString menuTreePart, menuTree) { + menu = getSubMenuFromName(menuTreePart.trimmed(), parent); + if (!menu) { + break; + } + parent = menu; + item++; + } + return menu; +} + +QAction* Menu::getMenuAction(const QString& menuName) { + QStringList menuTree = menuName.split(">"); + QMenu* parent = NULL; + QAction* action = NULL; + foreach (QString menuTreePart, menuTree) { + action = getActionFromName(menuTreePart.trimmed(), parent); + if (!action) { + break; + } + parent = action->menu(); + } + return action; +} + +int Menu::findPositionOfMenuItem(QMenu* menu, const QString& searchMenuItem) { + int position = 0; + foreach(QAction* action, menu->actions()) { + if (action->text() == searchMenuItem) { + return position; + } + position++; + } + return UNSPECIFIED_POSITION; // not found +} + +int Menu::positionBeforeSeparatorIfNeeded(QMenu* menu, int requestedPosition) { + QList menuActions = menu->actions(); + if (requestedPosition > 1 && requestedPosition < menuActions.size()) { + QAction* beforeRequested = menuActions[requestedPosition - 1]; + if (beforeRequested->isSeparator()) { + requestedPosition--; + } + } + return requestedPosition; +} + + +QMenu* Menu::addMenu(const QString& menuName) { + QStringList menuTree = menuName.split(">"); + QMenu* addTo = NULL; + QMenu* menu = NULL; + foreach (QString menuTreePart, menuTree) { + menu = getSubMenuFromName(menuTreePart.trimmed(), addTo); + if (!menu) { + if (!addTo) { + menu = QMenuBar::addMenu(menuTreePart.trimmed()); + } else { + menu = addTo->addMenu(menuTreePart.trimmed()); + } + } + addTo = menu; + } + + QMenuBar::repaint(); + return menu; +} + +void Menu::removeMenu(const QString& menuName) { + QAction* action = getMenuAction(menuName); + + // only proceed if the menu actually exists + if (action) { + QString finalMenuPart; + QMenu* parent = getMenuParent(menuName, finalMenuPart); + if (parent) { + parent->removeAction(action); + } else { + QMenuBar::removeAction(action); + } + + QMenuBar::repaint(); + } +} + +bool Menu::menuExists(const QString& menuName) { + QAction* action = getMenuAction(menuName); + + // only proceed if the menu actually exists + if (action) { + return true; + } + return false; +} + +void Menu::addSeparator(const QString& menuName, const QString& separatorName) { + QMenu* menuObj = getMenu(menuName); + if (menuObj) { + addDisabledActionAndSeparator(menuObj, separatorName); + } +} + +void Menu::removeSeparator(const QString& menuName, const QString& separatorName) { + QMenu* menu = getMenu(menuName); + bool separatorRemoved = false; + if (menu) { + int textAt = findPositionOfMenuItem(menu, separatorName); + QList menuActions = menu->actions(); + QAction* separatorText = menuActions[textAt]; + if (textAt > 0 && textAt < menuActions.size()) { + QAction* separatorLine = menuActions[textAt - 1]; + if (separatorLine) { + if (separatorLine->isSeparator()) { + menu->removeAction(separatorText); + menu->removeAction(separatorLine); + separatorRemoved = true; + } + } + } + } + if (separatorRemoved) { + QMenuBar::repaint(); + } +} + +void Menu::addMenuItem(const MenuItemProperties& properties) { + QMenu* menuObj = getMenu(properties.menuName); + if (menuObj) { + QShortcut* shortcut = NULL; + if (!properties.shortcutKeySequence.isEmpty()) { + shortcut = new QShortcut(properties.shortcutKeySequence, this); + } + + // check for positioning requests + int requestedPosition = properties.position; + if (requestedPosition == UNSPECIFIED_POSITION && !properties.beforeItem.isEmpty()) { + requestedPosition = findPositionOfMenuItem(menuObj, properties.beforeItem); + // double check that the requested location wasn't a separator label + requestedPosition = positionBeforeSeparatorIfNeeded(menuObj, requestedPosition); + } + if (requestedPosition == UNSPECIFIED_POSITION && !properties.afterItem.isEmpty()) { + int afterPosition = findPositionOfMenuItem(menuObj, properties.afterItem); + if (afterPosition != UNSPECIFIED_POSITION) { + requestedPosition = afterPosition + 1; + } + } + + QAction* menuItemAction = NULL; + if (properties.isSeparator) { + addDisabledActionAndSeparator(menuObj, properties.menuItemName, requestedPosition); + } else if (properties.isCheckable) { + menuItemAction = addCheckableActionToQMenuAndActionHash(menuObj, properties.menuItemName, + properties.shortcutKeySequence, properties.isChecked, + MenuScriptingInterface::getInstance(), SLOT(menuItemTriggered()), requestedPosition); + } else { + menuItemAction = addActionToQMenuAndActionHash(menuObj, properties.menuItemName, properties.shortcutKeySequence, + MenuScriptingInterface::getInstance(), SLOT(menuItemTriggered()), + QAction::NoRole, requestedPosition); + } + if (shortcut && menuItemAction) { + connect(shortcut, SIGNAL(activated()), menuItemAction, SLOT(trigger())); + } + QMenuBar::repaint(); + } +} + +void Menu::removeMenuItem(const QString& menu, const QString& menuitem) { + QMenu* menuObj = getMenu(menu); + if (menuObj) { + removeAction(menuObj, menuitem); + QMenuBar::repaint(); + } +}; + +bool Menu::menuItemExists(const QString& menu, const QString& menuitem) { + QAction* menuItemAction = _actionHash.value(menuitem); + if (menuItemAction) { + return (getMenu(menu) != NULL); + } + return false; +}; + + +//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +/////////////////////////////////////////// TODO: Move to appropriate files //////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// void Menu::aboutApp() { InfoView::forcedShow(INFO_HELP_PATH); } @@ -911,6 +1137,10 @@ void Menu::showEditEntitiesHelp() { InfoView::forcedShow(INFO_EDIT_ENTITIES_PATH); } +bool Menu::getShadowsEnabled() const { + return isOptionChecked(MenuOption::SimpleShadows) || isOptionChecked(MenuOption::CascadedShadows); +} + void Menu::bumpSettings() { Application::getInstance()->bumpSettings(); } @@ -1511,232 +1741,6 @@ void Menu::runTests() { runTimingTests(); } -QAction* Menu::getActionFromName(const QString& menuName, QMenu* menu) { - QList menuActions; - if (menu) { - menuActions = menu->actions(); - } else { - menuActions = actions(); - } - - foreach (QAction* menuAction, menuActions) { - if (menuName == menuAction->text()) { - return menuAction; - } - } - return NULL; -} - -QMenu* Menu::getSubMenuFromName(const QString& menuName, QMenu* menu) { - QAction* action = getActionFromName(menuName, menu); - if (action) { - return action->menu(); - } - return NULL; -} - -QMenu* Menu::getMenuParent(const QString& menuName, QString& finalMenuPart) { - QStringList menuTree = menuName.split(">"); - QMenu* parent = NULL; - QMenu* menu = NULL; - foreach (QString menuTreePart, menuTree) { - parent = menu; - finalMenuPart = menuTreePart.trimmed(); - menu = getSubMenuFromName(finalMenuPart, parent); - if (!menu) { - break; - } - } - return parent; -} - -QMenu* Menu::getMenu(const QString& menuName) { - QStringList menuTree = menuName.split(">"); - QMenu* parent = NULL; - QMenu* menu = NULL; - int item = 0; - foreach (QString menuTreePart, menuTree) { - menu = getSubMenuFromName(menuTreePart.trimmed(), parent); - if (!menu) { - break; - } - parent = menu; - item++; - } - return menu; -} - -QAction* Menu::getMenuAction(const QString& menuName) { - QStringList menuTree = menuName.split(">"); - QMenu* parent = NULL; - QAction* action = NULL; - foreach (QString menuTreePart, menuTree) { - action = getActionFromName(menuTreePart.trimmed(), parent); - if (!action) { - break; - } - parent = action->menu(); - } - return action; -} - -int Menu::findPositionOfMenuItem(QMenu* menu, const QString& searchMenuItem) { - int position = 0; - foreach(QAction* action, menu->actions()) { - if (action->text() == searchMenuItem) { - return position; - } - position++; - } - return UNSPECIFIED_POSITION; // not found -} - -int Menu::positionBeforeSeparatorIfNeeded(QMenu* menu, int requestedPosition) { - QList menuActions = menu->actions(); - if (requestedPosition > 1 && requestedPosition < menuActions.size()) { - QAction* beforeRequested = menuActions[requestedPosition - 1]; - if (beforeRequested->isSeparator()) { - requestedPosition--; - } - } - return requestedPosition; -} - - -QMenu* Menu::addMenu(const QString& menuName) { - QStringList menuTree = menuName.split(">"); - QMenu* addTo = NULL; - QMenu* menu = NULL; - foreach (QString menuTreePart, menuTree) { - menu = getSubMenuFromName(menuTreePart.trimmed(), addTo); - if (!menu) { - if (!addTo) { - menu = QMenuBar::addMenu(menuTreePart.trimmed()); - } else { - menu = addTo->addMenu(menuTreePart.trimmed()); - } - } - addTo = menu; - } - - QMenuBar::repaint(); - return menu; -} - -void Menu::removeMenu(const QString& menuName) { - QAction* action = getMenuAction(menuName); - - // only proceed if the menu actually exists - if (action) { - QString finalMenuPart; - QMenu* parent = getMenuParent(menuName, finalMenuPart); - if (parent) { - parent->removeAction(action); - } else { - QMenuBar::removeAction(action); - } - - QMenuBar::repaint(); - } -} - -bool Menu::menuExists(const QString& menuName) { - QAction* action = getMenuAction(menuName); - - // only proceed if the menu actually exists - if (action) { - return true; - } - return false; -} - -void Menu::addSeparator(const QString& menuName, const QString& separatorName) { - QMenu* menuObj = getMenu(menuName); - if (menuObj) { - addDisabledActionAndSeparator(menuObj, separatorName); - } -} - -void Menu::removeSeparator(const QString& menuName, const QString& separatorName) { - QMenu* menu = getMenu(menuName); - bool separatorRemoved = false; - if (menu) { - int textAt = findPositionOfMenuItem(menu, separatorName); - QList menuActions = menu->actions(); - QAction* separatorText = menuActions[textAt]; - if (textAt > 0 && textAt < menuActions.size()) { - QAction* separatorLine = menuActions[textAt - 1]; - if (separatorLine) { - if (separatorLine->isSeparator()) { - menu->removeAction(separatorText); - menu->removeAction(separatorLine); - separatorRemoved = true; - } - } - } - } - if (separatorRemoved) { - QMenuBar::repaint(); - } -} - -void Menu::addMenuItem(const MenuItemProperties& properties) { - QMenu* menuObj = getMenu(properties.menuName); - if (menuObj) { - QShortcut* shortcut = NULL; - if (!properties.shortcutKeySequence.isEmpty()) { - shortcut = new QShortcut(properties.shortcutKeySequence, this); - } - - // check for positioning requests - int requestedPosition = properties.position; - if (requestedPosition == UNSPECIFIED_POSITION && !properties.beforeItem.isEmpty()) { - requestedPosition = findPositionOfMenuItem(menuObj, properties.beforeItem); - // double check that the requested location wasn't a separator label - requestedPosition = positionBeforeSeparatorIfNeeded(menuObj, requestedPosition); - } - if (requestedPosition == UNSPECIFIED_POSITION && !properties.afterItem.isEmpty()) { - int afterPosition = findPositionOfMenuItem(menuObj, properties.afterItem); - if (afterPosition != UNSPECIFIED_POSITION) { - requestedPosition = afterPosition + 1; - } - } - - QAction* menuItemAction = NULL; - if (properties.isSeparator) { - addDisabledActionAndSeparator(menuObj, properties.menuItemName, requestedPosition); - } else if (properties.isCheckable) { - menuItemAction = addCheckableActionToQMenuAndActionHash(menuObj, properties.menuItemName, - properties.shortcutKeySequence, properties.isChecked, - MenuScriptingInterface::getInstance(), SLOT(menuItemTriggered()), requestedPosition); - } else { - menuItemAction = addActionToQMenuAndActionHash(menuObj, properties.menuItemName, properties.shortcutKeySequence, - MenuScriptingInterface::getInstance(), SLOT(menuItemTriggered()), - QAction::NoRole, requestedPosition); - } - if (shortcut && menuItemAction) { - connect(shortcut, SIGNAL(activated()), menuItemAction, SLOT(trigger())); - } - QMenuBar::repaint(); - } -} - -void Menu::removeMenuItem(const QString& menu, const QString& menuitem) { - QMenu* menuObj = getMenu(menu); - if (menuObj) { - removeAction(menuObj, menuitem); - QMenuBar::repaint(); - } -}; - -bool Menu::menuItemExists(const QString& menu, const QString& menuitem) { - QAction* menuItemAction = _actionHash.value(menuitem); - if (menuItemAction) { - return (getMenu(menu) != NULL); - } - return false; -}; - QString Menu::getSnapshotsLocation() const { if (_snapshotsLocation.isNull() || _snapshotsLocation.isEmpty() || QDir(_snapshotsLocation).exists() == false) { return QStandardPaths::writableLocation(QStandardPaths::DesktopLocation); diff --git a/interface/src/Menu.h b/interface/src/Menu.h index 52fb17a10d..392e7ddf71 100644 --- a/interface/src/Menu.h +++ b/interface/src/Menu.h @@ -83,7 +83,80 @@ public: void triggerOption(const QString& menuOption); QAction* getActionForOption(const QString& menuOption); - + + QAction* addActionToQMenuAndActionHash(QMenu* destinationMenu, + const QString& actionName, + const QKeySequence& shortcut = 0, + const QObject* receiver = NULL, + const char* member = NULL, + QAction::MenuRole role = QAction::NoRole, + int menuItemLocation = UNSPECIFIED_POSITION); + QAction* addActionToQMenuAndActionHash(QMenu* destinationMenu, + QAction* action, + const QString& actionName = QString(), + const QKeySequence& shortcut = 0, + QAction::MenuRole role = QAction::NoRole, + int menuItemLocation = UNSPECIFIED_POSITION); + + void removeAction(QMenu* menu, const QString& actionName); + +public slots: + void loadSettings(QSettings* settings = NULL); + void saveSettings(QSettings* settings = NULL); + void importSettings(); + void exportSettings(); + + QMenu* addMenu(const QString& menuName); + void removeMenu(const QString& menuName); + bool menuExists(const QString& menuName); + void addSeparator(const QString& menuName, const QString& separatorName); + void removeSeparator(const QString& menuName, const QString& separatorName); + void addMenuItem(const MenuItemProperties& properties); + void removeMenuItem(const QString& menuName, const QString& menuitem); + bool menuItemExists(const QString& menuName, const QString& menuitem); + bool isOptionChecked(const QString& menuOption) const; + void setIsOptionChecked(const QString& menuOption, bool isChecked); + +private: + static Menu* _instance; + Menu(); + + typedef void(*settingsAction)(QSettings*, QAction*); + static void loadAction(QSettings* set, QAction* action); + static void saveAction(QSettings* set, QAction* action); + void scanMenuBar(settingsAction modifySetting, QSettings* set); + void scanMenu(QMenu* menu, settingsAction modifySetting, QSettings* set); + + /// helper method to have separators with labels that are also compatible with OS X + void addDisabledActionAndSeparator(QMenu* destinationMenu, const QString& actionName, + int menuItemLocation = UNSPECIFIED_POSITION); + + QAction* addCheckableActionToQMenuAndActionHash(QMenu* destinationMenu, + const QString& actionName, + const QKeySequence& shortcut = 0, + const bool checked = false, + const QObject* receiver = NULL, + const char* member = NULL, + int menuItemLocation = UNSPECIFIED_POSITION); + + QAction* getActionFromName(const QString& menuName, QMenu* menu); + QMenu* getSubMenuFromName(const QString& menuName, QMenu* menu); + QMenu* getMenuParent(const QString& menuName, QString& finalMenuPart); + + QAction* getMenuAction(const QString& menuName); + int findPositionOfMenuItem(QMenu* menu, const QString& searchMenuItem); + int positionBeforeSeparatorIfNeeded(QMenu* menu, int requestedPosition); + QMenu* getMenu(const QString& menuName); + + + QHash _actionHash; + + + +//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +/////////////////////////////////////////// TODO: Move to appropriate files //////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +public: const InboundAudioStream::Settings& getReceivedAudioStreamSettings() const { return _receivedAudioStreamSettings; } void setReceivedAudioStreamSettings(const InboundAudioStream::Settings& receivedAudioStreamSettings) { _receivedAudioStreamSettings = receivedAudioStreamSettings; } float getFieldOfView() const { return _fieldOfView; } @@ -140,22 +213,6 @@ public: // User Tweakable PPS from Voxel Server int getMaxOctreePacketsPerSecond() const { return _maxOctreePacketsPerSecond; } void setMaxOctreePacketsPerSecond(int value) { _maxOctreePacketsPerSecond = value; bumpSettings(); } - - QAction* addActionToQMenuAndActionHash(QMenu* destinationMenu, - const QString& actionName, - const QKeySequence& shortcut = 0, - const QObject* receiver = NULL, - const char* member = NULL, - QAction::MenuRole role = QAction::NoRole, - int menuItemLocation = UNSPECIFIED_POSITION); - QAction* addActionToQMenuAndActionHash(QMenu* destinationMenu, - QAction* action, - const QString& actionName = QString(), - const QKeySequence& shortcut = 0, - QAction::MenuRole role = QAction::NoRole, - int menuItemLocation = UNSPECIFIED_POSITION); - - void removeAction(QMenu* menu, const QString& actionName); const QByteArray& getWalletPrivateKey() const { return _walletPrivateKey; } @@ -172,10 +229,6 @@ public slots: void cachesSizeDialog(); void lodTools(); void hmdTools(bool showTools); - void loadSettings(QSettings* settings = NULL); - void saveSettings(QSettings* settings = NULL); - void importSettings(); - void exportSettings(); void toggleAddressBar(); void copyAddress(); void copyPath(); @@ -183,17 +236,6 @@ public slots: void toggleLoginMenuItem(); void toggleSixense(bool shouldEnable); - QMenu* addMenu(const QString& menuName); - void removeMenu(const QString& menuName); - bool menuExists(const QString& menuName); - void addSeparator(const QString& menuName, const QString& separatorName); - void removeSeparator(const QString& menuName, const QString& separatorName); - void addMenuItem(const MenuItemProperties& properties); - void removeMenuItem(const QString& menuName, const QString& menuitem); - bool menuItemExists(const QString& menuName, const QString& menuitem); - bool isOptionChecked(const QString& menuOption) const; - void setIsOptionChecked(const QString& menuOption, bool isChecked); - private slots: void aboutApp(); void showEditEntitiesHelp(); @@ -220,39 +262,6 @@ private slots: void loadRSSDKFile(); private: - static Menu* _instance; - - Menu(); - - typedef void(*settingsAction)(QSettings*, QAction*); - static void loadAction(QSettings* set, QAction* action); - static void saveAction(QSettings* set, QAction* action); - void scanMenuBar(settingsAction modifySetting, QSettings* set); - void scanMenu(QMenu* menu, settingsAction modifySetting, QSettings* set); - - /// helper method to have separators with labels that are also compatible with OS X - void addDisabledActionAndSeparator(QMenu* destinationMenu, const QString& actionName, - int menuItemLocation = UNSPECIFIED_POSITION); - - QAction* addCheckableActionToQMenuAndActionHash(QMenu* destinationMenu, - const QString& actionName, - const QKeySequence& shortcut = 0, - const bool checked = false, - const QObject* receiver = NULL, - const char* member = NULL, - int menuItemLocation = UNSPECIFIED_POSITION); - - QAction* getActionFromName(const QString& menuName, QMenu* menu); - QMenu* getSubMenuFromName(const QString& menuName, QMenu* menu); - QMenu* getMenuParent(const QString& menuName, QString& finalMenuPart); - - QAction* getMenuAction(const QString& menuName); - int findPositionOfMenuItem(QMenu* menu, const QString& searchMenuItem); - int positionBeforeSeparatorIfNeeded(QMenu* menu, int requestedPosition); - QMenu* getMenu(const QString& menuName); - - - QHash _actionHash; InboundAudioStream::Settings _receivedAudioStreamSettings; // in Degrees, doesn't apply to HMD like Oculus float _fieldOfView = DEFAULT_FIELD_OF_VIEW_DEGREES; From 8996bf8e0d3bd802bae5157b25fca695dad4ce6d Mon Sep 17 00:00:00 2001 From: Atlante45 Date: Fri, 16 Jan 2015 15:26:42 -0800 Subject: [PATCH 002/167] Use qApp Reuse qApp global variable following Qt's pattern --- interface/src/Application.h | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/interface/src/Application.h b/interface/src/Application.h index a66a30abce..7b86236ffa 100644 --- a/interface/src/Application.h +++ b/interface/src/Application.h @@ -121,6 +121,12 @@ static const quint64 TOO_LONG_SINCE_LAST_SEND_DOWNSTREAM_AUDIO_STATS = 1 * USECS static const QString INFO_HELP_PATH = "html/interface-welcome-allsvg.html"; static const QString INFO_EDIT_ENTITIES_PATH = "html/edit-entities-commands.html"; +class Application; +#if defined(qApp) +#undef qApp +#endif +#define qApp (static_cast(QCoreApplication::instance())) + class Application : public QApplication, public AbstractViewStateInterface, AbstractScriptingServicesInterface { Q_OBJECT @@ -128,7 +134,7 @@ class Application : public QApplication, public AbstractViewStateInterface, Abst friend class DatagramProcessor; public: - static Application* getInstance() { return static_cast(QCoreApplication::instance()); } + static Application* getInstance() { return qApp; } // TODO: replace fully by qApp static const glm::vec3& getPositionForPath() { return getInstance()->_myAvatar->getPosition(); } static glm::quat getOrientationForPath() { return getInstance()->_myAvatar->getOrientation(); } From f34add9c9c3e58f65e6a60fff6e6ebf4a38f664c Mon Sep 17 00:00:00 2001 From: Atlante45 Date: Fri, 16 Jan 2015 16:30:33 -0800 Subject: [PATCH 003/167] Moved Bookmarks related funct out of Menu Took everything Bookmarks related in Menu and moved it over to Bookmarks. --- interface/src/Bookmarks.cpp | 132 ++++++++++++++++++++++++++++++++++++ interface/src/Bookmarks.h | 34 +++++++--- interface/src/Menu.cpp | 131 +---------------------------------- interface/src/Menu.h | 9 +-- 4 files changed, 161 insertions(+), 145 deletions(-) diff --git a/interface/src/Bookmarks.cpp b/interface/src/Bookmarks.cpp index d3ecf4097e..f8bc269635 100644 --- a/interface/src/Bookmarks.cpp +++ b/interface/src/Bookmarks.cpp @@ -9,10 +9,20 @@ // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // +#include +#include +#include #include +#include #include +#include #include +#include + +#include "MainWindow.h" +#include "Menu.h" + #include "Bookmarks.h" Bookmarks::Bookmarks() { @@ -71,3 +81,125 @@ void Bookmarks::persistToFile() { QByteArray data = json.toJson(); saveFile.write(data); } + +void Bookmarks::setupMenus(Menu* menubar, QMenu* menu) { + // Add menus/actions + menubar->addActionToQMenuAndActionHash(menu, MenuOption::BookmarkLocation, 0, + this, SLOT(bookmarkLocation())); + _bookmarksMenu = menu->addMenu(MenuOption::Bookmarks); + _deleteBookmarksAction = menubar->addActionToQMenuAndActionHash(menu, MenuOption::DeleteBookmark, 0, + this, SLOT(deleteBookmark())); + + // Enable/Disable menus as needed + enableMenuItems(_bookmarks.count() > 0); + + // Load bookmarks + for (auto it = _bookmarks.begin(); it != _bookmarks.end(); ++it ) { + QString bookmarkName = it.key(); + QString bookmarkAddress = it.value().toString(); + addLocationToMenu(menubar, bookmarkName, bookmarkAddress); + } +} + +void Bookmarks::bookmarkLocation() { + QInputDialog bookmarkLocationDialog(qApp->getWindow()); + bookmarkLocationDialog.setWindowTitle("Bookmark Location"); + bookmarkLocationDialog.setLabelText("Name:"); + bookmarkLocationDialog.setInputMode(QInputDialog::TextInput); + bookmarkLocationDialog.resize(400, 200); + + if (bookmarkLocationDialog.exec() == QDialog::Rejected) { + return; + } + + QString bookmarkName = bookmarkLocationDialog.textValue().trimmed(); + bookmarkName = bookmarkName.replace(QRegExp("(\r\n|[\r\n\t\v ])+"), " "); + if (bookmarkName.length() == 0) { + return; + } + + auto addressManager = DependencyManager::get(); + QString bookmarkAddress = addressManager->currentAddress().toString(); + + Menu* menubar = Menu::getInstance(); + if (contains(bookmarkName)) { + QMessageBox duplicateBookmarkMessage; + duplicateBookmarkMessage.setIcon(QMessageBox::Warning); + duplicateBookmarkMessage.setText("The bookmark name you entered already exists in your list."); + duplicateBookmarkMessage.setInformativeText("Would you like to overwrite it?"); + duplicateBookmarkMessage.setStandardButtons(QMessageBox::Yes | QMessageBox::No); + duplicateBookmarkMessage.setDefaultButton(QMessageBox::Yes); + if (duplicateBookmarkMessage.exec() == QMessageBox::No) { + return; + } + removeLocationFromMenu(menubar, bookmarkName); + } + + addLocationToMenu(menubar, bookmarkName, bookmarkAddress); + insert(bookmarkName, bookmarkAddress); // Overwrites any item with the same bookmarkName. + + enableMenuItems(true); +} + +void Bookmarks::teleportToBookmark() { + QAction* action = qobject_cast(sender()); + QString address = action->data().toString(); + DependencyManager::get()->handleLookupString(address); +} + +void Bookmarks::deleteBookmark() { + + QStringList bookmarkList; + QList menuItems = _bookmarksMenu->actions(); + for (int i = 0; i < menuItems.count(); i += 1) { + bookmarkList.append(menuItems[i]->text()); + } + + QInputDialog deleteBookmarkDialog(qApp->getWindow()); + deleteBookmarkDialog.setWindowTitle("Delete Bookmark"); + deleteBookmarkDialog.setLabelText("Select the bookmark to delete"); + deleteBookmarkDialog.resize(400, 400); + deleteBookmarkDialog.setOption(QInputDialog::UseListViewForComboBoxItems); + deleteBookmarkDialog.setComboBoxItems(bookmarkList); + deleteBookmarkDialog.setOkButtonText("Delete"); + + if (deleteBookmarkDialog.exec() == QDialog::Rejected) { + return; + } + + QString bookmarkName = deleteBookmarkDialog.textValue().trimmed(); + if (bookmarkName.length() == 0) { + return; + } + + removeLocationFromMenu(Menu::getInstance(), bookmarkName); + remove(bookmarkName); + + if (_bookmarksMenu->actions().count() == 0) { + enableMenuItems(false); + } +} + +void Bookmarks::enableMenuItems(bool enabled) { + if (_bookmarksMenu) { + _bookmarksMenu->setEnabled(enabled); + } + if (_deleteBookmarksAction) { + _deleteBookmarksAction->setEnabled(enabled); + } +} + +void Bookmarks::addLocationToMenu(Menu* menubar, QString& name, QString& address) { + QAction* teleportAction = new QAction(_bookmarksMenu); + teleportAction->setData(address); + connect(teleportAction, SIGNAL(triggered()), this, SLOT(teleportToBookmark())); + + menubar->addActionToQMenuAndActionHash(_bookmarksMenu, teleportAction, + name, 0, QAction::NoRole); +} + +void Bookmarks::removeLocationFromMenu(Menu* menubar, QString& name) { + menubar->removeAction(_bookmarksMenu, name); +} + + diff --git a/interface/src/Bookmarks.h b/interface/src/Bookmarks.h index 2f054bcdbc..59f9efb1b1 100644 --- a/interface/src/Bookmarks.h +++ b/interface/src/Bookmarks.h @@ -12,10 +12,13 @@ #ifndef hifi_Bookmarks_h #define hifi_Bookmarks_h -#include -#include #include #include +#include + +class QAction; +class QMenu; +class Menu; class Bookmarks: public QObject { Q_OBJECT @@ -23,19 +26,32 @@ class Bookmarks: public QObject { public: Bookmarks(); + void setupMenus(Menu* menubar, QMenu* menu); + +private slots: + void bookmarkLocation(); + void teleportToBookmark(); + void deleteBookmark(); + +private: + QVariantMap _bookmarks; // { name: address, ... } + + QPointer _bookmarksMenu; + QPointer _deleteBookmarksAction; + + const QString BOOKMARKS_FILENAME = "bookmarks.json"; + QString _bookmarksFilename; + void insert(const QString& name, const QString& address); // Overwrites any existing entry with same name. void remove(const QString& name); bool contains(const QString& name) const; - QVariantMap* getBookmarks() { return &_bookmarks; }; - -private: - QVariantMap _bookmarks; // { name: address, ... } - - const QString BOOKMARKS_FILENAME = "bookmarks.json"; - QString _bookmarksFilename; void readFromFile(); void persistToFile(); + + void enableMenuItems(bool enabled); + void addLocationToMenu(Menu* menubar, QString& name, QString& address); + void removeLocationFromMenu(Menu* menubar, QString& name); }; #endif // hifi_Bookmarks_h \ No newline at end of file diff --git a/interface/src/Menu.cpp b/interface/src/Menu.cpp index 686de54894..6531344f9b 100644 --- a/interface/src/Menu.cpp +++ b/interface/src/Menu.cpp @@ -125,15 +125,8 @@ Menu::Menu() : appInstance, SLOT(toggleRunningScriptsWidget())); addDisabledActionAndSeparator(fileMenu, "Location"); - addActionToQMenuAndActionHash(fileMenu, MenuOption::BookmarkLocation, 0, - this, SLOT(bookmarkLocation())); - _bookmarksMenu = fileMenu->addMenu(MenuOption::Bookmarks); - _bookmarksMenu->setEnabled(false); - _deleteBookmarksMenu = addActionToQMenuAndActionHash(fileMenu, - MenuOption::DeleteBookmark, 0, - this, SLOT(deleteBookmark())); - _deleteBookmarksMenu->setEnabled(false); - loadBookmarks(); + qApp->getBookmarks()->setupMenus(this, fileMenu); + addActionToQMenuAndActionHash(fileMenu, MenuOption::AddressBar, Qt::Key_Enter, @@ -1264,125 +1257,6 @@ void Menu::changeVSync() { Application::getInstance()->setVSyncEnabled(isOptionChecked(MenuOption::RenderTargetFramerateVSyncOn)); } -void Menu::loadBookmarks() { - QVariantMap* bookmarks = Application::getInstance()->getBookmarks()->getBookmarks(); - if (bookmarks->count() > 0) { - - QMapIterator i(*bookmarks); - while (i.hasNext()) { - i.next(); - - QString bookmarkName = i.key(); - QString bookmarkAddress = i.value().toString(); - - QAction* teleportAction = new QAction(getMenu(MenuOption::Bookmarks)); - teleportAction->setData(bookmarkAddress); - connect(teleportAction, SIGNAL(triggered()), this, SLOT(teleportToBookmark())); - - addActionToQMenuAndActionHash(_bookmarksMenu, teleportAction, bookmarkName, 0, QAction::NoRole); - } - - _bookmarksMenu->setEnabled(true); - _deleteBookmarksMenu->setEnabled(true); - } -} - -void Menu::bookmarkLocation() { - - QInputDialog bookmarkLocationDialog(Application::getInstance()->getWindow()); - bookmarkLocationDialog.setWindowTitle("Bookmark Location"); - bookmarkLocationDialog.setLabelText("Name:"); - bookmarkLocationDialog.setInputMode(QInputDialog::TextInput); - bookmarkLocationDialog.resize(400, 200); - - if (bookmarkLocationDialog.exec() == QDialog::Rejected) { - return; - } - - QString bookmarkName = bookmarkLocationDialog.textValue().trimmed(); - bookmarkName = bookmarkName.replace(QRegExp("(\r\n|[\r\n\t\v ])+"), " "); - if (bookmarkName.length() == 0) { - return; - } - - auto addressManager = DependencyManager::get(); - QString bookmarkAddress = addressManager->currentAddress().toString(); - - Bookmarks* bookmarks = Application::getInstance()->getBookmarks(); - if (bookmarks->contains(bookmarkName)) { - QMessageBox duplicateBookmarkMessage; - duplicateBookmarkMessage.setIcon(QMessageBox::Warning); - duplicateBookmarkMessage.setText("The bookmark name you entered already exists in your list."); - duplicateBookmarkMessage.setInformativeText("Would you like to overwrite it?"); - duplicateBookmarkMessage.setStandardButtons(QMessageBox::Yes | QMessageBox::No); - duplicateBookmarkMessage.setDefaultButton(QMessageBox::Yes); - if (duplicateBookmarkMessage.exec() == QMessageBox::No) { - return; - } - removeAction(_bookmarksMenu, bookmarkName); - } - - QAction* teleportAction = new QAction(getMenu(MenuOption::Bookmarks)); - teleportAction->setData(bookmarkAddress); - connect(teleportAction, SIGNAL(triggered()), this, SLOT(teleportToBookmark())); - - QList menuItems = _bookmarksMenu->actions(); - int position = 0; - while (position < menuItems.count() && bookmarkName > menuItems[position]->text()) { - position += 1; - } - - addActionToQMenuAndActionHash(_bookmarksMenu, teleportAction, bookmarkName, 0, - QAction::NoRole, position); - - bookmarks->insert(bookmarkName, bookmarkAddress); // Overwrites any item with the same bookmarkName. - - _bookmarksMenu->setEnabled(true); - _deleteBookmarksMenu->setEnabled(true); -} - -void Menu::teleportToBookmark() { - QAction *action = qobject_cast(sender()); - QString address = action->data().toString(); - DependencyManager::get()->handleLookupString(address); -} - -void Menu::deleteBookmark() { - - QStringList bookmarkList; - QList menuItems = _bookmarksMenu->actions(); - for (int i = 0; i < menuItems.count(); i += 1) { - bookmarkList.append(menuItems[i]->text()); - } - - QInputDialog deleteBookmarkDialog(Application::getInstance()->getWindow()); - deleteBookmarkDialog.setWindowTitle("Delete Bookmark"); - deleteBookmarkDialog.setLabelText("Select the bookmark to delete"); - deleteBookmarkDialog.resize(400, 400); - deleteBookmarkDialog.setOption(QInputDialog::UseListViewForComboBoxItems); - deleteBookmarkDialog.setComboBoxItems(bookmarkList); - deleteBookmarkDialog.setOkButtonText("Delete"); - - if (deleteBookmarkDialog.exec() == QDialog::Rejected) { - return; - } - - QString bookmarkName = deleteBookmarkDialog.textValue().trimmed(); - if (bookmarkName.length() == 0) { - return; - } - - removeAction(_bookmarksMenu, bookmarkName); - - Bookmarks* bookmarks = Application::getInstance()->getBookmarks(); - bookmarks->remove(bookmarkName); - - if (_bookmarksMenu->actions().count() == 0) { - _bookmarksMenu->setEnabled(false); - _deleteBookmarksMenu->setEnabled(false); - } -} - void Menu::displayNameLocationResponse(const QString& errorString) { if (!errorString.isEmpty()) { @@ -1753,3 +1627,4 @@ void Menu::setScriptsLocation(const QString& scriptsLocation) { bumpSettings(); emit scriptLocationChanged(scriptsLocation); } + diff --git a/interface/src/Menu.h b/interface/src/Menu.h index 392e7ddf71..bafcf401c9 100644 --- a/interface/src/Menu.h +++ b/interface/src/Menu.h @@ -80,6 +80,7 @@ class Menu : public QMenuBar { Q_OBJECT public: static Menu* getInstance(); + QMenu* getMenu(const QString& menuName); void triggerOption(const QString& menuOption); QAction* getActionForOption(const QString& menuOption); @@ -146,7 +147,6 @@ private: QAction* getMenuAction(const QString& menuName); int findPositionOfMenuItem(QMenu* menu, const QString& searchMenuItem); int positionBeforeSeparatorIfNeeded(QMenu* menu, int requestedPosition); - QMenu* getMenu(const QString& menuName); QHash _actionHash; @@ -244,9 +244,6 @@ private slots: void editAttachments(); void editAnimations(); void changePrivateKey(); - void bookmarkLocation(); - void teleportToBookmark(); - void deleteBookmark(); void hmdToolsClosed(); void runTests(); void showMetavoxelEditor(); @@ -318,10 +315,6 @@ private: bool _shouldRenderTableNeedsRebuilding = true; QMap _shouldRenderTable; - - void loadBookmarks(); - QMenu* _bookmarksMenu; - QAction* _deleteBookmarksMenu; }; namespace MenuOption { From a9047b7b151df28322b28134f05db0dd1fb6c958 Mon Sep 17 00:00:00 2001 From: Atlante45 Date: Fri, 16 Jan 2015 17:49:22 -0800 Subject: [PATCH 004/167] LODManager class Moved most LOD related members in menu to new Dependency LODManager Replaced all Menu::getInstance() call that accessed those members by DM gets --- interface/src/Application.cpp | 15 +- interface/src/LODManager.cpp | 181 +++++++++++++++++++++++++ interface/src/LODManager.h | 98 +++++++++++++ interface/src/Menu.cpp | 142 +------------------ interface/src/Menu.h | 54 +------- interface/src/avatar/Avatar.cpp | 4 +- interface/src/ui/LodToolsDialog.cpp | 46 ++++--- interface/src/ui/Stats.cpp | 2 +- interface/src/ui/overlays/Overlays.cpp | 16 ++- 9 files changed, 330 insertions(+), 228 deletions(-) create mode 100644 interface/src/LODManager.cpp create mode 100644 interface/src/LODManager.h diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index dbc409bac2..efbf429ab4 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -80,6 +80,7 @@ #include "Application.h" #include "InterfaceVersion.h" +#include "LODManager.h" #include "Menu.h" #include "ModelUploader.h" #include "Util.h" @@ -173,6 +174,7 @@ bool setupEssentials(int& argc, char** argv) { auto ddeFaceTracker = DependencyManager::set(); auto modelBlender = DependencyManager::set(); auto audioToolBox = DependencyManager::set(); + auto lodManager = DependencyManager::set(); return true; } @@ -1772,9 +1774,9 @@ void Application::updateLOD() { PerformanceTimer perfTimer("LOD"); // adjust it unless we were asked to disable this feature, or if we're currently in throttleRendering mode if (!Menu::getInstance()->isOptionChecked(MenuOption::DisableAutoAdjustLOD) && !isThrottleRendering()) { - Menu::getInstance()->autoAdjustLOD(_fps); + DependencyManager::get()->autoAdjustLOD(_fps); } else { - Menu::getInstance()->resetLODAdjust(); + DependencyManager::get()->resetLODAdjust(); } } @@ -2246,8 +2248,9 @@ void Application::queryOctree(NodeType_t serverType, PacketType packetType, Node _octreeQuery.setCameraNearClip(_viewFrustum.getNearClip()); _octreeQuery.setCameraFarClip(_viewFrustum.getFarClip()); _octreeQuery.setCameraEyeOffsetPosition(_viewFrustum.getEyeOffsetPosition()); - _octreeQuery.setOctreeSizeScale(Menu::getInstance()->getOctreeSizeScale()); - _octreeQuery.setBoundaryLevelAdjust(Menu::getInstance()->getBoundaryLevelAdjust()); + auto lodManager = DependencyManager::get(); + _octreeQuery.setOctreeSizeScale(lodManager->getOctreeSizeScale()); + _octreeQuery.setBoundaryLevelAdjust(lodManager->getBoundaryLevelAdjust()); unsigned char queryPacket[MAX_PACKET_SIZE]; @@ -2649,11 +2652,11 @@ bool Application::shouldRenderMesh(float largestDimension, float distanceToCamer } float Application::getSizeScale() const { - return Menu::getInstance()->getOctreeSizeScale(); + return DependencyManager::get()->getOctreeSizeScale(); } int Application::getBoundaryLevelAdjust() const { - return Menu::getInstance()->getBoundaryLevelAdjust(); + return DependencyManager::get()->getBoundaryLevelAdjust(); } PickRay Application::computePickRay(float x, float y) { diff --git a/interface/src/LODManager.cpp b/interface/src/LODManager.cpp new file mode 100644 index 0000000000..837020dc36 --- /dev/null +++ b/interface/src/LODManager.cpp @@ -0,0 +1,181 @@ +// +// LODManager.cpp +// +// +// Created by Clement on 1/16/15. +// Copyright 2015 High Fidelity, Inc. +// +// Distributed under the Apache License, Version 2.0. +// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html +// + +#include + +#include "Application.h" + +#include "LODManager.h" + +void LODManager::autoAdjustLOD(float currentFPS) { + // NOTE: our first ~100 samples at app startup are completely all over the place, and we don't + // really want to count them in our average, so we will ignore the real frame rates and stuff + // our moving average with simulated good data + const int IGNORE_THESE_SAMPLES = 100; + const float ASSUMED_FPS = 60.0f; + if (_fpsAverage.getSampleCount() < IGNORE_THESE_SAMPLES) { + currentFPS = ASSUMED_FPS; + } + _fpsAverage.updateAverage(currentFPS); + _fastFPSAverage.updateAverage(currentFPS); + + quint64 now = usecTimestampNow(); + + const quint64 ADJUST_AVATAR_LOD_DOWN_DELAY = 1000 * 1000; + if (_automaticAvatarLOD) { + if (_fastFPSAverage.getAverage() < _avatarLODDecreaseFPS) { + if (now - _lastAvatarDetailDrop > ADJUST_AVATAR_LOD_DOWN_DELAY) { + // attempt to lower the detail in proportion to the fps difference + float targetFps = (_avatarLODDecreaseFPS + _avatarLODIncreaseFPS) * 0.5f; + float averageFps = _fastFPSAverage.getAverage(); + const float MAXIMUM_MULTIPLIER_SCALE = 2.0f; + _avatarLODDistanceMultiplier = qMin(MAXIMUM_AVATAR_LOD_DISTANCE_MULTIPLIER, _avatarLODDistanceMultiplier * + (averageFps < EPSILON ? MAXIMUM_MULTIPLIER_SCALE : + qMin(MAXIMUM_MULTIPLIER_SCALE, targetFps / averageFps))); + _lastAvatarDetailDrop = now; + } + } else if (_fastFPSAverage.getAverage() > _avatarLODIncreaseFPS) { + // let the detail level creep slowly upwards + const float DISTANCE_DECREASE_RATE = 0.05f; + _avatarLODDistanceMultiplier = qMax(MINIMUM_AVATAR_LOD_DISTANCE_MULTIPLIER, + _avatarLODDistanceMultiplier - DISTANCE_DECREASE_RATE); + } + } + + bool changed = false; + quint64 elapsed = now - _lastAdjust; + + if (elapsed > ADJUST_LOD_DOWN_DELAY && _fpsAverage.getAverage() < ADJUST_LOD_DOWN_FPS + && _octreeSizeScale > ADJUST_LOD_MIN_SIZE_SCALE) { + + _octreeSizeScale *= ADJUST_LOD_DOWN_BY; + + if (_octreeSizeScale < ADJUST_LOD_MIN_SIZE_SCALE) { + _octreeSizeScale = ADJUST_LOD_MIN_SIZE_SCALE; + } + changed = true; + _lastAdjust = now; + qDebug() << "adjusting LOD down... average fps for last approximately 5 seconds=" << _fpsAverage.getAverage() + << "_octreeSizeScale=" << _octreeSizeScale; + } + + if (elapsed > ADJUST_LOD_UP_DELAY && _fpsAverage.getAverage() > ADJUST_LOD_UP_FPS + && _octreeSizeScale < ADJUST_LOD_MAX_SIZE_SCALE) { + _octreeSizeScale *= ADJUST_LOD_UP_BY; + if (_octreeSizeScale > ADJUST_LOD_MAX_SIZE_SCALE) { + _octreeSizeScale = ADJUST_LOD_MAX_SIZE_SCALE; + } + changed = true; + _lastAdjust = now; + qDebug() << "adjusting LOD up... average fps for last approximately 5 seconds=" << _fpsAverage.getAverage() + << "_octreeSizeScale=" << _octreeSizeScale; + } + + if (changed) { + _shouldRenderTableNeedsRebuilding = true; + // TODO: reactivate lodToolsDialog here +// if (_lodToolsDialog) { +// _lodToolsDialog->reloadSliders(); +// } + } +} + +void LODManager::resetLODAdjust() { + _fpsAverage.reset(); + _fastFPSAverage.reset(); + _lastAvatarDetailDrop = _lastAdjust = usecTimestampNow(); +} + +QString LODManager::getLODFeedbackText() { + // determine granularity feedback + int boundaryLevelAdjust = getBoundaryLevelAdjust(); + QString granularityFeedback; + + switch (boundaryLevelAdjust) { + case 0: { + granularityFeedback = QString("at standard granularity."); + } break; + case 1: { + granularityFeedback = QString("at half of standard granularity."); + } break; + case 2: { + granularityFeedback = QString("at a third of standard granularity."); + } break; + default: { + granularityFeedback = QString("at 1/%1th of standard granularity.").arg(boundaryLevelAdjust + 1); + } break; + } + + // distance feedback + float octreeSizeScale = getOctreeSizeScale(); + float relativeToDefault = octreeSizeScale / DEFAULT_OCTREE_SIZE_SCALE; + QString result; + if (relativeToDefault > 1.01) { + result = QString("%1 further %2").arg(relativeToDefault,8,'f',2).arg(granularityFeedback); + } else if (relativeToDefault > 0.99) { + result = QString("the default distance %1").arg(granularityFeedback); + } else { + result = QString("%1 of default %2").arg(relativeToDefault,8,'f',3).arg(granularityFeedback); + } + return result; +} + +void LODManager::setOctreeSizeScale(float sizeScale) { + _octreeSizeScale = sizeScale; + _shouldRenderTableNeedsRebuilding = true; +} + +void LODManager::setBoundaryLevelAdjust(int boundaryLevelAdjust) { + _boundaryLevelAdjust = boundaryLevelAdjust; + _shouldRenderTableNeedsRebuilding = true; +} + + +void LODManager::loadSettings(QSettings* settings) { + bool lockedSettings = false; + if (!settings) { + settings = qApp->lockSettings(); + lockedSettings = true; + } + + _automaticAvatarLOD = settings->value("automaticAvatarLOD", true).toBool(); + _avatarLODDecreaseFPS = loadSetting(settings, "avatarLODDecreaseFPS", DEFAULT_ADJUST_AVATAR_LOD_DOWN_FPS); + _avatarLODIncreaseFPS = loadSetting(settings, "avatarLODIncreaseFPS", ADJUST_LOD_UP_FPS); + _avatarLODDistanceMultiplier = loadSetting(settings, "avatarLODDistanceMultiplier", + DEFAULT_AVATAR_LOD_DISTANCE_MULTIPLIER); + _octreeSizeScale = loadSetting(settings, "octreeSizeScale", DEFAULT_OCTREE_SIZE_SCALE); + _boundaryLevelAdjust = loadSetting(settings, "boundaryLevelAdjust", 0); + + if (lockedSettings) { + qApp->unlockSettings(); + } +} + +void LODManager::saveSettings(QSettings* settings) { + bool lockedSettings = false; + if (!settings) { + settings = qApp->lockSettings(); + lockedSettings = true; + } + + settings->setValue("automaticAvatarLOD", _automaticAvatarLOD); + settings->setValue("avatarLODDecreaseFPS", _avatarLODDecreaseFPS); + settings->setValue("avatarLODIncreaseFPS", _avatarLODIncreaseFPS); + settings->setValue("avatarLODDistanceMultiplier", _avatarLODDistanceMultiplier); + settings->setValue("octreeSizeScale", _octreeSizeScale); + settings->setValue("boundaryLevelAdjust", _boundaryLevelAdjust); + + if (lockedSettings) { + qApp->unlockSettings(); + } +} + + diff --git a/interface/src/LODManager.h b/interface/src/LODManager.h new file mode 100644 index 0000000000..1b02a931ed --- /dev/null +++ b/interface/src/LODManager.h @@ -0,0 +1,98 @@ +// +// LODManager.h +// +// +// Created by Clement on 1/16/15. +// Copyright 2015 High Fidelity, Inc. +// +// Distributed under the Apache License, Version 2.0. +// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html +// + +#ifndef hifi_LODManager_h +#define hifi_LODManager_h + +#include + +#include +#include +#include +#include + +const float ADJUST_LOD_DOWN_FPS = 40.0; +const float ADJUST_LOD_UP_FPS = 55.0; +const float DEFAULT_ADJUST_AVATAR_LOD_DOWN_FPS = 30.0f; + +const quint64 ADJUST_LOD_DOWN_DELAY = 1000 * 1000 * 5; +const quint64 ADJUST_LOD_UP_DELAY = ADJUST_LOD_DOWN_DELAY * 2; + +const float ADJUST_LOD_DOWN_BY = 0.9f; +const float ADJUST_LOD_UP_BY = 1.1f; + +const float ADJUST_LOD_MIN_SIZE_SCALE = DEFAULT_OCTREE_SIZE_SCALE * 0.25f; +const float ADJUST_LOD_MAX_SIZE_SCALE = DEFAULT_OCTREE_SIZE_SCALE; + +const float MINIMUM_AVATAR_LOD_DISTANCE_MULTIPLIER = 0.1f; +const float MAXIMUM_AVATAR_LOD_DISTANCE_MULTIPLIER = 15.0f; +const float DEFAULT_AVATAR_LOD_DISTANCE_MULTIPLIER = 1.0f; + +const int ONE_SECOND_OF_FRAMES = 60; +const int FIVE_SECONDS_OF_FRAMES = 5 * ONE_SECOND_OF_FRAMES; + +class LODManager : public Dependency { + SINGLETON_DEPENDENCY + +public: + // TODO: actually use them + bool shouldRenderTableNeedsRebuilding() const { return _shouldRenderTableNeedsRebuilding; } + void setShouldRenderTableNeedsRebuilding(bool shouldRenderTableNeedsRebuilding) { + _shouldRenderTableNeedsRebuilding = shouldRenderTableNeedsRebuilding; + } + + // TODO: replace bumpSettings() + void setAutomaticAvatarLOD(bool automaticAvatarLOD) { _automaticAvatarLOD = automaticAvatarLOD; } + bool getAutomaticAvatarLOD() const { return _automaticAvatarLOD; } + void setAvatarLODDecreaseFPS(float avatarLODDecreaseFPS) { _avatarLODDecreaseFPS = avatarLODDecreaseFPS; } + float getAvatarLODDecreaseFPS() const { return _avatarLODDecreaseFPS; } + void setAvatarLODIncreaseFPS(float avatarLODIncreaseFPS) { _avatarLODIncreaseFPS = avatarLODIncreaseFPS; } + float getAvatarLODIncreaseFPS() const { return _avatarLODIncreaseFPS; } + void setAvatarLODDistanceMultiplier(float multiplier) { _avatarLODDistanceMultiplier = multiplier; } + float getAvatarLODDistanceMultiplier() const { return _avatarLODDistanceMultiplier; } + + // User Tweakable LOD Items + QString getLODFeedbackText(); + void setOctreeSizeScale(float sizeScale); + float getOctreeSizeScale() const { return _octreeSizeScale; } + + void setBoundaryLevelAdjust(int boundaryLevelAdjust); + int getBoundaryLevelAdjust() const { return _boundaryLevelAdjust; } + + void autoAdjustLOD(float currentFPS); + void resetLODAdjust(); + +private: + LODManager(); + + void loadSettings(QSettings* settings); + void saveSettings(QSettings* settings); + + bool _automaticAvatarLOD = true; + float _avatarLODDecreaseFPS = DEFAULT_ADJUST_AVATAR_LOD_DOWN_FPS; + float _avatarLODIncreaseFPS = ADJUST_LOD_UP_FPS; + float _avatarLODDistanceMultiplier = DEFAULT_AVATAR_LOD_DISTANCE_MULTIPLIER; + + float _octreeSizeScale = DEFAULT_OCTREE_SIZE_SCALE; + int _boundaryLevelAdjust = 0; + + quint64 _lastAdjust = 0; + quint64 _lastAvatarDetailDrop = 0; + SimpleMovingAverage _fpsAverage = FIVE_SECONDS_OF_FRAMES; + SimpleMovingAverage _fastFPSAverage = ONE_SECOND_OF_FRAMES; + + + // TODO: actually use them + bool _shouldRenderTableNeedsRebuilding = true; + QMap _shouldRenderTable; +}; + +#endif // hifi_LODManager_h \ No newline at end of file diff --git a/interface/src/Menu.cpp b/interface/src/Menu.cpp index 6531344f9b..7f8e1b82ae 100644 --- a/interface/src/Menu.cpp +++ b/interface/src/Menu.cpp @@ -86,10 +86,7 @@ Menu* Menu::getInstance() { return _instance; } -Menu::Menu() : - _lastAdjust(usecTimestampNow()), - _lastAvatarDetailDrop(usecTimestampNow()) -{ +Menu::Menu() { Application *appInstance = Application::getInstance(); QMenu* fileMenu = addMenu("File"); @@ -606,13 +603,6 @@ void Menu::loadSettings(QSettings* settings) { _faceshiftEyeDeflection = loadSetting(settings, "faceshiftEyeDeflection", DEFAULT_FACESHIFT_EYE_DEFLECTION); _faceshiftHostname = settings->value("faceshiftHostname", DEFAULT_FACESHIFT_HOSTNAME).toString(); _maxOctreePacketsPerSecond = loadSetting(settings, "maxOctreePPS", DEFAULT_MAX_OCTREE_PPS); - _octreeSizeScale = loadSetting(settings, "octreeSizeScale", DEFAULT_OCTREE_SIZE_SCALE); - _automaticAvatarLOD = settings->value("automaticAvatarLOD", true).toBool(); - _avatarLODDecreaseFPS = loadSetting(settings, "avatarLODDecreaseFPS", DEFAULT_ADJUST_AVATAR_LOD_DOWN_FPS); - _avatarLODIncreaseFPS = loadSetting(settings, "avatarLODIncreaseFPS", ADJUST_LOD_UP_FPS); - _avatarLODDistanceMultiplier = loadSetting(settings, "avatarLODDistanceMultiplier", - DEFAULT_AVATAR_LOD_DISTANCE_MULTIPLIER); - _boundaryLevelAdjust = loadSetting(settings, "boundaryLevelAdjust", 0); _snapshotsLocation = settings->value("snapshotsLocation", QStandardPaths::writableLocation(QStandardPaths::DesktopLocation)).toString(); setScriptsLocation(settings->value("scriptsLocation", QString()).toString()); @@ -669,12 +659,6 @@ void Menu::saveSettings(QSettings* settings) { settings->setValue("faceshiftEyeDeflection", _faceshiftEyeDeflection); settings->setValue("faceshiftHostname", _faceshiftHostname); settings->setValue("maxOctreePPS", _maxOctreePacketsPerSecond); - settings->setValue("octreeSizeScale", _octreeSizeScale); - settings->setValue("automaticAvatarLOD", _automaticAvatarLOD); - settings->setValue("avatarLODDecreaseFPS", _avatarLODDecreaseFPS); - settings->setValue("avatarLODIncreaseFPS", _avatarLODIncreaseFPS); - settings->setValue("avatarLODDistanceMultiplier", _avatarLODDistanceMultiplier); - settings->setValue("boundaryLevelAdjust", _boundaryLevelAdjust); settings->setValue("snapshotsLocation", _snapshotsLocation); settings->setValue("scriptsLocation", _scriptsLocation); #if defined(Q_OS_MAC) || defined(Q_OS_WIN) @@ -1404,130 +1388,6 @@ void Menu::octreeStatsDetails() { _octreeStatsDialog->raise(); } -QString Menu::getLODFeedbackText() { - // determine granularity feedback - int boundaryLevelAdjust = getBoundaryLevelAdjust(); - QString granularityFeedback; - - switch (boundaryLevelAdjust) { - case 0: { - granularityFeedback = QString("at standard granularity."); - } break; - case 1: { - granularityFeedback = QString("at half of standard granularity."); - } break; - case 2: { - granularityFeedback = QString("at a third of standard granularity."); - } break; - default: { - granularityFeedback = QString("at 1/%1th of standard granularity.").arg(boundaryLevelAdjust + 1); - } break; - } - - // distance feedback - float octreeSizeScale = getOctreeSizeScale(); - float relativeToDefault = octreeSizeScale / DEFAULT_OCTREE_SIZE_SCALE; - QString result; - if (relativeToDefault > 1.01) { - result = QString("%1 further %2").arg(relativeToDefault,8,'f',2).arg(granularityFeedback); - } else if (relativeToDefault > 0.99) { - result = QString("the default distance %1").arg(granularityFeedback); - } else { - result = QString("%1 of default %2").arg(relativeToDefault,8,'f',3).arg(granularityFeedback); - } - return result; -} - -void Menu::autoAdjustLOD(float currentFPS) { - // NOTE: our first ~100 samples at app startup are completely all over the place, and we don't - // really want to count them in our average, so we will ignore the real frame rates and stuff - // our moving average with simulated good data - const int IGNORE_THESE_SAMPLES = 100; - const float ASSUMED_FPS = 60.0f; - if (_fpsAverage.getSampleCount() < IGNORE_THESE_SAMPLES) { - currentFPS = ASSUMED_FPS; - } - _fpsAverage.updateAverage(currentFPS); - _fastFPSAverage.updateAverage(currentFPS); - - quint64 now = usecTimestampNow(); - - const quint64 ADJUST_AVATAR_LOD_DOWN_DELAY = 1000 * 1000; - if (_automaticAvatarLOD) { - if (_fastFPSAverage.getAverage() < _avatarLODDecreaseFPS) { - if (now - _lastAvatarDetailDrop > ADJUST_AVATAR_LOD_DOWN_DELAY) { - // attempt to lower the detail in proportion to the fps difference - float targetFps = (_avatarLODDecreaseFPS + _avatarLODIncreaseFPS) * 0.5f; - float averageFps = _fastFPSAverage.getAverage(); - const float MAXIMUM_MULTIPLIER_SCALE = 2.0f; - _avatarLODDistanceMultiplier = qMin(MAXIMUM_AVATAR_LOD_DISTANCE_MULTIPLIER, _avatarLODDistanceMultiplier * - (averageFps < EPSILON ? MAXIMUM_MULTIPLIER_SCALE : - qMin(MAXIMUM_MULTIPLIER_SCALE, targetFps / averageFps))); - _lastAvatarDetailDrop = now; - } - } else if (_fastFPSAverage.getAverage() > _avatarLODIncreaseFPS) { - // let the detail level creep slowly upwards - const float DISTANCE_DECREASE_RATE = 0.05f; - _avatarLODDistanceMultiplier = qMax(MINIMUM_AVATAR_LOD_DISTANCE_MULTIPLIER, - _avatarLODDistanceMultiplier - DISTANCE_DECREASE_RATE); - } - } - - bool changed = false; - quint64 elapsed = now - _lastAdjust; - - if (elapsed > ADJUST_LOD_DOWN_DELAY && _fpsAverage.getAverage() < ADJUST_LOD_DOWN_FPS - && _octreeSizeScale > ADJUST_LOD_MIN_SIZE_SCALE) { - - _octreeSizeScale *= ADJUST_LOD_DOWN_BY; - - if (_octreeSizeScale < ADJUST_LOD_MIN_SIZE_SCALE) { - _octreeSizeScale = ADJUST_LOD_MIN_SIZE_SCALE; - } - changed = true; - _lastAdjust = now; - qDebug() << "adjusting LOD down... average fps for last approximately 5 seconds=" << _fpsAverage.getAverage() - << "_octreeSizeScale=" << _octreeSizeScale; - } - - if (elapsed > ADJUST_LOD_UP_DELAY && _fpsAverage.getAverage() > ADJUST_LOD_UP_FPS - && _octreeSizeScale < ADJUST_LOD_MAX_SIZE_SCALE) { - _octreeSizeScale *= ADJUST_LOD_UP_BY; - if (_octreeSizeScale > ADJUST_LOD_MAX_SIZE_SCALE) { - _octreeSizeScale = ADJUST_LOD_MAX_SIZE_SCALE; - } - changed = true; - _lastAdjust = now; - qDebug() << "adjusting LOD up... average fps for last approximately 5 seconds=" << _fpsAverage.getAverage() - << "_octreeSizeScale=" << _octreeSizeScale; - } - - if (changed) { - _shouldRenderTableNeedsRebuilding = true; - if (_lodToolsDialog) { - _lodToolsDialog->reloadSliders(); - } - } -} - -void Menu::resetLODAdjust() { - _fpsAverage.reset(); - _fastFPSAverage.reset(); - _lastAvatarDetailDrop = _lastAdjust = usecTimestampNow(); -} - -void Menu::setOctreeSizeScale(float sizeScale) { - _octreeSizeScale = sizeScale; - _shouldRenderTableNeedsRebuilding = true; - bumpSettings(); -} - -void Menu::setBoundaryLevelAdjust(int boundaryLevelAdjust) { - _boundaryLevelAdjust = boundaryLevelAdjust; - _shouldRenderTableNeedsRebuilding = true; - bumpSettings(); -} - // TODO: This is essentially the same logic used to render octree cells, but since models are more detailed then octree cells // I've added a voxelToModelRatio that adjusts how much closer to a model you have to be to see it. bool Menu::shouldRenderMesh(float largestDimension, float distanceToCamera) { diff --git a/interface/src/Menu.h b/interface/src/Menu.h index bafcf401c9..0b12bb5066 100644 --- a/interface/src/Menu.h +++ b/interface/src/Menu.h @@ -21,7 +21,6 @@ #include #include -#include #if defined(Q_OS_MAC) || defined(Q_OS_WIN) #include "SpeechRecognizer.h" @@ -29,32 +28,11 @@ #include "devices/Faceshift.h" #include "devices/SixenseManager.h" +#include "LODManager.h" #include "ui/ChatWindow.h" #include "ui/JSConsole.h" #include "ui/ScriptEditorWindow.h" -// Make an LOD handler class and move everything overthere -const float ADJUST_LOD_DOWN_FPS = 40.0; -const float ADJUST_LOD_UP_FPS = 55.0; -const float DEFAULT_ADJUST_AVATAR_LOD_DOWN_FPS = 30.0f; - -const quint64 ADJUST_LOD_DOWN_DELAY = 1000 * 1000 * 5; -const quint64 ADJUST_LOD_UP_DELAY = ADJUST_LOD_DOWN_DELAY * 2; - -const float ADJUST_LOD_DOWN_BY = 0.9f; -const float ADJUST_LOD_UP_BY = 1.1f; - -const float ADJUST_LOD_MIN_SIZE_SCALE = DEFAULT_OCTREE_SIZE_SCALE * 0.25f; -const float ADJUST_LOD_MAX_SIZE_SCALE = DEFAULT_OCTREE_SIZE_SCALE; - -const float MINIMUM_AVATAR_LOD_DISTANCE_MULTIPLIER = 0.1f; -const float MAXIMUM_AVATAR_LOD_DISTANCE_MULTIPLIER = 15.0f; -const float DEFAULT_AVATAR_LOD_DISTANCE_MULTIPLIER = 1.0f; - -const int ONE_SECOND_OF_FRAMES = 60; -const int FIVE_SECONDS_OF_FRAMES = 5 * ONE_SECOND_OF_FRAMES; -////////////////////////////////////////////////////////// - const float DEFAULT_OCULUS_UI_ANGULAR_SIZE = 72.0f; const QString SETTINGS_ADDRESS_KEY = "address"; @@ -187,23 +165,6 @@ public: bool getShadowsEnabled() const; - // User Tweakable LOD Items - QString getLODFeedbackText(); - void autoAdjustLOD(float currentFPS); - void resetLODAdjust(); - void setOctreeSizeScale(float sizeScale); - float getOctreeSizeScale() const { return _octreeSizeScale; } - void setAutomaticAvatarLOD(bool automaticAvatarLOD) { _automaticAvatarLOD = automaticAvatarLOD; bumpSettings(); } - bool getAutomaticAvatarLOD() const { return _automaticAvatarLOD; } - void setAvatarLODDecreaseFPS(float avatarLODDecreaseFPS) { _avatarLODDecreaseFPS = avatarLODDecreaseFPS; bumpSettings(); } - float getAvatarLODDecreaseFPS() const { return _avatarLODDecreaseFPS; } - void setAvatarLODIncreaseFPS(float avatarLODIncreaseFPS) { _avatarLODIncreaseFPS = avatarLODIncreaseFPS; bumpSettings(); } - float getAvatarLODIncreaseFPS() const { return _avatarLODIncreaseFPS; } - void setAvatarLODDistanceMultiplier(float multiplier) { _avatarLODDistanceMultiplier = multiplier; bumpSettings(); } - float getAvatarLODDistanceMultiplier() const { return _avatarLODDistanceMultiplier; } - void setBoundaryLevelAdjust(int boundaryLevelAdjust); - int getBoundaryLevelAdjust() const { return _boundaryLevelAdjust; } - bool shouldRenderMesh(float largestDimension, float distanceToCamera); #if defined(Q_OS_MAC) || defined(Q_OS_WIN) @@ -271,26 +232,13 @@ private: #if defined(Q_OS_MAC) || defined(Q_OS_WIN) SpeechRecognizer _speechRecognizer; #endif - float _octreeSizeScale = DEFAULT_OCTREE_SIZE_SCALE; float _oculusUIAngularSize = DEFAULT_OCULUS_UI_ANGULAR_SIZE; float _sixenseReticleMoveSpeed = DEFAULT_SIXENSE_RETICLE_MOVE_SPEED; bool _invertSixenseButtons = DEFAULT_INVERT_SIXENSE_MOUSE_BUTTONS; bool _hasLoginDialogDisplayed = false; - bool _automaticAvatarLOD = true; - float _avatarLODDecreaseFPS = DEFAULT_ADJUST_AVATAR_LOD_DOWN_FPS; - float _avatarLODIncreaseFPS = ADJUST_LOD_UP_FPS; - float _avatarLODDistanceMultiplier = DEFAULT_AVATAR_LOD_DISTANCE_MULTIPLIER; - - int _boundaryLevelAdjust = 0; int _maxOctreePacketsPerSecond = DEFAULT_MAX_OCTREE_PPS; - quint64 _lastAdjust; - quint64 _lastAvatarDetailDrop; - - SimpleMovingAverage _fpsAverage = FIVE_SECONDS_OF_FRAMES; - SimpleMovingAverage _fastFPSAverage = ONE_SECOND_OF_FRAMES; - QPointer _addressBarDialog; QPointer _animationsDialog; QPointer _attachmentsDialog; diff --git a/interface/src/avatar/Avatar.cpp b/interface/src/avatar/Avatar.cpp index 7ad81d7bf5..b395fcadae 100644 --- a/interface/src/avatar/Avatar.cpp +++ b/interface/src/avatar/Avatar.cpp @@ -114,8 +114,8 @@ glm::quat Avatar::getWorldAlignedOrientation () const { } float Avatar::getLODDistance() const { - return Menu::getInstance()->getAvatarLODDistanceMultiplier() * - glm::distance(Application::getInstance()->getCamera()->getPosition(), _position) / _scale; + return DependencyManager::get()->getAvatarLODDistanceMultiplier() * + glm::distance(Application::getInstance()->getCamera()->getPosition(), _position) / _scale; } void Avatar::simulate(float deltaTime) { diff --git a/interface/src/ui/LodToolsDialog.cpp b/interface/src/ui/LodToolsDialog.cpp index 8ff9eadc51..5d079e840f 100644 --- a/interface/src/ui/LodToolsDialog.cpp +++ b/interface/src/ui/LodToolsDialog.cpp @@ -28,6 +28,7 @@ LodToolsDialog::LodToolsDialog(QWidget* parent) : QDialog(parent, Qt::Window | Qt::WindowCloseButtonHint | Qt::WindowStaysOnTopHint) { this->setWindowTitle("LOD Tools"); + auto lodManager = DependencyManager::get(); // Create layouter QFormLayout* form = new QFormLayout(this); @@ -45,7 +46,7 @@ LodToolsDialog::LodToolsDialog(QWidget* parent) : _lodSize->setTickPosition(QSlider::TicksBelow); _lodSize->setFixedWidth(SLIDER_WIDTH); _lodSize->setPageStep(PAGE_STEP_LOD_SIZE); - int sliderValue = Menu::getInstance()->getOctreeSizeScale() / TREE_SCALE; + int sliderValue = lodManager->getOctreeSizeScale() / TREE_SCALE; _lodSize->setValue(sliderValue); form->addRow("LOD Size Scale:", _lodSize); connect(_lodSize,SIGNAL(valueChanged(int)),this,SLOT(sizeScaleValueChanged(int))); @@ -60,7 +61,7 @@ LodToolsDialog::LodToolsDialog(QWidget* parent) : _boundaryLevelAdjust->setTickInterval(STEP_ADJUST); _boundaryLevelAdjust->setTickPosition(QSlider::TicksBelow); _boundaryLevelAdjust->setFixedWidth(SLIDER_WIDTH); - sliderValue = Menu::getInstance()->getBoundaryLevelAdjust(); + sliderValue = lodManager->getBoundaryLevelAdjust(); _boundaryLevelAdjust->setValue(sliderValue); form->addRow("Boundary Level Adjust:", _boundaryLevelAdjust); connect(_boundaryLevelAdjust,SIGNAL(valueChanged(int)),this,SLOT(boundaryLevelValueChanged(int))); @@ -71,22 +72,22 @@ LodToolsDialog::LodToolsDialog(QWidget* parent) : const unsigned redish = 0xfff00000; palette.setColor(QPalette::WindowText, QColor::fromRgb(redish)); _feedback->setPalette(palette); - _feedback->setText(Menu::getInstance()->getLODFeedbackText()); + _feedback->setText(lodManager->getLODFeedbackText()); const int FEEDBACK_WIDTH = 350; _feedback->setFixedWidth(FEEDBACK_WIDTH); form->addRow("You can see... ", _feedback); - + form->addRow("Automatic Avatar LOD Adjustment:", _automaticAvatarLOD = new QCheckBox(this)); - _automaticAvatarLOD->setChecked(Menu::getInstance()->getAutomaticAvatarLOD()); + _automaticAvatarLOD->setChecked(lodManager->getAutomaticAvatarLOD()); connect(_automaticAvatarLOD, SIGNAL(toggled(bool)), SLOT(updateAvatarLODControls())); form->addRow("Decrease Avatar LOD Below FPS:", _avatarLODDecreaseFPS = new QDoubleSpinBox(this)); - _avatarLODDecreaseFPS->setValue(Menu::getInstance()->getAvatarLODDecreaseFPS()); + _avatarLODDecreaseFPS->setValue(lodManager->getAvatarLODDecreaseFPS()); _avatarLODDecreaseFPS->setDecimals(0); connect(_avatarLODDecreaseFPS, SIGNAL(valueChanged(double)), SLOT(updateAvatarLODValues())); form->addRow("Increase Avatar LOD Above FPS:", _avatarLODIncreaseFPS = new QDoubleSpinBox(this)); - _avatarLODIncreaseFPS->setValue(Menu::getInstance()->getAvatarLODIncreaseFPS()); + _avatarLODIncreaseFPS->setValue(lodManager->getAvatarLODIncreaseFPS()); _avatarLODIncreaseFPS->setDecimals(0); connect(_avatarLODIncreaseFPS, SIGNAL(valueChanged(double)), SLOT(updateAvatarLODValues())); @@ -94,7 +95,7 @@ LodToolsDialog::LodToolsDialog(QWidget* parent) : _avatarLOD->setDecimals(3); _avatarLOD->setRange(1.0 / MAXIMUM_AVATAR_LOD_DISTANCE_MULTIPLIER, 1.0 / MINIMUM_AVATAR_LOD_DISTANCE_MULTIPLIER); _avatarLOD->setSingleStep(0.001); - _avatarLOD->setValue(1.0 / Menu::getInstance()->getAvatarLODDistanceMultiplier()); + _avatarLOD->setValue(1.0 / lodManager->getAvatarLODDistanceMultiplier()); connect(_avatarLOD, SIGNAL(valueChanged(double)), SLOT(updateAvatarLODValues())); // Add a button to reset @@ -108,15 +109,17 @@ LodToolsDialog::LodToolsDialog(QWidget* parent) : } void LodToolsDialog::reloadSliders() { - _lodSize->setValue(Menu::getInstance()->getOctreeSizeScale() / TREE_SCALE); - _boundaryLevelAdjust->setValue(Menu::getInstance()->getBoundaryLevelAdjust()); - _feedback->setText(Menu::getInstance()->getLODFeedbackText()); + auto lodManager = DependencyManager::get(); + _lodSize->setValue(lodManager->getOctreeSizeScale() / TREE_SCALE); + _boundaryLevelAdjust->setValue(lodManager->getBoundaryLevelAdjust()); + _feedback->setText(lodManager->getLODFeedbackText()); } void LodToolsDialog::updateAvatarLODControls() { QFormLayout* form = static_cast(layout()); - Menu::getInstance()->setAutomaticAvatarLOD(_automaticAvatarLOD->isChecked()); + auto lodManager = DependencyManager::get(); + lodManager->setAutomaticAvatarLOD(_automaticAvatarLOD->isChecked()); _avatarLODDecreaseFPS->setVisible(_automaticAvatarLOD->isChecked()); form->labelForField(_avatarLODDecreaseFPS)->setVisible(_automaticAvatarLOD->isChecked()); @@ -128,7 +131,7 @@ void LodToolsDialog::updateAvatarLODControls() { form->labelForField(_avatarLOD)->setVisible(!_automaticAvatarLOD->isChecked()); if (!_automaticAvatarLOD->isChecked()) { - _avatarLOD->setValue(1.0 / Menu::getInstance()->getAvatarLODDistanceMultiplier()); + _avatarLOD->setValue(1.0 / lodManager->getAvatarLODDistanceMultiplier()); } if (isVisible()) { @@ -137,25 +140,28 @@ void LodToolsDialog::updateAvatarLODControls() { } void LodToolsDialog::updateAvatarLODValues() { + auto lodManager = DependencyManager::get(); if (_automaticAvatarLOD->isChecked()) { - Menu::getInstance()->setAvatarLODDecreaseFPS(_avatarLODDecreaseFPS->value()); - Menu::getInstance()->setAvatarLODIncreaseFPS(_avatarLODIncreaseFPS->value()); + lodManager->setAvatarLODDecreaseFPS(_avatarLODDecreaseFPS->value()); + lodManager->setAvatarLODIncreaseFPS(_avatarLODIncreaseFPS->value()); } else { - Menu::getInstance()->setAvatarLODDistanceMultiplier(1.0 / _avatarLOD->value()); + lodManager->setAvatarLODDistanceMultiplier(1.0 / _avatarLOD->value()); } } void LodToolsDialog::sizeScaleValueChanged(int value) { + auto lodManager = DependencyManager::get(); float realValue = value * TREE_SCALE; - Menu::getInstance()->setOctreeSizeScale(realValue); + lodManager->setOctreeSizeScale(realValue); - _feedback->setText(Menu::getInstance()->getLODFeedbackText()); + _feedback->setText(lodManager->getLODFeedbackText()); } void LodToolsDialog::boundaryLevelValueChanged(int value) { - Menu::getInstance()->setBoundaryLevelAdjust(value); - _feedback->setText(Menu::getInstance()->getLODFeedbackText()); + auto lodManager = DependencyManager::get(); + lodManager->setBoundaryLevelAdjust(value); + _feedback->setText(lodManager->getLODFeedbackText()); } void LodToolsDialog::resetClicked(bool checked) { diff --git a/interface/src/ui/Stats.cpp b/interface/src/ui/Stats.cpp index 486a4621af..182cdce0cc 100644 --- a/interface/src/ui/Stats.cpp +++ b/interface/src/ui/Stats.cpp @@ -623,7 +623,7 @@ void Stats::display( // LOD Details if (_expanded) { octreeStats.str(""); - QString displayLODDetails = Menu::getInstance()->getLODFeedbackText(); + QString displayLODDetails = DependencyManager::get()->getLODFeedbackText(); octreeStats << "LOD: You can see " << qPrintable(displayLODDetails.trimmed()); verticalOffset += STATS_PELS_PER_LINE; drawText(horizontalOffset, verticalOffset, scale, rotation, font, (char*)octreeStats.str().c_str(), color); diff --git a/interface/src/ui/overlays/Overlays.cpp b/interface/src/ui/overlays/Overlays.cpp index 8f9f54c591..0c2279e22b 100644 --- a/interface/src/ui/overlays/Overlays.cpp +++ b/interface/src/ui/overlays/Overlays.cpp @@ -83,10 +83,13 @@ void Overlays::update(float deltatime) { void Overlays::renderHUD() { QReadLocker lock(&_lock); - + + auto lodManager = DependencyManager::get(); RenderArgs args = { NULL, Application::getInstance()->getViewFrustum(), - Menu::getInstance()->getOctreeSizeScale(), Menu::getInstance()->getBoundaryLevelAdjust(), - RenderArgs::DEFAULT_RENDER_MODE, RenderArgs::MONO, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + lodManager->getOctreeSizeScale(), + lodManager->getBoundaryLevelAdjust(), + RenderArgs::DEFAULT_RENDER_MODE, RenderArgs::MONO, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; foreach(Overlay* thisOverlay, _overlaysHUD) { if (thisOverlay->is3D()) { @@ -116,9 +119,12 @@ void Overlays::renderWorld(bool drawFront, RenderArgs::RenderMode renderMode, Re glm::vec3 axis(0.0f, 1.0f, 0.0f); float myAvatarScale = 1.0f; + auto lodManager = DependencyManager::get(); RenderArgs args = { NULL, Application::getInstance()->getViewFrustum(), - Menu::getInstance()->getOctreeSizeScale(), Menu::getInstance()->getBoundaryLevelAdjust(), - renderMode, renderSide, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + lodManager->getOctreeSizeScale(), + lodManager->getBoundaryLevelAdjust(), + renderMode, renderSide, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; foreach(Overlay* thisOverlay, _overlaysWorld) { From 3fbc8c5d449ae16f7380e35f88c426fee4e34d68 Mon Sep 17 00:00:00 2001 From: Atlante45 Date: Sat, 17 Jan 2015 17:56:33 -0800 Subject: [PATCH 005/167] Moved Menu::shouldRenderMesh() to LODManager --- interface/src/Application.cpp | 2 +- interface/src/LODManager.cpp | 38 +++++++++++++++++++++++++ interface/src/LODManager.h | 4 ++- interface/src/Menu.cpp | 39 -------------------------- interface/src/Menu.h | 3 -- interface/src/avatar/Avatar.cpp | 1 + interface/src/ui/LodToolsDialog.cpp | 11 ++++---- interface/src/ui/Stats.cpp | 1 + interface/src/ui/overlays/Overlays.cpp | 6 ++-- 9 files changed, 54 insertions(+), 51 deletions(-) diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index efbf429ab4..1c1a57f3a7 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -2648,7 +2648,7 @@ void Application::setupWorldLight() { } bool Application::shouldRenderMesh(float largestDimension, float distanceToCamera) { - return Menu::getInstance()->shouldRenderMesh(largestDimension, distanceToCamera); + return DependencyManager::get()->shouldRenderMesh(largestDimension, distanceToCamera); } float Application::getSizeScale() const { diff --git a/interface/src/LODManager.cpp b/interface/src/LODManager.cpp index 837020dc36..9f33677cff 100644 --- a/interface/src/LODManager.cpp +++ b/interface/src/LODManager.cpp @@ -138,6 +138,44 @@ void LODManager::setBoundaryLevelAdjust(int boundaryLevelAdjust) { _shouldRenderTableNeedsRebuilding = true; } +// TODO: This is essentially the same logic used to render octree cells, but since models are more detailed then octree cells +// I've added a voxelToModelRatio that adjusts how much closer to a model you have to be to see it. +bool LODManager::shouldRenderMesh(float largestDimension, float distanceToCamera) { + const float octreeToMeshRatio = 4.0f; // must be this many times closer to a mesh than a voxel to see it. + float octreeSizeScale = getOctreeSizeScale(); + int boundaryLevelAdjust = getBoundaryLevelAdjust(); + float maxScale = (float)TREE_SCALE; + float visibleDistanceAtMaxScale = boundaryDistanceForRenderLevel(boundaryLevelAdjust, octreeSizeScale) / octreeToMeshRatio; + + if (_shouldRenderTableNeedsRebuilding) { + _shouldRenderTable.clear(); + + float SMALLEST_SCALE_IN_TABLE = 0.001f; // 1mm is plenty small + float scale = maxScale; + float visibleDistanceAtScale = visibleDistanceAtMaxScale; + + while (scale > SMALLEST_SCALE_IN_TABLE) { + scale /= 2.0f; + visibleDistanceAtScale /= 2.0f; + _shouldRenderTable[scale] = visibleDistanceAtScale; + } + _shouldRenderTableNeedsRebuilding = false; + } + + float closestScale = maxScale; + float visibleDistanceAtClosestScale = visibleDistanceAtMaxScale; + QMap::const_iterator lowerBound = _shouldRenderTable.lowerBound(largestDimension); + if (lowerBound != _shouldRenderTable.constEnd()) { + closestScale = lowerBound.key(); + visibleDistanceAtClosestScale = lowerBound.value(); + } + + if (closestScale < largestDimension) { + visibleDistanceAtClosestScale *= 2.0f; + } + + return (distanceToCamera <= visibleDistanceAtClosestScale); +} void LODManager::loadSettings(QSettings* settings) { bool lockedSettings = false; diff --git a/interface/src/LODManager.h b/interface/src/LODManager.h index 1b02a931ed..364f7f1192 100644 --- a/interface/src/LODManager.h +++ b/interface/src/LODManager.h @@ -70,8 +70,10 @@ public: void autoAdjustLOD(float currentFPS); void resetLODAdjust(); + bool shouldRenderMesh(float largestDimension, float distanceToCamera); + private: - LODManager(); + LODManager() {} void loadSettings(QSettings* settings); void saveSettings(QSettings* settings); diff --git a/interface/src/Menu.cpp b/interface/src/Menu.cpp index 7f8e1b82ae..cf6951a9fc 100644 --- a/interface/src/Menu.cpp +++ b/interface/src/Menu.cpp @@ -1388,45 +1388,6 @@ void Menu::octreeStatsDetails() { _octreeStatsDialog->raise(); } -// TODO: This is essentially the same logic used to render octree cells, but since models are more detailed then octree cells -// I've added a voxelToModelRatio that adjusts how much closer to a model you have to be to see it. -bool Menu::shouldRenderMesh(float largestDimension, float distanceToCamera) { - const float octreeToMeshRatio = 4.0f; // must be this many times closer to a mesh than a voxel to see it. - float octreeSizeScale = getOctreeSizeScale(); - int boundaryLevelAdjust = getBoundaryLevelAdjust(); - float maxScale = (float)TREE_SCALE; - float visibleDistanceAtMaxScale = boundaryDistanceForRenderLevel(boundaryLevelAdjust, octreeSizeScale) / octreeToMeshRatio; - - if (_shouldRenderTableNeedsRebuilding) { - _shouldRenderTable.clear(); - - float SMALLEST_SCALE_IN_TABLE = 0.001f; // 1mm is plenty small - float scale = maxScale; - float visibleDistanceAtScale = visibleDistanceAtMaxScale; - - while (scale > SMALLEST_SCALE_IN_TABLE) { - scale /= 2.0f; - visibleDistanceAtScale /= 2.0f; - _shouldRenderTable[scale] = visibleDistanceAtScale; - } - _shouldRenderTableNeedsRebuilding = false; - } - - float closestScale = maxScale; - float visibleDistanceAtClosestScale = visibleDistanceAtMaxScale; - QMap::const_iterator lowerBound = _shouldRenderTable.lowerBound(largestDimension); - if (lowerBound != _shouldRenderTable.constEnd()) { - closestScale = lowerBound.key(); - visibleDistanceAtClosestScale = lowerBound.value(); - } - - if (closestScale < largestDimension) { - visibleDistanceAtClosestScale *= 2.0f; - } - - return (distanceToCamera <= visibleDistanceAtClosestScale); -} - void Menu::cachesSizeDialog() { qDebug() << "Caches size:" << _cachesSizeDialog.isNull(); if (!_cachesSizeDialog) { diff --git a/interface/src/Menu.h b/interface/src/Menu.h index 0b12bb5066..9d2861ac0d 100644 --- a/interface/src/Menu.h +++ b/interface/src/Menu.h @@ -28,7 +28,6 @@ #include "devices/Faceshift.h" #include "devices/SixenseManager.h" -#include "LODManager.h" #include "ui/ChatWindow.h" #include "ui/JSConsole.h" #include "ui/ScriptEditorWindow.h" @@ -165,8 +164,6 @@ public: bool getShadowsEnabled() const; - bool shouldRenderMesh(float largestDimension, float distanceToCamera); - #if defined(Q_OS_MAC) || defined(Q_OS_WIN) SpeechRecognizer* getSpeechRecognizer() { return &_speechRecognizer; } #endif diff --git a/interface/src/avatar/Avatar.cpp b/interface/src/avatar/Avatar.cpp index b395fcadae..1f9796aa3f 100644 --- a/interface/src/avatar/Avatar.cpp +++ b/interface/src/avatar/Avatar.cpp @@ -25,6 +25,7 @@ #include #include #include +#include #include #include #include diff --git a/interface/src/ui/LodToolsDialog.cpp b/interface/src/ui/LodToolsDialog.cpp index 5d079e840f..1b149bf903 100644 --- a/interface/src/ui/LodToolsDialog.cpp +++ b/interface/src/ui/LodToolsDialog.cpp @@ -9,17 +9,18 @@ // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // -#include -#include - -#include #include #include +#include #include -#include +#include +#include #include +#include #include +#include + #include "Menu.h" #include "ui/LodToolsDialog.h" diff --git a/interface/src/ui/Stats.cpp b/interface/src/ui/Stats.cpp index 182cdce0cc..9beedd4ac3 100644 --- a/interface/src/ui/Stats.cpp +++ b/interface/src/ui/Stats.cpp @@ -18,6 +18,7 @@ #include #include +#include #include #include "Stats.h" diff --git a/interface/src/ui/overlays/Overlays.cpp b/interface/src/ui/overlays/Overlays.cpp index 0c2279e22b..9e953344d6 100644 --- a/interface/src/ui/overlays/Overlays.cpp +++ b/interface/src/ui/overlays/Overlays.cpp @@ -8,12 +8,14 @@ // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // +#include + #include #include + #include #include -#include -#include +#include #include "BillboardOverlay.h" #include "Circle3DOverlay.h" From 10ec36874fbe5e3986a672cbd4cd278ad24782ce Mon Sep 17 00:00:00 2001 From: Atlante45 Date: Sat, 17 Jan 2015 17:59:24 -0800 Subject: [PATCH 006/167] Remove Menu deprecated members --- interface/src/Menu.h | 3 --- 1 file changed, 3 deletions(-) diff --git a/interface/src/Menu.h b/interface/src/Menu.h index 9d2861ac0d..83eb38b8d4 100644 --- a/interface/src/Menu.h +++ b/interface/src/Menu.h @@ -257,9 +257,6 @@ private: QString _snapshotsLocation; QString _scriptsLocation; QByteArray _walletPrivateKey; - - bool _shouldRenderTableNeedsRebuilding = true; - QMap _shouldRenderTable; }; namespace MenuOption { From 8175b4bb4419811a298962d8a572a95d0394be97 Mon Sep 17 00:00:00 2001 From: Atlante45 Date: Sat, 17 Jan 2015 18:23:43 -0800 Subject: [PATCH 007/167] Remove unused getter/setter --- interface/src/LODManager.h | 8 -------- 1 file changed, 8 deletions(-) diff --git a/interface/src/LODManager.h b/interface/src/LODManager.h index 364f7f1192..76a0c11a20 100644 --- a/interface/src/LODManager.h +++ b/interface/src/LODManager.h @@ -43,12 +43,6 @@ class LODManager : public Dependency { SINGLETON_DEPENDENCY public: - // TODO: actually use them - bool shouldRenderTableNeedsRebuilding() const { return _shouldRenderTableNeedsRebuilding; } - void setShouldRenderTableNeedsRebuilding(bool shouldRenderTableNeedsRebuilding) { - _shouldRenderTableNeedsRebuilding = shouldRenderTableNeedsRebuilding; - } - // TODO: replace bumpSettings() void setAutomaticAvatarLOD(bool automaticAvatarLOD) { _automaticAvatarLOD = automaticAvatarLOD; } bool getAutomaticAvatarLOD() const { return _automaticAvatarLOD; } @@ -91,8 +85,6 @@ private: SimpleMovingAverage _fpsAverage = FIVE_SECONDS_OF_FRAMES; SimpleMovingAverage _fastFPSAverage = ONE_SECOND_OF_FRAMES; - - // TODO: actually use them bool _shouldRenderTableNeedsRebuilding = true; QMap _shouldRenderTable; }; From 229791a9f22fe52d4ee2c4a99a64a78488df638f Mon Sep 17 00:00:00 2001 From: Atlante45 Date: Sat, 17 Jan 2015 19:45:48 -0800 Subject: [PATCH 008/167] Move Oculus UI ratio to ApplicationOverlay --- interface/src/Menu.h | 5 ----- interface/src/ui/ApplicationOverlay.cpp | 2 +- interface/src/ui/ApplicationOverlay.h | 7 +++++++ interface/src/ui/PreferencesDialog.cpp | 4 ++-- 4 files changed, 10 insertions(+), 8 deletions(-) diff --git a/interface/src/Menu.h b/interface/src/Menu.h index 83eb38b8d4..7d1a47f787 100644 --- a/interface/src/Menu.h +++ b/interface/src/Menu.h @@ -32,8 +32,6 @@ #include "ui/JSConsole.h" #include "ui/ScriptEditorWindow.h" -const float DEFAULT_OCULUS_UI_ANGULAR_SIZE = 72.0f; - const QString SETTINGS_ADDRESS_KEY = "address"; class QSettings; @@ -140,8 +138,6 @@ public: void setFieldOfView(float fieldOfView) { _fieldOfView = fieldOfView; bumpSettings(); } float getRealWorldFieldOfView() const { return _realWorldFieldOfView; } void setRealWorldFieldOfView(float realWorldFieldOfView) { _realWorldFieldOfView = realWorldFieldOfView; bumpSettings(); } - float getOculusUIAngularSize() const { return _oculusUIAngularSize; } - void setOculusUIAngularSize(float oculusUIAngularSize) { _oculusUIAngularSize = oculusUIAngularSize; bumpSettings(); } float getSixenseReticleMoveSpeed() const { return _sixenseReticleMoveSpeed; } void setSixenseReticleMoveSpeed(float sixenseReticleMoveSpeed) { _sixenseReticleMoveSpeed = sixenseReticleMoveSpeed; bumpSettings(); } bool getInvertSixenseButtons() const { return _invertSixenseButtons; } @@ -229,7 +225,6 @@ private: #if defined(Q_OS_MAC) || defined(Q_OS_WIN) SpeechRecognizer _speechRecognizer; #endif - float _oculusUIAngularSize = DEFAULT_OCULUS_UI_ANGULAR_SIZE; float _sixenseReticleMoveSpeed = DEFAULT_SIXENSE_RETICLE_MOVE_SPEED; bool _invertSixenseButtons = DEFAULT_INVERT_SIXENSE_MOUSE_BUTTONS; bool _hasLoginDialogDisplayed = false; diff --git a/interface/src/ui/ApplicationOverlay.cpp b/interface/src/ui/ApplicationOverlay.cpp index 2c5cc5b267..6d00ad6912 100644 --- a/interface/src/ui/ApplicationOverlay.cpp +++ b/interface/src/ui/ApplicationOverlay.cpp @@ -164,7 +164,7 @@ void ApplicationOverlay::renderOverlay(bool renderToTexture) { Overlays& overlays = application->getOverlays(); auto glCanvas = DependencyManager::get(); - _textureFov = glm::radians(Menu::getInstance()->getOculusUIAngularSize()); + _textureFov = glm::radians(_oculusUIAngularSize); _textureAspectRatio = (float)glCanvas->getDeviceWidth() / (float)glCanvas->getDeviceHeight(); //Handle fading and deactivation/activation of UI diff --git a/interface/src/ui/ApplicationOverlay.h b/interface/src/ui/ApplicationOverlay.h index 33dcea67a3..68edbda691 100644 --- a/interface/src/ui/ApplicationOverlay.h +++ b/interface/src/ui/ApplicationOverlay.h @@ -20,6 +20,8 @@ const float MAGNIFY_WIDTH = 220.0f; const float MAGNIFY_HEIGHT = 100.0f; const float MAGNIFY_MULT = 2.0f; +const float DEFAULT_OCULUS_UI_ANGULAR_SIZE = 72.0f; + // Handles the drawing of the overlays to the screen class ApplicationOverlay { public: @@ -35,6 +37,9 @@ public: QPoint getPalmClickLocation(const PalmData *palm) const; bool calculateRayUICollisionPoint(const glm::vec3& position, const glm::vec3& direction, glm::vec3& result) const; + float getOculusUIAngularSize() const { return _oculusUIAngularSize; } + void setOculusUIAngularSize(float oculusUIAngularSize) { _oculusUIAngularSize = oculusUIAngularSize; } + // Converter from one frame of reference to another. // Frame of reference: // Screen: Position on the screen (x,y) @@ -80,6 +85,8 @@ private: VerticesIndices _vbo; }; + float _oculusUIAngularSize = DEFAULT_OCULUS_UI_ANGULAR_SIZE; + void renderReticle(glm::quat orientation, float alpha); void renderPointers();; void renderMagnifier(glm::vec2 magPos, float sizeMult, bool showBorder); diff --git a/interface/src/ui/PreferencesDialog.cpp b/interface/src/ui/PreferencesDialog.cpp index c0d87898d7..75000a457a 100644 --- a/interface/src/ui/PreferencesDialog.cpp +++ b/interface/src/ui/PreferencesDialog.cpp @@ -157,7 +157,7 @@ void PreferencesDialog::loadPreferences() { ui.maxOctreePPSSpin->setValue(menuInstance->getMaxOctreePacketsPerSecond()); - ui.oculusUIAngularSizeSpin->setValue(menuInstance->getOculusUIAngularSize()); + ui.oculusUIAngularSizeSpin->setValue(qApp->getApplicationOverlay().getOculusUIAngularSize()); ui.sixenseReticleMoveSpeedSpin->setValue(menuInstance->getSixenseReticleMoveSpeed()); @@ -238,7 +238,7 @@ void PreferencesDialog::savePreferences() { Menu::getInstance()->setMaxOctreePacketsPerSecond(ui.maxOctreePPSSpin->value()); - Menu::getInstance()->setOculusUIAngularSize(ui.oculusUIAngularSizeSpin->value()); + qApp->getApplicationOverlay().setOculusUIAngularSize(ui.oculusUIAngularSizeSpin->value()); Menu::getInstance()->setSixenseReticleMoveSpeed(ui.sixenseReticleMoveSpeedSpin->value()); From 2eff7867b59082ad592f3b6155806d4fd9dc2f37 Mon Sep 17 00:00:00 2001 From: Atlante45 Date: Sat, 17 Jan 2015 20:09:48 -0800 Subject: [PATCH 009/167] Remove LODManager::load/saveSettings() for now --- interface/src/LODManager.cpp | 40 ------------------------------------ interface/src/LODManager.h | 3 --- 2 files changed, 43 deletions(-) diff --git a/interface/src/LODManager.cpp b/interface/src/LODManager.cpp index 9f33677cff..0455f41402 100644 --- a/interface/src/LODManager.cpp +++ b/interface/src/LODManager.cpp @@ -177,43 +177,3 @@ bool LODManager::shouldRenderMesh(float largestDimension, float distanceToCamera return (distanceToCamera <= visibleDistanceAtClosestScale); } -void LODManager::loadSettings(QSettings* settings) { - bool lockedSettings = false; - if (!settings) { - settings = qApp->lockSettings(); - lockedSettings = true; - } - - _automaticAvatarLOD = settings->value("automaticAvatarLOD", true).toBool(); - _avatarLODDecreaseFPS = loadSetting(settings, "avatarLODDecreaseFPS", DEFAULT_ADJUST_AVATAR_LOD_DOWN_FPS); - _avatarLODIncreaseFPS = loadSetting(settings, "avatarLODIncreaseFPS", ADJUST_LOD_UP_FPS); - _avatarLODDistanceMultiplier = loadSetting(settings, "avatarLODDistanceMultiplier", - DEFAULT_AVATAR_LOD_DISTANCE_MULTIPLIER); - _octreeSizeScale = loadSetting(settings, "octreeSizeScale", DEFAULT_OCTREE_SIZE_SCALE); - _boundaryLevelAdjust = loadSetting(settings, "boundaryLevelAdjust", 0); - - if (lockedSettings) { - qApp->unlockSettings(); - } -} - -void LODManager::saveSettings(QSettings* settings) { - bool lockedSettings = false; - if (!settings) { - settings = qApp->lockSettings(); - lockedSettings = true; - } - - settings->setValue("automaticAvatarLOD", _automaticAvatarLOD); - settings->setValue("avatarLODDecreaseFPS", _avatarLODDecreaseFPS); - settings->setValue("avatarLODIncreaseFPS", _avatarLODIncreaseFPS); - settings->setValue("avatarLODDistanceMultiplier", _avatarLODDistanceMultiplier); - settings->setValue("octreeSizeScale", _octreeSizeScale); - settings->setValue("boundaryLevelAdjust", _boundaryLevelAdjust); - - if (lockedSettings) { - qApp->unlockSettings(); - } -} - - diff --git a/interface/src/LODManager.h b/interface/src/LODManager.h index 76a0c11a20..2dffbf72f5 100644 --- a/interface/src/LODManager.h +++ b/interface/src/LODManager.h @@ -69,9 +69,6 @@ public: private: LODManager() {} - void loadSettings(QSettings* settings); - void saveSettings(QSettings* settings); - bool _automaticAvatarLOD = true; float _avatarLODDecreaseFPS = DEFAULT_ADJUST_AVATAR_LOD_DOWN_FPS; float _avatarLODIncreaseFPS = ADJUST_LOD_UP_FPS; From 8f5f634308a4acca012e7ea6e35c54b2c3e087fe Mon Sep 17 00:00:00 2001 From: Atlante45 Date: Sat, 17 Jan 2015 21:22:02 -0800 Subject: [PATCH 010/167] Took audio settings out of Menu Hooked to actual settings in Audio class --- interface/src/Audio.h | 3 +- interface/src/Menu.cpp | 18 ---------- interface/src/Menu.h | 3 -- interface/src/ui/PreferencesDialog.cpp | 45 ++++++++++++------------ libraries/audio/src/InboundAudioStream.h | 12 +++++-- libraries/shared/src/MovingMinMaxAvg.h | 1 + 6 files changed, 34 insertions(+), 48 deletions(-) diff --git a/interface/src/Audio.h b/interface/src/Audio.h index abf322627b..34b36d41ac 100644 --- a/interface/src/Audio.h +++ b/interface/src/Audio.h @@ -96,14 +96,13 @@ public: }; const MixedProcessedAudioStream& getReceivedAudioStream() const { return _receivedAudioStream; } + MixedProcessedAudioStream& getReceivedAudioStream() { return _receivedAudioStream; } float getLastInputLoudness() const { return glm::max(_lastInputLoudness - _inputGate.getMeasuredFloor(), 0.0f); } float getTimeSinceLastClip() const { return _timeSinceLastClip; } float getAudioAverageInputLoudness() const { return _lastInputLoudness; } - void setReceivedAudioStreamSettings(const InboundAudioStream::Settings& settings) { _receivedAudioStream.setSettings(settings); } - int getDesiredJitterBufferFrames() const { return _receivedAudioStream.getDesiredJitterBufferFrames(); } bool isMuted() { return _muted; } diff --git a/interface/src/Menu.cpp b/interface/src/Menu.cpp index cf6951a9fc..62b607fdd1 100644 --- a/interface/src/Menu.cpp +++ b/interface/src/Menu.cpp @@ -582,15 +582,6 @@ void Menu::loadSettings(QSettings* settings) { lockedSettings = true; } - _receivedAudioStreamSettings._dynamicJitterBuffers = settings->value("dynamicJitterBuffers", DEFAULT_DYNAMIC_JITTER_BUFFERS).toBool(); - _receivedAudioStreamSettings._maxFramesOverDesired = settings->value("maxFramesOverDesired", DEFAULT_MAX_FRAMES_OVER_DESIRED).toInt(); - _receivedAudioStreamSettings._staticDesiredJitterBufferFrames = settings->value("staticDesiredJitterBufferFrames", DEFAULT_STATIC_DESIRED_JITTER_BUFFER_FRAMES).toInt(); - _receivedAudioStreamSettings._useStDevForJitterCalc = settings->value("useStDevForJitterCalc", DEFAULT_USE_STDEV_FOR_JITTER_CALC).toBool(); - _receivedAudioStreamSettings._windowStarveThreshold = settings->value("windowStarveThreshold", DEFAULT_WINDOW_STARVE_THRESHOLD).toInt(); - _receivedAudioStreamSettings._windowSecondsForDesiredCalcOnTooManyStarves = settings->value("windowSecondsForDesiredCalcOnTooManyStarves", DEFAULT_WINDOW_SECONDS_FOR_DESIRED_CALC_ON_TOO_MANY_STARVES).toInt(); - _receivedAudioStreamSettings._windowSecondsForDesiredReduction = settings->value("windowSecondsForDesiredReduction", DEFAULT_WINDOW_SECONDS_FOR_DESIRED_REDUCTION).toInt(); - _receivedAudioStreamSettings._repetitionWithFade = settings->value("repetitionWithFade", DEFAULT_REPETITION_WITH_FADE).toBool(); - auto audio = DependencyManager::get