4
1
mirror of https://github.com/QuasarApp/Heart.git synced 2025-05-11 08:59:41 +00:00

Merge pull request from QuasarApp/quasar_app_games_fixes

Quasarapp games fixes
This commit is contained in:
Andrei Yankovich 2025-02-02 17:11:12 +01:00 committed by GitHub
commit 1588d125f6
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 22 additions and 18 deletions

@ -94,7 +94,7 @@ bool Async::asyncLauncher(const Async::Job &job, bool await, bool freaze) const
return QMetaObject::invokeMethod(const_cast<Async*>(this),
"asyncHandler",
Qt::QueuedConnection,
Q_ARG(QH::Async::Job, job));
Q_ARG(QH::Async::Job, std::move(job)));
}
bool workOfEnd = false, workResult = false;
@ -102,7 +102,7 @@ bool Async::asyncLauncher(const Async::Job &job, bool await, bool freaze) const
bool invockeResult = QMetaObject::invokeMethod(const_cast<Async*>(this),
"asyncHandler",
Qt::QueuedConnection,
Q_ARG(QH::Async::Job, job),
Q_ARG(QH::Async::Job, std::move(job)),
Q_ARG(bool*, &workOfEnd),
Q_ARG(bool*, &workResult));

@ -6,38 +6,42 @@
*/
#include "asyncrenderloop.h"
#include <QDateTime>
#include <QThread>
namespace QH {
AsyncRenderLoop::AsyncRenderLoop(QThread *thread, QObject *ptr): Async(thread, ptr) {
}
AsyncRenderLoop::~AsyncRenderLoop() {
stop();
AsyncRenderLoop::stop();
}
void QH::AsyncRenderLoop::run() {
m_run = true;
asyncLauncher([this](){
renderLoopPrivate();
return true;
});
if (auto && thrd = thread()) {
m_run = true;
thrd->start();
asyncLauncher([this](){
renderLoopPrivate();
return true;
});
}
}
void QH::AsyncRenderLoop::stop() {
m_run = false;
thread()->quit();
thread()->wait();
}
bool AsyncRenderLoop::isRun() const {
return m_run || (thread() && thread()->isRunning());
return m_run && (thread() && thread()->isRunning());
}
void QH::AsyncRenderLoop::renderLoopPrivate() {
quint64 currentTime = QDateTime::currentMSecsSinceEpoch();
auto&& currentTime = std::chrono::high_resolution_clock::now();
_lastIterationTime = currentTime;
int iterationTime = 0;
@ -45,8 +49,8 @@ void QH::AsyncRenderLoop::renderLoopPrivate() {
while (m_run) {
renderIteration(iterationTime);
currentTime = QDateTime::currentMSecsSinceEpoch();
iterationTime = currentTime - _lastIterationTime;
currentTime = std::chrono::high_resolution_clock::now();
iterationTime = std::chrono::duration_cast<std::chrono::microseconds>(currentTime - _lastIterationTime).count();
_lastIterationTime = currentTime;
}
}

@ -51,7 +51,7 @@ public:
/**
* @brief stop This method stops the render loop.
*/
virtual void stop();
void stop();
/**
* @brief isRun This method returns the state of the render loop.
@ -64,18 +64,18 @@ protected:
/**
* @brief renderIteration This method is called in each iteration of the render loop.
* This method must be implemented in the derived class.
* @param msec time in milliseconds from the last iteration.
* @param mmsec time in microseconds from the last iteration.
* @see stop
* @see run
*/
virtual void renderIteration(int msec) = 0;
virtual void renderIteration(int mmsec) = 0;
private slots:
void renderLoopPrivate();
private:
bool m_run = false;
quint64 _lastIterationTime = 0;
std::chrono::time_point<std::chrono::high_resolution_clock> _lastIterationTime;
};
}