qmlfrontend/game_view.h
author Wuzzy <Wuzzy2@mail.ru>
Sat, 02 Nov 2019 13:01:28 +0100
changeset 15501 5a30396f8fb2
parent 14842 ef9630519491
child 16010 a73b9770467a
permissions -rw-r--r--
ClimbHome: Change misleading Seed assignment to nil value This was "Seed = ClimbHome", but ClimbHome was a nil value. This code still worked as the engine interpreted the nil value as empty string. But it can be very misleading. This changeset makes the Seed assignment more explicit by assigning the empty string directly. The compability has been tested.

#ifndef GAMEVIEW_H
#define GAMEVIEW_H

#include <QQuickItem>

#include <QPointer>
#include <QScopedPointer>
#include <QtGui/QOpenGLFunctions>
#include <QtGui/QOpenGLShaderProgram>

#include "engine_instance.h"

class GameViewRenderer : public QObject, protected QOpenGLFunctions {
  Q_OBJECT
 public:
  explicit GameViewRenderer();
  ~GameViewRenderer() override;

  void tick(quint32 delta);
  void setEngineInstance(EngineInstance* engineInstance);

 public slots:
  void paint();
  void onViewportSizeChanged(QQuickWindow* window);

 private:
  quint32 m_delta;
  QPointer<EngineInstance> m_engineInstance;
};

class GameView : public QQuickItem {
  Q_OBJECT

  Q_PROPERTY(EngineInstance* engineInstance READ engineInstance WRITE
                 setEngineInstance NOTIFY engineInstanceChanged)

 public:
  explicit GameView(QQuickItem* parent = nullptr);

  Q_INVOKABLE void tick(quint32 delta);

  EngineInstance* engineInstance() const;

 signals:
  void engineInstanceChanged(EngineInstance* engineInstance);

 public slots:
  void sync();
  void cleanup();
  void setEngineInstance(EngineInstance* engineInstance);

 private slots:
  void handleWindowChanged(QQuickWindow* win);

 private:
  quint32 m_delta;
  QScopedPointer<GameViewRenderer> m_renderer;
  bool m_windowChanged;
  QPointer<EngineInstance> m_engineInstance;
  QSize m_viewportSize;
  QPoint m_centerPoint;
};

#endif  // GAMEVIEW_H