From 00185ee82e0afcf953b4713cad0dd17e4b6b0d77 Mon Sep 17 00:00:00 2001 From: Andrew Meadows Date: Wed, 26 Jun 2019 17:05:44 -0700 Subject: [PATCH] cleaup to help unravel one spaghetti strand --- interface/src/Application.cpp | 41 +++++++++++-------- interface/src/Application.h | 1 + .../src/octree/OctreePacketProcessor.cpp | 10 +++-- interface/src/octree/OctreePacketProcessor.h | 1 + interface/src/octree/SafeLanding.cpp | 8 ++-- interface/src/octree/SafeLanding.h | 8 ++-- 6 files changed, 42 insertions(+), 27 deletions(-) diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index e23e3172ac..58b042e084 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -6165,6 +6165,24 @@ void Application::updateSecondaryCameraViewFrustum() { static bool domainLoadingInProgress = false; +void Application::tryToEnablePhysics() { + bool enableInterstitial = DependencyManager::get()->getDomainHandler().getInterstitialModeEnabled(); + + if (gpuTextureMemSizeStable() || !enableInterstitial) { + _fullSceneCounterAtLastPhysicsCheck = _fullSceneReceivedCounter; + _lastQueriedViews.clear(); // Force new view. + + // process octree stats packets are sent in between full sends of a scene (this isn't currently true). + // We keep physics disabled until we've received a full scene and everything near the avatar in that + // scene is ready to compute its collision shape. + if (getMyAvatar()->isReadyForPhysics()) { + _physicsEnabled = true; + setIsInterstitialMode(false); + getMyAvatar()->updateMotionBehaviorFromMenu(); + } + } +} + void Application::update(float deltaTime) { PROFILE_RANGE_EX(app, __FUNCTION__, 0xffff0000, (uint64_t)_graphicsEngine._renderFrameCount + 1); @@ -6172,7 +6190,6 @@ void Application::update(float deltaTime) { return; } - if (!_physicsEnabled) { if (!domainLoadingInProgress) { PROFILE_ASYNC_BEGIN(app, "Scene Loading", ""); @@ -6182,21 +6199,13 @@ void Application::update(float deltaTime) { // we haven't yet enabled physics. we wait until we think we have all the collision information // for nearby entities before starting bullet up. quint64 now = usecTimestampNow(); - if (isServerlessMode() || _octreeProcessor.isLoadSequenceComplete()) { - bool enableInterstitial = DependencyManager::get()->getDomainHandler().getInterstitialModeEnabled(); - - if (gpuTextureMemSizeStable() || !enableInterstitial) { - _fullSceneCounterAtLastPhysicsCheck = _fullSceneReceivedCounter; - _lastQueriedViews.clear(); // Force new view. - - // process octree stats packets are sent in between full sends of a scene (this isn't currently true). - // We keep physics disabled until we've received a full scene and everything near the avatar in that - // scene is ready to compute its collision shape. - if (getMyAvatar()->isReadyForPhysics()) { - _physicsEnabled = true; - setIsInterstitialMode(false); - getMyAvatar()->updateMotionBehaviorFromMenu(); - } + if (isServerlessMode()) { + tryToEnablePhysics(); + } else if (_failedToConnectToEntityServer) { + _octreeProcessor.stopSafeLanding(); + } else { + if (_octreeProcessor.isLoadSequenceComplete()) { + tryToEnablePhysics(); } } } else if (domainLoadingInProgress) { diff --git a/interface/src/Application.h b/interface/src/Application.h index bd7c9d758e..8b25417abe 100644 --- a/interface/src/Application.h +++ b/interface/src/Application.h @@ -564,6 +564,7 @@ private: void cleanupBeforeQuit(); void idle(); + void tryToEnablePhysics(); void update(float deltaTime); // Various helper functions called during update() diff --git a/interface/src/octree/OctreePacketProcessor.cpp b/interface/src/octree/OctreePacketProcessor.cpp index 544c56c802..68e68ee0af 100644 --- a/interface/src/octree/OctreePacketProcessor.cpp +++ b/interface/src/octree/OctreePacketProcessor.cpp @@ -115,7 +115,7 @@ void OctreePacketProcessor::processPacket(QSharedPointer messag auto renderer = qApp->getEntities(); if (renderer) { renderer->processDatagram(*message, sendingNode); - _safeLanding->noteReceivedsequenceNumber(renderer->getLastOctreeMessageSequence()); + _safeLanding->updateSequence(renderer->getLastOctreeMessageSequence()); } } } break; @@ -124,7 +124,7 @@ void OctreePacketProcessor::processPacket(QSharedPointer messag // Read sequence # OCTREE_PACKET_SEQUENCE completionNumber; message->readPrimitive(&completionNumber); - _safeLanding->setCompletionSequenceNumbers(0, completionNumber); + _safeLanding->finishSequence(0, completionNumber); } break; default: { @@ -134,5 +134,9 @@ void OctreePacketProcessor::processPacket(QSharedPointer messag } void OctreePacketProcessor::startSafeLanding() { - _safeLanding->startEntitySequence(qApp->getEntities()); + _safeLanding->startTracking(qApp->getEntities()); +} + +void OctreePacketProcessor::stopSafeLanding() { + _safeLanding->stopTracking(); } diff --git a/interface/src/octree/OctreePacketProcessor.h b/interface/src/octree/OctreePacketProcessor.h index 7f906eab99..5c5bc7ed9a 100644 --- a/interface/src/octree/OctreePacketProcessor.h +++ b/interface/src/octree/OctreePacketProcessor.h @@ -26,6 +26,7 @@ public: ~OctreePacketProcessor(); void startSafeLanding(); + void stopSafeLanding(); bool isLoadSequenceComplete() const { return _safeLanding->isLoadSequenceComplete(); } float domainLoadingProgress() const { return _safeLanding->loadingProgressPercentage(); } diff --git a/interface/src/octree/SafeLanding.cpp b/interface/src/octree/SafeLanding.cpp index e4a2156aff..3ae31a4b1a 100644 --- a/interface/src/octree/SafeLanding.cpp +++ b/interface/src/octree/SafeLanding.cpp @@ -33,7 +33,7 @@ bool SafeLanding::SequenceLessThan::operator()(const int& a, const int& b) const return lessThanWraparound(a, b); } -void SafeLanding::startEntitySequence(QSharedPointer entityTreeRenderer) { +void SafeLanding::startTracking(QSharedPointer entityTreeRenderer) { if (!entityTreeRenderer.isNull()) { auto entityTree = entityTreeRenderer->getTree(); if (entityTree && !_trackingEntities) { @@ -81,7 +81,7 @@ void SafeLanding::deleteTrackedEntity(const EntityItemID& entityID) { _trackedEntities.erase(entityID); } -void SafeLanding::setCompletionSequenceNumbers(int first, int last) { +void SafeLanding::finishSequence(int first, int last) { Locker lock(_lock); if (_initialStart == INVALID_SEQUENCE) { _initialStart = first; @@ -89,7 +89,7 @@ void SafeLanding::setCompletionSequenceNumbers(int first, int last) { } } -void SafeLanding::noteReceivedsequenceNumber(int sequenceNumber) { +void SafeLanding::updateSequence(int sequenceNumber) { if (_trackingEntities) { Locker lock(_lock); _sequenceNumbers.insert(sequenceNumber); @@ -97,7 +97,7 @@ void SafeLanding::noteReceivedsequenceNumber(int sequenceNumber) { } bool SafeLanding::isLoadSequenceComplete() { - if ((isEntityLoadingComplete() && isSequenceNumbersComplete()) || qApp->failedToConnectToEntityServer()) { + if (isEntityLoadingComplete() && isSequenceNumbersComplete()) { stopTracking(); } return !_trackingEntities; diff --git a/interface/src/octree/SafeLanding.h b/interface/src/octree/SafeLanding.h index f88282ba5e..ec9fb98989 100644 --- a/interface/src/octree/SafeLanding.h +++ b/interface/src/octree/SafeLanding.h @@ -25,9 +25,10 @@ class EntityItemID; class SafeLanding : public QObject { public: - void startEntitySequence(QSharedPointer entityTreeRenderer); - void setCompletionSequenceNumbers(int first, int last); // 'last' exclusive. - void noteReceivedsequenceNumber(int sequenceNumber); + void startTracking(QSharedPointer entityTreeRenderer); + void stopTracking(); + void finishSequence(int first, int last); // 'last' exclusive. + void updateSequence(int sequenceNumber); bool isLoadSequenceComplete(); float loadingProgressPercentage(); @@ -40,7 +41,6 @@ private: bool isEntityPhysicsReady(const EntityItemPointer& entity); void debugDumpSequenceIDs() const; bool isEntityLoadingComplete(); - void stopTracking(); std::mutex _lock; using Locker = std::lock_guard;