-
Notifications
You must be signed in to change notification settings - Fork 0
/
PST4Net.hpp
109 lines (76 loc) · 2.65 KB
/
PST4Net.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
#pragma once
#include <Annwvyn.h>
#include <RakPeerInterface.h>
#include <RakNetTypes.h>
#include <RakVoice.h>
#include <BitStream.h>
#include <MessageIdentifiers.h>
#define I_AM_CLIENT
#include <PST4Packets.hpp>
#include <cstring>
#include "PST4RemoteUser.hpp"
#include "PST4VoiceSystem.hpp"
namespace PST4
{
class NetSubSystem : public Annwvyn::AnnUserSubSystem
{
public:
///State of the connection
enum class NetState { NOT_READY, READY, CONNECTED, FAILED };
///Connect to the port 42420 on the given host
NetSubSystem(const std::string& serverHostname);
///Cleanly disconnect here
~NetSubSystem();
///Locked to return true
bool needUpdate() override;
///Get execution of our netcode here
void update() override;
///Access to this class singleton instance
static NetSubSystem* getNet();
void addSyncedPhyscisObject(std::shared_ptr<Annwvyn::AnnGameObject> obj);
void setGrabbedObject(std::shared_ptr<Annwvyn::AnnGameObject> obj);
bool dynamicObjectOwned(const std::string& objName);
private:
std::unordered_map <std::string, std::shared_ptr<Annwvyn::AnnGameObject >> syncedPhysicsObject;
std::unordered_map <std::string, size_t> lastOwner;
float dynObjectDeviationThreshold;
std::shared_ptr<Annwvyn::AnnGameObject> userGrabbedDynamicObject;
void sendCycle();
void handleRecivedHeadPose();
void handleReceivedHandPose();
void handleReceivedVoiceBuffer();
void handleReceivedDynamicObject();
void waitAndRequestSessionID();
void handleEndOfRemoteSession();
void receiveCycle();
///State
NetState netState;
///text address of the server
std::string serverAddress;
///Last packet sent ACK's number. For heartbeat
uint32_t lastHBAck;
///Singleton
static NetSubSystem* singleton;
///The peer, our interface with the network
RakNet::RakPeerInterface* peer;
///Pointer to the packet we're processing
RakNet::Packet* packet;
///Socket descriptor
RakNet::SocketDescriptor sd;
///systemAddress of the server, you need that to send packet to the server directly
RakNet::SystemAddress serverSystemAddress;
///Port of the server application. Must have an open UDP path to this port
static constexpr const auto port = 42420U;
///A packet with an echo message
echoPacket p;
///Time since last heartbeat worked
double lastHeartbeatTime;
///ID of the session. Server will give us this number.
size_t sessionId;
///Map of remotes, indexed to their session id
std::unordered_map<size_t, std::unique_ptr<RemoteUser>> remotes;
//RakNet::RakVoice rakvoice; <- we're using our own
///Object that permit to record, encode and decode audio.
std::unique_ptr<VoiceSystem> voiceSystem;
};
}