R-Type
Distributed multiplayer game engine in C++
Loading...
Searching...
No Matches
ENetHostWrapper Class Referencefinal

#include <ENetHost.hpp>

Inheritance diagram for ENetHostWrapper:
Inheritance graph
Collaboration diagram for ENetHostWrapper:
Collaboration graph

Public Member Functions

 ENetHostWrapper (size_t maxConnections=1, size_t maxChannels=2, uint32_t incomingBandwidth=0, uint32_t outgoingBandwidth=0)
 
 ENetHostWrapper (const IAddress &address, size_t maxConnections, size_t maxChannels=2, uint32_t incomingBandwidth=0, uint32_t outgoingBandwidth=0)
 
 ~ENetHostWrapper () override
 
 ENetHostWrapper (const ENetHostWrapper &)=delete
 
ENetHostWrapperoperator= (const ENetHostWrapper &)=delete
 
IPeerconnect (const IAddress &address, size_t channelCount, uint32_t data) override
 Connect to a remote host.
 
std::optional< HostNetworkEventservice (uint32_t timeout) override
 Service the host, processing network events.
 
void broadcast (std::unique_ptr< IPacket > packet, uint8_t channelID) override
 Broadcast a packet to all connected peers.
 
void flush () override
 Send all queued packets immediately.
 
size_t getPeerCount () const override
 Get the number of connected peers.
 
const IAddressgetAddress () const override
 Get the address this host is bound to.
 
- Public Member Functions inherited from IHost
virtual ~IHost ()=default
 

Private Attributes

ENetHost * _host
 
std::map< ENetPeer *, std::unique_ptr< ENetPeerWrapper > > _peers
 
std::unique_ptr< ENetAddressWrapper_cachedAddress
 

Detailed Description

Definition at line 18 of file ENetHost.hpp.

Constructor & Destructor Documentation

◆ ENetHostWrapper() [1/3]

ENetHostWrapper::ENetHostWrapper ( size_t  maxConnections = 1,
size_t  maxChannels = 2,
uint32_t  incomingBandwidth = 0,
uint32_t  outgoingBandwidth = 0 
)
explicit

Definition at line 16 of file ENetHost.cpp.

References _host.

◆ ENetHostWrapper() [2/3]

ENetHostWrapper::ENetHostWrapper ( const IAddress address,
size_t  maxConnections,
size_t  maxChannels = 2,
uint32_t  incomingBandwidth = 0,
uint32_t  outgoingBandwidth = 0 
)

Definition at line 27 of file ENetHost.cpp.

References _host.

◆ ~ENetHostWrapper()

ENetHostWrapper::~ENetHostWrapper ( )
override

Definition at line 49 of file ENetHost.cpp.

References _host.

◆ ENetHostWrapper() [3/3]

ENetHostWrapper::ENetHostWrapper ( const ENetHostWrapper )
delete

Member Function Documentation

◆ broadcast()

void ENetHostWrapper::broadcast ( std::unique_ptr< IPacket packet,
uint8_t  channelID 
)
overridevirtual

Broadcast a packet to all connected peers.

Parameters
packetThe packet to broadcast.
channelIDThe channel to broadcast on.

Implements IHost.

Definition at line 127 of file ENetHost.cpp.

References _host.

◆ connect()

IPeer * ENetHostWrapper::connect ( const IAddress address,
size_t  channelCount,
uint32_t  data 
)
overridevirtual

Connect to a remote host.

Parameters
addressThe address to connect to.
channelCountNumber of channels to allocate (default: 1).
dataUser data to send with the connection request.
Returns
Pointer to the peer object representing the connection, or nullptr on failure.

Implements IHost.

Definition at line 55 of file ENetHost.cpp.

References _host, and _peers.

◆ flush()

void ENetHostWrapper::flush ( )
overridevirtual

Send all queued packets immediately.

Implements IHost.

Definition at line 143 of file ENetHost.cpp.

References _host.

◆ getAddress()

const IAddress & ENetHostWrapper::getAddress ( ) const
overridevirtual

Get the address this host is bound to.

Returns
Reference to the host's address.

Implements IHost.

Definition at line 153 of file ENetHost.cpp.

References _cachedAddress, and _host.

◆ getPeerCount()

size_t ENetHostWrapper::getPeerCount ( ) const
overridevirtual

Get the number of connected peers.

Returns
Number of connected peers.

Implements IHost.

Definition at line 149 of file ENetHost.cpp.

References _host.

◆ operator=()

ENetHostWrapper & ENetHostWrapper::operator= ( const ENetHostWrapper )
delete

◆ service()

std::optional< HostNetworkEvent > ENetHostWrapper::service ( uint32_t  timeout)
overridevirtual

Service the host, processing network events.

Parameters
timeoutMaximum time to wait for events in milliseconds.
Returns
Optional HostNetworkEvent if an event occurred, std::nullopt otherwise.

Implements IHost.

Definition at line 75 of file ENetHost.cpp.

References _host, _peers, HostNetworkEvent::channelID, CONNECT, DISCONNECT, HostNetworkEvent::packet, HostNetworkEvent::peer, RECEIVE, and HostNetworkEvent::type.

Member Data Documentation

◆ _cachedAddress

std::unique_ptr<ENetAddressWrapper> ENetHostWrapper::_cachedAddress
mutableprivate

Definition at line 44 of file ENetHost.hpp.

Referenced by getAddress().

◆ _host

ENetHost* ENetHostWrapper::_host
private

◆ _peers

std::map<ENetPeer *, std::unique_ptr<ENetPeerWrapper> > ENetHostWrapper::_peers
private

Definition at line 43 of file ENetHost.hpp.

Referenced by connect(), and service().


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