Heart 1.3.880.d32293b
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#include <qdebug.h>
11
12namespace QH {
13
14AsyncRenderLoop::AsyncRenderLoop(QThread *thread, QObject *ptr): Async(thread, ptr) {
15}
16
18
19#ifdef QT_DEBUG
20 Q_ASSERT_X(!isRun(), __FUNCTION__, "try to delete runned render loop! Please stop before delete."
21 "If you the SharedPointer,"
22 " it should be stoped monualy Or You can use AsyncRenderLoop::MainSharedPtr class");
23#endif
25
26 delete thread();
27
28}
29
31 if (auto && thrd = thread()) {
32 m_run = true;
33 thrd->start();
34
35 asyncLauncher([this](){
36 renderLoopPrivate();
37 return true;
38 });
39 }
40
41}
42
44 if (isRun()) {
45 m_run = false;
46 thread()->quit();
47 thread()->wait();
48 }
49
50}
51
53 return m_run && (thread() && thread()->isRunning());
54}
55
56void QH::AsyncRenderLoop::renderLoopPrivate() {
57 auto&& currentTime = std::chrono::high_resolution_clock::now();
58
59 _lastIterationTime = currentTime;
60 int iterationTime = 0;
61
62 while (m_run) {
63 renderIteration(iterationTime);
64
65 currentTime = std::chrono::high_resolution_clock::now();
66 iterationTime = std::chrono::duration_cast<std::chrono::microseconds>(currentTime - _lastIterationTime).count();
67 _lastIterationTime = currentTime;
68 }
69}
70
71} // 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