diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index 14ee3befc5..cc2c7f601a 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -6322,10 +6322,11 @@ void Application::clearDomainOctreeDetails() { _octreeServerSceneStats.clear(); }); - _octreeProcessor.resetCompletionSequenceNumber(); // reset the model renderer getEntities()->clear(); + _octreeProcessor.startEntitySequence(); + auto skyStage = DependencyManager::get()->getSkyStage(); skyStage->setBackgroundMode(graphics::SunSkyStage::SKY_DEFAULT); diff --git a/interface/src/octree/OctreePacketProcessor.cpp b/interface/src/octree/OctreePacketProcessor.cpp index 3f06e1579a..6dab37b1a1 100644 --- a/interface/src/octree/OctreePacketProcessor.cpp +++ b/interface/src/octree/OctreePacketProcessor.cpp @@ -122,7 +122,7 @@ void OctreePacketProcessor::processPacket(QSharedPointer messag OCTREE_PACKET_SEQUENCE completionNumber; message->readPrimitive(&completionNumber); - _completionSequenceNumber = completionNumber; + completionNumber; _safeLanding->setCompletionSequenceNumbers(0, completionNumber); } break; @@ -132,26 +132,6 @@ void OctreePacketProcessor::processPacket(QSharedPointer messag } } -void OctreePacketProcessor::resetCompletionSequenceNumber() { - _completionSequenceNumber = INVALID_SEQUENCE; -} - -namespace { - template bool lessThanWraparound(int a, int b) { - constexpr int MAX_T_VALUE = std::numeric_limits::max(); - if (b <= a) { - b += MAX_T_VALUE; - } - return (b - a) < (MAX_T_VALUE / 2); - } -} - -//bool OctreePacketProcessor::octreeSequenceIsComplete(int sequenceNumber) const { -// // If we've received the flagged seq # and the current one is >= it. -// return _completionSequenceNumber != INVALID_SEQUENCE && -// !lessThanWraparound(sequenceNumber, _completionSequenceNumber); -//} - void OctreePacketProcessor::startEntitySequence() { _safeLanding->startEntitySequence(qApp->getEntities()); } diff --git a/interface/src/octree/OctreePacketProcessor.h b/interface/src/octree/OctreePacketProcessor.h index 0a1fecaf96..f9c24ddc51 100644 --- a/interface/src/octree/OctreePacketProcessor.h +++ b/interface/src/octree/OctreePacketProcessor.h @@ -31,9 +31,6 @@ public: signals: void packetVersionMismatch(); -public slots: - void resetCompletionSequenceNumber(); - protected: virtual void processPacket(QSharedPointer message, SharedNodePointer sendingNode) override; @@ -41,8 +38,6 @@ private slots: void handleOctreePacket(QSharedPointer message, SharedNodePointer senderNode); private: - static constexpr int INVALID_SEQUENCE = -1; - std::atomic _completionSequenceNumber { INVALID_SEQUENCE }; std::unique_ptr _safeLanding; }; #endif // hifi_OctreePacketProcessor_h diff --git a/interface/src/octree/SafeLanding.cpp b/interface/src/octree/SafeLanding.cpp index c0f8b0130d..352c83dad0 100644 --- a/interface/src/octree/SafeLanding.cpp +++ b/interface/src/octree/SafeLanding.cpp @@ -12,7 +12,6 @@ #include "SafeLanding.h" #include "EntityTreeRenderer.h" #include "ModelEntityItem.h" -#include "model-networking/ModelCache.h" #include "InterfaceLogging.h" const int SafeLanding::SEQUENCE_MODULO = std::numeric_limits::max() + 1; @@ -31,9 +30,6 @@ bool SafeLanding::SequenceLessThan::operator()(const int& a, const int& b) const return lessThanWraparound(a, b); } -SafeLanding::SafeLanding() { -} - void SafeLanding::startEntitySequence(QSharedPointer entityTreeRenderer) { if (!_trackingEntities) { auto entityTree = entityTreeRenderer->getTree(); @@ -59,19 +55,20 @@ void SafeLanding::stopEntitySequence() { } void SafeLanding::addTrackedEntity(const EntityItemID& entityID) { - volatile EntityItemID id = entityID; if (_trackingEntities) { EntityItemPointer entity = _entityTree->findEntityByID(entityID); - if (entity) { - const auto& entityType = entity->getType(); - // Entity types of interest: - static const std::set solidTypes - { EntityTypes::Box, EntityTypes::Sphere, EntityTypes::Shape, EntityTypes::Model }; - if (solidTypes.count(entity->getType()) && !entity->getCollisionless()) { - _trackedEntities.emplace(entityID, entity); - trackResources(entity); - qCDebug(interfaceapp) << "Tracking entity " << entity->getItemName(); + if (entity && !entity->getCollisionless()) { + const auto& entityType = entity->getType(); + if (entityType == EntityTypes::Model) { + ModelEntityItem * modelEntity = std::dynamic_pointer_cast(entity).get(); + auto shapeType = modelEntity->getShapeType(); + if (shapeType == SHAPE_TYPE_COMPOUND || shapeType == SHAPE_TYPE_STATIC_MESH || + shapeType == SHAPE_TYPE_SIMPLE_COMPOUND) { + // Only track entities with downloaded collision bodies. + _trackedEntities.emplace(entityID, entity); + qCDebug(interfaceapp) << "Safe Landing: Tracking entity " << entity->getItemName(); + } } } } @@ -112,58 +109,46 @@ bool SafeLanding::sequenceNumbersComplete() { return false; } -void SafeLanding::trackResources(EntityItemPointer entity) { - if (entity->getType() == EntityTypes::Model) { - ModelEntityItem * modelEntity = std::dynamic_pointer_cast(entity).get(); - QString resourceURL; - QSharedPointer resource; - auto shapeType = modelEntity->getShapeType(); - - if (shapeType == SHAPE_TYPE_COMPOUND) { - resourceURL = modelEntity->getCompoundShapeURL(); - resource = DependencyManager::get()->getCollisionGeometryResource(resourceURL); - } else if (shapeType == SHAPE_TYPE_STATIC_MESH || shapeType == SHAPE_TYPE_SIMPLE_COMPOUND) { - resourceURL = modelEntity->getModelURL(); - resource = DependencyManager::get()->getGeometryResource(resourceURL); - } - - if (resource) { - connect(resource.data(), &Resource::loaded, this, &SafeLanding::resourceLoaded); - // Remove it either way: - connect(resource.data(), &Resource::failed, this, &SafeLanding::resourceLoaded); - if (!resource->isLoaded()) { - _trackedURLs.insert(resourceURL); - } - } - } -} - void SafeLanding::resourceLoaded() { QObject * sender = QObject::sender(); if (sender) { Resource * resource = dynamic_cast(sender); const QString resourceURL = resource->getURL().toString(); _trackedURLs.erase(resourceURL); - qCDebug(interfaceapp) << "Removed tracked URL" << resourceURL; + qCDebug(interfaceapp) << "Safe Landing: Removed tracked URL" << resourceURL; } } bool SafeLanding::isLoadSequenceComplete() { - if (sequenceNumbersComplete() && _trackedURLs.empty()) { + if (sequenceNumbersComplete() && entityPhysicsComplete()) { _trackingEntities = false; _trackedEntities.clear(); + qCDebug(interfaceapp) << "Safe Landing: load sequence complete"; } return !_trackingEntities; } -void SafeLanding::DebugDumpSequenceIDs() const { +bool SafeLanding::entityPhysicsComplete() { + for (auto entityMapIter = _trackedEntities.begin(); entityMapIter != _trackedEntities.end(); ++entityMapIter) { + auto entity = entityMapIter->second; + if (!entity->shouldBePhysical() || entity->isReadyToComputeShape()) { + entityMapIter = _trackedEntities.erase(entityMapIter); + if (entityMapIter == _trackedEntities.end()) { + break; + } + } + } + return _trackedEntities.empty(); +} + +void SafeLanding::debugDumpSequenceIDs() const { int p = -1; qCDebug(interfaceapp) << "Sequence set size:" << _sequenceNumbers.size(); for (auto s: _sequenceNumbers) { if (p == -1) { p = s; - qCDebug(interfaceapp) << "First: " << s; + qCDebug(interfaceapp) << "First:" << s; } else { if (s != p + 1) { qCDebug(interfaceapp) << "Gap from" << p << "to" << s << "(exclusive)"; diff --git a/interface/src/octree/SafeLanding.h b/interface/src/octree/SafeLanding.h index e32a444784..e81746e077 100644 --- a/interface/src/octree/SafeLanding.h +++ b/interface/src/octree/SafeLanding.h @@ -24,9 +24,6 @@ class EntityItemID; class SafeLanding : public QObject { public: - SafeLanding(); - ~SafeLanding() = default; - void startEntitySequence(QSharedPointer entityTreeRenderer); void stopEntitySequence(); void setCompletionSequenceNumbers(int first, int last); @@ -40,8 +37,8 @@ private slots: private: bool sequenceNumbersComplete(); - void trackResources(EntityItemPointer entity); - void DebugDumpSequenceIDs() const; + void debugDumpSequenceIDs() const; + bool entityPhysicsComplete(); bool _trackingEntities { false }; EntityTreePointer _entityTree;