vkmEngine 1.0.15
A C++ game engine · vkmengine.com
Loading...
Searching...
No Matches
protocol.h
1#pragma once
2
3#include <cstdint>
4
5#include "core/engine_config.h"
6#include "net/wire/bit_stream.h"
7
8namespace Vkm::Engine {
9
11constexpr uint16_t NET_PROTOCOL_TAG = 0x564B;
12
14constexpr uint8_t NET_PROTOCOL_VERSION = 12;
15
23enum class NetMessage : uint8_t {
24 Hello = 1,
25 Welcome = 2,
26 Refuse = 3,
27 Goodbye = 4,
28 Snapshot = 5,
29 Command = 6,
30 Challenge = 7,
31 Count
32};
33
39enum class NetRefusal : uint8_t {
40 Full = 1,
41 Mismatch = 2,
42 Declined = 3,
43 TickRate = 4,
44 Count
45};
46
48const char* toString(NetRefusal reason);
49
51enum class NetSender : uint8_t {
52 ThisBuild,
53 OtherBuild,
54 Unknown
55};
56
58constexpr uint32_t NET_MESSAGE_HEADER_BITS = 16 + 8 + 8 + 64;
59
67void writeMessageHeader(BitWriter& out, NetMessage message, uint64_t token);
68
81NetSender readMessageHeader(BitReader& in, NetMessage& message, uint64_t& token);
82
88enum class NetRole : uint8_t {
89 Offline = 0,
90 Server,
91 Client,
92
100 Disconnected,
101 Count
102};
103
105constexpr bool isAuthority(NetRole role) {
106 return role == NetRole::Offline || role == NetRole::Server;
107}
108
116constexpr float NET_MAX_SCALE = 1024.0f;
117
125constexpr uint32_t NET_MAX_TICK_JUMP = Config::MAX_TICK_RATE * 60;
126
130using PlayerId = uint16_t;
131constexpr PlayerId NO_PLAYER = 0;
132
133} // namespace Vkm::Engine
Reads back what a BitWriter wrote, in the same order.
Definition bit_stream.h:145
Packs values to the bit into a byte buffer.
Definition bit_stream.h:19