From 31d198a7a9b8c1fdda0ab4ec8dbd3bf79f5346b1 Mon Sep 17 00:00:00 2001 From: Ryan Huffman Date: Thu, 21 Aug 2014 15:37:12 -0700 Subject: [PATCH 01/50] Remove custom behavior from chat window --- interface/src/ui/ChatWindow.cpp | 24 ++++++------- interface/src/ui/ChatWindow.h | 2 +- interface/ui/chatWindow.ui | 62 ++------------------------------- 3 files changed, 15 insertions(+), 73 deletions(-) diff --git a/interface/src/ui/ChatWindow.cpp b/interface/src/ui/ChatWindow.cpp index 8874f18dba..8c37cc6a70 100644 --- a/interface/src/ui/ChatWindow.cpp +++ b/interface/src/ui/ChatWindow.cpp @@ -30,16 +30,14 @@ const int NUM_MESSAGES_TO_TIME_STAMP = 20; -const float OPACITY_ACTIVE = 1.0f; -const float OPACITY_INACTIVE = 0.8f; - const QRegularExpression regexLinks("((?:(?:ftp)|(?:https?)|(?:hifi))://\\S+)"); const QRegularExpression regexHifiLinks("([#@]\\S+)"); const QString mentionSoundsPath("/mention-sounds/"); const QString mentionRegex("@(\\b%1\\b)"); ChatWindow::ChatWindow(QWidget* parent) : - FramelessDialog(parent, 0, POSITION_RIGHT), + QWidget(parent, Qt::Window | Qt::CustomizeWindowHint | Qt::WindowTitleHint | Qt::WindowMinMaxButtonsHint | + Qt::WindowCloseButtonHint), ui(new Ui::ChatWindow), numMessagesAfterLastTimeStamp(0), _mousePressed(false), @@ -82,7 +80,6 @@ ChatWindow::ChatWindow(QWidget* parent) : startTimerForTimeStamps(); } else { ui->numOnlineLabel->hide(); - ui->closeButton->hide(); ui->usersArea->hide(); ui->messagesScrollArea->hide(); ui->messagePlainTextEdit->hide(); @@ -113,17 +110,21 @@ void ChatWindow::keyPressEvent(QKeyEvent* event) { if (event->key() == Qt::Key_Escape) { Application::getInstance()->getWindow()->activateWindow(); } else { - FramelessDialog::keyPressEvent(event); + QWidget::keyPressEvent(event); } } void ChatWindow::showEvent(QShowEvent* event) { - FramelessDialog::showEvent(event); + QWidget::showEvent(event); if (!event->spontaneous()) { ui->messagePlainTextEdit->setFocus(); } + const QRect parentGeometry = parentWidget()->geometry(); + setGeometry(parentGeometry.topRight().x() - size().width(), parentGeometry.topRight().y(), + size().width(), parentWidget()->height()); + #ifdef HAVE_QXMPP const QXmppClient& xmppClient = XmppClient::getInstance().getXMPPClient(); if (xmppClient.isConnected()) { @@ -163,7 +164,7 @@ bool ChatWindow::eventFilter(QObject* sender, QEvent* event) { return true; } } - return FramelessDialog::eventFilter(sender, event); + return QWidget::eventFilter(sender, event); } void ChatWindow::addTimeStamp() { @@ -210,7 +211,6 @@ void ChatWindow::startTimerForTimeStamps() { void ChatWindow::connected() { ui->connectingToXMPPLabel->hide(); ui->numOnlineLabel->show(); - ui->closeButton->show(); ui->usersArea->show(); ui->messagesScrollArea->show(); ui->messagePlainTextEdit->show(); @@ -389,9 +389,7 @@ void ChatWindow::scrollToBottom() { bool ChatWindow::event(QEvent* event) { if (event->type() == QEvent::WindowActivate) { - setWindowOpacity(OPACITY_ACTIVE); - } else if (event->type() == QEvent::WindowDeactivate) { - setWindowOpacity(OPACITY_INACTIVE); + ui->messagePlainTextEdit->setFocus(); } - return FramelessDialog::event(event); + return QWidget::event(event); } diff --git a/interface/src/ui/ChatWindow.h b/interface/src/ui/ChatWindow.h index 652dcb5b08..afaacf34b4 100644 --- a/interface/src/ui/ChatWindow.h +++ b/interface/src/ui/ChatWindow.h @@ -38,7 +38,7 @@ const int AUTO_SCROLL_THRESHOLD = 20; class ChatWindow; } -class ChatWindow : public FramelessDialog { +class ChatWindow : public QWidget { Q_OBJECT public: diff --git a/interface/ui/chatWindow.ui b/interface/ui/chatWindow.ui index 46ccafd5f8..4120515b3d 100644 --- a/interface/ui/chatWindow.ui +++ b/interface/ui/chatWindow.ui @@ -1,7 +1,7 @@ ChatWindow - + 0 @@ -86,45 +86,6 @@ - - - - - 0 - 0 - - - - - 16 - 16 - - - - Qt::NoFocus - - - QPushButton { - background-color: rgba( 0, 0, 0, 0% ); - border: none; - image: url(../resources/images/close.svg) -} - - -QPushButton:pressed { - background-color: rgba( 0, 0, 0, 0% ); - border: none; - image: url(../resources/images/close_down.svg) -} - - - - - - true - - - @@ -283,7 +244,7 @@ border-color: palette(dark); border-style: solid; border-left-width: 1px; borde QAbstractScrollArea::AdjustToContents - true + true false @@ -308,22 +269,5 @@ border-color: palette(dark); border-style: solid; border-left-width: 1px; borde messagesScrollArea - - - closeButton - clicked() - ChatWindow - hide() - - - 390 - 42 - - - 550 - 42 - - - - + From 7e250bc89972dd22219a9074a8a06abfb524e9b5 Mon Sep 17 00:00:00 2001 From: stojce Date: Sat, 23 Aug 2014 00:16:25 +0200 Subject: [PATCH 02/50] Remove custom styling --- interface/resources/styles/preferences.qss | 23 - interface/src/Menu.cpp | 2 +- interface/src/ui/PreferencesDialog.cpp | 57 +- interface/src/ui/PreferencesDialog.h | 8 +- interface/ui/preferencesDialog.ui | 740 ++++++--------------- 5 files changed, 213 insertions(+), 617 deletions(-) delete mode 100644 interface/resources/styles/preferences.qss diff --git a/interface/resources/styles/preferences.qss b/interface/resources/styles/preferences.qss deleted file mode 100644 index 40e35c8e52..0000000000 --- a/interface/resources/styles/preferences.qss +++ /dev/null @@ -1,23 +0,0 @@ -QLabel#avatarLabel { - background-image: url(styles/avatar.svg); - background-repeat: no-repeat; - background-position: left center; -} - -QLabel#advancedTuningLabel { - background-image: url(styles/wrench.svg); - background-repeat: no-repeat; - background-position: left center; -} - -QPushButton#buttonBrowseHead, -QPushButton#buttonBrowseBody, -QPushButton#buttonBrowseLocation, -QPushButton#buttonBrowseScriptsLocation { - background-image: url(styles/search.svg); - background-repeat: no-repeat; - background-position: center center; - background-color: #fff; - border-radius: 0; - padding: 0; -} diff --git a/interface/src/Menu.cpp b/interface/src/Menu.cpp index 2e2c10458d..2f638592e9 100644 --- a/interface/src/Menu.cpp +++ b/interface/src/Menu.cpp @@ -1049,7 +1049,7 @@ void Menu::loginForCurrentDomain() { void Menu::editPreferences() { if (!_preferencesDialog) { - _preferencesDialog = new PreferencesDialog(Application::getInstance()->getWindow()); + _preferencesDialog = new PreferencesDialog(); _preferencesDialog->show(); } else { _preferencesDialog->close(); diff --git a/interface/src/ui/PreferencesDialog.cpp b/interface/src/ui/PreferencesDialog.cpp index 4ebd5f4c1a..f04d3b182c 100644 --- a/interface/src/ui/PreferencesDialog.cpp +++ b/interface/src/ui/PreferencesDialog.cpp @@ -16,16 +16,13 @@ #include "PreferencesDialog.h" #include "UserActivityLogger.h" -const int SCROLL_PANEL_BOTTOM_MARGIN = 30; -const int OK_BUTTON_RIGHT_MARGIN = 30; -const int BUTTONS_TOP_MARGIN = 24; - -PreferencesDialog::PreferencesDialog(QWidget* parent, Qt::WindowFlags flags) : FramelessDialog(parent, flags, POSITION_LEFT) { +PreferencesDialog::PreferencesDialog() : + QDialog(Application::getInstance()->getWindow()) { + + setAttribute(Qt::WA_DeleteOnClose); ui.setupUi(this); - setStyleSheetFile("styles/preferences.qss"); loadPreferences(); - connect(ui.closeButton, &QPushButton::clicked, this, &QDialog::close); connect(ui.buttonBrowseHead, &QPushButton::clicked, this, &PreferencesDialog::openHeadModelBrowser); connect(ui.buttonBrowseBody, &QPushButton::clicked, this, &PreferencesDialog::openBodyModelBrowser); @@ -49,78 +46,48 @@ void PreferencesDialog::setSkeletonUrl(QString modelUrl) { } void PreferencesDialog::openHeadModelBrowser() { - setWindowFlags(windowFlags() & ~Qt::WindowStaysOnTopHint); - show(); - ModelsBrowser modelBrowser(HEAD_MODEL); connect(&modelBrowser, &ModelsBrowser::selected, this, &PreferencesDialog::setHeadUrl); modelBrowser.browse(); - - setWindowFlags(windowFlags() | Qt::WindowStaysOnTopHint); - show(); } void PreferencesDialog::openBodyModelBrowser() { - setWindowFlags(windowFlags() & ~Qt::WindowStaysOnTopHint); - show(); - ModelsBrowser modelBrowser(SKELETON_MODEL); connect(&modelBrowser, &ModelsBrowser::selected, this, &PreferencesDialog::setSkeletonUrl); modelBrowser.browse(); - - setWindowFlags(windowFlags() | Qt::WindowStaysOnTopHint); - show(); } void PreferencesDialog::openSnapshotLocationBrowser() { - setWindowFlags(windowFlags() & ~Qt::WindowStaysOnTopHint); - show(); - QString dir = QFileDialog::getExistingDirectory(this, tr("Snapshots Location"), QStandardPaths::writableLocation(QStandardPaths::DesktopLocation), QFileDialog::ShowDirsOnly | QFileDialog::DontResolveSymlinks); if (!dir.isNull() && !dir.isEmpty()) { ui.snapshotLocationEdit->setText(dir); } - - setWindowFlags(windowFlags() | Qt::WindowStaysOnTopHint); - show(); } void PreferencesDialog::openScriptsLocationBrowser() { - setWindowFlags(windowFlags() & ~Qt::WindowStaysOnTopHint); - show(); - QString dir = QFileDialog::getExistingDirectory(this, tr("Scripts Location"), ui.scriptsLocationEdit->text(), QFileDialog::ShowDirsOnly | QFileDialog::DontResolveSymlinks); if (!dir.isNull() && !dir.isEmpty()) { ui.scriptsLocationEdit->setText(dir); } - - setWindowFlags(windowFlags() | Qt::WindowStaysOnTopHint); - show(); } void PreferencesDialog::resizeEvent(QResizeEvent *resizeEvent) { - + // keep buttons panel at the bottom - ui.buttonsPanel->setGeometry(0, size().height() - ui.buttonsPanel->height(), size().width(), ui.buttonsPanel->height()); - + ui.buttonsPanel->setGeometry(0, + size().height() - ui.buttonsPanel->height(), + size().width(), + ui.buttonsPanel->height()); + // set width and height of srcollarea to match bottom panel and width ui.scrollArea->setGeometry(ui.scrollArea->geometry().x(), ui.scrollArea->geometry().y(), size().width(), - size().height() - ui.buttonsPanel->height() - - SCROLL_PANEL_BOTTOM_MARGIN - ui.scrollArea->geometry().y()); - - // move Save button to left position - ui.defaultButton->move(size().width() - OK_BUTTON_RIGHT_MARGIN - ui.defaultButton->size().width(), BUTTONS_TOP_MARGIN); - - // move Save button to left position - ui.cancelButton->move(ui.defaultButton->pos().x() - ui.cancelButton->size().width(), BUTTONS_TOP_MARGIN); - - // move close button - ui.closeButton->move(size().width() - OK_BUTTON_RIGHT_MARGIN - ui.closeButton->size().width(), ui.closeButton->pos().y()); + size().height() - ui.buttonsPanel->height() - ui.scrollArea->geometry().y()); + } void PreferencesDialog::loadPreferences() { diff --git a/interface/src/ui/PreferencesDialog.h b/interface/src/ui/PreferencesDialog.h index 0573304eda..f2646080ef 100644 --- a/interface/src/ui/PreferencesDialog.h +++ b/interface/src/ui/PreferencesDialog.h @@ -12,20 +12,20 @@ #ifndef hifi_PreferencesDialog_h #define hifi_PreferencesDialog_h -#include "FramelessDialog.h" #include "ui_preferencesDialog.h" +#include #include -class PreferencesDialog : public FramelessDialog { +class PreferencesDialog : public QDialog { Q_OBJECT public: - PreferencesDialog(QWidget* parent = 0, Qt::WindowFlags flags = 0); + PreferencesDialog(); protected: void resizeEvent(QResizeEvent* resizeEvent); - + private: void loadPreferences(); void savePreferences(); diff --git a/interface/ui/preferencesDialog.ui b/interface/ui/preferencesDialog.ui index 566c24e4e3..937c9f0f04 100644 --- a/interface/ui/preferencesDialog.ui +++ b/interface/ui/preferencesDialog.ui @@ -1,13 +1,13 @@ PreferencesDialog - + 0 0 - 638 - 652 + 500 + 609 @@ -18,124 +18,23 @@ - 610 + 500 0 - - 0.950000000000000 + + + 500 + 16777215 + - - - - 0 - 560 - 611 - 97 - - - - - 0 - 0 - - - - - 0 - 97 - - - - - Arial - - - - background-color: #0e7077 - - - - - 310 - 24 - 91 - 50 - - - - - 0 - 0 - - - - - 0 - 50 - - - - - Arial - 18 - 50 - false - - - - - - - Cancel - - - - - - 400 - 24 - 188 - 50 - - - - - 0 - 0 - - - - - 188 - 49 - - - - - Arial - 18 - - - - background-color: #fff; -color: #0e7077 - - - Save all changes - - - true - - - 0 - 30 - 494 - 361 + 0 + 501 + 501 @@ -155,8 +54,8 @@ color: #0e7077 0 0 - 494 - 1456 + 501 + 1350 @@ -175,31 +74,6 @@ color: #0e7077 30 - - - - - 0 - 0 - - - - - Arial - 24 - - - - color: #0e7077 - - - Avatar - - - 25 - - - @@ -220,9 +94,6 @@ color: #0e7077 16 - - color: #0e7077 - <html><head/><body><p>Avatar display name <span style=" color:#909090;">(optional)</span></p></body></html> @@ -284,9 +155,6 @@ color: #0e7077 16 - - color: #0e7077 - Head @@ -311,11 +179,6 @@ color: #0e7077 0 - - - Arial - - @@ -336,34 +199,13 @@ color: #0e7077 - - - 0 - 0 - - - - - 30 - 30 - - - - - 30 - 30 - - - - - - + Browse - 30 - 30 + 0 + 0 @@ -390,9 +232,6 @@ color: #0e7077 16 - - color: #0e7077 - Body @@ -414,11 +253,6 @@ color: #0e7077 0 - - - Arial - - @@ -439,34 +273,13 @@ color: #0e7077 - - - 0 - 0 - - - - - 30 - 30 - - - - - 30 - 30 - - - - - - + Browse - 30 - 30 + 0 + 0 @@ -495,9 +308,6 @@ color: #0e7077 false - - color: #0e7077 - Snapshots @@ -526,9 +336,6 @@ color: #0e7077 16 - - color: #0e7077 - Place my Snapshots here: @@ -578,34 +385,13 @@ color: #0e7077 - - - 0 - 0 - - - - - 30 - 30 - - - - - 30 - 30 - - - - - - + Browse - 30 - 30 + 0 + 0 @@ -634,9 +420,6 @@ color: #0e7077 false - - color: #0e7077 - Scripts @@ -665,9 +448,6 @@ color: #0e7077 16 - - color: #0e7077 - Load scripts from this directory: @@ -717,34 +497,13 @@ color: #0e7077 - - - 0 - 0 - - - - - 30 - 30 - - - - - 30 - 30 - - - - - - + Browse - 30 - 30 + 0 + 0 @@ -756,22 +515,15 @@ color: #0e7077 - - - 0 - 0 - - - - background: #0e7077; -color: #fff; -border-radius: 4px; -font: bold 14px; -padding: 10px;margin-top:10px - Load Default Scripts + + + 0 + 0 + + @@ -810,9 +562,6 @@ padding: 10px;margin-top:10px 16 - - color: #0e7077 - Privacy @@ -890,7 +639,7 @@ padding: 10px;margin-top:10px - 32 + 22 0 @@ -905,8 +654,8 @@ padding: 10px;margin-top:10px - 32 - 32 + 0 + 0 @@ -950,7 +699,7 @@ padding: 10px;margin-top:10px - color: #0e7077 + Advanced Tuning @@ -959,7 +708,7 @@ padding: 10px;margin-top:10px Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter - 25 + 0 @@ -1016,9 +765,6 @@ padding: 10px;margin-top:10px false - - color: #0e7077 - Avatar @@ -1082,16 +828,10 @@ padding: 10px;margin-top:10px - - - 0 - 0 - - - 95 - 36 + 100 + 0 @@ -1178,8 +918,8 @@ padding: 10px;margin-top:10px - 95 - 36 + 100 + 0 @@ -1277,21 +1017,15 @@ padding: 10px;margin-top:10px - + 0 0 - 95 - 36 - - - - - 70 - 16777215 + 100 + 0 @@ -1358,16 +1092,10 @@ padding: 10px;margin-top:10px - - - 0 - 0 - - - 95 - 36 + 100 + 0 @@ -1448,7 +1176,7 @@ padding: 10px;margin-top:10px - 125 + 130 0 @@ -1519,22 +1247,10 @@ padding: 10px;margin-top:10px - - - 0 - 0 - - - 95 - 36 - - - - - 70 - 16777215 + 100 + 0 @@ -1556,98 +1272,84 @@ padding: 10px;margin-top:10px - - - 0 - - - 10 - - - 0 - - - 10 - - - - - - Arial - - - - color: rgb(51, 51, 51) - - - Max Frames Over Desired - - - 15 - - - maxFramesOverDesiredSpin - - - - - - - - Arial - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - - 0 - 0 - - - - - 95 - 36 - - - - - 70 - 16777215 - - - - - Arial - - - - 0 - - - 10000 - - - 1 - - - - - - - + + + 0 + + + 10 + + + 0 + + + 10 + + + + + + Arial + + + + color: rgb(51, 51, 51) + + + Max Frames Over Desired + + + 15 + + + maxFramesOverDesiredSpin + + + + + + + + Arial + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + 100 + 0 + + + + + Arial + + + + 0 + + + 10000 + + + 1 + + + + + @@ -1711,7 +1413,7 @@ padding: 10px;margin-top:10px - 125 + 130 0 @@ -1749,9 +1451,6 @@ padding: 10px;margin-top:10px false - - color: #0e7077 - Voxels @@ -1815,16 +1514,10 @@ padding: 10px;margin-top:10px - - - 0 - 0 - - - 125 - 36 + 100 + 0 @@ -1894,22 +1587,10 @@ padding: 10px;margin-top:10px - - - 0 - 0 - - - 95 - 36 - - - - - 70 - 16777215 + 100 + 0 @@ -1932,12 +1613,6 @@ padding: 10px;margin-top:10px - - - 0 - 0 - - 0 @@ -1952,9 +1627,6 @@ padding: 10px;margin-top:10px false - - color: #0e7077 - Oculus Rift @@ -2018,16 +1690,10 @@ padding: 10px;margin-top:10px - - - 0 - 0 - - - 125 - 36 + 100 + 0 @@ -2073,9 +1739,6 @@ padding: 10px;margin-top:10px false - - color: #0e7077 - Sixense Controllers @@ -2139,18 +1802,6 @@ padding: 10px;margin-top:10px - - - 0 - 0 - - - - - 32 - 0 - - 0 @@ -2162,8 +1813,8 @@ padding: 10px;margin-top:10px - 32 - 32 + 0 + 0 @@ -2225,16 +1876,10 @@ padding: 10px;margin-top:10px - - - 0 - 0 - - - 125 - 36 + 100 + 0 @@ -2258,64 +1903,71 @@ padding: 10px;margin-top:10px - + - 540 - 24 - 31 - 31 + 0 + 530 + 501 + 60 - - - PreferAntialias - + + QFrame::NoFrame - - + + QFrame::Raised + + + + 0 + 10 + 491 + 41 + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + Cancel + + + false + + + + + + + Save all changes + + + true + + + false + + + + + - - - FramelessDialog - 1 - - - - - cancelButton - clicked() - PreferencesDialog - close() - - - 966 - 557 - - - 528 - 0 - - - - - defaultButton - clicked() - PreferencesDialog - accept() - - - 1070 - 557 - - - 20 - 20 - - - - + From ce6a3128139807b1059107d95fb1966efcd149c3 Mon Sep 17 00:00:00 2001 From: stojce Date: Fri, 29 Aug 2014 19:50:39 +0200 Subject: [PATCH 03/50] Fix preferences dialog layout --- interface/src/ui/PreferencesDialog.cpp | 3 + interface/ui/preferencesDialog.ui | 1673 ++++++++++-------------- 2 files changed, 723 insertions(+), 953 deletions(-) diff --git a/interface/src/ui/PreferencesDialog.cpp b/interface/src/ui/PreferencesDialog.cpp index 5295dca752..a1f0f4e2d4 100644 --- a/interface/src/ui/PreferencesDialog.cpp +++ b/interface/src/ui/PreferencesDialog.cpp @@ -30,6 +30,9 @@ PreferencesDialog::PreferencesDialog() : connect(ui.buttonBrowseScriptsLocation, &QPushButton::clicked, this, &PreferencesDialog::openScriptsLocationBrowser); connect(ui.buttonReloadDefaultScripts, &QPushButton::clicked, Application::getInstance(), &Application::loadDefaultScripts); + // move dialog to left side + move(0, 0); + setWindowState(Qt::WindowMaximized); } void PreferencesDialog::accept() { diff --git a/interface/ui/preferencesDialog.ui b/interface/ui/preferencesDialog.ui index 11132ce1b1..2ec8579383 100644 --- a/interface/ui/preferencesDialog.ui +++ b/interface/ui/preferencesDialog.ui @@ -7,7 +7,7 @@ 0 0 500 - 609 + 554 @@ -34,9 +34,15 @@ 0 0 501 - 501 + 491 + + + 0 + 0 + + QFrame::NoFrame @@ -55,7 +61,7 @@ 0 0 501 - 1350 + 1435 @@ -74,6 +80,42 @@ 30 + + + + + 0 + 40 + + + + + 0 + 40 + + + + + Arial + 20 + 75 + true + + + + color:#29967e + + + Avatar basics + + + Qt::AlignBottom|Qt::AlignLeading|Qt::AlignLeft + + + 0 + + + @@ -146,7 +188,7 @@ 0 - 30 + 25 @@ -191,7 +233,7 @@ - 20 + 5 20 @@ -199,6 +241,12 @@ + + + Arial + 14 + + Browse @@ -223,7 +271,7 @@ 0 - 30 + 25 @@ -265,7 +313,7 @@ - 20 + 5 20 @@ -273,6 +321,12 @@ + + + Arial + 14 + + Browse @@ -297,17 +351,20 @@ 0 - 40 + 35 Arial 20 - 50 - false + 75 + true + + color:#29967e + Snapshots @@ -327,7 +384,7 @@ 0 - 30 + 25 @@ -377,7 +434,7 @@ - 20 + 5 20 @@ -385,6 +442,12 @@ + + + Arial + 14 + + Browse @@ -416,10 +479,13 @@ Arial 20 - 50 - false + 75 + true + + color:#29967e + Scripts @@ -439,7 +505,7 @@ 0 - 30 + 25 @@ -489,7 +555,7 @@ - 20 + 5 20 @@ -497,6 +563,12 @@ + + + Arial + 14 + + Browse @@ -511,35 +583,34 @@ - - - - - - Load Default Scripts - - - - 0 - 0 - - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - + + + + 0 + 0 + + + + + 150 + 0 + + + + + 300 + 0 + + + + + Arial + 14 + + + + Load Default Scripts + @@ -559,9 +630,14 @@ Arial - 16 + 20 + 75 + true + + color:#29967e + Privacy @@ -577,93 +653,41 @@ - - - 0 + + + + 0 + 0 + - - 10 + + + 32 + 32 + - - 0 + + + 0 + 0 + - - 10 + + + Arial + 13 + - - - - - Arial - - - - color: rgb(51, 51, 51) - - - Send data - - - 15 - - - maxVoxelsSpin - - - - - - - - Arial - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - - 0 - 0 - - - - - 22 - 0 - - - - - 0 - 0 - - - - - - - - 0 - 0 - - - - true - - - - + + Send data + + + + 0 + 0 + + + @@ -678,71 +702,6 @@ - - - - - 0 - 0 - - - - - 0 - 0 - - - - - Arial - 24 - - - - - - - Advanced Tuning - - - Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter - - - 0 - - - - - - - - 0 - 0 - - - - - Arial - 16 - - - - true - - - color: rgb(51, 51, 51); - - - It's not recomended that you play with these settings unless you've looked into exactly what they do. - - - false - - - true - - - @@ -761,12 +720,15 @@ Arial 20 - 50 - false + 75 + true + + color:#29967e + - Avatar + Avatar tuning Qt::AlignBottom|Qt::AlignLeading|Qt::AlignLeft @@ -779,13 +741,13 @@ 0 - 10 + 8 0 - 10 + 8 @@ -801,7 +763,7 @@ Real world vertical field of view (angular size of monitor) - 15 + 0 fieldOfViewSpin @@ -861,13 +823,13 @@ 0 - 10 + 8 0 - 10 + 8 @@ -883,7 +845,7 @@ Vertical field of view - 15 + 0 fieldOfViewSpin @@ -949,10 +911,10 @@ 0 - 10 + 8 - 10 + 8 @@ -986,7 +948,7 @@ Lean scale (applies to Faceshift users) - 15 + 0 leanScaleSpin @@ -1043,13 +1005,13 @@ 0 - 10 + 8 0 - 10 + 8 @@ -1065,7 +1027,7 @@ Avatar scale <span style=" color:#909090;">(default is 1.0)</span> - 15 + 0 avatarScaleSpin @@ -1119,13 +1081,13 @@ 0 - 10 + 8 0 - 10 + 8 @@ -1141,7 +1103,7 @@ Pupil dillation - 15 + 0 pupilDilationSlider @@ -1192,110 +1154,50 @@ - - - - - - 0 - - - 10 - - - 0 - - - 10 - - - - - - Arial - - - - color: rgb(51, 51, 51) - - - Enable Dynamic Jitter Buffers - - - 15 - - - dynamicJitterBuffersCheckBox - - - - - - - - Arial - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - - 0 - 0 - - - - - 32 - 0 - - - - - 0 - 0 - - - - - - - - 32 - 32 - - - - - - - - - + + + + + 0 + 0 + + + + + 0 + 40 + + + + + 0 + 40 + + + + + Arial + 13 + + + + Enable Dynamic Jitter Buffers + + + 0 - 10 + 8 0 - 10 + 8 @@ -1311,7 +1213,7 @@ Static Jitter Buffer Frames - 15 + 0 staticDesiredJitterBufferFramesSpin @@ -1374,13 +1276,13 @@ 0 - 10 + 8 0 - 10 + 8 @@ -1396,7 +1298,7 @@ Max Frames Over Desired - 15 + 0 maxFramesOverDesiredSpin @@ -1447,573 +1349,455 @@ - - - - 0 - - - 10 - - - 0 - - - 10 - - - - - - Arial - - - - color: rgb(51, 51, 51) - - - Max Frames Over Desired - - - 15 - - - maxFramesOverDesiredSpin - - - - - - - - Arial - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - - 0 - 0 - - - - - 95 - 36 - - - - - 70 - 16777215 - - - - - Arial - - - - 0 - - - 10000 - - - 1 - - - - - - - - - - - - 0 - - - 10 - - - 0 - - - 10 - - - - - - Arial - - - - color: rgb(51, 51, 51) - - - Use Stdev for Dynamic Jitter Calc - - - 15 - - - useStdevForJitterCalcCheckBox - - - - - - - - Arial - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - - 0 - 0 - - - - - 32 - 0 - - - - - 0 - 0 - - - - - - - - 32 - 32 - - - - - - - - - - - - - - 0 - - - 10 - - - 0 - - - 10 - - - - - - Arial - - - - color: rgb(51, 51, 51) - - - Window A Starve Threshold - - - 15 - - - windowStarveThresholdSpin - - - - - - - - Arial - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - - 0 - 0 - - - - - 95 - 36 - - - - - 70 - 16777215 - - - - - Arial - - - - 0 - - - 10000 - - - 1 - - - - - - - - - - - - 0 - - - 10 - - - 0 - - - 10 - - - - - - Arial - - - - color: rgb(51, 51, 51) - - - Window A (raise desired on N starves) Seconds - - - 15 - - - windowSecondsForDesiredCalcOnTooManyStarvesSpin - - - - - - - - Arial - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - - 0 - 0 - - - - - 95 - 36 - - - - - 70 - 16777215 - - - - - Arial - - - - 0 - - - 10000 - - - 1 - - - - - - - - - - - - 0 - - - 10 - - - 0 - - - 10 - - - - - - Arial - - - - color: rgb(51, 51, 51) - - - Window B (desired ceiling) Seconds - - - 15 - - - windowSecondsForDesiredReductionSpin - - - - - - - - Arial - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - - 0 - 0 - - - - - 95 - 36 - - - - - 70 - 16777215 - - - - - Arial - - - - 0 - - - 10000 - - - 1 - - - - - - - - - - - - 0 - - - 10 - - - 0 - - - 10 - - - - - - Arial - - - - color: rgb(51, 51, 51) - - - Repetition with Fade - - - 15 - - - repetitionWithFadeCheckBox - - - - - - - - Arial - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - - 0 - 0 - - - - - 32 - 0 - - - - - 0 - 0 - - - - - - - - 32 - 32 - - - - - - - + + + 0 + + + 8 + + + 0 + + + 8 + + + + + + Arial + + + + color: rgb(51, 51, 51) + + + Max Frames Over Desired + + + 0 + + + maxFramesOverDesiredSpin + + + + + + + + Arial + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + 0 + 0 + + + + + 100 + 0 + + + + + 70 + 16777215 + + + + + Arial + + + + 0 + + + 10000 + + + 1 + + + + + + + + + + 0 + 0 + + + + + 0 + 40 + + + + + 0 + 32 + + + + + Arial + + + + Use Stdev for Dynamic Jitter Calc + + + + 32 + 32 + + + + + + + + 0 + + + 8 + + + 0 + + + 8 + + + + + + Arial + + + + color: rgb(51, 51, 51) + + + Window A Starve Threshold + + + 0 + + + windowStarveThresholdSpin + + + + + + + + Arial + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + 0 + 0 + + + + + 100 + 0 + + + + + 70 + 16777215 + + + + + Arial + + + + 0 + + + 10000 + + + 1 + + + + + + + + + 0 + + + 8 + + + 0 + + + 8 + + + + + + Arial + + + + color: rgb(51, 51, 51) + + + Window A (raise desired on N starves) Seconds + + + 0 + + + windowSecondsForDesiredCalcOnTooManyStarvesSpin + + + + + + + + Arial + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + 0 + 0 + + + + + 100 + 0 + + + + + 70 + 16777215 + + + + + Arial + + + + 0 + + + 10000 + + + 1 + + + + + + + + + 0 + + + 8 + + + 0 + + + 8 + + + + + + Arial + + + + color: rgb(51, 51, 51) + + + Window B (desired ceiling) Seconds + + + 0 + + + windowSecondsForDesiredReductionSpin + + + + + + + + Arial + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + 0 + 0 + + + + + 100 + 0 + + + + + 70 + 16777215 + + + + + Arial + + + + 0 + + + 10000 + + + 1 + + + + + + + + + + 0 + 0 + + + + + 32 + 40 + + + + + 0 + 0 + + + + + Arial + + + + Repetition with Fade + + + + 32 + 32 + + + + 0 - 10 + 8 0 - 10 + 8 @@ -2029,7 +1813,7 @@ Faceshift eye detection - 15 + 0 faceshiftEyeDeflectionSider @@ -2083,7 +1867,7 @@ - + 0 0 @@ -2091,7 +1875,7 @@ 0 - 40 + 35 @@ -2102,6 +1886,9 @@ false + + color:#29967e + Voxels @@ -2116,13 +1903,13 @@ 0 - 10 + 8 0 - 10 + 8 @@ -2138,7 +1925,7 @@ Maximum voxels - 15 + 0 maxVoxelsSpin @@ -2192,13 +1979,13 @@ 0 - 10 + 8 0 - 10 + 8 @@ -2211,7 +1998,7 @@ Max voxels sent each second - 15 + 0 maxVoxelsPPSSpin @@ -2264,10 +2051,16 @@ + + + 0 + 0 + + 0 - 40 + 35 @@ -2278,6 +2071,9 @@ false + + color:#29967e + Oculus Rift @@ -2292,13 +2088,13 @@ 0 - 10 + 8 0 - 10 + 8 @@ -2314,7 +2110,7 @@ User Interface Angular Size - 15 + 0 maxVoxelsSpin @@ -2371,7 +2167,7 @@ - + 0 0 @@ -2379,7 +2175,7 @@ 0 - 40 + 35 @@ -2390,6 +2186,9 @@ false + + color:#29967e + Sixense Controllers @@ -2399,78 +2198,34 @@ - - - 0 + + + + 0 + 40 + - - 10 + + + 0 + 40 + - - 0 + + + Arial + - - 10 + + Invert Mouse Buttons - - - - - Arial - - - - color: rgb(51, 51, 51) - - - Invert Mouse Buttons - - - 15 - - - maxVoxelsSpin - - - - - - - - Arial - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - - 0 - 0 - - - - - - - - 0 - 0 - - - - - + + + 0 + 0 + + + @@ -2478,13 +2233,13 @@ 0 - 10 + 8 0 - 10 + 8 @@ -2500,7 +2255,7 @@ Reticle Movement Speed - 15 + 0 maxVoxelsSpin @@ -2558,9 +2313,9 @@ 0 - 530 + 490 501 - 60 + 50 @@ -2573,7 +2328,7 @@ 0 - 10 + 0 491 41 @@ -2594,6 +2349,12 @@ + + + Arial + 14 + + Cancel @@ -2604,6 +2365,12 @@ + + + Arial + 14 + + Save all changes From 974c88442c7d10479bc61a54493cbd8833d3fc1c Mon Sep 17 00:00:00 2001 From: Craig Hansen-Sturm Date: Fri, 29 Aug 2014 14:36:11 -0700 Subject: [PATCH 04/50] new audio format object --- libraries/audio/src/AudioFormat.h | 84 +++++++++++++++++++++++++++++++ 1 file changed, 84 insertions(+) create mode 100644 libraries/audio/src/AudioFormat.h diff --git a/libraries/audio/src/AudioFormat.h b/libraries/audio/src/AudioFormat.h new file mode 100644 index 0000000000..0ded25d0c3 --- /dev/null +++ b/libraries/audio/src/AudioFormat.h @@ -0,0 +1,84 @@ +// +// AudioFormat.h +// hifi +// +// Created by Craig Hansen-Sturm on 8/28/14. +// Copyright 2014 High Fidelity, Inc. +// +// Distributed under the Apache License, Version 2.0. +// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html +// + +#ifndef hifi_AudioFormat_h +#define hifi_AudioFormat_h + +#ifndef _FLOAT32_T +#define _FLOAT32_T +typedef float float32_t; +#endif + +#ifndef _FLOAT64_T +#define _FLOAT64_T +typedef double float64_t; +#endif + +// +// Audio format structure (uncompressed streams only) +// + +struct AudioFormat { + + struct Flags { + uint32_t _isFloat : 1; + uint32_t _isSigned : 1; + uint32_t _isInterleaved : 1; + uint32_t _isBigEndian : 1; + uint32_t _isPacked : 1; + uint32_t _reserved : 27; + } _flags; + + uint32_t _bytesPerFrame; + uint32_t _channelsPerFrame; + uint32_t _bitsPerChannel; + float64_t _sampleRate; + + AudioFormat() { + std::memset(this, 0, sizeof(*this)); + } + ~AudioFormat() { } + + AudioFormat& operator=(const AudioFormat& fmt) { + std::memcpy(this, &fmt, sizeof(*this)); + return *this; + } + + bool operator==(const AudioFormat& fmt) { + return std::memcmp(this, &fmt, sizeof(*this)) == 0; + } + + bool operator!=(const AudioFormat& fmt) { + return std::memcmp(this, &fmt, sizeof(*this)) != 0; + } + + void setCanonicalFloat32(uint32_t channels) { + assert(channels > 0 && channels <= 2); + _sampleRate = SAMPLE_RATE; + _bitsPerChannel = sizeof(float32_t) * 8; + _channelsPerFrame = channels; + _bytesPerFrame = _channelsPerFrame * _bitsPerChannel / 8; + _flags._isFloat = true; + _flags._isInterleaved = _channelsPerFrame > 1; + } + + void setCanonicalInt16(uint32_t channels) { + assert(channels > 0 && channels <= 2); + _sampleRate = SAMPLE_RATE; + _bitsPerChannel = sizeof(int16_t) * 8; + _channelsPerFrame = channels; + _bytesPerFrame = _channelsPerFrame * _bitsPerChannel / 8; + _flags._isSigned = true; + _flags._isInterleaved = _channelsPerFrame > 1; + } +}; + +#endif // hifi_AudioFormat_h From f12f45adec6b74c3ed07ea59f1deb10dae473dc8 Mon Sep 17 00:00:00 2001 From: stojce Date: Thu, 4 Sep 2014 00:55:36 +0200 Subject: [PATCH 05/50] Layout fixes --- interface/src/ui/PreferencesDialog.cpp | 6 +- interface/ui/preferencesDialog.ui | 246 ++++++------------------- 2 files changed, 59 insertions(+), 193 deletions(-) diff --git a/interface/src/ui/PreferencesDialog.cpp b/interface/src/ui/PreferencesDialog.cpp index a1f0f4e2d4..961c728fcc 100644 --- a/interface/src/ui/PreferencesDialog.cpp +++ b/interface/src/ui/PreferencesDialog.cpp @@ -16,6 +16,8 @@ #include "PreferencesDialog.h" #include "UserActivityLogger.h" +const int PREFERENCES_HEIGHT_PADDING = 20; + PreferencesDialog::PreferencesDialog() : QDialog(Application::getInstance()->getWindow()) { @@ -31,8 +33,8 @@ PreferencesDialog::PreferencesDialog() : connect(ui.buttonReloadDefaultScripts, &QPushButton::clicked, Application::getInstance(), &Application::loadDefaultScripts); // move dialog to left side - move(0, 0); - setWindowState(Qt::WindowMaximized); + move(parentWidget()->geometry().topLeft()); + setFixedHeight(parentWidget()->size().height() - PREFERENCES_HEIGHT_PADDING); } void PreferencesDialog::accept() { diff --git a/interface/ui/preferencesDialog.ui b/interface/ui/preferencesDialog.ui index 2ec8579383..1f7439a749 100644 --- a/interface/ui/preferencesDialog.ui +++ b/interface/ui/preferencesDialog.ui @@ -33,8 +33,8 @@ 0 0 - 501 - 491 + 500 + 481 @@ -60,8 +60,8 @@ 0 0 - 501 - 1435 + 500 + 1347 @@ -97,7 +97,7 @@ Arial - 20 + 18 75 true @@ -133,7 +133,7 @@ Arial - 16 + 14 @@ -188,13 +188,13 @@ 0 - 25 + 28 Arial - 16 + 14 @@ -244,7 +244,6 @@ Arial - 14 @@ -271,13 +270,13 @@ 0 - 25 + 28 Arial - 16 + 14 @@ -324,7 +323,6 @@ Arial - 14 @@ -357,7 +355,7 @@ Arial - 20 + 18 75 true @@ -384,13 +382,13 @@ 0 - 25 + 22 Arial - 16 + 13 @@ -445,7 +443,6 @@ Arial - 14 @@ -478,7 +475,7 @@ Arial - 20 + 18 75 true @@ -505,13 +502,13 @@ 0 - 25 + 22 Arial - 16 + 13 @@ -566,7 +563,6 @@ Arial - 14 @@ -605,7 +601,6 @@ Arial - 14 @@ -630,7 +625,7 @@ Arial - 20 + 18 75 true @@ -663,7 +658,7 @@ 32 - 32 + 28 @@ -675,7 +670,6 @@ Arial - 13 @@ -713,13 +707,13 @@ 0 - 40 + 35 Arial - 20 + 18 75 true @@ -741,13 +735,13 @@ 0 - 8 + 7 0 - 8 + 7 @@ -823,13 +817,13 @@ 0 - 8 + 7 0 - 8 + 7 @@ -941,9 +935,6 @@ Arial - - color: rgb(51, 51, 51) - Lean scale (applies to Faceshift users) @@ -1005,13 +996,13 @@ 0 - 8 + 7 0 - 8 + 7 @@ -1020,9 +1011,6 @@ Arial - - color: rgb(51, 51, 51) - Avatar scale <span style=" color:#909090;">(default is 1.0)</span> @@ -1081,13 +1069,13 @@ 0 - 8 + 7 0 - 8 + 7 @@ -1096,9 +1084,6 @@ Arial - - color: rgb(51, 51, 51) - Pupil dillation @@ -1177,7 +1162,6 @@ Arial - 13 @@ -1191,13 +1175,13 @@ 0 - 8 + 7 0 - 8 + 7 @@ -1206,9 +1190,6 @@ Arial - - color: rgb(51, 51, 51) - Static Jitter Buffer Frames @@ -1276,13 +1257,13 @@ 0 - 8 + 7 0 - 8 + 7 @@ -1291,9 +1272,6 @@ Arial - - color: rgb(51, 51, 51) - Max Frames Over Desired @@ -1349,97 +1327,6 @@ - - - - 0 - - - 8 - - - 0 - - - 8 - - - - - - Arial - - - - color: rgb(51, 51, 51) - - - Max Frames Over Desired - - - 0 - - - maxFramesOverDesiredSpin - - - - - - - - Arial - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - - 0 - 0 - - - - - 100 - 0 - - - - - 70 - 16777215 - - - - - Arial - - - - 0 - - - 10000 - - - 1 - - - - - @@ -1482,13 +1369,13 @@ 0 - 8 + 7 0 - 8 + 7 @@ -1497,9 +1384,6 @@ Arial - - color: rgb(51, 51, 51) - Window A Starve Threshold @@ -1573,13 +1457,13 @@ 0 - 8 + 7 0 - 8 + 7 @@ -1588,9 +1472,6 @@ Arial - - color: rgb(51, 51, 51) - Window A (raise desired on N starves) Seconds @@ -1664,13 +1545,13 @@ 0 - 8 + 7 0 - 8 + 7 @@ -1679,9 +1560,6 @@ Arial - - color: rgb(51, 51, 51) - Window B (desired ceiling) Seconds @@ -1791,13 +1669,13 @@ 0 - 8 + 7 0 - 8 + 7 @@ -1806,9 +1684,6 @@ Arial - - color: rgb(51, 51, 51) - Faceshift eye detection @@ -1875,13 +1750,13 @@ 0 - 35 + 33 Arial - 20 + 18 50 false @@ -1903,13 +1778,13 @@ 0 - 8 + 7 0 - 8 + 7 @@ -1918,9 +1793,6 @@ Arial - - color: rgb(51, 51, 51) - Maximum voxels @@ -1979,13 +1851,13 @@ 0 - 8 + 7 0 - 8 + 7 @@ -2060,13 +1932,13 @@ 0 - 35 + 33 Arial - 20 + 18 50 false @@ -2088,13 +1960,13 @@ 0 - 8 + 7 0 - 8 + 7 @@ -2103,9 +1975,6 @@ Arial - - color: rgb(51, 51, 51) - User Interface Angular Size @@ -2175,13 +2044,13 @@ 0 - 35 + 33 Arial - 20 + 18 50 false @@ -2202,7 +2071,7 @@ 0 - 40 + 35 @@ -2233,13 +2102,13 @@ 0 - 8 + 7 0 - 8 + 7 @@ -2248,9 +2117,6 @@ Arial - - color: rgb(51, 51, 51) - Reticle Movement Speed @@ -2352,7 +2218,6 @@ Arial - 14 @@ -2368,7 +2233,6 @@ Arial - 14 From f07f270deee6c452447c35fd5b7134bc883c2d33 Mon Sep 17 00:00:00 2001 From: stojce Date: Thu, 4 Sep 2014 01:22:17 +0200 Subject: [PATCH 06/50] restore default buttons events --- interface/ui/preferencesDialog.ui | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/interface/ui/preferencesDialog.ui b/interface/ui/preferencesDialog.ui index 1f7439a749..eeb7252dbf 100644 --- a/interface/ui/preferencesDialog.ui +++ b/interface/ui/preferencesDialog.ui @@ -2251,5 +2251,18 @@ - + + + cancelButton + clicked() + PreferencesDialog + close() + + + defaultButton + clicked() + PreferencesDialog + accept() + + From 51e616d12224b82e03a2ce3936f22ca4b5538313 Mon Sep 17 00:00:00 2001 From: Ryan Huffman Date: Thu, 4 Sep 2014 07:20:27 -0700 Subject: [PATCH 07/50] Add margin to chat window for titlebar + menu --- interface/src/Menu.cpp | 5 +++++ interface/src/ui/ChatWindow.cpp | 14 +++++++++----- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/interface/src/Menu.cpp b/interface/src/Menu.cpp index 0dcfd60051..a2e572dd9e 100644 --- a/interface/src/Menu.cpp +++ b/interface/src/Menu.cpp @@ -1456,7 +1456,9 @@ void Menu::showChat() { if (_chatWindow->isHidden()) { _chatWindow->show(); } + _chatWindow->raise(); _chatWindow->activateWindow(); + _chatWindow->setFocus(); } else { Application::getInstance()->getTrayIcon()->showMessage("Interface", "You need to login to be able to chat with others on this domain."); } @@ -1468,6 +1470,9 @@ void Menu::toggleChat() { if (!_chatAction->isEnabled() && _chatWindow && AccountManager::getInstance().isLoggedIn()) { if (_chatWindow->isHidden()) { _chatWindow->show(); + _chatWindow->raise(); + _chatWindow->activateWindow(); + _chatWindow->setFocus(); } else { _chatWindow->hide(); } diff --git a/interface/src/ui/ChatWindow.cpp b/interface/src/ui/ChatWindow.cpp index 8c37cc6a70..5253e0958e 100644 --- a/interface/src/ui/ChatWindow.cpp +++ b/interface/src/ui/ChatWindow.cpp @@ -18,12 +18,13 @@ #include #include "Application.h" +#include "ChatMessageArea.h" #include "FlowLayout.h" #include "qtimespan.h" -#include "ui_chatWindow.h" +#include "UIUtil.h" #include "XmppClient.h" -#include "ChatMessageArea.h" +#include "ui_chatWindow.h" #include "ChatWindow.h" @@ -120,10 +121,13 @@ void ChatWindow::showEvent(QShowEvent* event) { if (!event->spontaneous()) { ui->messagePlainTextEdit->setFocus(); } - const QRect parentGeometry = parentWidget()->geometry(); - setGeometry(parentGeometry.topRight().x() - size().width(), parentGeometry.topRight().y(), - size().width(), parentWidget()->height()); + int titleBarHeight = UIUtil::getWindowTitleBarHeight(this); + int menuBarHeight = Menu::getInstance()->geometry().height(); + int topMargin = titleBarHeight + menuBarHeight; + + setGeometry(parentGeometry.topRight().x() - size().width() + 1, parentGeometry.topRight().y() + topMargin, + size().width(), parentWidget()->height() - topMargin); #ifdef HAVE_QXMPP const QXmppClient& xmppClient = XmppClient::getInstance().getXMPPClient(); From 2b5759bb3991d0fd61a262480abc7f4b656f9460 Mon Sep 17 00:00:00 2001 From: Ryan Huffman Date: Thu, 4 Sep 2014 10:53:51 -0700 Subject: [PATCH 08/50] Update chat to close on ESC --- interface/src/ui/ChatWindow.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/interface/src/ui/ChatWindow.cpp b/interface/src/ui/ChatWindow.cpp index 5253e0958e..47c29a30a9 100644 --- a/interface/src/ui/ChatWindow.cpp +++ b/interface/src/ui/ChatWindow.cpp @@ -110,6 +110,7 @@ ChatWindow::~ChatWindow() { void ChatWindow::keyPressEvent(QKeyEvent* event) { if (event->key() == Qt::Key_Escape) { Application::getInstance()->getWindow()->activateWindow(); + hide(); } else { QWidget::keyPressEvent(event); } From 9820e73c8e2d1966e1d3dd0888a0473884f29311 Mon Sep 17 00:00:00 2001 From: stojce Date: Thu, 4 Sep 2014 20:15:54 +0200 Subject: [PATCH 09/50] layout tweaks --- interface/ui/preferencesDialog.ui | 63 +++++++++++++++++-------------- 1 file changed, 35 insertions(+), 28 deletions(-) diff --git a/interface/ui/preferencesDialog.ui b/interface/ui/preferencesDialog.ui index eeb7252dbf..9b6e381602 100644 --- a/interface/ui/preferencesDialog.ui +++ b/interface/ui/preferencesDialog.ui @@ -34,7 +34,7 @@ 0 0 500 - 481 + 491 @@ -61,7 +61,7 @@ 0 0 500 - 1347 + 1386 @@ -127,7 +127,7 @@ 0 - 30 + 28 @@ -349,7 +349,7 @@ 0 - 35 + 40 @@ -619,7 +619,7 @@ 0 - 30 + 40 @@ -683,19 +683,6 @@ - - - - Qt::Vertical - - - - 0 - 35 - - - - @@ -707,7 +694,7 @@ 0 - 35 + 40 @@ -1750,15 +1737,15 @@ 0 - 33 + 40 Arial 18 - 50 - false + 75 + true @@ -1932,15 +1919,15 @@ 0 - 33 + 40 Arial 18 - 50 - false + 75 + true @@ -2044,15 +2031,15 @@ 0 - 33 + 40 Arial 18 - 50 - false + 75 + true @@ -2257,12 +2244,32 @@ clicked() PreferencesDialog close() + + + 20 + 20 + + + 20 + 20 + + defaultButton clicked() PreferencesDialog accept() + + + 20 + 20 + + + 20 + 20 + + From eecc94f816a73942c9cb777ef29732dfc483c911 Mon Sep 17 00:00:00 2001 From: Andrzej Kapolka Date: Fri, 5 Sep 2014 15:27:55 -0700 Subject: [PATCH 10/50] Enable high resolution for OS X. --- cmake/modules/MacOSXBundleInfo.plist.in | 2 ++ 1 file changed, 2 insertions(+) diff --git a/cmake/modules/MacOSXBundleInfo.plist.in b/cmake/modules/MacOSXBundleInfo.plist.in index 1682b6c022..a06fac092f 100644 --- a/cmake/modules/MacOSXBundleInfo.plist.in +++ b/cmake/modules/MacOSXBundleInfo.plist.in @@ -43,5 +43,7 @@ + NSHighResolutionCapable + From 619aebcd679e97304b4e7f1eb5e1e1332fc0464e Mon Sep 17 00:00:00 2001 From: Atlante45 Date: Fri, 5 Sep 2014 16:18:02 -0700 Subject: [PATCH 11/50] move isStereo packing to the correct position --- libraries/audio/src/AudioInjector.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/libraries/audio/src/AudioInjector.cpp b/libraries/audio/src/AudioInjector.cpp index 7209ecb36a..17b082f07a 100644 --- a/libraries/audio/src/AudioInjector.cpp +++ b/libraries/audio/src/AudioInjector.cpp @@ -64,13 +64,13 @@ void AudioInjector::injectAudio() { // pack some placeholder sequence number for now int numPreSequenceNumberBytes = injectAudioPacket.size(); packetStream << (quint16)0; - - // pack the stereo/mono type of the stream - packetStream << _options.isStereo(); // pack stream identifier (a generated UUID) packetStream << QUuid::createUuid(); + // pack the stereo/mono type of the stream + packetStream << _options.isStereo(); + // pack the flag for loopback uchar loopbackFlag = (uchar) (!_options.getLoopbackAudioInterface()); packetStream << loopbackFlag; From 0ddc8eb448b0abbdc43181e6835d9f826312b3fe Mon Sep 17 00:00:00 2001 From: Andrew Meadows Date: Fri, 5 Sep 2014 16:40:14 -0700 Subject: [PATCH 12/50] fix signed/unsigned comparison --- libraries/octree/src/OctreeEditPacketSender.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libraries/octree/src/OctreeEditPacketSender.cpp b/libraries/octree/src/OctreeEditPacketSender.cpp index 78b9e29f12..65308f906f 100644 --- a/libraries/octree/src/OctreeEditPacketSender.cpp +++ b/libraries/octree/src/OctreeEditPacketSender.cpp @@ -275,7 +275,7 @@ void OctreeEditPacketSender::queueOctreeEditMessage(PacketType type, unsigned ch // If we're switching type, then we send the last one and start over if ((type != packetBuffer._currentType && packetBuffer._currentSize > 0) || - (packetBuffer._currentSize + length >= _maxPacketSize)) { + (packetBuffer._currentSize + length >= (size_t)_maxPacketSize)) { releaseQueuedPacket(packetBuffer); initializePacket(packetBuffer, type); } From 62438bae6ac21c4fcc6798c3db62f11de3c71c51 Mon Sep 17 00:00:00 2001 From: Andrew Meadows Date: Fri, 5 Sep 2014 16:41:01 -0700 Subject: [PATCH 13/50] fixed signed/unsigned comparison and unused variable --- libraries/octree/src/Octree.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/libraries/octree/src/Octree.cpp b/libraries/octree/src/Octree.cpp index ff9ebbcd87..9569296502 100644 --- a/libraries/octree/src/Octree.cpp +++ b/libraries/octree/src/Octree.cpp @@ -242,7 +242,7 @@ int Octree::readElementData(OctreeElement* destinationElement, const unsigned ch // give this destination element the child mask from the packet const unsigned char ALL_CHILDREN_ASSUMED_TO_EXIST = 0xFF; - if (bytesLeftToRead < sizeof(unsigned char)) { + if ((size_t)bytesLeftToRead < sizeof(unsigned char)) { qDebug() << "UNEXPECTED: readElementData() only had " << bytesLeftToRead << " bytes. Not enough for meaningful data."; return bytesAvailable; // assume we read the entire buffer... } @@ -1865,7 +1865,6 @@ int Octree::encodeTreeBitstreamRecursion(OctreeElement* element, bool Octree::readFromSVOFile(const char* fileName) { bool fileOk = false; - bool hasBufferBreaks = false; PacketVersion gotVersion = 0; std::ifstream file(fileName, std::ios::in|std::ios::binary|std::ios::ate); From 3ae78da593fde573dbe491a89ad031ec323b76cc Mon Sep 17 00:00:00 2001 From: Andrew Meadows Date: Fri, 5 Sep 2014 16:41:51 -0700 Subject: [PATCH 14/50] fixed signed/unsigned comparison --- libraries/entities/src/EntityTree.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libraries/entities/src/EntityTree.cpp b/libraries/entities/src/EntityTree.cpp index b7fd267c30..a571a17a20 100644 --- a/libraries/entities/src/EntityTree.cpp +++ b/libraries/entities/src/EntityTree.cpp @@ -492,7 +492,7 @@ int EntityTree::processEditPacketData(PacketType packetType, const unsigned char void EntityTree::notifyNewlyCreatedEntity(const EntityItem& newEntity, const SharedNodePointer& senderNode) { _newlyCreatedHooksLock.lockForRead(); - for (size_t i = 0; i < _newlyCreatedHooks.size(); i++) { + for (int i = 0; i < _newlyCreatedHooks.size(); i++) { _newlyCreatedHooks[i]->entityCreated(newEntity, senderNode); } _newlyCreatedHooksLock.unlock(); @@ -506,7 +506,7 @@ void EntityTree::addNewlyCreatedHook(NewlyCreatedEntityHook* hook) { void EntityTree::removeNewlyCreatedHook(NewlyCreatedEntityHook* hook) { _newlyCreatedHooksLock.lockForWrite(); - for (size_t i = 0; i < _newlyCreatedHooks.size(); i++) { + for (int i = 0; i < _newlyCreatedHooks.size(); i++) { if (_newlyCreatedHooks[i] == hook) { _newlyCreatedHooks.erase(_newlyCreatedHooks.begin() + i); break; From e7b39ae1193648687ea3ca9d868acd116c7d99f4 Mon Sep 17 00:00:00 2001 From: Andrew Meadows Date: Fri, 5 Sep 2014 16:42:24 -0700 Subject: [PATCH 15/50] removed unused variable --- libraries/entities/src/EntityTreeElement.cpp | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/libraries/entities/src/EntityTreeElement.cpp b/libraries/entities/src/EntityTreeElement.cpp index e1aa9b33e1..8f223abf7e 100644 --- a/libraries/entities/src/EntityTreeElement.cpp +++ b/libraries/entities/src/EntityTreeElement.cpp @@ -723,7 +723,6 @@ int EntityTreeElement::readElementDataFromBuffer(const unsigned char* data, int int bytesForThisEntity = 0; EntityItemID entityItemID; EntityItem* entityItem = NULL; - bool newEntity = false; // Old model files don't have UUIDs in them. So we don't want to try to read those IDs from the stream. // Since this can only happen on loading an old file, we can safely treat these as new entity cases, @@ -768,7 +767,6 @@ int EntityTreeElement::readElementDataFromBuffer(const unsigned char* data, int addEntityItem(entityItem); // add this new entity to this elements entities entityItemID = entityItem->getEntityItemID(); _myTree->setContainingElement(entityItemID, this); - newEntity = true; EntityItem::SimulationState newState = entityItem->getSimulationState(); _myTree->changeEntityState(entityItem, EntityItem::Static, newState); } @@ -826,4 +824,4 @@ void EntityTreeElement::debugDump() { entity->debugDump(); } } - \ No newline at end of file + From c089dbb0bb39c6b94ec8d80362b92a731e056511 Mon Sep 17 00:00:00 2001 From: Andrew Meadows Date: Fri, 5 Sep 2014 16:44:33 -0700 Subject: [PATCH 16/50] removed signed/unsigned comparisons --- libraries/script-engine/src/TypedArrayPrototype.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libraries/script-engine/src/TypedArrayPrototype.cpp b/libraries/script-engine/src/TypedArrayPrototype.cpp index 37274dd080..bb612b393f 100644 --- a/libraries/script-engine/src/TypedArrayPrototype.cpp +++ b/libraries/script-engine/src/TypedArrayPrototype.cpp @@ -30,11 +30,11 @@ void TypedArrayPrototype::set(QScriptValue array, qint32 offset) { engine()->evaluate("throw \"ArgumentError: negative offset\""); } quint32 length = array.property("length").toInt32(); - if (offset + length > thisObject().data().property(typedArray->_lengthName).toInt32()) { + if (offset + (qint32)length > thisObject().data().property(typedArray->_lengthName).toInt32()) { engine()->evaluate("throw \"ArgumentError: array does not fit\""); return; } - for (int i = 0; i < length; ++i) { + for (quint32 i = 0; i < length; ++i) { thisObject().setProperty(QString::number(offset + i), array.property(QString::number(i))); } } else { From 7f6b3d3649116e937ae7588a95a9d58e9b7acbf7 Mon Sep 17 00:00:00 2001 From: Andrzej Kapolka Date: Fri, 5 Sep 2014 16:44:45 -0700 Subject: [PATCH 17/50] Dimension fixes for Retina displays. --- interface/src/Application.cpp | 40 ++++----- interface/src/Application.h | 4 +- interface/src/Camera.cpp | 4 +- interface/src/GLCanvas.cpp | 19 +++-- interface/src/GLCanvas.h | 5 ++ interface/src/devices/OculusManager.cpp | 8 +- interface/src/devices/PrioVR.cpp | 6 +- interface/src/devices/SixenseManager.cpp | 8 +- interface/src/devices/TV3DManager.cpp | 13 +-- .../src/renderer/AmbientOcclusionEffect.cpp | 2 +- .../ControllerScriptingInterface.cpp | 4 +- interface/src/ui/ApplicationOverlay.cpp | 85 ++++++++++--------- interface/src/ui/MetavoxelEditor.cpp | 3 +- interface/src/ui/NodeBounds.cpp | 6 +- interface/src/ui/Stats.cpp | 21 ++--- 15 files changed, 125 insertions(+), 103 deletions(-) diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index 966f222c52..7eae29f041 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -596,7 +596,7 @@ void Application::paintGL() { if (OculusManager::isConnected()) { _textureCache.setFrameBufferSize(OculusManager::getRenderTargetSize()); } else { - _textureCache.setFrameBufferSize(_glWidget->size()); + _textureCache.setFrameBufferSize(_glWidget->getDeviceSize()); } glEnable(GL_LINE_SMOOTH); @@ -986,7 +986,7 @@ void Application::keyPressEvent(QKeyEvent* event) { if (isShifted) { _viewFrustum.setFocalLength(_viewFrustum.getFocalLength() - 0.1f); if (TV3DManager::isConnected()) { - TV3DManager::configureCamera(_myCamera, _glWidget->width(),_glWidget->height()); + TV3DManager::configureCamera(_myCamera, _glWidget->getDeviceWidth(), _glWidget->getDeviceHeight()); } } else { _myCamera.setEyeOffsetPosition(_myCamera.getEyeOffsetPosition() + glm::vec3(-0.001, 0, 0)); @@ -998,7 +998,7 @@ void Application::keyPressEvent(QKeyEvent* event) { if (isShifted) { _viewFrustum.setFocalLength(_viewFrustum.getFocalLength() + 0.1f); if (TV3DManager::isConnected()) { - TV3DManager::configureCamera(_myCamera, _glWidget->width(),_glWidget->height()); + TV3DManager::configureCamera(_myCamera, _glWidget->getDeviceWidth(), _glWidget->getDeviceHeight()); } } else { @@ -1424,7 +1424,7 @@ void Application::checkBandwidthMeterClick() { if (Menu::getInstance()->isOptionChecked(MenuOption::Bandwidth) && glm::compMax(glm::abs(glm::ivec2(_mouseX - _mouseDragStartedX, _mouseY - _mouseDragStartedY))) <= BANDWIDTH_METER_CLICK_MAX_DRAG_LENGTH - && _bandwidthMeter.isWithinArea(_mouseX, _mouseY, _glWidget->width(), _glWidget->height())) { + && _bandwidthMeter.isWithinArea(_mouseX, _mouseY, _glWidget->getDeviceWidth(), _glWidget->getDeviceHeight())) { // The bandwidth meter is visible, the click didn't get dragged too far and // we actually hit the bandwidth meter @@ -1438,7 +1438,7 @@ void Application::setFullscreen(bool fullscreen) { } void Application::setEnable3DTVMode(bool enable3DTVMode) { - resizeGL(_glWidget->width(),_glWidget->height()); + resizeGL(_glWidget->getDeviceWidth(),_glWidget->getDeviceHeight()); } void Application::setEnableVRMode(bool enableVRMode) { @@ -1451,7 +1451,7 @@ void Application::setEnableVRMode(bool enableVRMode) { } } - resizeGL(_glWidget->width(), _glWidget->height()); + resizeGL(_glWidget->getDeviceWidth(), _glWidget->getDeviceHeight()); } void Application::setRenderVoxels(bool voxelRender) { @@ -1742,8 +1742,8 @@ void Application::init() { _voxelShader.init(); _pointShader.init(); - _mouseX = _glWidget->width() / 2; - _mouseY = _glWidget->height() / 2; + _mouseX = _glWidget->getDeviceWidth() / 2; + _mouseY = _glWidget->getDeviceHeight() / 2; QCursor::setPos(_mouseX, _mouseY); // TODO: move _myAvatar out of Application. Move relevant code to MyAvataar or AvatarManager @@ -1898,8 +1898,8 @@ void Application::updateMouseRay() { // if the mouse pointer isn't visible, act like it's at the center of the screen float x = 0.5f, y = 0.5f; if (!_mouseHidden) { - x = _mouseX / (float)_glWidget->width(); - y = _mouseY / (float)_glWidget->height(); + x = _mouseX / (float)_glWidget->getDeviceWidth(); + y = _mouseY / (float)_glWidget->getDeviceHeight(); } _viewFrustum.computePickRay(x, y, _mouseRayOrigin, _mouseRayDirection); @@ -2686,7 +2686,7 @@ void Application::updateShadowMap() { fbo->release(); - glViewport(0, 0, _glWidget->width(), _glWidget->height()); + glViewport(0, 0, _glWidget->getDeviceWidth(), _glWidget->getDeviceHeight()); } const GLfloat WORLD_AMBIENT_COLOR[] = { 0.525f, 0.525f, 0.6f }; @@ -2716,7 +2716,7 @@ QImage Application::renderAvatarBillboard() { glDisable(GL_BLEND); const int BILLBOARD_SIZE = 64; - renderRearViewMirror(QRect(0, _glWidget->height() - BILLBOARD_SIZE, BILLBOARD_SIZE, BILLBOARD_SIZE), true); + renderRearViewMirror(QRect(0, _glWidget->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()); @@ -2976,8 +2976,8 @@ void Application::computeOffAxisFrustum(float& left, float& right, float& bottom } glm::vec2 Application::getScaledScreenPoint(glm::vec2 projectedPoint) { - float horizontalScale = _glWidget->width() / 2.0f; - float verticalScale = _glWidget->height() / 2.0f; + float horizontalScale = _glWidget->getDeviceWidth() / 2.0f; + float verticalScale = _glWidget->getDeviceHeight() / 2.0f; // -1,-1 is 0,windowHeight // 1,1 is windowWidth,0 @@ -2996,7 +2996,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->height()); + ((projectedPoint.y + 1.0) * -verticalScale) + _glWidget->getDeviceHeight()); return screenPoint; } @@ -3032,8 +3032,8 @@ void Application::renderRearViewMirror(const QRect& region, bool billboard) { _mirrorCamera.update(1.0f/_fps); // set the bounds of rear mirror view - glViewport(region.x(), _glWidget->height() - region.y() - region.height(), region.width(), region.height()); - glScissor(region.x(), _glWidget->height() - region.y() - region.height(), region.width(), region.height()); + glViewport(region.x(), _glWidget->getDeviceHeight() - region.y() - region.height(), region.width(), region.height()); + glScissor(region.x(), _glWidget->getDeviceHeight() - region.y() - region.height(), region.width(), region.height()); bool updateViewFrustum = false; updateProjectionMatrix(_mirrorCamera, updateViewFrustum); glEnable(GL_SCISSOR_TEST); @@ -3100,7 +3100,7 @@ void Application::renderRearViewMirror(const QRect& region, bool billboard) { } // reset Viewport and projection matrix - glViewport(0, 0, _glWidget->width(), _glWidget->height()); + glViewport(0, 0, _glWidget->getDeviceWidth(), _glWidget->getDeviceHeight()); glDisable(GL_SCISSOR_TEST); updateProjectionMatrix(_myCamera, updateViewFrustum); } @@ -3282,8 +3282,8 @@ void Application::deleteVoxelAt(const VoxelDetail& voxel) { void Application::resetSensors() { - _mouseX = _glWidget->width() / 2; - _mouseY = _glWidget->height() / 2; + _mouseX = _glWidget->getDeviceWidth() / 2; + _mouseY = _glWidget->getDeviceHeight() / 2; _faceplus.reset(); _faceshift.reset(); diff --git a/interface/src/Application.h b/interface/src/Application.h index a68528ce72..302c1bf2d3 100644 --- a/interface/src/Application.h +++ b/interface/src/Application.h @@ -186,7 +186,7 @@ public: glm::vec3 getMouseVoxelWorldCoordinates(const VoxelDetail& mouseVoxel); - QGLWidget* getGLWidget() { return _glWidget; } + GLCanvas* getGLWidget() { return _glWidget; } bool isThrottleRendering() const { return _glWidget->isThrottleRendering(); } MyAvatar* getAvatar() { return _myAvatar; } Audio* getAudio() { return &_audio; } @@ -288,7 +288,7 @@ public: PointShader& getPointShader() { return _pointShader; } FileLogger* getLogger() { return _logger; } - glm::vec2 getViewportDimensions() const{ return glm::vec2(_glWidget->width(),_glWidget->height()); } + glm::vec2 getViewportDimensions() const { return glm::vec2(_glWidget->getDeviceWidth(), _glWidget->getDeviceHeight()); } NodeToJurisdictionMap& getVoxelServerJurisdictions() { return _voxelServerJurisdictions; } NodeToJurisdictionMap& getParticleServerJurisdictions() { return _particleServerJurisdictions; } NodeToJurisdictionMap& getEntityServerJurisdictions() { return _entityServerJurisdictions; } diff --git a/interface/src/Camera.cpp b/interface/src/Camera.cpp index 4a924b4ec3..c4df0f7f2a 100644 --- a/interface/src/Camera.cpp +++ b/interface/src/Camera.cpp @@ -262,8 +262,8 @@ CameraScriptableObject::CameraScriptableObject(Camera* camera, ViewFrustum* view } PickRay CameraScriptableObject::computePickRay(float x, float y) { - float screenWidth = Application::getInstance()->getGLWidget()->width(); - float screenHeight = Application::getInstance()->getGLWidget()->height(); + float screenWidth = Application::getInstance()->getGLWidget()->getDeviceWidth(); + float screenHeight = Application::getInstance()->getGLWidget()->getDeviceHeight(); PickRay result; if (OculusManager::isConnected()) { result.origin = _camera->getPosition(); diff --git a/interface/src/GLCanvas.cpp b/interface/src/GLCanvas.cpp index cde1890e6d..108b9ba829 100644 --- a/interface/src/GLCanvas.cpp +++ b/interface/src/GLCanvas.cpp @@ -9,13 +9,14 @@ // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // -#include "Application.h" - -#include "GLCanvas.h" -#include "devices/OculusManager.h" +#include #include #include -#include +#include + +#include "Application.h" +#include "GLCanvas.h" +#include "devices/OculusManager.h" const int MSECS_PER_FRAME_WHEN_THROTTLED = 66; @@ -34,6 +35,14 @@ bool GLCanvas::isThrottleRendering() const { return _throttleRendering || Application::getInstance()->getWindow()->isMinimized(); } +int GLCanvas::getDeviceWidth() const { + return width() * (windowHandle() ? windowHandle()->devicePixelRatio() : 1.0f); +} + +int GLCanvas::getDeviceHeight() const { + return height() * (windowHandle() ? windowHandle()->devicePixelRatio() : 1.0f); +} + void GLCanvas::initializeGL() { Application::getInstance()->initializeGL(); setAttribute(Qt::WA_AcceptTouchEvents); diff --git a/interface/src/GLCanvas.h b/interface/src/GLCanvas.h index 773fcb5c27..0d381fa0bf 100644 --- a/interface/src/GLCanvas.h +++ b/interface/src/GLCanvas.h @@ -21,6 +21,11 @@ class GLCanvas : public QGLWidget { public: GLCanvas(); bool isThrottleRendering() const; + + int getDeviceWidth() const; + int getDeviceHeight() const; + QSize getDeviceSize() const { return QSize(getDeviceWidth(), getDeviceHeight()); } + protected: QTimer _frameTimer; diff --git a/interface/src/devices/OculusManager.cpp b/interface/src/devices/OculusManager.cpp index 3582f82820..bc6dc842ce 100644 --- a/interface/src/devices/OculusManager.cpp +++ b/interface/src/devices/OculusManager.cpp @@ -383,7 +383,8 @@ void OculusManager::display(const glm::quat &bodyOrientation, const glm::vec3 &p } // restore our normal viewport - glViewport(0, 0, Application::getInstance()->getGLWidget()->width(), Application::getInstance()->getGLWidget()->height()); + glViewport(0, 0, Application::getInstance()->getGLWidget()->getDeviceWidth(), + Application::getInstance()->getGLWidget()->getDeviceHeight()); glMatrixMode(GL_PROJECTION); glPopMatrix(); @@ -400,7 +401,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()->width(), 0, Application::getInstance()->getGLWidget()->height()); + gluOrtho2D(0, Application::getInstance()->getGLWidget()->getDeviceWidth(), 0, + Application::getInstance()->getGLWidget()->getDeviceHeight()); glDisable(GL_DEPTH_TEST); @@ -525,4 +527,4 @@ QSize OculusManager::getRenderTargetSize() { #else return QSize(100, 100); #endif -} \ No newline at end of file +} diff --git a/interface/src/devices/PrioVR.cpp b/interface/src/devices/PrioVR.cpp index 195de5705d..b4a11231ed 100644 --- a/interface/src/devices/PrioVR.cpp +++ b/interface/src/devices/PrioVR.cpp @@ -209,8 +209,8 @@ void PrioVR::renderCalibrationCountdown() { } static TextRenderer textRenderer(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); + textRenderer.draw((Application::getInstance()->getGLWidget()->getDeviceWidth() - + textRenderer.computeWidth(text.constData())) / 2, Application::getInstance()->getGLWidget()->getDeviceHeight() / 2, + text); #endif } diff --git a/interface/src/devices/SixenseManager.cpp b/interface/src/devices/SixenseManager.cpp index 803060e5d3..86c4b17cb2 100644 --- a/interface/src/devices/SixenseManager.cpp +++ b/interface/src/devices/SixenseManager.cpp @@ -369,7 +369,7 @@ void SixenseManager::updateCalibration(const sixenseControllerData* controllers) void SixenseManager::emulateMouse(PalmData* palm, int index) { Application* application = Application::getInstance(); MyAvatar* avatar = application->getAvatar(); - QGLWidget* widget = application->getGLWidget(); + GLCanvas* widget = application->getGLWidget(); QPoint pos; Qt::MouseButton bumperButton; @@ -396,10 +396,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 = widget->getDeviceWidth() * getCursorPixelRangeMult(); - pos.setX(widget->width() / 2.0f + cursorRange * xAngle); - pos.setY(widget->height() / 2.0f + cursorRange * yAngle); + pos.setX(widget->getDeviceWidth() / 2.0f + cursorRange * xAngle); + pos.setY(widget->getDeviceHeight() / 2.0f + cursorRange * yAngle); } diff --git a/interface/src/devices/TV3DManager.cpp b/interface/src/devices/TV3DManager.cpp index 3b42c03f2d..2ce78b7ac1 100644 --- a/interface/src/devices/TV3DManager.cpp +++ b/interface/src/devices/TV3DManager.cpp @@ -33,8 +33,8 @@ bool TV3DManager::isConnected() { void TV3DManager::connect() { Application* app = Application::getInstance(); - int width = app->getGLWidget()->width(); - int height = app->getGLWidget()->height(); + int width = app->getGLWidget()->getDeviceWidth(); + int height = app->getGLWidget()->getDeviceHeight(); Camera& camera = *app->getCamera(); configureCamera(camera, width, height); @@ -90,8 +90,8 @@ void TV3DManager::display(Camera& whichCamera) { // left eye portal int portalX = 0; int portalY = 0; - int portalW = Application::getInstance()->getGLWidget()->width() / 2; - int portalH = Application::getInstance()->getGLWidget()->height(); + int portalW = Application::getInstance()->getGLWidget()->getDeviceWidth() / 2; + int portalH = Application::getInstance()->getGLWidget()->getDeviceHeight(); const bool glowEnabled = Menu::getInstance()->isOptionChecked(MenuOption::EnableGlowEffect); @@ -137,7 +137,7 @@ void TV3DManager::display(Camera& whichCamera) { glDisable(GL_SCISSOR_TEST); // render right side view - portalX = Application::getInstance()->getGLWidget()->width() / 2; + portalX = Application::getInstance()->getGLWidget()->getDeviceWidth() / 2; glEnable(GL_SCISSOR_TEST); // render left side view glViewport(portalX, portalY, portalW, portalH); @@ -165,7 +165,8 @@ void TV3DManager::display(Camera& whichCamera) { glDisable(GL_SCISSOR_TEST); // reset the viewport to how we started - glViewport(0, 0, Application::getInstance()->getGLWidget()->width(), Application::getInstance()->getGLWidget()->height()); + glViewport(0, 0, Application::getInstance()->getGLWidget()->getDeviceWidth(), + Application::getInstance()->getGLWidget()->getDeviceHeight()); if (glowEnabled) { Application::getInstance()->getGlowEffect()->render(); diff --git a/interface/src/renderer/AmbientOcclusionEffect.cpp b/interface/src/renderer/AmbientOcclusionEffect.cpp index 635e6c9bd6..a4977e5e01 100644 --- a/interface/src/renderer/AmbientOcclusionEffect.cpp +++ b/interface/src/renderer/AmbientOcclusionEffect.cpp @@ -116,7 +116,7 @@ void AmbientOcclusionEffect::render() { glGetIntegerv(GL_VIEWPORT, viewport); const int VIEWPORT_X_INDEX = 0; const int VIEWPORT_WIDTH_INDEX = 2; - QSize widgetSize = Application::getInstance()->getGLWidget()->size(); + QSize widgetSize = Application::getInstance()->getGLWidget()->getDeviceSize(); float sMin = viewport[VIEWPORT_X_INDEX] / (float)widgetSize.width(); float sWidth = viewport[VIEWPORT_WIDTH_INDEX] / (float)widgetSize.width(); diff --git a/interface/src/scripting/ControllerScriptingInterface.cpp b/interface/src/scripting/ControllerScriptingInterface.cpp index 8d6a9486d9..0ebcfea987 100644 --- a/interface/src/scripting/ControllerScriptingInterface.cpp +++ b/interface/src/scripting/ControllerScriptingInterface.cpp @@ -256,8 +256,8 @@ void ControllerScriptingInterface::releaseJoystick(int joystickIndex) { } glm::vec2 ControllerScriptingInterface::getViewportDimensions() const { - QGLWidget* widget = Application::getInstance()->getGLWidget(); - return glm::vec2(widget->width(), widget->height()); + GLCanvas* widget = Application::getInstance()->getGLWidget(); + return glm::vec2(widget->getDeviceWidth(), widget->getDeviceHeight()); } AbstractInputController* ControllerScriptingInterface::createInputController(const QString& deviceName, const QString& tracker) { diff --git a/interface/src/ui/ApplicationOverlay.cpp b/interface/src/ui/ApplicationOverlay.cpp index 7dcb50c314..ccb32e286a 100644 --- a/interface/src/ui/ApplicationOverlay.cpp +++ b/interface/src/ui/ApplicationOverlay.cpp @@ -70,7 +70,7 @@ void ApplicationOverlay::renderOverlay(bool renderToTexture) { Application* application = Application::getInstance(); Overlays& overlays = application->getOverlays(); - QGLWidget* glWidget = application->getGLWidget(); + GLCanvas* glWidget = application->getGLWidget(); MyAvatar* myAvatar = application->getAvatar(); //Handle fading and deactivation/activation of UI @@ -99,14 +99,14 @@ void ApplicationOverlay::renderOverlay(bool renderToTexture) { glPushMatrix(); glLoadIdentity(); - gluOrtho2D(0, glWidget->width(), glWidget->height(), 0); + gluOrtho2D(0, glWidget->getDeviceWidth(), glWidget->getDeviceHeight(), 0); glDisable(GL_DEPTH_TEST); glDisable(GL_LIGHTING); renderAudioMeter(); if (Menu::getInstance()->isOptionChecked(MenuOption::HeadMouse)) { - myAvatar->renderHeadMouse(glWidget->width(), glWidget->height()); + myAvatar->renderHeadMouse(glWidget->getDeviceWidth(), glWidget->getDeviceHeight()); } renderStatsAndLogs(); @@ -141,7 +141,7 @@ void ApplicationOverlay::displayOverlayTexture() { } Application* application = Application::getInstance(); - QGLWidget* glWidget = application->getGLWidget(); + GLCanvas* glWidget = application->getGLWidget(); glEnable(GL_TEXTURE_2D); @@ -152,16 +152,16 @@ void ApplicationOverlay::displayOverlayTexture() { glPushMatrix(); glLoadIdentity(); - gluOrtho2D(0, glWidget->width(), glWidget->height(), 0); + gluOrtho2D(0, glWidget->getDeviceWidth(), glWidget->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->height()); - glTexCoord2f(1, 0); glVertex2i(glWidget->width(), glWidget->height()); - glTexCoord2f(1, 1); glVertex2i(glWidget->width(), 0); + glTexCoord2f(0, 0); glVertex2i(0, glWidget->getDeviceHeight()); + glTexCoord2f(1, 0); glVertex2i(glWidget->getDeviceWidth(), glWidget->getDeviceHeight()); + glTexCoord2f(1, 1); glVertex2i(glWidget->getDeviceWidth(), 0); glTexCoord2f(0, 1); glVertex2i(0, 0); glEnd(); glColor4f(1.0f, 1.0f, 1.0f, 1.0f); @@ -275,7 +275,7 @@ bool raySphereIntersect(const glm::vec3 &dir, const glm::vec3 &origin, float r, QPoint ApplicationOverlay::getPalmClickLocation(const PalmData *palm) const { Application* application = Application::getInstance(); - QGLWidget* glWidget = application->getGLWidget(); + GLCanvas* glWidget = application->getGLWidget(); MyAvatar* myAvatar = application->getAvatar(); glm::vec3 tip = myAvatar->getLaserPointerTipPosition(palm); @@ -305,8 +305,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 * glWidget->getDeviceWidth()); + rv.setY(v * glWidget->getDeviceHeight()); } } else { //if they did not click on the overlay, just set the coords to INT_MAX @@ -323,8 +323,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) * glWidget->getDeviceWidth()); + rv.setY((1.0 - ((ndcSpacePos.y + 1.0) / 2.0)) * glWidget->getDeviceHeight()); } return rv; } @@ -496,11 +496,11 @@ void ApplicationOverlay::displayOverlayTexture3DTV(Camera& whichCamera, float as //draw the mouse pointer glBindTexture(GL_TEXTURE_2D, _crosshairTexture); - const float reticleSize = 40.0f / application->getGLWidget()->width() * quadWidth; + const float reticleSize = 40.0f / application->getGLWidget()->getDeviceWidth() * 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)application->getGLWidget()->getDeviceWidth()) * quadWidth; + const float mouseY = (1.0 - (application->getMouseY() / (float)application->getGLWidget()->getDeviceHeight())) * quadHeight; glBegin(GL_QUADS); @@ -564,7 +564,7 @@ void ApplicationOverlay::renderPointers() { void ApplicationOverlay::renderControllerPointers() { Application* application = Application::getInstance(); - QGLWidget* glWidget = application->getGLWidget(); + GLCanvas* glWidget = application->getGLWidget(); MyAvatar* myAvatar = application->getAvatar(); //Static variables used for storing controller state @@ -671,14 +671,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() * application->getSixenseManager()->getCursorPixelRangeMult(); + float cursorRange = glWidget->getDeviceWidth() * application->getSixenseManager()->getCursorPixelRangeMult(); - mouseX = (glWidget->width() / 2.0f + cursorRange * xAngle); - mouseY = (glWidget->height() / 2.0f + cursorRange * yAngle); + mouseX = (glWidget->getDeviceWidth() / 2.0f + cursorRange * xAngle); + mouseY = (glWidget->getDeviceHeight() / 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 >= glWidget->getDeviceWidth() || mouseY < 0 || mouseY >= glWidget->getDeviceHeight()) { _reticleActive[index] = false; continue; } @@ -706,11 +706,11 @@ void ApplicationOverlay::renderControllerPointers() { void ApplicationOverlay::renderPointersOculus(const glm::vec3& eyePos) { Application* application = Application::getInstance(); - QGLWidget* glWidget = application->getGLWidget(); + GLCanvas* glWidget = application->getGLWidget(); glm::vec3 cursorVerts[4]; - const int widgetWidth = glWidget->width(); - const int widgetHeight = glWidget->height(); + const int widgetWidth = glWidget->getDeviceWidth(); + const int widgetHeight = glWidget->getDeviceHeight(); const float reticleSize = 50.0f; @@ -848,10 +848,10 @@ void ApplicationOverlay::renderPointersOculus(const glm::vec3& eyePos) { void ApplicationOverlay::renderMagnifier(int mouseX, int mouseY, float sizeMult, bool showBorder) const { Application* application = Application::getInstance(); - QGLWidget* glWidget = application->getGLWidget(); + GLCanvas* glWidget = application->getGLWidget(); - const int widgetWidth = glWidget->width(); - const int widgetHeight = glWidget->height(); + const int widgetWidth = glWidget->getDeviceWidth(); + const int widgetHeight = glWidget->getDeviceHeight(); const float magnifyWidth = MAGNIFY_WIDTH * sizeMult; const float magnifyHeight = MAGNIFY_HEIGHT * sizeMult; @@ -960,7 +960,7 @@ void ApplicationOverlay::renderAudioMeter() { Application* application = Application::getInstance(); - QGLWidget* glWidget = application->getGLWidget(); + GLCanvas* glWidget = application->getGLWidget(); Audio* audio = application->getAudio(); // Display a single screen-size quad to create an alpha blended 'collision' flash @@ -968,7 +968,8 @@ 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(), audio->getCollisionSoundMagnitude()); + renderCollisionOverlay(glWidget->getDeviceWidth(), glWidget->getDeviceHeight(), + audio->getCollisionSoundMagnitude()); } } @@ -1018,16 +1019,16 @@ void ApplicationOverlay::renderAudioMeter() { if ((audio->getTimeSinceLastClip() > 0.f) && (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(glWidget->getDeviceWidth(), glWidget->getDeviceHeight(), magnitude, 1.0f); } audio->renderToolBox(MIRROR_VIEW_LEFT_PADDING + AUDIO_METER_GAP, audioMeterY, Menu::getInstance()->isOptionChecked(MenuOption::Mirror)); - audio->renderScope(glWidget->width(), glWidget->height()); + audio->renderScope(glWidget->getDeviceWidth(), glWidget->getDeviceHeight()); - audio->renderStats(WHITE_TEXT, glWidget->width(), glWidget->height()); + audio->renderStats(WHITE_TEXT, glWidget->getDeviceWidth(), glWidget->getDeviceHeight()); glBegin(GL_QUADS); if (isClipping) { @@ -1089,7 +1090,7 @@ void ApplicationOverlay::renderStatsAndLogs() { Application* application = Application::getInstance(); - QGLWidget* glWidget = application->getGLWidget(); + GLCanvas* glWidget = application->getGLWidget(); const OctreePacketProcessor& octreePacketProcessor = application->getOctreePacketProcessor(); BandwidthMeter* bandwidthMeter = application->getBandwidthMeter(); NodeBounds& nodeBoundsDisplay = application->getNodeBoundsDisplay(); @@ -1103,11 +1104,12 @@ void ApplicationOverlay::renderStatsAndLogs() { int horizontalOffset = MIRROR_VIEW_WIDTH + MIRROR_VIEW_LEFT_PADDING * 2; int voxelPacketsToProcess = octreePacketProcessor.packetsToProcessCount(); // Onscreen text about position, servers, etc - Stats::getInstance()->display(WHITE_TEXT, horizontalOffset, application->getFps(), application->getPacketsPerSecond(), application->getBytesPerSecond(), voxelPacketsToProcess); + Stats::getInstance()->display(WHITE_TEXT, horizontalOffset, application->getFps(), + 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, glWidget->getDeviceWidth() - 296, glWidget->getDeviceHeight() - 68, 296, 68); + bandwidthMeter->render(glWidget->getDeviceWidth(), glWidget->getDeviceHeight()); } } @@ -1120,7 +1122,8 @@ void ApplicationOverlay::renderStatsAndLogs() { (Menu::getInstance()->isOptionChecked(MenuOption::Stats) && Menu::getInstance()->isOptionChecked(MenuOption::Bandwidth)) ? 80 : 20; - drawText(glWidget->width() - 100, glWidget->height() - timerBottom, 0.30f, 0.0f, 0, frameTimer, WHITE_TEXT); + drawText(glWidget->getDeviceWidth() - 100, glWidget->getDeviceHeight() - timerBottom, + 0.30f, 0.0f, 0, frameTimer, WHITE_TEXT); } nodeBoundsDisplay.drawOverlay(); } @@ -1243,9 +1246,9 @@ void ApplicationOverlay::renderDomainConnectionStatusBorder() { NodeList* nodeList = NodeList::getInstance(); if (nodeList && !nodeList->getDomainHandler().isConnected()) { - QGLWidget* glWidget = Application::getInstance()->getGLWidget(); - int right = glWidget->width(); - int bottom = glWidget->height(); + GLCanvas* glWidget = Application::getInstance()->getGLWidget(); + int right = glWidget->getDeviceWidth(); + int bottom = glWidget->getDeviceHeight(); glColor3f(CONNECTION_STATUS_BORDER_COLOR[0], CONNECTION_STATUS_BORDER_COLOR[1], @@ -1264,7 +1267,7 @@ void ApplicationOverlay::renderDomainConnectionStatusBorder() { } QOpenGLFramebufferObject* ApplicationOverlay::getFramebufferObject() { - QSize size = Application::getInstance()->getGLWidget()->size(); + QSize size = Application::getInstance()->getGLWidget()->getDeviceSize(); if (!_framebufferObject || _framebufferObject->size() != size) { delete _framebufferObject; diff --git a/interface/src/ui/MetavoxelEditor.cpp b/interface/src/ui/MetavoxelEditor.cpp index dc669365e8..c59ef48570 100644 --- a/interface/src/ui/MetavoxelEditor.cpp +++ b/interface/src/ui/MetavoxelEditor.cpp @@ -920,7 +920,8 @@ void SetSpannerTool::applyEdit(const AttributePointer& attribute, const SharedOb Application::getInstance()->getTextureCache()->getPrimaryFramebufferObject()->release(); - glViewport(0, 0, Application::getInstance()->getGLWidget()->width(), Application::getInstance()->getGLWidget()->height()); + glViewport(0, 0, Application::getInstance()->getGLWidget()->getDeviceWidth(), + Application::getInstance()->getGLWidget()->getDeviceHeight()); // send the images off to the lab for processing QThreadPool::globalInstance()->start(new Voxelizer(size, cellBounds, diff --git a/interface/src/ui/NodeBounds.cpp b/interface/src/ui/NodeBounds.cpp index bcb5395a78..a17aed6c42 100644 --- a/interface/src/ui/NodeBounds.cpp +++ b/interface/src/ui/NodeBounds.cpp @@ -40,9 +40,9 @@ void NodeBounds::draw() { // Compute ray to find selected nodes later on. We can't use the pre-computed ray in Application because it centers // itself after the cursor disappears. Application* application = Application::getInstance(); - QGLWidget* glWidget = application->getGLWidget(); - float mouseX = application->getMouseX() / (float)glWidget->width(); - float mouseY = application->getMouseY() / (float)glWidget->height(); + GLCanvas* glWidget = application->getGLWidget(); + float mouseX = application->getMouseX() / (float)glWidget->getDeviceWidth(); + float mouseY = application->getMouseY() / (float)glWidget->getDeviceHeight(); glm::vec3 mouseRayOrigin; glm::vec3 mouseRayDirection; application->getViewFrustum()->computePickRay(mouseX, mouseY, mouseRayOrigin, mouseRayDirection); diff --git a/interface/src/ui/Stats.cpp b/interface/src/ui/Stats.cpp index 58a93fa0ae..76a803e2b8 100644 --- a/interface/src/ui/Stats.cpp +++ b/interface/src/ui/Stats.cpp @@ -56,8 +56,8 @@ Stats::Stats(): _metavoxelReceiveProgress(0), _metavoxelReceiveTotal(0) { - QGLWidget* glWidget = Application::getInstance()->getGLWidget(); - resetWidth(glWidget->width(), 0); + GLCanvas* glWidget = Application::getInstance()->getGLWidget(); + resetWidth(glWidget->getDeviceWidth(), 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) { - QGLWidget* glWidget = Application::getInstance()->getGLWidget(); + GLCanvas* glWidget = Application::getInstance()->getGLWidget(); 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 = glWidget->getDeviceWidth() - 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) { - QGLWidget* glWidget = Application::getInstance()->getGLWidget(); - int extraSpace = glWidget->width() - horizontalOffset -2 + GLCanvas* glWidget = Application::getInstance()->getGLWidget(); + int extraSpace = glWidget->getDeviceWidth() - 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 += glWidget->getDeviceWidth() - (_generalStatsWidth + _pingStatsWidth + _geoStatsWidth + 3); } } @@ -198,7 +198,7 @@ void Stats::display( int bytesPerSecond, int voxelPacketsToProcess) { - QGLWidget* glWidget = Application::getInstance()->getGLWidget(); + GLCanvas* glWidget = Application::getInstance()->getGLWidget(); 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(glWidget->getDeviceWidth(), horizontalOffset); _lastHorizontalOffset = horizontalOffset; } @@ -410,7 +410,8 @@ void Stats::display( } } - drawBackground(backgroundColor, horizontalOffset, 0, glWidget->width() - horizontalOffset, lines * STATS_PELS_PER_LINE + 10); + drawBackground(backgroundColor, horizontalOffset, 0, glWidget->getDeviceWidth() - horizontalOffset, + lines * STATS_PELS_PER_LINE + 10); horizontalOffset += 5; if (_expanded) { From 2fdfb125f2c52ad635508e65506bad3faa0e3e28 Mon Sep 17 00:00:00 2001 From: Andrew Meadows Date: Fri, 5 Sep 2014 16:55:24 -0700 Subject: [PATCH 18/50] removed signed/unsigned comparisons --- libraries/script-engine/src/TypedArrays.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/libraries/script-engine/src/TypedArrays.cpp b/libraries/script-engine/src/TypedArrays.cpp index 751d1385e5..c9663556d9 100644 --- a/libraries/script-engine/src/TypedArrays.cpp +++ b/libraries/script-engine/src/TypedArrays.cpp @@ -50,7 +50,7 @@ QScriptValue TypedArray::newInstance(QScriptValue array) { if (array.property(ARRAY_LENGTH_HANDLE).isValid()) { quint32 length = array.property(ARRAY_LENGTH_HANDLE).toInt32(); QScriptValue newArray = newInstance(length); - for (int i = 0; i < length; ++i) { + for (quint32 i = 0; i < length; ++i) { QScriptValue value = array.property(QString::number(i)); setProperty(newArray, engine()->toStringHandle(QString::number(i)), i * _bytesPerElement, (value.isNumber()) ? value : QScriptValue(0)); @@ -119,7 +119,7 @@ QScriptValue TypedArray::construct(QScriptContext* context, QScriptEngine* engin return QScriptValue(); } if (lengthArg.toInt32() < 0 || - byteOffsetArg.toInt32() + lengthArg.toInt32() * cls->_bytesPerElement > arrayBuffer->size()) { + byteOffsetArg.toInt32() + lengthArg.toInt32() * (qint32)(cls->_bytesPerElement) > arrayBuffer->size()) { engine->evaluate("throw \"RangeError: byteLength out of range\""); return QScriptValue(); } @@ -155,7 +155,7 @@ QScriptClass::QueryFlags TypedArray::queryProperty(const QScriptValue& object, quint32 byteOffset = object.data().property(_byteOffsetName).toInt32(); quint32 length = object.data().property(_lengthName).toInt32(); bool ok = false; - int pos = name.toArrayIndex(&ok); + quint32 pos = name.toArrayIndex(&ok); // Check that name is a valid index and arrayBuffer exists if (ok && pos >= 0 && pos < length) { From 51dca12a7b2b4a00eafb4b509067e68e96e7016e Mon Sep 17 00:00:00 2001 From: Andrew Meadows Date: Fri, 5 Sep 2014 16:55:42 -0700 Subject: [PATCH 19/50] added default case for switch statements which avoids warnings about unhandled enum values --- libraries/script-engine/src/XMLHttpRequestClass.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/libraries/script-engine/src/XMLHttpRequestClass.cpp b/libraries/script-engine/src/XMLHttpRequestClass.cpp index cb891c2ab1..fc8216551b 100644 --- a/libraries/script-engine/src/XMLHttpRequestClass.cpp +++ b/libraries/script-engine/src/XMLHttpRequestClass.cpp @@ -71,6 +71,8 @@ QScriptValue XMLHttpRequestClass::getStatus() const { return QScriptValue(408); case QNetworkReply::ContentOperationNotPermittedError: return QScriptValue(501); + default: + break; } } return QScriptValue(0); @@ -92,6 +94,8 @@ QString XMLHttpRequestClass::getStatusText() const { return "Timeout"; case QNetworkReply::ContentOperationNotPermittedError: return "Not Implemented"; + default: + break; } } return ""; From be4ec8920d35f75e5cf2e67632e46cab335744c7 Mon Sep 17 00:00:00 2001 From: Andrew Meadows Date: Fri, 5 Sep 2014 16:58:25 -0700 Subject: [PATCH 20/50] reorderd init of data members in ctor --- assignment-client/src/AssignmentClient.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/assignment-client/src/AssignmentClient.cpp b/assignment-client/src/AssignmentClient.cpp index 3e3c7c0609..24b6127d63 100644 --- a/assignment-client/src/AssignmentClient.cpp +++ b/assignment-client/src/AssignmentClient.cpp @@ -37,8 +37,8 @@ int hifiSockAddrMeta = qRegisterMetaType("HifiSockAddr"); AssignmentClient::AssignmentClient(int &argc, char **argv) : QCoreApplication(argc, argv), - _assignmentServerHostname(DEFAULT_ASSIGNMENT_SERVER_HOSTNAME), - _shutdownEventListener(this) + _shutdownEventListener(this), + _assignmentServerHostname(DEFAULT_ASSIGNMENT_SERVER_HOSTNAME) { LogUtils::init(); From 2f03f0fb0d86438362f0540aa17fe94cbb2dbd64 Mon Sep 17 00:00:00 2001 From: Andrew Meadows Date: Fri, 5 Sep 2014 17:00:23 -0700 Subject: [PATCH 21/50] removed unused variables --- assignment-client/src/audio/AudioMixer.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/assignment-client/src/audio/AudioMixer.cpp b/assignment-client/src/audio/AudioMixer.cpp index 3f5829b72f..044396f844 100644 --- a/assignment-client/src/audio/AudioMixer.cpp +++ b/assignment-client/src/audio/AudioMixer.cpp @@ -327,7 +327,6 @@ int AudioMixer::addStreamToMixForListeningNodeWithStream(PositionalAudioStream* const float FULL_POWER = 1.0f; const float SQUARE_ROOT_OF_TWO_OVER_TWO = 0.71f; const float HALF_POWER = SQUARE_ROOT_OF_TWO_OVER_TWO; - const float QUARTER_POWER = HALF_POWER * HALF_POWER; const float ONE_OVER_TWO_PI = 1.0f / TWO_PI; const float FILTER_CUTOFF_FREQUENCY_HZ = 1000.0f; @@ -344,8 +343,8 @@ int AudioMixer::addStreamToMixForListeningNodeWithStream(PositionalAudioStream* ((-1.0 * ONE_OVER_TWO_PI * (bearingRelativeAngleToSource + PI_OVER_TWO)) + HALF_POWER) : ((-1.0 * ONE_OVER_TWO_PI * (bearingRelativeAngleToSource - PI)) + HALF_POWER); - float distanceBetween = glm::length(relativePosition); #if 0 + float distanceBetween = glm::length(relativePosition); qDebug() << "avatar=" << listeningNodeStream << "gainL=" From 5c75b53c0d081bd5e498705bcf30e2c978026157 Mon Sep 17 00:00:00 2001 From: Andrew Meadows Date: Fri, 5 Sep 2014 17:06:42 -0700 Subject: [PATCH 22/50] removed singed/unsigned comparisons --- interface/src/avatar/ModelReferential.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/interface/src/avatar/ModelReferential.cpp b/interface/src/avatar/ModelReferential.cpp index 063b872f1f..eb2a61a819 100644 --- a/interface/src/avatar/ModelReferential.cpp +++ b/interface/src/avatar/ModelReferential.cpp @@ -108,7 +108,7 @@ JointReferential::JointReferential(Referential* referential, EntityTree* tree, A const EntityItem* item = _tree->findEntityByID(_entityID); const Model* model = getModel(item); - if (!isValid() || model == NULL || _jointIndex >= model->getJointStateCount()) { + if (!isValid() || model == NULL || _jointIndex >= (uint32_t)(model->getJointStateCount())) { _refScale = item->getRadius(); model->getJointRotationInWorldFrame(_jointIndex, _refRotation); model->getJointPositionInWorldFrame(_jointIndex, _refPosition); @@ -123,7 +123,7 @@ JointReferential::JointReferential(uint32_t jointIndex, const QUuid& entityID, E _type = JOINT; const EntityItem* item = _tree->findEntityByID(_entityID); const Model* model = getModel(item); - if (!isValid() || model == NULL || _jointIndex >= model->getJointStateCount()) { + if (!isValid() || model == NULL || _jointIndex >= (uint32_t)(model->getJointStateCount())) { qDebug() << "JointReferential::constructor(): Not Valid"; _isValid = false; return; @@ -142,7 +142,7 @@ JointReferential::JointReferential(uint32_t jointIndex, const QUuid& entityID, E void JointReferential::update() { const EntityItem* item = _tree->findEntityByID(_entityID); const Model* model = getModel(item); - if (!isValid() || model == NULL || _jointIndex >= model->getJointStateCount()) { + if (!isValid() || model == NULL || _jointIndex >= (uint32_t)(model->getJointStateCount())) { return; } @@ -189,4 +189,4 @@ int JointReferential::unpackExtraData(const unsigned char *sourceBuffer, int siz sourceBuffer += sizeof(_jointIndex); return sourceBuffer - startPosition; -} \ No newline at end of file +} From c2cd23a54cba68322effc3abcd4160520c292c7d Mon Sep 17 00:00:00 2001 From: Andrzej Kapolka Date: Fri, 5 Sep 2014 17:07:37 -0700 Subject: [PATCH 23/50] Mouse coordinate fix. --- interface/src/Application.cpp | 21 +++++++++++++++------ interface/src/Application.h | 2 ++ interface/src/GLCanvas.cpp | 8 ++++++++ interface/src/GLCanvas.h | 3 +++ 4 files changed, 28 insertions(+), 6 deletions(-) diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index 9b30e03697..6fff0bf171 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -1166,8 +1166,7 @@ void Application::mouseMoveEvent(QMouseEvent* event, unsigned int deviceID) { _seenMouseMove = true; } - _mouseX = event->x(); - _mouseY = event->y(); + setMousePosition(event, deviceID); } void Application::mousePressEvent(QMouseEvent* event, unsigned int deviceID) { @@ -1181,8 +1180,7 @@ void Application::mousePressEvent(QMouseEvent* event, unsigned int deviceID) { if (activeWindow() == _window) { if (event->button() == Qt::LeftButton) { - _mouseX = event->x(); - _mouseY = event->y(); + setMousePosition(event, deviceID); _mouseDragStartedX = _mouseX; _mouseDragStartedY = _mouseY; _mousePressed = true; @@ -1213,8 +1211,7 @@ void Application::mouseReleaseEvent(QMouseEvent* event, unsigned int deviceID) { if (activeWindow() == _window) { if (event->button() == Qt::LeftButton) { - _mouseX = event->x(); - _mouseY = event->y(); + setMousePosition(event, deviceID); _mousePressed = false; checkBandwidthMeterClick(); if (Menu::getInstance()->isOptionChecked(MenuOption::Stats)) { @@ -2328,6 +2325,18 @@ int Application::sendNackPackets() { return packetsSent; } +void Application::setMousePosition(QMouseEvent* event, unsigned int deviceID) { + if (deviceID > 0) { + // simulated events are in device coordinates + _mouseX = event->x(); + _mouseY = event->y(); + + } else { + _mouseX = _glWidget->getDeviceX(event->x()); + _mouseY = _glWidget->getDeviceY(event->y()); + } +} + void Application::queryOctree(NodeType_t serverType, PacketType packetType, NodeToJurisdictionMap& jurisdictions) { //qDebug() << ">>> inside... queryOctree()... _viewFrustum.getFieldOfView()=" << _viewFrustum.getFieldOfView(); diff --git a/interface/src/Application.h b/interface/src/Application.h index 302c1bf2d3..73f8555dbb 100644 --- a/interface/src/Application.h +++ b/interface/src/Application.h @@ -435,6 +435,8 @@ private: int sendNackPackets(); + void setMousePosition(QMouseEvent* event, unsigned int deviceID); + MainWindow* _window; GLCanvas* _glWidget; // our GLCanvas has a couple extra features diff --git a/interface/src/GLCanvas.cpp b/interface/src/GLCanvas.cpp index 108b9ba829..e63e79f1f0 100644 --- a/interface/src/GLCanvas.cpp +++ b/interface/src/GLCanvas.cpp @@ -43,6 +43,14 @@ int GLCanvas::getDeviceHeight() const { return height() * (windowHandle() ? windowHandle()->devicePixelRatio() : 1.0f); } +int GLCanvas::getDeviceX(int x) const { + return x * getDeviceWidth() / width(); +} + +int GLCanvas::getDeviceY(int y) const { + return y * getDeviceHeight() / height(); +} + void GLCanvas::initializeGL() { Application::getInstance()->initializeGL(); setAttribute(Qt::WA_AcceptTouchEvents); diff --git a/interface/src/GLCanvas.h b/interface/src/GLCanvas.h index 0d381fa0bf..22cdaae75f 100644 --- a/interface/src/GLCanvas.h +++ b/interface/src/GLCanvas.h @@ -26,6 +26,9 @@ public: int getDeviceHeight() const; QSize getDeviceSize() const { return QSize(getDeviceWidth(), getDeviceHeight()); } + int getDeviceX(int x) const; + int getDeviceY(int y) const; + protected: QTimer _frameTimer; From 1d7ac23aa169bb28f097b0caf563f5331a59f0f6 Mon Sep 17 00:00:00 2001 From: Andrew Meadows Date: Fri, 5 Sep 2014 17:10:13 -0700 Subject: [PATCH 24/50] removed signed/unsigned comparison --- interface/src/devices/DeviceTracker.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/interface/src/devices/DeviceTracker.cpp b/interface/src/devices/DeviceTracker.cpp index 47301ad826..265a77b362 100644 --- a/interface/src/devices/DeviceTracker.cpp +++ b/interface/src/devices/DeviceTracker.cpp @@ -38,7 +38,7 @@ DeviceTracker* DeviceTracker::getDevice(const Name& name) { } DeviceTracker* DeviceTracker::getDevice(DeviceTracker::ID deviceID) { - if ((deviceID >= 0) && (deviceID < Singleton::get()->_devicesVector.size())) { + if ((deviceID >= 0) && (deviceID < (int)(Singleton::get()->_devicesVector.size()))) { return Singleton::get()->_devicesVector[ deviceID ]; } else { return NULL; From 526d998924f4417d47ebdc1fb17c69118759f71d Mon Sep 17 00:00:00 2001 From: Andrew Meadows Date: Fri, 5 Sep 2014 17:21:15 -0700 Subject: [PATCH 25/50] removed warnigs about ill-formed narrowing conversion --- tests/octree/src/OctreeTests.cpp | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/tests/octree/src/OctreeTests.cpp b/tests/octree/src/OctreeTests.cpp index e564754974..fee8f3ff37 100644 --- a/tests/octree/src/OctreeTests.cpp +++ b/tests/octree/src/OctreeTests.cpp @@ -115,7 +115,7 @@ void OctreeTests::propertyFlagsTests(bool verbose) { outputBufferBits((const unsigned char*)encoded.constData(), encoded.size()); } - char expectedBytes[] = { 196, 15, 2 }; + char expectedBytes[] = { (char)196, (char)15, (char)2 }; QByteArray expectedResult(expectedBytes, sizeof(expectedBytes)/sizeof(expectedBytes[0])); if (encoded == expectedResult) { @@ -140,7 +140,7 @@ void OctreeTests::propertyFlagsTests(bool verbose) { outputBufferBits((const unsigned char*)encoded.constData(), encoded.size()); } - char expectedBytesB[] = { 136, 30 }; + char expectedBytesB[] = { (char)136, (char)30 }; QByteArray expectedResultB(expectedBytesB, sizeof(expectedBytesB)/sizeof(expectedBytesB[0])); if (encoded == expectedResultB) { @@ -172,7 +172,7 @@ void OctreeTests::propertyFlagsTests(bool verbose) { qDebug() << "encoded="; outputBufferBits((const unsigned char*)encoded.constData(), encoded.size()); } - char expectedBytes[] = { 196, 15, 2 }; + char expectedBytes[] = { (char)196, (char)15, (char)2 }; QByteArray expectedResult(expectedBytes, sizeof(expectedBytes)/sizeof(expectedBytes[0])); if (encoded == expectedResult) { @@ -197,7 +197,7 @@ void OctreeTests::propertyFlagsTests(bool verbose) { outputBufferBits((const unsigned char*)encoded.constData(), encoded.size()); } - char expectedBytesB[] = { 136, 30 }; + char expectedBytesB[] = { (char)136, (char)30 }; QByteArray expectedResultB(expectedBytesB, sizeof(expectedBytesB)/sizeof(expectedBytesB[0])); if (encoded == expectedResultB) { @@ -231,7 +231,7 @@ void OctreeTests::propertyFlagsTests(bool verbose) { outputBufferBits((const unsigned char*)encoded.constData(), encoded.size()); } - char expectedBytes[] = { 196, 15, 2 }; + char expectedBytes[] = { (char)196, (char)15, (char)2 }; QByteArray expectedResult(expectedBytes, sizeof(expectedBytes)/sizeof(expectedBytes[0])); if (encoded == expectedResult) { @@ -264,7 +264,7 @@ void OctreeTests::propertyFlagsTests(bool verbose) { outputBufferBits((const unsigned char*)encoded.constData(), encoded.size()); } - char expectedBytes[] = { 196, 15, 2 }; + char expectedBytes[] = { (char)196, (char)15, (char)2 }; QByteArray expectedResult(expectedBytes, sizeof(expectedBytes)/sizeof(expectedBytes[0])); if (encoded == expectedResult) { @@ -296,7 +296,7 @@ void OctreeTests::propertyFlagsTests(bool verbose) { outputBufferBits((const unsigned char*)encoded.constData(), encoded.size()); } - char expectedBytes[] = { 196, 15, 2 }; + char expectedBytes[] = { (char)196, (char)15, (char)2 }; QByteArray expectedResult(expectedBytes, sizeof(expectedBytes)/sizeof(expectedBytes[0])); if (encoded == expectedResult) { @@ -329,7 +329,7 @@ void OctreeTests::propertyFlagsTests(bool verbose) { outputBufferBits((const unsigned char*)encoded.constData(), encoded.size()); } - char expectedBytes[] = { 196, 15, 2 }; + char expectedBytes[] = { (char)196, (char)15, (char)2 }; QByteArray expectedResult(expectedBytes, sizeof(expectedBytes)/sizeof(expectedBytes[0])); if (encoded == expectedResult) { @@ -362,7 +362,7 @@ void OctreeTests::propertyFlagsTests(bool verbose) { outputBufferBits((const unsigned char*)encoded.constData(), encoded.size()); } - char expectedBytes[] = { 196, 15, 2 }; + char expectedBytes[] = { (char)196, (char)15, (char)2 }; QByteArray expectedResult(expectedBytes, sizeof(expectedBytes)/sizeof(expectedBytes[0])); if (encoded == expectedResult) { @@ -395,7 +395,7 @@ void OctreeTests::propertyFlagsTests(bool verbose) { outputBufferBits((const unsigned char*)encoded.constData(), encoded.size()); } - char expectedBytes[] = { 196, 15, 2 }; + char expectedBytes[] = { (char)196, (char)15, (char)2 }; QByteArray expectedResult(expectedBytes, sizeof(expectedBytes)/sizeof(expectedBytes[0])); if (encoded == expectedResult) { @@ -432,7 +432,7 @@ void OctreeTests::propertyFlagsTests(bool verbose) { outputBufferBits((const unsigned char*)encoded.constData(), encoded.size()); } - char expectedBytes[] = { 196, 15, 2 }; + char expectedBytes[] = { (char)196, (char)15, (char)2 }; QByteArray expectedResult(expectedBytes, sizeof(expectedBytes)/sizeof(expectedBytes[0])); if (encoded == expectedResult) { @@ -642,7 +642,7 @@ void OctreeTests::propertyFlagsTests(bool verbose) { qDebug() << "props.getHasProperty(PARTICLE_PROP_VISIBLE)" << (props.getHasProperty(PARTICLE_PROP_VISIBLE)) << "{ expect true }"; } - char expectedBytesD[] = { 136, 16 }; + char expectedBytesD[] = { (char)136, (char)16 }; QByteArray expectedResultD(expectedBytesD, sizeof(expectedBytesD)/sizeof(expectedBytesD[0])); testsTaken++; From 0b2d0a0b0776b5a6a5e3b64a49203266fa16de25 Mon Sep 17 00:00:00 2001 From: Andrzej Kapolka Date: Fri, 5 Sep 2014 17:30:19 -0700 Subject: [PATCH 26/50] Fix for mouse events. --- interface/src/Application.cpp | 30 ++++++++++++++++-------------- interface/src/Application.h | 2 +- 2 files changed, 17 insertions(+), 15 deletions(-) diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index 6fff0bf171..12bd4331ba 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -1151,7 +1151,8 @@ void Application::mouseMoveEvent(QMouseEvent* event, unsigned int deviceID) { showMouse = false; } - _controllerScriptingInterface.emitMouseMoveEvent(event, deviceID); // send events to any registered scripts + QMouseEvent deviceEvent = getDeviceEvent(event, deviceID); + _controllerScriptingInterface.emitMouseMoveEvent(&deviceEvent, deviceID); // send events to any registered scripts // if one of our scripts have asked to capture this event, then stop processing it if (_controllerScriptingInterface.isMouseCaptured()) { @@ -1166,11 +1167,13 @@ void Application::mouseMoveEvent(QMouseEvent* event, unsigned int deviceID) { _seenMouseMove = true; } - setMousePosition(event, deviceID); + _mouseX = deviceEvent.x(); + _mouseY = deviceEvent.y(); } void Application::mousePressEvent(QMouseEvent* event, unsigned int deviceID) { - _controllerScriptingInterface.emitMousePressEvent(event); // send events to any registered scripts + QMouseEvent deviceEvent = getDeviceEvent(event, deviceID); + _controllerScriptingInterface.emitMousePressEvent(&deviceEvent); // send events to any registered scripts // if one of our scripts have asked to capture this event, then stop processing it if (_controllerScriptingInterface.isMouseCaptured()) { @@ -1180,7 +1183,8 @@ void Application::mousePressEvent(QMouseEvent* event, unsigned int deviceID) { if (activeWindow() == _window) { if (event->button() == Qt::LeftButton) { - setMousePosition(event, deviceID); + _mouseX = deviceEvent.x(); + _mouseY = deviceEvent.y(); _mouseDragStartedX = _mouseX; _mouseDragStartedY = _mouseY; _mousePressed = true; @@ -1202,7 +1206,8 @@ void Application::mousePressEvent(QMouseEvent* event, unsigned int deviceID) { } void Application::mouseReleaseEvent(QMouseEvent* event, unsigned int deviceID) { - _controllerScriptingInterface.emitMouseReleaseEvent(event); // send events to any registered scripts + QMouseEvent deviceEvent = getDeviceEvent(event, deviceID); + _controllerScriptingInterface.emitMouseReleaseEvent(&deviceEvent); // send events to any registered scripts // if one of our scripts have asked to capture this event, then stop processing it if (_controllerScriptingInterface.isMouseCaptured()) { @@ -1211,7 +1216,8 @@ void Application::mouseReleaseEvent(QMouseEvent* event, unsigned int deviceID) { if (activeWindow() == _window) { if (event->button() == Qt::LeftButton) { - setMousePosition(event, deviceID); + _mouseX = deviceEvent.x(); + _mouseY = deviceEvent.y(); _mousePressed = false; checkBandwidthMeterClick(); if (Menu::getInstance()->isOptionChecked(MenuOption::Stats)) { @@ -2325,16 +2331,12 @@ int Application::sendNackPackets() { return packetsSent; } -void Application::setMousePosition(QMouseEvent* event, unsigned int deviceID) { +QMouseEvent Application::getDeviceEvent(QMouseEvent* event, unsigned int deviceID) { if (deviceID > 0) { - // simulated events are in device coordinates - _mouseX = event->x(); - _mouseY = event->y(); - - } else { - _mouseX = _glWidget->getDeviceX(event->x()); - _mouseY = _glWidget->getDeviceY(event->y()); + return *event; } + return QMouseEvent(event->type(), QPointF(_glWidget->getDeviceX(event->x()), _glWidget->getDeviceY(event->y())), + event->windowPos(), event->screenPos(), event->button(), event->buttons(), event->modifiers()); } void Application::queryOctree(NodeType_t serverType, PacketType packetType, NodeToJurisdictionMap& jurisdictions) { diff --git a/interface/src/Application.h b/interface/src/Application.h index 73f8555dbb..14d74012b5 100644 --- a/interface/src/Application.h +++ b/interface/src/Application.h @@ -435,7 +435,7 @@ private: int sendNackPackets(); - void setMousePosition(QMouseEvent* event, unsigned int deviceID); + QMouseEvent getDeviceEvent(QMouseEvent* event, unsigned int deviceID); MainWindow* _window; GLCanvas* _glWidget; // our GLCanvas has a couple extra features From bd8fc75305f546766445e0bd38210ffce12eb117 Mon Sep 17 00:00:00 2001 From: Andrew Meadows Date: Fri, 5 Sep 2014 17:51:18 -0700 Subject: [PATCH 27/50] fix bug: zero velocity when teleporting to new locations --- interface/src/avatar/Avatar.cpp | 14 ++++++++++++++ interface/src/avatar/Avatar.h | 3 +++ interface/src/avatar/MyAvatar.cpp | 4 ++-- libraries/avatars/src/AvatarData.h | 2 +- 4 files changed, 20 insertions(+), 3 deletions(-) diff --git a/interface/src/avatar/Avatar.cpp b/interface/src/avatar/Avatar.cpp index b8def5bebd..b5b238b9d7 100644 --- a/interface/src/avatar/Avatar.cpp +++ b/interface/src/avatar/Avatar.cpp @@ -223,6 +223,20 @@ void Avatar::measureMotionDerivatives(float deltaTime) { _lastOrientation = getOrientation(); } +void Avatar::setPosition(const glm::vec3 position, bool overideReferential) { + AvatarData::setPosition(position, overideReferential); + _lastPosition = position; + _velocity = glm::vec3(0.0f); + _lastVelocity = glm::vec3(0.0f); +} + +void Avatar::slamPosition(const glm::vec3& newPosition) { + _position = newPosition; + _lastPosition = newPosition; + _velocity = glm::vec3(0.0f); + _lastVelocity = glm::vec3(0.0f); +} + void Avatar::setMouseRay(const glm::vec3 &origin, const glm::vec3 &direction) { _mouseRayOrigin = origin; _mouseRayDirection = direction; diff --git a/interface/src/avatar/Avatar.h b/interface/src/avatar/Avatar.h index 8923a67994..43b5150a48 100755 --- a/interface/src/avatar/Avatar.h +++ b/interface/src/avatar/Avatar.h @@ -160,6 +160,9 @@ public: /// Scales a world space position vector relative to the avatar position and scale /// \param vector position to be scaled. Will store the result void scaleVectorRelativeToPosition(glm::vec3 &positionToScale) const; + + void setPosition(const glm::vec3 position, bool overideReferential = false); + void slamPosition(const glm::vec3& newPosition); public slots: void updateCollisionGroups(); diff --git a/interface/src/avatar/MyAvatar.cpp b/interface/src/avatar/MyAvatar.cpp index b3468a9214..4b0e4eef5a 100644 --- a/interface/src/avatar/MyAvatar.cpp +++ b/interface/src/avatar/MyAvatar.cpp @@ -1767,7 +1767,7 @@ void MyAvatar::maybeUpdateBillboard() { void MyAvatar::goHome() { qDebug("Going Home!"); - setPosition(START_LOCATION); + slamPosition(START_LOCATION); } void MyAvatar::increaseSize() { @@ -1827,7 +1827,7 @@ void MyAvatar::goToLocationFromAddress(const QJsonObject& locationObject) { const float DISTANCE_TO_USER = 2.0f; glm::vec3 newPosition = glm::vec3(coordinateItems[0].toFloat(), coordinateItems[1].toFloat(), coordinateItems[2].toFloat()) - newOrientation * IDENTITY_FRONT * DISTANCE_TO_USER; - setPosition(newPosition); + slamPosition(newPosition); emit transformChanged(); } diff --git a/libraries/avatars/src/AvatarData.h b/libraries/avatars/src/AvatarData.h index 8e7082fc1e..d70876722b 100755 --- a/libraries/avatars/src/AvatarData.h +++ b/libraries/avatars/src/AvatarData.h @@ -145,7 +145,7 @@ public: const QUuid& getSessionUUID() { return _sessionUUID; } const glm::vec3& getPosition(); - void setPosition(const glm::vec3 position, bool overideReferential = false); + virtual void setPosition(const glm::vec3 position, bool overideReferential = false); glm::vec3 getHandPosition() const; void setHandPosition(const glm::vec3& handPosition); From 68fa44f845aa5b45c851079f47eb7bf050101d5a Mon Sep 17 00:00:00 2001 From: Craig Hansen-Sturm Date: Fri, 5 Sep 2014 18:30:39 -0700 Subject: [PATCH 28/50] audio menu changes to support tone and noise generators --- interface/src/Menu.cpp | 24 ++++++++++++++++++++++-- interface/src/Menu.h | 4 +++- 2 files changed, 25 insertions(+), 3 deletions(-) diff --git a/interface/src/Menu.cpp b/interface/src/Menu.cpp index 0dcfd60051..c2620c1e46 100644 --- a/interface/src/Menu.cpp +++ b/interface/src/Menu.cpp @@ -544,11 +544,31 @@ Menu::Menu() : 0, this, SLOT(muteEnvironment())); - addCheckableActionToQMenuAndActionHash(audioDebugMenu, MenuOption::AudioToneInjection, + + addCheckableActionToQMenuAndActionHash(audioDebugMenu, MenuOption::AudioSourceInject, 0, false, appInstance->getAudio(), - SLOT(toggleToneInjection())); + SLOT(toggleAudioSourceInject())); + QMenu* audioSourceMenu = audioDebugMenu->addMenu("Generated Audio Source"); + { + QAction *pinkNoise = addCheckableActionToQMenuAndActionHash(audioSourceMenu, MenuOption::AudioSourcePinkNoise, + 0, + false, + appInstance->getAudio(), + SLOT(selectAudioSourcePinkNoise())); + + QAction *sine440 = addCheckableActionToQMenuAndActionHash(audioSourceMenu, MenuOption::AudioSourceSine440, + 0, + true, + appInstance->getAudio(), + SLOT(selectAudioSourceSine440)); + + QActionGroup* audioSourceGroup = new QActionGroup(audioSourceMenu); + audioSourceGroup->addAction(pinkNoise); + audioSourceGroup->addAction(sine440); + } + addCheckableActionToQMenuAndActionHash(audioDebugMenu, MenuOption::AudioScope, Qt::CTRL | Qt::Key_P, false, appInstance->getAudio(), diff --git a/interface/src/Menu.h b/interface/src/Menu.h index 1d57da2891..a00da23b7b 100644 --- a/interface/src/Menu.h +++ b/interface/src/Menu.h @@ -346,7 +346,9 @@ namespace MenuOption { const QString AudioSpatialProcessingSlightlyRandomSurfaces = "Slightly Random Surfaces"; const QString AudioSpatialProcessingStereoSource = "Stereo Source"; const QString AudioSpatialProcessingWithDiffusions = "With Diffusions"; - const QString AudioToneInjection = "Inject Test Tone"; + const QString AudioSourceInject = "Generated Audio"; + const QString AudioSourcePinkNoise = "Pink Noise"; + const QString AudioSourceSine440 = "Sine 440hz"; const QString Avatars = "Avatars"; const QString AvatarsReceiveShadows = "Avatars Receive Shadows"; const QString Bandwidth = "Bandwidth Display"; From 9e21d26a6dbcb749e195628a9d28bb550e0cf7dd Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Fri, 5 Sep 2014 19:03:44 -0700 Subject: [PATCH 29/50] improve ping behavior and clockskew in octree servers by introducing datagramprocessing thread --- .../src/octree/OctreeQueryNode.cpp | 2 +- .../src/octree/OctreeQueryNode.h | 2 +- assignment-client/src/octree/OctreeServer.cpp | 113 +++++++++++------- assignment-client/src/octree/OctreeServer.h | 5 +- .../octree/OctreeServerDatagramProcessor.cpp | 55 +++++++++ .../octree/OctreeServerDatagramProcessor.h | 32 +++++ 6 files changed, 165 insertions(+), 44 deletions(-) create mode 100644 assignment-client/src/octree/OctreeServerDatagramProcessor.cpp create mode 100644 assignment-client/src/octree/OctreeServerDatagramProcessor.h diff --git a/assignment-client/src/octree/OctreeQueryNode.cpp b/assignment-client/src/octree/OctreeQueryNode.cpp index 57f408adf0..2d8d8d357e 100644 --- a/assignment-client/src/octree/OctreeQueryNode.cpp +++ b/assignment-client/src/octree/OctreeQueryNode.cpp @@ -389,7 +389,7 @@ const QByteArray* OctreeQueryNode::getNextNackedPacket() { return NULL; } -void OctreeQueryNode::parseNackPacket(QByteArray& packet) { +void OctreeQueryNode::parseNackPacket(const QByteArray& packet) { int numBytesPacketHeader = numBytesForPacketHeader(packet); const unsigned char* dataAt = reinterpret_cast(packet.data()) + numBytesPacketHeader; diff --git a/assignment-client/src/octree/OctreeQueryNode.h b/assignment-client/src/octree/OctreeQueryNode.h index aeb5c852e4..d7b660f18a 100644 --- a/assignment-client/src/octree/OctreeQueryNode.h +++ b/assignment-client/src/octree/OctreeQueryNode.h @@ -109,7 +109,7 @@ public: OCTREE_PACKET_SEQUENCE getSequenceNumber() const { return _sequenceNumber; } - void parseNackPacket(QByteArray& packet); + void parseNackPacket(const QByteArray& packet); bool hasNextNackedPacket() const; const QByteArray* getNextNackedPacket(); diff --git a/assignment-client/src/octree/OctreeServer.cpp b/assignment-client/src/octree/OctreeServer.cpp index ca6c498aa3..52a027852c 100644 --- a/assignment-client/src/octree/OctreeServer.cpp +++ b/assignment-client/src/octree/OctreeServer.cpp @@ -25,6 +25,7 @@ #include "OctreeServer.h" #include "OctreeServerConsts.h" +#include "OctreeServerDatagramProcessor.h" OctreeServer* OctreeServer::_instance = NULL; int OctreeServer::_clientCount = 0; @@ -827,55 +828,83 @@ void OctreeServer::parsePayload() { } } -void OctreeServer::readPendingDatagrams() { - QByteArray receivedPacket; - HifiSockAddr senderSockAddr; - +void OctreeServer::readPendingDatagram(const QByteArray& receivedPacket, const HifiSockAddr& senderSockAddr) { NodeList* nodeList = NodeList::getInstance(); - while (readAvailableDatagram(receivedPacket, senderSockAddr)) { - if (nodeList->packetVersionAndHashMatch(receivedPacket)) { - PacketType packetType = packetTypeForPacket(receivedPacket); - SharedNodePointer matchingNode = nodeList->sendingNodeForPacket(receivedPacket); - if (packetType == getMyQueryMessageType()) { - // If we got a query packet, then we're talking to an agent, and we - // need to make sure we have it in our nodeList. - if (matchingNode) { - nodeList->updateNodeWithDataFromPacket(matchingNode, receivedPacket); - OctreeQueryNode* nodeData = (OctreeQueryNode*)matchingNode->getLinkedData(); - if (nodeData && !nodeData->isOctreeSendThreadInitalized()) { - - // NOTE: this is an important aspect of the proper ref counting. The send threads/node data need to - // know that the OctreeServer/Assignment will not get deleted on it while it's still active. The - // solution is to get the shared pointer for the current assignment. We need to make sure this is the - // same SharedAssignmentPointer that was ref counted by the assignment client. - SharedAssignmentPointer sharedAssignment = AssignmentClient::getCurrentAssignment(); - nodeData->initializeOctreeSendThread(sharedAssignment, matchingNode); - } + if (nodeList->packetVersionAndHashMatch(receivedPacket)) { + PacketType packetType = packetTypeForPacket(receivedPacket); + SharedNodePointer matchingNode = nodeList->sendingNodeForPacket(receivedPacket); + if (packetType == getMyQueryMessageType()) { + // If we got a query packet, then we're talking to an agent, and we + // need to make sure we have it in our nodeList. + if (matchingNode) { + nodeList->updateNodeWithDataFromPacket(matchingNode, receivedPacket); + OctreeQueryNode* nodeData = (OctreeQueryNode*)matchingNode->getLinkedData(); + if (nodeData && !nodeData->isOctreeSendThreadInitalized()) { + + // NOTE: this is an important aspect of the proper ref counting. The send threads/node data need to + // know that the OctreeServer/Assignment will not get deleted on it while it's still active. The + // solution is to get the shared pointer for the current assignment. We need to make sure this is the + // same SharedAssignmentPointer that was ref counted by the assignment client. + SharedAssignmentPointer sharedAssignment = AssignmentClient::getCurrentAssignment(); + nodeData->initializeOctreeSendThread(sharedAssignment, matchingNode); } - } else if (packetType == PacketTypeOctreeDataNack) { - // If we got a nack packet, then we're talking to an agent, and we - // need to make sure we have it in our nodeList. - if (matchingNode) { - OctreeQueryNode* nodeData = (OctreeQueryNode*)matchingNode->getLinkedData(); - if (nodeData) { - nodeData->parseNackPacket(receivedPacket); - } - } - } else if (packetType == PacketTypeJurisdictionRequest) { - _jurisdictionSender->queueReceivedPacket(matchingNode, receivedPacket); - } else if (packetType == PacketTypeSignedTransactionPayment) { - handleSignedTransactionPayment(packetType, receivedPacket); - } else if (_octreeInboundPacketProcessor && getOctree()->handlesEditPacketType(packetType)) { - _octreeInboundPacketProcessor->queueReceivedPacket(matchingNode, receivedPacket); - } else { - // let processNodeData handle it. - NodeList::getInstance()->processNodeData(senderSockAddr, receivedPacket); } + } else if (packetType == PacketTypeOctreeDataNack) { + // If we got a nack packet, then we're talking to an agent, and we + // need to make sure we have it in our nodeList. + if (matchingNode) { + OctreeQueryNode* nodeData = (OctreeQueryNode*)matchingNode->getLinkedData(); + if (nodeData) { + nodeData->parseNackPacket(receivedPacket); + } + } + } else if (packetType == PacketTypeJurisdictionRequest) { + _jurisdictionSender->queueReceivedPacket(matchingNode, receivedPacket); + } else if (packetType == PacketTypeSignedTransactionPayment) { + handleSignedTransactionPayment(packetType, receivedPacket); + } else if (_octreeInboundPacketProcessor && getOctree()->handlesEditPacketType(packetType)) { + _octreeInboundPacketProcessor->queueReceivedPacket(matchingNode, receivedPacket); + } else { + // let processNodeData handle it. + NodeList::getInstance()->processNodeData(senderSockAddr, receivedPacket); } } } +void OctreeServer::setupDatagramProcessingThread() { + NodeList* nodeList = NodeList::getInstance(); + + // we do not want this event loop to be the handler for UDP datagrams, so disconnect + disconnect(&nodeList->getNodeSocket(), 0, this, 0); + + // setup a QThread with us as parent that will house the AudioMixerDatagramProcessor + _datagramProcessingThread = new QThread(this); + + // create an AudioMixerDatagramProcessor and move it to that thread + OctreeServerDatagramProcessor* datagramProcessor = new OctreeServerDatagramProcessor(nodeList->getNodeSocket(), thread()); + datagramProcessor->moveToThread(_datagramProcessingThread); + + // remove the NodeList as the parent of the node socket + nodeList->getNodeSocket().setParent(NULL); + nodeList->getNodeSocket().moveToThread(_datagramProcessingThread); + + // let the datagram processor handle readyRead from node socket + connect(&nodeList->getNodeSocket(), &QUdpSocket::readyRead, + datagramProcessor, &OctreeServerDatagramProcessor::readPendingDatagrams); + + // connect to the datagram processing thread signal that tells us we have to handle a packet + connect(datagramProcessor, &OctreeServerDatagramProcessor::packetRequiresProcessing, this, &OctreeServer::readPendingDatagram); + + // delete the datagram processor and the associated thread when the QThread quits + connect(_datagramProcessingThread, &QThread::finished, datagramProcessor, &QObject::deleteLater); + connect(datagramProcessor, &QObject::destroyed, _datagramProcessingThread, &QThread::deleteLater); + + // start the datagram processing thread + _datagramProcessingThread->start(); + +} + void OctreeServer::run() { _safeServerName = getMyServerName(); @@ -887,6 +916,8 @@ void OctreeServer::run() { // use common init to setup common timers and logging commonInit(getMyLoggingServerTargetName(), getMyNodeType()); + setupDatagramProcessingThread(); + // Now would be a good time to parse our arguments, if we got them as assignment if (getPayload().size() > 0) { parsePayload(); diff --git a/assignment-client/src/octree/OctreeServer.h b/assignment-client/src/octree/OctreeServer.h index f24cdc5af2..fda3187892 100644 --- a/assignment-client/src/octree/OctreeServer.h +++ b/assignment-client/src/octree/OctreeServer.h @@ -123,13 +123,15 @@ public: public slots: /// runs the voxel server assignment void run(); - void readPendingDatagrams(); void nodeAdded(SharedNodePointer node); void nodeKilled(SharedNodePointer node); void sendStatsPacket(); void handleSignedTransactionPaymentResponse(const QJsonObject& jsonObject); + void readPendingDatagrams() { }; // this will not be called since our datagram processing thread will handle + void readPendingDatagram(const QByteArray& receivedPacket, const HifiSockAddr& senderSockAddr); + protected: void parsePayload(); void initHTTPManager(int port); @@ -140,6 +142,7 @@ protected: QString getStatusLink(); void handleSignedTransactionPayment(PacketType packetType, const QByteArray& datagram); + void setupDatagramProcessingThread(); int _argc; const char** _argv; diff --git a/assignment-client/src/octree/OctreeServerDatagramProcessor.cpp b/assignment-client/src/octree/OctreeServerDatagramProcessor.cpp new file mode 100644 index 0000000000..0d3c622900 --- /dev/null +++ b/assignment-client/src/octree/OctreeServerDatagramProcessor.cpp @@ -0,0 +1,55 @@ +// +// OctreeServerDatagramProcessor.cpp +// assignment-client/src +// +// Created by Brad Hefta-Gaub on 2014-09-05 +// Copyright 2014 High Fidelity, Inc. +// +// Distributed under the Apache License, Version 2.0. +// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html +// + +#include + +#include +#include +#include +#include + +#include "OctreeServerDatagramProcessor.h" + +OctreeServerDatagramProcessor::OctreeServerDatagramProcessor(QUdpSocket& nodeSocket, QThread* previousNodeSocketThread) : + _nodeSocket(nodeSocket), + _previousNodeSocketThread(previousNodeSocketThread) +{ + +} + +OctreeServerDatagramProcessor::~OctreeServerDatagramProcessor() { + // return the node socket to its previous thread + _nodeSocket.moveToThread(_previousNodeSocketThread); +} + +void OctreeServerDatagramProcessor::readPendingDatagrams() { + + HifiSockAddr senderSockAddr; + static QByteArray incomingPacket; + + // read everything that is available + while (_nodeSocket.hasPendingDatagrams()) { + incomingPacket.resize(_nodeSocket.pendingDatagramSize()); + + // just get this packet off the stack + _nodeSocket.readDatagram(incomingPacket.data(), incomingPacket.size(), + senderSockAddr.getAddressPointer(), senderSockAddr.getPortPointer()); + + PacketType packetType = packetTypeForPacket(incomingPacket); + if (packetType == PacketTypePing) { + NodeList::getInstance()->processNodeData(senderSockAddr, incomingPacket); + return; // don't emit + } + + // emit the signal to tell AudioMixer it needs to process a packet + emit packetRequiresProcessing(incomingPacket, senderSockAddr); + } +} diff --git a/assignment-client/src/octree/OctreeServerDatagramProcessor.h b/assignment-client/src/octree/OctreeServerDatagramProcessor.h new file mode 100644 index 0000000000..cefe03a64a --- /dev/null +++ b/assignment-client/src/octree/OctreeServerDatagramProcessor.h @@ -0,0 +1,32 @@ +// +// OctreeServerDatagramProcessor.h +// assignment-client/src +// +// Created by Stephen Birarda on 2014-08-14. +// Copyright 2014 High Fidelity, Inc. +// +// Distributed under the Apache License, Version 2.0. +// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html +// + +#ifndef hifi_OctreeServerDatagramProcessor_h +#define hifi_OctreeServerDatagramProcessor_h + +#include +#include + +class OctreeServerDatagramProcessor : public QObject { + Q_OBJECT +public: + OctreeServerDatagramProcessor(QUdpSocket& nodeSocket, QThread* previousNodeSocketThread); + ~OctreeServerDatagramProcessor(); +public slots: + void readPendingDatagrams(); +signals: + void packetRequiresProcessing(const QByteArray& receivedPacket, const HifiSockAddr& senderSockAddr); +private: + QUdpSocket& _nodeSocket; + QThread* _previousNodeSocketThread; +}; + +#endif // hifi_OctreeServerDatagramProcessor_h \ No newline at end of file From f16a85b2aa6a69a1ec595978c6bd9a2b10f49b7f Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Fri, 5 Sep 2014 19:07:30 -0700 Subject: [PATCH 30/50] fix header --- assignment-client/src/octree/OctreeServerDatagramProcessor.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/assignment-client/src/octree/OctreeServerDatagramProcessor.h b/assignment-client/src/octree/OctreeServerDatagramProcessor.h index cefe03a64a..8c1d4943dd 100644 --- a/assignment-client/src/octree/OctreeServerDatagramProcessor.h +++ b/assignment-client/src/octree/OctreeServerDatagramProcessor.h @@ -2,7 +2,7 @@ // OctreeServerDatagramProcessor.h // assignment-client/src // -// Created by Stephen Birarda on 2014-08-14. +// Created by Brad Hefta-Gaub on 2014-09-05 // Copyright 2014 High Fidelity, Inc. // // Distributed under the Apache License, Version 2.0. From c6911274f610c2f2e7da903d7827f3ca61ecdf3e Mon Sep 17 00:00:00 2001 From: Craig Hansen-Sturm Date: Sat, 6 Sep 2014 02:14:47 -0700 Subject: [PATCH 31/50] new tone generator audio source object --- libraries/audio/src/AudioSourceTone.cpp | 20 +++++++ libraries/audio/src/AudioSourceTone.h | 69 +++++++++++++++++++++++++ 2 files changed, 89 insertions(+) create mode 100644 libraries/audio/src/AudioSourceTone.cpp create mode 100644 libraries/audio/src/AudioSourceTone.h diff --git a/libraries/audio/src/AudioSourceTone.cpp b/libraries/audio/src/AudioSourceTone.cpp new file mode 100644 index 0000000000..80a6aed48e --- /dev/null +++ b/libraries/audio/src/AudioSourceTone.cpp @@ -0,0 +1,20 @@ +// +// AudioSourceTone.cpp +// hifi +// +// Created by Craig Hansen-Sturm on 8/10/14. +// Copyright 2014 High Fidelity, Inc. +// +// Distributed under the Apache License, Version 2.0. +// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html +// + +#include +#include +#include +#include "AudioRingBuffer.h" +#include "AudioFormat.h" +#include "AudioBuffer.h" +#include "AudioSourceTone.h" + +uint32_t AudioSourceTone::_frameOffset = 0; diff --git a/libraries/audio/src/AudioSourceTone.h b/libraries/audio/src/AudioSourceTone.h new file mode 100644 index 0000000000..fb9d6be0fe --- /dev/null +++ b/libraries/audio/src/AudioSourceTone.h @@ -0,0 +1,69 @@ +// +// AudioSourceTone.h +// hifi +// +// Created by Craig Hansen-Sturm on 9/1/14. +// Copyright 2014 High Fidelity, Inc. +// +// Distributed under the Apache License, Version 2.0. +// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html +// + +#ifndef hifi_AudioSourceTone_h +#define hifi_AudioSourceTone_h + +class AudioSourceTone +{ + static uint32_t _frameOffset; + float32_t _frequency; + float32_t _sampleRate; + float32_t _omega; + +public: + AudioSourceTone() { + initialize(); + } + + ~AudioSourceTone() { + finalize(); + } + + void initialize() { + _frameOffset = 0; + setParameters(SAMPLE_RATE, 220.0f); + } + + void finalize() { + } + + void reset() { + _frameOffset = 0; + } + + void setParameters(const float32_t sampleRate, const float32_t frequency) { + _sampleRate = std::max(sampleRate, 1.0f); + _frequency = std::max(frequency, 1.0f); + _omega = _frequency / _sampleRate * TWO_PI; + } + + void getParameters(float32_t& sampleRate, float32_t& frequency) { + sampleRate = _sampleRate; + frequency = _frequency; + } + + void render(AudioBufferFloat32& frameBuffer) { + + // note: this is a placeholder implementation. final version will not include any transcendental ops in our render loop + + float32_t** samples = frameBuffer.getFrameData(); + for (uint16_t i = 0; i < frameBuffer.getFrameCount(); ++i) { + for (uint16_t j = 0; j < frameBuffer.getChannelCount(); ++j) { + samples[j][i] = sinf((i + _frameOffset) * _omega); + } + } + _frameOffset += frameBuffer.getFrameCount(); + } +}; + +#endif + From 3a9a4a64024068644068fc069e31fa7bdc552de8 Mon Sep 17 00:00:00 2001 From: Craig Hansen-Sturm Date: Sat, 6 Sep 2014 02:16:00 -0700 Subject: [PATCH 32/50] new pink noise generator audio source object --- libraries/audio/src/AudioSourceNoise.cpp | 21 +++++ libraries/audio/src/AudioSourceNoise.h | 103 +++++++++++++++++++++++ 2 files changed, 124 insertions(+) create mode 100644 libraries/audio/src/AudioSourceNoise.cpp create mode 100644 libraries/audio/src/AudioSourceNoise.h diff --git a/libraries/audio/src/AudioSourceNoise.cpp b/libraries/audio/src/AudioSourceNoise.cpp new file mode 100644 index 0000000000..6cfdf82fd9 --- /dev/null +++ b/libraries/audio/src/AudioSourceNoise.cpp @@ -0,0 +1,21 @@ +// +// AudioSourceNoise.cpp +// hifi +// +// Created by Craig Hansen-Sturm on 8/10/14. +// Copyright 2014 High Fidelity, Inc. +// +// Distributed under the Apache License, Version 2.0. +// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html +// + +#include +#include +#include +#include "AudioRingBuffer.h" +#include "AudioFormat.h" +#include "AudioBuffer.h" +#include "AudioSourceNoise.h" + +template<> +uint32_t AudioSourcePinkNoise::_randomSeed = 1974; // a truly random number diff --git a/libraries/audio/src/AudioSourceNoise.h b/libraries/audio/src/AudioSourceNoise.h new file mode 100644 index 0000000000..88340628e9 --- /dev/null +++ b/libraries/audio/src/AudioSourceNoise.h @@ -0,0 +1,103 @@ +// +// AudioSourceNoise.h +// hifi +// +// Created by Craig Hansen-Sturm on 9/1/14. +// Copyright 2014 High Fidelity, Inc. +// +// Distributed under the Apache License, Version 2.0. +// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html +// +// Adapted from code by Phil Burk http://www.firstpr.com.au/dsp/pink-noise/ +// + +#ifndef hifi_AudioSourceNoise_h +#define hifi_AudioSourceNoise_h + +template< const uint16_t N = 30> +class AudioSourceNoise +{ + static const uint16_t _randomRows = N; + static const uint16_t _randomBits = 24; + static const uint16_t _randomShift = (sizeof(int32_t) * 8) - _randomBits; + + static uint32_t _randomSeed; + + int32_t _rows[_randomRows]; + int32_t _runningSum; // used to optimize summing of generators. + uint16_t _index; // incremented each sample. + uint16_t _indexMask; // index wrapped by ANDing with this mask. + float32_t _scale; // used to scale within range of -1.0 to +1.0 + + static uint32_t generateRandomNumber() { + _randomSeed = (_randomSeed * 196314165) + 907633515; + return _randomSeed >> _randomShift; + } + +public: + AudioSourceNoise() { + initialize(); + } + + ~AudioSourceNoise() { + finalize(); + } + + void initialize() { + std::memset(_rows, 0, _randomRows * sizeof(int32_t)); + + _runningSum = 0; + _index = 0; + _indexMask = (1 << _randomRows) - 1; + _scale = 1.0f / ((_randomRows + 1) * (1 << (_randomBits - 1))); + } + + void finalize() { + } + + void reset() { + initialize(); + } + + void setParameters(void) { + } + + void getParameters(void) { + } + + void render(AudioBufferFloat32& frameBuffer) { + + uint32_t randomNumber; + + float32_t** samples = frameBuffer.getFrameData(); + for (uint16_t i = 0; i < frameBuffer.getFrameCount(); ++i) { + for (uint16_t j = 0; j < frameBuffer.getChannelCount(); ++j) { + + _index = (_index + 1) & _indexMask; // increment and mask index. + if (_index != 0) { // if index is zero, don't update any random values. + + uint32_t numZeros = 0; // determine how many trailing zeros in _index + uint32_t tmp = _index; + while ((tmp & 1) == 0) { + tmp >>= 1; + numZeros++; + } + // replace the indexed _rows random value. subtract and add back to _runningSum instead + // of adding all the random values together. only one value changes each time. + _runningSum -= _rows[numZeros]; + randomNumber = generateRandomNumber(); + _runningSum += randomNumber; + _rows[numZeros] = randomNumber; + } + + // add extra white noise value and scale between -1.0 and +1.0 + samples[j][i] = (_runningSum + generateRandomNumber()) * _scale; + } + } + } +}; + +typedef AudioSourceNoise<> AudioSourcePinkNoise; + +#endif // AudioSourceNoise_h + From f439475f3ce6cfb622edaab5526b86037621cbee Mon Sep 17 00:00:00 2001 From: Craig Hansen-Sturm Date: Sat, 6 Sep 2014 02:18:04 -0700 Subject: [PATCH 33/50] new audio gain/mute object --- libraries/audio/src/AudioGain.h | 75 +++++++++++++++++++++++++++++++++ 1 file changed, 75 insertions(+) create mode 100644 libraries/audio/src/AudioGain.h diff --git a/libraries/audio/src/AudioGain.h b/libraries/audio/src/AudioGain.h new file mode 100644 index 0000000000..c2cc64cba5 --- /dev/null +++ b/libraries/audio/src/AudioGain.h @@ -0,0 +1,75 @@ +// +// AudioGain.h +// hifi +// +// Created by Craig Hansen-Sturm on 9/1/14. +// Copyright 2014 High Fidelity, Inc. +// +// Distributed under the Apache License, Version 2.0. +// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html +// + +#ifndef hifi_AudioGain_h +#define hifi_AudioGain_h + +class AudioGain +{ + float32_t _gain; + bool _mute; + +public: + AudioGain() { + initialize(); + } + + ~AudioGain() { + finalize(); + } + + void initialize() { + setParameters(1.0f,0.0f); + } + + void finalize() { + } + + void reset() { + initialize(); + } + + void setParameters(const float gain, const float mute) { + _gain = std::min(std::max(gain, 0.0f), 1.0f); + _mute = mute != 0.0f; + + } + + void getParameters(float& gain, float& mute) { + gain = _gain; + mute = _mute ? 1.0f : 0.0f; + } + + void render(AudioBufferFloat32& frameBuffer) { + if (_mute) { + frameBuffer.zeroFrames(); + return; + } + + float32_t** samples = frameBuffer.getFrameData(); + for (uint16_t j = 0; j < frameBuffer.getChannelCount(); ++j) { + for (uint16_t i = 0; i < frameBuffer.getFrameCount(); i += 8) { + samples[j][i + 0] *= _gain; + samples[j][i + 1] *= _gain; + samples[j][i + 2] *= _gain; + samples[j][i + 3] *= _gain; + samples[j][i + 4] *= _gain; + samples[j][i + 5] *= _gain; + samples[j][i + 6] *= _gain; + samples[j][i + 7] *= _gain; + } + } + } +}; + +#endif // AudioGain_h + + From 0b33c344fffbcc83eaf55bc6e5010549297b0dd0 Mon Sep 17 00:00:00 2001 From: Craig Hansen-Sturm Date: Sat, 6 Sep 2014 02:18:35 -0700 Subject: [PATCH 34/50] new audio buffer object --- libraries/audio/src/AudioBuffer.h | 174 ++++++++++++++++++++++++++++++ 1 file changed, 174 insertions(+) create mode 100644 libraries/audio/src/AudioBuffer.h diff --git a/libraries/audio/src/AudioBuffer.h b/libraries/audio/src/AudioBuffer.h new file mode 100644 index 0000000000..dd0030ecd8 --- /dev/null +++ b/libraries/audio/src/AudioBuffer.h @@ -0,0 +1,174 @@ +// +// AudioBuffer.h +// hifi +// +// Created by Craig Hansen-Sturm on 8/29/14. +// Copyright 2014 High Fidelity, Inc. +// +// Distributed under the Apache License, Version 2.0. +// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html +// + +#ifndef hifi_AudioBuffer_h +#define hifi_AudioBuffer_h + +#include + +template< typename T > +class AudioFrameBuffer { + + uint16_t _channelCount; + uint16_t _frameCount; + uint16_t _frameCountMax; + + T** _frameBuffer; + + void allocateFrames() { + _frameBuffer = new T*[_channelCount]; + if (_frameBuffer) { + for (uint16_t i = 0; i < _channelCount; ++i) { + _frameBuffer[i] = new T[_frameCountMax]; + } + } + } + + void deallocateFrames() { + if (_frameBuffer) { + for (uint16_t i = 0; i < _channelCount; ++i) { + delete _frameBuffer[i]; + } + delete _frameBuffer; + } + _frameBuffer = NULL; + } + +public: + + AudioFrameBuffer() + : _channelCount(0) + , _frameCount(0) + , _frameCountMax(0) + , _frameBuffer(NULL) { + } + + AudioFrameBuffer(const uint16_t channelCount, const uint16_t frameCount) + : _channelCount(channelCount) + , _frameCount(frameCount) + , _frameCountMax(frameCount) + , _frameBuffer(NULL) { + allocateFrames(); + } + + ~AudioFrameBuffer() { + finalize(); + } + + void initialize(const uint16_t channelCount, const uint16_t frameCount) { + if (_frameBuffer) { + finalize(); + } + _channelCount = channelCount; + _frameCount = frameCount; + _frameCountMax = frameCount; + allocateFrames(); + } + + void finalize() { + deallocateFrames(); + _channelCount = 0; + _frameCount = 0; + } + + T**& getFrameData() { + return _frameBuffer; + } + + uint16_t getChannelCount() { + return _channelCount; + } + + uint16_t getFrameCount() { + return _frameCount; + } + + void zeroFrames() { + if (!_frameBuffer) { + return; + } + for (uint16_t i = 0; i < _channelCount; ++i) { + std::memset(_frameBuffer[i], 0, sizeof(T)*_frameCountMax); + } + } + + template< typename S > + void copyFrames(uint16_t channelCount, const uint16_t frameCount, S* frames, const bool copyOut = false) { + if ( !_frameBuffer || !frames) { + return; + } + assert(channelCount == _channelCount); + assert(frameCount <= _frameCountMax); + + _frameCount = frameCount; // we allow copying fewer frames than we've allocated + + if (copyOut) { + S* dst = frames; + + if(typeid(T) == typeid(S)) { // source and destination types are the same + for (int i = 0; i < _frameCount; ++i) { + for (int j = 0; j < _channelCount; ++j) { + *dst++ = _frameBuffer[j][i]; + } + } + } + else { + if(typeid(T) == typeid(float32_t) && + typeid(S) == typeid(int16_t)) { + + const int scale = (2 << ((8 * sizeof(S)) - 1)); + + for (int i = 0; i < _frameCount; ++i) { + for (int j = 0; j < _channelCount; ++j) { + *dst++ = (S)(_frameBuffer[j][i] * scale); + } + } + } + else { + assert(0); // currently unsupported conversion + } + } + } + else { // copyIn + S* src = frames; + + if(typeid(T) == typeid(S)) { // source and destination types are the same + for (int i = 0; i < _frameCount; ++i) { + for (int j = 0; j < _channelCount; ++j) { + _frameBuffer[j][i] = *src++; + } + } + } + else { + if(typeid(T) == typeid(float32_t) && + typeid(S) == typeid(int16_t)) { + + const int scale = (2 << ((8 * sizeof(S)) - 1)); + + for (int i = 0; i < _frameCount; ++i) { + for (int j = 0; j < _channelCount; ++j) { + _frameBuffer[j][i] = ((T)(*src++)) / scale; + } + } + } + else { + assert(0); // currently unsupported conversion + } + } + } + } +}; + +typedef AudioFrameBuffer< float32_t > AudioBufferFloat32; +typedef AudioFrameBuffer< int32_t > AudioBufferSInt32; + +#endif // hifi_AudioBuffer_h + From 8ecf0870e7c7ff8325e9835155a9e5417d3e9359 Mon Sep 17 00:00:00 2001 From: Craig Hansen-Sturm Date: Sat, 6 Sep 2014 02:20:14 -0700 Subject: [PATCH 35/50] dependency on new audiobuffer and audioformat objects --- libraries/audio/src/PositionalAudioStream.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/libraries/audio/src/PositionalAudioStream.h b/libraries/audio/src/PositionalAudioStream.h index a7f59aebde..f5f1b9027a 100644 --- a/libraries/audio/src/PositionalAudioStream.h +++ b/libraries/audio/src/PositionalAudioStream.h @@ -16,6 +16,8 @@ #include #include "InboundAudioStream.h" +#include "AudioFormat.h" +#include "AudioBuffer.h" #include "AudioFilter.h" #include "AudioFilterBank.h" From 5bab1ee7f58d49d4bea8334afbef7d563b7bc603 Mon Sep 17 00:00:00 2001 From: Craig Hansen-Sturm Date: Sat, 6 Sep 2014 02:22:27 -0700 Subject: [PATCH 36/50] dependency on new audiobuffer and audioformat objects/render call now uses audiobuffers --- libraries/audio/src/AudioFilterBank.cpp | 3 +++ libraries/audio/src/AudioFilterBank.h | 13 ++++++++++++- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/libraries/audio/src/AudioFilterBank.cpp b/libraries/audio/src/AudioFilterBank.cpp index a7b969540a..6599b29a01 100644 --- a/libraries/audio/src/AudioFilterBank.cpp +++ b/libraries/audio/src/AudioFilterBank.cpp @@ -9,9 +9,12 @@ // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // +#include #include #include #include "AudioRingBuffer.h" +#include "AudioFormat.h" +#include "AudioBuffer.h" #include "AudioFilter.h" #include "AudioFilterBank.h" diff --git a/libraries/audio/src/AudioFilterBank.h b/libraries/audio/src/AudioFilterBank.h index c523736a57..2ea29cb3a9 100644 --- a/libraries/audio/src/AudioFilterBank.h +++ b/libraries/audio/src/AudioFilterBank.h @@ -64,7 +64,7 @@ public: // // public interface // - void initialize(const float sampleRate, const int frameCount) { + void initialize(const float sampleRate, const int frameCount = 0) { finalize(); for (int i = 0; i < _channelCount; ++i) { @@ -141,6 +141,17 @@ public: } } + void render(AudioBufferFloat32& frameBuffer) { + + float32_t** samples = frameBuffer.getFrameData(); + for (uint16_t j = 0; j < frameBuffer.getChannelCount(); ++j) { + for (int i = 0; i < _filterCount; ++i) { + _filters[i][j].render( samples[j], samples[j], frameBuffer.getFrameCount() ); + } + } + + } + void reset() { for (int i = 0; i < _filterCount; ++i) { for (int j = 0; j < _channelCount; ++j) { From 7a5ec429d19509b51856142ab65f8936c387d1a5 Mon Sep 17 00:00:00 2001 From: Craig Hansen-Sturm Date: Sat, 6 Sep 2014 02:29:48 -0700 Subject: [PATCH 37/50] audio rendering loop now uses input-gain, tone-generator, noise-generator, and post-generator-gain objects / audiobuffer object now shared between all new audio objects / zero buffer copy between new objects / inline tone-generator code removed / new audio options for generators --- interface/src/Audio.cpp | 82 ++++++++++++++++++++++++++++------------- interface/src/Audio.h | 36 +++++++++++++++--- 2 files changed, 88 insertions(+), 30 deletions(-) diff --git a/interface/src/Audio.cpp b/interface/src/Audio.cpp index 8a788df831..3c13d3825d 100644 --- a/interface/src/Audio.cpp +++ b/interface/src/Audio.cpp @@ -40,6 +40,7 @@ #include #include "Audio.h" + #include "Menu.h" #include "Util.h" #include "PositionalAudioStream.h" @@ -82,7 +83,7 @@ Audio::Audio(QObject* parent) : _noiseGateSampleCounter(0), _noiseGateOpen(false), _noiseGateEnabled(true), - _toneInjectionEnabled(false), + _audioSourceInjectEnabled(false), _noiseGateFramesToClose(0), _totalInputAudioSamples(0), _collisionSoundMagnitude(0.0f), @@ -102,6 +103,8 @@ Audio::Audio(QObject* parent) : _framesPerScope(DEFAULT_FRAMES_PER_SCOPE), _samplesPerScope(NETWORK_SAMPLES_PER_FRAME * _framesPerScope), _peqEnabled(false), + _noiseSourceEnabled(false), + _toneSourceEnabled(true), _scopeInput(0), _scopeOutputLeft(0), _scopeOutputRight(0), @@ -137,6 +140,10 @@ void Audio::reset() { _receivedAudioStream.reset(); resetStats(); _peq.reset(); + _noiseSource.reset(); + _toneSource.reset(); + _sourceGain.reset(); + _inputGain.reset(); } void Audio::resetStats() { @@ -424,14 +431,25 @@ void Audio::start() { qDebug() << "Unable to set up audio output because of a problem with output format."; } - _peq.initialize( _inputFormat.sampleRate(), _audioInput->bufferSize() ); - + _inputFrameBuffer.initialize( _inputFormat.channelCount(), _audioInput->bufferSize() * 2 ); + _peq.initialize( _inputFormat.sampleRate() ); + _inputGain.initialize(); + _sourceGain.initialize(); + _noiseSource.initialize(); + _toneSource.initialize(); + _sourceGain.setParameters(0.25f,0.0f); + _inputGain.setParameters(1.0f,0.0f); } void Audio::stop() { + _inputFrameBuffer.finalize(); _peq.finalize(); - + _inputGain.finalize(); + _sourceGain.finalize(); + _noiseSource.finalize(); + _toneSource.finalize(); + // "switch" to invalid devices in order to shut down the state switchInputToAudioDevice(QAudioDeviceInfo()); switchOutputToAudioDevice(QAudioDeviceInfo()); @@ -477,14 +495,30 @@ void Audio::handleAudioInput() { QByteArray inputByteArray = _inputDevice->readAll(); + int16_t* inputBuffer = (int16_t*)inputByteArray.data(); + const int inputFrameCount = inputByteArray.size() / sizeof(int16_t); + + _inputFrameBuffer.copyFrames(1, inputFrameCount, inputBuffer, false /*copy in*/); + + _inputGain.render(_inputFrameBuffer); // input/mic gain+mute + + // Add audio source injection if enabled + if (_audioSourceInjectEnabled && !_muted) { + + if (_toneSourceEnabled) { // sine generator + _toneSource.render(_inputFrameBuffer); + } + else if(_noiseSourceEnabled) { // pink noise generator + _noiseSource.render(_inputFrameBuffer); + } + _sourceGain.render(_inputFrameBuffer); // post gain + } if (_peqEnabled && !_muted) { - // we wish to pre-filter our captured input, prior to loopback - - int16_t* ioBuffer = (int16_t*)inputByteArray.data(); - - _peq.render(ioBuffer, ioBuffer, inputByteArray.size() / sizeof(int16_t)); + _peq.render(_inputFrameBuffer); // 3-band parametric eq } + _inputFrameBuffer.copyFrames(1, inputFrameCount, inputBuffer, true /*copy out*/); + if (Menu::getInstance()->isOptionChecked(MenuOption::EchoLocalAudio) && !_muted && _audioOutput) { // if this person wants local loopback add that to the locally injected audio @@ -522,7 +556,7 @@ void Audio::handleAudioInput() { int16_t* inputAudioSamples = new int16_t[inputSamplesRequired]; _inputRingBuffer.readSamples(inputAudioSamples, inputSamplesRequired); - + const int numNetworkBytes = _isStereoInput ? NETWORK_BUFFER_LENGTH_BYTES_STEREO : NETWORK_BUFFER_LENGTH_BYTES_PER_CHANNEL; const int numNetworkSamples = _isStereoInput ? NETWORK_BUFFER_LENGTH_SAMPLES_STEREO : NETWORK_BUFFER_LENGTH_SAMPLES_PER_CHANNEL; @@ -599,20 +633,8 @@ void Audio::handleAudioInput() { _dcOffset = DC_OFFSET_AVERAGING * _dcOffset + (1.0f - DC_OFFSET_AVERAGING) * measuredDcOffset; } - // Add tone injection if enabled - const float TONE_FREQ = 220.0f / SAMPLE_RATE * TWO_PI; - const float QUARTER_VOLUME = 8192.0f; - if (_toneInjectionEnabled) { - loudness = 0.0f; - for (int i = 0; i < NETWORK_BUFFER_LENGTH_SAMPLES_PER_CHANNEL; i++) { - networkAudioSamples[i] = QUARTER_VOLUME * sinf(TONE_FREQ * (float)(i + _proceduralEffectSample)); - loudness += fabsf(networkAudioSamples[i]); - } - } - _lastInputLoudness = fabs(loudness / NETWORK_BUFFER_LENGTH_SAMPLES_PER_CHANNEL); - // If Noise Gate is enabled, check and turn the gate on and off - if (!_toneInjectionEnabled && _noiseGateEnabled) { + if (!_audioSourceInjectEnabled && _noiseGateEnabled) { float averageOfAllSampleFrames = 0.0f; _noiseSampleFrames[_noiseGateSampleCounter++] = _lastInputLoudness; if (_noiseGateSampleCounter == NUMBER_OF_NOISE_SAMPLE_FRAMES) { @@ -1041,8 +1063,18 @@ void Audio::processProceduralAudio(int16_t* monoInput, int numSamples) { } } -void Audio::toggleToneInjection() { - _toneInjectionEnabled = !_toneInjectionEnabled; +void Audio::toggleAudioSourceInject() { + _audioSourceInjectEnabled = !_audioSourceInjectEnabled; +} + +void Audio::selectAudioSourcePinkNoise() { + _noiseSourceEnabled = Menu::getInstance()->isOptionChecked(MenuOption::AudioSourcePinkNoise); + _toneSourceEnabled = !_noiseSourceEnabled; +} + +void Audio::selectAudioSourceSine440() { + _toneSourceEnabled = Menu::getInstance()->isOptionChecked(MenuOption::AudioSourceSine440); + _noiseSourceEnabled = !_toneSourceEnabled; } void Audio::toggleAudioSpatialProcessing() { diff --git a/interface/src/Audio.h b/interface/src/Audio.h index b5069f3b3a..f73e0331de 100644 --- a/interface/src/Audio.h +++ b/interface/src/Audio.h @@ -20,6 +20,12 @@ #include "Recorder.h" #include "RingBufferHistory.h" #include "MovingMinMaxAvg.h" +#include "AudioRingBuffer.h" +#include "AudioFormat.h" +#include "AudioBuffer.h" +#include "AudioSourceTone.h" +#include "AudioSourceNoise.h" +#include "AudioGain.h" #include "AudioFilter.h" #include "AudioFilterBank.h" @@ -116,7 +122,9 @@ public slots: void audioMixerKilled(); void toggleMute(); void toggleAudioNoiseReduction(); - void toggleToneInjection(); + void toggleAudioSourceInject(); + void selectAudioSourcePinkNoise(); + void selectAudioSourceSine440(); void toggleScope(); void toggleScopePause(); void toggleStats(); @@ -199,7 +207,8 @@ private: int _noiseGateSampleCounter; bool _noiseGateOpen; bool _noiseGateEnabled; - bool _toneInjectionEnabled; + bool _audioSourceInjectEnabled; + int _noiseGateFramesToClose; int _totalInputAudioSamples; @@ -282,10 +291,27 @@ private: int _framesPerScope; int _samplesPerScope; - // Multi-band parametric EQ - bool _peqEnabled; - AudioFilterPEQ3m _peq; + // Input framebuffer + AudioBufferFloat32 _inputFrameBuffer; + + // Input gain + AudioGain _inputGain; + + // Post tone/pink noise generator gain + AudioGain _sourceGain; + // Pink noise source + bool _noiseSourceEnabled; + AudioSourcePinkNoise _noiseSource; + + // Tone source + bool _toneSourceEnabled; + AudioSourceTone _toneSource; + + // Multi-band parametric EQ + bool _peqEnabled; + AudioFilterPEQ3m _peq; + QMutex _guard; QByteArray* _scopeInput; QByteArray* _scopeOutputLeft; From 1eba20bc3bd44feaa208752aa45cd2f6714d4287 Mon Sep 17 00:00:00 2001 From: Craig Hansen-Sturm Date: Sat, 6 Sep 2014 02:32:13 -0700 Subject: [PATCH 38/50] minor cleanup --- libraries/audio/src/AudioFormat.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/libraries/audio/src/AudioFormat.h b/libraries/audio/src/AudioFormat.h index 0ded25d0c3..da082ead94 100644 --- a/libraries/audio/src/AudioFormat.h +++ b/libraries/audio/src/AudioFormat.h @@ -23,7 +23,7 @@ typedef double float64_t; #endif // -// Audio format structure (uncompressed streams only) +// Audio format structure (currently for uncompressed streams only) // struct AudioFormat { @@ -62,7 +62,7 @@ struct AudioFormat { void setCanonicalFloat32(uint32_t channels) { assert(channels > 0 && channels <= 2); - _sampleRate = SAMPLE_RATE; + _sampleRate = SAMPLE_RATE; // todo: create audio constants header _bitsPerChannel = sizeof(float32_t) * 8; _channelsPerFrame = channels; _bytesPerFrame = _channelsPerFrame * _bitsPerChannel / 8; @@ -72,7 +72,7 @@ struct AudioFormat { void setCanonicalInt16(uint32_t channels) { assert(channels > 0 && channels <= 2); - _sampleRate = SAMPLE_RATE; + _sampleRate = SAMPLE_RATE; // todo: create audio constants header _bitsPerChannel = sizeof(int16_t) * 8; _channelsPerFrame = channels; _bytesPerFrame = _channelsPerFrame * _bitsPerChannel / 8; From f309875069e0060d99df535e6fcf7a5e7cd7af06 Mon Sep 17 00:00:00 2001 From: Craig Hansen-Sturm Date: Sat, 6 Sep 2014 02:50:37 -0700 Subject: [PATCH 39/50] formatting/renaming --- interface/src/Audio.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/interface/src/Audio.cpp b/interface/src/Audio.cpp index 3c13d3825d..0d114b7208 100644 --- a/interface/src/Audio.cpp +++ b/interface/src/Audio.cpp @@ -495,10 +495,10 @@ void Audio::handleAudioInput() { QByteArray inputByteArray = _inputDevice->readAll(); - int16_t* inputBuffer = (int16_t*)inputByteArray.data(); + int16_t* inputFrameData = (int16_t*)inputByteArray.data(); const int inputFrameCount = inputByteArray.size() / sizeof(int16_t); - _inputFrameBuffer.copyFrames(1, inputFrameCount, inputBuffer, false /*copy in*/); + _inputFrameBuffer.copyFrames(1, inputFrameCount, inputFrameData, false /*copy in*/); _inputGain.render(_inputFrameBuffer); // input/mic gain+mute @@ -517,7 +517,7 @@ void Audio::handleAudioInput() { _peq.render(_inputFrameBuffer); // 3-band parametric eq } - _inputFrameBuffer.copyFrames(1, inputFrameCount, inputBuffer, true /*copy out*/); + _inputFrameBuffer.copyFrames(1, inputFrameCount, inputFrameData, true /*copy out*/); if (Menu::getInstance()->isOptionChecked(MenuOption::EchoLocalAudio) && !_muted && _audioOutput) { // if this person wants local loopback add that to the locally injected audio From e2f3392f09517a5a350b70a75c61772d819b39e3 Mon Sep 17 00:00:00 2001 From: Craig Hansen-Sturm Date: Sat, 6 Sep 2014 02:51:11 -0700 Subject: [PATCH 40/50] formatting/renaming --- libraries/audio/src/AudioFilterBank.h | 1 - 1 file changed, 1 deletion(-) diff --git a/libraries/audio/src/AudioFilterBank.h b/libraries/audio/src/AudioFilterBank.h index 2ea29cb3a9..46d781075a 100644 --- a/libraries/audio/src/AudioFilterBank.h +++ b/libraries/audio/src/AudioFilterBank.h @@ -149,7 +149,6 @@ public: _filters[i][j].render( samples[j], samples[j], frameBuffer.getFrameCount() ); } } - } void reset() { From e64c81420e0c0da2fd40cb6d68963b0e2bca2b81 Mon Sep 17 00:00:00 2001 From: Craig Hansen-Sturm Date: Sat, 6 Sep 2014 03:29:14 -0700 Subject: [PATCH 41/50] ubuntu build fix (remove std::memset ...) --- libraries/audio/src/AudioFormat.h | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/libraries/audio/src/AudioFormat.h b/libraries/audio/src/AudioFormat.h index da082ead94..9548138f58 100644 --- a/libraries/audio/src/AudioFormat.h +++ b/libraries/audio/src/AudioFormat.h @@ -42,22 +42,23 @@ struct AudioFormat { uint32_t _bitsPerChannel; float64_t _sampleRate; + AudioFormat() { - std::memset(this, 0, sizeof(*this)); + memset(this, 0, sizeof(*this)); } ~AudioFormat() { } AudioFormat& operator=(const AudioFormat& fmt) { - std::memcpy(this, &fmt, sizeof(*this)); + memcpy(this, &fmt, sizeof(*this)); return *this; } bool operator==(const AudioFormat& fmt) { - return std::memcmp(this, &fmt, sizeof(*this)) == 0; + return memcmp(this, &fmt, sizeof(*this)) == 0; } bool operator!=(const AudioFormat& fmt) { - return std::memcmp(this, &fmt, sizeof(*this)) != 0; + return memcmp(this, &fmt, sizeof(*this)) != 0; } void setCanonicalFloat32(uint32_t channels) { From 76adb952a30da1287f5c0e4d9036472d13c3714b Mon Sep 17 00:00:00 2001 From: Craig Hansen-Sturm Date: Sat, 6 Sep 2014 03:57:11 -0700 Subject: [PATCH 42/50] ubuntu build fix (remove std::memset ...) --- libraries/audio/src/AudioBuffer.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libraries/audio/src/AudioBuffer.h b/libraries/audio/src/AudioBuffer.h index dd0030ecd8..7c244f47bf 100644 --- a/libraries/audio/src/AudioBuffer.h +++ b/libraries/audio/src/AudioBuffer.h @@ -96,7 +96,7 @@ public: return; } for (uint16_t i = 0; i < _channelCount; ++i) { - std::memset(_frameBuffer[i], 0, sizeof(T)*_frameCountMax); + memset(_frameBuffer[i], 0, sizeof(T)*_frameCountMax); } } From 2700d8c59d8f76d2427750d9118da86f0e0de51f Mon Sep 17 00:00:00 2001 From: Craig Hansen-Sturm Date: Sat, 6 Sep 2014 04:05:52 -0700 Subject: [PATCH 43/50] ubuntu build fix (remove std::memset ...) --- libraries/audio/src/AudioSourceNoise.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libraries/audio/src/AudioSourceNoise.h b/libraries/audio/src/AudioSourceNoise.h index 88340628e9..26cb21a065 100644 --- a/libraries/audio/src/AudioSourceNoise.h +++ b/libraries/audio/src/AudioSourceNoise.h @@ -44,7 +44,7 @@ public: } void initialize() { - std::memset(_rows, 0, _randomRows * sizeof(int32_t)); + memset(_rows, 0, _randomRows * sizeof(int32_t)); _runningSum = 0; _index = 0; From 5ebe6962a491a56411c3e4730b1bd65f2d0ba751 Mon Sep 17 00:00:00 2001 From: David Rowe Date: Sat, 6 Sep 2014 09:59:47 -0700 Subject: [PATCH 44/50] Make scripts loaded with Script.load() not persist --- interface/src/Application.cpp | 32 +++++++++++++------- interface/src/Application.h | 5 +-- interface/src/ui/JSConsole.cpp | 2 +- interface/src/ui/RunningScriptsWidget.cpp | 2 +- interface/src/ui/ScriptEditorWidget.cpp | 2 +- libraries/script-engine/src/ScriptEngine.cpp | 4 ++- libraries/script-engine/src/ScriptEngine.h | 8 +++-- 7 files changed, 36 insertions(+), 19 deletions(-) diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index 966f222c52..b31a40c269 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -382,6 +382,8 @@ Application::Application(int& argc, char** argv, QElapsedTimer &startup_time) : _runningScriptsWidget->setRunningScripts(getRunningScripts()); connect(_runningScriptsWidget, &RunningScriptsWidget::stopScriptName, this, &Application::stopScript); + connect(this, SIGNAL(aboutToQuit()), this, SLOT(saveScripts())); + // check first run... QVariant firstRunValue = _settings->value("firstRun",QVariant(true)); if (firstRunValue.isValid() && firstRunValue.toBool()) { @@ -393,7 +395,7 @@ Application::Application(int& argc, char** argv, QElapsedTimer &startup_time) : QMutexLocker locker(&_settingsMutex); _settings->setValue("firstRun",QVariant(false)); } else { - // do this as late as possible so that all required subsystems are inialized + // do this as late as possible so that all required subsystems are initialized loadScripts(); QMutexLocker locker(&_settingsMutex); @@ -425,7 +427,6 @@ Application::~Application() { saveSettings(); storeSizeAndPosition(); - saveScripts(); int DELAY_TIME = 1000; UserActivityLogger::getInstance().close(DELAY_TIME); @@ -3675,18 +3676,26 @@ void Application::clearScriptsBeforeRunning() { } void Application::saveScripts() { - // saves all current running scripts + // Saves all currently running user-loaded scripts QMutexLocker locker(&_settingsMutex); _settings->beginWriteArray("Settings"); - for (int i = 0; i < getRunningScripts().size(); ++i){ - _settings->setArrayIndex(i); - _settings->setValue("script", getRunningScripts().at(i)); + + QStringList runningScripts = getRunningScripts(); + int i = 0; + for (QStringList::const_iterator it = runningScripts.begin(); it != runningScripts.end(); it += 1) { + if (getScriptEngine(*it)->isUserLoaded()) { + _settings->setArrayIndex(i); + _settings->setValue("script", *it); + i += 1; + } } + _settings->endArray(); } -ScriptEngine* Application::loadScript(const QString& scriptName, bool loadScriptFromEditor, bool activateMainWindow) { - QUrl scriptUrl(scriptName); +ScriptEngine* Application::loadScript(const QString& scriptFilename, bool isUserLoaded, + bool loadScriptFromEditor, bool activateMainWindow) { + QUrl scriptUrl(scriptFilename); const QString& scriptURLString = scriptUrl.toString(); if (_scriptEnginesHash.contains(scriptURLString) && loadScriptFromEditor && !_scriptEnginesHash[scriptURLString]->isFinished()) { @@ -3695,7 +3704,7 @@ ScriptEngine* Application::loadScript(const QString& scriptName, bool loadScript } ScriptEngine* scriptEngine; - if (scriptName.isNull()) { + if (scriptFilename.isNull()) { scriptEngine = new ScriptEngine(NO_SCRIPT, "", &_controllerScriptingInterface); } else { // start the script on a new thread... @@ -3711,6 +3720,7 @@ ScriptEngine* Application::loadScript(const QString& scriptName, bool loadScript _runningScriptsWidget->setRunningScripts(getRunningScripts()); UserActivityLogger::getInstance().loadedScript(scriptURLString); } + scriptEngine->setUserLoaded(isUserLoaded); // setup the packet senders and jurisdiction listeners of the script engine's scripting interfaces so // we can use the same ones from the application. @@ -3743,7 +3753,7 @@ ScriptEngine* Application::loadScript(const QString& scriptName, bool loadScript connect(scriptEngine, SIGNAL(finished(const QString&)), this, SLOT(scriptFinished(const QString&))); - connect(scriptEngine, SIGNAL(loadScript(const QString&)), this, SLOT(loadScript(const QString&))); + connect(scriptEngine, SIGNAL(loadScript(const QString&, bool)), this, SLOT(loadScript(const QString&, bool))); scriptEngine->registerGlobalObject("Overlays", &_overlays); @@ -3813,7 +3823,7 @@ void Application::stopAllScripts(bool restart) { // stops all current running scripts for (QHash::const_iterator it = _scriptEnginesHash.constBegin(); it != _scriptEnginesHash.constEnd(); it++) { - if (restart) { + if (restart && it.value()->isUserLoaded()) { connect(it.value(), SIGNAL(finished(const QString&)), SLOT(loadScript(const QString&))); } it.value()->stop(); diff --git a/interface/src/Application.h b/interface/src/Application.h index a68528ce72..5aa6cfe6f2 100644 --- a/interface/src/Application.h +++ b/interface/src/Application.h @@ -150,7 +150,6 @@ public: void setPreviousScriptLocation(const QString& previousScriptLocation); void storeSizeAndPosition(); void clearScriptsBeforeRunning(); - void saveScripts(); void initializeGL(); void paintGL(); void resizeGL(int width, int height); @@ -340,13 +339,15 @@ public slots: void loadScriptURLDialog(); void toggleLogDialog(); void initAvatarAndViewFrustum(); - ScriptEngine* loadScript(const QString& fileNameString = QString(), bool loadScriptFromEditor = false, bool activateMainWindow = false); + ScriptEngine* loadScript(const QString& scriptFilename = QString(), bool isUserLoaded = true, + bool loadScriptFromEditor = false, bool activateMainWindow = false); void scriptFinished(const QString& scriptName); void stopAllScripts(bool restart = false); void stopScript(const QString& scriptName); void reloadAllScripts(); void loadDefaultScripts(); void toggleRunningScriptsWidget(); + void saveScripts(); void uploadHead(); void uploadSkeleton(); diff --git a/interface/src/ui/JSConsole.cpp b/interface/src/ui/JSConsole.cpp index 921c571d44..8dbece41f0 100644 --- a/interface/src/ui/JSConsole.cpp +++ b/interface/src/ui/JSConsole.cpp @@ -52,7 +52,7 @@ JSConsole::JSConsole(QWidget* parent, ScriptEngine* scriptEngine) : if (_scriptEngine == NULL) { - _scriptEngine = Application::getInstance()->loadScript(); + _scriptEngine = Application::getInstance()->loadScript(QString(), false); } connect(_scriptEngine, SIGNAL(evaluationFinished(QScriptValue, bool)), diff --git a/interface/src/ui/RunningScriptsWidget.cpp b/interface/src/ui/RunningScriptsWidget.cpp index 7a46873129..6efa2f8fe6 100644 --- a/interface/src/ui/RunningScriptsWidget.cpp +++ b/interface/src/ui/RunningScriptsWidget.cpp @@ -69,7 +69,7 @@ void RunningScriptsWidget::updateFileFilter(const QString& filter) { void RunningScriptsWidget::loadScriptFromList(const QModelIndex& index) { QVariant scriptFile = _proxyModel.data(index, ScriptsModel::ScriptPath); - Application::getInstance()->loadScript(scriptFile.toString(), false, false); + Application::getInstance()->loadScript(scriptFile.toString()); } void RunningScriptsWidget::loadSelectedScript() { diff --git a/interface/src/ui/ScriptEditorWidget.cpp b/interface/src/ui/ScriptEditorWidget.cpp index d25408e568..f99c9d5ac4 100644 --- a/interface/src/ui/ScriptEditorWidget.cpp +++ b/interface/src/ui/ScriptEditorWidget.cpp @@ -93,7 +93,7 @@ bool ScriptEditorWidget::setRunning(bool run) { if (run) { const QString& scriptURLString = QUrl(_currentScript).toString(); - _scriptEngine = Application::getInstance()->loadScript(scriptURLString, true); + _scriptEngine = Application::getInstance()->loadScript(scriptURLString, true, true); connect(_scriptEngine, &ScriptEngine::runningStateChanged, this, &ScriptEditorWidget::runningStateChanged); connect(_scriptEngine, &ScriptEngine::errorMessage, this, &ScriptEditorWidget::onScriptError); connect(_scriptEngine, &ScriptEngine::printedMessage, this, &ScriptEditorWidget::onScriptPrint); diff --git a/libraries/script-engine/src/ScriptEngine.cpp b/libraries/script-engine/src/ScriptEngine.cpp index 8a9a818af7..a55a05bc5c 100644 --- a/libraries/script-engine/src/ScriptEngine.cpp +++ b/libraries/script-engine/src/ScriptEngine.cpp @@ -88,6 +88,7 @@ ScriptEngine::ScriptEngine(const QString& scriptContents, const QString& fileNam _isRunning(false), _isInitialized(false), _isAvatar(false), + _isUserLoaded(false), _avatarIdentityTimer(NULL), _avatarBillboardTimer(NULL), _timerFunctionMap(), @@ -113,6 +114,7 @@ ScriptEngine::ScriptEngine(const QUrl& scriptURL, _isRunning(false), _isInitialized(false), _isAvatar(false), + _isUserLoaded(false), _avatarIdentityTimer(NULL), _avatarBillboardTimer(NULL), _timerFunctionMap(), @@ -708,7 +710,7 @@ void ScriptEngine::include(const QString& includeFile) { void ScriptEngine::load(const QString& loadFile) { QUrl url = resolveInclude(loadFile); - emit loadScript(url.toString()); + emit loadScript(url.toString(), false); } void ScriptEngine::nodeKilled(SharedNodePointer node) { diff --git a/libraries/script-engine/src/ScriptEngine.h b/libraries/script-engine/src/ScriptEngine.h index 9a38e805b8..130dc501f9 100644 --- a/libraries/script-engine/src/ScriptEngine.h +++ b/libraries/script-engine/src/ScriptEngine.h @@ -93,6 +93,9 @@ public: bool isFinished() const { return _isFinished; } bool isRunning() const { return _isRunning; } + void setUserLoaded(bool isUserLoaded) { _isUserLoaded = isUserLoaded; } + bool isUserLoaded() const { return _isUserLoaded; } + public slots: void stop(); @@ -116,7 +119,7 @@ signals: void errorMessage(const QString& message); void runningStateChanged(); void evaluationFinished(QScriptValue result, bool isException); - void loadScript(const QString& scriptName); + void loadScript(const QString& scriptName, bool isUserLoaded); protected: QString _scriptContents; @@ -152,7 +155,8 @@ private: Vec3 _vec3Library; ScriptUUID _uuidLibrary; AnimationCache _animationCache; - + bool _isUserLoaded; + ArrayBufferClass* _arrayBufferClass; QHash _outgoingScriptAudioSequenceNumbers; From 293fc56a66ef8a71605b43953fb9903e436ff269 Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Sat, 6 Sep 2014 15:38:01 -0700 Subject: [PATCH 45/50] use load instead of include for default scripts since Script.load() now works better --- examples/defaultScripts.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/examples/defaultScripts.js b/examples/defaultScripts.js index 18d518d49d..d7d704b02b 100644 --- a/examples/defaultScripts.js +++ b/examples/defaultScripts.js @@ -8,9 +8,9 @@ // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // -Script.include("lookWithTouch.js"); -Script.include("editVoxels.js"); -Script.include("editModels.js"); -Script.include("selectAudioDevice.js"); -Script.include("hydraMove.js"); -Script.include("inspect.js"); \ No newline at end of file +Script.load("lookWithTouch.js"); +Script.load("editVoxels.js"); +Script.load("editModels.js"); +Script.load("selectAudioDevice.js"); +Script.load("hydraMove.js"); +Script.load("inspect.js"); From d734655ab6a7aabe40f471a2417189237e62c585 Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Sat, 6 Sep 2014 16:03:03 -0700 Subject: [PATCH 46/50] fix some recently introduced warnings --- libraries/script-engine/src/ScriptEngine.cpp | 4 ++-- libraries/script-engine/src/TypedArrays.cpp | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/libraries/script-engine/src/ScriptEngine.cpp b/libraries/script-engine/src/ScriptEngine.cpp index a55a05bc5c..d85d201d88 100644 --- a/libraries/script-engine/src/ScriptEngine.cpp +++ b/libraries/script-engine/src/ScriptEngine.cpp @@ -88,7 +88,6 @@ ScriptEngine::ScriptEngine(const QString& scriptContents, const QString& fileNam _isRunning(false), _isInitialized(false), _isAvatar(false), - _isUserLoaded(false), _avatarIdentityTimer(NULL), _avatarBillboardTimer(NULL), _timerFunctionMap(), @@ -103,6 +102,7 @@ ScriptEngine::ScriptEngine(const QString& scriptContents, const QString& fileNam _vec3Library(), _uuidLibrary(), _animationCache(this), + _isUserLoaded(false), _arrayBufferClass(new ArrayBufferClass(this)) { } @@ -114,7 +114,6 @@ ScriptEngine::ScriptEngine(const QUrl& scriptURL, _isRunning(false), _isInitialized(false), _isAvatar(false), - _isUserLoaded(false), _avatarIdentityTimer(NULL), _avatarBillboardTimer(NULL), _timerFunctionMap(), @@ -129,6 +128,7 @@ ScriptEngine::ScriptEngine(const QUrl& scriptURL, _vec3Library(), _uuidLibrary(), _animationCache(this), + _isUserLoaded(false), _arrayBufferClass(new ArrayBufferClass(this)) { QString scriptURLString = scriptURL.toString(); diff --git a/libraries/script-engine/src/TypedArrays.cpp b/libraries/script-engine/src/TypedArrays.cpp index c9663556d9..c1c4117f76 100644 --- a/libraries/script-engine/src/TypedArrays.cpp +++ b/libraries/script-engine/src/TypedArrays.cpp @@ -158,7 +158,7 @@ QScriptClass::QueryFlags TypedArray::queryProperty(const QScriptValue& object, quint32 pos = name.toArrayIndex(&ok); // Check that name is a valid index and arrayBuffer exists - if (ok && pos >= 0 && pos < length) { + if (ok && pos < length) { *id = byteOffset + pos * _bytesPerElement; // save pos to avoid recomputation return HandlesReadAccess | HandlesWriteAccess; // Read/Write access } From 9fdd1f422aaa93ea7bdfe7155c1e18c047c9169a Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Sat, 6 Sep 2014 16:54:36 -0700 Subject: [PATCH 47/50] fix crash on change domains while entities are animating or moving --- libraries/entities/src/EntityTree.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/libraries/entities/src/EntityTree.cpp b/libraries/entities/src/EntityTree.cpp index a571a17a20..d2d87eb111 100644 --- a/libraries/entities/src/EntityTree.cpp +++ b/libraries/entities/src/EntityTree.cpp @@ -39,6 +39,9 @@ void EntityTree::eraseAllOctreeElements(bool createNewRoot) { } _entityToElementMap.clear(); Octree::eraseAllOctreeElements(createNewRoot); + _movingEntities.clear(); + _changingEntities.clear(); + _mortalEntities.clear(); } bool EntityTree::handlesEditPacketType(PacketType packetType) const { From 420f7de95738f64745a3131faf15b89b870b6e87 Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Sun, 7 Sep 2014 20:31:54 -0700 Subject: [PATCH 48/50] fix various crashes in entites --- .../entities/src/DeleteEntityOperator.cpp | 6 +++++ libraries/entities/src/EntityTree.cpp | 5 +++- .../entities/src/MovingEntitiesOperator.cpp | 27 +++++++++++++++++-- .../entities/src/MovingEntitiesOperator.h | 1 + 4 files changed, 36 insertions(+), 3 deletions(-) diff --git a/libraries/entities/src/DeleteEntityOperator.cpp b/libraries/entities/src/DeleteEntityOperator.cpp index dd22425f09..5b0ada4ec1 100644 --- a/libraries/entities/src/DeleteEntityOperator.cpp +++ b/libraries/entities/src/DeleteEntityOperator.cpp @@ -125,6 +125,12 @@ bool DeleteEntityOperator::postRecursion(OctreeElement* element) { if ((subTreeContainsSomeEntitiesToDelete(element))) { element->markWithChangedTime(); } + + // It should always be ok to prune children. Because we are only in this PostRecursion function if + // we've already finished processing all of the children of this current element. If any of those + // children are the containing element for any entity in our lists of entities to delete, then they + // must have already deleted the entity, and they are safe to prune. Since this operation doesn't + // ever add any elements we don't have to worry about memory being reused within this recursion pass. EntityTreeElement* entityTreeElement = static_cast(element); entityTreeElement->pruneChildren(); // take this opportunity to prune any empty leaves return keepSearching; // if we haven't yet found it, keep looking diff --git a/libraries/entities/src/EntityTree.cpp b/libraries/entities/src/EntityTree.cpp index d2d87eb111..4380171df2 100644 --- a/libraries/entities/src/EntityTree.cpp +++ b/libraries/entities/src/EntityTree.cpp @@ -862,6 +862,7 @@ void EntityTree::forgetEntitiesDeletedBefore(quint64 sinceTime) { // TODO: consider consolidating processEraseMessageDetails() and processEraseMessage() int EntityTree::processEraseMessage(const QByteArray& dataByteArray, const SharedNodePointer& sourceNode) { + lockForWrite(); const unsigned char* packetData = (const unsigned char*)dataByteArray.constData(); const unsigned char* dataAt = packetData; size_t packetLength = dataByteArray.size(); @@ -904,10 +905,13 @@ int EntityTree::processEraseMessage(const QByteArray& dataByteArray, const Share } deleteEntities(entityItemIDsToDelete); } + unlock(); + return processedBytes; } // This version skips over the header +// NOTE: Caller must lock the tree before calling this. // TODO: consider consolidating processEraseMessageDetails() and processEraseMessage() int EntityTree::processEraseMessageDetails(const QByteArray& dataByteArray, const SharedNodePointer& sourceNode) { const unsigned char* packetData = (const unsigned char*)dataByteArray.constData(); @@ -941,7 +945,6 @@ int EntityTree::processEraseMessageDetails(const QByteArray& dataByteArray, cons } deleteEntities(entityItemIDsToDelete); } - return processedBytes; } diff --git a/libraries/entities/src/MovingEntitiesOperator.cpp b/libraries/entities/src/MovingEntitiesOperator.cpp index 07242b0f63..d6ccb1aad4 100644 --- a/libraries/entities/src/MovingEntitiesOperator.cpp +++ b/libraries/entities/src/MovingEntitiesOperator.cpp @@ -38,6 +38,7 @@ void MovingEntitiesOperator::addEntityToMoveList(EntityItem* entity, const AACub // check our tree, to determine if this entity is known EntityToMoveDetails details; details.oldContainingElement = oldContainingElement; + details.oldContainingElementCube = oldContainingElement->getAACube(); details.entity = entity; details.oldFound = false; details.newFound = false; @@ -123,8 +124,30 @@ bool MovingEntitiesOperator::postRecursion(OctreeElement* element) { element->markWithChangedTime(); } - EntityTreeElement* entityTreeElement = static_cast(element); - entityTreeElement->pruneChildren(); // take this opportunity to prune any empty leaves + + + // It's not OK to prune if we have the potential of deleting the original containig element. + // because if we prune the containing element then new might end up reallocating the same memory later + // and that will confuse our logic. + // + // it's ok to prune if: + // 2) this subtree doesn't contain any old elements + // 3) this subtree contains an old element, but this element isn't a direct parent of any old containing element + + bool elementSubTreeContainsOldElements = false; + bool elementIsDirectParentOfOldElment = false; + foreach(const EntityToMoveDetails& details, _entitiesToMove) { + if (element->getAACube().contains(details.oldContainingElementCube)) { + elementSubTreeContainsOldElements = true; + } + if (element->isParentOf(details.oldContainingElement)) { + elementIsDirectParentOfOldElment = true; + } + } + if (!elementSubTreeContainsOldElements || !elementIsDirectParentOfOldElment) { + EntityTreeElement* entityTreeElement = static_cast(element); + entityTreeElement->pruneChildren(); // take this opportunity to prune any empty leaves + } return keepSearching; // if we haven't yet found it, keep looking } diff --git a/libraries/entities/src/MovingEntitiesOperator.h b/libraries/entities/src/MovingEntitiesOperator.h index 80096184cb..047cc0c52b 100644 --- a/libraries/entities/src/MovingEntitiesOperator.h +++ b/libraries/entities/src/MovingEntitiesOperator.h @@ -19,6 +19,7 @@ public: AACube newCube; AABox newBox; EntityTreeElement* oldContainingElement; + AACube oldContainingElementCube; bool oldFound; bool newFound; }; From a824712ee6cdb05b1afecbd3bcb390686a9b2145 Mon Sep 17 00:00:00 2001 From: Chris Collins Date: Mon, 8 Sep 2014 10:55:45 -0700 Subject: [PATCH 49/50] Changed list model icon Changed list-model.svg icon to be consistent with the other icons --- examples/editModels.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/editModels.js b/examples/editModels.js index 9f73b30682..cec1bff783 100644 --- a/examples/editModels.js +++ b/examples/editModels.js @@ -1147,10 +1147,10 @@ var toolBar = (function () { }, true, false); browseModelsButton = toolBar.addTool({ - imageURL: toolIconUrl + "list-icon.png", + imageURL: toolIconUrl + "list-icon.svg", width: toolWidth, height: toolHeight, - alpha: 0.7, + alpha: 0.9, visible: true }); From 431fcbcf6c7ba2eaaed97f690f34d72f83380210 Mon Sep 17 00:00:00 2001 From: Craig Hansen-Sturm Date: Mon, 8 Sep 2014 11:18:14 -0700 Subject: [PATCH 50/50] coding standard / SLOT selectAudioSourceSine440 linkage / tone gen amplitude parameter --- interface/src/Menu.cpp | 2 +- libraries/audio/src/AudioBuffer.h | 20 ++++++++++---------- libraries/audio/src/AudioFilter.h | 10 +++++----- libraries/audio/src/AudioFilterBank.h | 6 +++--- libraries/audio/src/AudioSourceTone.h | 9 ++++++--- 5 files changed, 25 insertions(+), 22 deletions(-) diff --git a/interface/src/Menu.cpp b/interface/src/Menu.cpp index 5f6abe9527..c863c098c2 100644 --- a/interface/src/Menu.cpp +++ b/interface/src/Menu.cpp @@ -563,7 +563,7 @@ Menu::Menu() : 0, true, appInstance->getAudio(), - SLOT(selectAudioSourceSine440)); + SLOT(selectAudioSourceSine440())); QActionGroup* audioSourceGroup = new QActionGroup(audioSourceMenu); audioSourceGroup->addAction(pinkNoise); diff --git a/libraries/audio/src/AudioBuffer.h b/libraries/audio/src/AudioBuffer.h index 7c244f47bf..0644139f80 100644 --- a/libraries/audio/src/AudioBuffer.h +++ b/libraries/audio/src/AudioBuffer.h @@ -44,18 +44,18 @@ class AudioFrameBuffer { public: - AudioFrameBuffer() - : _channelCount(0) - , _frameCount(0) - , _frameCountMax(0) - , _frameBuffer(NULL) { + AudioFrameBuffer() : + _channelCount(0), + _frameCount(0), + _frameCountMax(0), + _frameBuffer(NULL) { } - AudioFrameBuffer(const uint16_t channelCount, const uint16_t frameCount) - : _channelCount(channelCount) - , _frameCount(frameCount) - , _frameCountMax(frameCount) - , _frameBuffer(NULL) { + AudioFrameBuffer(const uint16_t channelCount, const uint16_t frameCount) : + _channelCount(channelCount), + _frameCount(frameCount), + _frameCountMax(frameCount), + _frameBuffer(NULL) { allocateFrames(); } diff --git a/libraries/audio/src/AudioFilter.h b/libraries/audio/src/AudioFilter.h index c2de3860db..c9458f280e 100644 --- a/libraries/audio/src/AudioFilter.h +++ b/libraries/audio/src/AudioFilter.h @@ -37,11 +37,11 @@ public: // // ctor/dtor // - AudioBiquad() - : _xm1(0.) - , _xm2(0.) - , _ym1(0.) - , _ym2(0.) { + AudioBiquad() : + _xm1(0.), + _xm2(0.), + _ym1(0.), + _ym2(0.) { setParameters(0.,0.,0.,0.,0.); } diff --git a/libraries/audio/src/AudioFilterBank.h b/libraries/audio/src/AudioFilterBank.h index 46d781075a..b9546999d9 100644 --- a/libraries/audio/src/AudioFilterBank.h +++ b/libraries/audio/src/AudioFilterBank.h @@ -49,9 +49,9 @@ public: // // ctor/dtor // - AudioFilterBank() - : _sampleRate(0.) - , _frameCount(0) { + AudioFilterBank() : + _sampleRate(0.0f), + _frameCount(0) { for (int i = 0; i < _channelCount; ++i) { _buffer[ i ] = NULL; } diff --git a/libraries/audio/src/AudioSourceTone.h b/libraries/audio/src/AudioSourceTone.h index fb9d6be0fe..5ebe1ba2a9 100644 --- a/libraries/audio/src/AudioSourceTone.h +++ b/libraries/audio/src/AudioSourceTone.h @@ -16,6 +16,7 @@ class AudioSourceTone { static uint32_t _frameOffset; float32_t _frequency; + float32_t _amplitude; float32_t _sampleRate; float32_t _omega; @@ -30,7 +31,7 @@ public: void initialize() { _frameOffset = 0; - setParameters(SAMPLE_RATE, 220.0f); + setParameters(SAMPLE_RATE, 220.0f, 0.9f); } void finalize() { @@ -40,15 +41,17 @@ public: _frameOffset = 0; } - void setParameters(const float32_t sampleRate, const float32_t frequency) { + void setParameters(const float32_t sampleRate, const float32_t frequency, const float32_t amplitude) { _sampleRate = std::max(sampleRate, 1.0f); _frequency = std::max(frequency, 1.0f); + _amplitude = std::max(amplitude, 1.0f); _omega = _frequency / _sampleRate * TWO_PI; } - void getParameters(float32_t& sampleRate, float32_t& frequency) { + void getParameters(float32_t& sampleRate, float32_t& frequency, float32_t& amplitude) { sampleRate = _sampleRate; frequency = _frequency; + amplitude = _amplitude; } void render(AudioBufferFloat32& frameBuffer) {