SuperTuxKart
Loading...
Searching...
No Matches
Public Types | Public Member Functions | Private Member Functions | Private Attributes | List of all members
GameEventsProtocol Class Reference
Inheritance diagram for GameEventsProtocol:
Inheritance graph
[legend]

Public Types

enum  GameEventType : uint8_t {
  GE_KART_FINISHED_RACE = 1 , GE_STARTUP_BOOST = 2 , GE_BATTLE_KART_SCORE = 3 , GE_CTF_SCORED = 4 ,
  GE_RESET_BALL = 5 , GE_PLAYER_GOAL = 6 , GE_CHECK_LINE = 7
}
 

Public Member Functions

 GameEventsProtocol ()
 This class handles all 'major' game events.
 
virtual bool notifyEvent (Event *event) OVERRIDE
 Notify a protocol matching the Event type of that event.
 
void kartFinishedRace (AbstractKart *kart, float time)
 This function is called from the server when a kart finishes a race.
 
void kartFinishedRace (const NetworkString &ns)
 This function is called on a client when it receives a kartFinishedRace event from the server.
 
void sendStartupBoost (uint8_t kart_id)
 
virtual void setup () OVERRIDE
 Called when the protocol is going to start.
 
virtual void update (int ticks) OVERRIDE
 Called by the protocol listener, synchronously with the main loop.
 
virtual void asynchronousUpdate () OVERRIDE
 Called by the protocol listener as often as possible.
 
virtual bool notifyEventAsynchronous (Event *event) OVERRIDE
 Notify a protocol matching the Event type of that event.
 
- Public Member Functions inherited from Protocol
 Protocol (ProtocolType type)
 Constructor Sets the basic protocol parameters, as the callback object and the protocol type.
 
virtual ~Protocol ()
 Destructor.
 
virtual void setup ()=0
 Called when the protocol is going to start.
 
virtual void update (int ticks)=0
 Called by the protocol listener, synchronously with the main loop.
 
virtual void asynchronousUpdate ()=0
 Called by the protocol listener as often as possible.
 
NetworkStringgetNetworkString (size_t capacity=16) const
 functions to check incoming data easily
 
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.
 
void sendMessageToPeers (NetworkString *message, bool reliable=true)
 Sends a message to all validated peers in game, encrypt the message if needed.
 
void sendMessageToPeersInServer (NetworkString *message, bool reliable=true)
 Sends a message to all validated peers in server, encrypt the message if needed.
 
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.
 
virtual bool notifyEventAsynchronous (Event *event)
 Notify a protocol matching the Event type of that event.
 
ProtocolType getProtocolType () const
 Method to get a protocol's type.
 
void setHandleConnections (bool b)
 Sets if this protocol should receive connection events.
 
void setHandleDisconnections (bool b)
 Sets if this protocol should receive disconnection events.
 
virtual bool handleConnects () const
 Return true if this protocol should be informed about connects.
 
virtual bool handleDisconnects () const
 Return true if this protocol should be informed about disconnects.
 

Private Member Functions

void eliminatePlayer (const NetworkString &ns)
 

Private Attributes

int m_last_finished_position
 

Additional Inherited Members

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

Constructor & Destructor Documentation

◆ GameEventsProtocol()

GameEventsProtocol::GameEventsProtocol ( )

This class handles all 'major' game events.

E.g. finishing a race or goal etc. The game events manager is notified from the game code, and it calls the corresponding function in this class. The server then notifies all clients. Clients receive the message in the synchronous notifyEvent function here, decode the message and call the original game code. The functions name are identical, e.g. kartFinishedRace(some parameter) is called from the GameEventManager on the server, and the received message is then handled by kartFinishedRace(const NetworkString &).

Member Function Documentation

◆ asynchronousUpdate()

virtual void GameEventsProtocol::asynchronousUpdate ( )
inlinevirtual

Called by the protocol listener as often as possible.

Must be re-defined.

Implements Protocol.

◆ kartFinishedRace() [1/2]

void GameEventsProtocol::kartFinishedRace ( AbstractKart kart,
float  time 
)

This function is called from the server when a kart finishes a race.

It sends a notification to all clients about this event.

Parameters
kartThe kart that finished the race.
timeThe time at which the kart finished.

◆ kartFinishedRace() [2/2]

void GameEventsProtocol::kartFinishedRace ( const NetworkString ns)

This function is called on a client when it receives a kartFinishedRace event from the server.

It updates the game with this information.

Parameters
nsThe message from the server.

◆ notifyEvent()

bool GameEventsProtocol::notifyEvent ( Event event)
virtual

Notify a protocol matching the Event type of that event.

Parameters
event: Pointer to the event.
Returns
True if the event has been treated, false otherwise.

Reimplemented from Protocol.

◆ notifyEventAsynchronous()

virtual bool GameEventsProtocol::notifyEventAsynchronous ( Event event)
inlinevirtual

Notify a protocol matching the Event type of that event.

This update is done asynchronously :

Parameters
event: Pointer to the event.
Returns
True if the event has been treated, false otherwise

Reimplemented from Protocol.

◆ setup()

virtual void GameEventsProtocol::setup ( )
inlinevirtual

Called when the protocol is going to start.

Must be re-defined by subclasses.

Implements Protocol.

◆ update()

void GameEventsProtocol::update ( int  ticks)
virtual

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

Must be re-defined.

Implements Protocol.


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