Leviathan  0.8.0.0
Leviathan game engine
NetworkAckField.h
Go to the documentation of this file.
1 // Leviathan Game Engine
2 // Copyright (c) 2012-2017 Henri Hyyryläinen
3 #pragma once
4 #include "Define.h"
5 // ------------------------------------ //
6 
7 #include <map>
8 #include <vector>
9 #include <functional>
10 #include <memory>
11 
12 namespace sf{
13 class Packet;
14 }
15 
16 
17 namespace Leviathan{
18 
22 enum class RECEIVED_STATE{
23 
25  NotReceived = 0,
26 
29 
32  AcksSent,
33 
37 };
38 
40 public:
41 
42  using PacketReceiveStatus = std::map<uint32_t, RECEIVED_STATE>;
43 
47  DLLEXPORT NetworkAckField(uint32_t firstpacketid, uint8_t maxacks,
48  PacketReceiveStatus &copyfrom);
49 
50  DLLEXPORT NetworkAckField(sf::Packet &packet);
51 
52 
53  DLLEXPORT void AddDataToPacket(sf::Packet &packet) const;
54 
56  inline bool IsAckSet(uint8_t ackindex) const{
57 
58  // We can use division to find out which vector element is wanted //
59  size_t vecelement = ackindex / 8;
60 
61  if (vecelement >= Acks.size())
62  return false;
63 
64  return (Acks[vecelement] & (1 << (ackindex % 8))) != 0;
65  }
66 
68  DLLEXPORT void InvokeForEachAck(std::function<void (uint32_t)> func) const;
69 
70  // Data //
72  std::vector<uint8_t> Acks;
73 };
74 
75 
77 struct SentAcks{
78 
79  SentAcks(uint32_t localpacketid, std::shared_ptr<NetworkAckField> acks) :
80  InsidePacket(localpacketid), AcksInThePacket(acks)
81  {}
82 
85 
86  std::shared_ptr<NetworkAckField> AcksInThePacket;
87 
90  bool Received = false;
91 };
92 
93 }
Entity is received from a server.
Definition: Components.h:167
uint32_t InsidePacket
The packet (SentNetworkThing) in which these acks were sent //.
DLLEXPORT NetworkAckField(uint32_t firstpacketid, uint8_t maxacks, PacketReceiveStatus &copyfrom)
Copies acts from copyfrom starting with the number firstpacketid.
bool IsAckSet(uint8_t ackindex) const
Holds sent ack packets in order to mark the acks as properly sent.
std::vector< uint8_t > Acks
RECEIVED_STATE
For keeping track of received remote packets.
unsigned char uint8_t
Definition: core.h:38
SentAcks(uint32_t localpacketid, std::shared_ptr< NetworkAckField > acks)
Definition: Connection.h:19
DLLEXPORT void InvokeForEachAck(std::function< void(uint32_t)> func) const
Calls func with each set ack.
Packet is received but no acks have been sent.
std::map< uint32_t, RECEIVED_STATE > PacketReceiveStatus
#define DLLEXPORT
Definition: Include.h:84
DLLEXPORT void AddDataToPacket(sf::Packet &packet) const
Packet hasn&#39;t been received.
The access mask controls which registered functions and classes a script sees.
Definition: GameModule.h:12
unsigned int uint32_t
Definition: core.h:40
std::shared_ptr< NetworkAckField > AcksInThePacket