From b0361025b0df025594924281545d33b94d72e848 Mon Sep 17 00:00:00 2001 From: Ryan Huffman Date: Thu, 21 Aug 2014 14:32:38 -0700 Subject: [PATCH 01/31] Remove custom behavior from running scripts widget --- interface/src/Application.cpp | 15 +++++++++------ interface/src/ui/RunningScriptsWidget.cpp | 15 +++++++++------ interface/src/ui/RunningScriptsWidget.h | 3 +-- interface/ui/runningScriptsWidget.ui | 10 ++++++++-- 4 files changed, 27 insertions(+), 16 deletions(-) diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index 11729eef90..4be2e689b8 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -3850,14 +3850,17 @@ void Application::manageRunningScriptsWidgetVisibility(bool shown) { } void Application::toggleRunningScriptsWidget() { - if (_runningScriptsWidgetWasVisible) { - _runningScriptsWidget->hide(); - _runningScriptsWidgetWasVisible = false; + if (_runningScriptsWidget->isVisible()) { + if (_runningScriptsWidget->hasFocus()) { + _runningScriptsWidget->hide(); + } else { + _runningScriptsWidget->raise(); + setActiveWindow(_runningScriptsWidget); + _runningScriptsWidget->setFocus(); + } } else { - _runningScriptsWidget->setBoundary(QRect(_window->geometry().topLeft(), - _window->size())); _runningScriptsWidget->show(); - _runningScriptsWidgetWasVisible = true; + _runningScriptsWidget->setFocus(); } } diff --git a/interface/src/ui/RunningScriptsWidget.cpp b/interface/src/ui/RunningScriptsWidget.cpp index 5bcb1a85de..38298643a3 100644 --- a/interface/src/ui/RunningScriptsWidget.cpp +++ b/interface/src/ui/RunningScriptsWidget.cpp @@ -24,7 +24,7 @@ #include "ScriptsModel.h" RunningScriptsWidget::RunningScriptsWidget(QWidget* parent) : - FramelessDialog(parent, 0, POSITION_LEFT), + QWidget(parent, Qt::Window), ui(new Ui::RunningScriptsWidget), _signalMapper(this), _proxyModel(this), @@ -33,8 +33,6 @@ RunningScriptsWidget::RunningScriptsWidget(QWidget* parent) : setAttribute(Qt::WA_DeleteOnClose, false); - setAllowResize(false); - ui->hideWidgetButton->setIcon(QIcon(Application::resourcesPath() + "images/close.svg")); ui->reloadAllButton->setIcon(QIcon(Application::resourcesPath() + "images/reload.svg")); ui->stopAllButton->setIcon(QIcon(Application::resourcesPath() + "images/stop.svg")); @@ -143,6 +141,8 @@ void RunningScriptsWidget::setRunningScripts(const QStringList& list) { line->setFrameShape(QFrame::HLine); line->setStyleSheet("color: #E1E1E1; margin-left: 6px; margin-right: 6px;"); + row->setStyleSheet("background: #f7f7f7;"); + ui->scrollAreaWidgetContents->layout()->addWidget(row); ui->scrollAreaWidgetContents->layout()->addWidget(line); } @@ -163,7 +163,10 @@ void RunningScriptsWidget::showEvent(QShowEvent* event) { ui->filterLineEdit->setFocus(); } - FramelessDialog::showEvent(event); + const QRect parentGeometry = parentWidget()->geometry(); + setGeometry(parentGeometry.topLeft().x(), parentGeometry.topLeft().y(), size().width(), parentWidget()->size().height()); + + QWidget::showEvent(event); } void RunningScriptsWidget::selectFirstInList() { @@ -189,14 +192,14 @@ bool RunningScriptsWidget::eventFilter(QObject* sender, QEvent* event) { return false; } - return FramelessDialog::eventFilter(sender, event); + return QWidget::eventFilter(sender, event); } void RunningScriptsWidget::keyPressEvent(QKeyEvent *keyEvent) { if (keyEvent->key() == Qt::Key_Escape) { return; } else { - FramelessDialog::keyPressEvent(keyEvent); + QWidget::keyPressEvent(keyEvent); } } diff --git a/interface/src/ui/RunningScriptsWidget.h b/interface/src/ui/RunningScriptsWidget.h index 6810aca487..7493a1a5ce 100644 --- a/interface/src/ui/RunningScriptsWidget.h +++ b/interface/src/ui/RunningScriptsWidget.h @@ -25,8 +25,7 @@ namespace Ui { class RunningScriptsWidget; } -class RunningScriptsWidget : public FramelessDialog -{ +class RunningScriptsWidget : public QWidget { Q_OBJECT public: explicit RunningScriptsWidget(QWidget* parent = NULL); diff --git a/interface/ui/runningScriptsWidget.ui b/interface/ui/runningScriptsWidget.ui index b58c8436d0..42d4813021 100644 --- a/interface/ui/runningScriptsWidget.ui +++ b/interface/ui/runningScriptsWidget.ui @@ -7,7 +7,7 @@ 0 0 324 - 971 + 643 @@ -17,7 +17,7 @@ * { font-family: Helvetica, Arial, sans-serif; } -QWidget { +#RunningScriptsWidget { background: #f7f7f7; } @@ -326,6 +326,11 @@ padding-top: 3px; Qt::LeftToRight + + #runningScriptsList { + background: #f7f7f7; +} + QFrame::NoFrame @@ -608,6 +613,7 @@ background-color: white; QListView { + background: #f7f7f7; border: 1px solid rgb(128, 128, 128); border-radius: 2px; } From dcae9eb6da1a8b701abaa54d7f2594f6778c6079 Mon Sep 17 00:00:00 2001 From: Ryan Huffman Date: Thu, 21 Aug 2014 14:57:55 -0700 Subject: [PATCH 02/31] Remove fullscreen button from running scripts window --- interface/src/ui/RunningScriptsWidget.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/interface/src/ui/RunningScriptsWidget.cpp b/interface/src/ui/RunningScriptsWidget.cpp index 38298643a3..163b83367d 100644 --- a/interface/src/ui/RunningScriptsWidget.cpp +++ b/interface/src/ui/RunningScriptsWidget.cpp @@ -24,7 +24,8 @@ #include "ScriptsModel.h" RunningScriptsWidget::RunningScriptsWidget(QWidget* parent) : - QWidget(parent, Qt::Window), + QWidget(parent, Qt::Window | Qt::CustomizeWindowHint | Qt::WindowTitleHint | Qt::WindowMinMaxButtonsHint | + Qt::WindowCloseButtonHint), ui(new Ui::RunningScriptsWidget), _signalMapper(this), _proxyModel(this), From dd8f7765254bdd6b3b1a49b6e5ae424d3665749d Mon Sep 17 00:00:00 2001 From: Ryan Huffman Date: Thu, 21 Aug 2014 15:06:27 -0700 Subject: [PATCH 03/31] Fix size of running scripts window --- interface/src/ui/RunningScriptsWidget.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/interface/src/ui/RunningScriptsWidget.cpp b/interface/src/ui/RunningScriptsWidget.cpp index 163b83367d..11ced36142 100644 --- a/interface/src/ui/RunningScriptsWidget.cpp +++ b/interface/src/ui/RunningScriptsWidget.cpp @@ -165,7 +165,7 @@ void RunningScriptsWidget::showEvent(QShowEvent* event) { } const QRect parentGeometry = parentWidget()->geometry(); - setGeometry(parentGeometry.topLeft().x(), parentGeometry.topLeft().y(), size().width(), parentWidget()->size().height()); + setGeometry(parentGeometry.topLeft().x(), parentGeometry.topLeft().y(), size().width(), parentWidget()->height()); QWidget::showEvent(event); } From b3bdfc45ce0c59051cc77dd50b8f29a67a0edd2c Mon Sep 17 00:00:00 2001 From: Ryan Huffman Date: Thu, 21 Aug 2014 15:13:08 -0700 Subject: [PATCH 04/31] Remove close button from running scripts widget --- interface/src/ui/RunningScriptsWidget.cpp | 3 --- interface/ui/runningScriptsWidget.ui | 22 ---------------------- 2 files changed, 25 deletions(-) diff --git a/interface/src/ui/RunningScriptsWidget.cpp b/interface/src/ui/RunningScriptsWidget.cpp index 11ced36142..a2da0412ff 100644 --- a/interface/src/ui/RunningScriptsWidget.cpp +++ b/interface/src/ui/RunningScriptsWidget.cpp @@ -34,7 +34,6 @@ RunningScriptsWidget::RunningScriptsWidget(QWidget* parent) : setAttribute(Qt::WA_DeleteOnClose, false); - ui->hideWidgetButton->setIcon(QIcon(Application::resourcesPath() + "images/close.svg")); ui->reloadAllButton->setIcon(QIcon(Application::resourcesPath() + "images/reload.svg")); ui->stopAllButton->setIcon(QIcon(Application::resourcesPath() + "images/stop.svg")); ui->loadScriptButton->setIcon(QIcon(Application::resourcesPath() + "images/plus-white.svg")); @@ -58,8 +57,6 @@ RunningScriptsWidget::RunningScriptsWidget(QWidget* parent) : _recentlyLoadedScriptsTable->setColumnCount(1); _recentlyLoadedScriptsTable->setColumnWidth(0, 265); - connect(ui->hideWidgetButton, &QPushButton::clicked, - Application::getInstance(), &Application::toggleRunningScriptsWidget); connect(ui->reloadAllButton, &QPushButton::clicked, Application::getInstance(), &Application::reloadAllScripts); connect(ui->stopAllButton, &QPushButton::clicked, diff --git a/interface/ui/runningScriptsWidget.ui b/interface/ui/runningScriptsWidget.ui index 42d4813021..e5d5ba0e98 100644 --- a/interface/ui/runningScriptsWidget.ui +++ b/interface/ui/runningScriptsWidget.ui @@ -77,28 +77,6 @@ background: transparent; - - - - PointingHandCursor - - - border: 0 - - - - - - - 16 - 16 - - - - true - - - From ad4956b2e2a309c3405a62d5bbaf3aec2418c040 Mon Sep 17 00:00:00 2001 From: Ryan Huffman Date: Thu, 21 Aug 2014 17:19:39 -0700 Subject: [PATCH 05/31] Update assignment client to close on WM_CLOSE message on Windows --- assignment-client/src/AssignmentClient.cpp | 16 +++++++++++++++- assignment-client/src/AssignmentClient.h | 5 ++++- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/assignment-client/src/AssignmentClient.cpp b/assignment-client/src/AssignmentClient.cpp index 009bd42e88..5c9a5453b9 100644 --- a/assignment-client/src/AssignmentClient.cpp +++ b/assignment-client/src/AssignmentClient.cpp @@ -41,7 +41,9 @@ AssignmentClient::AssignmentClient(int &argc, char **argv) : setOrganizationDomain("highfidelity.io"); setApplicationName("assignment-client"); QSettings::setDefaultFormat(QSettings::IniFormat); - + + installNativeEventFilter(this); + QStringList argumentList = arguments(); // register meta type is required for queued invoke method on Assignment subclasses @@ -113,6 +115,18 @@ AssignmentClient::AssignmentClient(int &argc, char **argv) : this, &AssignmentClient::handleAuthenticationRequest); } +bool AssignmentClient::nativeEventFilter(const QByteArray &eventType, void* msg, long* result) { + if (eventType == "windows_generic_MSG") { + MSG* message = (MSG*)msg; + if (message->message == WM_CLOSE) { + qDebug() << "Received WM_CLOSE message, closing"; + quit(); + return false; + } + } + return true; +} + void AssignmentClient::sendAssignmentRequest() { if (!_currentAssignment) { NodeList::getInstance()->sendAssignment(_requestAssignment); diff --git a/assignment-client/src/AssignmentClient.h b/assignment-client/src/AssignmentClient.h index 9834402dbf..7b57cd65c1 100644 --- a/assignment-client/src/AssignmentClient.h +++ b/assignment-client/src/AssignmentClient.h @@ -13,14 +13,17 @@ #define hifi_AssignmentClient_h #include +#include #include "ThreadedAssignment.h" -class AssignmentClient : public QCoreApplication { +class AssignmentClient : public QCoreApplication, QAbstractNativeEventFilter { Q_OBJECT public: AssignmentClient(int &argc, char **argv); static const SharedAssignmentPointer& getCurrentAssignment() { return _currentAssignment; } + virtual bool nativeEventFilter(const QByteArray& eventType, void* message, long* result); + private slots: void sendAssignmentRequest(); void readPendingDatagrams(); From e71366f304ccc5b51e992ffb4e770b1fa649f675 Mon Sep 17 00:00:00 2001 From: Ryan Huffman Date: Thu, 21 Aug 2014 17:37:40 -0700 Subject: [PATCH 06/31] Add guards around custom windows message handling --- assignment-client/src/AssignmentClient.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/assignment-client/src/AssignmentClient.cpp b/assignment-client/src/AssignmentClient.cpp index 5c9a5453b9..0fc5d90645 100644 --- a/assignment-client/src/AssignmentClient.cpp +++ b/assignment-client/src/AssignmentClient.cpp @@ -116,6 +116,7 @@ AssignmentClient::AssignmentClient(int &argc, char **argv) : } bool AssignmentClient::nativeEventFilter(const QByteArray &eventType, void* msg, long* result) { +#if Q_OS_WIN if (eventType == "windows_generic_MSG") { MSG* message = (MSG*)msg; if (message->message == WM_CLOSE) { @@ -124,6 +125,7 @@ bool AssignmentClient::nativeEventFilter(const QByteArray &eventType, void* msg, return false; } } +#endif return true; } From bc28bfa4640d17c4240ba5dee527d7fa5f18b861 Mon Sep 17 00:00:00 2001 From: Ryan Huffman Date: Thu, 21 Aug 2014 17:41:17 -0700 Subject: [PATCH 07/31] Add guards around custom windows message handling --- assignment-client/src/AssignmentClient.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/assignment-client/src/AssignmentClient.cpp b/assignment-client/src/AssignmentClient.cpp index 5c9a5453b9..813062bd6f 100644 --- a/assignment-client/src/AssignmentClient.cpp +++ b/assignment-client/src/AssignmentClient.cpp @@ -116,6 +116,7 @@ AssignmentClient::AssignmentClient(int &argc, char **argv) : } bool AssignmentClient::nativeEventFilter(const QByteArray &eventType, void* msg, long* result) { +#ifdef Q_OS_WIN if (eventType == "windows_generic_MSG") { MSG* message = (MSG*)msg; if (message->message == WM_CLOSE) { @@ -124,6 +125,7 @@ bool AssignmentClient::nativeEventFilter(const QByteArray &eventType, void* msg, return false; } } +#endif return true; } From cd46a553696d46e81f728a60c3194f668a4dca78 Mon Sep 17 00:00:00 2001 From: Ryan Huffman Date: Fri, 22 Aug 2014 09:33:13 -0700 Subject: [PATCH 08/31] Fix QAbstractNativeEventFilter include --- assignment-client/src/AssignmentClient.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/assignment-client/src/AssignmentClient.h b/assignment-client/src/AssignmentClient.h index 7b57cd65c1..693ac6dbba 100644 --- a/assignment-client/src/AssignmentClient.h +++ b/assignment-client/src/AssignmentClient.h @@ -13,7 +13,7 @@ #define hifi_AssignmentClient_h #include -#include +#include #include "ThreadedAssignment.h" From b75c3a4976dd40d6e4972383fd66bae5ea736986 Mon Sep 17 00:00:00 2001 From: Ryan Huffman Date: Fri, 22 Aug 2014 15:08:57 -0700 Subject: [PATCH 09/31] Disable stdout/err buffering on Windows for assignment client and domain server --- assignment-client/src/AssignmentClient.cpp | 11 +++++++++++ domain-server/src/DomainServer.cpp | 11 +++++++++++ 2 files changed, 22 insertions(+) diff --git a/assignment-client/src/AssignmentClient.cpp b/assignment-client/src/AssignmentClient.cpp index 813062bd6f..ac0ab887d7 100644 --- a/assignment-client/src/AssignmentClient.cpp +++ b/assignment-client/src/AssignmentClient.cpp @@ -37,6 +37,17 @@ AssignmentClient::AssignmentClient(int &argc, char **argv) : QCoreApplication(argc, argv), _assignmentServerHostname(DEFAULT_ASSIGNMENT_SERVER_HOSTNAME) { + +#ifdef Q_OS_WIN + // Windows applications buffer stdout/err hard when not run from a terminal, + // making assignment clients run from the Stack Manager application not flush + // log messages. + // This will disable the buffering. If this becomes a performance issue, + // an alternative is to call fflush(...) periodically. + setbuf(stdout, NULL); + setbuf(stderr, NULL); +#endif + setOrganizationName("High Fidelity"); setOrganizationDomain("highfidelity.io"); setApplicationName("assignment-client"); diff --git a/domain-server/src/DomainServer.cpp b/domain-server/src/DomainServer.cpp index b5c2d00d3e..8c388c6e47 100644 --- a/domain-server/src/DomainServer.cpp +++ b/domain-server/src/DomainServer.cpp @@ -43,6 +43,17 @@ DomainServer::DomainServer(int argc, char* argv[]) : _networkReplyUUIDMap(), _sessionAuthenticationHash() { + +#ifdef Q_OS_WIN + // Windows applications buffer stdout/err hard when not run from a terminal, + // making a domain server run from the Stack Manager application not flush + // log messages. + // This will disable the buffering. If this becomes a performance issue, + // an alternative is to call fflush(...) periodically. + setbuf(stdout, NULL); + setbuf(stderr, NULL); +#endif + setOrganizationName("High Fidelity"); setOrganizationDomain("highfidelity.io"); setApplicationName("domain-server"); From fa7b2a87bf1c78337a8615c9b2ab479dec7766c1 Mon Sep 17 00:00:00 2001 From: Ryan Huffman Date: Fri, 22 Aug 2014 15:09:55 -0700 Subject: [PATCH 10/31] Add WM_CLOSE support to domain server --- assignment-client/src/AssignmentClient.h | 2 +- domain-server/src/DomainServer.cpp | 16 ++++++++++++++++ domain-server/src/DomainServer.h | 5 ++++- 3 files changed, 21 insertions(+), 2 deletions(-) diff --git a/assignment-client/src/AssignmentClient.h b/assignment-client/src/AssignmentClient.h index 693ac6dbba..5c8d1945ee 100644 --- a/assignment-client/src/AssignmentClient.h +++ b/assignment-client/src/AssignmentClient.h @@ -17,7 +17,7 @@ #include "ThreadedAssignment.h" -class AssignmentClient : public QCoreApplication, QAbstractNativeEventFilter { +class AssignmentClient : public QCoreApplication, public QAbstractNativeEventFilter { Q_OBJECT public: AssignmentClient(int &argc, char **argv); diff --git a/domain-server/src/DomainServer.cpp b/domain-server/src/DomainServer.cpp index b5c2d00d3e..ddef6e7ab1 100644 --- a/domain-server/src/DomainServer.cpp +++ b/domain-server/src/DomainServer.cpp @@ -47,6 +47,8 @@ DomainServer::DomainServer(int argc, char* argv[]) : setOrganizationDomain("highfidelity.io"); setApplicationName("domain-server"); QSettings::setDefaultFormat(QSettings::IniFormat); + + installNativeEventFilter(this); _argumentVariantMap = HifiConfigVariantMap::mergeCLParametersWithJSONConfig(arguments()); @@ -61,6 +63,20 @@ DomainServer::DomainServer(int argc, char* argv[]) : } } +bool DomainServer::nativeEventFilter(const QByteArray &eventType, void* msg, long* result) { +#ifdef Q_OS_WIN + if (eventType == "windows_generic_MSG") { + MSG* message = (MSG*)msg; + if (message->message == WM_CLOSE) { + qDebug() << "Received WM_CLOSE message, closing"; + quit(); + return false; + } + } +#endif + return true; +} + bool DomainServer::optionallyReadX509KeyAndCertificate() { const QString X509_CERTIFICATE_OPTION = "cert"; const QString X509_PRIVATE_KEY_OPTION = "key"; diff --git a/domain-server/src/DomainServer.h b/domain-server/src/DomainServer.h index b038850b3d..e6eddacbce 100644 --- a/domain-server/src/DomainServer.h +++ b/domain-server/src/DomainServer.h @@ -19,6 +19,7 @@ #include #include #include +#include #include #include @@ -31,13 +32,15 @@ typedef QSharedPointer SharedAssignmentPointer; typedef QMultiHash TransactionHash; -class DomainServer : public QCoreApplication, public HTTPSRequestHandler { +class DomainServer : public QCoreApplication, public HTTPSRequestHandler, public QAbstractNativeEventFilter { Q_OBJECT public: DomainServer(int argc, char* argv[]); bool handleHTTPRequest(HTTPConnection* connection, const QUrl& url); bool handleHTTPSRequest(HTTPSConnection* connection, const QUrl& url); + + bool nativeEventFilter(const QByteArray &eventType, void* msg, long* result); void exit(int retCode = 0); From ce0e0a9c592aea1841694e53811c9d1f8114e209 Mon Sep 17 00:00:00 2001 From: Ryan Huffman Date: Sun, 31 Aug 2014 11:30:26 -0700 Subject: [PATCH 11/31] Remove custom background, font, and button styles on RunningScripts --- interface/src/ui/RunningScriptsWidget.cpp | 2 - interface/ui/runningScriptsWidget.ui | 86 ----------------------- 2 files changed, 88 deletions(-) diff --git a/interface/src/ui/RunningScriptsWidget.cpp b/interface/src/ui/RunningScriptsWidget.cpp index a2da0412ff..72147ee1b2 100644 --- a/interface/src/ui/RunningScriptsWidget.cpp +++ b/interface/src/ui/RunningScriptsWidget.cpp @@ -139,8 +139,6 @@ void RunningScriptsWidget::setRunningScripts(const QStringList& list) { line->setFrameShape(QFrame::HLine); line->setStyleSheet("color: #E1E1E1; margin-left: 6px; margin-right: 6px;"); - row->setStyleSheet("background: #f7f7f7;"); - ui->scrollAreaWidgetContents->layout()->addWidget(row); ui->scrollAreaWidgetContents->layout()->addWidget(line); } diff --git a/interface/ui/runningScriptsWidget.ui b/interface/ui/runningScriptsWidget.ui index e5d5ba0e98..0dd418af70 100644 --- a/interface/ui/runningScriptsWidget.ui +++ b/interface/ui/runningScriptsWidget.ui @@ -13,14 +13,6 @@ Form - - * { - font-family: Helvetica, Arial, sans-serif; -} -#RunningScriptsWidget { - background: #f7f7f7; -} - 20 @@ -114,7 +106,6 @@ background: transparent; - Helvetica,Arial,sans-serif -1 75 false @@ -173,31 +164,6 @@ background: transparent; - - - 0 - 0 - - - - - 111 - 35 - - - - PointingHandCursor - - - false - - - background: #0e7077; -color: #fff; -border-radius: 4px; -font: bold 14px; -padding-top: 3px; - Reload all @@ -205,28 +171,6 @@ padding-top: 3px; - - - 0 - 0 - - - - - 111 - 35 - - - - PointingHandCursor - - - background: #0e7077; -color: #fff; -border-radius: 4px; -font: bold 14px; -padding-top: 3px; - Stop all @@ -304,11 +248,6 @@ padding-top: 3px; Qt::LeftToRight - - #runningScriptsList { - background: #f7f7f7; -} - QFrame::NoFrame @@ -459,9 +398,6 @@ font-size: 14px; 300 - - - 0 @@ -522,28 +458,6 @@ font: bold 16px; - - - 0 - 0 - - - - - 111 - 35 - - - - PointingHandCursor - - - background: #0e7077; -color: #fff; -border-radius: 4px; -font: bold 14px; -padding-top: 3px; - Load script From 2283b68dba1072fc7f7d4f30f4e050b0e0fb1760 Mon Sep 17 00:00:00 2001 From: Ryan Huffman Date: Sun, 31 Aug 2014 11:31:45 -0700 Subject: [PATCH 12/31] Remove 'recently loaded' widgets from RunningScripts --- interface/src/ui/RunningScriptsWidget.cpp | 7 --- interface/ui/runningScriptsWidget.ui | 77 ----------------------- 2 files changed, 84 deletions(-) diff --git a/interface/src/ui/RunningScriptsWidget.cpp b/interface/src/ui/RunningScriptsWidget.cpp index 72147ee1b2..f0e4f427d9 100644 --- a/interface/src/ui/RunningScriptsWidget.cpp +++ b/interface/src/ui/RunningScriptsWidget.cpp @@ -38,8 +38,6 @@ RunningScriptsWidget::RunningScriptsWidget(QWidget* parent) : ui->stopAllButton->setIcon(QIcon(Application::resourcesPath() + "images/stop.svg")); ui->loadScriptButton->setIcon(QIcon(Application::resourcesPath() + "images/plus-white.svg")); - ui->recentlyLoadedScriptsArea->hide(); - ui->filterLineEdit->installEventFilter(this); connect(&_proxyModel, &QSortFilterProxyModel::modelReset, @@ -53,10 +51,6 @@ RunningScriptsWidget::RunningScriptsWidget(QWidget* parent) : connect(ui->filterLineEdit, &QLineEdit::textChanged, this, &RunningScriptsWidget::updateFileFilter); connect(ui->scriptListView, &QListView::doubleClicked, this, &RunningScriptsWidget::loadScriptFromList); - _recentlyLoadedScriptsTable = new ScriptsTableWidget(ui->recentlyLoadedScriptsTableWidget); - _recentlyLoadedScriptsTable->setColumnCount(1); - _recentlyLoadedScriptsTable->setColumnWidth(0, 265); - connect(ui->reloadAllButton, &QPushButton::clicked, Application::getInstance(), &Application::reloadAllScripts); connect(ui->stopAllButton, &QPushButton::clicked, @@ -200,7 +194,6 @@ void RunningScriptsWidget::keyPressEvent(QKeyEvent *keyEvent) { } void RunningScriptsWidget::scriptStopped(const QString& scriptName) { - // _recentlyLoadedScripts.prepend(scriptName); } void RunningScriptsWidget::allScriptsStopped() { diff --git a/interface/ui/runningScriptsWidget.ui b/interface/ui/runningScriptsWidget.ui index 0dd418af70..701c4ca75e 100644 --- a/interface/ui/runningScriptsWidget.ui +++ b/interface/ui/runningScriptsWidget.ui @@ -307,83 +307,6 @@ background: transparent; - - - - true - - - - 0 - 100 - - - - - 16777215 - 16777215 - - - - - 0 - - - 0 - - - 0 - - - 0 - - - 0 - - - - - color: #0e7077; -font: bold 16px; - - - <html><head/><body><p><span style=" font-weight:600;">Recently loaded</span></p></body></html> - - - - - - - font: 14px; - - - There are no recently loaded scripts. - - - - - - - - 0 - 1 - - - - - 284 - 0 - - - - background: transparent; -font-size: 14px; - - - - - - From 936a9fad4784c0e41bf7af05ca2b1a0c04fe5930 Mon Sep 17 00:00:00 2001 From: Ryan Huffman Date: Sun, 31 Aug 2014 12:28:45 -0700 Subject: [PATCH 13/31] Disable icons on RunningScripts buttons --- interface/src/ui/RunningScriptsWidget.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/interface/src/ui/RunningScriptsWidget.cpp b/interface/src/ui/RunningScriptsWidget.cpp index f0e4f427d9..ee04c68b14 100644 --- a/interface/src/ui/RunningScriptsWidget.cpp +++ b/interface/src/ui/RunningScriptsWidget.cpp @@ -34,9 +34,9 @@ RunningScriptsWidget::RunningScriptsWidget(QWidget* parent) : setAttribute(Qt::WA_DeleteOnClose, false); - ui->reloadAllButton->setIcon(QIcon(Application::resourcesPath() + "images/reload.svg")); - ui->stopAllButton->setIcon(QIcon(Application::resourcesPath() + "images/stop.svg")); - ui->loadScriptButton->setIcon(QIcon(Application::resourcesPath() + "images/plus-white.svg")); + //ui->reloadAllButton->setIcon(QIcon(Application::resourcesPath() + "images/reload.svg")); + //ui->stopAllButton->setIcon(QIcon(Application::resourcesPath() + "images/stop.svg")); + //ui->loadScriptButton->setIcon(QIcon(Application::resourcesPath() + "images/plus.svg")); ui->filterLineEdit->installEventFilter(this); From 9e510632b9d5f196c8c29a129d52c5172758a71b Mon Sep 17 00:00:00 2001 From: Ryan Huffman Date: Sun, 31 Aug 2014 12:29:54 -0700 Subject: [PATCH 14/31] Remove box styling from RunningScripts --- interface/ui/runningScriptsWidget.ui | 55 +++------------------------- 1 file changed, 6 insertions(+), 49 deletions(-) diff --git a/interface/ui/runningScriptsWidget.ui b/interface/ui/runningScriptsWidget.ui index 701c4ca75e..8bb29a2f49 100644 --- a/interface/ui/runningScriptsWidget.ui +++ b/interface/ui/runningScriptsWidget.ui @@ -42,11 +42,10 @@ color: #0e7077; -font-size: 20px; -background: transparent; +font-size: 20px; - <html><head/><body><p><span style=" font-size:18px;">Running Scripts</span></p></body></html> + Running Scripts 0 @@ -115,10 +114,10 @@ background: transparent; color: #0e7077; font: bold 16px; -background: transparent; + - <html><head/><body><p><span style=" font-weight:600;">Currently running</span></p></body></html> + Currently Running @@ -147,9 +146,6 @@ background: transparent; - - 24 - 0 @@ -183,8 +179,8 @@ background: transparent; - 40 - 20 + 0 + 0 @@ -192,22 +188,6 @@ background: transparent; - - - - Qt::Vertical - - - QSizePolicy::Fixed - - - - 20 - 8 - - - - @@ -391,12 +371,6 @@ font: bold 16px; - - border: 1px solid rgb(128, 128, 128); -border-radius: 2px; -padding: 4px; -background-color: white; - @@ -426,23 +400,6 @@ background-color: white; - - QListView { - background: #f7f7f7; - border: 1px solid rgb(128, 128, 128); - border-radius: 2px; -} -QListView::item { - padding-top: 2px; - padding-bottom: 2px; -} - - - QFrame::Box - - - QFrame::Plain - Qt::ScrollBarAlwaysOn From a95b670716f601598606bcbd6f1a2ca007b46d09 Mon Sep 17 00:00:00 2001 From: Ryan Huffman Date: Tue, 2 Sep 2014 12:37:51 -0700 Subject: [PATCH 15/31] Update RunningScripts style: font, spacing, title --- interface/ui/runningScriptsWidget.ui | 333 +++++++++++++++------------ 1 file changed, 184 insertions(+), 149 deletions(-) diff --git a/interface/ui/runningScriptsWidget.ui b/interface/ui/runningScriptsWidget.ui index 8bb29a2f49..5d21dc387e 100644 --- a/interface/ui/runningScriptsWidget.ui +++ b/interface/ui/runningScriptsWidget.ui @@ -11,17 +11,20 @@ - Form + Running Scripts + + + * { font-family: Helvetica, Arial, sans-serif; } - 20 + 14 20 - 20 + 14 20 @@ -30,13 +33,13 @@ - 0 + 6 0 - 0 + 6 @@ -102,23 +105,45 @@ font-size: 20px; 0 - - - - -1 - 75 - false - true - - - - color: #0e7077; + + + + 0 + + + 6 + + + 0 + + + 6 + + + 0 + + + + + + Helvetica,Arial,sans-serif + -1 + 75 + false + true + + + + color: #0e7077; font: bold 16px; - - - Currently Running - + + + Currently Running + + + + @@ -145,6 +170,9 @@ font: bold 16px; 0 + + reloadStopButtonArea { padding: 0 } + 0 @@ -189,99 +217,104 @@ font: bold 16px; - - - font: 14px; - - - There are no scripts currently running. - - - Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter - - - - - - - Qt::Vertical - - - QSizePolicy::Fixed - - - - 20 - 10 - - - - - - - - - Helvetica,Arial,sans-serif - 14 - - - - Qt::LeftToRight - - - QFrame::NoFrame - - - 0 - - - Qt::ScrollBarAsNeeded - - - Qt::ScrollBarAlwaysOff - - - true - - - Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop - - - - - 0 - 0 - 284 - 16 - + + + + 0 - - - 0 - 0 - + + 6 - - font-size: 14px; + + 0 - - - 0 - - - 0 - - - 0 - - - 0 - - - 0 - - - + + 6 + + + 0 + + + + + + Helvetica,Arial,sans-serif + 14 + + + + Qt::LeftToRight + + + QFrame::NoFrame + + + 0 + + + Qt::ScrollBarAsNeeded + + + Qt::ScrollBarAlwaysOff + + + true + + + Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop + + + + + 0 + 0 + 284 + 16 + + + + + 0 + 0 + + + + font-size: 14px; + + + + 0 + + + 0 + + + 0 + + + 0 + + + 0 + + + + + + + + + font: 14px; + + + There are no scripts currently running. + + + Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter + + + + @@ -324,16 +357,16 @@ font: bold 16px; 0 - 0 + 6 0 - 0 + 6 - 15 + 0 @@ -370,42 +403,44 @@ font: bold 16px; - - - - - - filter - - - true - - - - - - - Qt::Vertical - - - QSizePolicy::Fixed - - - - 20 - 6 - - - - - - - - Qt::ScrollBarAlwaysOn - - - Qt::ScrollBarAlwaysOff - + + + + 6 + + + 0 + + + 6 + + + 0 + + + + + + + + filter + + + true + + + + + + + Qt::ScrollBarAlwaysOn + + + Qt::ScrollBarAlwaysOff + + + + From 67cefc8d54957019e942c796ca32133e50172ffb Mon Sep 17 00:00:00 2001 From: Ryan Huffman Date: Tue, 2 Sep 2014 13:12:52 -0700 Subject: [PATCH 16/31] Reduce height of RunningScripts so titlebar is inside main window --- interface/src/ui/RunningScriptsWidget.cpp | 6 ++++- libraries/shared/src/UIUtil.cpp | 29 +++++++++++++++++++++++ libraries/shared/src/UIUtil.h | 24 +++++++++++++++++++ 3 files changed, 58 insertions(+), 1 deletion(-) create mode 100644 libraries/shared/src/UIUtil.cpp create mode 100644 libraries/shared/src/UIUtil.h diff --git a/interface/src/ui/RunningScriptsWidget.cpp b/interface/src/ui/RunningScriptsWidget.cpp index ee04c68b14..7f3428784b 100644 --- a/interface/src/ui/RunningScriptsWidget.cpp +++ b/interface/src/ui/RunningScriptsWidget.cpp @@ -22,6 +22,7 @@ #include "Application.h" #include "Menu.h" #include "ScriptsModel.h" +#include "UIUtil.h" RunningScriptsWidget::RunningScriptsWidget(QWidget* parent) : QWidget(parent, Qt::Window | Qt::CustomizeWindowHint | Qt::WindowTitleHint | Qt::WindowMinMaxButtonsHint | @@ -154,7 +155,10 @@ void RunningScriptsWidget::showEvent(QShowEvent* event) { } const QRect parentGeometry = parentWidget()->geometry(); - setGeometry(parentGeometry.topLeft().x(), parentGeometry.topLeft().y(), size().width(), parentWidget()->height()); + int titleBarHeight = UIUtil::getWindowTitleBarHeight(this); + + setGeometry(parentGeometry.topLeft().x(), parentGeometry.topLeft().y() + titleBarHeight, + size().width(), parentWidget()->height() - titleBarHeight); QWidget::showEvent(event); } diff --git a/libraries/shared/src/UIUtil.cpp b/libraries/shared/src/UIUtil.cpp new file mode 100644 index 0000000000..82c41e42c8 --- /dev/null +++ b/libraries/shared/src/UIUtil.cpp @@ -0,0 +1,29 @@ +// +// UIUtil.cpp +// library/shared/src +// +// Created by Ryan Huffman on 09/02/2014. +// 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 "UIUtil.h" + +int UIUtil::getWindowTitleBarHeight(QWidget *window) { + QStyleOptionTitleBar options; + options.titleBarState = 1; + options.titleBarFlags = Qt::Window; + int titleBarHeight = window->style()->pixelMetric(QStyle::PM_TitleBarHeight, &options, window); + +#if defined(Q_OS_MAC) + // The height on OSX is 4 pixels too tall + titleBarHeight -= 4; +#endif + + return titleBarHeight; +} diff --git a/libraries/shared/src/UIUtil.h b/libraries/shared/src/UIUtil.h new file mode 100644 index 0000000000..3eeae9efbd --- /dev/null +++ b/libraries/shared/src/UIUtil.h @@ -0,0 +1,24 @@ +// +// UIUtil.h +// library/shared/src +// +// Created by Ryan Huffman on 09/02/2014. +// 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_UIUtil_h +#define hifi_UIUtil_h + +#include + +class UIUtil { +public: + static int getWindowTitleBarHeight(QWidget *window); + +}; + +#endif // hifi_UIUtil_h From e6def6e35b4f8f25faa3c2cc92564a445c81126e Mon Sep 17 00:00:00 2001 From: Ryan Huffman Date: Tue, 2 Sep 2014 14:01:24 -0700 Subject: [PATCH 17/31] Fix spacing on RunningScripts --- interface/ui/runningScriptsWidget.ui | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/interface/ui/runningScriptsWidget.ui b/interface/ui/runningScriptsWidget.ui index 5d21dc387e..ddc6ad6c27 100644 --- a/interface/ui/runningScriptsWidget.ui +++ b/interface/ui/runningScriptsWidget.ui @@ -175,13 +175,13 @@ font: bold 16px; - 0 + 6 0 - 0 + 6 0 @@ -360,13 +360,13 @@ font: bold 16px; 6 - 0 + 6 6 - 0 + 6 From 55acff02a18f41c3fef8b53af346891e88654727 Mon Sep 17 00:00:00 2001 From: Ryan Huffman Date: Tue, 2 Sep 2014 14:13:42 -0700 Subject: [PATCH 18/31] Update RunningScripts height to take menu bar into account --- interface/src/ui/RunningScriptsWidget.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/interface/src/ui/RunningScriptsWidget.cpp b/interface/src/ui/RunningScriptsWidget.cpp index 7f3428784b..52735f3a2b 100644 --- a/interface/src/ui/RunningScriptsWidget.cpp +++ b/interface/src/ui/RunningScriptsWidget.cpp @@ -156,9 +156,11 @@ void RunningScriptsWidget::showEvent(QShowEvent* event) { const QRect parentGeometry = parentWidget()->geometry(); int titleBarHeight = UIUtil::getWindowTitleBarHeight(this); + int menuBarHeight = Menu::getInstance()->geometry().height(); + int topMargin = titleBarHeight + menuBarHeight; - setGeometry(parentGeometry.topLeft().x(), parentGeometry.topLeft().y() + titleBarHeight, - size().width(), parentWidget()->height() - titleBarHeight); + setGeometry(parentGeometry.topLeft().x(), parentGeometry.topLeft().y() + topMargin, + size().width(), parentWidget()->height() - topMargin); QWidget::showEvent(event); } From c27bee2c0690d96a50de3de2d8d02a990fe706a7 Mon Sep 17 00:00:00 2001 From: Ryan Huffman Date: Wed, 3 Sep 2014 06:47:05 -0700 Subject: [PATCH 19/31] Move wm_close handling to a shared library --- assignment-client/src/AssignmentClient.cpp | 20 +++---------- assignment-client/src/AssignmentClient.h | 5 ++-- domain-server/src/DomainServer.cpp | 4 ++- domain-server/src/DomainServer.h | 3 ++ .../shared/src/ShutdownEventListener.cpp | 27 +++++++++++++++++ libraries/shared/src/ShutdownEventListener.h | 29 +++++++++++++++++++ 6 files changed, 69 insertions(+), 19 deletions(-) create mode 100644 libraries/shared/src/ShutdownEventListener.cpp create mode 100644 libraries/shared/src/ShutdownEventListener.h diff --git a/assignment-client/src/AssignmentClient.cpp b/assignment-client/src/AssignmentClient.cpp index 4d2538eb25..71fbef4cf8 100644 --- a/assignment-client/src/AssignmentClient.cpp +++ b/assignment-client/src/AssignmentClient.cpp @@ -36,7 +36,8 @@ int hifiSockAddrMeta = qRegisterMetaType("HifiSockAddr"); AssignmentClient::AssignmentClient(int &argc, char **argv) : QCoreApplication(argc, argv), - _assignmentServerHostname(DEFAULT_ASSIGNMENT_SERVER_HOSTNAME) + _assignmentServerHostname(DEFAULT_ASSIGNMENT_SERVER_HOSTNAME), + _shutdownEventListener(this) { #ifdef Q_OS_WIN @@ -54,7 +55,8 @@ AssignmentClient::AssignmentClient(int &argc, char **argv) : setApplicationName("assignment-client"); QSettings::setDefaultFormat(QSettings::IniFormat); - installNativeEventFilter(this); + installNativeEventFilter(&_shutdownEventListener); + connect(&_shutdownEventListener, SIGNAL(receivedCloseEvent()), SLOT(quit())); // set the logging target to the the CHILD_TARGET_NAME Logging::setTargetName(ASSIGNMENT_CLIENT_TARGET_NAME); @@ -121,20 +123,6 @@ AssignmentClient::AssignmentClient(int &argc, char **argv) : NetworkAccessManager::getInstance(); } -bool AssignmentClient::nativeEventFilter(const QByteArray &eventType, void* msg, long* result) { -#ifdef Q_OS_WIN - if (eventType == "windows_generic_MSG") { - MSG* message = (MSG*)msg; - if (message->message == WM_CLOSE) { - qDebug() << "Received WM_CLOSE message, closing"; - quit(); - return false; - } - } -#endif - return true; -} - void AssignmentClient::sendAssignmentRequest() { if (!_currentAssignment) { NodeList::getInstance()->sendAssignment(_requestAssignment); diff --git a/assignment-client/src/AssignmentClient.h b/assignment-client/src/AssignmentClient.h index 5c8d1945ee..24a4c97f73 100644 --- a/assignment-client/src/AssignmentClient.h +++ b/assignment-client/src/AssignmentClient.h @@ -15,14 +15,14 @@ #include #include +#include "ShutdownEventListener.h" #include "ThreadedAssignment.h" -class AssignmentClient : public QCoreApplication, public QAbstractNativeEventFilter { +class AssignmentClient : public QCoreApplication { Q_OBJECT public: AssignmentClient(int &argc, char **argv); static const SharedAssignmentPointer& getCurrentAssignment() { return _currentAssignment; } - virtual bool nativeEventFilter(const QByteArray& eventType, void* message, long* result); private slots: void sendAssignmentRequest(); @@ -33,6 +33,7 @@ private slots: private: Assignment _requestAssignment; static SharedAssignmentPointer _currentAssignment; + ShutdownEventListener _shutdownEventListener; QString _assignmentServerHostname; }; diff --git a/domain-server/src/DomainServer.cpp b/domain-server/src/DomainServer.cpp index a4a50bbe2c..f96444d8fb 100644 --- a/domain-server/src/DomainServer.cpp +++ b/domain-server/src/DomainServer.cpp @@ -31,6 +31,7 @@ DomainServer::DomainServer(int argc, char* argv[]) : QCoreApplication(argc, argv), + _shutdownEventListener(this), _httpManager(DOMAIN_SERVER_HTTP_PORT, QString("%1/resources/web/").arg(QCoreApplication::applicationDirPath()), this), _httpsManager(NULL), _allAssignments(), @@ -62,7 +63,8 @@ DomainServer::DomainServer(int argc, char* argv[]) : setApplicationName("domain-server"); QSettings::setDefaultFormat(QSettings::IniFormat); - installNativeEventFilter(this); + installNativeEventFilter(&_shutdownEventListener); + connect(&_shutdownEventListener, SIGNAL(receivedCloseEvent()), SLOT(quit())); qRegisterMetaType("DomainServerWebSessionData"); qRegisterMetaTypeStreamOperators("DomainServerWebSessionData"); diff --git a/domain-server/src/DomainServer.h b/domain-server/src/DomainServer.h index 12a4970612..524f237c9d 100644 --- a/domain-server/src/DomainServer.h +++ b/domain-server/src/DomainServer.h @@ -27,6 +27,7 @@ #include "DomainServerSettingsManager.h" #include "DomainServerWebSessionData.h" +#include "ShutdownEventListener.h" #include "WalletTransaction.h" #include "PendingAssignedNodeData.h" @@ -100,6 +101,8 @@ private: QJsonObject jsonForSocket(const HifiSockAddr& socket); QJsonObject jsonObjectForNode(const SharedNodePointer& node); + + ShutdownEventListener _shutdownEventListener; HTTPManager _httpManager; HTTPSManager* _httpsManager; diff --git a/libraries/shared/src/ShutdownEventListener.cpp b/libraries/shared/src/ShutdownEventListener.cpp new file mode 100644 index 0000000000..e800c61110 --- /dev/null +++ b/libraries/shared/src/ShutdownEventListener.cpp @@ -0,0 +1,27 @@ +// +// ShutdownEventListener.cpp +// libraries/shared/src +// +// Created by Ryan Huffman on 09/03/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 "ShutdownEventListener.h" + +ShutdownEventListener::ShutdownEventListener(QObject* parent) : QObject(parent) { +} + +bool ShutdownEventListener::nativeEventFilter(const QByteArray &eventType, void* msg, long* result) { +#ifdef Q_OS_WIN + if (eventType == "windows_generic_MSG") { + MSG* message = (MSG*)msg; + if (message->message == WM_CLOSE) { + emit receivedCloseEvent(); + } + } +#endif + return true; +} diff --git a/libraries/shared/src/ShutdownEventListener.h b/libraries/shared/src/ShutdownEventListener.h new file mode 100644 index 0000000000..e39770c13d --- /dev/null +++ b/libraries/shared/src/ShutdownEventListener.h @@ -0,0 +1,29 @@ +// +// ShutdownEventListener.h +// libraries/shared/src +// +// Created by Ryan Huffman on 09/03/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_ShutdownEventListener_h +#define hifi_ShutdownEventListener_h + +#include +#include + +class ShutdownEventListener : public QObject, public QAbstractNativeEventFilter { + Q_OBJECT +public: + ShutdownEventListener(QObject* parent = NULL); + + virtual bool nativeEventFilter(const QByteArray& eventType, void* message, long* result); + +signals: + void receivedCloseEvent(); +}; + +#endif // hifi_ShutdownEventListener_h From 76bede04aa941f4c8165c15882662cef720cb673 Mon Sep 17 00:00:00 2001 From: Ryan Huffman Date: Wed, 3 Sep 2014 07:06:08 -0700 Subject: [PATCH 20/31] Move stdout/err disabling to a library class --- assignment-client/src/AssignmentClient.cpp | 12 ++--------- domain-server/src/DomainServer.cpp | 11 ++-------- libraries/shared/src/LogUtils.cpp | 24 ++++++++++++++++++++++ libraries/shared/src/LogUtils.h | 20 ++++++++++++++++++ 4 files changed, 48 insertions(+), 19 deletions(-) create mode 100644 libraries/shared/src/LogUtils.cpp create mode 100644 libraries/shared/src/LogUtils.h diff --git a/assignment-client/src/AssignmentClient.cpp b/assignment-client/src/AssignmentClient.cpp index 71fbef4cf8..3e3c7c0609 100644 --- a/assignment-client/src/AssignmentClient.cpp +++ b/assignment-client/src/AssignmentClient.cpp @@ -17,6 +17,7 @@ #include #include #include +#include #include #include #include @@ -39,16 +40,7 @@ AssignmentClient::AssignmentClient(int &argc, char **argv) : _assignmentServerHostname(DEFAULT_ASSIGNMENT_SERVER_HOSTNAME), _shutdownEventListener(this) { - -#ifdef Q_OS_WIN - // Windows applications buffer stdout/err hard when not run from a terminal, - // making assignment clients run from the Stack Manager application not flush - // log messages. - // This will disable the buffering. If this becomes a performance issue, - // an alternative is to call fflush(...) periodically. - setbuf(stdout, NULL); - setbuf(stderr, NULL); -#endif + LogUtils::init(); setOrganizationName("High Fidelity"); setOrganizationDomain("highfidelity.io"); diff --git a/domain-server/src/DomainServer.cpp b/domain-server/src/DomainServer.cpp index f96444d8fb..022fb1f92d 100644 --- a/domain-server/src/DomainServer.cpp +++ b/domain-server/src/DomainServer.cpp @@ -21,6 +21,7 @@ #include #include #include +#include #include #include #include @@ -48,15 +49,7 @@ DomainServer::DomainServer(int argc, char* argv[]) : _settingsManager() { -#ifdef Q_OS_WIN - // Windows applications buffer stdout/err hard when not run from a terminal, - // making a domain server run from the Stack Manager application not flush - // log messages. - // This will disable the buffering. If this becomes a performance issue, - // an alternative is to call fflush(...) periodically. - setbuf(stdout, NULL); - setbuf(stderr, NULL); -#endif + LogUtils::init(); setOrganizationName("High Fidelity"); setOrganizationDomain("highfidelity.io"); diff --git a/libraries/shared/src/LogUtils.cpp b/libraries/shared/src/LogUtils.cpp new file mode 100644 index 0000000000..c38f5c8574 --- /dev/null +++ b/libraries/shared/src/LogUtils.cpp @@ -0,0 +1,24 @@ +// +// LogUtils.cpp +// libraries/shared/src +// +// Created by Ryan Huffman on 09/03/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 "LogUtils.h" + +void LogUtils::init() { +#ifdef Q_OS_WIN + // Windows applications buffer stdout/err hard when not run from a terminal, + // making assignment clients run from the Stack Manager application not flush + // log messages. + // This will disable the buffering. If this becomes a performance issue, + // an alternative is to call fflush(...) periodically. + setbuf(stdout, NULL); + setbuf(stderr, NULL); +#endif +} diff --git a/libraries/shared/src/LogUtils.h b/libraries/shared/src/LogUtils.h new file mode 100644 index 0000000000..955c33d338 --- /dev/null +++ b/libraries/shared/src/LogUtils.h @@ -0,0 +1,20 @@ +// +// LogUtils.h +// libraries/shared/src +// +// Created by Ryan Huffman on 09/03/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_LogUtils_h +#define hifi_LogUtils_h + +class LogUtils { +public: + static void init(); +}; + +#endif // hifi_LogUtils_h From f3efbb35f4ea6d7e67f48631bdcd72f268706b27 Mon Sep 17 00:00:00 2001 From: Ryan Huffman Date: Wed, 3 Sep 2014 07:08:51 -0700 Subject: [PATCH 21/31] Remove nativeEventFilter from DomainServer --- domain-server/src/DomainServer.cpp | 14 -------------- domain-server/src/DomainServer.h | 4 +--- 2 files changed, 1 insertion(+), 17 deletions(-) diff --git a/domain-server/src/DomainServer.cpp b/domain-server/src/DomainServer.cpp index 022fb1f92d..c9864ef156 100644 --- a/domain-server/src/DomainServer.cpp +++ b/domain-server/src/DomainServer.cpp @@ -75,20 +75,6 @@ DomainServer::DomainServer(int argc, char* argv[]) : } } -bool DomainServer::nativeEventFilter(const QByteArray &eventType, void* msg, long* result) { -#ifdef Q_OS_WIN - if (eventType == "windows_generic_MSG") { - MSG* message = (MSG*)msg; - if (message->message == WM_CLOSE) { - qDebug() << "Received WM_CLOSE message, closing"; - quit(); - return false; - } - } -#endif - return true; -} - bool DomainServer::optionallyReadX509KeyAndCertificate() { const QString X509_CERTIFICATE_OPTION = "cert"; const QString X509_PRIVATE_KEY_OPTION = "key"; diff --git a/domain-server/src/DomainServer.h b/domain-server/src/DomainServer.h index 524f237c9d..10633cc71a 100644 --- a/domain-server/src/DomainServer.h +++ b/domain-server/src/DomainServer.h @@ -35,15 +35,13 @@ typedef QSharedPointer SharedAssignmentPointer; typedef QMultiHash TransactionHash; -class DomainServer : public QCoreApplication, public HTTPSRequestHandler, public QAbstractNativeEventFilter { +class DomainServer : public QCoreApplication, public HTTPSRequestHandler { Q_OBJECT public: DomainServer(int argc, char* argv[]); bool handleHTTPRequest(HTTPConnection* connection, const QUrl& url); bool handleHTTPSRequest(HTTPSConnection* connection, const QUrl& url); - - bool nativeEventFilter(const QByteArray &eventType, void* msg, long* result); void exit(int retCode = 0); From 1ee23a16611224fab556630ac9b97dc933288725 Mon Sep 17 00:00:00 2001 From: Ryan Huffman Date: Wed, 3 Sep 2014 08:04:39 -0700 Subject: [PATCH 22/31] Add Windows.h include to ShutdownEventListener --- assignment-client/src/AssignmentClient.h | 1 - libraries/shared/src/ShutdownEventListener.cpp | 4 ++++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/assignment-client/src/AssignmentClient.h b/assignment-client/src/AssignmentClient.h index 24a4c97f73..7628aa0a3b 100644 --- a/assignment-client/src/AssignmentClient.h +++ b/assignment-client/src/AssignmentClient.h @@ -13,7 +13,6 @@ #define hifi_AssignmentClient_h #include -#include #include "ShutdownEventListener.h" #include "ThreadedAssignment.h" diff --git a/libraries/shared/src/ShutdownEventListener.cpp b/libraries/shared/src/ShutdownEventListener.cpp index e800c61110..961d18e793 100644 --- a/libraries/shared/src/ShutdownEventListener.cpp +++ b/libraries/shared/src/ShutdownEventListener.cpp @@ -11,6 +11,10 @@ #include "ShutdownEventListener.h" +#ifdef Q_OS_WIN +#include +#endif + ShutdownEventListener::ShutdownEventListener(QObject* parent) : QObject(parent) { } From 5937830443d628457b3b1761b930cdf3e81c1c1f Mon Sep 17 00:00:00 2001 From: Ryan Huffman Date: Wed, 3 Sep 2014 08:27:18 -0700 Subject: [PATCH 23/31] Update getWindowTitleBarHeight signature --- libraries/shared/src/UIUtil.cpp | 2 +- libraries/shared/src/UIUtil.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/libraries/shared/src/UIUtil.cpp b/libraries/shared/src/UIUtil.cpp index 82c41e42c8..db9dde2f00 100644 --- a/libraries/shared/src/UIUtil.cpp +++ b/libraries/shared/src/UIUtil.cpp @@ -14,7 +14,7 @@ #include "UIUtil.h" -int UIUtil::getWindowTitleBarHeight(QWidget *window) { +int UIUtil::getWindowTitleBarHeight(const QWidget* window) { QStyleOptionTitleBar options; options.titleBarState = 1; options.titleBarFlags = Qt::Window; diff --git a/libraries/shared/src/UIUtil.h b/libraries/shared/src/UIUtil.h index 3eeae9efbd..304e8bfce9 100644 --- a/libraries/shared/src/UIUtil.h +++ b/libraries/shared/src/UIUtil.h @@ -17,7 +17,7 @@ class UIUtil { public: - static int getWindowTitleBarHeight(QWidget *window); + static int getWindowTitleBarHeight(const QWidget* window); }; From d4ebe577df40324cc9a0275810ef484ae54b396c Mon Sep 17 00:00:00 2001 From: Ryan Huffman Date: Wed, 3 Sep 2014 08:28:25 -0700 Subject: [PATCH 24/31] Remove commented out icons --- interface/src/ui/RunningScriptsWidget.cpp | 4 ---- 1 file changed, 4 deletions(-) diff --git a/interface/src/ui/RunningScriptsWidget.cpp b/interface/src/ui/RunningScriptsWidget.cpp index 52735f3a2b..7a46873129 100644 --- a/interface/src/ui/RunningScriptsWidget.cpp +++ b/interface/src/ui/RunningScriptsWidget.cpp @@ -35,10 +35,6 @@ RunningScriptsWidget::RunningScriptsWidget(QWidget* parent) : setAttribute(Qt::WA_DeleteOnClose, false); - //ui->reloadAllButton->setIcon(QIcon(Application::resourcesPath() + "images/reload.svg")); - //ui->stopAllButton->setIcon(QIcon(Application::resourcesPath() + "images/stop.svg")); - //ui->loadScriptButton->setIcon(QIcon(Application::resourcesPath() + "images/plus.svg")); - ui->filterLineEdit->installEventFilter(this); connect(&_proxyModel, &QSortFilterProxyModel::modelReset, From d89b29581b668dfd241316de1a6e95bc04a52bb3 Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Wed, 3 Sep 2014 17:14:34 -0700 Subject: [PATCH 25/31] remove assert in favor of warning --- libraries/entities/src/UpdateEntityOperator.cpp | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/libraries/entities/src/UpdateEntityOperator.cpp b/libraries/entities/src/UpdateEntityOperator.cpp index 157e68aa70..37dfe73add 100644 --- a/libraries/entities/src/UpdateEntityOperator.cpp +++ b/libraries/entities/src/UpdateEntityOperator.cpp @@ -175,7 +175,15 @@ bool UpdateEntityOperator::preRecursion(OctreeElement* element) { // if we are the existing containing element, then we can just do the update of the entity properties if (entityTreeElement == _containingElement) { - assert(!_removeOld); // We shouldn't be in a remove old case and also be the new best fit + + // TODO: We shouldn't be in a remove old case and also be the new best fit. This indicates that + // we have some kind of a logic error in this operator. But, it can handle it properly by setting + // the new properties for the entity and moving on. Still going to output a warning that if we + // see consistently we will want to address this. + if (_removeOld) { + qDebug() << "UNEXPECTED - UpdateEntityOperator - " + "we thought we needed to removeOld, but the old entity is our best fit."; + } // set the entity properties and mark our element as changed. _existingEntity->setProperties(_properties); From e680260c897281ea6fab61035219ee47c8797fa1 Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Wed, 3 Sep 2014 17:17:36 -0700 Subject: [PATCH 26/31] remove assert in favor of warning --- libraries/entities/src/UpdateEntityOperator.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/libraries/entities/src/UpdateEntityOperator.cpp b/libraries/entities/src/UpdateEntityOperator.cpp index 37dfe73add..65a86a80ca 100644 --- a/libraries/entities/src/UpdateEntityOperator.cpp +++ b/libraries/entities/src/UpdateEntityOperator.cpp @@ -183,6 +183,7 @@ bool UpdateEntityOperator::preRecursion(OctreeElement* element) { if (_removeOld) { qDebug() << "UNEXPECTED - UpdateEntityOperator - " "we thought we needed to removeOld, but the old entity is our best fit."; + _removeOld = false; } // set the entity properties and mark our element as changed. From 5b8be780a728a1bdf54091bc9d01283d58781980 Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Wed, 3 Sep 2014 18:03:00 -0700 Subject: [PATCH 27/31] add color to sphere property editor --- examples/editModels.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/editModels.js b/examples/editModels.js index 8d0cf7e71c..fc9c8617ef 100644 --- a/examples/editModels.js +++ b/examples/editModels.js @@ -2828,7 +2828,7 @@ function handeMenuEvent(menuItem) { array.push({ label: "Lifetime:", value: properties.lifetime.toFixed(decimals) }); - if (properties.type == "Box") { + if (properties.type == "Box" || properties.type == "Sphere") { array.push({ label: "Red:", value: properties.color.red }); array.push({ label: "Green:", value: properties.color.green }); array.push({ label: "Blue:", value: properties.color.blue }); From 3e1401014d3cc85a20eef15262ffb91eb3b574d5 Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Wed, 3 Sep 2014 18:32:44 -0700 Subject: [PATCH 28/31] more model naming cleanup and fixing example scripts --- examples/animatedModelExample.js | 16 ++++--- examples/inspect.js | 4 +- examples/rayPickExample.js | 10 ++-- .../entities/src/EntityScriptingInterface.cpp | 47 +++++++++---------- 4 files changed, 39 insertions(+), 38 deletions(-) diff --git a/examples/animatedModelExample.js b/examples/animatedModelExample.js index 9a4bdb3ea7..3fffdc88d2 100644 --- a/examples/animatedModelExample.js +++ b/examples/animatedModelExample.js @@ -21,6 +21,7 @@ var roll = 0.0; var rotation = Quat.fromPitchYawRollDegrees(pitch, yaw, roll) var originalProperties = { + type: "Model", position: { x: MyAvatar.position.x, y: MyAvatar.position.y, z: MyAvatar.position.z }, @@ -37,8 +38,8 @@ var originalProperties = { animationIsPlaying: true, }; -var modelID = Models.addModel(originalProperties); -print("Models.addModel()... modelID.creatorTokenID = " + modelID.creatorTokenID); +var modelID = Entities.addEntity(originalProperties); +print("Entities.addEntity()... modelID.creatorTokenID = " + modelID.creatorTokenID); var isPlaying = true; var playPauseEveryWhile = 360; @@ -48,6 +49,7 @@ var resetFrameEveryWhile = 600; function moveModel(deltaTime) { var somethingChanged = false; + print("count= " + count); if (count % playPauseEveryWhile == 0) { isPlaying = !isPlaying; print("isPlaying=" + isPlaying); @@ -56,11 +58,11 @@ function moveModel(deltaTime) { if (count % adjustFPSEveryWhile == 0) { if (animationFPS == 30) { - animationFPS = 30; - } else if (animationFPS == 10) { animationFPS = 10; - } else if (animationFPS == 60) { + } else if (animationFPS == 10) { animationFPS = 60; + } else if (animationFPS == 60) { + animationFPS = 30; } print("animationFPS=" + animationFPS); isPlaying = true; @@ -78,7 +80,7 @@ function moveModel(deltaTime) { // delete it... if (count == moveUntil) { print("calling Models.deleteModel()"); - Models.deleteModel(modelID); + Entities.deleteEntity(modelID); } // stop it... @@ -107,7 +109,7 @@ function moveModel(deltaTime) { resetFrame = false; } - Models.editModel(modelID, newProperties); + Entities.editEntity(modelID, newProperties); } } diff --git a/examples/inspect.js b/examples/inspect.js index a4ff405c3f..b9ed5a3f00 100644 --- a/examples/inspect.js +++ b/examples/inspect.js @@ -205,7 +205,7 @@ function mousePressEvent(event) { // Compute trajectories related values var pickRay = Camera.computePickRay(mouseLastX, mouseLastY); var voxelIntersection = Voxels.findRayIntersection(pickRay); - var modelIntersection = Models.findRayIntersection(pickRay); + var modelIntersection = Entities.findRayIntersection(pickRay); position = Camera.getPosition(); @@ -218,7 +218,7 @@ function mousePressEvent(event) { if (modelIntersection.intersects && modelIntersection.accurate) { distance = modelIntersection.distance; - center = modelIntersection.modelProperties.position; + center = modelIntersection.properties.position; string = "Inspecting model"; } diff --git a/examples/rayPickExample.js b/examples/rayPickExample.js index 336fbe2162..c3b6581007 100644 --- a/examples/rayPickExample.js +++ b/examples/rayPickExample.js @@ -42,16 +42,16 @@ function mouseMoveEvent(event) { print("voxelAt.red/green/blue=" + voxelAt.red + ", " + voxelAt.green + ", " + voxelAt.blue); } - intersection = Models.findRayIntersection(pickRay); + intersection = Entities.findRayIntersection(pickRay); if (!intersection.accurate) { - print(">>> NOTE: intersection not accurate. will try calling Models.findRayIntersectionBlocking()"); - intersection = Models.findRayIntersectionBlocking(pickRay); + print(">>> NOTE: intersection not accurate. will try calling Entities.findRayIntersectionBlocking()"); + intersection = Entities.findRayIntersectionBlocking(pickRay); print(">>> AFTER BLOCKING CALL intersection.accurate=" + intersection.accurate); } if (intersection.intersects) { - print("intersection modelID.id=" + intersection.modelID.id); - print("intersection modelProperties.modelURL=" + intersection.modelProperties.modelURL); + print("intersection entityID.id=" + intersection.entityID.id); + print("intersection properties.modelURL=" + intersection.properties.modelURL); print("intersection face=" + intersection.face); print("intersection distance=" + intersection.distance); print("intersection intersection.x/y/z=" + intersection.intersection.x + ", " diff --git a/libraries/entities/src/EntityScriptingInterface.cpp b/libraries/entities/src/EntityScriptingInterface.cpp index a7ed908a63..971d7066eb 100644 --- a/libraries/entities/src/EntityScriptingInterface.cpp +++ b/libraries/entities/src/EntityScriptingInterface.cpp @@ -1,6 +1,6 @@ // // EntityScriptingInterface.cpp -// libraries/models/src +// libraries/entities/src // // Created by Brad Hefta-Gaub on 12/6/13. // Copyright 2013 High Fidelity, Inc. @@ -19,7 +19,6 @@ EntityScriptingInterface::EntityScriptingInterface() : { } - void EntityScriptingInterface::queueEntityMessage(PacketType packetType, EntityItemID entityID, const EntityItemProperties& properties) { getEntityPacketSender()->queueEditEntityMessage(packetType, entityID, properties); @@ -35,7 +34,7 @@ EntityItemID EntityScriptingInterface::addEntity(const EntityItemProperties& pro // queue the packet queueEntityMessage(PacketTypeEntityAddOrEdit, id, properties); - // If we have a local model tree set, then also update it. + // If we have a local entity tree set, then also update it. if (_entityTree) { _entityTree->lockForWrite(); _entityTree->addEntity(id, properties); @@ -93,20 +92,20 @@ EntityItemProperties EntityScriptingInterface::getEntityProperties(EntityItemID EntityItemID EntityScriptingInterface::editEntity(EntityItemID entityID, const EntityItemProperties& properties) { EntityItemID actualID = entityID; - // if the model is unknown, attempt to look it up + // if the entity is unknown, attempt to look it up if (!entityID.isKnownID) { actualID = EntityItemID::getIDfromCreatorTokenID(entityID.creatorTokenID); } - // if at this point, we know the id, send the update to the model server + // if at this point, we know the id, send the update to the entity server if (actualID.id != UNKNOWN_ENTITY_ID) { entityID.id = actualID.id; entityID.isKnownID = true; queueEntityMessage(PacketTypeEntityAddOrEdit, entityID, properties); } - // If we have a local model tree set, then also update it. We can do this even if we don't know - // the actual id, because we can edit out local models just with creatorTokenID + // If we have a local entity tree set, then also update it. We can do this even if we don't know + // the actual id, because we can edit out local entities just with creatorTokenID if (_entityTree) { _entityTree->lockForWrite(); _entityTree->updateEntity(entityID, properties); @@ -119,19 +118,19 @@ void EntityScriptingInterface::deleteEntity(EntityItemID entityID) { EntityItemID actualID = entityID; - // if the model is unknown, attempt to look it up + // if the entity is unknown, attempt to look it up if (!entityID.isKnownID) { actualID = EntityItemID::getIDfromCreatorTokenID(entityID.creatorTokenID); } - // if at this point, we know the id, send the update to the model server + // if at this point, we know the id, send the update to the entity server if (actualID.id != UNKNOWN_ENTITY_ID) { entityID.id = actualID.id; entityID.isKnownID = true; getEntityPacketSender()->queueEraseEntityMessage(entityID); } - // If we have a local model tree set, then also update it. + // If we have a local entity tree set, then also update it. if (_entityTree) { _entityTree->lockForWrite(); _entityTree->deleteEntity(entityID); @@ -167,12 +166,12 @@ QVector EntityScriptingInterface::findEntities(const glm::vec3& ce QVector result; if (_entityTree) { _entityTree->lockForRead(); - QVector models; - _entityTree->findEntities(center/(float)TREE_SCALE, radius/(float)TREE_SCALE, models); + QVector entities; + _entityTree->findEntities(center/(float)TREE_SCALE, radius/(float)TREE_SCALE, entities); _entityTree->unlock(); - foreach (const EntityItem* model, models) { - EntityItemID thisEntityItemID(model->getID(), UNKNOWN_ENTITY_TOKEN, true); + foreach (const EntityItem* entity, entities) { + EntityItemID thisEntityItemID(entity->getID(), UNKNOWN_ENTITY_TOKEN, true); result << thisEntityItemID; } } @@ -219,11 +218,11 @@ QScriptValue RayToEntityIntersectionResultToScriptValue(QScriptEngine* engine, c QScriptValue obj = engine->newObject(); obj.setProperty("intersects", value.intersects); obj.setProperty("accurate", value.accurate); - QScriptValue modelItemValue = EntityItemIDtoScriptValue(engine, value.entityID); - obj.setProperty("entityID", modelItemValue); + QScriptValue entityItemValue = EntityItemIDtoScriptValue(engine, value.entityID); + obj.setProperty("entityID", entityItemValue); - QScriptValue modelPropertiesValue = EntityItemPropertiesToScriptValue(engine, value.properties); - obj.setProperty("properties", modelPropertiesValue); + QScriptValue propertiesValue = EntityItemPropertiesToScriptValue(engine, value.properties); + obj.setProperty("properties", propertiesValue); obj.setProperty("distance", value.distance); @@ -262,13 +261,13 @@ QScriptValue RayToEntityIntersectionResultToScriptValue(QScriptEngine* engine, c void RayToEntityIntersectionResultFromScriptValue(const QScriptValue& object, RayToEntityIntersectionResult& value) { value.intersects = object.property("intersects").toVariant().toBool(); value.accurate = object.property("accurate").toVariant().toBool(); - QScriptValue modelIDValue = object.property("entityID"); - if (modelIDValue.isValid()) { - EntityItemIDfromScriptValue(modelIDValue, value.entityID); + QScriptValue entityIDValue = object.property("entityID"); + if (entityIDValue.isValid()) { + EntityItemIDfromScriptValue(entityIDValue, value.entityID); } - QScriptValue modelPropertiesValue = object.property("properties"); - if (modelPropertiesValue.isValid()) { - EntityItemPropertiesFromScriptValue(modelPropertiesValue, value.properties); + QScriptValue entityPropertiesValue = object.property("properties"); + if (entityPropertiesValue.isValid()) { + EntityItemPropertiesFromScriptValue(entityPropertiesValue, value.properties); } value.distance = object.property("distance").toVariant().toFloat(); From 31716697c0bc60497d3e24ad98d2592150d79bf8 Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Wed, 3 Sep 2014 18:35:09 -0700 Subject: [PATCH 29/31] new example script --- examples/twoFallingEntities.js | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 examples/twoFallingEntities.js diff --git a/examples/twoFallingEntities.js b/examples/twoFallingEntities.js new file mode 100644 index 0000000000..e7a8ff69e4 --- /dev/null +++ b/examples/twoFallingEntities.js @@ -0,0 +1,25 @@ +// +// Testing.js +// +// Creates a red 0.2 meter diameter ball right in front of your avatar that lives for 60 seconds +// + +var radius = 0.1; +var position = Vec3.sum(MyAvatar.position, Quat.getFront(MyAvatar.orientation)); +var properties = { + type: "Sphere", + position: position, + velocity: { x: 0, y: 0, z: 0}, + gravity: { x: 0, y: -0.05, z: 0}, + radius: radius, + damping: 0.999, + color: { red: 200, green: 0, blue: 0 }, + lifetime: 60 + }; + +var newEntity = Entities.addEntity(properties); +position.x -= radius * 1.0; +properties.position = position; +var newEntityTwo = Entities.addEntity(properties); + +Script.stop(); // no need to run anymore \ No newline at end of file From be7a03b97e1ccb5947c4d08c3227272dec1181b4 Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Wed, 3 Sep 2014 19:41:53 -0700 Subject: [PATCH 30/31] flock of butterflies as entities --- examples/entitiesButterflyFlock.js | 247 +++++++++++++++++++++++++++++ 1 file changed, 247 insertions(+) create mode 100644 examples/entitiesButterflyFlock.js diff --git a/examples/entitiesButterflyFlock.js b/examples/entitiesButterflyFlock.js new file mode 100644 index 0000000000..c3382e43e1 --- /dev/null +++ b/examples/entitiesButterflyFlock.js @@ -0,0 +1,247 @@ +// +// butterflyFlockTest1.js +// +// +// Created by Adrian McCarlie on August 2, 2014 +// Copyright 2014 High Fidelity, Inc. +// +// This sample script creates a swarm of butterfly Entities that fly around the avatar. +// +// Distributed under the Apache License, Version 2.0. +// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html +// + + +function getRandomFloat(min, max) { + return Math.random() * (max - min) + min; +} + +// Multiply vector by scalar + +function vScalarMult(v, s) { + var rval = { x: v.x * s, y: v.y * s, z: v.z * s }; + return rval; +} + +function printVector(v) { + print(v.x + ", " + v.y + ", " + v.z + "\n"); +} +// Create a random vector with individual lengths between a,b +function randVector(a, b) { + var rval = { x: a + Math.random() * (b - a), y: a + Math.random() * (b - a), z: a + Math.random() * (b - a) }; + return rval; +} + +// Returns a vector which is fraction of the way between a and b +function vInterpolate(a, b, fraction) { + var rval = { x: a.x + (b.x - a.x) * fraction, y: a.y + (b.y - a.y) * fraction, z: a.z + (b.z - a.z) * fraction }; + return rval; +} + +var startTimeInSeconds = new Date().getTime() / 1000; + +var lifeTime = 60; // lifetime of the butterflies in seconds! +var range = 1.0; // Over what distance in meters do you want the flock to fly around +var frame = 0; + +var CHANCE_OF_MOVING = 0.9; +var BUTTERFLY_GRAVITY = 0;//-0.06; +var BUTTERFLY_FLAP_SPEED = 1.0; +var BUTTERFLY_VELOCITY = 0.55; +var myPosition = MyAvatar.position; + +var pitch = 0.0;//experimental +var yaw = 0.0;//experimental +var roll = 0.0; //experimental +var rotation = Quat.fromPitchYawRollDegrees(pitch, yaw, roll);//experimental + +// This is our butterfly object +function defineButterfly (entityID, targetPosition ) { + this.entityID = entityID; + this.previousFlapOffset = 0; + this.targetPosition = targetPosition; + this.moving = false; +} + +// Array of butterflies +var butterflies = []; +var numButterflies = 20; +function addButterfly( ){ + // Decide the size of butterfly + var color = { red: 100, green: 100, blue: 100 }; + var size = 0; + + var which = Math.random(); + if (which < 0.2) { + size = 0.08; + } else if (which < 0.4) { + size = 0.09; + } else if (which < 0.6) { + size = 0.8; + } else if (which < 0.8) { + size = 0.8; + } else { + size = 0.8; + } + + myPosition = MyAvatar.position; + // if ( frame < numButterflies){ + // myPosition = {x: myPosition.x, y: myPosition.y, z: myPosition.z }; + // } + + var properties = { + type: "Model", + lifetime: lifeTime, + position: Vec3.sum(randVector(-range, range), myPosition), + velocity: { x: 0, y: 0.0, z: 0 }, + gravity: { x: 0, y: 1.0, z: 0 }, + damping: 0.1, + radius : size, + color: color, + rotation: rotation, + //animationURL: "http://business.ozblog.me/objects/butterfly/newButterfly6.fbx", + //animationIsPlaying: true, + modelURL: "http://business.ozblog.me/objects/butterfly/newButterfly6.fbx" + + }; + properties.position.z = properties.position.z+1; + butterflies.push(new defineButterfly(Entities.addEntity(properties), properties.position)); + +} + + + +// Generate the butterflies +for (var i = 0; i < numButterflies; i++) { + addButterfly(); + +} + +// Main update function +function updateButterflies(deltaTime) { + + // Check to see if we've been running long enough that our butterflies are dead + var nowTimeInSeconds = new Date().getTime() / 1000; + if ((nowTimeInSeconds - startTimeInSeconds) >= lifeTime) { + + // print("our butterflies are dying, stop our script"); + Script.stop(); + return; + } + + frame++; + // Only update every third frame + if ((frame % 3) == 0) { + myPosition = MyAvatar.position; + + // Update all the butterflies + for (var i = 0; i < numButterflies; i++) { + entityID = butterflies[i].entityID; + var properties = Entities.getEntityProperties(entityID); + + if (properties.position.y > myPosition.y + getRandomFloat(0.0,0.3)){ //0.3 //ceiling + properties.gravity.y = - 3.0; + properties.damping.y = 1.0; + properties.velocity.y = 0; + properties.velocity.x = properties.velocity.x; + properties.velocity.z = properties.velocity.z; + if (properties.velocity.x < 0.5){ + butterflies[i].moving = false; + } + if (properties.velocity.z < 0.5){ + butterflies[i].moving = false; + } + } + + if (properties.velocity.y <= -0.2) { + properties.velocity.y = 0.22; + properties.velocity.x = properties.velocity.x; + properties.velocity.z = properties.velocity.z; + } + + if (properties.position.y < myPosition.y - getRandomFloat(0.0,0.3)) { //-0.3 // floor + properties.velocity.y = 0.9; + properties.gravity.y = - 4.0; + properties.velocity.x = properties.velocity.x; + properties.velocity.z = properties.velocity.z; + if (properties.velocity.x < 0.5){ + butterflies[i].moving = false; + } + if (properties.velocity.z < 0.5){ + butterflies[i].moving = false; + } + } + + + // Begin movement by getting a target + if (butterflies[i].moving == false) { + if (Math.random() < CHANCE_OF_MOVING) { + var targetPosition = Vec3.sum(randVector(-range, range), myPosition); + + if (targetPosition.x < 0) { + targetPosition.x = 0; + } + if (targetPosition.y < 0) { + targetPosition.y = 0; + } + if (targetPosition.z < 0) { + targetPosition.z = 0; + } + if (targetPosition.x > TREE_SCALE) { + targetPosition.x = TREE_SCALE; + } + if (targetPosition.y > TREE_SCALE) { + targetPosition.y = TREE_SCALE; + } + if (targetPosition.z > TREE_SCALE) { + targetPosition.z = TREE_SCALE; + } + + butterflies[i].targetPosition = targetPosition; + + butterflies[i].moving = true; + } + } + + + // If we are moving, move towards the target + if (butterflies[i].moving) { + + var holding = properties.velocity.y; + + var desiredVelocity = Vec3.subtract(butterflies[i].targetPosition, properties.position); + desiredVelocity = vScalarMult(Vec3.normalize(desiredVelocity), BUTTERFLY_VELOCITY); + + properties.velocity = vInterpolate(properties.velocity, desiredVelocity, 0.2); + properties.velocity.y = holding ; + + + // If we are near the target, we should get a new target + if (Vec3.length(Vec3.subtract(properties.position, butterflies[i].targetPosition)) < (properties.radius / 1.0)) { + butterflies[i].moving = false; + } + + + var yawRads = Math.atan2(properties.velocity.z, properties.velocity.x); + yawRads = yawRads + Math.PI / 2.0; + var newOrientation = Quat.fromPitchYawRollRadians(0.0, yawRads, 0.0); + properties.rotation = newOrientation; + + + } + + + // Use a cosine wave offset to make it look like its flapping. + var offset = Math.cos(nowTimeInSeconds * BUTTERFLY_FLAP_SPEED) * (properties.radius); + properties.position.y = properties.position.y + (offset - butterflies[i].previousFlapOffset); + // Change position relative to previous offset. + butterflies[i].previousFlapOffset = offset; + + + Entities.editEntity(entityID, properties); + } + } +} + +// register the call back so it fires before each data send +Script.update.connect(updateButterflies); \ No newline at end of file From 68d2be97f7b3b3f70e61ecc1d1c20c82f0b7991b Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Wed, 3 Sep 2014 19:46:33 -0700 Subject: [PATCH 31/31] formatting fixes --- examples/entitiesButterflyFlock.js | 31 +++++++----------------------- examples/twoFallingEntities.js | 2 +- 2 files changed, 8 insertions(+), 25 deletions(-) diff --git a/examples/entitiesButterflyFlock.js b/examples/entitiesButterflyFlock.js index c3382e43e1..a715c33c59 100644 --- a/examples/entitiesButterflyFlock.js +++ b/examples/entitiesButterflyFlock.js @@ -3,9 +3,10 @@ // // // Created by Adrian McCarlie on August 2, 2014 +// Modified by Brad Hefta-Gaub to use Entities on Sept. 3, 2014 // Copyright 2014 High Fidelity, Inc. // -// This sample script creates a swarm of butterfly Entities that fly around the avatar. +// This sample script creates a swarm of butterfly entities that fly around the avatar. // // Distributed under the Apache License, Version 2.0. // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html @@ -17,7 +18,6 @@ function getRandomFloat(min, max) { } // Multiply vector by scalar - function vScalarMult(v, s) { var rval = { x: v.x * s, y: v.y * s, z: v.z * s }; return rval; @@ -56,7 +56,7 @@ var roll = 0.0; //experimental var rotation = Quat.fromPitchYawRollDegrees(pitch, yaw, roll);//experimental // This is our butterfly object -function defineButterfly (entityID, targetPosition ) { +function defineButterfly(entityID, targetPosition) { this.entityID = entityID; this.previousFlapOffset = 0; this.targetPosition = targetPosition; @@ -66,7 +66,7 @@ function defineButterfly (entityID, targetPosition ) { // Array of butterflies var butterflies = []; var numButterflies = 20; -function addButterfly( ){ +function addButterfly() { // Decide the size of butterfly var color = { red: 100, green: 100, blue: 100 }; var size = 0; @@ -102,29 +102,22 @@ function addButterfly( ){ //animationURL: "http://business.ozblog.me/objects/butterfly/newButterfly6.fbx", //animationIsPlaying: true, modelURL: "http://business.ozblog.me/objects/butterfly/newButterfly6.fbx" - }; properties.position.z = properties.position.z+1; butterflies.push(new defineButterfly(Entities.addEntity(properties), properties.position)); - } - - // Generate the butterflies for (var i = 0; i < numButterflies; i++) { addButterfly(); - } // Main update function function updateButterflies(deltaTime) { - // Check to see if we've been running long enough that our butterflies are dead var nowTimeInSeconds = new Date().getTime() / 1000; if ((nowTimeInSeconds - startTimeInSeconds) >= lifeTime) { - - // print("our butterflies are dying, stop our script"); + // print("our butterflies are dying, stop our script"); Script.stop(); return; } @@ -177,7 +170,6 @@ function updateButterflies(deltaTime) { if (butterflies[i].moving == false) { if (Math.random() < CHANCE_OF_MOVING) { var targetPosition = Vec3.sum(randVector(-range, range), myPosition); - if (targetPosition.x < 0) { targetPosition.x = 0; } @@ -196,13 +188,10 @@ function updateButterflies(deltaTime) { if (targetPosition.z > TREE_SCALE) { targetPosition.z = TREE_SCALE; } - butterflies[i].targetPosition = targetPosition; - butterflies[i].moving = true; } } - // If we are moving, move towards the target if (butterflies[i].moving) { @@ -216,28 +205,22 @@ function updateButterflies(deltaTime) { properties.velocity.y = holding ; - // If we are near the target, we should get a new target + // If we are near the target, we should get a new target if (Vec3.length(Vec3.subtract(properties.position, butterflies[i].targetPosition)) < (properties.radius / 1.0)) { butterflies[i].moving = false; } - var yawRads = Math.atan2(properties.velocity.z, properties.velocity.x); yawRads = yawRads + Math.PI / 2.0; var newOrientation = Quat.fromPitchYawRollRadians(0.0, yawRads, 0.0); properties.rotation = newOrientation; - - } - - + // Use a cosine wave offset to make it look like its flapping. var offset = Math.cos(nowTimeInSeconds * BUTTERFLY_FLAP_SPEED) * (properties.radius); properties.position.y = properties.position.y + (offset - butterflies[i].previousFlapOffset); // Change position relative to previous offset. butterflies[i].previousFlapOffset = offset; - - Entities.editEntity(entityID, properties); } } diff --git a/examples/twoFallingEntities.js b/examples/twoFallingEntities.js index e7a8ff69e4..0d157b70c3 100644 --- a/examples/twoFallingEntities.js +++ b/examples/twoFallingEntities.js @@ -1,5 +1,5 @@ // -// Testing.js +// twoFallingEntities.js // // Creates a red 0.2 meter diameter ball right in front of your avatar that lives for 60 seconds //