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

The NetworkManager implements the basic functionality for the multiplayer mode of this game. More...

#include <networkmanager.h>

Inheritance diagram for terminus::NetworkManager:

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

Gamem_game
 Game instance that this NetworkManager is associated to. More...
 
Mode m_mode
 operation mode of this NetworkManager More...
 
std::unique_ptr< NetworkEndpointm_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...
 

Detailed Description

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.

See also
NetworkEndpoint

Member Enumeration Documentation

Enumerator
Singleplayer 
MultiplayerHost 
MultiplayerClient 

Constructor & Destructor Documentation

terminus::NetworkManager::NetworkManager ( Game game)
terminus::NetworkManager::~NetworkManager ( )
virtual

Member Function Documentation

NetworkManager::Mode terminus::NetworkManager::mode ( )
Returns
operation mode of this network manager

Before either startClient() or startServer() the mode is Mode::Singleplayer

void terminus::NetworkManager::onEndpointStateChange ( NetworkEndpoint::State  state)
protectedslot

called if the underlying NetworkEndpoints changes its state

Parameters
stateThis only reacts to a client connecting to a Server and prepares the multiplayer session accordingly
void terminus::NetworkManager::onReceivedCommand ( AbstractCommand command)
protectedslot

called if the underlying NetworkEndpoint receives an AbstractCommand

Parameters
command- ownership is taken

command is scheduled to be executed for the next frame update

void terminus::NetworkManager::onSendCommand ( AbstractCommand command)
protectedslot

Slot-wrapper for sendMessage()

Parameters
commandA 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 ( )
void terminus::NetworkManager::sendCommand ( AbstractCommand command)
signal

sends a command

Parameters
command- takes ownership

This method may be called from any thread and uses a QueuedConnection to route this request to the network thread

See also
onSendCommand()
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)
void terminus::NetworkManager::setEndpoint ( NetworkEndpoint endpoint)
protected

sets a new NetworkEndpoint and connects its signals

Parameters
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

Parameters
host
port
See also
NetworkClient
void terminus::NetworkManager::startServer ( unsigned short  port)

starts this NetworkManager in Mode::MultiplayerHost and creates the respective NetworkEndpoint

Parameters
port
See also
NetworkServer
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

Member Data Documentation

Game& terminus::NetworkManager::m_game
protected

Game instance that this NetworkManager is associated to.

Mode terminus::NetworkManager::m_mode
protected

operation mode of this NetworkManager

std::unique_ptr<NetworkEndpoint> terminus::NetworkManager::m_networkEndpoint
protected

NetworkEndpoint that is used for low-level network communication.

A pointer is necessary as specific subclasses of NetworkEndpoint may be used

Timer::TimerID terminus::NetworkManager::m_syncTimer
protected

timer that determines when sync commands should be sent


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