update render loop iterations msec to mmsec
Some checks failed
buildbot/DocsGenerator Build finished.
buildbot/AndroidBuilder_v8Qt6 Build finished.
buildbot/LinuxCMakeBuilderQt6 Build finished.

This commit is contained in:
Andrei Yankovich 2025-01-30 10:40:56 +01:00
parent 880c91320a
commit cd6da9b177
2 changed files with 6 additions and 8 deletions

View File

@ -6,13 +6,11 @@
*/ */
#include "asyncrenderloop.h" #include "asyncrenderloop.h"
#include <QDateTime>
#include <QThread> #include <QThread>
namespace QH { namespace QH {
AsyncRenderLoop::AsyncRenderLoop(QThread *thread, QObject *ptr): Async(thread, ptr) { AsyncRenderLoop::AsyncRenderLoop(QThread *thread, QObject *ptr): Async(thread, ptr) {
} }
AsyncRenderLoop::~AsyncRenderLoop() { AsyncRenderLoop::~AsyncRenderLoop() {
@ -43,7 +41,7 @@ bool AsyncRenderLoop::isRun() const {
} }
void QH::AsyncRenderLoop::renderLoopPrivate() { void QH::AsyncRenderLoop::renderLoopPrivate() {
quint64 currentTime = QDateTime::currentMSecsSinceEpoch(); auto&& currentTime = std::chrono::high_resolution_clock::now();
_lastIterationTime = currentTime; _lastIterationTime = currentTime;
int iterationTime = 0; int iterationTime = 0;
@ -51,8 +49,8 @@ void QH::AsyncRenderLoop::renderLoopPrivate() {
while (m_run) { while (m_run) {
renderIteration(iterationTime); renderIteration(iterationTime);
currentTime = QDateTime::currentMSecsSinceEpoch(); currentTime = std::chrono::high_resolution_clock::now();
iterationTime = currentTime - _lastIterationTime; iterationTime = std::chrono::duration_cast<std::chrono::microseconds>(currentTime - _lastIterationTime).count();
_lastIterationTime = currentTime; _lastIterationTime = currentTime;
} }
} }

View File

@ -64,18 +64,18 @@ protected:
/** /**
* @brief renderIteration This method is called in each iteration of the render loop. * @brief renderIteration This method is called in each iteration of the render loop.
* This method must be implemented in the derived class. * This method must be implemented in the derived class.
* @param msec time in milliseconds from the last iteration. * @param mmsec time in microseconds from the last iteration.
* @see stop * @see stop
* @see run * @see run
*/ */
virtual void renderIteration(int msec) = 0; virtual void renderIteration(int mmsec) = 0;
private slots: private slots:
void renderLoopPrivate(); void renderLoopPrivate();
private: private:
bool m_run = false; bool m_run = false;
quint64 _lastIterationTime = 0; std::chrono::time_point<std::chrono::high_resolution_clock> _lastIterationTime;
}; };
} }