better example
This commit is contained in:
@@ -10,11 +10,7 @@ enum KeepAlivePacketFields {
|
||||
};
|
||||
|
||||
using KeepAliveFields = std::tuple<
|
||||
std::uint64_t, //<- KeepAliveId
|
||||
sp::BitField<std::uint16_t,
|
||||
sp::Field<std::uint16_t, 12>, //<- m_Tower
|
||||
sp::Field<std::uint8_t, 4> //<- m_Upgrade
|
||||
>
|
||||
std::uint64_t //<- KeepAliveId
|
||||
>;
|
||||
|
||||
DeclarePacket(KeepAlive){
|
||||
@@ -24,12 +20,4 @@ DeclarePacket(KeepAlive){
|
||||
std::uint64_t GetKeepAliveId() const {
|
||||
return GetField<KeepAlive>();
|
||||
}
|
||||
|
||||
std::uint16_t GetTowerId() const {
|
||||
return GetField<TestAlignField>().GetField<0>();
|
||||
}
|
||||
|
||||
std::uint8_t GetTowerUpgrade() const {
|
||||
return GetField<TestAlignField>().GetField<1>();
|
||||
}
|
||||
};
|
||||
@@ -3,13 +3,15 @@
|
||||
enum PacketId {
|
||||
KeepAlive = 0,
|
||||
Disconnect,
|
||||
UpgradeTower,
|
||||
};
|
||||
|
||||
#include <examples/KeepAlivePacket.h>
|
||||
#include <examples/DisconnectPacket.h>
|
||||
#include <examples/UpgradeTowerPacket.h>
|
||||
|
||||
// they must be in the same order !
|
||||
using AllPackets = std::tuple<KeepAlivePacket, DisconnectPacket>;
|
||||
// they must be in the same order as in the enum !
|
||||
using AllPackets = std::tuple<KeepAlivePacket, DisconnectPacket, UpgradeTowerPacket>;
|
||||
|
||||
#include <sp/default/DefaultPacketHandler.h>
|
||||
#include <sp/default/DefaultPacketFactory.h>
|
||||
30
include/examples/UpgradeTowerPacket.h
Normal file
30
include/examples/UpgradeTowerPacket.h
Normal file
@@ -0,0 +1,30 @@
|
||||
#pragma once
|
||||
|
||||
#include <sp/default/DefaultPacket.h>
|
||||
#include <sp/protocol/Field.h>
|
||||
#include <sp/protocol/MessageBase.h>
|
||||
|
||||
enum UpgradeTowerPacketFields {
|
||||
m_Tower = 0,
|
||||
m_Upgrade,
|
||||
};
|
||||
|
||||
using UpgradeTowerFields = std::tuple<
|
||||
sp::BitField<std::uint16_t,
|
||||
sp::Field<std::uint16_t, 12>, //<- m_Tower
|
||||
sp::Field<std::uint8_t, 4> //<- m_Upgrade
|
||||
>
|
||||
>;
|
||||
|
||||
DeclarePacket(UpgradeTower){
|
||||
public:
|
||||
PacketConstructor(UpgradeTower)
|
||||
|
||||
std::uint16_t GetTowerId() const {
|
||||
return GetField<0>().GetField<m_Tower>();
|
||||
}
|
||||
|
||||
std::uint8_t GetTowerUpgrade() const {
|
||||
return GetField<0>().GetField<m_Upgrade>();
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user