Owns a host or client UDP session and exchanges replicated game state. More...
#include <examples/asteroids-net/multiplayer.hpp>
Public Member Functions | |
| bool | active () const |
| Returns whether a host or client session is active. | |
| bool | connected () const |
| Returns whether the local player has an established peer connection. | |
| NetworkExchange | exchange (const NetworkState &local_state, float delta_time) |
| Sends local state and receives remote updates. | |
| void | host (const std::string &port, const std::string &player_name) |
| Starts hosting a session. | |
| bool | is_host () const |
| Returns whether this session is the host. | |
| void | join (const std::string &address, const std::string &port, const std::string &player_name, const std::string &join_code) |
| Joins a hosted session. | |
| const std::string & | join_code () const |
| Returns the session join code. | |
| std::uint8_t | local_player_id () const |
| Returns the assigned local player slot. | |
| MultiplayerSession () | |
| Initializes the networking subsystem. | |
| MultiplayerSession (const MultiplayerSession &)=delete | |
| MultiplayerSession & | operator= (const MultiplayerSession &)=delete |
| const std::array< bool, NETWORK_PLAYER_COUNT > & | player_connected () const |
| Returns connection flags indexed by player slot. | |
| std::size_t | player_count () const |
| Returns the number of connected players. | |
| const std::array< std::string, NETWORK_PLAYER_COUNT > & | player_names () const |
| Returns display names indexed by player slot. | |
| const std::string & | port_mapping_status () const |
| Returns the automatic router port-mapping status. | |
| void | stop () |
| Stops the active host or client session. | |
| ~MultiplayerSession () | |
| Stops the session and releases networking resources. | |
Owns a host or client UDP session and exchanges replicated game state.
Definition at line 92 of file multiplayer.hpp.
|
default |
Initializes the networking subsystem.
| space::MultiplayerSession::~MultiplayerSession | ( | ) |
Stops the session and releases networking resources.
Definition at line 13 of file multiplayer.cpp.
|
delete |
|
nodiscard |
Returns whether a host or client session is active.
Definition at line 197 of file multiplayer.cpp.
|
nodiscard |
Returns whether the local player has an established peer connection.
Definition at line 198 of file multiplayer.cpp.
| NetworkExchange space::MultiplayerSession::exchange | ( | const NetworkState & | local_state, |
| float | delta_time ) |
Sends local state and receives remote updates.
| local_state | Current local gameplay state. |
| delta_time | Frame duration in seconds. |
Definition at line 93 of file multiplayer.cpp.
| void space::MultiplayerSession::host | ( | const std::string & | port, |
| const std::string & | player_name ) |
Starts hosting a session.
| port | Local UDP port. |
| player_name | Host display name. |
Definition at line 37 of file multiplayer.cpp.
|
nodiscard |
Returns whether this session is the host.
Definition at line 199 of file multiplayer.cpp.
| void space::MultiplayerSession::join | ( | const std::string & | address, |
| const std::string & | port, | ||
| const std::string & | player_name, | ||
| const std::string & | join_code ) |
Joins a hosted session.
| address | Host address. |
| port | Host UDP port. |
| player_name | Local display name. |
| join_code | Host-provided session code. |
Definition at line 58 of file multiplayer.cpp.
|
nodiscard |
Returns the session join code.
Definition at line 208 of file multiplayer.cpp.
|
nodiscard |
Returns the assigned local player slot.
Definition at line 200 of file multiplayer.cpp.
|
delete |
|
nodiscard |
Returns connection flags indexed by player slot.
Definition at line 207 of file multiplayer.cpp.
|
nodiscard |
Returns the number of connected players.
Definition at line 202 of file multiplayer.cpp.
|
nodiscard |
Returns display names indexed by player slot.
Definition at line 206 of file multiplayer.cpp.
|
nodiscard |
Returns the automatic router port-mapping status.
Definition at line 210 of file multiplayer.cpp.
| void space::MultiplayerSession::stop | ( | ) |
Stops the active host or client session.
Definition at line 75 of file multiplayer.cpp.