Terminus
Public Slots | Signals | Public Member Functions | Protected Member Functions | Protected Attributes | Properties | List of all members
terminus::Game Class Reference

The Game class is the main entry point. It subclasses QQuickItem and handles all communication between QML and C++. More...

#include <game.h>

Inheritance diagram for terminus::Game:

Public Slots

void sync ()
 Update game world, taking elapsed time into account. More...
 
void render ()
 Render game world. More...
 
void cleanup ()
 
void handleWindowChanged (QQuickWindow *win)
 Handles a change of the QQuickWindow. More...
 
void setPaused (bool paused)
 Pause or continue ingame time. More...
 
void togglePaused ()
 
bool isPaused ()
 

Signals

void qmlDataChanged ()
 

Public Member Functions

 Game ()
 The one and only Game constructor. More...
 
 Game (const Game &other)=delete
 Delete copy constructor. More...
 
Gameoperator= (const Game &other)=delete
 Delete assignment operator. More...
 
 ~Game ()
 
Q_INVOKABLE void startLocalGame ()
 Sets up a local game against an AI player with the local plaer being the one on the right. More...
 
Q_INVOKABLE void hostNetworkGame ()
 Start a paused game and wait for a connecting player. More...
 
Q_INVOKABLE void joinNetworkGame (QString host)
 Try to connect to the given host and receive game information. More...
 
void createWorld (bool isNetworkGame, bool isPlayerOne, int terrainSeed)
 Generic method to create a World. More...
 
void endGame (bool localPlayerWins, bool showMessage)
 
void toggleUI ()
 Hide or show the UI. More...
 
void showUI ()
 
void hideUI ()
 
Worldworld () const
 
QVariant & qmlData ()
 
ActionSchedulerscheduler ()
 
NetworkManagernetworkManager ()
 
Timertimer ()
 
Q_INVOKABLE void buttonInput (int type)
 Handle a pressed button event from the UI. More...
 
Q_INVOKABLE void keyInput (Qt::Key key)
 Handle a key event. More...
 
Q_INVOKABLE void moveInput (int type, qreal x, qreal y)
 Handle a mouse move event. More...
 
Q_INVOKABLE void touchInput (qreal oldx, qreal oldy, qreal x, qreal y)
 

Protected Member Functions

void connectSignals (QQuickWindow *win)
 
void disconnectSignals ()
 
void updateQMLData ()
 Update the data storage used by the UI to display game info. More...
 

Protected Attributes

Timer m_timer
 
EventHandler m_eventHandler
 
ActionScheduler m_scheduler
 
NetworkManager m_networkManager
 
QVariant m_qmlData
 
QQuickWindow * m_window
 
std::unique_ptr< QTimer > m_renderTrigger
 
bool m_isGLInitialized
 The timer that triggers a redraw. More...
 
QOpenGLFunctions m_gl
 
bool m_isPlayerOne
 
bool m_isUIActive
 
std::unique_ptr< Worldm_world
 

Properties

QVariant qmlData
 

Detailed Description

The Game class is the main entry point. It subclasses QQuickItem and handles all communication between QML and C++.

The Game class gets instantiated on QML side and thereby handles all communication with the "outside" / QML environment.beforeSynchronizing It connects to the QML signals QQUickItem::beforeSynchronizing() and QQUickItem::beforeRendering() to receive update and render signals. A timer triggers a redraw every 1000 / 60 milliseconds to cap the framerate at 60fps.

Constructor & Destructor Documentation

terminus::Game::Game ( )

The one and only Game constructor.

terminus::Game::Game ( const Game other)
delete

Delete copy constructor.

terminus::Game::~Game ( )

Do not delete this destructor, even if it is empty

  • otherwise std::shared_ptr<IncompleteType> in the header will break

Member Function Documentation

void terminus::Game::buttonInput ( int  type)

Handle a pressed button event from the UI.

void terminus::Game::cleanup ( )
slot
void terminus::Game::connectSignals ( QQuickWindow *  win)
protected
void terminus::Game::createWorld ( bool  isNetworkGame,
bool  isPlayerOne,
int  terrainSeed 
)

Generic method to create a World.

Parameters
isNetworkGameWhether the local game is a network game
isPlayerOneWhether the local player is player one (right track)
terrainSeedThe seed used to initialize the Perlin noise function to generate the terrain
void terminus::Game::disconnectSignals ( )
protected
void terminus::Game::endGame ( bool  localPlayerWins,
bool  showMessage 
)
void terminus::Game::handleWindowChanged ( QQuickWindow *  win)
slot

Handles a change of the QQuickWindow.

Parameters
winA Pointer to the QQuickWindow that this QQuickItem is being displayed on

This method gets called upon instantiation and whenever the QQuickWindow changes. It (re)connects sync() and render() to the window.

See also
sync() and render()
void terminus::Game::hideUI ( )
void terminus::Game::hostNetworkGame ( )

Start a paused game and wait for a connecting player.

bool terminus::Game::isPaused ( )
inlineslot
void terminus::Game::joinNetworkGame ( QString  host)

Try to connect to the given host and receive game information.

Parameters
hostThe IP address of the host
void terminus::Game::keyInput ( Qt::Key  key)

Handle a key event.

void terminus::Game::moveInput ( int  type,
qreal  x,
qreal  y 
)

Handle a mouse move event.

NetworkManager & terminus::Game::networkManager ( )
Game& terminus::Game::operator= ( const Game other)
delete

Delete assignment operator.

QVariant& terminus::Game::qmlData ( )
void terminus::Game::qmlDataChanged ( )
signal
void terminus::Game::render ( )
slot

Render game world.

This renders the current state of all objects. Object state should not be changed here.

See also
sync()
ActionScheduler & terminus::Game::scheduler ( )
void terminus::Game::setPaused ( bool  paused)
slot

Pause or continue ingame time.

Parameters
pausedWhether the game should be paused or not
void terminus::Game::showUI ( )
void terminus::Game::startLocalGame ( )

Sets up a local game against an AI player with the local plaer being the one on the right.

void terminus::Game::sync ( )
slot

Update game world, taking elapsed time into account.

This updates all dynamic elements in the game. All calculation should be done in this step so that this method transforms one valid game state into another one.

Timer & terminus::Game::timer ( )
void terminus::Game::togglePaused ( )
slot
void terminus::Game::toggleUI ( )

Hide or show the UI.

void terminus::Game::touchInput ( qreal  oldx,
qreal  oldy,
qreal  x,
qreal  y 
)
void terminus::Game::updateQMLData ( )
protected

Update the data storage used by the UI to display game info.

Creates Data for QML. This is incredibly inefficient since QVariants cannot be edited only set.

World & terminus::Game::world ( ) const

Member Data Documentation

EventHandler terminus::Game::m_eventHandler
protected
QOpenGLFunctions terminus::Game::m_gl
protected
bool terminus::Game::m_isGLInitialized
protected

The timer that triggers a redraw.

bool terminus::Game::m_isPlayerOne
protected
bool terminus::Game::m_isUIActive
protected
NetworkManager terminus::Game::m_networkManager
protected
QVariant terminus::Game::m_qmlData
protected
std::unique_ptr<QTimer> terminus::Game::m_renderTrigger
protected
ActionScheduler terminus::Game::m_scheduler
protected
Timer terminus::Game::m_timer
protected
QQuickWindow* terminus::Game::m_window
protected
std::unique_ptr<World> terminus::Game::m_world
protected

Property Documentation

QVariant & terminus::Game::qmlData
read

The documentation for this class was generated from the following files: