From 39cb5100a3f441b2b3e0fad16a83c5498853d005 Mon Sep 17 00:00:00 2001 From: Atlante45 Date: Wed, 8 Jul 2015 12:23:22 -0700 Subject: [PATCH 01/28] Clear cache and restart first draft --- interface/src/Application.cpp | 13 +++++++++++++ interface/src/Application.h | 7 +++++++ interface/src/Menu.cpp | 1 + interface/src/Menu.h | 1 + interface/src/main.cpp | 10 ++++++++++ 5 files changed, 32 insertions(+) diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index 48fa53777d..6c140e8cbb 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -697,6 +697,14 @@ void Application::cleanupBeforeQuit() { #endif } +void Application::emptyLocalCache() { + QNetworkDiskCache* cache = qobject_cast(NetworkAccessManager::getInstance().cache()); + if (cache) { + qDebug() << "DiskCacheEditor::clear(): Clearing disk cache."; + cache->clear(); + } +} + Application::~Application() { EntityTree* tree = _entities.getTree(); tree->lockForWrite(); @@ -2404,6 +2412,11 @@ void Application::cameraMenuChanged() { } } +void Application::clearCacheAndQuit() { + emptyLocalCache(); + exit(RESTART_CODE); +} + void Application::rotationModeChanged() { if (!Menu::getInstance()->isOptionChecked(MenuOption::CenterPlayerInView)) { _myAvatar->setHeadPitch(0); diff --git a/interface/src/Application.h b/interface/src/Application.h index 8dd987fbcd..c387d80380 100644 --- a/interface/src/Application.h +++ b/interface/src/Application.h @@ -91,6 +91,9 @@ class Node; class ProgramObject; class ScriptEngine; + +static int RESTART_CODE = 1000; + static const float NODE_ADDED_RED = 0.0f; static const float NODE_ADDED_GREEN = 1.0f; static const float NODE_ADDED_BLUE = 0.0f; @@ -450,6 +453,8 @@ public slots: void domainConnectionDenied(const QString& reason); void cameraMenuChanged(); + + void clearCacheAndQuit(); private slots: void clearDomainOctreeDetails(); @@ -495,6 +500,8 @@ private: void init(); void cleanupBeforeQuit(); + + void emptyLocalCache(); void update(float deltaTime); diff --git a/interface/src/Menu.cpp b/interface/src/Menu.cpp index 9f49361f79..30d92f16dc 100644 --- a/interface/src/Menu.cpp +++ b/interface/src/Menu.cpp @@ -127,6 +127,7 @@ Menu::Menu() { addActionToQMenuAndActionHash(fileMenu, MenuOption::CopyPath, 0, addressManager.data(), SLOT(copyPath())); + addActionToQMenuAndActionHash(fileMenu, MenuOption::ClearCacheAndQuit, 0, qApp, SLOT(clearCacheAndQuit())); addActionToQMenuAndActionHash(fileMenu, MenuOption::Quit, Qt::CTRL | Qt::Key_Q, diff --git a/interface/src/Menu.h b/interface/src/Menu.h index 043bb53a7f..17f429a3f2 100644 --- a/interface/src/Menu.h +++ b/interface/src/Menu.h @@ -160,6 +160,7 @@ namespace MenuOption { const QString CalibrateCamera = "Calibrate Camera"; const QString CenterPlayerInView = "Center Player In View"; const QString Chat = "Chat..."; + const QString ClearCacheAndQuit = "Clear Cache and Quit"; const QString Collisions = "Collisions"; const QString Console = "Console..."; const QString ControlWithSpeech = "Control With Speech"; diff --git a/interface/src/main.cpp b/interface/src/main.cpp index e591034fb5..bfa1d9d643 100644 --- a/interface/src/main.cpp +++ b/interface/src/main.cpp @@ -11,6 +11,7 @@ #include #include #include +#include #include #include @@ -116,5 +117,14 @@ int main(int argc, const char* argv[]) { #endif qCDebug(interfaceapp, "Normal exit."); + + if (exitCode == RESTART_CODE) { + qCDebug(interfaceapp, "Interface restarting."); + QStringList arguments; + for (int i = 0; i < argc; ++i) { + arguments << argv[i]; + } + QProcess::startDetached(arguments[0], arguments); + } return exitCode; } From ed296850e22fd26b419baf723e0e9e2e53d31c03 Mon Sep 17 00:00:00 2001 From: Atlante45 Date: Wed, 8 Jul 2015 12:24:45 -0700 Subject: [PATCH 02/28] Rename to clear cache and restart --- interface/src/Application.cpp | 2 +- interface/src/Application.h | 2 +- interface/src/Menu.cpp | 2 +- interface/src/Menu.h | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index 6c140e8cbb..522d16981c 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -2412,7 +2412,7 @@ void Application::cameraMenuChanged() { } } -void Application::clearCacheAndQuit() { +void Application::clearCacheAndRestart() { emptyLocalCache(); exit(RESTART_CODE); } diff --git a/interface/src/Application.h b/interface/src/Application.h index c387d80380..a4c584da50 100644 --- a/interface/src/Application.h +++ b/interface/src/Application.h @@ -454,7 +454,7 @@ public slots: void cameraMenuChanged(); - void clearCacheAndQuit(); + void clearCacheAndRestart(); private slots: void clearDomainOctreeDetails(); diff --git a/interface/src/Menu.cpp b/interface/src/Menu.cpp index 30d92f16dc..7808840232 100644 --- a/interface/src/Menu.cpp +++ b/interface/src/Menu.cpp @@ -127,7 +127,7 @@ Menu::Menu() { addActionToQMenuAndActionHash(fileMenu, MenuOption::CopyPath, 0, addressManager.data(), SLOT(copyPath())); - addActionToQMenuAndActionHash(fileMenu, MenuOption::ClearCacheAndQuit, 0, qApp, SLOT(clearCacheAndQuit())); + addActionToQMenuAndActionHash(fileMenu, MenuOption::ClearCacheAndRestart, 0, qApp, SLOT(clearCacheAndRestart())); addActionToQMenuAndActionHash(fileMenu, MenuOption::Quit, Qt::CTRL | Qt::Key_Q, diff --git a/interface/src/Menu.h b/interface/src/Menu.h index 17f429a3f2..aa8e3f7a2a 100644 --- a/interface/src/Menu.h +++ b/interface/src/Menu.h @@ -160,7 +160,7 @@ namespace MenuOption { const QString CalibrateCamera = "Calibrate Camera"; const QString CenterPlayerInView = "Center Player In View"; const QString Chat = "Chat..."; - const QString ClearCacheAndQuit = "Clear Cache and Quit"; + const QString ClearCacheAndRestart = "Clear Cache and Restart"; const QString Collisions = "Collisions"; const QString Console = "Console..."; const QString ControlWithSpeech = "Control With Speech"; From ee3a8b1b6e54d2f87fbb1df007faea64e69dbda6 Mon Sep 17 00:00:00 2001 From: Atlante45 Date: Wed, 8 Jul 2015 18:23:16 -0700 Subject: [PATCH 03/28] Clear resource caches instead of restarting --- interface/src/Application.cpp | 6 +++++- libraries/model/src/model/Skybox.cpp | 2 +- libraries/networking/src/ResourceCache.cpp | 10 ++++++++++ libraries/networking/src/ResourceCache.h | 5 +++-- 4 files changed, 19 insertions(+), 4 deletions(-) diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index 522d16981c..78707410ed 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -2414,7 +2414,11 @@ void Application::cameraMenuChanged() { void Application::clearCacheAndRestart() { emptyLocalCache(); - exit(RESTART_CODE); + + DependencyManager::get()->refreshAll(); + DependencyManager::get()->refreshAll(); + DependencyManager::get()->refreshAll(); + DependencyManager::get()->refreshAll(); } void Application::rotationModeChanged() { diff --git a/libraries/model/src/model/Skybox.cpp b/libraries/model/src/model/Skybox.cpp index 10199adda3..f403f59e30 100755 --- a/libraries/model/src/model/Skybox.cpp +++ b/libraries/model/src/model/Skybox.cpp @@ -101,7 +101,7 @@ void Skybox::render(gpu::Batch& batch, const ViewFrustum& viewFrustum, const Sky batch.setModelTransform(Transform()); // only for Mac batch.setPipeline(thePipeline); batch.setInputBuffer(gpu::Stream::POSITION, theBuffer, 0, 8); - batch.setUniformBuffer(SKYBOX_CONSTANTS_SLOT, theConstants, 0, theConstants->getSize()); + //batch.setUniformBuffer(SKYBOX_CONSTANTS_SLOT, theConstants, 0, theConstants->getSize()); batch.setInputFormat(theFormat); batch.setUniformTexture(0, skybox.getCubemap()); batch.draw(gpu::TRIANGLE_STRIP, 4); diff --git a/libraries/networking/src/ResourceCache.cpp b/libraries/networking/src/ResourceCache.cpp index 0b6e39b151..cee0dbecf6 100644 --- a/libraries/networking/src/ResourceCache.cpp +++ b/libraries/networking/src/ResourceCache.cpp @@ -44,10 +44,20 @@ ResourceCache::~ResourceCache() { } } +void ResourceCache::refreshAll() { + for (auto it = _resources.begin(); it != _resources.end(); ++it) { + if (!it.value().isNull()) { + it.value().data()->refresh(); + } + } +} + void ResourceCache::refresh(const QUrl& url) { QSharedPointer resource = _resources.value(url); if (!resource.isNull()) { resource->refresh(); + } else { + _resources.remove(url); } } diff --git a/libraries/networking/src/ResourceCache.h b/libraries/networking/src/ResourceCache.h index ebe2c6e684..b4b9f089c5 100644 --- a/libraries/networking/src/ResourceCache.h +++ b/libraries/networking/src/ResourceCache.h @@ -78,7 +78,8 @@ public: ResourceCache(QObject* parent = NULL); virtual ~ResourceCache(); - + + void refreshAll(); void refresh(const QUrl& url); public slots: @@ -110,7 +111,7 @@ protected: private: friend class Resource; - QHash > _resources; + QHash> _resources; int _lastLRUKey = 0; static int _requestLimit; From 90edf055f74ae36244c1a02c3119d61c7dfe6eae Mon Sep 17 00:00:00 2001 From: Atlante45 Date: Thu, 9 Jul 2015 18:00:07 -0700 Subject: [PATCH 04/28] Clear unused resources before refresh --- libraries/networking/src/ResourceCache.cpp | 39 +++++++++++++--------- libraries/networking/src/ResourceCache.h | 17 ++++------ 2 files changed, 30 insertions(+), 26 deletions(-) diff --git a/libraries/networking/src/ResourceCache.cpp b/libraries/networking/src/ResourceCache.cpp index cee0dbecf6..f3ed60c281 100644 --- a/libraries/networking/src/ResourceCache.cpp +++ b/libraries/networking/src/ResourceCache.cpp @@ -34,20 +34,17 @@ ResourceCache::ResourceCache(QObject* parent) : } ResourceCache::~ResourceCache() { - // the unused resources may themselves reference resources that will be added to the unused - // list on destruction, so keep clearing until there are no references left - while (!_unusedResources.isEmpty()) { - foreach (const QSharedPointer& resource, _unusedResources) { - resource->setCache(nullptr); - } - _unusedResources.clear(); - } + clearUnusedResource(); } void ResourceCache::refreshAll() { - for (auto it = _resources.begin(); it != _resources.end(); ++it) { - if (!it.value().isNull()) { - it.value().data()->refresh(); + // Clear all unused resources so we don't have to reload them + clearUnusedResource(); + + // Refresh all remaining resources in use + foreach (auto resource, _resources) { + if (!resource.isNull()) { + resource.data()->refresh(); } } } @@ -144,6 +141,17 @@ void ResourceCache::reserveUnusedResource(qint64 resourceSize) { } } +void ResourceCache::clearUnusedResource() { + // the unused resources may themselves reference resources that will be added to the unused + // list on destruction, so keep clearing until there are no references left + while (!_unusedResources.isEmpty()) { + foreach (const QSharedPointer& resource, _unusedResources) { + resource->setCache(nullptr); + } + _unusedResources.clear(); + } +} + void ResourceCache::attemptRequest(Resource* resource) { auto sharedItems = DependencyManager::get(); if (_requestLimit <= 0) { @@ -271,11 +279,12 @@ void Resource::refresh() { } void Resource::allReferencesCleared() { - if (QThread::currentThread() != thread()) { - QMetaObject::invokeMethod(this, "allReferencesCleared"); - return; - } if (_cache) { + if (QThread::currentThread() != thread()) { + QMetaObject::invokeMethod(this, "allReferencesCleared"); + return; + } + // create and reinsert new shared pointer QSharedPointer self(this, &Resource::allReferencesCleared); setSelf(self); diff --git a/libraries/networking/src/ResourceCache.h b/libraries/networking/src/ResourceCache.h index b4b9f089c5..4997826870 100644 --- a/libraries/networking/src/ResourceCache.h +++ b/libraries/networking/src/ResourceCache.h @@ -51,7 +51,7 @@ static const qint64 MAX_UNUSED_MAX_SIZE = 10 * BYTES_PER_GIGABYTES; class ResourceCacheSharedItems : public Dependency { SINGLETON_DEPENDENCY public: - QList > _pendingRequests; + QList> _pendingRequests; QList _loadingRequests; private: ResourceCacheSharedItems() { } @@ -86,10 +86,6 @@ public slots: void checkAsynchronousGets(); protected: - qint64 _unusedResourcesMaxSize = DEFAULT_UNUSED_MAX_SIZE; - qint64 _unusedResourcesSize = 0; - QMap > _unusedResources; - /// Loads a resource from the specified URL. /// \param fallback a fallback URL to load if the desired one is unavailable /// \param delayLoad if true, don't load the resource immediately; wait until load is first requested @@ -104,6 +100,7 @@ protected: void addUnusedResource(const QSharedPointer& resource); void removeUnusedResource(const QSharedPointer& resource); void reserveUnusedResource(qint64 resourceSize); + void clearUnusedResource(); static void attemptRequest(Resource* resource); static void requestCompleted(Resource* resource); @@ -119,7 +116,10 @@ private: void getResourceAsynchronously(const QUrl& url); QReadWriteLock _resourcesToBeGottenLock; QQueue _resourcesToBeGotten; - + + qint64 _unusedResourcesMaxSize = DEFAULT_UNUSED_MAX_SIZE; + qint64 _unusedResourcesSize = 0; + QMap> _unusedResources; }; /// Base class for resources. @@ -173,12 +173,10 @@ public: const QUrl& getURL() const { return _url; } signals: - /// Fired when the resource has been loaded. void loaded(); protected slots: - void attemptRequest(); /// Refreshes the resource if the last modified date on the network @@ -186,7 +184,6 @@ protected slots: void maybeRefresh(); protected: - virtual void init(); /// Called when the download has finished. The recipient should delete the reply when done with it. @@ -208,14 +205,12 @@ protected: QPointer _cache; private slots: - void handleDownloadProgress(qint64 bytesReceived, qint64 bytesTotal); void handleReplyError(); void handleReplyFinished(); void handleReplyTimeout(); private: - void setLRUKey(int lruKey) { _lruKey = lruKey; } void makeRequest(); From 6c591131ba32315b5fb2c3dfeac97e7d54bf6869 Mon Sep 17 00:00:00 2001 From: Atlante45 Date: Fri, 10 Jul 2015 12:01:51 -0700 Subject: [PATCH 05/28] Made Animations safe for resource reload --- .../src/avatars/ScriptableAvatar.cpp | 2 +- libraries/animation/src/AnimationCache.cpp | 4 +--- libraries/animation/src/AnimationCache.h | 3 --- libraries/audio/src/AudioInjector.cpp | 2 +- libraries/entities/src/ModelEntityItem.cpp | 17 ++++++++++------- libraries/entities/src/ModelEntityItem.h | 2 +- libraries/networking/src/ResourceCache.cpp | 9 ++++----- libraries/networking/src/ResourceCache.h | 1 + libraries/render-utils/src/AnimationHandle.cpp | 11 ++++++++++- libraries/render-utils/src/AnimationHandle.h | 2 ++ 10 files changed, 31 insertions(+), 22 deletions(-) diff --git a/assignment-client/src/avatars/ScriptableAvatar.cpp b/assignment-client/src/avatars/ScriptableAvatar.cpp index e2f0449216..3d243d78ec 100644 --- a/assignment-client/src/avatars/ScriptableAvatar.cpp +++ b/assignment-client/src/avatars/ScriptableAvatar.cpp @@ -53,7 +53,7 @@ AnimationDetails ScriptableAvatar::getAnimationDetails() { void ScriptableAvatar::update(float deltatime) { // Run animation - if (_animation != NULL && _animation->isValid() && _animation->getFrames().size() > 0) { + if (_animation && _animation->isLoaded() && _animation->getFrames().size() > 0) { QStringList modelJoints = getJointNames(); QStringList animationJoints = _animation->getJointNames(); diff --git a/libraries/animation/src/AnimationCache.cpp b/libraries/animation/src/AnimationCache.cpp index 6c02ccbd2b..9eb68cedc2 100644 --- a/libraries/animation/src/AnimationCache.cpp +++ b/libraries/animation/src/AnimationCache.cpp @@ -39,8 +39,7 @@ QSharedPointer AnimationCache::createResource(const QUrl& url, const Q } Animation::Animation(const QUrl& url) : - Resource(url), - _isValid(false) { + Resource(url) { } class AnimationReader : public QRunnable { @@ -97,7 +96,6 @@ QVector Animation::getFrames() const { void Animation::setGeometry(const FBXGeometry& geometry) { _geometry = geometry; finishedLoading(true); - _isValid = true; } void Animation::downloadFinished(QNetworkReply* reply) { diff --git a/libraries/animation/src/AnimationCache.h b/libraries/animation/src/AnimationCache.h index 6dbd5fdaad..c90c4c9225 100644 --- a/libraries/animation/src/AnimationCache.h +++ b/libraries/animation/src/AnimationCache.h @@ -57,8 +57,6 @@ public: Q_INVOKABLE QStringList getJointNames() const; Q_INVOKABLE QVector getFrames() const; - - bool isValid() const { return _isValid; } protected: @@ -69,7 +67,6 @@ protected: private: FBXGeometry _geometry; - bool _isValid; }; diff --git a/libraries/audio/src/AudioInjector.cpp b/libraries/audio/src/AudioInjector.cpp index 36b0345d34..f49d51bb8b 100644 --- a/libraries/audio/src/AudioInjector.cpp +++ b/libraries/audio/src/AudioInjector.cpp @@ -294,7 +294,7 @@ AudioInjector* AudioInjector::playSound(const QString& soundUrl, const float vol if (soundCache.isNull()) { return NULL; } - SharedSoundPointer sound = soundCache.data()->getSound(QUrl(soundUrl)); + SharedSoundPointer sound = soundCache->getSound(QUrl(soundUrl)); if (sound.isNull() || !sound->isReady()) { return NULL; } diff --git a/libraries/entities/src/ModelEntityItem.cpp b/libraries/entities/src/ModelEntityItem.cpp index a6ae9e04de..b72dd5fab4 100644 --- a/libraries/entities/src/ModelEntityItem.cpp +++ b/libraries/entities/src/ModelEntityItem.cpp @@ -184,7 +184,7 @@ void ModelEntityItem::cleanupLoadedAnimations() { _loadedAnimations.clear(); } -Animation* ModelEntityItem::getAnimation(const QString& url) { +AnimationPointer ModelEntityItem::getAnimation(const QString& url) { AnimationPointer animation; // if we don't already have this model then create it and initialize it @@ -194,7 +194,7 @@ Animation* ModelEntityItem::getAnimation(const QString& url) { } else { animation = _loadedAnimations[url]; } - return animation.data(); + return animation; } void ModelEntityItem::mapJoints(const QStringList& modelJointNames) { @@ -203,9 +203,8 @@ void ModelEntityItem::mapJoints(const QStringList& modelJointNames) { return; } - Animation* myAnimation = getAnimation(_animationURL); - - if (!_jointMappingCompleted) { + AnimationPointer myAnimation = getAnimation(_animationURL); + if (myAnimation && myAnimation->isLoaded()) { QStringList animationJointNames = myAnimation->getJointNames(); if (modelJointNames.size() > 0 && animationJointNames.size() > 0) { @@ -220,8 +219,12 @@ void ModelEntityItem::mapJoints(const QStringList& modelJointNames) { QVector ModelEntityItem::getAnimationFrame() { QVector frameData; - if (hasAnimation() && _jointMappingCompleted) { - Animation* myAnimation = getAnimation(_animationURL); + if (!hasAnimation() || !_jointMappingCompleted) { + return frameData; + } + + AnimationPointer myAnimation = getAnimation(_animationURL); + if (myAnimation && myAnimation->isLoaded()) { QVector frames = myAnimation->getFrames(); int frameCount = frames.size(); if (frameCount > 0) { diff --git a/libraries/entities/src/ModelEntityItem.h b/libraries/entities/src/ModelEntityItem.h index 32441decd3..ae6a86cde1 100644 --- a/libraries/entities/src/ModelEntityItem.h +++ b/libraries/entities/src/ModelEntityItem.h @@ -141,7 +141,7 @@ protected: bool _jointMappingCompleted; QVector _jointMapping; - static Animation* getAnimation(const QString& url); + static AnimationPointer getAnimation(const QString& url); static QMap _loadedAnimations; static AnimationCache _animationCache; diff --git a/libraries/networking/src/ResourceCache.cpp b/libraries/networking/src/ResourceCache.cpp index f3ed60c281..e127380630 100644 --- a/libraries/networking/src/ResourceCache.cpp +++ b/libraries/networking/src/ResourceCache.cpp @@ -271,11 +271,11 @@ void Resource::refresh() { _replyTimer->deleteLater(); _replyTimer = nullptr; } + init(); _request.setAttribute(QNetworkRequest::CacheLoadControlAttribute, QNetworkRequest::AlwaysNetwork); - if (!_startedLoading) { - attemptRequest(); - } + ensureLoading(); + emit onRefresh(); } void Resource::allReferencesCleared() { @@ -331,8 +331,7 @@ void Resource::reinsert() { _cache->_resources.insert(_url, _self); } -const int REPLY_TIMEOUT_MS = 5000; - +static const int REPLY_TIMEOUT_MS = 5000; void Resource::handleDownloadProgress(qint64 bytesReceived, qint64 bytesTotal) { if (!_reply->isFinished()) { _bytesReceived = bytesReceived; diff --git a/libraries/networking/src/ResourceCache.h b/libraries/networking/src/ResourceCache.h index 4997826870..93ddfe77be 100644 --- a/libraries/networking/src/ResourceCache.h +++ b/libraries/networking/src/ResourceCache.h @@ -175,6 +175,7 @@ public: signals: /// Fired when the resource has been loaded. void loaded(); + void onRefresh(); protected slots: void attemptRequest(); diff --git a/libraries/render-utils/src/AnimationHandle.cpp b/libraries/render-utils/src/AnimationHandle.cpp index 55995b87d8..217c4948e8 100644 --- a/libraries/render-utils/src/AnimationHandle.cpp +++ b/libraries/render-utils/src/AnimationHandle.cpp @@ -15,6 +15,7 @@ void AnimationHandle::setURL(const QUrl& url) { if (_url != url) { _animation = DependencyManager::get()->getAnimation(_url = url); + QObject::connect(_animation.data(), &Resource::onRefresh, this, &AnimationHandle::clearJoints); _jointMappings.clear(); } } @@ -110,11 +111,15 @@ void AnimationHandle::setAnimationDetails(const AnimationDetails& details) { void AnimationHandle::simulate(float deltaTime) { + if (!_animation->isLoaded()) { + return; + } + _animationLoop.simulate(deltaTime); // update the joint mappings if necessary/possible if (_jointMappings.isEmpty()) { - if (_model->isActive()) { + if (_model && _model->isActive()) { _jointMappings = _model->getGeometry()->getJointMappings(_animation); } if (_jointMappings.isEmpty()) { @@ -146,6 +151,10 @@ void AnimationHandle::simulate(float deltaTime) { } void AnimationHandle::applyFrame(float frameIndex) { + if (!_animation->isLoaded()) { + return; + } + const FBXGeometry& animationGeometry = _animation->getGeometry(); int frameCount = animationGeometry.animationFrames.size(); const FBXAnimationFrame& floorFrame = animationGeometry.animationFrames.at((int)glm::floor(frameIndex) % frameCount); diff --git a/libraries/render-utils/src/AnimationHandle.h b/libraries/render-utils/src/AnimationHandle.h index 13a1b97dc1..ca9c2eb6d0 100644 --- a/libraries/render-utils/src/AnimationHandle.h +++ b/libraries/render-utils/src/AnimationHandle.h @@ -94,6 +94,8 @@ private: void replaceMatchingPriorities(float newPriority); void restoreJoints(); + void clearJoints() { _jointMappings.clear(); } + Model* _model; WeakAnimationHandlePointer _self; AnimationPointer _animation; From 5cfa1605dfaf27604e78c52eee04172c9e8f21d6 Mon Sep 17 00:00:00 2001 From: Atlante45 Date: Fri, 10 Jul 2015 12:28:06 -0700 Subject: [PATCH 06/28] Made Texture safe with resource refresh --- .../src/ui/overlays/BillboardOverlay.cpp | 6 +++--- libraries/model/src/model/Skybox.cpp | 2 +- libraries/render-utils/src/GeometryCache.cpp | 21 +++++++------------ 3 files changed, 12 insertions(+), 17 deletions(-) diff --git a/interface/src/ui/overlays/BillboardOverlay.cpp b/interface/src/ui/overlays/BillboardOverlay.cpp index 988223765a..365c8a2785 100644 --- a/interface/src/ui/overlays/BillboardOverlay.cpp +++ b/interface/src/ui/overlays/BillboardOverlay.cpp @@ -28,12 +28,12 @@ BillboardOverlay::BillboardOverlay(const BillboardOverlay* billboardOverlay) : } void BillboardOverlay::render(RenderArgs* args) { - if (!_isLoaded) { + if (!_texture) { _isLoaded = true; _texture = DependencyManager::get()->getTexture(_url); } - if (!_visible || !_texture->isLoaded()) { + if (!_visible || !_texture || !_texture->isLoaded()) { return; } @@ -170,7 +170,7 @@ void BillboardOverlay::setBillboardURL(const QString& url) { bool BillboardOverlay::findRayIntersection(const glm::vec3& origin, const glm::vec3& direction, float& distance, BoxFace& face) { - if (_texture) { + if (_texture && _texture->isLoaded()) { glm::quat rotation = getRotation(); if (_isFacingAvatar) { // rotate about vertical to face the camera diff --git a/libraries/model/src/model/Skybox.cpp b/libraries/model/src/model/Skybox.cpp index 5be3412c6c..a02c646668 100755 --- a/libraries/model/src/model/Skybox.cpp +++ b/libraries/model/src/model/Skybox.cpp @@ -101,7 +101,7 @@ void Skybox::render(gpu::Batch& batch, const ViewFrustum& viewFrustum, const Sky batch.setModelTransform(Transform()); // only for Mac batch.setPipeline(thePipeline); batch.setInputBuffer(gpu::Stream::POSITION, theBuffer, 0, 8); - //batch.setUniformBuffer(SKYBOX_CONSTANTS_SLOT, theConstants, 0, theConstants->getSize()); + batch.setUniformBuffer(SKYBOX_CONSTANTS_SLOT, theConstants, 0, theConstants->getSize()); batch.setInputFormat(theFormat); batch.setUniformTexture(0, skybox.getCubemap()); batch.draw(gpu::TRIANGLE_STRIP, 4); diff --git a/libraries/render-utils/src/GeometryCache.cpp b/libraries/render-utils/src/GeometryCache.cpp index 02e59bfa3a..6d0748df7c 100644 --- a/libraries/render-utils/src/GeometryCache.cpp +++ b/libraries/render-utils/src/GeometryCache.cpp @@ -2061,21 +2061,16 @@ void NetworkGeometry::setTextureWithNameToURL(const QString& name, const QUrl& u QSharedPointer matchingTexture = QSharedPointer(); if (part.diffuseTextureName == name) { - part.diffuseTexture = - textureCache->getTexture(url, DEFAULT_TEXTURE, - _geometry.meshes[i].isEye, QByteArray()); + part.diffuseTexture = textureCache->getTexture(url, DEFAULT_TEXTURE, _geometry.meshes[i].isEye); part.diffuseTexture->setLoadPriorities(_loadPriorities); } else if (part.normalTextureName == name) { - part.normalTexture = textureCache->getTexture(url, DEFAULT_TEXTURE, - false, QByteArray()); + part.normalTexture = textureCache->getTexture(url); part.normalTexture->setLoadPriorities(_loadPriorities); } else if (part.specularTextureName == name) { - part.specularTexture = textureCache->getTexture(url, DEFAULT_TEXTURE, - false, QByteArray()); + part.specularTexture = textureCache->getTexture(url); part.specularTexture->setLoadPriorities(_loadPriorities); } else if (part.emissiveTextureName == name) { - part.emissiveTexture = textureCache->getTexture(url, DEFAULT_TEXTURE, - false, QByteArray()); + part.emissiveTexture = textureCache->getTexture(url); part.emissiveTexture->setLoadPriorities(_loadPriorities); } } @@ -2095,22 +2090,22 @@ QStringList NetworkGeometry::getTextureNames() const { for (int j = 0; j < mesh.parts.size(); j++) { const NetworkMeshPart& part = mesh.parts[j]; - if (!part.diffuseTextureName.isEmpty()) { + if (!part.diffuseTextureName.isEmpty() && part.diffuseTexture) { QString textureURL = part.diffuseTexture->getURL().toString(); result << part.diffuseTextureName + ":" + textureURL; } - if (!part.normalTextureName.isEmpty()) { + if (!part.normalTextureName.isEmpty() && part.normalTexture) { QString textureURL = part.normalTexture->getURL().toString(); result << part.normalTextureName + ":" + textureURL; } - if (!part.specularTextureName.isEmpty()) { + if (!part.specularTextureName.isEmpty() && part.specularTexture) { QString textureURL = part.specularTexture->getURL().toString(); result << part.specularTextureName + ":" + textureURL; } - if (!part.emissiveTextureName.isEmpty()) { + if (!part.emissiveTextureName.isEmpty() && part.emissiveTexture) { QString textureURL = part.emissiveTexture->getURL().toString(); result << part.emissiveTextureName + ":" + textureURL; } From 49993695a5f7dc53486b37bfc05607f2e17cded1 Mon Sep 17 00:00:00 2001 From: Atlante45 Date: Fri, 10 Jul 2015 15:20:19 -0700 Subject: [PATCH 07/28] Made geometry refresh safe --- .../src/EntityTreeRenderer.cpp | 2 +- .../src/RenderableModelEntityItem.cpp | 6 +-- libraries/render-utils/src/Model.cpp | 47 ++++++++++++++++--- libraries/render-utils/src/Model.h | 8 ++-- 4 files changed, 49 insertions(+), 14 deletions(-) diff --git a/libraries/entities-renderer/src/EntityTreeRenderer.cpp b/libraries/entities-renderer/src/EntityTreeRenderer.cpp index 11d24c6d9d..5bad452d00 100644 --- a/libraries/entities-renderer/src/EntityTreeRenderer.cpp +++ b/libraries/entities-renderer/src/EntityTreeRenderer.cpp @@ -544,7 +544,7 @@ const FBXGeometry* EntityTreeRenderer::getCollisionGeometryForEntity(EntityItemP Model* model = modelEntityItem->getModel(this); if (model) { const QSharedPointer collisionNetworkGeometry = model->getCollisionGeometry(); - if (!collisionNetworkGeometry.isNull()) { + if (!collisionNetworkGeometry || !collisionNetworkGeometry->isLoaded()) { result = &collisionNetworkGeometry->getFBXGeometry(); } } diff --git a/libraries/entities-renderer/src/RenderableModelEntityItem.cpp b/libraries/entities-renderer/src/RenderableModelEntityItem.cpp index 85b7bafc78..cc4c8390c9 100644 --- a/libraries/entities-renderer/src/RenderableModelEntityItem.cpp +++ b/libraries/entities-renderer/src/RenderableModelEntityItem.cpp @@ -397,8 +397,8 @@ bool RenderableModelEntityItem::isReadyToComputeShape() { const QSharedPointer collisionNetworkGeometry = _model->getCollisionGeometry(); const QSharedPointer renderNetworkGeometry = _model->getGeometry(); - if ((! collisionNetworkGeometry.isNull() && collisionNetworkGeometry->isLoadedWithTextures()) && - (! renderNetworkGeometry.isNull() && renderNetworkGeometry->isLoadedWithTextures())) { + if ((!collisionNetworkGeometry && collisionNetworkGeometry->isLoadedWithTextures()) && + (!renderNetworkGeometry && renderNetworkGeometry->isLoadedWithTextures())) { // we have both URLs AND both geometries AND they are both fully loaded. return true; } @@ -419,7 +419,7 @@ void RenderableModelEntityItem::computeShapeInfo(ShapeInfo& info) { // should never fall in here when collision model not fully loaded // hence we assert collisionNetworkGeometry is not NULL - assert(!collisionNetworkGeometry.isNull()); + assert(!collisionNetworkGeometry); const FBXGeometry& collisionGeometry = collisionNetworkGeometry->getFBXGeometry(); const QSharedPointer renderNetworkGeometry = _model->getGeometry(); diff --git a/libraries/render-utils/src/Model.cpp b/libraries/render-utils/src/Model.cpp index 03140c4dfb..2820fe74a9 100644 --- a/libraries/render-utils/src/Model.cpp +++ b/libraries/render-utils/src/Model.cpp @@ -457,7 +457,8 @@ bool Model::updateGeometry() { } deleteGeometry(); _dilatedTextures.clear(); - _geometry = geometry; + setGeometry(geometry); + _meshGroupsKnown = false; _readyWhenAdded = false; // in case any of our users are using scenes invalidCalculatedMeshBoxes(); // if we have to reload, we need to assume our mesh boxes are all invalid @@ -1142,13 +1143,32 @@ void Model::setURL(const QUrl& url, const QUrl& fallback, bool retainCurrent, bo onInvalidate(); // if so instructed, keep the current geometry until the new one is loaded - _nextBaseGeometry = _nextGeometry = DependencyManager::get()->getGeometry(url, fallback, delayLoad); + _nextGeometry = DependencyManager::get()->getGeometry(url, fallback, delayLoad); _nextLODHysteresis = NetworkGeometry::NO_HYSTERESIS; if (!retainCurrent || !isActive() || (_nextGeometry && _nextGeometry->isLoaded())) { applyNextGeometry(); } } +void Model::geometryRefreshed() { + QObject* sender = QObject::sender(); + + if (sender == _geometry) { + _readyWhenAdded = false; // reset out render items. + _needsReload = true; + invalidCalculatedMeshBoxes(); + + onInvalidate(); + + // if so instructed, keep the current geometry until the new one is loaded + _nextGeometry = DependencyManager::get()->getGeometry(_url); + _nextLODHysteresis = NetworkGeometry::NO_HYSTERESIS; + applyNextGeometry(); + } else { + sender->disconnect(this, SLOT(geometryRefreshed())); + } +} + const QSharedPointer Model::getCollisionGeometry(bool delayLoad) { @@ -1156,7 +1176,11 @@ const QSharedPointer Model::getCollisionGeometry(bool delayLoad _collisionGeometry = DependencyManager::get()->getGeometry(_collisionUrl, QUrl(), delayLoad); } - return _collisionGeometry; + if (_collisionGeometry && _collisionGeometry->isLoaded()) { + return _collisionGeometry; + } + + return QSharedPointer(); } void Model::setCollisionModelURL(const QUrl& url) { @@ -1776,6 +1800,18 @@ void Model::setBlendedVertices(int blendNumber, const QWeakPointer& newGeometry) { + if (_geometry == newGeometry) { + return; + } + + if (_geometry) { + _geometry->disconnect(_geometry.data(), &Resource::onRefresh, this, &Model::geometryRefreshed); + } + _geometry = newGeometry; + QObject::connect(_geometry.data(), &Resource::onRefresh, this, &Model::geometryRefreshed); +} + void Model::applyNextGeometry() { // delete our local geometry and custom textures deleteGeometry(); @@ -1783,13 +1819,12 @@ void Model::applyNextGeometry() { _lodHysteresis = _nextLODHysteresis; // we retain a reference to the base geometry so that its reference count doesn't fall to zero - _baseGeometry = _nextBaseGeometry; - _geometry = _nextGeometry; + setGeometry(_nextGeometry); + _meshGroupsKnown = false; _readyWhenAdded = false; // in case any of our users are using scenes _needsReload = false; // we are loaded now! invalidCalculatedMeshBoxes(); - _nextBaseGeometry.reset(); _nextGeometry.reset(); } diff --git a/libraries/render-utils/src/Model.h b/libraries/render-utils/src/Model.h index a6ce566a36..60e4d1dbaa 100644 --- a/libraries/render-utils/src/Model.h +++ b/libraries/render-utils/src/Model.h @@ -245,6 +245,7 @@ public: protected: QSharedPointer _geometry; + void setGeometry(const QSharedPointer& newGeometry); glm::vec3 _scale; glm::vec3 _offset; @@ -321,6 +322,9 @@ protected: // hook for derived classes to be notified when setUrl invalidates the current model. virtual void onInvalidate() {}; +protected slots: + void geometryRefreshed(); + private: friend class AnimationHandle; @@ -330,15 +334,12 @@ private: QVector createJointStates(const FBXGeometry& geometry); void initJointTransforms(); - QSharedPointer _baseGeometry; ///< reference required to prevent collection of base - QSharedPointer _nextBaseGeometry; QSharedPointer _nextGeometry; float _lodDistance; float _lodHysteresis; float _nextLODHysteresis; QSharedPointer _collisionGeometry; - QSharedPointer _saveNonCollisionGeometry; float _pupilDilation; QVector _blendshapeCoefficients; @@ -524,7 +525,6 @@ private: QMap _renderItems; bool _readyWhenAdded = false; bool _needsReload = true; - }; Q_DECLARE_METATYPE(QPointer) From a3848f08d2c9d9da3639f90155df9759946a3925 Mon Sep 17 00:00:00 2001 From: Atlante45 Date: Fri, 10 Jul 2015 15:36:17 -0700 Subject: [PATCH 08/28] Conditionnal fixes. --- interface/src/avatar/Avatar.cpp | 2 +- libraries/entities-renderer/src/EntityTreeRenderer.cpp | 2 +- .../entities-renderer/src/RenderableModelEntityItem.cpp | 6 +++--- libraries/render-utils/src/AnimationHandle.cpp | 4 ++-- libraries/render-utils/src/GeometryCache.cpp | 2 +- 5 files changed, 8 insertions(+), 8 deletions(-) diff --git a/interface/src/avatar/Avatar.cpp b/interface/src/avatar/Avatar.cpp index 3d4c158a0b..48dad3cabb 100644 --- a/interface/src/avatar/Avatar.cpp +++ b/interface/src/avatar/Avatar.cpp @@ -622,7 +622,7 @@ void Avatar::renderBillboard(RenderArgs* renderArgs) { _billboardTexture = DependencyManager::get()->getTexture( uniqueUrl, DEFAULT_TEXTURE, false, _billboard); } - if (!_billboardTexture->isLoaded()) { + if (!_billboardTexture || !_billboardTexture->isLoaded()) { return; } // rotate about vertical to face the camera diff --git a/libraries/entities-renderer/src/EntityTreeRenderer.cpp b/libraries/entities-renderer/src/EntityTreeRenderer.cpp index 5bad452d00..a2ea23c51e 100644 --- a/libraries/entities-renderer/src/EntityTreeRenderer.cpp +++ b/libraries/entities-renderer/src/EntityTreeRenderer.cpp @@ -544,7 +544,7 @@ const FBXGeometry* EntityTreeRenderer::getCollisionGeometryForEntity(EntityItemP Model* model = modelEntityItem->getModel(this); if (model) { const QSharedPointer collisionNetworkGeometry = model->getCollisionGeometry(); - if (!collisionNetworkGeometry || !collisionNetworkGeometry->isLoaded()) { + if (collisionNetworkGeometry && collisionNetworkGeometry->isLoaded()) { result = &collisionNetworkGeometry->getFBXGeometry(); } } diff --git a/libraries/entities-renderer/src/RenderableModelEntityItem.cpp b/libraries/entities-renderer/src/RenderableModelEntityItem.cpp index cc4c8390c9..03aca71284 100644 --- a/libraries/entities-renderer/src/RenderableModelEntityItem.cpp +++ b/libraries/entities-renderer/src/RenderableModelEntityItem.cpp @@ -397,8 +397,8 @@ bool RenderableModelEntityItem::isReadyToComputeShape() { const QSharedPointer collisionNetworkGeometry = _model->getCollisionGeometry(); const QSharedPointer renderNetworkGeometry = _model->getGeometry(); - if ((!collisionNetworkGeometry && collisionNetworkGeometry->isLoadedWithTextures()) && - (!renderNetworkGeometry && renderNetworkGeometry->isLoadedWithTextures())) { + if ((collisionNetworkGeometry && collisionNetworkGeometry->isLoadedWithTextures()) && + (renderNetworkGeometry && renderNetworkGeometry->isLoadedWithTextures())) { // we have both URLs AND both geometries AND they are both fully loaded. return true; } @@ -419,7 +419,7 @@ void RenderableModelEntityItem::computeShapeInfo(ShapeInfo& info) { // should never fall in here when collision model not fully loaded // hence we assert collisionNetworkGeometry is not NULL - assert(!collisionNetworkGeometry); + assert(collisionNetworkGeometry); const FBXGeometry& collisionGeometry = collisionNetworkGeometry->getFBXGeometry(); const QSharedPointer renderNetworkGeometry = _model->getGeometry(); diff --git a/libraries/render-utils/src/AnimationHandle.cpp b/libraries/render-utils/src/AnimationHandle.cpp index 217c4948e8..6ad6730952 100644 --- a/libraries/render-utils/src/AnimationHandle.cpp +++ b/libraries/render-utils/src/AnimationHandle.cpp @@ -111,7 +111,7 @@ void AnimationHandle::setAnimationDetails(const AnimationDetails& details) { void AnimationHandle::simulate(float deltaTime) { - if (!_animation->isLoaded()) { + if (!_animation || !_animation->isLoaded()) { return; } @@ -151,7 +151,7 @@ void AnimationHandle::simulate(float deltaTime) { } void AnimationHandle::applyFrame(float frameIndex) { - if (!_animation->isLoaded()) { + if (!_animation || !_animation->isLoaded()) { return; } diff --git a/libraries/render-utils/src/GeometryCache.cpp b/libraries/render-utils/src/GeometryCache.cpp index 6d0748df7c..14890bd154 100644 --- a/libraries/render-utils/src/GeometryCache.cpp +++ b/libraries/render-utils/src/GeometryCache.cpp @@ -1942,7 +1942,7 @@ QSharedPointer NetworkGeometry::getLODOrFallback(float distance } } } - if (lod->isLoaded()) { + if (lod && lod->isLoaded()) { hysteresis = lodDistance; return lod; } From ec7e1df8c0ae2d0f720481bdf8b0fc1beacdcaac Mon Sep 17 00:00:00 2001 From: Atlante45 Date: Fri, 10 Jul 2015 15:47:46 -0700 Subject: [PATCH 09/28] Move and rename menu item --- interface/src/Application.cpp | 2 +- interface/src/Application.h | 2 +- interface/src/Menu.cpp | 3 ++- interface/src/Menu.h | 2 +- libraries/model/src/model/Skybox.cpp | 2 +- 5 files changed, 6 insertions(+), 5 deletions(-) diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index 140656bc16..1281b12a53 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -2415,7 +2415,7 @@ void Application::cameraMenuChanged() { } } -void Application::clearCacheAndRestart() { +void Application::reloadResourceCaches() { emptyLocalCache(); DependencyManager::get()->refreshAll(); diff --git a/interface/src/Application.h b/interface/src/Application.h index a4c584da50..21d5d72a54 100644 --- a/interface/src/Application.h +++ b/interface/src/Application.h @@ -454,7 +454,7 @@ public slots: void cameraMenuChanged(); - void clearCacheAndRestart(); + void reloadResourceCaches(); private slots: void clearDomainOctreeDetails(); diff --git a/interface/src/Menu.cpp b/interface/src/Menu.cpp index 7808840232..ee9f7491ac 100644 --- a/interface/src/Menu.cpp +++ b/interface/src/Menu.cpp @@ -127,7 +127,6 @@ Menu::Menu() { addActionToQMenuAndActionHash(fileMenu, MenuOption::CopyPath, 0, addressManager.data(), SLOT(copyPath())); - addActionToQMenuAndActionHash(fileMenu, MenuOption::ClearCacheAndRestart, 0, qApp, SLOT(clearCacheAndRestart())); addActionToQMenuAndActionHash(fileMenu, MenuOption::Quit, Qt::CTRL | Qt::Key_Q, @@ -257,6 +256,8 @@ Menu::Menu() { avatar, SLOT(updateMotionBehavior())); MenuWrapper* viewMenu = addMenu("View"); + + addActionToQMenuAndActionHash(viewMenu, MenuOption::ReloadContent, 0, qApp, SLOT(reloadResourceCaches())); addCheckableActionToQMenuAndActionHash(viewMenu, MenuOption::Fullscreen, diff --git a/interface/src/Menu.h b/interface/src/Menu.h index aa8e3f7a2a..9387a97c69 100644 --- a/interface/src/Menu.h +++ b/interface/src/Menu.h @@ -160,7 +160,6 @@ namespace MenuOption { const QString CalibrateCamera = "Calibrate Camera"; const QString CenterPlayerInView = "Center Player In View"; const QString Chat = "Chat..."; - const QString ClearCacheAndRestart = "Clear Cache and Restart"; const QString Collisions = "Collisions"; const QString Console = "Console..."; const QString ControlWithSpeech = "Control With Speech"; @@ -231,6 +230,7 @@ namespace MenuOption { const QString Preferences = "Preferences..."; const QString Quit = "Quit"; const QString ReloadAllScripts = "Reload All Scripts"; + const QString ReloadContent = "Reload Content (Clears all caches)"; const QString RenderBoundingCollisionShapes = "Show Bounding Collision Shapes"; const QString RenderFocusIndicator = "Show Eye Focus"; const QString RenderHeadCollisionShapes = "Show Head Collision Shapes"; diff --git a/libraries/model/src/model/Skybox.cpp b/libraries/model/src/model/Skybox.cpp index a02c646668..5be3412c6c 100755 --- a/libraries/model/src/model/Skybox.cpp +++ b/libraries/model/src/model/Skybox.cpp @@ -101,7 +101,7 @@ void Skybox::render(gpu::Batch& batch, const ViewFrustum& viewFrustum, const Sky batch.setModelTransform(Transform()); // only for Mac batch.setPipeline(thePipeline); batch.setInputBuffer(gpu::Stream::POSITION, theBuffer, 0, 8); - batch.setUniformBuffer(SKYBOX_CONSTANTS_SLOT, theConstants, 0, theConstants->getSize()); + //batch.setUniformBuffer(SKYBOX_CONSTANTS_SLOT, theConstants, 0, theConstants->getSize()); batch.setInputFormat(theFormat); batch.setUniformTexture(0, skybox.getCubemap()); batch.draw(gpu::TRIANGLE_STRIP, 4); From 8ecefdfe392931be3cab7fdbebf1ae0239a3d816 Mon Sep 17 00:00:00 2001 From: David Rowe Date: Fri, 10 Jul 2015 16:03:27 -0700 Subject: [PATCH 10/28] If an external texture isn't found, still display the model If the texture is present the next Interface is run then it will be used. --- .../src/RenderableModelEntityItem.cpp | 12 +++---- libraries/render-utils/src/Model.cpp | 33 +++++++++---------- libraries/render-utils/src/Model.h | 3 +- libraries/render-utils/src/TextureCache.cpp | 20 +++++++++-- libraries/render-utils/src/TextureCache.h | 8 +++++ 5 files changed, 49 insertions(+), 27 deletions(-) diff --git a/libraries/entities-renderer/src/RenderableModelEntityItem.cpp b/libraries/entities-renderer/src/RenderableModelEntityItem.cpp index 85b7bafc78..791b1de469 100644 --- a/libraries/entities-renderer/src/RenderableModelEntityItem.cpp +++ b/libraries/entities-renderer/src/RenderableModelEntityItem.cpp @@ -63,11 +63,11 @@ void RenderableModelEntityItem::remapTextures() { return; // nothing to do if we don't have a model } - if (!_model->isLoadedWithTextures()) { - return; // nothing to do if the model has not yet loaded its default textures + if (!_model->isLoaded()) { + return; // nothing to do if the model has not yet loaded } - if (!_originalTexturesRead && _model->isLoadedWithTextures()) { + if (!_originalTexturesRead) { const QSharedPointer& networkGeometry = _model->getGeometry(); if (networkGeometry) { _originalTextures = networkGeometry->getTextureNames(); @@ -119,7 +119,7 @@ bool RenderableModelEntityItem::readyToAddToScene(RenderArgs* renderArgs) { EntityTreeRenderer* renderer = static_cast(renderArgs->_renderer); getModel(renderer); } - if (renderArgs && _model && _needsInitialSimulation && _model->isActive() && _model->isLoadedWithTextures()) { + if (renderArgs && _model && _needsInitialSimulation && _model->isActive() && _model->isLoaded()) { _model->setScaleToFit(true, getDimensions()); _model->setSnapModelToRegistrationPoint(true, getRegistrationPoint()); _model->setRotation(getRotation()); @@ -397,8 +397,8 @@ bool RenderableModelEntityItem::isReadyToComputeShape() { const QSharedPointer collisionNetworkGeometry = _model->getCollisionGeometry(); const QSharedPointer renderNetworkGeometry = _model->getGeometry(); - if ((! collisionNetworkGeometry.isNull() && collisionNetworkGeometry->isLoadedWithTextures()) && - (! renderNetworkGeometry.isNull() && renderNetworkGeometry->isLoadedWithTextures())) { + if ((! collisionNetworkGeometry.isNull() && collisionNetworkGeometry->isLoaded()) && + (! renderNetworkGeometry.isNull() && renderNetworkGeometry->isLoaded())) { // we have both URLs AND both geometries AND they are both fully loaded. return true; } diff --git a/libraries/render-utils/src/Model.cpp b/libraries/render-utils/src/Model.cpp index 03140c4dfb..edc74eac2f 100644 --- a/libraries/render-utils/src/Model.cpp +++ b/libraries/render-utils/src/Model.cpp @@ -824,7 +824,7 @@ void Model::renderSetup(RenderArgs* args) { } } - if (!_meshGroupsKnown && isLoadedWithTextures()) { + if (!_meshGroupsKnown && isLoaded()) { segregateMeshGroups(); } } @@ -883,7 +883,7 @@ void Model::setVisibleInScene(bool newValue, std::shared_ptr scen bool Model::addToScene(std::shared_ptr scene, render::PendingChanges& pendingChanges) { - if (!_meshGroupsKnown && isLoadedWithTextures()) { + if (!_meshGroupsKnown && isLoaded()) { segregateMeshGroups(); } @@ -913,7 +913,7 @@ bool Model::addToScene(std::shared_ptr scene, render::PendingChan } bool Model::addToScene(std::shared_ptr scene, render::PendingChanges& pendingChanges, render::Item::Status::Getters& statusGetters) { - if (!_meshGroupsKnown && isLoadedWithTextures()) { + if (!_meshGroupsKnown && isLoaded()) { segregateMeshGroups(); } @@ -2029,12 +2029,10 @@ void Model::renderPart(RenderArgs* args, int meshIndex, int partIndex, bool tran } } } - static bool showDiffuse = true; - if (showDiffuse && diffuseMap) { + if (diffuseMap && static_cast(diffuseMap)->isLoaded()) { batch.setUniformTexture(0, diffuseMap->getGPUTexture()); - } else { - batch.setUniformTexture(0, textureCache->getWhiteTexture()); + batch.setUniformTexture(0, textureCache->getGrayTexture()); } if (locations->texcoordMatrices >= 0) { @@ -2049,16 +2047,15 @@ void Model::renderPart(RenderArgs* args, int meshIndex, int partIndex, bool tran } if (!mesh.tangents.isEmpty()) { - Texture* normalMap = networkPart.normalTexture.data(); - batch.setUniformTexture(1, !normalMap ? - textureCache->getBlueTexture() : normalMap->getGPUTexture()); - + NetworkTexture* normalMap = networkPart.normalTexture.data(); + batch.setUniformTexture(1, !normalMap || !normalMap->isLoaded() ? + textureCache->getBlueTexture() : normalMap->getGPUTexture()); } if (locations->specularTextureUnit >= 0) { - Texture* specularMap = networkPart.specularTexture.data(); - batch.setUniformTexture(locations->specularTextureUnit, !specularMap ? - textureCache->getWhiteTexture() : specularMap->getGPUTexture()); + NetworkTexture* specularMap = networkPart.specularTexture.data(); + batch.setUniformTexture(locations->specularTextureUnit, !specularMap || !specularMap->isLoaded() ? + textureCache->getBlackTexture() : specularMap->getGPUTexture()); } if (args) { @@ -2073,9 +2070,9 @@ void Model::renderPart(RenderArgs* args, int meshIndex, int partIndex, bool tran float emissiveScale = part.emissiveParams.y; GLBATCH(glUniform2f)(locations->emissiveParams, emissiveOffset, emissiveScale); - Texture* emissiveMap = networkPart.emissiveTexture.data(); - batch.setUniformTexture(locations->emissiveTextureUnit, !emissiveMap ? - textureCache->getWhiteTexture() : emissiveMap->getGPUTexture()); + NetworkTexture* emissiveMap = networkPart.emissiveTexture.data(); + batch.setUniformTexture(locations->emissiveTextureUnit, !emissiveMap || !emissiveMap->isLoaded() ? + textureCache->getGrayTexture() : emissiveMap->getGPUTexture()); } if (translucent && locations->lightBufferUnit >= 0) { @@ -2188,7 +2185,7 @@ void Model::pickPrograms(gpu::Batch& batch, RenderMode mode, bool translucent, f } bool Model::initWhenReady(render::ScenePointer scene) { - if (isActive() && isRenderable() && !_meshGroupsKnown && isLoadedWithTextures()) { + if (isActive() && isRenderable() && !_meshGroupsKnown && isLoaded()) { segregateMeshGroups(); render::PendingChanges pendingChanges; diff --git a/libraries/render-utils/src/Model.h b/libraries/render-utils/src/Model.h index a6ce566a36..e1fcbcef25 100644 --- a/libraries/render-utils/src/Model.h +++ b/libraries/render-utils/src/Model.h @@ -106,6 +106,7 @@ public: void setVisibleInScene(bool newValue, std::shared_ptr scene); bool isVisible() const { return _isVisible; } + bool isLoaded() const { return _geometry && _geometry->isLoaded(); } bool isLoadedWithTextures() const { return _geometry && _geometry->isLoadedWithTextures(); } void init(); @@ -116,7 +117,7 @@ public: // new Scene/Engine rendering support bool needsFixupInScene() { return !_readyWhenAdded && readyToAddToScene(); } - bool readyToAddToScene(RenderArgs* renderArgs = nullptr) { return !_needsReload && isRenderable() && isActive() && isLoadedWithTextures(); } + bool readyToAddToScene(RenderArgs* renderArgs = nullptr) { return !_needsReload && isRenderable() && isActive() && isLoaded(); } bool addToScene(std::shared_ptr scene, render::PendingChanges& pendingChanges); bool addToScene(std::shared_ptr scene, render::PendingChanges& pendingChanges, render::Item::Status::Getters& statusGetters); void removeFromScene(std::shared_ptr scene, render::PendingChanges& pendingChanges); diff --git a/libraries/render-utils/src/TextureCache.cpp b/libraries/render-utils/src/TextureCache.cpp index 97385cb060..4df9718e24 100644 --- a/libraries/render-utils/src/TextureCache.cpp +++ b/libraries/render-utils/src/TextureCache.cpp @@ -118,9 +118,9 @@ const gpu::TexturePointer& TextureCache::getPermutationNormalTexture() { } const unsigned char OPAQUE_WHITE[] = { 0xFF, 0xFF, 0xFF, 0xFF }; -//const unsigned char TRANSPARENT_WHITE[] = { 0xFF, 0xFF, 0xFF, 0x0 }; -//const unsigned char OPAQUE_BLACK[] = { 0x0, 0x0, 0x0, 0xFF }; +const unsigned char OPAQUE_GRAY[] = { 0x80, 0x80, 0x80, 0xFF }; const unsigned char OPAQUE_BLUE[] = { 0x80, 0x80, 0xFF, 0xFF }; +const unsigned char OPAQUE_BLACK[] = { 0x00, 0x00, 0x00, 0xFF }; /* static void loadSingleColorTexture(const unsigned char* color) { @@ -137,6 +137,14 @@ const gpu::TexturePointer& TextureCache::getWhiteTexture() { return _whiteTexture; } +const gpu::TexturePointer& TextureCache::getGrayTexture() { + if (!_grayTexture) { + _grayTexture = gpu::TexturePointer(gpu::Texture::create2D(gpu::Element(gpu::VEC4, gpu::UINT8, gpu::RGBA), 1, 1)); + _grayTexture->assignStoredMip(0, _whiteTexture->getTexelFormat(), sizeof(OPAQUE_WHITE), OPAQUE_GRAY); + } + return _grayTexture; +} + const gpu::TexturePointer& TextureCache::getBlueTexture() { if (!_blueTexture) { _blueTexture = gpu::TexturePointer(gpu::Texture::create2D(gpu::Element(gpu::VEC4, gpu::UINT8, gpu::RGBA), 1, 1)); @@ -145,6 +153,14 @@ const gpu::TexturePointer& TextureCache::getBlueTexture() { return _blueTexture; } +const gpu::TexturePointer& TextureCache::getBlackTexture() { + if (!_blackTexture) { + _blackTexture = gpu::TexturePointer(gpu::Texture::create2D(gpu::Element(gpu::VEC4, gpu::UINT8, gpu::RGBA), 1, 1)); + _blackTexture->assignStoredMip(0, _whiteTexture->getTexelFormat(), sizeof(OPAQUE_BLACK), OPAQUE_BLACK); + } + return _blackTexture; +} + /// Extra data for creating textures. class TextureExtra { public: diff --git a/libraries/render-utils/src/TextureCache.h b/libraries/render-utils/src/TextureCache.h index ba7176b2a4..fc02438c84 100644 --- a/libraries/render-utils/src/TextureCache.h +++ b/libraries/render-utils/src/TextureCache.h @@ -52,9 +52,15 @@ public: /// Returns an opaque white texture (useful for a default). const gpu::TexturePointer& getWhiteTexture(); + /// Returns an opaque gray texture (useful for a default). + const gpu::TexturePointer& getGrayTexture(); + /// Returns the a pale blue texture (useful for a normal map). const gpu::TexturePointer& getBlueTexture(); + /// Returns the a black texture (useful for a default). + const gpu::TexturePointer& getBlackTexture(); + /// Returns a texture version of an image file static gpu::TexturePointer getImageTexture(const QString& path); @@ -112,7 +118,9 @@ private: gpu::TexturePointer _permutationNormalTexture; gpu::TexturePointer _whiteTexture; + gpu::TexturePointer _grayTexture; gpu::TexturePointer _blueTexture; + gpu::TexturePointer _blackTexture; QHash > _dilatableNetworkTextures; From 51be24515974e60fe4625c979d3644981d5383c0 Mon Sep 17 00:00:00 2001 From: Howard Stearns Date: Fri, 10 Jul 2015 16:55:45 -0700 Subject: [PATCH 11/28] Remove old octreeFade code that wasn't working anyway. --- interface/src/Application.cpp | 38 ---------------- interface/src/Application.h | 10 ----- interface/src/Menu.cpp | 1 - interface/src/Menu.h | 1 - interface/src/octree/OctreeFade.cpp | 68 ----------------------------- interface/src/octree/OctreeFade.h | 46 ------------------- tests/ui/src/main.cpp | 2 +- 7 files changed, 1 insertion(+), 165 deletions(-) delete mode 100644 interface/src/octree/OctreeFade.cpp delete mode 100644 interface/src/octree/OctreeFade.h diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index 00a4440920..aa978f3464 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -3572,23 +3572,6 @@ void Application::displaySide(RenderArgs* renderArgs, Camera& theCamera, bool se if (!selfAvatarOnly) { _nodeBoundsDisplay.draw(); - // render octree fades if they exist - if (_octreeFades.size() > 0) { - PerformanceTimer perfTimer("octreeFades"); - PerformanceWarning warn(Menu::getInstance()->isOptionChecked(MenuOption::PipelineWarnings), - "Application::displaySide() ... octree fades..."); - _octreeFadesLock.lockForWrite(); - for(std::vector::iterator fade = _octreeFades.begin(); fade != _octreeFades.end();) { - fade->render(renderArgs); - if(fade->isDone()) { - fade = _octreeFades.erase(fade); - } else { - ++fade; - } - } - _octreeFadesLock.unlock(); - } - // give external parties a change to hook in { PerformanceTimer perfTimer("inWorldInterface"); @@ -3880,17 +3863,6 @@ void Application::nodeKilled(SharedNodePointer node) { qCDebug(interfaceapp, "model server going away...... v[%f, %f, %f, %f]", (double)rootDetails.x, (double)rootDetails.y, (double)rootDetails.z, (double)rootDetails.s); - // Add the jurisditionDetails object to the list of "fade outs" - if (!Menu::getInstance()->isOptionChecked(MenuOption::DontFadeOnOctreeServerChanges)) { - OctreeFade fade(OctreeFade::FADE_OUT, NODE_KILLED_RED, NODE_KILLED_GREEN, NODE_KILLED_BLUE); - fade.voxelDetails = rootDetails; - const float slightly_smaller = 0.99f; - fade.voxelDetails.s = fade.voxelDetails.s * slightly_smaller; - _octreeFadesLock.lockForWrite(); - _octreeFades.push_back(fade); - _octreeFadesLock.unlock(); - } - // If the model server is going away, remove it from our jurisdiction map so we don't send voxels to a dead server _entityServerJurisdictions.lockForWrite(); _entityServerJurisdictions.erase(_entityServerJurisdictions.find(nodeUUID)); @@ -3967,16 +3939,6 @@ int Application::parseOctreeStats(const QByteArray& packet, const SharedNodePoin qPrintable(serverType), (double)rootDetails.x, (double)rootDetails.y, (double)rootDetails.z, (double)rootDetails.s); - // Add the jurisditionDetails object to the list of "fade outs" - if (!Menu::getInstance()->isOptionChecked(MenuOption::DontFadeOnOctreeServerChanges)) { - OctreeFade fade(OctreeFade::FADE_OUT, NODE_ADDED_RED, NODE_ADDED_GREEN, NODE_ADDED_BLUE); - fade.voxelDetails = rootDetails; - const float slightly_smaller = 0.99f; - fade.voxelDetails.s = fade.voxelDetails.s * slightly_smaller; - _octreeFadesLock.lockForWrite(); - _octreeFades.push_back(fade); - _octreeFadesLock.unlock(); - } } else { jurisdiction->unlock(); } diff --git a/interface/src/Application.h b/interface/src/Application.h index 8dd987fbcd..b621b3e1f2 100644 --- a/interface/src/Application.h +++ b/interface/src/Application.h @@ -72,7 +72,6 @@ #include "ui/ToolWindow.h" #include "ui/UserInputMapper.h" #include "devices/KeyboardMouseDevice.h" -#include "octree/OctreeFade.h" #include "octree/OctreePacketProcessor.h" #include "UndoStackScriptingInterface.h" @@ -91,13 +90,6 @@ class Node; class ProgramObject; class ScriptEngine; -static const float NODE_ADDED_RED = 0.0f; -static const float NODE_ADDED_GREEN = 1.0f; -static const float NODE_ADDED_BLUE = 0.0f; -static const float NODE_KILLED_RED = 1.0f; -static const float NODE_KILLED_GREEN = 0.0f; -static const float NODE_KILLED_BLUE = 0.0f; - static const QString SNAPSHOT_EXTENSION = ".jpg"; static const QString SVO_EXTENSION = ".svo"; static const QString SVO_JSON_EXTENSION = ".svo.json"; @@ -627,8 +619,6 @@ private: NodeBounds _nodeBoundsDisplay; - std::vector _octreeFades; - QReadWriteLock _octreeFadesLock; ControllerScriptingInterface _controllerScriptingInterface; QPointer _logDialog; QPointer _snapshotShareDialog; diff --git a/interface/src/Menu.cpp b/interface/src/Menu.cpp index 9f49361f79..c583d40d2c 100644 --- a/interface/src/Menu.cpp +++ b/interface/src/Menu.cpp @@ -340,7 +340,6 @@ Menu::Menu() { 0, // QML Qt::SHIFT | Qt::Key_A, true); addCheckableActionToQMenuAndActionHash(renderOptionsMenu, MenuOption::AmbientOcclusion); - addCheckableActionToQMenuAndActionHash(renderOptionsMenu, MenuOption::DontFadeOnOctreeServerChanges); MenuWrapper* ambientLightMenu = renderOptionsMenu->addMenu(MenuOption::RenderAmbientLight); QActionGroup* ambientLightGroup = new QActionGroup(ambientLightMenu); diff --git a/interface/src/Menu.h b/interface/src/Menu.h index 043bb53a7f..f7c00c72ff 100644 --- a/interface/src/Menu.h +++ b/interface/src/Menu.h @@ -179,7 +179,6 @@ namespace MenuOption { const QString DisplayModelElementProxy = "Display Model Element Bounds"; const QString DisplayDebugTimingDetails = "Display Timing Details"; const QString DontDoPrecisionPicking = "Don't Do Precision Picking"; - const QString DontFadeOnOctreeServerChanges = "Don't Fade In/Out on Octree Server Changes"; const QString DontRenderEntitiesAsScene = "Don't Render Entities as Scene"; const QString EchoLocalAudio = "Echo Local Audio"; const QString EchoServerAudio = "Echo Server Audio"; diff --git a/interface/src/octree/OctreeFade.cpp b/interface/src/octree/OctreeFade.cpp deleted file mode 100644 index 881f3c5938..0000000000 --- a/interface/src/octree/OctreeFade.cpp +++ /dev/null @@ -1,68 +0,0 @@ -// -// OctreeFade.cpp -// interface/src/octree -// -// Created by Brad Hefta-Gaub on 8/6/13. -// Copyright 2013 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 "InterfaceConfig.h" - -#include -#include -#include - -#include "Application.h" -#include "OctreeFade.h" - -const float OctreeFade::FADE_OUT_START = 0.5f; -const float OctreeFade::FADE_OUT_END = 0.05f; -const float OctreeFade::FADE_OUT_STEP = 0.9f; -const float OctreeFade::FADE_IN_START = 0.05f; -const float OctreeFade::FADE_IN_END = 0.5f; -const float OctreeFade::FADE_IN_STEP = 1.1f; -const float OctreeFade::DEFAULT_RED = 0.5f; -const float OctreeFade::DEFAULT_GREEN = 0.5f; -const float OctreeFade::DEFAULT_BLUE = 0.5f; - -OctreeFade::OctreeFade(FadeDirection direction, float red, float green, float blue) : - direction(direction), - red(red), - green(green), - blue(blue) -{ - opacity = (direction == FADE_OUT) ? FADE_OUT_START : FADE_IN_START; -} - -void OctreeFade::render(RenderArgs* renderArgs) { - DependencyManager::get()->begin(renderArgs); - - glDisable(GL_LIGHTING); - glPushMatrix(); - glScalef(1.0f, 1.0f, 1.0f); - glTranslatef(voxelDetails.x + voxelDetails.s * 0.5f, - voxelDetails.y + voxelDetails.s * 0.5f, - voxelDetails.z + voxelDetails.s * 0.5f); - glLineWidth(1.0f); - DependencyManager::get()->renderSolidCube(voxelDetails.s, glm::vec4(red, green, blue, opacity)); - glLineWidth(1.0f); - glPopMatrix(); - glEnable(GL_LIGHTING); - - - DependencyManager::get()->end(renderArgs); - - opacity *= (direction == FADE_OUT) ? FADE_OUT_STEP : FADE_IN_STEP; -} - -bool OctreeFade::isDone() const { - if (direction == FADE_OUT) { - return opacity <= FADE_OUT_END; - } else { - return opacity >= FADE_IN_END; - } - return true; // unexpected case, assume we're done -} diff --git a/interface/src/octree/OctreeFade.h b/interface/src/octree/OctreeFade.h deleted file mode 100644 index 137a505537..0000000000 --- a/interface/src/octree/OctreeFade.h +++ /dev/null @@ -1,46 +0,0 @@ -// -// OctreeFade.h -// interface/src/octree -// -// Created by Brad Hefta-Gaub on 8/6/13. -// Copyright 2013 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_OctreeFade_h -#define hifi_OctreeFade_h - -#include // for VoxelPositionSize - -class OctreeFade { -public: - - enum FadeDirection { FADE_OUT, FADE_IN}; - static const float FADE_OUT_START; - static const float FADE_OUT_END; - static const float FADE_OUT_STEP; - static const float FADE_IN_START; - static const float FADE_IN_END; - static const float FADE_IN_STEP; - static const float DEFAULT_RED; - static const float DEFAULT_GREEN; - static const float DEFAULT_BLUE; - - VoxelPositionSize voxelDetails; - FadeDirection direction; - float opacity; - - float red; - float green; - float blue; - - OctreeFade(FadeDirection direction = FADE_OUT, float red = DEFAULT_RED, - float green = DEFAULT_GREEN, float blue = DEFAULT_BLUE); - - void render(RenderArgs* renderArgs); - bool isDone() const; -}; - -#endif // hifi_OctreeFade_h diff --git a/tests/ui/src/main.cpp b/tests/ui/src/main.cpp index 19070e9699..07ff40d738 100644 --- a/tests/ui/src/main.cpp +++ b/tests/ui/src/main.cpp @@ -125,7 +125,7 @@ public: DisplayModelElementProxy, DisplayDebugTimingDetails, DontDoPrecisionPicking, - DontFadeOnOctreeServerChanges, + RESERVED_DontFadeOnOctreeServerChanges, DontRenderEntitiesAsScene, EchoLocalAudio, EchoServerAudio, From 29333d0cad6a864423cd66e0664759769957deca Mon Sep 17 00:00:00 2001 From: Brad Davis Date: Sun, 12 Jul 2015 18:52:15 -0700 Subject: [PATCH 12/28] Qt5.5 fixes --- libraries/avatars/src/AvatarHashMap.cpp | 2 ++ libraries/networking/src/DataServerAccountInfo.cpp | 1 + libraries/networking/src/DomainHandler.cpp | 1 + libraries/networking/src/JSONBreakableMarshal.h | 1 + libraries/networking/src/NetworkPeer.cpp | 1 + libraries/ui/src/VrMenu.cpp | 8 ++++---- 6 files changed, 10 insertions(+), 4 deletions(-) diff --git a/libraries/avatars/src/AvatarHashMap.cpp b/libraries/avatars/src/AvatarHashMap.cpp index 6d0d9d8d76..bf7a1a4464 100644 --- a/libraries/avatars/src/AvatarHashMap.cpp +++ b/libraries/avatars/src/AvatarHashMap.cpp @@ -9,6 +9,8 @@ // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // +#include + #include #include #include diff --git a/libraries/networking/src/DataServerAccountInfo.cpp b/libraries/networking/src/DataServerAccountInfo.cpp index fd2c6da13d..a85aa588a8 100644 --- a/libraries/networking/src/DataServerAccountInfo.cpp +++ b/libraries/networking/src/DataServerAccountInfo.cpp @@ -13,6 +13,7 @@ #include #include +#include #include "NetworkLogging.h" #include "DataServerAccountInfo.h" diff --git a/libraries/networking/src/DomainHandler.cpp b/libraries/networking/src/DomainHandler.cpp index 38d1ade2ad..5f21708d28 100644 --- a/libraries/networking/src/DomainHandler.cpp +++ b/libraries/networking/src/DomainHandler.cpp @@ -12,6 +12,7 @@ #include #include +#include #include "Assignment.h" #include "HifiSockAddr.h" diff --git a/libraries/networking/src/JSONBreakableMarshal.h b/libraries/networking/src/JSONBreakableMarshal.h index cbcc454f5a..287fed675a 100644 --- a/libraries/networking/src/JSONBreakableMarshal.h +++ b/libraries/networking/src/JSONBreakableMarshal.h @@ -17,6 +17,7 @@ #include #include #include +#include class JSONBreakableMarshal { public: diff --git a/libraries/networking/src/NetworkPeer.cpp b/libraries/networking/src/NetworkPeer.cpp index dfa4066dd2..2e98c096ab 100644 --- a/libraries/networking/src/NetworkPeer.cpp +++ b/libraries/networking/src/NetworkPeer.cpp @@ -13,6 +13,7 @@ #include #include +#include #include #include diff --git a/libraries/ui/src/VrMenu.cpp b/libraries/ui/src/VrMenu.cpp index 1b402ff2a3..4c83e6e3cd 100644 --- a/libraries/ui/src/VrMenu.cpp +++ b/libraries/ui/src/VrMenu.cpp @@ -102,13 +102,15 @@ class QQuickMenuItem; QObject* addItem(QObject* parent, const QString& text) { // FIXME add more checking here to ensure no name conflicts QQuickMenuItem* returnedValue{ nullptr }; - #ifndef QT_NO_DEBUG bool invokeResult = - #endif QMetaObject::invokeMethod(parent, "addItem", Qt::DirectConnection, Q_RETURN_ARG(QQuickMenuItem*, returnedValue), Q_ARG(QString, text)); +#ifndef QT_NO_DEBUG Q_ASSERT(invokeResult); +#else + Q_UNUSED(invokeResult); +#endif QObject* result = reinterpret_cast(returnedValue); return result; } @@ -206,9 +208,7 @@ void VrMenu::insertAction(QAction* before, QAction* action) { result = ::addItem(menu, action->text()); } else { QQuickMenuItem* returnedValue{ nullptr }; - #ifndef QT_NO_DEBUG bool invokeResult = - #endif QMetaObject::invokeMethod(menu, "insertItem", Qt::DirectConnection, Q_RETURN_ARG(QQuickMenuItem*, returnedValue), Q_ARG(int, index), Q_ARG(QString, action->text())); Q_ASSERT(invokeResult); From 2bab7d1c037845c87dbc18b521d546bf361a175a Mon Sep 17 00:00:00 2001 From: David Rowe Date: Mon, 13 Jul 2015 16:38:51 -0700 Subject: [PATCH 13/28] Add parentheses --- libraries/render-utils/src/Model.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/libraries/render-utils/src/Model.cpp b/libraries/render-utils/src/Model.cpp index 00d1d89fab..4d1a37fe61 100644 --- a/libraries/render-utils/src/Model.cpp +++ b/libraries/render-utils/src/Model.cpp @@ -2048,13 +2048,13 @@ void Model::renderPart(RenderArgs* args, int meshIndex, int partIndex, bool tran if (!mesh.tangents.isEmpty()) { NetworkTexture* normalMap = networkPart.normalTexture.data(); - batch.setResourceTexture(1, !normalMap || !normalMap->isLoaded() ? + batch.setResourceTexture(1, (!normalMap || !normalMap->isLoaded()) ? textureCache->getBlueTexture() : normalMap->getGPUTexture()); } if (locations->specularTextureUnit >= 0) { NetworkTexture* specularMap = networkPart.specularTexture.data(); - batch.setResourceTexture(locations->specularTextureUnit, !specularMap || !specularMap->isLoaded() ? + batch.setResourceTexture(locations->specularTextureUnit, (!specularMap || !specularMap->isLoaded()) ? textureCache->getBlackTexture() : specularMap->getGPUTexture()); } @@ -2071,7 +2071,7 @@ void Model::renderPart(RenderArgs* args, int meshIndex, int partIndex, bool tran GLBATCH(glUniform2f)(locations->emissiveParams, emissiveOffset, emissiveScale); NetworkTexture* emissiveMap = networkPart.emissiveTexture.data(); - batch.setResourceTexture(locations->emissiveTextureUnit, !emissiveMap || !emissiveMap->isLoaded() ? + batch.setResourceTexture(locations->emissiveTextureUnit, (!emissiveMap || !emissiveMap->isLoaded()) ? textureCache->getGrayTexture() : emissiveMap->getGPUTexture()); } From 7610fe48c228d092b1a14e5ae1ea6e9057244b80 Mon Sep 17 00:00:00 2001 From: Andrew Meadows Date: Tue, 14 Jul 2015 09:21:42 -0700 Subject: [PATCH 14/28] filter action updates during simulation ownership This fixes a bug where actions can be thrashed (created/deleted) by late entity update echos from the entity-server. --- libraries/entities/src/EntityItem.cpp | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/libraries/entities/src/EntityItem.cpp b/libraries/entities/src/EntityItem.cpp index 7354628390..50b36ec6e2 100644 --- a/libraries/entities/src/EntityItem.cpp +++ b/libraries/entities/src/EntityItem.cpp @@ -610,6 +610,9 @@ int EntityItem::readEntityDataFromBuffer(const unsigned char* data, int bytesLef int bytesRead = parser.offset(); #endif + auto nodeList = DependencyManager::get(); + const QUuid& myNodeID = nodeList->getSessionUUID(); + bool weOwnSimulation = _simulationOwner.matchesValidID(myNodeID); if (args.bitstreamVersion >= VERSION_ENTITIES_HAVE_SIMULATION_OWNER_AND_ACTIONS_OVER_WIRE) { // pack SimulationOwner and terse update properties near each other @@ -632,10 +635,8 @@ int EntityItem::readEntityDataFromBuffer(const unsigned char* data, int bytesLef } { // When we own the simulation we don't accept updates to the entity's transform/velocities // but since we're using macros below we have to temporarily modify overwriteLocalData. - auto nodeList = DependencyManager::get(); - bool weOwnIt = _simulationOwner.matchesValidID(nodeList->getSessionUUID()); bool oldOverwrite = overwriteLocalData; - overwriteLocalData = overwriteLocalData && !weOwnIt; + overwriteLocalData = overwriteLocalData && !weOwnSimulation; READ_ENTITY_PROPERTY(PROP_POSITION, glm::vec3, updatePosition); READ_ENTITY_PROPERTY(PROP_ROTATION, glm::quat, updateRotation); READ_ENTITY_PROPERTY(PROP_VELOCITY, glm::vec3, updateVelocity); @@ -657,6 +658,7 @@ int EntityItem::readEntityDataFromBuffer(const unsigned char* data, int bytesLef READ_ENTITY_PROPERTY(PROP_REGISTRATION_POINT, glm::vec3, setRegistrationPoint); } else { // legacy order of packing here + // TODO: purge this logic in a few months from now (2015.07) READ_ENTITY_PROPERTY(PROP_POSITION, glm::vec3, updatePosition); READ_ENTITY_PROPERTY(PROP_DIMENSIONS, glm::vec3, updateDimensions); READ_ENTITY_PROPERTY(PROP_ROTATION, glm::quat, updateRotation); @@ -702,7 +704,16 @@ int EntityItem::readEntityDataFromBuffer(const unsigned char* data, int bytesLef READ_ENTITY_PROPERTY(PROP_HREF, QString, setHref); READ_ENTITY_PROPERTY(PROP_DESCRIPTION, QString, setDescription); - READ_ENTITY_PROPERTY(PROP_ACTION_DATA, QByteArray, setActionData); + { // When we own the simulation we don't accept updates to the entity's actions + // but since we're using macros below we have to temporarily modify overwriteLocalData. + // NOTE: this prevents userB from adding an action to an object1 when UserA + // has simulation ownership of it. + // TODO: figure out how to allow multiple users to update actions simultaneously + bool oldOverwrite = overwriteLocalData; + overwriteLocalData = overwriteLocalData && !weOwnSimulation; + READ_ENTITY_PROPERTY(PROP_ACTION_DATA, QByteArray, setActionData); + overwriteLocalData = oldOverwrite; + } bytesRead += readEntitySubclassDataFromBuffer(dataAt, (bytesLeftToRead - bytesRead), args, propertyFlags, overwriteLocalData); @@ -713,7 +724,7 @@ int EntityItem::readEntityDataFromBuffer(const unsigned char* data, int bytesLef // NOTE: we had a bad version of the stream that we added stream data after the subclass. We can attempt to recover // by doing this parsing here... but it's not likely going to fully recover the content. // - // TODO: Remove this conde once we've sufficiently migrated content past this damaged version + // TODO: Remove this code once we've sufficiently migrated content past this damaged version if (args.bitstreamVersion == VERSION_ENTITIES_HAS_MARKETPLACE_ID_DAMAGED) { READ_ENTITY_PROPERTY(PROP_MARKETPLACE_ID, QString, setMarketplaceID); } @@ -738,8 +749,6 @@ int EntityItem::readEntityDataFromBuffer(const unsigned char* data, int bytesLef } } - auto nodeList = DependencyManager::get(); - const QUuid& myNodeID = nodeList->getSessionUUID(); if (overwriteLocalData) { if (!_simulationOwner.matchesValidID(myNodeID)) { From 69db9aa01ac18f1330396f9b4fd8d7f8d847fc78 Mon Sep 17 00:00:00 2001 From: Andrew Meadows Date: Tue, 14 Jul 2015 09:23:05 -0700 Subject: [PATCH 15/28] fix grab transitions between vert and horiz planes --- examples/grab.js | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/examples/grab.js b/examples/grab.js index f64aaa30ee..13c91bebb8 100644 --- a/examples/grab.js +++ b/examples/grab.js @@ -43,9 +43,10 @@ var gMaxGrabDistance; // elevationAzimuth var gGrabMode = "xzplane"; -// gGrabOffset allows the user to grab an object off-center. It points from ray's intersection -// with the move-plane to object center (at the moment the grab is initiated). Future target positions -// are relative to the ray's intersection by the same offset. +// gGrabOffset allows the user to grab an object off-center. It points from the object's center +// to the point where the ray intersects the grab plane (at the moment the grab is initiated). +// Future target positions of the ray intersection are on the same plane, and the offset is subtracted +// to compute the target position of the object's center. var gGrabOffset = { x: 0, y: 0, z: 0 }; var gTargetPosition; @@ -152,7 +153,6 @@ function computeNewGrabPlane() { maybeResetMousePosition = true; } gGrabMode = "xzPlane"; - gPointOnPlane = gCurrentPosition; gPlaneNormal = { x: 0, y: 1, z: 0 }; if (gLiftKey) { if (!gRotateKey) { @@ -163,7 +163,7 @@ function computeNewGrabPlane() { gGrabMode = "rotate"; } - gPointOnPlane = Vec3.subtract(gCurrentPosition, gGrabOffset); + gPointOnPlane = Vec3.sum(gCurrentPosition, gGrabOffset); var xzOffset = Vec3.subtract(gPointOnPlane, Camera.getPosition()); xzOffset.y = 0; gXzDistanceToGrab = Vec3.length(xzOffset); @@ -220,8 +220,8 @@ function mousePressEvent(event) { nearestPoint = Vec3.multiply(distanceToGrab, pickRay.direction); gPointOnPlane = Vec3.sum(cameraPosition, nearestPoint); - // compute the grab offset - gGrabOffset = Vec3.subtract(gStartPosition, gPointOnPlane); + // compute the grab offset (points from object center to point of grab) + gGrabOffset = Vec3.subtract(gPointOnPlane, gStartPosition); computeNewGrabPlane(); @@ -258,6 +258,7 @@ function mouseMoveEvent(event) { if (Vec3.length(entityProperties.gravity) != 0) { gOriginalGravity = entityProperties.gravity; } + gCurrentPosition = entityProperties.position; var actionArgs = {}; @@ -287,6 +288,7 @@ function mouseMoveEvent(event) { var pointOnCylinder = Vec3.multiply(planeNormal, gXzDistanceToGrab); pointOnCylinder = Vec3.sum(Camera.getPosition(), pointOnCylinder); newTargetPosition = mouseIntersectionWithPlane(pointOnCylinder, planeNormal, event); + gPointOnPlane = Vec3.sum(newTargetPosition, gGrabOffset); } else { var cameraPosition = Camera.getPosition(); newTargetPosition = mouseIntersectionWithPlane(gPointOnPlane, gPlaneNormal, event); @@ -298,7 +300,7 @@ function mouseMoveEvent(event) { newTargetPosition = Vec3.sum(relativePosition, cameraPosition); } } - gTargetPosition = Vec3.sum(newTargetPosition, gGrabOffset); + gTargetPosition = Vec3.subtract(newTargetPosition, gGrabOffset); actionArgs = {targetPosition: gTargetPosition, linearTimeScale: 0.1}; } gPreviousMouse = { x: event.x, y: event.y }; From c49851cf032d0add4a17fa368bb891f7135a41db Mon Sep 17 00:00:00 2001 From: Howard Stearns Date: Tue, 14 Jul 2015 09:33:08 -0700 Subject: [PATCH 16/28] Update sword script for current controller/physics behavior. --- examples/example/games/sword.js | 30 ++++++++++++++++++++---------- 1 file changed, 20 insertions(+), 10 deletions(-) diff --git a/examples/example/games/sword.js b/examples/example/games/sword.js index 18d6911f0b..178a48f35a 100644 --- a/examples/example/games/sword.js +++ b/examples/example/games/sword.js @@ -175,10 +175,12 @@ function positionStick(stickOrientation) { inHand = false; Entities.updateAction(stickID, actionID, { relativePosition: offset, - relativeRotation: stickOrientation + relativeRotation: stickOrientation, + hand: "right" }); } -function resetToHand() { // Maybe coordinate with positionStick? +function resetToHand() { // For use with controllers, puts the sword in contact with the hand. + // Maybe coordinate with positionStick? if (inHand) { // Optimization: bail if we're already inHand. return; } @@ -191,14 +193,14 @@ function resetToHand() { // Maybe coordinate with positionStick? }); inHand = true; } +function isControllerActive() { + // I don't think the hydra API provides any reliable way to know whether a particular controller is active. Ask for both. + controllerActive = (Vec3.length(Controller.getSpatialControlPosition(3)) > 0) || Vec3.length(Controller.getSpatialControlPosition(4)) > 0; + return controllerActive; +} function mouseMoveEvent(event) { - if (event.deviceID) { // Not a MOUSE mouse event, but a (e.g., hydra) mouse event, with x/y that is not meaningful for us. - resetToHand(); // Can only happen when controller is uncradled, so let's drive with that, resetting our attachement. - return; - } - controllerActive = (Vec3.length(Controller.getSpatialControlPosition(controllerID)) > 0); - //print("Mouse move with hand controller " + (controllerActive ? "active" : "inactive") + JSON.stringify(event)); - if (controllerActive || !isFighting()) { + // When a controller like the hydra gives a mouse event, the x/y is not meaningful to us, but we can detect with a truty deviceID + if (event.deviceID || !isFighting() || isControllerActive()) { print('Attempting attachment reset'); resetToHand(); return; @@ -244,12 +246,20 @@ function cleanUp(leaveButtons) { } function makeSword() { initControls(); + var swordPosition; + if (!isControllerActive()) { // Dont' knock yourself with sword + swordPosition = Vec3.sum(MyAvatar.position, Vec3.multiply(2, Quat.getFront(MyAvatar.orientation))); + } else if (hand === 'right') { + swordPosition = MyAvatar.getRightPalmPosition(); + } else { + swordPosition = MyAvatar.getLeftPalmPosition(); + } stickID = Entities.addEntity({ type: "Model", modelURL: swordModel, compoundShapeURL: swordCollisionShape, dimensions: dimensions, - position: (hand === 'right') ? MyAvatar.getRightPalmPosition() : MyAvatar.getLeftPalmPosition(), // initial position doesn't matter, as long as it's close + position: swordPosition, rotation: MyAvatar.orientation, damping: 0.1, collisionSoundURL: swordCollisionSoundURL, From 5196648b229e6216e5043f3dbf5eaa50c02b4458 Mon Sep 17 00:00:00 2001 From: Howard Stearns Date: Tue, 14 Jul 2015 09:57:19 -0700 Subject: [PATCH 17/28] Remove obsolete enum member. --- tests/ui/src/main.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/ui/src/main.cpp b/tests/ui/src/main.cpp index 07ff40d738..1b0c7e0ab1 100644 --- a/tests/ui/src/main.cpp +++ b/tests/ui/src/main.cpp @@ -125,7 +125,6 @@ public: DisplayModelElementProxy, DisplayDebugTimingDetails, DontDoPrecisionPicking, - RESERVED_DontFadeOnOctreeServerChanges, DontRenderEntitiesAsScene, EchoLocalAudio, EchoServerAudio, From 1c8ec3b1c9c80bd35dfab0aaf0ebe3f6e0bb2d27 Mon Sep 17 00:00:00 2001 From: Brad Davis Date: Tue, 14 Jul 2015 10:16:06 -0700 Subject: [PATCH 18/28] preventing unused warnings --- libraries/ui/src/VrMenu.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/libraries/ui/src/VrMenu.cpp b/libraries/ui/src/VrMenu.cpp index 4c83e6e3cd..ce4aba83d3 100644 --- a/libraries/ui/src/VrMenu.cpp +++ b/libraries/ui/src/VrMenu.cpp @@ -211,7 +211,11 @@ void VrMenu::insertAction(QAction* before, QAction* action) { bool invokeResult = QMetaObject::invokeMethod(menu, "insertItem", Qt::DirectConnection, Q_RETURN_ARG(QQuickMenuItem*, returnedValue), Q_ARG(int, index), Q_ARG(QString, action->text())); +#ifndef QT_NO_DEBUG Q_ASSERT(invokeResult); +#else + Q_UNUSED(invokeResult); +#endif result = reinterpret_cast(returnedValue); } Q_ASSERT(result); From a32f54da2f04747776d6d7b101d1e89bc9c86d90 Mon Sep 17 00:00:00 2001 From: Atlante45 Date: Tue, 14 Jul 2015 12:36:18 -0700 Subject: [PATCH 19/28] Cleanup --- interface/src/main.cpp | 1 - libraries/model/src/model/Skybox.cpp | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/interface/src/main.cpp b/interface/src/main.cpp index 2347b3b1d6..e591034fb5 100644 --- a/interface/src/main.cpp +++ b/interface/src/main.cpp @@ -11,7 +11,6 @@ #include #include #include -#include #include #include diff --git a/libraries/model/src/model/Skybox.cpp b/libraries/model/src/model/Skybox.cpp index f33891c478..0fb2458f01 100755 --- a/libraries/model/src/model/Skybox.cpp +++ b/libraries/model/src/model/Skybox.cpp @@ -101,7 +101,7 @@ void Skybox::render(gpu::Batch& batch, const ViewFrustum& viewFrustum, const Sky batch.setModelTransform(Transform()); // only for Mac batch.setPipeline(thePipeline); batch.setInputBuffer(gpu::Stream::POSITION, theBuffer, 0, 8); - //batch.setUniformBuffer(SKYBOX_CONSTANTS_SLOT, theConstants, 0, theConstants->getSize()); + batch.setUniformBuffer(SKYBOX_CONSTANTS_SLOT, theConstants, 0, theConstants->getSize()); batch.setInputFormat(theFormat); batch.setResourceTexture(0, skybox.getCubemap()); batch.draw(gpu::TRIANGLE_STRIP, 4); From 3cd1e318b2bd93c18bfbfbe377964594934f1b25 Mon Sep 17 00:00:00 2001 From: Howard Stearns Date: Tue, 14 Jul 2015 13:15:24 -0700 Subject: [PATCH 20/28] Fix https://app.asana.com/0/32622044445063/39927009585710 --- libraries/fbx/src/FSTReader.cpp | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/libraries/fbx/src/FSTReader.cpp b/libraries/fbx/src/FSTReader.cpp index a62c0fcea2..6f5d0d7ec5 100644 --- a/libraries/fbx/src/FSTReader.cpp +++ b/libraries/fbx/src/FSTReader.cpp @@ -93,7 +93,16 @@ QByteArray FSTReader::writeMapping(const QVariantHash& mapping) { for (auto key : PREFERED_ORDER) { auto it = mapping.find(key); if (it != mapping.constEnd()) { - writeVariant(buffer, it); + if (key == FREE_JOINT_FIELD) { // writeVariant does not handle strings added using insertMulti. + for (auto multi : mapping.values(key)) { + buffer.write(key.toUtf8()); + buffer.write(" = "); + buffer.write(multi.toByteArray()); + buffer.write("\n"); + } + } else { + writeVariant(buffer, it); + } } } From bfad3ee02a0a8ebca3519e223f7e1deaed8e79a2 Mon Sep 17 00:00:00 2001 From: David Rowe Date: Tue, 14 Jul 2015 14:07:32 -0700 Subject: [PATCH 21/28] Fix eye directions so that they're correct when avatar leans backwards --- interface/src/avatar/FaceModel.cpp | 12 ++---- libraries/avatars/src/AvatarData.cpp | 45 ++++++++++++++-------- libraries/networking/src/PacketHeaders.cpp | 2 +- 3 files changed, 35 insertions(+), 24 deletions(-) diff --git a/interface/src/avatar/FaceModel.cpp b/interface/src/avatar/FaceModel.cpp index 1501c52de5..170965bb4d 100644 --- a/interface/src/avatar/FaceModel.cpp +++ b/interface/src/avatar/FaceModel.cpp @@ -56,18 +56,14 @@ void FaceModel::maybeUpdateNeckRotation(const JointState& parentState, const FBX glm::translate(state.getDefaultTranslationInConstrainedFrame()) * joint.preTransform * glm::mat4_cast(joint.preRotation))); glm::vec3 pitchYawRoll = safeEulerAngles(_owningHead->getFinalOrientationInLocalFrame()); - if (owningAvatar->isMyAvatar()) { - glm::vec3 lean = glm::radians(glm::vec3(_owningHead->getFinalLeanForward(), - _owningHead->getTorsoTwist(), - _owningHead->getFinalLeanSideways())); - pitchYawRoll -= lean; - } - + glm::vec3 lean = glm::radians(glm::vec3(_owningHead->getFinalLeanForward(), + _owningHead->getTorsoTwist(), + _owningHead->getFinalLeanSideways())); + pitchYawRoll -= lean; state.setRotationInConstrainedFrame(glm::angleAxis(-pitchYawRoll.z, glm::normalize(inverse * axes[2])) * glm::angleAxis(pitchYawRoll.y, glm::normalize(inverse * axes[1])) * glm::angleAxis(-pitchYawRoll.x, glm::normalize(inverse * axes[0])) * joint.rotation, DEFAULT_PRIORITY); - } void FaceModel::maybeUpdateEyeRotation(Model* model, const JointState& parentState, const FBXJoint& joint, JointState& state) { diff --git a/libraries/avatars/src/AvatarData.cpp b/libraries/avatars/src/AvatarData.cpp index 9a6400ae16..a7fdcdeafd 100644 --- a/libraries/avatars/src/AvatarData.cpp +++ b/libraries/avatars/src/AvatarData.cpp @@ -161,19 +161,15 @@ QByteArray AvatarData::toByteArray() { // Body scale destinationBuffer += packFloatRatioToTwoByte(destinationBuffer, _targetScale); - // Head rotation (NOTE: This needs to become a quaternion to save two bytes) - glm::vec3 pitchYawRoll = glm::vec3(_headData->getFinalPitch(), - _headData->getFinalYaw(), - _headData->getFinalRoll()); - if (this->isMyAvatar()) { - glm::vec3 lean = glm::vec3(_headData->getFinalLeanForward(), - _headData->getTorsoTwist(), - _headData->getFinalLeanSideways()); - pitchYawRoll -= lean; - } - destinationBuffer += packFloatAngleToTwoByte(destinationBuffer, pitchYawRoll.x); - destinationBuffer += packFloatAngleToTwoByte(destinationBuffer, pitchYawRoll.y); - destinationBuffer += packFloatAngleToTwoByte(destinationBuffer, pitchYawRoll.z); + // Head rotation + destinationBuffer += packFloatAngleToTwoByte(destinationBuffer, _headData->getFinalPitch()); + destinationBuffer += packFloatAngleToTwoByte(destinationBuffer, _headData->getFinalYaw()); + destinationBuffer += packFloatAngleToTwoByte(destinationBuffer, _headData->getFinalRoll()); + + // Body lean + destinationBuffer += packFloatAngleToTwoByte(destinationBuffer, _headData->_leanForward); + destinationBuffer += packFloatAngleToTwoByte(destinationBuffer, _headData->_leanSideways); + destinationBuffer += packFloatAngleToTwoByte(destinationBuffer, _headData->_torsoTwist); // Lookat Position memcpy(destinationBuffer, &_headData->_lookAtPosition, sizeof(_headData->_lookAtPosition)); @@ -291,13 +287,16 @@ int AvatarData::parseDataAtOffset(const QByteArray& packet, int offset) { // headPitch = 2 (compressed float) // headYaw = 2 (compressed float) // headRoll = 2 (compressed float) + // leanForward = 2 (compressed float) + // leanSideways = 2 (compressed float) + // torsoTwist = 2 (compressed float) // lookAt = 12 // audioLoudness = 4 // } // + 1 byte for pupilSize // + 1 byte for numJoints (0) - // = 45 bytes - int minPossibleSize = 45; + // = 51 bytes + int minPossibleSize = 51; int maxAvailableSize = packet.size() - offset; if (minPossibleSize > maxAvailableSize) { @@ -371,6 +370,22 @@ int AvatarData::parseDataAtOffset(const QByteArray& packet, int offset) { _headData->setBaseYaw(headYaw); _headData->setBaseRoll(headRoll); } // 6 bytes + + { // Head lean (relative to pelvis) + float leanForward, leanSideways, torsoTwist; + sourceBuffer += unpackFloatAngleFromTwoByte((uint16_t*)sourceBuffer, &leanForward); + sourceBuffer += unpackFloatAngleFromTwoByte((uint16_t*)sourceBuffer, &leanSideways); + sourceBuffer += unpackFloatAngleFromTwoByte((uint16_t*)sourceBuffer, &torsoTwist); + if (glm::isnan(leanForward) || glm::isnan(leanSideways)) { + if (shouldLogError(now)) { + qCDebug(avatars) << "Discard nan AvatarData::leanForward,leanSideways,torsoTwise; displayName = '" << _displayName << "'"; + } + return maxAvailableSize; + } + _headData->_leanForward = leanForward; + _headData->_leanSideways = leanSideways; + _headData->_torsoTwist = torsoTwist; + } // 6 bytes { // Lookat Position glm::vec3 lookAt; diff --git a/libraries/networking/src/PacketHeaders.cpp b/libraries/networking/src/PacketHeaders.cpp index 42ee9f3025..74b6aa55f1 100644 --- a/libraries/networking/src/PacketHeaders.cpp +++ b/libraries/networking/src/PacketHeaders.cpp @@ -55,7 +55,7 @@ PacketVersion versionForPacketType(PacketType packetType) { case PacketTypeInjectAudio: return 1; case PacketTypeAvatarData: - return 6; + return 7; case PacketTypeAvatarIdentity: return 1; case PacketTypeEnvironmentData: From 22f0dbdefb4efcb3f37f8f2ac775cbdee9132e67 Mon Sep 17 00:00:00 2001 From: Atlante45 Date: Tue, 14 Jul 2015 15:16:00 -0700 Subject: [PATCH 22/28] CR --- libraries/animation/src/AnimationCache.cpp | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/libraries/animation/src/AnimationCache.cpp b/libraries/animation/src/AnimationCache.cpp index 9eb68cedc2..99224f7dce 100644 --- a/libraries/animation/src/AnimationCache.cpp +++ b/libraries/animation/src/AnimationCache.cpp @@ -38,9 +38,7 @@ QSharedPointer AnimationCache::createResource(const QUrl& url, const Q return QSharedPointer(new Animation(url), &Resource::allReferencesCleared); } -Animation::Animation(const QUrl& url) : - Resource(url) { -} +Animation::Animation(const QUrl& url) : Resource(url) {} class AnimationReader : public QRunnable { public: From 68f4fe6566515cc9440ae8f6ee490648c14ec3b4 Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Tue, 14 Jul 2015 16:03:44 -0700 Subject: [PATCH 23/28] fix lagging touch events --- interface/src/Application.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index aa978f3464..de99940d51 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -1853,7 +1853,7 @@ void Application::idle() { } // After finishing all of the above work, ensure the idle timer is set to the proper interval, // depending on whether we're throttling or not - idleTimer->start(_glWidget->isThrottleRendering() ? THROTTLED_IDLE_TIMER_DELAY : 0); + idleTimer->start(_glWidget->isThrottleRendering() ? THROTTLED_IDLE_TIMER_DELAY : 1); } // check for any requested background downloads. From bc251de43c241fa4555f172aa9c73d36f5bbc761 Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Tue, 14 Jul 2015 16:49:22 -0700 Subject: [PATCH 24/28] delete dead code --- libraries/networking/src/NetworkPacket.cpp | 13 ------------- libraries/networking/src/NetworkPacket.h | 6 ------ libraries/octree/src/JurisdictionMap.cpp | 17 ----------------- libraries/octree/src/JurisdictionMap.h | 6 ------ 4 files changed, 42 deletions(-) diff --git a/libraries/networking/src/NetworkPacket.cpp b/libraries/networking/src/NetworkPacket.cpp index 69bd0962bf..e99ef1ab8b 100644 --- a/libraries/networking/src/NetworkPacket.cpp +++ b/libraries/networking/src/NetworkPacket.cpp @@ -40,16 +40,3 @@ NetworkPacket& NetworkPacket::operator=(NetworkPacket const& other) { copyContents(other.getNode(), other.getByteArray()); return *this; } - -#ifdef HAS_MOVE_SEMANTICS -// move, same as copy, but other packet won't be used further -NetworkPacket::NetworkPacket(NetworkPacket && packet) { - copyContents(packet.getNode(), packet.getByteArray()); -} - -// move assignment -NetworkPacket& NetworkPacket::operator=(NetworkPacket&& other) { - copyContents(other.getNode(), other.getByteArray()); - return *this; -} -#endif diff --git a/libraries/networking/src/NetworkPacket.h b/libraries/networking/src/NetworkPacket.h index caee42f126..a7e5a6b3cd 100644 --- a/libraries/networking/src/NetworkPacket.h +++ b/libraries/networking/src/NetworkPacket.h @@ -22,12 +22,6 @@ public: NetworkPacket() { } NetworkPacket(const NetworkPacket& packet); // copy constructor NetworkPacket& operator= (const NetworkPacket& other); // copy assignment - -#ifdef HAS_MOVE_SEMANTICS - NetworkPacket(NetworkPacket&& packet); // move?? // same as copy, but other packet won't be used further - NetworkPacket& operator= (NetworkPacket&& other); // move assignment -#endif - NetworkPacket(const SharedNodePointer& node, const QByteArray& byteArray); const SharedNodePointer& getNode() const { return _node; } diff --git a/libraries/octree/src/JurisdictionMap.cpp b/libraries/octree/src/JurisdictionMap.cpp index 46e758cb42..f1a0fd2a38 100644 --- a/libraries/octree/src/JurisdictionMap.cpp +++ b/libraries/octree/src/JurisdictionMap.cpp @@ -30,23 +30,6 @@ JurisdictionMap& JurisdictionMap::operator=(const JurisdictionMap& other) { return *this; } -#ifdef HAS_MOVE_SEMANTICS -// Move constructor -JurisdictionMap::JurisdictionMap(JurisdictionMap&& other) : _rootOctalCode(NULL) { - init(other._rootOctalCode, other._endNodes); - other._rootOctalCode = NULL; - other._endNodes.clear(); -} - -// move assignment -JurisdictionMap& JurisdictionMap::operator=(JurisdictionMap&& other) { - init(other._rootOctalCode, other._endNodes); - other._rootOctalCode = NULL; - other._endNodes.clear(); - return *this; -} -#endif - // Copy constructor JurisdictionMap::JurisdictionMap(const JurisdictionMap& other) : _rootOctalCode(NULL) { copyContents(other); diff --git a/libraries/octree/src/JurisdictionMap.h b/libraries/octree/src/JurisdictionMap.h index ba75e3102b..ed4ceb79c0 100644 --- a/libraries/octree/src/JurisdictionMap.h +++ b/libraries/octree/src/JurisdictionMap.h @@ -37,12 +37,6 @@ public: // standard assignment JurisdictionMap& operator=(const JurisdictionMap& other); // copy assignment -#ifdef HAS_MOVE_SEMANTICS - // move constructor and assignment - JurisdictionMap(JurisdictionMap&& other); // move constructor - JurisdictionMap& operator= (JurisdictionMap&& other); // move assignment -#endif - // application constructors JurisdictionMap(const char* filename); JurisdictionMap(unsigned char* rootOctalCode, const std::vector& endNodes); From d19c7125daad7bf017593b63e0fc4cf46d41524d Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Tue, 14 Jul 2015 16:49:43 -0700 Subject: [PATCH 25/28] remove naked gl calls --- libraries/render-utils/src/GeometryCache.cpp | 102 ------------------- libraries/render-utils/src/GeometryCache.h | 2 - 2 files changed, 104 deletions(-) diff --git a/libraries/render-utils/src/GeometryCache.cpp b/libraries/render-utils/src/GeometryCache.cpp index 14890bd154..7cb882acc1 100644 --- a/libraries/render-utils/src/GeometryCache.cpp +++ b/libraries/render-utils/src/GeometryCache.cpp @@ -55,8 +55,6 @@ const int NUM_VERTICES_PER_TRIANGLE = 3; const int NUM_TRIANGLES_PER_QUAD = 2; const int NUM_VERTICES_PER_TRIANGULATED_QUAD = NUM_VERTICES_PER_TRIANGLE * NUM_TRIANGLES_PER_QUAD; const int NUM_COORDS_PER_VERTEX = 3; -const int NUM_BYTES_PER_VERTEX = NUM_COORDS_PER_VERTEX * sizeof(GLfloat); -const int NUM_BYTES_PER_INDEX = sizeof(GLushort); void GeometryCache::renderSphere(float radius, int slices, int stacks, const glm::vec4& color, bool solid, int id) { gpu::Batch batch; @@ -308,106 +306,6 @@ void GeometryCache::renderSphere(gpu::Batch& batch, float radius, int slices, in } } -void GeometryCache::renderCone(float base, float height, int slices, int stacks) { - VerticesIndices& vbo = _coneVBOs[IntPair(slices, stacks)]; - int vertices = (stacks + 2) * slices; - int baseTriangles = slices - 2; - int indices = NUM_VERTICES_PER_TRIANGULATED_QUAD * slices * stacks + NUM_VERTICES_PER_TRIANGLE * baseTriangles; - if (vbo.first == 0) { - GLfloat* vertexData = new GLfloat[vertices * NUM_COORDS_PER_VERTEX * 2]; - GLfloat* vertex = vertexData; - // cap - for (int i = 0; i < slices; i++) { - float theta = TWO_PI * i / slices; - - //normals - *(vertex++) = 0.0f; - *(vertex++) = 0.0f; - *(vertex++) = -1.0f; - - // vertices - *(vertex++) = cosf(theta); - *(vertex++) = sinf(theta); - *(vertex++) = 0.0f; - } - // body - for (int i = 0; i <= stacks; i++) { - float z = (float)i / stacks; - float radius = 1.0f - z; - - for (int j = 0; j < slices; j++) { - float theta = TWO_PI * j / slices; - - //normals - *(vertex++) = cosf(theta) / SQUARE_ROOT_OF_2; - *(vertex++) = sinf(theta) / SQUARE_ROOT_OF_2; - *(vertex++) = 1.0f / SQUARE_ROOT_OF_2; - - // vertices - *(vertex++) = radius * cosf(theta); - *(vertex++) = radius * sinf(theta); - *(vertex++) = z; - } - } - - glGenBuffers(1, &vbo.first); - glBindBuffer(GL_ARRAY_BUFFER, vbo.first); - glBufferData(GL_ARRAY_BUFFER, 2 * vertices * NUM_BYTES_PER_VERTEX, vertexData, GL_STATIC_DRAW); - delete[] vertexData; - - GLushort* indexData = new GLushort[indices]; - GLushort* index = indexData; - for (int i = 0; i < baseTriangles; i++) { - *(index++) = 0; - *(index++) = i + 2; - *(index++) = i + 1; - } - for (int i = 1; i <= stacks; i++) { - GLushort bottom = i * slices; - GLushort top = bottom + slices; - for (int j = 0; j < slices; j++) { - int next = (j + 1) % slices; - - *(index++) = bottom + j; - *(index++) = top + next; - *(index++) = top + j; - - *(index++) = bottom + j; - *(index++) = bottom + next; - *(index++) = top + next; - } - } - - glGenBuffers(1, &vbo.second); - glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, vbo.second); - glBufferData(GL_ELEMENT_ARRAY_BUFFER, indices * NUM_BYTES_PER_INDEX, indexData, GL_STATIC_DRAW); - delete[] indexData; - - } else { - glBindBuffer(GL_ARRAY_BUFFER, vbo.first); - glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, vbo.second); - } - glEnableClientState(GL_VERTEX_ARRAY); - glEnableClientState(GL_NORMAL_ARRAY); - - int stride = NUM_VERTICES_PER_TRIANGULATED_QUAD * sizeof(float); - glNormalPointer(GL_FLOAT, stride, 0); - glVertexPointer(NUM_COORDS_PER_VERTEX, GL_FLOAT, stride, (const void *)(NUM_COORDS_PER_VERTEX * sizeof(float))); - - glPushMatrix(); - glScalef(base, base, height); - - glDrawRangeElementsEXT(GL_TRIANGLES, 0, vertices - 1, indices, GL_UNSIGNED_SHORT, 0); - - glPopMatrix(); - - glDisableClientState(GL_VERTEX_ARRAY); - glDisableClientState(GL_NORMAL_ARRAY); - - glBindBuffer(GL_ARRAY_BUFFER, 0); - glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); -} - void GeometryCache::renderGrid(int xDivisions, int yDivisions, const glm::vec4& color) { gpu::Batch batch; renderGrid(batch, xDivisions, yDivisions, color); diff --git a/libraries/render-utils/src/GeometryCache.h b/libraries/render-utils/src/GeometryCache.h index 83891bbf49..2e64489c3e 100644 --- a/libraries/render-utils/src/GeometryCache.h +++ b/libraries/render-utils/src/GeometryCache.h @@ -133,8 +133,6 @@ public: int allocateID() { return _nextID++; } static const int UNKNOWN_ID; - void renderCone(float base, float height, int slices, int stacks); - void renderSphere(float radius, int slices, int stacks, const glm::vec3& color, bool solid = true, int id = UNKNOWN_ID) { renderSphere(radius, slices, stacks, glm::vec4(color, 1.0f), solid, id); } void renderSphere(gpu::Batch& batch, float radius, int slices, int stacks, const glm::vec3& color, bool solid = true, int id = UNKNOWN_ID) From 23b89a6f7d04b82516f10fdd1015bae6a8a41b64 Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Tue, 14 Jul 2015 17:04:07 -0700 Subject: [PATCH 26/28] remove naked gl/dead code from line and cube overlays --- interface/src/ui/overlays/Cube3DOverlay.cpp | 87 --------------------- interface/src/ui/overlays/Line3DOverlay.cpp | 33 -------- 2 files changed, 120 deletions(-) diff --git a/interface/src/ui/overlays/Cube3DOverlay.cpp b/interface/src/ui/overlays/Cube3DOverlay.cpp index 7eb9a5b414..433a55e231 100644 --- a/interface/src/ui/overlays/Cube3DOverlay.cpp +++ b/interface/src/ui/overlays/Cube3DOverlay.cpp @@ -104,93 +104,6 @@ void Cube3DOverlay::render(RenderArgs* args) { DependencyManager::get()->renderWireCube(*batch, 1.0f, cubeColor); } } - } else { - float glowLevel = getGlowLevel(); - Glower* glower = NULL; - if (glowLevel > 0.0f) { - glower = new Glower(glowLevel); - } - - glPushMatrix(); - glTranslatef(position.x, position.y, position.z); - glm::vec3 axis = glm::axis(rotation); - glRotatef(glm::degrees(glm::angle(rotation)), axis.x, axis.y, axis.z); - glPushMatrix(); - glm::vec3 positionToCenter = center - position; - glTranslatef(positionToCenter.x, positionToCenter.y, positionToCenter.z); - if (_isSolid) { - if (_borderSize > 0) { - // Draw a cube at a larger size behind the main cube, creating - // a border effect. - // Disable writing to the depth mask so that the "border" cube will not - // occlude the main cube. This means the border could be covered by - // overlays that are further back and drawn later, but this is good - // enough for the use-case. - glDepthMask(GL_FALSE); - glPushMatrix(); - glScalef(dimensions.x * _borderSize, dimensions.y * _borderSize, dimensions.z * _borderSize); - - if (_drawOnHUD) { - DependencyManager::get()->renderSolidCube(1.0f, glm::vec4(1.0f, 1.0f, 1.0f, alpha)); - } else { - DependencyManager::get()->renderSolidCube(1.0f, glm::vec4(1.0f, 1.0f, 1.0f, alpha)); - } - - glPopMatrix(); - glDepthMask(GL_TRUE); - } - - glPushMatrix(); - glScalef(dimensions.x, dimensions.y, dimensions.z); - if (_drawOnHUD) { - DependencyManager::get()->renderSolidCube(1.0f, cubeColor); - } else { - DependencyManager::get()->renderSolidCube(1.0f, cubeColor); - } - glPopMatrix(); - } else { - glLineWidth(_lineWidth); - - if (getIsDashedLine()) { - glm::vec3 halfDimensions = dimensions / 2.0f; - glm::vec3 bottomLeftNear(-halfDimensions.x, -halfDimensions.y, -halfDimensions.z); - glm::vec3 bottomRightNear(halfDimensions.x, -halfDimensions.y, -halfDimensions.z); - glm::vec3 topLeftNear(-halfDimensions.x, halfDimensions.y, -halfDimensions.z); - glm::vec3 topRightNear(halfDimensions.x, halfDimensions.y, -halfDimensions.z); - - glm::vec3 bottomLeftFar(-halfDimensions.x, -halfDimensions.y, halfDimensions.z); - glm::vec3 bottomRightFar(halfDimensions.x, -halfDimensions.y, halfDimensions.z); - glm::vec3 topLeftFar(-halfDimensions.x, halfDimensions.y, halfDimensions.z); - glm::vec3 topRightFar(halfDimensions.x, halfDimensions.y, halfDimensions.z); - - auto geometryCache = DependencyManager::get(); - - geometryCache->renderDashedLine(bottomLeftNear, bottomRightNear, cubeColor); - geometryCache->renderDashedLine(bottomRightNear, bottomRightFar, cubeColor); - geometryCache->renderDashedLine(bottomRightFar, bottomLeftFar, cubeColor); - geometryCache->renderDashedLine(bottomLeftFar, bottomLeftNear, cubeColor); - - geometryCache->renderDashedLine(topLeftNear, topRightNear, cubeColor); - geometryCache->renderDashedLine(topRightNear, topRightFar, cubeColor); - geometryCache->renderDashedLine(topRightFar, topLeftFar, cubeColor); - geometryCache->renderDashedLine(topLeftFar, topLeftNear, cubeColor); - - geometryCache->renderDashedLine(bottomLeftNear, topLeftNear, cubeColor); - geometryCache->renderDashedLine(bottomRightNear, topRightNear, cubeColor); - geometryCache->renderDashedLine(bottomLeftFar, topLeftFar, cubeColor); - geometryCache->renderDashedLine(bottomRightFar, topRightFar, cubeColor); - - } else { - glScalef(dimensions.x, dimensions.y, dimensions.z); - DependencyManager::get()->renderWireCube(1.0f, cubeColor); - } - } - glPopMatrix(); - glPopMatrix(); - - if (glower) { - delete glower; - } } } diff --git a/interface/src/ui/overlays/Line3DOverlay.cpp b/interface/src/ui/overlays/Line3DOverlay.cpp index 0bb32b9d6e..0abc86d7ad 100644 --- a/interface/src/ui/overlays/Line3DOverlay.cpp +++ b/interface/src/ui/overlays/Line3DOverlay.cpp @@ -53,7 +53,6 @@ void Line3DOverlay::render(RenderArgs* args) { glm::vec4 colorv4(color.red / MAX_COLOR, color.green / MAX_COLOR, color.blue / MAX_COLOR, alpha); auto batch = args->_batch; - if (batch) { batch->setModelTransform(_transform); @@ -63,38 +62,6 @@ void Line3DOverlay::render(RenderArgs* args) { } else { DependencyManager::get()->renderLine(*batch, _start, _end, colorv4, _geometryCacheID); } - } else { - float glowLevel = getGlowLevel(); - Glower* glower = NULL; - if (glowLevel > 0.0f) { - glower = new Glower(glowLevel); - } - - glPushMatrix(); - - glDisable(GL_LIGHTING); - glLineWidth(_lineWidth); - - glm::vec3 position = getPosition(); - glm::quat rotation = getRotation(); - - glTranslatef(position.x, position.y, position.z); - glm::vec3 axis = glm::axis(rotation); - glRotatef(glm::degrees(glm::angle(rotation)), axis.x, axis.y, axis.z); - - if (getIsDashedLine()) { - // TODO: add support for color to renderDashedLine() - DependencyManager::get()->renderDashedLine(_start, _end, colorv4, _geometryCacheID); - } else { - DependencyManager::get()->renderLine(_start, _end, colorv4, _geometryCacheID); - } - glEnable(GL_LIGHTING); - - glPopMatrix(); - - if (glower) { - delete glower; - } } } From f1b85aefa9633b797ce6673414b44dd9f5edb82f Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Tue, 14 Jul 2015 17:59:20 -0700 Subject: [PATCH 27/28] more dead code removal: NodeBounds --- interface/src/Application.cpp | 3 - interface/src/Application.h | 5 - interface/src/Menu.cpp | 8 -- interface/src/ui/ApplicationOverlay.cpp | 13 -- interface/src/ui/NodeBounds.cpp | 183 ------------------------ interface/src/ui/NodeBounds.h | 47 ------ 6 files changed, 259 deletions(-) delete mode 100644 interface/src/ui/NodeBounds.cpp delete mode 100644 interface/src/ui/NodeBounds.h diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index a0a4af29f6..65615a65b0 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -337,7 +337,6 @@ Application::Application(int& argc, char** argv, QElapsedTimer &startup_time) : _mousePressed(false), _enableProcessOctreeThread(true), _octreeProcessor(), - _nodeBoundsDisplay(this), _runningScriptsWidget(NULL), _runningScriptsWidgetWasVisible(false), _trayIcon(new QSystemTrayIcon(_window)), @@ -3587,8 +3586,6 @@ void Application::displaySide(RenderArgs* renderArgs, Camera& theCamera, bool se } if (!selfAvatarOnly) { - _nodeBoundsDisplay.draw(); - // give external parties a change to hook in { PerformanceTimer perfTimer("inWorldInterface"); diff --git a/interface/src/Application.h b/interface/src/Application.h index 55dbaf7f27..44ead54563 100644 --- a/interface/src/Application.h +++ b/interface/src/Application.h @@ -60,7 +60,6 @@ #include "ui/BandwidthDialog.h" #include "ui/HMDToolsDialog.h" #include "ui/ModelsBrowser.h" -#include "ui/NodeBounds.h" #include "ui/OctreeStatsDialog.h" #include "ui/SnapshotShareDialog.h" #include "ui/LodToolsDialog.h" @@ -303,8 +302,6 @@ public: virtual void endOverrideEnvironmentData() { _environment.endOverride(); } virtual qreal getDevicePixelRatio(); - NodeBounds& getNodeBoundsDisplay() { return _nodeBoundsDisplay; } - FileLogger* getLogger() { return _logger; } glm::vec2 getViewportDimensions() const; @@ -621,8 +618,6 @@ private: NodeToOctreeSceneStats _octreeServerSceneStats; QReadWriteLock _octreeSceneStatsLock; - NodeBounds _nodeBoundsDisplay; - ControllerScriptingInterface _controllerScriptingInterface; QPointer _logDialog; QPointer _snapshotShareDialog; diff --git a/interface/src/Menu.cpp b/interface/src/Menu.cpp index ff6a144fce..60311904de 100644 --- a/interface/src/Menu.cpp +++ b/interface/src/Menu.cpp @@ -37,7 +37,6 @@ #include "SpeechRecognizer.h" #endif #include "ui/DialogsManager.h" -#include "ui/NodeBounds.h" #include "ui/StandAloneJSConsole.h" #include "InterfaceLogging.h" @@ -316,13 +315,6 @@ Menu::Menu() { qApp, SLOT(setEnable3DTVMode(bool))); - - MenuWrapper* nodeBordersMenu = viewMenu->addMenu("Server Borders"); - NodeBounds& nodeBounds = qApp->getNodeBoundsDisplay(); - addCheckableActionToQMenuAndActionHash(nodeBordersMenu, MenuOption::ShowBordersEntityNodes, - Qt::CTRL | Qt::SHIFT | Qt::Key_1, false, - &nodeBounds, SLOT(setShowEntityNodes(bool))); - addCheckableActionToQMenuAndActionHash(viewMenu, MenuOption::TurnWithHead, 0, false); addCheckableActionToQMenuAndActionHash(viewMenu, MenuOption::Stats); diff --git a/interface/src/ui/ApplicationOverlay.cpp b/interface/src/ui/ApplicationOverlay.cpp index 44904a8655..b28c5c83a2 100644 --- a/interface/src/ui/ApplicationOverlay.cpp +++ b/interface/src/ui/ApplicationOverlay.cpp @@ -165,19 +165,6 @@ void ApplicationOverlay::renderStatsAndLogs(RenderArgs* renderArgs) { drawText(canvasSize.x - 100, canvasSize.y - timerBottom, 0.30f, 0.0f, 0, frameTimer.toUtf8().constData(), WHITE_TEXT); } - - glPointSize(1.0f); - glDisable(GL_DEPTH_TEST); - glDisable(GL_LIGHTING); - glEnable(GL_BLEND); - glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); - NodeBounds& nodeBoundsDisplay = qApp->getNodeBoundsDisplay(); - nodeBoundsDisplay.drawOverlay(); - glEnable(GL_DEPTH_TEST); - glEnable(GL_LIGHTING); - glEnable(GL_BLEND); - glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_CONSTANT_ALPHA, GL_ONE); - fboViewport(_overlayFramebuffer); */ } diff --git a/interface/src/ui/NodeBounds.cpp b/interface/src/ui/NodeBounds.cpp deleted file mode 100644 index 2b1b2f56e1..0000000000 --- a/interface/src/ui/NodeBounds.cpp +++ /dev/null @@ -1,183 +0,0 @@ -// -// NodeBounds.cpp -// interface/src/ui -// -// Created by Ryan Huffman on 05/14/14. -// Copyright 2014 High Fidelity, Inc. -// -// This class draws a border around the different Entity nodes on the current domain, -// and a semi-transparent cube around the currently mouse-overed node. -// -// 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 "Application.h" -#include "Util.h" - -#include "NodeBounds.h" - -NodeBounds::NodeBounds(QObject* parent) : - QObject(parent), - _showEntityNodes(false), - _overlayText() { - -} - -void NodeBounds::draw() { - if (!_showEntityNodes) { - _overlayText[0] = '\0'; - return; - } - - NodeToJurisdictionMap& entityServerJurisdictions = Application::getInstance()->getEntityServerJurisdictions(); - NodeToJurisdictionMap* serverJurisdictions; - - // 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. - PickRay pickRay = qApp->computePickRay(); - - // Variables to keep track of the selected node and properties to draw the cube later if needed - Node* selectedNode = NULL; - float selectedDistance = FLT_MAX; - bool selectedIsInside = true; - glm::vec3 selectedCenter; - float selectedScale = 0; - - auto nodeList = DependencyManager::get(); - nodeList->eachNode([&](const SharedNodePointer& node){ - NodeType_t nodeType = node->getType(); - - if (nodeType == NodeType::EntityServer && _showEntityNodes) { - serverJurisdictions = &entityServerJurisdictions; - } else { - return; - } - - QUuid nodeUUID = node->getUUID(); - serverJurisdictions->lockForRead(); - if (serverJurisdictions->find(nodeUUID) != serverJurisdictions->end()) { - const JurisdictionMap& map = (*serverJurisdictions)[nodeUUID]; - - unsigned char* rootCode = map.getRootOctalCode(); - - if (rootCode) { - VoxelPositionSize rootDetails; - voxelDetailsForCode(rootCode, rootDetails); - serverJurisdictions->unlock(); - glm::vec3 location(rootDetails.x, rootDetails.y, rootDetails.z); - - AACube serverBounds(location, rootDetails.s); - - glm::vec3 center = serverBounds.getVertex(BOTTOM_RIGHT_NEAR) - + ((serverBounds.getVertex(TOP_LEFT_FAR) - serverBounds.getVertex(BOTTOM_RIGHT_NEAR)) / 2.0f); - - const float ENTITY_NODE_SCALE = 0.99f; - - float scaleFactor = rootDetails.s; - - // Scale by 0.92 - 1.00 depending on the scale of the node. This allows smaller nodes to scale in - // a bit and not overlap larger nodes. - scaleFactor *= 0.92f + (rootDetails.s * 0.08f); - - // Scale different node types slightly differently because it's common for them to overlap. - if (nodeType == NodeType::EntityServer) { - scaleFactor *= ENTITY_NODE_SCALE; - } - - float red, green, blue; - getColorForNodeType(nodeType, red, green, blue); - drawNodeBorder(center, scaleFactor, red, green, blue); - - float distance; - BoxFace face; - - bool inside = serverBounds.contains(pickRay.origin); - bool colliding = serverBounds.findRayIntersection(pickRay.origin, pickRay.direction, distance, face); - - // If the camera is inside a node it will be "selected" if you don't have your cursor over another node - // that you aren't inside. - if (colliding && (!selectedNode || (!inside && (distance < selectedDistance || selectedIsInside)))) { - selectedNode = node.data(); - selectedDistance = distance; - selectedIsInside = inside; - selectedCenter = center; - selectedScale = scaleFactor; - } - } else { - serverJurisdictions->unlock(); - } - } else { - serverJurisdictions->unlock(); - } - }); - - if (selectedNode) { - glPushMatrix(); - - glTranslatef(selectedCenter.x, selectedCenter.y, selectedCenter.z); - glScalef(selectedScale, selectedScale, selectedScale); - - float red, green, blue; - getColorForNodeType(selectedNode->getType(), red, green, blue); - - DependencyManager::get()->renderSolidCube(1.0f, glm::vec4(red, green, blue, 0.2f)); - - glPopMatrix(); - - HifiSockAddr addr = selectedNode->getPublicSocket(); - QString overlay = QString("%1:%2 %3ms") - .arg(addr.getAddress().toString()) - .arg(addr.getPort()) - .arg(selectedNode->getPingMs()) - .left(MAX_OVERLAY_TEXT_LENGTH); - - // Ideally we'd just use a QString, but I ran into weird blinking issues using - // constData() directly, as if the data was being overwritten. - strcpy(_overlayText, overlay.toLocal8Bit().constData()); - } else { - _overlayText[0] = '\0'; - } -} - -void NodeBounds::drawNodeBorder(const glm::vec3& center, float scale, float red, float green, float blue) { - glPushMatrix(); - glTranslatef(center.x, center.y, center.z); - glScalef(scale, scale, scale); - glLineWidth(2.5); - DependencyManager::get()->renderWireCube(1.0f, glm::vec4(red, green, blue, 1.0f)); - glPopMatrix(); -} - -void NodeBounds::getColorForNodeType(NodeType_t nodeType, float& red, float& green, float& blue) { - red = nodeType == 0.0; - green = 0.0; - blue = nodeType == NodeType::EntityServer ? 1.0 : 0.0; -} - -void NodeBounds::drawOverlay() { - if (strlen(_overlayText) > 0) { - Application* application = Application::getInstance(); - - const float TEXT_COLOR[] = { 0.90f, 0.90f, 0.90f }; - const float TEXT_SCALE = 0.1f; - const int TEXT_HEIGHT = 10; - const float ROTATION = 0.0f; - const int FONT = 2; - const int PADDING = 10; - const int MOUSE_OFFSET = 10; - const int BACKGROUND_BEVEL = 3; - - int mouseX = application->getTrueMouseX(), - mouseY = application->getTrueMouseY(), - textWidth = widthText(TEXT_SCALE, 0, _overlayText); - DependencyManager::get()->renderBevelCornersRect( - mouseX + MOUSE_OFFSET, mouseY - TEXT_HEIGHT - PADDING, - textWidth + (2 * PADDING), TEXT_HEIGHT + (2 * PADDING), BACKGROUND_BEVEL, - glm::vec4(0.4f, 0.4f, 0.4f, 0.6f)); - drawText(mouseX + MOUSE_OFFSET + PADDING, mouseY, TEXT_SCALE, ROTATION, FONT, _overlayText, TEXT_COLOR); - } -} diff --git a/interface/src/ui/NodeBounds.h b/interface/src/ui/NodeBounds.h deleted file mode 100644 index 66255a6432..0000000000 --- a/interface/src/ui/NodeBounds.h +++ /dev/null @@ -1,47 +0,0 @@ -// -// NodeBounds.h -// interface/src/ui -// -// Created by Ryan Huffman on 05/14/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_NodeBounds_h -#define hifi_NodeBounds_h - -#include - -#include - -const int MAX_OVERLAY_TEXT_LENGTH = 64; - -class NodeBounds : public QObject { - Q_OBJECT -public: - NodeBounds(QObject* parent = NULL); - - bool getShowEntityNodes() { return _showEntityNodes; } - bool getShowParticleNodes() { return _showParticleNodes; } - - void draw(); - void drawOverlay(); - -public slots: - void setShowEntityNodes(bool value) { _showEntityNodes = value; } - void setShowParticleNodes(bool value) { _showParticleNodes = value; } - -protected: - void drawNodeBorder(const glm::vec3& center, float scale, float red, float green, float blue); - void getColorForNodeType(NodeType_t nodeType, float& red, float& green, float& blue); - -private: - bool _showEntityNodes; - bool _showParticleNodes; - char _overlayText[MAX_OVERLAY_TEXT_LENGTH + 1]; - -}; - -#endif // hifi_NodeBounds_h From 47dad82d50a34e8ee4f73425343aed6a58e7bdb3 Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Tue, 14 Jul 2015 18:09:58 -0700 Subject: [PATCH 28/28] removed dead code --- libraries/render-utils/src/RenderUtil.h | 50 ------------------------- 1 file changed, 50 deletions(-) diff --git a/libraries/render-utils/src/RenderUtil.h b/libraries/render-utils/src/RenderUtil.h index 8c1b1e12e7..b2f244733a 100644 --- a/libraries/render-utils/src/RenderUtil.h +++ b/libraries/render-utils/src/RenderUtil.h @@ -15,54 +15,4 @@ /// Renders a quad from (-1, -1, 0) to (1, 1, 0) with texture coordinates from (sMin, tMin) to (sMax, tMax). void renderFullscreenQuad(float sMin = 0.0f, float sMax = 1.0f, float tMin = 0.0f, float tMax = 1.0f); -template -void withMatrixPush(F f) { - glMatrixMode(matrix); - glPushMatrix(); - f(); - glPopMatrix(); -} - -template -void withProjectionPush(F f) { - withMatrixPush(f); -} - -template -void withProjectionIdentity(F f) { - withProjectionPush([&] { - glLoadIdentity(); - f(); - }); -} - -template -void withProjectionMatrix(GLfloat* matrix, F f) { - withProjectionPush([&] { - glLoadMatrixf(matrix); - f(); - }); -} - -template -void withModelviewPush(F f) { - withMatrixPush(f); -} - -template -void withModelviewIdentity(F f) { - withModelviewPush([&] { - glLoadIdentity(); - f(); - }); -} - -template -void withModelviewMatrix(GLfloat* matrix, F f) { - withModelviewPush([&] { - glLoadMatrixf(matrix); - f(); - }); -} - #endif // hifi_RenderUtil_h