qmlfrontend/game_view.cpp
changeset 16017 e8afb1bf2779
parent 16015 0e90bdfc2642
--- a/qmlfrontend/game_view.cpp	Mon May 20 14:58:30 2024 +0200
+++ b/qmlfrontend/game_view.cpp	Tue May 21 14:38:30 2024 +0200
@@ -64,21 +64,16 @@
     m_gameViewSize = currentSize;
     m_dirty = true;
   }
+
+  m_gameView->executeActions();
 }
 
-GameView::GameView(QQuickItem* parent)
-    : QQuickFramebufferObject(parent), m_delta(0) {
+GameView::GameView(QQuickItem* parent) : QQuickFramebufferObject(parent) {
   setMirrorVertically(true);
 }
 
 void GameView::tick(quint32 delta) {
-  m_delta = delta;
-
-  if (window()) {
-    QTimer* timer = new QTimer(this);
-    connect(timer, &QTimer::timeout, this, &GameView::update);
-    timer->start(100);
-  }
+  addAction([delta](auto engine) { engine->advance(delta); });
 }
 
 EngineInstance* GameView::engineInstance() const { return m_engineInstance; }
@@ -87,6 +82,18 @@
   return new GameViewRenderer{};
 }
 
+void GameView::executeActions() {
+  if (!m_engineInstance) {
+    return;
+  }
+
+  for (const auto& action : m_actions) {
+    action(m_engineInstance);
+  }
+
+  m_actions.clear();
+}
+
 void GameView::setEngineInstance(EngineInstance* engineInstance) {
   if (m_engineInstance == engineInstance) {
     return;
@@ -96,3 +103,7 @@
 
   Q_EMIT engineInstanceChanged(m_engineInstance);
 }
+
+void GameView::addAction(std::function<void(EngineInstance*)>&& action) {
+  m_actions.append(std::move(action));
+}