Heart 1.4.918.d927d9c
Heart is base back end library for your c++ Qt projects.
Loading...
Searching...
No Matches
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): Async(thread) {
15}
16
18
19 Q_ASSERT_X(!isRun(), __FUNCTION__, "try to delete runned render loop! Please stop before delete."
20 "If you the SharedPointer,"
21 " it should be stoped monualy Or You can use AsyncRenderLoop::MainSharedPtr class");
23
24 delete thread();
25
26}
27
29 if (isRun())
30 return ;
31
32 if (auto && thrd = thread()) {
33 m_run = true;
34 thrd->start();
35
36 asyncLauncher([this](){
37 renderLoopPrivate();
38 return true;
39 });
40 }
41
42}
43
45 if (isRun()) {
46 m_run = false;
47 thread()->quit();
48 thread()->wait();
49 }
50
51}
52
54 return m_run && (thread() && thread()->isRunning());
55}
56
57void QH::AsyncRenderLoop::renderLoopPrivate() {
58 auto&& currentTime = std::chrono::high_resolution_clock::now();
59
60 _lastIterationTime = currentTime;
61 int iterationTime = 0;
62
63 while (m_run) {
64 renderIteration(iterationTime);
65
66 currentTime = std::chrono::high_resolution_clock::now();
67 iterationTime = std::chrono::duration_cast<std::chrono::microseconds>(currentTime - _lastIterationTime).count();
68 _lastIterationTime = currentTime;
69 }
70}
71
72} // namespace QH
AsyncRenderLoop(QThread *thread)
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.
Async(QThread *thread)
Async This is default constructor of the async object.
Definition async.cpp:38
bool asyncLauncher(const Job &job, bool await=false, bool freaze=true) const
asyncLauncher This method invoke a job on the thread (using the asyncHandler method) of this object.
Definition async.cpp:78
The QH namespace - QuasarApp Heart namespace. This namespace contains all classes of the Heart librar...
Definition heart.cpp:13