Terminus
|
The Game class is the main entry point. It subclasses QQuickItem and handles all communication between QML and C++. More...
#include <game.h>
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... | |
Game & | operator= (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 () |
World & | world () const |
QVariant & | qmlData () |
ActionScheduler & | scheduler () |
NetworkManager & | networkManager () |
Timer & | timer () |
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< World > | m_world |
Properties | |
QVariant | qmlData |
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.
terminus::Game::Game | ( | ) |
The one and only Game constructor.
|
delete |
Delete copy constructor.
terminus::Game::~Game | ( | ) |
Do not delete this destructor, even if it is empty
void terminus::Game::buttonInput | ( | int | type | ) |
Handle a pressed button event from the UI.
|
slot |
|
protected |
void terminus::Game::createWorld | ( | bool | isNetworkGame, |
bool | isPlayerOne, | ||
int | terrainSeed | ||
) |
Generic method to create a World.
isNetworkGame | Whether the local game is a network game |
isPlayerOne | Whether the local player is player one (right track) |
terrainSeed | The seed used to initialize the Perlin noise function to generate the terrain |
|
protected |
void terminus::Game::endGame | ( | bool | localPlayerWins, |
bool | showMessage | ||
) |
|
slot |
void terminus::Game::hideUI | ( | ) |
void terminus::Game::hostNetworkGame | ( | ) |
Start a paused game and wait for a connecting player.
|
inlineslot |
void terminus::Game::joinNetworkGame | ( | QString | host | ) |
Try to connect to the given host and receive game information.
host | The 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 | ( | ) |
QVariant& terminus::Game::qmlData | ( | ) |
|
signal |
|
slot |
Render game world.
This renders the current state of all objects. Object state should not be changed here.
ActionScheduler & terminus::Game::scheduler | ( | ) |
|
slot |
Pause or continue ingame time.
paused | Whether 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.
|
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 | ( | ) |
|
slot |
void terminus::Game::toggleUI | ( | ) |
Hide or show the UI.
void terminus::Game::touchInput | ( | qreal | oldx, |
qreal | oldy, | ||
qreal | x, | ||
qreal | y | ||
) |
|
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 |
|
protected |
|
protected |
|
protected |
The timer that triggers a redraw.
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
read |