Divide Framework 0.1
A free and open-source 3D Framework under heavy development
Loading...
Searching...
No Matches
NetworkingComponent.cpp
Go to the documentation of this file.
1
2
4
7
10
11namespace Divide {
12
13hashMap<I64, NetworkingComponent*> NetworkingComponent::s_NetComponents;
14
17 _parentClient(context.client()),
18 _resendRequired(true)
19{
20 // Register a receive callback with parent:
21 // e.g.: _receive->bind(NetworkingComponent::onNetworkReceive);
22
23 s_NetComponents[parentSGN->getGUID()] = this;
24}
25
27{
28 s_NetComponents.erase(_parentSGN->getGUID());
29}
30
32 _resendRequired = true;
33}
34
35WorldPacket NetworkingComponent::deltaCompress(const WorldPacket& crt, [[maybe_unused]] const WorldPacket& previous) const {
36 return crt;
37}
38
39WorldPacket NetworkingComponent::deltaDecompress(const WorldPacket& crt, [[maybe_unused]] const WorldPacket& previous) const {
40 return crt;
41}
42
43void NetworkingComponent::onNetworkSend(const U32 frameCountIn) {
44 if (!_resendRequired) {
45 return;
46 }
47
49 dataOut << _parentSGN->getGUID();
50 dataOut << frameCountIn;
51
52 Attorney::SceneNodeNetworkComponent::onNetworkSend(_parentSGN, _parentSGN->getNode(), dataOut);
53
54 const WorldPacket p = deltaCompress(dataOut, _previousSent);
55 _previousSent = p;
56
58}
59
63
64 Attorney::SceneNodeNetworkComponent::onNetworkReceive(_parentSGN, _parentSGN->getNode(), dataIn);
65}
66
69
70 if (it != std::cend(s_NetComponents)) {
71 return it->second;
72 }
73
74 return nullptr;
75}
76
78 I64 tempGUID = -1;
79 p >> tempGUID;
80
82
83 if (net) {
84 U32 frameCountOut = 0;
85 // May be used to handle delta decompression in a specific manner;
86 p >> frameCountOut;
87 net->onNetworkReceive(p);
88 }
89}
90
91} //namespace Divide
virtual bool sendPacket(WorldPacket &p) const
Send a packet to the target server.
Definition: ASIO.cpp:93
static void onNetworkReceive(SceneGraphNode *sgn, const SceneNode &node, WorldPacket &dataIn)
Definition: SceneNode.h:198
static void onNetworkSend(SceneGraphNode *sgn, const SceneNode &node, WorldPacket &dataOut)
Definition: SceneNode.h:194
FORCE_INLINE I64 getGUID() const noexcept
Definition: GUIDWrapper.h:51
NetworkingComponent(SceneGraphNode *parentSGN, PlatformContext &context)
WorldPacket deltaDecompress(const WorldPacket &crt, const WorldPacket &previous) const
WorldPacket deltaCompress(const WorldPacket &crt, const WorldPacket &previous) const
static hashMap< I64, NetworkingComponent * > s_NetComponents
void onNetworkSend(U32 frameCountIn)
static NetworkingComponent * getReceiver(I64 guid)
void onNetworkReceive(WorldPacket &dataIn)
static const ValueType CMSG_ENTITY_UPDATE
Definition: OPCodesTpl.h:22
Handle console commands that start with a forward slash.
Definition: AIProcessor.cpp:7
void UpdateEntities(WorldPacket &p)
hashAlg::unordered_map< K, V, HashFun, Predicate > hashMap
Definition: HashMap.h:55
SGNComponent::Registrar< T, C > BaseComponentType
Definition: SGNComponent.h:207
int64_t I64
uint32_t U32