diff --git a/OSBindings/Qt/mainwindow.cpp b/OSBindings/Qt/mainwindow.cpp index 7ec363529..ad9e13d4d 100644 --- a/OSBindings/Qt/mainwindow.cpp +++ b/OSBindings/Qt/mainwindow.cpp @@ -7,6 +7,7 @@ #include "../../Numeric/CRC.hpp" + /* General Qt implementation notes: @@ -35,11 +36,6 @@ MainWindow::MainWindow(QWidget *parent) connect(qTimer.get(), SIGNAL(timeout()), timer.get(), SLOT(tick())); - // Start the thread and timer. - // TODO: not until there's actually something to display. - timerThread->start(); - qTimer->start(); - // Hide the missing ROMs box unless or until it's needed; grab the text it // began with as a prefix for future mutation. ui->missingROMsBox->setVisible(false); @@ -144,12 +140,26 @@ void MainWindow::launchMachine() { std::unique_ptr machine(Machine::MachineForTargets(targets, rom_fetcher, error)); switch(error) { - default: + default: { ui->missingROMsBox->setVisible(false); uiPhase = UIPhase::RunningMachine; - // TODO: launch machine. - break; + // TODO: Install the OpenGL scan target. + // This is subject to having created an OpenGL context. +// const auto scan_producer = machine->scan_producer(); +// if(scan_producer) { +// scan_producer->set_scan_target(&scanTarget); +// } + + // If this is a timed machine, start up the timer. + const auto timedMachine = machine->timed_machine(); + if(timedMachine) { + timer->setMachine(timedMachine); + timerThread->start(); + qTimer->start(); + } + + } break; case Machine::Error::MissingROM: { ui->missingROMsBox->setVisible(true); diff --git a/OSBindings/Qt/mainwindow.h b/OSBindings/Qt/mainwindow.h index 819e56323..e3fa28c79 100644 --- a/OSBindings/Qt/mainwindow.h +++ b/OSBindings/Qt/mainwindow.h @@ -8,6 +8,7 @@ #include "../../Analyser/Static/StaticAnalyser.hpp" #include "../../Machines/Utility/MachineForTarget.hpp" +#include "../../Outputs/OpenGL/ScanTarget.hpp" QT_BEGIN_NAMESPACE namespace Ui { class MainWindow; } @@ -42,6 +43,9 @@ class MainWindow : public QMainWindow { void dragEnterEvent(QDragEnterEvent* event) override; void dropEvent(QDropEvent* event) override; + // Output. + Outputs::Display::OpenGL::ScanTarget scanTarget; + private slots: void open(); }; diff --git a/OSBindings/Qt/timer.cpp b/OSBindings/Qt/timer.cpp index 74984f84f..157a97137 100644 --- a/OSBindings/Qt/timer.cpp +++ b/OSBindings/Qt/timer.cpp @@ -2,13 +2,19 @@ #include "../../ClockReceiver/TimeTypes.hpp" +#include #include Timer::Timer(QObject *parent) : QObject(parent) {} -void Timer::tick() { -// static int64_t last = 0; -// const auto now = Time::nanos_now(); -// qDebug() << now - last; -// last = now; +void Timer::setMachine(MachineTypes::TimedMachine *machine) { + this->machine = machine; +} + +void Timer::tick() { + const auto now = Time::nanos_now(); + const auto duration = std::min(now - lastTickNanos, int64_t(500'000)); + lastTickNanos = now; + + machine->run_for(double(duration) / 1e9); } diff --git a/OSBindings/Qt/timer.h b/OSBindings/Qt/timer.h index c137332b6..abc6b8c9d 100644 --- a/OSBindings/Qt/timer.h +++ b/OSBindings/Qt/timer.h @@ -3,15 +3,22 @@ #include +#include "../../Machines/Utility/MachineForTarget.hpp" + class Timer : public QObject { Q_OBJECT public: explicit Timer(QObject *parent = nullptr); + void setMachine(MachineTypes::TimedMachine *machine); public slots: void tick(); + + private: + MachineTypes::TimedMachine *machine = nullptr; + int64_t lastTickNanos = 0; }; #endif // TIMER_H