equal
deleted
inserted
replaced
1 #ifndef GAMEVIEW_H |
1 #ifndef GAMEVIEW_H |
2 #define GAMEVIEW_H |
2 #define GAMEVIEW_H |
3 |
3 |
4 #include <QQuickItem> |
|
5 |
|
6 #include <QPointer> |
4 #include <QPointer> |
|
5 #include <QQuickFramebufferObject> |
7 #include <QScopedPointer> |
6 #include <QScopedPointer> |
8 #include <QtGui/QOpenGLFunctions> |
|
9 #include <QtGui/QOpenGLShaderProgram> |
|
10 |
7 |
11 #include "engine_instance.h" |
8 #include "engine_instance.h" |
12 |
9 |
13 class GameViewRenderer : public QObject, protected QOpenGLFunctions { |
10 class GameView : public QQuickFramebufferObject { |
14 Q_OBJECT |
|
15 public: |
|
16 explicit GameViewRenderer(); |
|
17 ~GameViewRenderer() override; |
|
18 |
|
19 void tick(quint32 delta); |
|
20 void setEngineInstance(EngineInstance* engineInstance); |
|
21 |
|
22 public slots: |
|
23 void paint(); |
|
24 void onViewportSizeChanged(QQuickWindow* window); |
|
25 |
|
26 private: |
|
27 quint32 m_delta; |
|
28 QPointer<EngineInstance> m_engineInstance; |
|
29 }; |
|
30 |
|
31 class GameView : public QQuickItem { |
|
32 Q_OBJECT |
11 Q_OBJECT |
33 |
12 |
34 Q_PROPERTY(EngineInstance* engineInstance READ engineInstance WRITE |
13 Q_PROPERTY(EngineInstance* engineInstance READ engineInstance WRITE |
35 setEngineInstance NOTIFY engineInstanceChanged) |
14 setEngineInstance NOTIFY engineInstanceChanged) |
36 |
15 |
38 explicit GameView(QQuickItem* parent = nullptr); |
17 explicit GameView(QQuickItem* parent = nullptr); |
39 |
18 |
40 Q_INVOKABLE void tick(quint32 delta); |
19 Q_INVOKABLE void tick(quint32 delta); |
41 |
20 |
42 EngineInstance* engineInstance() const; |
21 EngineInstance* engineInstance() const; |
|
22 Renderer* createRenderer() const override; |
|
23 void executeActions(); |
43 |
24 |
44 signals: |
25 Q_SIGNALS: |
45 void engineInstanceChanged(EngineInstance* engineInstance); |
26 void engineInstanceChanged(EngineInstance* engineInstance); |
46 |
27 |
47 public slots: |
28 public Q_SLOTS: |
48 void sync(); |
|
49 void cleanup(); |
|
50 void setEngineInstance(EngineInstance* engineInstance); |
29 void setEngineInstance(EngineInstance* engineInstance); |
51 |
30 |
52 private slots: |
|
53 void handleWindowChanged(QQuickWindow* win); |
|
54 |
|
55 private: |
31 private: |
56 quint32 m_delta; |
|
57 QScopedPointer<GameViewRenderer> m_renderer; |
|
58 bool m_windowChanged; |
|
59 QPointer<EngineInstance> m_engineInstance; |
32 QPointer<EngineInstance> m_engineInstance; |
60 QSize m_viewportSize; |
33 QSize m_viewportSize; |
61 QPoint m_centerPoint; |
34 QPoint m_centerPoint; |
|
35 QList<std::function<void(EngineInstance*)>> m_actions; |
|
36 |
|
37 void addAction(std::function<void(EngineInstance*)>&& action); |
62 }; |
38 }; |
63 |
39 |
64 #endif // GAMEVIEW_H |
40 #endif // GAMEVIEW_H |