GekkoNet
1.0
C/C++ Peer to Peer Game Networking SDK
Loading...
Searching...
No Matches
net.h
Go to the documentation of this file.
1
#pragma once
2
3
#include "
gekkonet.h
"
4
#include "
gekko_types.h
"
5
6
#include <memory>
7
#include <vector>
8
#include <variant>
9
#include <chrono>
10
11
namespace
Gekko
{
12
struct
NetAddress
{
13
NetAddress
();
14
NetAddress
(
void
* data,
u32
size);
15
16
u8
*
GetAddress
();
17
u32
GetSize
();
18
19
void
Copy
(
NetAddress
* other);
20
bool
Equals
(
NetAddress
& other);
21
22
private
:
23
std::unique_ptr<u8[]>
_data
;
24
u32
_size
;
25
};
26
27
enum
PacketType
:
u8
{
28
Inputs
= 1,
29
SpectatorInputs
,
30
InputAck
,
31
SyncRequest
,
32
SyncResponse
,
33
SessionHealth
,
34
NetworkHealth
,
35
Disconnect
,
36
DisconnectClaim
,
37
SpectatorState
,
38
SpectatorStateAck
39
};
40
41
struct
MsgHeader
{
42
PacketType
type
;
43
u16
magic
;
44
};
45
46
struct
InputMsg
{
47
Frame
start_frame
;
48
u16
input_count
;
49
u16
total_size
;
50
bool
compressed
;
51
52
std::vector<u8>
inputs
;
53
};
54
55
struct
InputAckMsg
{
56
Frame
ack_frame
;
57
i8
frame_advantage
;
58
};
59
60
struct
SyncMsg
{
61
u16
rng_data
;
62
};
63
64
struct
SessionHealthMsg
{
65
Frame
frame
;
66
u32
checksum
;
67
};
68
69
struct
NetworkHealthMsg
{
70
u64
send_time
;
71
bool
received
;
72
};
73
74
struct
SpectatorStateMsg
{
75
Frame
frame
;
76
u32
total_size
;
77
u32
offset
;
78
79
std::vector<u8>
state
;
80
};
81
82
struct
SpectatorStateAckMsg
{
83
Frame
frame
;
84
};
85
86
struct
DisconnectMsg
{
87
};
88
89
// claims which inputs the sender holds for a disconnected player and carries
90
// them along, so every peer can end that player on the same newest known frame.
91
struct
DisconnectClaimMsg
{
92
Handle
player
;
93
Frame
start_frame
;
94
Frame
last_frame
;
95
96
std::vector<u8>
inputs
;
97
};
98
99
using
MsgBody
= std::variant<
100
InputMsg
,
101
InputAckMsg
,
102
SyncMsg
,
103
SessionHealthMsg
,
104
NetworkHealthMsg
,
105
DisconnectMsg
,
106
DisconnectClaimMsg
,
107
SpectatorStateMsg
,
108
SpectatorStateAckMsg
109
>;
110
111
struct
NetPacket
{
112
MsgHeader
header
;
113
MsgBody
body
;
114
};
115
116
struct
NetData
{
117
NetAddress
addr
;
118
NetPacket
pkt
;
119
};
120
121
struct
NetStats
{
122
static
const
u64
DISCONNECT_TIMEOUT
= 5000;
123
static
const
u64
DISCONNECT_MSG_DELAY
= 200;
124
static
const
u64
DISCONNECT_CLAIM_HOLD
= 2000;
125
static
const
u64
SYNC_MSG_DELAY
= 200;
126
static
const
u64
NET_CHECK_DELAY
= 500;
127
static
const
u64
INPUT_RETRY_INTERVAL
= 200;
128
static
const
u32
RTT_HISTORY_SIZE
= 10;
129
130
Frame
last_acked_frame
= -1;
131
u64
last_sent_sync_message
= 0;
132
u64
last_received_message
= 0;
133
u64
last_received_frame
= 0;
134
135
float
kb_sent_per_sec
= 0;
136
float
kb_received_per_sec
= 0;
137
u32
bytes_sent_accum
= 0;
138
u32
bytes_received_accum
= 0;
139
u64
last_bandwidth_update
= 0;
140
141
std::vector<u16>
rtt
;
142
143
void
AddRTT
(
u16
rtt_ms);
144
void
UpdateBandwidth
();
145
float
CalculateJitter
();
146
float
CalculateAvgRTT
();
147
u32
LastRTT
();
148
};
149
150
struct
NetInputData
{
151
std::vector<Handle>
handles
;
152
InputMsg
input
;
153
};
154
}
gekko_types.h
u64
uint64_t u64
Definition
gekko_types.h:8
Handle
int32_t Handle
Definition
gekko_types.h:19
Frame
int32_t Frame
Definition
gekko_types.h:18
u8
uint8_t u8
Definition
gekko_types.h:5
u16
uint16_t u16
Definition
gekko_types.h:6
i8
int8_t i8
Definition
gekko_types.h:10
u32
uint32_t u32
Definition
gekko_types.h:7
gekkonet.h
Gekko
Definition
backend.h:18
Gekko::PacketType
PacketType
Definition
net.h:27
Gekko::InputAck
@ InputAck
Definition
net.h:30
Gekko::SpectatorStateAck
@ SpectatorStateAck
Definition
net.h:38
Gekko::SyncResponse
@ SyncResponse
Definition
net.h:32
Gekko::SessionHealth
@ SessionHealth
Definition
net.h:33
Gekko::NetworkHealth
@ NetworkHealth
Definition
net.h:34
Gekko::Inputs
@ Inputs
Definition
net.h:28
Gekko::DisconnectClaim
@ DisconnectClaim
Definition
net.h:36
Gekko::SpectatorState
@ SpectatorState
Definition
net.h:37
Gekko::Disconnect
@ Disconnect
Definition
net.h:35
Gekko::SyncRequest
@ SyncRequest
Definition
net.h:31
Gekko::SpectatorInputs
@ SpectatorInputs
Definition
net.h:29
Gekko::MsgBody
std::variant< InputMsg, InputAckMsg, SyncMsg, SessionHealthMsg, NetworkHealthMsg, DisconnectMsg, DisconnectClaimMsg, SpectatorStateMsg, SpectatorStateAckMsg > MsgBody
Definition
net.h:99
Gekko::DisconnectClaimMsg
Definition
net.h:91
Gekko::DisconnectClaimMsg::last_frame
Frame last_frame
Definition
net.h:94
Gekko::DisconnectClaimMsg::inputs
std::vector< u8 > inputs
Definition
net.h:96
Gekko::DisconnectClaimMsg::start_frame
Frame start_frame
Definition
net.h:93
Gekko::DisconnectClaimMsg::player
Handle player
Definition
net.h:92
Gekko::DisconnectMsg
Definition
net.h:86
Gekko::InputAckMsg
Definition
net.h:55
Gekko::InputAckMsg::frame_advantage
i8 frame_advantage
Definition
net.h:57
Gekko::InputAckMsg::ack_frame
Frame ack_frame
Definition
net.h:56
Gekko::InputMsg
Definition
net.h:46
Gekko::InputMsg::start_frame
Frame start_frame
Definition
net.h:47
Gekko::InputMsg::inputs
std::vector< u8 > inputs
Definition
net.h:52
Gekko::InputMsg::compressed
bool compressed
Definition
net.h:50
Gekko::InputMsg::input_count
u16 input_count
Definition
net.h:48
Gekko::InputMsg::total_size
u16 total_size
Definition
net.h:49
Gekko::MsgHeader
Definition
net.h:41
Gekko::MsgHeader::type
PacketType type
Definition
net.h:42
Gekko::MsgHeader::magic
u16 magic
Definition
net.h:43
Gekko::NetAddress
Definition
net.h:12
Gekko::NetAddress::Equals
bool Equals(NetAddress &other)
Definition
net.cpp:44
Gekko::NetAddress::_data
std::unique_ptr< u8[]> _data
Definition
net.h:23
Gekko::NetAddress::_size
u32 _size
Definition
net.h:24
Gekko::NetAddress::NetAddress
NetAddress()
Definition
net.cpp:21
Gekko::NetAddress::GetAddress
u8 * GetAddress()
Definition
net.cpp:49
Gekko::NetAddress::GetSize
u32 GetSize()
Definition
net.cpp:8
Gekko::NetAddress::Copy
void Copy(NetAddress *other)
Definition
net.cpp:27
Gekko::NetData
Definition
net.h:116
Gekko::NetData::addr
NetAddress addr
Definition
net.h:117
Gekko::NetData::pkt
NetPacket pkt
Definition
net.h:118
Gekko::NetInputData
Definition
net.h:150
Gekko::NetInputData::handles
std::vector< Handle > handles
Definition
net.h:151
Gekko::NetInputData::input
InputMsg input
Definition
net.h:152
Gekko::NetPacket
Definition
net.h:111
Gekko::NetPacket::header
MsgHeader header
Definition
net.h:112
Gekko::NetPacket::body
MsgBody body
Definition
net.h:113
Gekko::NetStats
Definition
net.h:121
Gekko::NetStats::INPUT_RETRY_INTERVAL
static const u64 INPUT_RETRY_INTERVAL
Definition
net.h:127
Gekko::NetStats::CalculateJitter
float CalculateJitter()
Definition
net.cpp:54
Gekko::NetStats::last_received_message
u64 last_received_message
Definition
net.h:132
Gekko::NetStats::rtt
std::vector< u16 > rtt
Definition
net.h:141
Gekko::NetStats::AddRTT
void AddRTT(u16 rtt_ms)
Definition
net.cpp:84
Gekko::NetStats::DISCONNECT_TIMEOUT
static const u64 DISCONNECT_TIMEOUT
Definition
net.h:122
Gekko::NetStats::bytes_sent_accum
u32 bytes_sent_accum
Definition
net.h:137
Gekko::NetStats::last_sent_sync_message
u64 last_sent_sync_message
Definition
net.h:131
Gekko::NetStats::DISCONNECT_MSG_DELAY
static const u64 DISCONNECT_MSG_DELAY
Definition
net.h:123
Gekko::NetStats::RTT_HISTORY_SIZE
static const u32 RTT_HISTORY_SIZE
Definition
net.h:128
Gekko::NetStats::bytes_received_accum
u32 bytes_received_accum
Definition
net.h:138
Gekko::NetStats::NET_CHECK_DELAY
static const u64 NET_CHECK_DELAY
Definition
net.h:126
Gekko::NetStats::kb_received_per_sec
float kb_received_per_sec
Definition
net.h:136
Gekko::NetStats::last_received_frame
u64 last_received_frame
Definition
net.h:133
Gekko::NetStats::LastRTT
u32 LastRTT()
Definition
net.cpp:112
Gekko::NetStats::last_bandwidth_update
u64 last_bandwidth_update
Definition
net.h:139
Gekko::NetStats::last_acked_frame
Frame last_acked_frame
Definition
net.h:130
Gekko::NetStats::kb_sent_per_sec
float kb_sent_per_sec
Definition
net.h:135
Gekko::NetStats::SYNC_MSG_DELAY
static const u64 SYNC_MSG_DELAY
Definition
net.h:125
Gekko::NetStats::DISCONNECT_CLAIM_HOLD
static const u64 DISCONNECT_CLAIM_HOLD
Definition
net.h:124
Gekko::NetStats::UpdateBandwidth
void UpdateBandwidth()
Definition
net.cpp:92
Gekko::NetStats::CalculateAvgRTT
float CalculateAvgRTT()
Definition
net.cpp:69
Gekko::NetworkHealthMsg
Definition
net.h:69
Gekko::NetworkHealthMsg::received
bool received
Definition
net.h:71
Gekko::NetworkHealthMsg::send_time
u64 send_time
Definition
net.h:70
Gekko::SessionHealthMsg
Definition
net.h:64
Gekko::SessionHealthMsg::frame
Frame frame
Definition
net.h:65
Gekko::SessionHealthMsg::checksum
u32 checksum
Definition
net.h:66
Gekko::SpectatorStateAckMsg
Definition
net.h:82
Gekko::SpectatorStateAckMsg::frame
Frame frame
Definition
net.h:83
Gekko::SpectatorStateMsg
Definition
net.h:74
Gekko::SpectatorStateMsg::frame
Frame frame
Definition
net.h:75
Gekko::SpectatorStateMsg::offset
u32 offset
Definition
net.h:77
Gekko::SpectatorStateMsg::state
std::vector< u8 > state
Definition
net.h:79
Gekko::SpectatorStateMsg::total_size
u32 total_size
Definition
net.h:76
Gekko::SyncMsg
Definition
net.h:60
Gekko::SyncMsg::rng_data
u16 rng_data
Definition
net.h:61
include
private
net.h
Generated by
1.15.0