qol
This commit is contained in:
parent
43c8fb2cce
commit
42737c0a66
5 changed files with 107 additions and 18 deletions
|
|
@ -1,9 +1,14 @@
|
|||
#include "MachineController.h"
|
||||
#include "../../include/machine.h"
|
||||
#include <chrono>
|
||||
#include <QDebug>
|
||||
|
||||
MachineController::MachineController(QObject *parent)
|
||||
: QObject(parent)
|
||||
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>();
|
||||
}
|
||||
}
|
||||
|
||||
MachineController::~MachineController() {
|
||||
|
|
@ -21,12 +26,30 @@ void MachineController::stop() {
|
|||
}
|
||||
|
||||
void MachineController::step() {
|
||||
emit tick();
|
||||
try {
|
||||
if (m_machine) {
|
||||
m_machine->execute();
|
||||
m_machine->tick();
|
||||
emit tick();
|
||||
}
|
||||
} catch (const std::exception &e) {
|
||||
emit error(QString::fromStdString(e.what()));
|
||||
}
|
||||
}
|
||||
|
||||
void MachineController::runLoop() {
|
||||
while (m_running.load()) {
|
||||
emit tick();
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(100));
|
||||
try {
|
||||
if (m_machine) {
|
||||
m_machine->execute();
|
||||
m_machine->tick();
|
||||
emit tick();
|
||||
}
|
||||
} catch (const std::exception &e) {
|
||||
emit error(QString::fromStdString(e.what()));
|
||||
// Stop on fatal error
|
||||
m_running.store(false);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue