qmlfrontend/game_view.h
author Wuzzy <Wuzzy2@mail.ru>
Sat, 26 Oct 2019 21:59:42 +0200
changeset 15488 70aba717485a
parent 14847 ef9630519491
permissions -rw-r--r--
Racer: Reposition and resize predefined waypoints in scaled drawn maps Previously, predefined waypoints broke when using any but the default drawn map size.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
14148
745c73e0e644 Start working on frontend to rust engine rewrite
unC0Rr
parents:
diff changeset
     1
#ifndef GAMEVIEW_H
745c73e0e644 Start working on frontend to rust engine rewrite
unC0Rr
parents:
diff changeset
     2
#define GAMEVIEW_H
745c73e0e644 Start working on frontend to rust engine rewrite
unC0Rr
parents:
diff changeset
     3
745c73e0e644 Start working on frontend to rust engine rewrite
unC0Rr
parents:
diff changeset
     4
#include <QQuickItem>
745c73e0e644 Start working on frontend to rust engine rewrite
unC0Rr
parents:
diff changeset
     5
14295
92e5682810d4 Prepare to have possibility to pass opengl context to engine
unc0rr
parents: 14159
diff changeset
     6
#include <QPointer>
92e5682810d4 Prepare to have possibility to pass opengl context to engine
unc0rr
parents: 14159
diff changeset
     7
#include <QScopedPointer>
14148
745c73e0e644 Start working on frontend to rust engine rewrite
unC0Rr
parents:
diff changeset
     8
#include <QtGui/QOpenGLFunctions>
745c73e0e644 Start working on frontend to rust engine rewrite
unC0Rr
parents:
diff changeset
     9
#include <QtGui/QOpenGLShaderProgram>
745c73e0e644 Start working on frontend to rust engine rewrite
unC0Rr
parents:
diff changeset
    10
14295
92e5682810d4 Prepare to have possibility to pass opengl context to engine
unc0rr
parents: 14159
diff changeset
    11
#include "engine_instance.h"
92e5682810d4 Prepare to have possibility to pass opengl context to engine
unc0rr
parents: 14159
diff changeset
    12
14148
745c73e0e644 Start working on frontend to rust engine rewrite
unC0Rr
parents:
diff changeset
    13
class GameViewRenderer : public QObject, protected QOpenGLFunctions {
745c73e0e644 Start working on frontend to rust engine rewrite
unC0Rr
parents:
diff changeset
    14
  Q_OBJECT
745c73e0e644 Start working on frontend to rust engine rewrite
unC0Rr
parents:
diff changeset
    15
 public:
14717
57293f34ce59 Detect and handle resize
unc0rr
parents: 14295
diff changeset
    16
  explicit GameViewRenderer();
57293f34ce59 Detect and handle resize
unc0rr
parents: 14295
diff changeset
    17
  ~GameViewRenderer() override;
14148
745c73e0e644 Start working on frontend to rust engine rewrite
unC0Rr
parents:
diff changeset
    18
14295
92e5682810d4 Prepare to have possibility to pass opengl context to engine
unc0rr
parents: 14159
diff changeset
    19
  void tick(quint32 delta);
92e5682810d4 Prepare to have possibility to pass opengl context to engine
unc0rr
parents: 14159
diff changeset
    20
  void setEngineInstance(EngineInstance* engineInstance);
14148
745c73e0e644 Start working on frontend to rust engine rewrite
unC0Rr
parents:
diff changeset
    21
745c73e0e644 Start working on frontend to rust engine rewrite
unC0Rr
parents:
diff changeset
    22
 public slots:
745c73e0e644 Start working on frontend to rust engine rewrite
unC0Rr
parents:
diff changeset
    23
  void paint();
14717
57293f34ce59 Detect and handle resize
unc0rr
parents: 14295
diff changeset
    24
  void onViewportSizeChanged(QQuickWindow* window);
14148
745c73e0e644 Start working on frontend to rust engine rewrite
unC0Rr
parents:
diff changeset
    25
745c73e0e644 Start working on frontend to rust engine rewrite
unC0Rr
parents:
diff changeset
    26
 private:
745c73e0e644 Start working on frontend to rust engine rewrite
unC0Rr
parents:
diff changeset
    27
  quint32 m_delta;
14295
92e5682810d4 Prepare to have possibility to pass opengl context to engine
unc0rr
parents: 14159
diff changeset
    28
  QPointer<EngineInstance> m_engineInstance;
14148
745c73e0e644 Start working on frontend to rust engine rewrite
unC0Rr
parents:
diff changeset
    29
};
745c73e0e644 Start working on frontend to rust engine rewrite
unC0Rr
parents:
diff changeset
    30
745c73e0e644 Start working on frontend to rust engine rewrite
unC0Rr
parents:
diff changeset
    31
class GameView : public QQuickItem {
745c73e0e644 Start working on frontend to rust engine rewrite
unC0Rr
parents:
diff changeset
    32
  Q_OBJECT
745c73e0e644 Start working on frontend to rust engine rewrite
unC0Rr
parents:
diff changeset
    33
14295
92e5682810d4 Prepare to have possibility to pass opengl context to engine
unc0rr
parents: 14159
diff changeset
    34
  Q_PROPERTY(EngineInstance* engineInstance READ engineInstance WRITE
92e5682810d4 Prepare to have possibility to pass opengl context to engine
unc0rr
parents: 14159
diff changeset
    35
                 setEngineInstance NOTIFY engineInstanceChanged)
92e5682810d4 Prepare to have possibility to pass opengl context to engine
unc0rr
parents: 14159
diff changeset
    36
14148
745c73e0e644 Start working on frontend to rust engine rewrite
unC0Rr
parents:
diff changeset
    37
 public:
14847
ef9630519491 Fix some minor problems with new frontend code
unc0rr
parents: 14718
diff changeset
    38
  explicit GameView(QQuickItem* parent = nullptr);
14148
745c73e0e644 Start working on frontend to rust engine rewrite
unC0Rr
parents:
diff changeset
    39
745c73e0e644 Start working on frontend to rust engine rewrite
unC0Rr
parents:
diff changeset
    40
  Q_INVOKABLE void tick(quint32 delta);
745c73e0e644 Start working on frontend to rust engine rewrite
unC0Rr
parents:
diff changeset
    41
14295
92e5682810d4 Prepare to have possibility to pass opengl context to engine
unc0rr
parents: 14159
diff changeset
    42
  EngineInstance* engineInstance() const;
92e5682810d4 Prepare to have possibility to pass opengl context to engine
unc0rr
parents: 14159
diff changeset
    43
14148
745c73e0e644 Start working on frontend to rust engine rewrite
unC0Rr
parents:
diff changeset
    44
 signals:
14295
92e5682810d4 Prepare to have possibility to pass opengl context to engine
unc0rr
parents: 14159
diff changeset
    45
  void engineInstanceChanged(EngineInstance* engineInstance);
14148
745c73e0e644 Start working on frontend to rust engine rewrite
unC0Rr
parents:
diff changeset
    46
745c73e0e644 Start working on frontend to rust engine rewrite
unC0Rr
parents:
diff changeset
    47
 public slots:
745c73e0e644 Start working on frontend to rust engine rewrite
unC0Rr
parents:
diff changeset
    48
  void sync();
745c73e0e644 Start working on frontend to rust engine rewrite
unC0Rr
parents:
diff changeset
    49
  void cleanup();
14295
92e5682810d4 Prepare to have possibility to pass opengl context to engine
unc0rr
parents: 14159
diff changeset
    50
  void setEngineInstance(EngineInstance* engineInstance);
14148
745c73e0e644 Start working on frontend to rust engine rewrite
unC0Rr
parents:
diff changeset
    51
745c73e0e644 Start working on frontend to rust engine rewrite
unC0Rr
parents:
diff changeset
    52
 private slots:
745c73e0e644 Start working on frontend to rust engine rewrite
unC0Rr
parents:
diff changeset
    53
  void handleWindowChanged(QQuickWindow* win);
745c73e0e644 Start working on frontend to rust engine rewrite
unC0Rr
parents:
diff changeset
    54
745c73e0e644 Start working on frontend to rust engine rewrite
unC0Rr
parents:
diff changeset
    55
 private:
745c73e0e644 Start working on frontend to rust engine rewrite
unC0Rr
parents:
diff changeset
    56
  quint32 m_delta;
14295
92e5682810d4 Prepare to have possibility to pass opengl context to engine
unc0rr
parents: 14159
diff changeset
    57
  QScopedPointer<GameViewRenderer> m_renderer;
14148
745c73e0e644 Start working on frontend to rust engine rewrite
unC0Rr
parents:
diff changeset
    58
  bool m_windowChanged;
14295
92e5682810d4 Prepare to have possibility to pass opengl context to engine
unc0rr
parents: 14159
diff changeset
    59
  QPointer<EngineInstance> m_engineInstance;
14717
57293f34ce59 Detect and handle resize
unc0rr
parents: 14295
diff changeset
    60
  QSize m_viewportSize;
14718
cc6ab1e3f7d5 Allow to move camera around
unc0rr
parents: 14717
diff changeset
    61
  QPoint m_centerPoint;
14148
745c73e0e644 Start working on frontend to rust engine rewrite
unC0Rr
parents:
diff changeset
    62
};
745c73e0e644 Start working on frontend to rust engine rewrite
unC0Rr
parents:
diff changeset
    63
745c73e0e644 Start working on frontend to rust engine rewrite
unC0Rr
parents:
diff changeset
    64
#endif  // GAMEVIEW_H