final version
This commit is contained in:
parent
098766bb65
commit
042bae9089
8 changed files with 143 additions and 21 deletions
|
|
@ -3,12 +3,15 @@
|
|||
#include <chrono>
|
||||
#include <QDebug>
|
||||
|
||||
using namespace std::chrono;
|
||||
|
||||
MachineController::MachineController(std::shared_ptr<Machine> machine, QObject *parent)
|
||||
: QObject(parent), m_machine(std::move(machine))
|
||||
{
|
||||
if (!m_machine) {
|
||||
m_machine = std::make_shared<Machine>();
|
||||
}
|
||||
m_lastUpdateTime = steady_clock::now();
|
||||
}
|
||||
|
||||
MachineController::~MachineController() {
|
||||
|
|
@ -38,14 +41,27 @@ void MachineController::step() {
|
|||
}
|
||||
|
||||
void MachineController::runLoop() {
|
||||
const auto minUpdateInterval = milliseconds(16);
|
||||
|
||||
while (m_running.load()) {
|
||||
try {
|
||||
if (m_machine) {
|
||||
m_machine->execute();
|
||||
m_machine->tick();
|
||||
emit tick();
|
||||
m_machine->tick();
|
||||
m_ticksSinceLastUpdate++;
|
||||
|
||||
// Throttle GUI updates to 60 Hz
|
||||
auto now = steady_clock::now();
|
||||
auto elapsed = duration_cast<milliseconds>(now - m_lastUpdateTime);
|
||||
|
||||
if (elapsed >= minUpdateInterval) {
|
||||
emit tick();
|
||||
m_lastUpdateTime = now;
|
||||
m_ticksSinceLastUpdate = 0;
|
||||
}
|
||||
|
||||
if (m_machine->isStopped()) {
|
||||
emit tick();
|
||||
m_running.store(false);
|
||||
break;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue