spo/simulator_SIC_XE/gui/qt/MachineController.cpp
2025-11-12 19:05:16 +01:00

32 lines
661 B
C++

#include "MachineController.h"
#include <chrono>
MachineController::MachineController(QObject *parent)
: QObject(parent)
{
}
MachineController::~MachineController() {
stop();
}
void MachineController::start() {
if (m_running.exchange(true)) return;
m_thread = std::thread([this]{ runLoop(); });
}
void MachineController::stop() {
if (!m_running.exchange(false)) return;
if (m_thread.joinable()) m_thread.join();
}
void MachineController::step() {
emit tick();
}
void MachineController::runLoop() {
while (m_running.load()) {
emit tick();
std::this_thread::sleep_for(std::chrono::milliseconds(100));
}
}