62 if (const auto currentSize = m_gameView->size(); |
62 if (const auto currentSize = m_gameView->size(); |
63 currentSize != m_gameViewSize) { |
63 currentSize != m_gameViewSize) { |
64 m_gameViewSize = currentSize; |
64 m_gameViewSize = currentSize; |
65 m_dirty = true; |
65 m_dirty = true; |
66 } |
66 } |
|
67 |
|
68 m_gameView->executeActions(); |
67 } |
69 } |
68 |
70 |
69 GameView::GameView(QQuickItem* parent) |
71 GameView::GameView(QQuickItem* parent) : QQuickFramebufferObject(parent) { |
70 : QQuickFramebufferObject(parent), m_delta(0) { |
|
71 setMirrorVertically(true); |
72 setMirrorVertically(true); |
72 } |
73 } |
73 |
74 |
74 void GameView::tick(quint32 delta) { |
75 void GameView::tick(quint32 delta) { |
75 m_delta = delta; |
76 addAction([delta](auto engine) { engine->advance(delta); }); |
76 |
|
77 if (window()) { |
|
78 QTimer* timer = new QTimer(this); |
|
79 connect(timer, &QTimer::timeout, this, &GameView::update); |
|
80 timer->start(100); |
|
81 } |
|
82 } |
77 } |
83 |
78 |
84 EngineInstance* GameView::engineInstance() const { return m_engineInstance; } |
79 EngineInstance* GameView::engineInstance() const { return m_engineInstance; } |
85 |
80 |
86 QQuickFramebufferObject::Renderer* GameView::createRenderer() const { |
81 QQuickFramebufferObject::Renderer* GameView::createRenderer() const { |
87 return new GameViewRenderer{}; |
82 return new GameViewRenderer{}; |
|
83 } |
|
84 |
|
85 void GameView::executeActions() { |
|
86 if (!m_engineInstance) { |
|
87 return; |
|
88 } |
|
89 |
|
90 for (const auto& action : m_actions) { |
|
91 action(m_engineInstance); |
|
92 } |
|
93 |
|
94 m_actions.clear(); |
88 } |
95 } |
89 |
96 |
90 void GameView::setEngineInstance(EngineInstance* engineInstance) { |
97 void GameView::setEngineInstance(EngineInstance* engineInstance) { |
91 if (m_engineInstance == engineInstance) { |
98 if (m_engineInstance == engineInstance) { |
92 return; |
99 return; |