-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
871 additions
and
0 deletions.
There are no files selected for viewing
65 changes: 65 additions & 0 deletions
65
dependencies/enetpp/include/enetpp/client_connect_params.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
#ifndef ENETPP_CLIENT_CONNECT_PARAMS_H_ | ||
#define ENETPP_CLIENT_CONNECT_PARAMS_H_ | ||
|
||
#include "enet/enet.h" | ||
#include <chrono> | ||
|
||
namespace enetpp { | ||
|
||
class client_connect_params { | ||
public: | ||
size_t _channel_count; | ||
enet_uint32 _incoming_bandwidth; | ||
enet_uint32 _outgoing_bandwidth; | ||
std::string _server_host_name; | ||
enet_uint16 _server_port; | ||
std::chrono::milliseconds _timeout; | ||
|
||
public: | ||
client_connect_params() | ||
: _channel_count(0) | ||
, _incoming_bandwidth(0) | ||
, _outgoing_bandwidth(0) | ||
, _server_host_name() | ||
, _server_port(0) | ||
, _timeout(0) { | ||
} | ||
|
||
client_connect_params& set_channel_count(size_t channel_count) { | ||
_channel_count = channel_count; | ||
return *this; | ||
} | ||
|
||
client_connect_params& set_incoming_bandwidth(enet_uint32 bandwidth) { | ||
_incoming_bandwidth = bandwidth; | ||
return *this; | ||
} | ||
|
||
client_connect_params& set_outgoing_bandwidth(enet_uint32 bandwidth) { | ||
_outgoing_bandwidth = bandwidth; | ||
return *this; | ||
} | ||
|
||
client_connect_params& set_server_host_name_and_port(const char* host_name, enet_uint16 port) { | ||
_server_host_name = host_name; | ||
_server_port = port; | ||
return *this; | ||
} | ||
|
||
client_connect_params& set_timeout(std::chrono::milliseconds timeout) { | ||
_timeout = timeout; | ||
return *this; | ||
} | ||
|
||
ENetAddress make_server_address() const { | ||
ENetAddress address; | ||
enet_address_set_host(&address, _server_host_name.c_str()); | ||
address.port = _server_port; | ||
return address; | ||
} | ||
|
||
}; | ||
|
||
} | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
#ifndef ENETPP_CLIENT_QUEUED_PACKET_H_ | ||
#define ENETPP_CLIENT_QUEUED_PACKET_H_ | ||
|
||
#include "enet/enet.h" | ||
|
||
namespace enetpp { | ||
|
||
class client_queued_packet { | ||
public: | ||
enet_uint8 _channel_id; | ||
ENetPacket* _packet; | ||
|
||
public: | ||
client_queued_packet() | ||
: _channel_id(0) | ||
, _packet(nullptr) { | ||
} | ||
|
||
client_queued_packet(enet_uint8 channel_id, ENetPacket* packet) | ||
: _channel_id(channel_id) | ||
, _packet(packet) { | ||
} | ||
}; | ||
|
||
} | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
#pragma once | ||
|
||
#include <atomic> | ||
|
||
namespace enetpp { | ||
|
||
class client_statistics { | ||
public: | ||
std::atomic<int> _round_trip_time_in_ms; | ||
std::atomic<int> _round_trip_time_variance_in_ms; | ||
|
||
public: | ||
client_statistics() | ||
: _round_trip_time_in_ms(0) | ||
, _round_trip_time_variance_in_ms(0) { | ||
} | ||
}; | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
#ifndef ENETPP_GLOBAL_STATE_H_ | ||
#define ENETPP_GLOBAL_STATE_H_ | ||
|
||
#include <assert.h> | ||
#include "enet/enet.h" | ||
|
||
namespace enetpp { | ||
|
||
//ugh | ||
class global_state { | ||
private: | ||
bool _is_initialized; | ||
|
||
public: | ||
static global_state& get() { | ||
static global_state g; | ||
return g; | ||
} | ||
|
||
public: | ||
bool is_initialized() const { | ||
return _is_initialized; | ||
} | ||
|
||
void initialize() { | ||
assert(!_is_initialized); | ||
enet_initialize(); | ||
_is_initialized = true; | ||
} | ||
|
||
void deinitialize() { | ||
enet_deinitialize(); | ||
_is_initialized = false; | ||
} | ||
|
||
private: | ||
global_state() | ||
: _is_initialized(false) { | ||
} | ||
}; | ||
|
||
} | ||
|
||
#endif |
Oops, something went wrong.