Skip to content

Commit

Permalink
actually add enetpp
Browse files Browse the repository at this point in the history
  • Loading branch information
praydog committed Jul 29, 2022
1 parent ff63ef4 commit 31dc59f
Show file tree
Hide file tree
Showing 12 changed files with 871 additions and 0 deletions.
65 changes: 65 additions & 0 deletions dependencies/enetpp/include/enetpp/client_connect_params.h
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
27 changes: 27 additions & 0 deletions dependencies/enetpp/include/enetpp/client_queued_packet.h
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
19 changes: 19 additions & 0 deletions dependencies/enetpp/include/enetpp/client_statistics.h
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) {
}
};

}
44 changes: 44 additions & 0 deletions dependencies/enetpp/include/enetpp/global_state.h
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
Loading

0 comments on commit 31dc59f

Please sign in to comment.