Heart 1.3.851.58f1cb2
Heart is base back end library for your c++ Qt projects.
asyncrenderloop.cpp
Go to the documentation of this file.
1/*
2 * Copyright (C) 2025-2025 QuasarApp.
3 * Distributed under the lgplv3 software license, see the accompanying
4 * Everyone is permitted to copy and distribute verbatim copies
5 * of this license document, but changing it is not allowed.
6*/
7
8#include "asyncrenderloop.h"
9#include <QDateTime>
10#include <QThread>
11
12namespace QH {
13
14AsyncRenderLoop::AsyncRenderLoop(QThread *thread, QObject *ptr): Async(thread, ptr) {
15
16}
17
21
23 m_run = true;
24 asyncLauncher([this](){
25 renderLoopPrivate();
26 return true;
27 });
28}
29
31 m_run = false;
32 thread()->wait();
33}
34
36 return m_run || (thread() && thread()->isRunning());
37}
38
39void QH::AsyncRenderLoop::renderLoopPrivate() {
40 quint64 currentTime = QDateTime::currentMSecsSinceEpoch();
41
42 _lastIterationTime = currentTime;
43 int iterationTime = 0;
44
45 while (m_run) {
46 renderIteration(iterationTime);
47
48 currentTime = QDateTime::currentMSecsSinceEpoch();
49 iterationTime = currentTime - _lastIterationTime;
50 _lastIterationTime = currentTime;
51 }
52}
53
54} // namespace QH
virtual void stop()
stop This method stops the render loop.
virtual void run()
run This method starts the render loop.
bool isRun() const
isRun This method returns the state of the render loop.
AsyncRenderLoop(QThread *thread, QObject *ptr=nullptr)
The Async class This is bundle of async templates and async wrappers.
Definition async.h:25
The QH namespace - QuasarApp Heart namespace. This namespace contains all classes of the Heart librar...
Definition heart.cpp:13