Heart 1.3.864.4bd6f7b
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 <QThread>
10
11namespace QH {
12
13AsyncRenderLoop::AsyncRenderLoop(QThread *thread, QObject *ptr): Async(thread, ptr) {
14}
15
19
21 if (auto && thrd = thread()) {
22 m_run = true;
23 thrd->start();
24
25 asyncLauncher([this](){
26 renderLoopPrivate();
27 return true;
28 });
29 }
30
31}
32
34 m_run = false;
35 thread()->quit();
36 thread()->wait();
37}
38
40 return m_run && (thread() && thread()->isRunning());
41}
42
43void QH::AsyncRenderLoop::renderLoopPrivate() {
44 auto&& currentTime = std::chrono::high_resolution_clock::now();
45
46 _lastIterationTime = currentTime;
47 int iterationTime = 0;
48
49 while (m_run) {
50 renderIteration(iterationTime);
51
52 currentTime = std::chrono::high_resolution_clock::now();
53 iterationTime = std::chrono::duration_cast<std::chrono::microseconds>(currentTime - _lastIterationTime).count();
54 _lastIterationTime = currentTime;
55 }
56}
57
58} // namespace QH
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