diff --git a/assignment-client/src/octree/OctreeServer.cpp b/assignment-client/src/octree/OctreeServer.cpp index 798f539211..c2fbc8ab37 100644 --- a/assignment-client/src/octree/OctreeServer.cpp +++ b/assignment-client/src/octree/OctreeServer.cpp @@ -1053,7 +1053,7 @@ void OctreeServer::readConfiguration() { int result { -1 }; readOptionInt(QString("persistInterval"), settingsSectionObject, result); if (result != -1) { - _persistInterval = std::chrono::seconds(result); + _persistInterval = std::chrono::milliseconds(result); } qDebug() << "persistInterval=" << _persistInterval.count(); diff --git a/libraries/octree/src/OctreePersistThread.cpp b/libraries/octree/src/OctreePersistThread.cpp index ae03ff2463..af0bf55b46 100644 --- a/libraries/octree/src/OctreePersistThread.cpp +++ b/libraries/octree/src/OctreePersistThread.cpp @@ -36,7 +36,8 @@ #include "OctreeUtils.h" #include "OctreeDataUtils.h" -const std::chrono::seconds OctreePersistThread::DEFAULT_PERSIST_INTERVAL { 30 }; +constexpr std::chrono::seconds OctreePersistThread::DEFAULT_PERSIST_INTERVAL { 30 }; +constexpr std::chrono::milliseconds TIME_BETWEEN_PROCESSING { 10 }; constexpr int MAX_OCTREE_REPLACEMENT_BACKUP_FILES_COUNT { 20 }; constexpr size_t MAX_OCTREE_REPLACEMENT_BACKUP_FILES_SIZE_BYTES { 50 * 1000 * 1000 }; @@ -48,7 +49,7 @@ OctreePersistThread::OctreePersistThread(OctreePointer tree, const QString& file _persistInterval(persistInterval), _initialLoadComplete(false), _loadTimeUSecs(0), - _lastCheck(0), + _lastPersistCheck(std::chrono::steady_clock::now()), _debugTimestampNow(debugTimestampNow), _lastTimeDebug(0), _persistAsFileType(persistAsFileType) @@ -95,7 +96,7 @@ void OctreePersistThread::start() { packet->writePrimitive(false); } - qCDebug(octree) << "Sending request for octree data to DS"; + qCDebug(octree) << "Sending OctreeDataFileRequest to DS"; nodeList->sendPacket(std::move(packet), domainHandler.getSockAddr()); } @@ -111,9 +112,9 @@ void OctreePersistThread::handleOctreeDataFileReply(QSharedPointerreadAll(); replaceData(replacementData); - qDebug() << "Got reply to octree data file request, new data sent"; + qDebug() << "Got OctreeDataFileReply, new data sent"; } else { - qDebug() << "Got reply to octree data file request, current entity data is sufficient"; + qDebug() << "Got OctreeDataFileReply, current entity data is sufficient"; OctreeUtils::RawEntityData data; qCDebug(octree) << "Reading octree data from" << _filename; @@ -178,16 +179,14 @@ void OctreePersistThread::handleOctreeDataFileReply(QSharedPointerupdate(); - // do our updates then check to save... - _tree->update(); + auto now = std::chrono::steady_clock::now(); + auto timeSinceLastPersist = now - _lastPersistCheck; - quint64 now = usecTimestampNow(); - quint64 sinceLastSave = now - _lastCheck; - quint64 intervalToCheck = std::chrono::microseconds(_persistInterval).count(); - - if (sinceLastSave > intervalToCheck) { - _lastCheck = now; - persist(); - } + qDebug() << "Seconds since last persist: " << std::chrono::duration_cast(timeSinceLastPersist).count(); + if (timeSinceLastPersist > _persistInterval) { + _lastPersistCheck = now; + persist(); } - - // if we were asked to debugTimestampNow do that now... - if (_debugTimestampNow) { - quint64 now = usecTimestampNow(); - quint64 sinceLastDebug = now - _lastTimeDebug; - quint64 DEBUG_TIMESTAMP_INTERVAL = 600000000; // every 10 minutes - if (sinceLastDebug > DEBUG_TIMESTAMP_INTERVAL) { - _lastTimeDebug = usecTimestampNow(true); // ask for debug output - } - - } - //return isStillRunning(); // keep running till they terminate us - QTimer::singleShot(1000, this, &OctreePersistThread::process); - return true; + QTimer::singleShot(TIME_BETWEEN_PROCESSING.count(), this, &OctreePersistThread::process); } void OctreePersistThread::aboutToFinish() { diff --git a/libraries/octree/src/OctreePersistThread.h b/libraries/octree/src/OctreePersistThread.h index bd114cec06..5bb6e51e5f 100644 --- a/libraries/octree/src/OctreePersistThread.h +++ b/libraries/octree/src/OctreePersistThread.h @@ -54,7 +54,7 @@ signals: void loadCompleted(); protected slots: - bool process(); + void process(); void handleOctreeDataFileReply(QSharedPointer message); protected: @@ -71,12 +71,11 @@ private: OctreePointer _tree; QString _filename; std::chrono::milliseconds _persistInterval; + std::chrono::steady_clock::time_point _lastPersistCheck; bool _initialLoadComplete; quint64 _loadTimeUSecs; - quint64 _lastCheck; - bool _debugTimestampNow; quint64 _lastTimeDebug;