mirror of
https://github.com/QuasarApp/Heart.git
synced 2025-05-17 03:49:41 +00:00
52 lines
1.2 KiB
C++
52 lines
1.2 KiB
C++
|
/*
|
||
|
* 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
|