Heart
1.4.918.d927d9c
Heart is base back end library for your c++ Qt projects.
Toggle main menu visibility
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
12
namespace
QH
{
13
14
AsyncRenderLoop::AsyncRenderLoop
(QThread *thread):
Async
(thread) {
15
}
16
17
AsyncRenderLoop::~AsyncRenderLoop
() {
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"
);
22
AsyncRenderLoop::stop
();
23
24
delete
thread();
25
26
}
27
28
void
QH::AsyncRenderLoop::run
() {
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
44
void
QH::AsyncRenderLoop::stop
() {
45
if
(
isRun
()) {
46
m_run =
false
;
47
thread()->quit();
48
thread()->wait();
49
}
50
51
}
52
53
bool
AsyncRenderLoop::isRun
()
const
{
54
return
m_run && (thread() && thread()->isRunning());
55
}
56
57
void
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.h
QH::AsyncRenderLoop::AsyncRenderLoop
AsyncRenderLoop(QThread *thread)
Definition
asyncrenderloop.cpp:14
QH::AsyncRenderLoop::stop
virtual void stop()
stop This method stops the render loop.
Definition
asyncrenderloop.cpp:44
QH::AsyncRenderLoop::run
virtual void run()
run This method starts the render loop.
Definition
asyncrenderloop.cpp:28
QH::AsyncRenderLoop::~AsyncRenderLoop
~AsyncRenderLoop()
Definition
asyncrenderloop.cpp:17
QH::AsyncRenderLoop::isRun
bool isRun() const
isRun This method returns the state of the render loop.
Definition
asyncrenderloop.cpp:53
QH::Async::Async
Async(QThread *thread)
Async This is default constructor of the async object.
Definition
async.cpp:38
QH::Async::asyncLauncher
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
QH
The QH namespace - QuasarApp Heart namespace. This namespace contains all classes of the Heart librar...
Definition
heart.cpp:13
src
public
asyncrenderloop.cpp
Generated by
1.18.0