declare packets + commands

This commit is contained in:
2024-10-13 15:30:57 +02:00
parent 77317df56c
commit 0354ce776b
18 changed files with 461 additions and 273 deletions

View File

@@ -2,6 +2,10 @@
#include <td/Types.h>
#include <vector>
#include <td/protocol/command/Commands.h>
// Make it dynamic ?
#define LOCKSTEP_BUFFER_SIZE 10
namespace td {
namespace protocol {
@@ -11,64 +15,60 @@ struct PlayerInfo {
std::string m_PlayerName;
};
struct MapData {
};
namespace pdata {
/** Client attempts to login (very basic) */
struct PlayerLogin {
std::string m_PlayerName;
};
struct UpdateHealth {
float m_NewHealth;
};
/** Server indicates success */
struct LoggingSuccess {
PlayerID m_PlayerId;
};
struct PlayerDeath {};
/** Player joins the lobby */
struct PlayerJoin {
PlayerInfo m_Player;
};
/** Player leaves the lobby */
struct PlayerLeave {
PlayerID m_PlayerId;
};
struct PlayerStats {};
struct PlayerList {
std::vector<PlayerInfo> m_Players;
};
struct ServerConfig {};
struct ServerTps {};
struct UpdateGameState {};
/** Keep alive */
struct KeepAlive {
std::uint64_t m_KeepAliveId;
};
struct Disconnect {};
/** Can be used by both client and server */
struct Disconnect {
std::string m_Reason;
};
/** Chat message */
struct ChatMessage {
std::string m_Text;
};
struct PlayerPositionAndRotation {
PlayerID m_Player;
// godot::Vector3 m_Position;
// godot::Vector3 m_Rotation;
// godot::Vector3 m_Velocity;
// TODO: handle players joining in the first second
struct BeginGame {
MapData m_Map;
std::vector<PlayerInfo> m_BlueTeam;
std::vector<PlayerInfo> m_RedTeam;
// optional, used for players joining mid game
std::vector<LockStep> m_FirstLocksteps;
};
struct PlayerShoot {
PlayerID m_Sender;
// godot::Vector3 m_Position;
// godot::Vector3 m_Rotation;
// godot::Vector3 m_Velocity;
struct LockSteps {
std::uint16_t m_FirstFrameNumber;
std::array<LockStep, LOCKSTEP_BUFFER_SIZE> m_LockSteps;
};
} // namespace pdata

View File

@@ -34,21 +34,14 @@ enum class PacketSendType {
*/
#define DeclareAllPacket() \
DeclarePacket(ChatMessage, Reliable, Both) \
DeclarePacket(BeginGame, Reliable, Server) \
DeclarePacket(Disconnect, Reliable, Both) \
DeclarePacket(KeepAlive, Reliable, Both) \
DeclarePacket(LockSteps, Unreliable, Both) \
DeclarePacket(LoggingSuccess, Reliable, Server) \
DeclarePacket(PlayerDeath, Reliable, Server) \
DeclarePacket(PlayerJoin, Reliable, Server) \
DeclarePacket(PlayerLeave, Reliable, Server) \
DeclarePacket(PlayerList, Reliable, Server) \
DeclarePacket(PlayerLogin, Reliable, Client) \
DeclarePacket(PlayerPositionAndRotation, Unreliable, Both) \
DeclarePacket(PlayerShoot, Reliable, Both) \
DeclarePacket(PlayerStats, Reliable, Server) \
DeclarePacket(ServerConfig, Reliable, Server) \
DeclarePacket(ServerTps, Reliable, Server) \
DeclarePacket(UpdateGameState, Reliable, Server) \
DeclarePacket(UpdateHealth, Reliable, Client)
} // namespace protocol

View File

@@ -6,13 +6,12 @@
*/
#include <td/protocol/Dispatcher.h>
#include <td/protocol/packet/Packets.h>
namespace td {
namespace protocol {
class PacketHandler;
using PacketDispatcher = Dispatcher<PacketType, PacketHandler, Packet>;
using PacketDispatcher = Dispatcher<PacketType, PacketVisitor, Packet>;
} // namespace protocol
} // namespace td

View File

@@ -1,33 +0,0 @@
#pragma once
/**
* \file PacketHandler.h
* \brief File containing the td::protocol::PacketHandler class
*/
#include <td/protocol/packet/PacketVisitor.h>
#include <td/protocol/packet/Packets.h>
namespace td {
namespace protocol {
#define DeclarePacket(PacketName, ...) \
virtual void Visit(const packets::PacketName&); \
virtual void HandlePacket(const packets::PacketName&) {}
/**
* \class PacketHandler
* \brief Class used to handle packets
*/
class PacketHandler : public PacketVisitor {
public:
PacketHandler() {}
~PacketHandler() {}
DeclareAllPacket()
};
#undef DeclarePacket
} // namespace protocol
} // namespace td