Heart 1.3.880.d32293b
Heart is base back end library for your c++ Qt projects.
asyncrenderloop.h
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#ifndef ASYNCRENDERLOOP_H
9#define ASYNCRENDERLOOP_H
10
11#include "async.h"
12
13namespace QH {
14
59{
60
61 Q_OBJECT
62public:
63
71 template<typename T>
73 public:
75 static_assert(std::is_base_of_v<AsyncRenderLoop, T>,
76 "T must be derived from AsyncRenderLoop");
77 }
78
79 MainSharedPtr(const QSharedPointer<T>& ptr): _ptr(ptr) {
80 static_assert(std::is_base_of_v<AsyncRenderLoop, T>,
81 "T must be derived from AsyncRenderLoop");
82 }
84 if (_ptr) {
85 _ptr->stop();
86 }
87 }
88
89 T* operator->() const {
90 return _ptr.operator->();
91 }
92
97 T* get() const {
98 return _ptr.get();
99 }
100
106 template <typename... Args>
107 [[nodiscard]] static MainSharedPtr create(Args && ...arguments) {
108 return MainSharedPtr(QSharedPointer<T>::create(std::forward<Args>(arguments)...));
109 }
110
115 const QSharedPointer<T>& getShared() const {
116 return _ptr;
117 }
118
119 private:
120 QSharedPointer<T> _ptr;
121 };
122
123
124 AsyncRenderLoop(QThread* thread, QObject* ptr = nullptr);
126
130 virtual void run();
131
135 void stop();
136
141 bool isRun() const;
142
150 template<typename Type, typename... Args>
151 static MainSharedPtr<Type> createMainPtr(Args && ...arguments) {
152 return MainSharedPtr<Type>(QSharedPointer<Type>::create(std::forward<Args>(arguments)...));
153 };
154
155protected:
156
164 virtual void renderIteration(int mmsec) = 0;
165
166private slots:
167 void renderLoopPrivate();
168
169private:
170 bool m_run = false;
171 std::chrono::time_point<std::chrono::high_resolution_clock> _lastIterationTime;
172
173};
174}
175
176#endif // ASYNCRENDERLOOP_H
The MainSharedPtr class is a helper class for creating a shared pointer to the render loop.
MainSharedPtr(const QSharedPointer< T > &ptr)
static MainSharedPtr create(Args &&...arguments)
create This method creates a shared pointer to the render loop.
const QSharedPointer< T > & getShared() const
getShared This method return child shared pointer. You can use them as a general shared pointer of th...
T * get() const
get This is a alias of the QSharedPointer::get method.
The AsyncRenderLoop is a class for asynchronous rendering. This class is used to create a render loop...
virtual void renderIteration(int mmsec)=0
renderIteration This method is called in each iteration of the render loop. This method must be imple...
static MainSharedPtr< Type > createMainPtr(Args &&...arguments)
createMainPtr This method creates a shared pointer to the render loop.
The Async class This is bundle of async templates and async wrappers.
Definition async.h:25
#define HEARTSHARED_EXPORT
The QH namespace - QuasarApp Heart namespace. This namespace contains all classes of the Heart librar...
Definition heart.cpp:13