LibNRG  0.0.1
Networking for Real-time Games library
 All Classes Files Functions Variables Friends
nrg::Client Class Reference

The main client-side nrg class.

#include <nrg_client.h>

Public Member Functions

 Client (const std::string &game_name, uint32_t game_version, InputBase &input)
 Standard Client constructor. More...
 
 Client (const std::string &game_name, uint32_t game_version)
 No-Input Client constructor. More...
 
bool connect (const NetAddress &server_addr)
 Sets the address of the Server to connect to, and calls Socket::connect on it.
 
bool isConnected () const
 Returns whether or not this Client is connected or not.
 
const NetAddress * getConnectedAddress () const
 Returns the NetAddress this Client is connected to, or nullptr if not connected.
 
void registerEntity (Entity *e)
 Registers a subclass of Entity with this Client, must be called once for each user-defined Entity before connecting.
 
template<class M , class F >
void addMessageHandler (F &&f)
 Adds a function f, that will be called when the Client receives a Message of type M.
 
void sendMessage (const MessageBase &m)
 Queues the the user-defined Message m to be sent to the connected Server.
 
bool update ()
 Sends and Recieves any queued Packets and updates the contained State classes, returns false on error.
 
bool pollEvent (Event &e)
 Places the next Event from the Client's EventQueue into e, returning true if this happened, or false if there were no more events.
 
const ClientStats & getStats () const
 Returns a ClientStats reference, which contains statistics about this Client's connection.
 
void startRecordingReplay (const char *filename)
 Starts recording received packets into a file called filename.
 
void stopRecordingReplay ()
 Stops recording received packets into a file called filename.
 
 ~Client ()
 Standard destructor.
 
uint32_t getPacketRateLimit (void)
 Gets a limit on how many full Packets the Client will send per second.
 
void setPacketRateLimit (uint32_t packets_per_sec)
 Sets a limit on how many full Packets the Client will send per second.
 
void * getUserPointer () const
 Get a user-defined pointer to be associated with this Client instance.
 
void setUserPointer (void *p)
 Set a user-defined pointer to be associated with this Client instance.
 
Misc Getters
InputBase * getInput ()
 
EventQueue & getEventQueue ()
 
UDPSocket & getSock ()
 
const std::string & getGameName ()
 
const uint32_t getGameVersion ()
 
const int getPlayerID ()
 

Constructor & Destructor Documentation

nrg::Client::Client ( const std::string &  game_name,
uint32_t  game_version,
InputBase &  input 
)
Parameters
game_gameUser-chosen game name, it must match the Server's game name
game_versionUser-chosen game version
inputUser-defined subclass of InputBase, containing data to be sent to the server each frame
nrg::Client::Client ( const std::string &  game_name,
uint32_t  game_version 
)
Parameters
game_gameUser-chosen game name, it must match the Server's game name
game_versionUser-chosen game version

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