diff --git a/include/examples/KeepAlivePacket.h b/include/examples/KeepAlivePacket.h index 02b63e2..fe6c266 100644 --- a/include/examples/KeepAlivePacket.h +++ b/include/examples/KeepAlivePacket.h @@ -10,11 +10,7 @@ enum KeepAlivePacketFields { }; using KeepAliveFields = std::tuple< - std::uint64_t, //<- KeepAliveId - sp::BitField, //<- m_Tower - sp::Field //<- m_Upgrade - > + std::uint64_t //<- KeepAliveId >; DeclarePacket(KeepAlive){ @@ -24,12 +20,4 @@ DeclarePacket(KeepAlive){ std::uint64_t GetKeepAliveId() const { return GetField(); } - - std::uint16_t GetTowerId() const { - return GetField().GetField<0>(); - } - - std::uint8_t GetTowerUpgrade() const { - return GetField().GetField<1>(); - } }; \ No newline at end of file diff --git a/include/examples/PacketExample.h b/include/examples/PacketExample.h index 02e18fc..c185c8f 100644 --- a/include/examples/PacketExample.h +++ b/include/examples/PacketExample.h @@ -3,13 +3,15 @@ enum PacketId { KeepAlive = 0, Disconnect, + UpgradeTower, }; #include #include +#include -// they must be in the same order ! -using AllPackets = std::tuple; +// they must be in the same order as in the enum ! +using AllPackets = std::tuple; #include #include \ No newline at end of file diff --git a/include/examples/UpgradeTowerPacket.h b/include/examples/UpgradeTowerPacket.h new file mode 100644 index 0000000..d54e692 --- /dev/null +++ b/include/examples/UpgradeTowerPacket.h @@ -0,0 +1,30 @@ +#pragma once + +#include +#include +#include + +enum UpgradeTowerPacketFields { + m_Tower = 0, + m_Upgrade, +}; + +using UpgradeTowerFields = std::tuple< + sp::BitField, //<- m_Tower + sp::Field //<- m_Upgrade + > + >; + +DeclarePacket(UpgradeTower){ + public: + PacketConstructor(UpgradeTower) + + std::uint16_t GetTowerId() const { + return GetField<0>().GetField(); + } + + std::uint8_t GetTowerUpgrade() const { + return GetField<0>().GetField(); + } +}; \ No newline at end of file diff --git a/src/main.cpp b/src/main.cpp index d6d7347..47f8ae5 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -11,12 +11,17 @@ class KeepAliveHandler : public sp::PacketHandler { void Handle(DisconnectPacket& packet) { std::cout << "Disconnect handled !\n"; } + + // TODO: add constness + void Handle(UpgradeTowerPacket& packet) { + std::cout << "UpgradeTower handled !\n"; + } }; int main() { - auto keepAlive = std::make_unique(69, std::make_tuple(666, 9)); + auto upgradeTower = std::make_unique(std::make_tuple(666, 9)); - sp::PacketMessage* msg = keepAlive.get(); + sp::PacketMessage* msg = upgradeTower.get(); KeepAliveHandler handler; msg->Dispatch(handler); @@ -27,13 +32,10 @@ int main() { std::uint8_t msgId; buffer >> msgId; - auto keepAlive2 = std::make_unique(); - keepAlive2->Read(buffer); + auto upgradeTower2 = std::make_unique(); + upgradeTower2->Read(buffer); - std::cout << "KeepAlive2 : " << keepAlive2->GetKeepAliveId() << "\n"; - - keepAlive2->GetField().GetField<0>(); - std::cout << "Test : " << (unsigned) keepAlive2->GetTowerId() << "\n"; + std::cout << "Test : " << (unsigned) upgradeTower2->GetTowerId() << "\n"; sp::PacketFactory factory; auto packet = factory.CreateMessage(msgId);