Heart/src/public/asyncrenderloop.cpp

52 lines
1.2 KiB
C++
Raw Normal View History

2025-01-20 10:04:23 +01:00
/*
* Copyright (C) 2025-2025 QuasarApp.
* Distributed under the lgplv3 software license, see the accompanying
* Everyone is permitted to copy and distribute verbatim copies
* of this license document, but changing it is not allowed.
*/
#include "asyncrenderloop.h"
#include <QDateTime>
#include <QThread>
namespace QH {
AsyncRenderLoop::AsyncRenderLoop(QThread *thread, QObject *ptr): Async(thread, ptr) {
}
void QH::AsyncRenderLoop::run() {
m_run = true;
asyncLauncher([this](){
renderLoopPrivate();
return true;
});
}
void QH::AsyncRenderLoop::stop() {
m_run = false;
thread()->exit();
thread()->wait();
}
bool AsyncRenderLoop::isRun() const {
return m_run || (thread() && thread()->isRunning());
}
void QH::AsyncRenderLoop::renderLoopPrivate() {
quint64 currentTime = QDateTime::currentMSecsSinceEpoch();
_lastIterationTime = currentTime;
int iterationTime = 0;
while (m_run) {
renderIteration(iterationTime);
currentTime = QDateTime::currentMSecsSinceEpoch();
iterationTime = currentTime - _lastIterationTime;
_lastIterationTime = currentTime;
}
}
} // namespace QH