Heart 1.3.879.d03aaa4
Heart is base back end library for your c++ Qt projects.
QH::AsyncRenderLoop Class Referenceabstract

The AsyncRenderLoop is a class for asynchronous rendering. This class is used to create a render loop that is executed in a separate thread. To use this class, you must inherit from it and implement the renderIteration method. example: : More...

#include <asyncrenderloop.h>

Inheritance diagram for QH::AsyncRenderLoop:
Inheritance graph
Collaboration diagram for QH::AsyncRenderLoop:
Collaboration graph

Classes

class  MainSharedPtr
 The MainSharedPtr class is a helper class for creating a shared pointer to the render loop. More...
 

Public Member Functions

 AsyncRenderLoop (QThread *thread, QObject *ptr=nullptr)
 
 ~AsyncRenderLoop ()
 
virtual void run ()
 run This method starts the render loop.
 
void stop ()
 stop This method stops the render loop.
 
bool isRun () const
 isRun This method returns the state of the render loop.
 
- Public Member Functions inherited from QH::Async
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.
 

Static Public Member Functions

template<typename Type , typename... Args>
static MainSharedPtr< Type > createMainPtr (Args &&...arguments)
 createMainPtr This method creates a shared pointer to the render loop.
 

Protected Member Functions

virtual void renderIteration (int mmsec)=0
 renderIteration This method is called in each iteration of the render loop. This method must be implemented in the derived class.
 
- Protected Member Functions inherited from QH::Async
 Async (QThread *thread, QObject *ptr=nullptr)
 Async This is default constructor of the async object.
 
 ~Async ()
 
bool waitFor (bool *condition, int timeout=WAIT_TIME, bool freaze=true) const
 waitFor This is base wait function.
 
bool waitFor (const Job &condition, int timeout=WAIT_TIME, bool freaze=true) const
 waitFor This is base wait function.
 

Additional Inherited Members

- Public Types inherited from QH::Async
using Job = std::function< bool()>
 

Detailed Description

The AsyncRenderLoop is a class for asynchronous rendering. This class is used to create a render loop that is executed in a separate thread. To use this class, you must inherit from it and implement the renderIteration method. example: :

class MyRenderLoop: public AsyncRenderLoop
{
public:
MyRenderLoop(QThread* thread, QObject* ptr = nullptr): AsyncRenderLoop(thread, ptr) {}
void renderIteration(int msec) override {
// your code here
}
};
int main (int argc, char* argv[]) {
QCoreApplication app(argc, argv);
MyRenderLoop loop(new thread());
loop.run();
loop.stop();
return app.exec();
The AsyncRenderLoop is a class for asynchronous rendering. This class is used to create a render loop...
Warning
This class may be broken if you use it as a QSharedPointer and push WeackPointer to the child objects. To solve this issue use the AsyncRenderLoop::MainSharedPtr class.

Example:

class MyRenderLoop: public AsyncRenderLoop
{
...
};
int main (int argc, char* argv[]) {
auto loop = QSharedPointer<MyRenderLoop>(new MyRenderLoop(new QThread())); // wrong! it will be broken
auto loop = MyRenderLoop::MainSharedPtr<MyRenderLoop>>(new QThread()); // right!
auto loop = MyRenderLoop::createMainPtr<MyRenderLoop>(new QThread()); // this is short version of initialization Main pointer
...
return app.exec();
}

Definition at line 58 of file asyncrenderloop.h.

Constructor & Destructor Documentation

◆ AsyncRenderLoop()

QH::AsyncRenderLoop::AsyncRenderLoop ( QThread *  thread,
QObject *  ptr = nullptr 
)

Definition at line 14 of file asyncrenderloop.cpp.

◆ ~AsyncRenderLoop()

QH::AsyncRenderLoop::~AsyncRenderLoop ( )

Definition at line 17 of file asyncrenderloop.cpp.

Here is the call graph for this function:

Member Function Documentation

◆ createMainPtr()

template<typename Type , typename... Args>
static MainSharedPtr< Type > QH::AsyncRenderLoop::createMainPtr ( Args &&...  arguments)
inlinestatic

createMainPtr This method creates a shared pointer to the render loop.

Template Parameters
Typetype of the render loop object.
Argsarguments for the constructor of the render loop object.
Parameters
argumentsarguments for the constructor of the render loop object.
Returns
shared pointer to the render loop.

Definition at line 151 of file asyncrenderloop.h.

◆ isRun()

bool QH::AsyncRenderLoop::isRun ( ) const

isRun This method returns the state of the render loop.

Returns
true if the render loop is running, else false.

Definition at line 52 of file asyncrenderloop.cpp.

Here is the caller graph for this function:

◆ renderIteration()

virtual void QH::AsyncRenderLoop::renderIteration ( int  mmsec)
protectedpure virtual

renderIteration This method is called in each iteration of the render loop. This method must be implemented in the derived class.

Parameters
mmsectime in microseconds from the last iteration.
See also
stop
run

◆ run()

void QH::AsyncRenderLoop::run ( )
virtual

run This method starts the render loop.

Definition at line 30 of file asyncrenderloop.cpp.

◆ stop()

void QH::AsyncRenderLoop::stop ( )

stop This method stops the render loop.

Definition at line 43 of file asyncrenderloop.cpp.

Here is the caller graph for this function:

The documentation for this class was generated from the following files: