SuperTuxKart
Classes | Public Member Functions | Static Public Member Functions | Private Types | Private Member Functions | Private Attributes | Static Private Attributes | List of all members
GameProtocol Class Reference
Inheritance diagram for GameProtocol:
Inheritance graph
[legend]

Classes

struct  Action
 

Public Member Functions

 GameProtocol ()
 Constructor. More...
 
virtual bool notifyEventAsynchronous (Event *event) OVERRIDE
 Called when a message from a remote GameProtocol is received.
 
virtual void update (int ticks) OVERRIDE
 Called by the protocol listener, synchronously with the main loop. More...
 
void sendActions ()
 Synchronous update - will send all commands collected during the last frame (and could optional only send messages every N frames).
 
void controllerAction (int kart_id, PlayerAction action, int value, int val_l, int val_r)
 Called from the local kart controller when an action (like steering, acceleration, ...) was triggered. More...
 
void startNewState ()
 Called by the server before assembling a new message containing the full state of the race to be sent to a client.
 
void addState (BareNetworkString *buffer)
 Called by a server to add data to the current state. More...
 
void sendState ()
 Called when the last state information has been added and the message can be sent to the clients.
 
void finalizeState (std::vector< std::string > &cur_rewinder)
 Called by a server to finalize the current state, which add updated names of rewinder using to the beginning of state buffer. More...
 
void sendItemEventConfirmation (int ticks)
 Sends a confirmation to the server that all item events up to 'ticks' have been received. More...
 
virtual void undo (BareNetworkString *buffer) OVERRIDE
 Called from the RewindManager when rolling back. More...
 
virtual void rewind (BareNetworkString *buffer) OVERRIDE
 Called from the RewindManager after a rollback to replay the stored events. More...
 
virtual void setup () OVERRIDE
 Called when the protocol is going to start. More...
 
virtual void asynchronousUpdate () OVERRIDE
 Called by the protocol listener as often as possible. More...
 
NetworkStringgetState () const
 Returns the NetworkString in which a state was saved. More...
 
std::unique_lock< std::mutex > acquireWorldDeletingMutex () const
 
- Public Member Functions inherited from Protocol
 Protocol (ProtocolType type)
 Constructor Sets the basic protocol parameters, as the callback object and the protocol type. More...
 
virtual ~Protocol ()
 Destructor.
 
NetworkStringgetNetworkString (size_t capacity=16) const
 functions to check incoming data easily More...
 
bool checkDataSize (Event *event, unsigned int minimum_size)
 Checks if the message has at least the specified size, and if not prints a warning message including the message content. More...
 
void sendMessageToPeers (NetworkString *message, bool reliable=true)
 Sends a message to all validated peers in game, encrypt the message if needed. More...
 
void sendMessageToPeersInServer (NetworkString *message, bool reliable=true)
 Sends a message to all validated peers in server, encrypt the message if needed. More...
 
void sendToServer (NetworkString *message, bool reliable=true)
 Sends a message from a client to the server.
 
virtual void requestStart ()
 Starts a request in the protocol manager to start this protocol.
 
virtual void requestTerminate ()
 Submits a request to the ProtocolManager to terminate this protocol.
 
virtual bool notifyEvent (Event *event)
 Notify a protocol matching the Event type of that event. More...
 
ProtocolType getProtocolType () const
 Method to get a protocol's type. More...
 
void setHandleConnections (bool b)
 Sets if this protocol should receive connection events. More...
 
void setHandleDisconnections (bool b)
 Sets if this protocol should receive disconnection events. More...
 
virtual bool handleConnects () const
 Return true if this protocol should be informed about connects. More...
 
virtual bool handleDisconnects () const
 Return true if this protocol should be informed about disconnects. More...
 
- Public Member Functions inherited from EventRewinder
 EventRewinder ()
 Constructor. More...
 
virtual ~EventRewinder ()
 Destructor.
 

Static Public Member Functions

static std::shared_ptr< GameProtocolcreateInstance ()
 
static bool emptyInstance ()
 
static std::shared_ptr< GameProtocollock ()
 

Private Types

enum  {
  GP_CONTROLLER_ACTION, GP_STATE, GP_ITEM_UPDATE, GP_ITEM_CONFIRMATION,
  GP_ADJUST_TIME
}
 The type of game events to be forwarded to the server. More...
 

Private Member Functions

void handleControllerAction (Event *event)
 Called when a controller event is received - either on the server from a client, or on a client from the server. More...
 
void handleState (Event *event)
 Called when a new full state is received form the server.
 
void handleAdjustTime (Event *event)
 
void handleItemEventConfirmation (Event *event)
 Handles an item even confirmation from a client. More...
 
std::tuple< uint8_t, uint16_t, uint16_t, uint16_t > compressAction (const Action &a)
 
std::tuple< PlayerAction, int, int, int > decompressAction (uint8_t w, uint16_t x, uint16_t y, uint16_t z)
 

Private Attributes

std::mutex m_world_deleting_mutex
 
NetworkStringm_data_to_send
 A network string that collects all information from the server to be sent next. More...
 
std::vector< int8_t > m_adjust_time
 The server might request that the world clock of a client is adjusted to reduce number of rollbacks. More...
 
std::vector< Actionm_all_actions
 
NetworkItemManagerm_network_item_manager
 

Static Private Attributes

static std::weak_ptr< GameProtocolm_game_protocol [PT_COUNT]
 

Additional Inherited Members

- Protected Attributes inherited from Protocol
ProtocolType m_type
 The type of the protocol. More...
 
bool m_handle_connections
 True if this protocol should receive connection events. More...
 
bool m_handle_disconnections
 TRue if this protocol should recceiver disconnection events. More...
 

Member Enumeration Documentation

◆ anonymous enum

anonymous enum
private

The type of game events to be forwarded to the server.

Constructor & Destructor Documentation

◆ GameProtocol()

GameProtocol::GameProtocol ( )

Constructor.

Allocates the buffer for events to send to the server.

Member Function Documentation

◆ addState()

void GameProtocol::addState ( BareNetworkString buffer)

Called by a server to add data to the current state.

The data in buffer is copied, so the data can be freed after this call/.

Parameters
bufferAdds the data in the buffer to the current state.

◆ asynchronousUpdate()

virtual void GameProtocol::asynchronousUpdate ( )
inlinevirtual

Called by the protocol listener as often as possible.

Must be re-defined.

Implements Protocol.

◆ controllerAction()

void GameProtocol::controllerAction ( int  kart_id,
PlayerAction  action,
int  value,
int  val_l,
int  val_r 
)

Called from the local kart controller when an action (like steering, acceleration, ...) was triggered.

It sends a message with the new info to the server and informs the rewind manager to store the event.

Parameters
Kartid that triggered the action.
actionWhich action was triggered.
valueNew value for the given action.

◆ finalizeState()

void GameProtocol::finalizeState ( std::vector< std::string > &  cur_rewinder)

Called by a server to finalize the current state, which add updated names of rewinder using to the beginning of state buffer.

Parameters
cur_rewinderList of current rewinder using.

◆ getState()

NetworkString* GameProtocol::getState ( ) const
inline

Returns the NetworkString in which a state was saved.

◆ handleControllerAction()

void GameProtocol::handleControllerAction ( Event event)
private

Called when a controller event is received - either on the server from a client, or on a client from the server.

It sorts the event into the RewindManager's network event queue. The server will also send this event immediately to all clients (except to the original sender).

◆ handleItemEventConfirmation()

void GameProtocol::handleItemEventConfirmation ( Event event)
private

Handles an item even confirmation from a client.

Once it has been confirmed that all clients have received certain events, those can be deleted and do not need to be sent again.

Parameters
eventThe data from the client.

◆ rewind()

void GameProtocol::rewind ( BareNetworkString buffer)
virtual

Called from the RewindManager after a rollback to replay the stored events.

Parameters
bufferPointer to the saved state information.

Implements EventRewinder.

◆ sendItemEventConfirmation()

void GameProtocol::sendItemEventConfirmation ( int  ticks)

Sends a confirmation to the server that all item events up to 'ticks' have been received.

Parameters
ticksUp to which time in ticks the item events have been received.

◆ setup()

virtual void GameProtocol::setup ( )
inlinevirtual

Called when the protocol is going to start.

Must be re-defined by subclasses.

Implements Protocol.

◆ undo()

void GameProtocol::undo ( BareNetworkString buffer)
virtual

Called from the RewindManager when rolling back.

Parameters
bufferPointer to the saved state information.

Implements EventRewinder.

◆ update()

void GameProtocol::update ( int  ticks)
virtual

Called by the protocol listener, synchronously with the main loop.

Must be re-defined.

Implements Protocol.

Member Data Documentation

◆ m_adjust_time

std::vector<int8_t> GameProtocol::m_adjust_time
private

The server might request that the world clock of a client is adjusted to reduce number of rollbacks.

◆ m_data_to_send

NetworkString* GameProtocol::m_data_to_send
private

A network string that collects all information from the server to be sent next.


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