Terminus
|
The NetworkManager implements the basic functionality for the multiplayer mode of this game. More...
#include <networkmanager.h>
Public Types | |
enum | Mode { Mode::Singleplayer, Mode::MultiplayerHost, Mode::MultiplayerClient } |
Signals | |
void | sendCommand (AbstractCommand *command) |
sends a command More... | |
Public Member Functions | |
NetworkManager (Game &game) | |
virtual | ~NetworkManager () |
void | startServer (unsigned short port) |
starts this NetworkManager in Mode::MultiplayerHost and creates the respective NetworkEndpoint More... | |
void | startClient (QString host, unsigned short port) |
starts this NetworkManager in Mode::MultiplayerClient and creates the respective NetworkEndpoint More... | |
void | update () |
checks the sync timer and sends a sync command as necessary More... | |
void | sendPauseCommand (bool pause) |
void | sendPrepareNewGameCommand (bool isPlayerOne, unsigned int terrainSeed) |
void | sendProjectileFiredCommand (QVector3D startPosition, QVector3D velocity) |
void | sendProjectileHitCommand (int wagonIndex, float damage) |
void | sendSyncCommand (const Train &playerTrain) |
void | sendGameEndedCommand (bool youWin) |
void | sendClientReadyCommand () |
void | prepareAndSyncNewGame () |
Initiates the command sequence of a multiplayer game. More... | |
Mode | mode () |
Protected Slots | |
void | onReceivedCommand (AbstractCommand *command) |
called if the underlying NetworkEndpoint receives an AbstractCommand More... | |
void | onEndpointStateChange (NetworkEndpoint::State state) |
called if the underlying NetworkEndpoints changes its state More... | |
void | onSendCommand (AbstractCommand *command) |
Slot-wrapper for sendMessage() More... | |
Protected Member Functions | |
void | setEndpoint (NetworkEndpoint *endpoint) |
sets a new NetworkEndpoint and connects its signals More... | |
Protected Attributes | |
Game & | m_game |
Game instance that this NetworkManager is associated to. More... | |
Mode | m_mode |
operation mode of this NetworkManager More... | |
std::unique_ptr< NetworkEndpoint > | m_networkEndpoint |
NetworkEndpoint that is used for low-level network communication. More... | |
Timer::TimerID | m_syncTimer |
timer that determines when sync commands should be sent More... | |
The NetworkManager implements the basic functionality for the multiplayer mode of this game.
It provides an interface to initiate network connections, send commands and schedule received commands for execution.
|
strong |
terminus::NetworkManager::NetworkManager | ( | Game & | game | ) |
|
virtual |
NetworkManager::Mode terminus::NetworkManager::mode | ( | ) |
Before either startClient() or startServer() the mode is Mode::Singleplayer
|
protectedslot |
called if the underlying NetworkEndpoints changes its state
state | This only reacts to a client connecting to a Server and prepares the multiplayer session accordingly |
|
protectedslot |
called if the underlying NetworkEndpoint receives an AbstractCommand
command | - ownership is taken |
command is scheduled to be executed for the next frame update
|
protectedslot |
Slot-wrapper for sendMessage()
command | A pointer to the command to be sent |
A "wrapper" through a signal-slot-connection is used here to prevent calling methods on the underlying socket from a thread different from the one that created the socket. By using Qt::AutoConnection, messages are queued and guaranteed to execute in the right thread.
void terminus::NetworkManager::prepareAndSyncNewGame | ( | ) |
Initiates the command sequence of a multiplayer game.
Gets called if a NetworServer goes from State::Listening to State::Connected and is therefore only relevant in Mode::MultiplayerHost
void terminus::NetworkManager::sendClientReadyCommand | ( | ) |
|
signal |
sends a command
command | - takes ownership |
This method may be called from any thread and uses a QueuedConnection to route this request to the network thread
void terminus::NetworkManager::sendGameEndedCommand | ( | bool | youWin | ) |
void terminus::NetworkManager::sendPauseCommand | ( | bool | pause | ) |
void terminus::NetworkManager::sendPrepareNewGameCommand | ( | bool | isPlayerOne, |
unsigned int | terrainSeed | ||
) |
void terminus::NetworkManager::sendProjectileFiredCommand | ( | QVector3D | startPosition, |
QVector3D | velocity | ||
) |
void terminus::NetworkManager::sendProjectileHitCommand | ( | int | wagonIndex, |
float | damage | ||
) |
void terminus::NetworkManager::sendSyncCommand | ( | const Train & | playerTrain | ) |
|
protected |
sets a new NetworkEndpoint and connects its signals
endpoint | - ownership managed by QObject parent mechanism |
The previous NetworkEndpoints signals will be disconnected
void terminus::NetworkManager::startClient | ( | QString | host, |
unsigned short | port | ||
) |
starts this NetworkManager in Mode::MultiplayerClient and creates the respective NetworkEndpoint
host | |
port |
void terminus::NetworkManager::startServer | ( | unsigned short | port | ) |
starts this NetworkManager in Mode::MultiplayerHost and creates the respective NetworkEndpoint
port |
void terminus::NetworkManager::update | ( | ) |
checks the sync timer and sends a sync command as necessary
This method is meant to be called by the associated game during its frame update
|
protected |
Game instance that this NetworkManager is associated to.
|
protected |
operation mode of this NetworkManager
|
protected |
NetworkEndpoint that is used for low-level network communication.
A pointer is necessary as specific subclasses of NetworkEndpoint may be used
|
protected |
timer that determines when sync commands should be sent