unreliable packets

This commit is contained in:
2024-08-20 19:27:20 +02:00
parent bebc306097
commit d0948f6ce5
5 changed files with 144 additions and 15 deletions

View File

@@ -12,7 +12,7 @@ namespace protocol {
* \enum PacketSender
* \brief Indicate who should send a packet
*/
enum class PacketSender {
enum class PacketSenderType {
/** Sent by clients and server */
Both,
/** Sent by clients to the server */
@@ -36,7 +36,7 @@ enum class PacketSender {
DeclarePacket(PlayerLeave, Reliable, Server) \
DeclarePacket(PlayerList, Reliable, Server) \
DeclarePacket(PlayerLogin, Reliable, Client) \
DeclarePacket(PlayerPositionAndRotation, Reliable, Both) \
DeclarePacket(PlayerPositionAndRotation, Unreliable, Both) \
DeclarePacket(PlayerShoot, Reliable, Both) \
DeclarePacket(PlayerStats, Reliable, Server) \
DeclarePacket(ServerConfig, Reliable, Server) \

View File

@@ -0,0 +1,57 @@
#pragma once
#include <blitz/protocol/PacketVisitor.h>
namespace blitz {
class NetworkInterface;
namespace protocol {
///////////////////////
/* PacketBroadcaster */
///////////////////////
#define DeclarePacket(PacketName, Reliability, ...) void Visit(const protocol::packets::PacketName& a_Packet) override;
class PacketBroadcaster : public protocol::PacketVisitor {
private:
NetworkInterface& m_NetworkInterface;
public:
PacketBroadcaster(NetworkInterface& a_NetworkInterface) : m_NetworkInterface(a_NetworkInterface) {}
void BroadcastPacket(const protocol::Packet& a_Packet) {
Check(a_Packet);
}
DeclareAllPacket()
};
//////////////////
/* PacketSender */
//////////////////
class PacketSender : public protocol::PacketVisitor {
private:
NetworkInterface& m_NetworkInterface;
PeerID m_PeerId;
public:
PacketSender(PeerID a_PeerId, NetworkInterface& a_NetworkInterface) : m_PeerId(a_PeerId), m_NetworkInterface(a_NetworkInterface) {}
void SendPacket(const protocol::Packet& a_Packet) {
Check(a_Packet);
}
DeclareAllPacket()
};
#undef DeclarePacket
} // namespace protocol
} // namespace blitz