mirror of
https://github.com/QuasarApp/Heart.git
synced 2025-05-11 08:59:41 +00:00
Merge pull request #77 from QuasarApp/quasar_app_games_fixes
Quasarapp games fixes
This commit is contained in:
commit
1588d125f6
@ -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;
|
||||
|
||||
};
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user