VOX
A little voxel engine
Loading...
Searching...
No Matches
BlockActionPacket Class Reference

#include <BlockActionPacket.hpp>

Inheritance diagram for BlockActionPacket:
Inheritance graph
Collaboration diagram for BlockActionPacket:
Collaboration graph

Public Types

enum class  Action : uint8_t { PLACE }
 
- Public Types inherited from IPacket
enum class  Type : uint32_t {
  CONNECTION , PLAYER_CONNECTED , PLAYER_MOVE , DISCONNECT ,
  BLOCK_ACTION , PING , PLAYER_LIST , CHUNK ,
  CHUNK_REQUEST , CHUNK_UNLOAD , LOAD_DISTANCE , ENUM_MAX ,
  ENUM_MIN = 0
}
 

Public Member Functions

 BlockActionPacket ()
 
 BlockActionPacket (BlockInfo::Type block_id, glm::vec3 position, Action action)
 
 ~BlockActionPacket ()
 
 BlockActionPacket (const BlockActionPacket &other)
 
BlockActionPacketoperator= (const BlockActionPacket &other)
 
 BlockActionPacket (BlockActionPacket &&other)
 
BlockActionPacketoperator= (BlockActionPacket &&other)
 
void Serialize (uint8_t *buffer) const override
 will write the packet in the buffer, the buffer must at least be of size Size() More...
 
void Deserialize (const uint8_t *buffer) override
 read the packet from the buffer, the buffer must at least be of size Size() More...
 
uint32_t Size () const override
 return the size of the packet in bytes, usually used to reserve the right amount of memory in the send buffer More...
 
bool HasDynamicSize () const override
 Tell if the packet has a dynamic size. More...
 
IPacket::Type GetType () const override
 Get the Type of the packet. More...
 
std::shared_ptr< IPacketClone () const override
 Create a new instance of the packet. More...
 
BlockInfo::Type GetBlockID () const
 
glm::vec3 GetPosition () const
 
Action GetAction () const
 
void SetBlockID (BlockInfo::Type block_id)
 
void SetPosition (glm::vec3 position)
 
void SetAction (Action action)
 
- Public Member Functions inherited from IPacket
virtual ~IPacket ()
 
 IPacket (const IPacket &)
 
IPacketoperator= (const IPacket &)
 
 IPacket (IPacket &&)
 
IPacketoperator= (IPacket &&)
 
virtual void Serialize (uint8_t *buffer) const =0
 will write the packet in the buffer, the buffer must at least be of size Size() More...
 
void ExtractMessage (Connection &connection)
 Extracts the implemented packet from the connection. More...
 
virtual uint32_t Size () const =0
 return the size of the packet in bytes, usually used to reserve the right amount of memory in the send buffer More...
 
virtual bool HasDynamicSize () const =0
 Tell if the packet has a dynamic size. More...
 
virtual enum Type GetType () const =0
 Get the Type of the packet. More...
 
virtual std::shared_ptr< IPacketClone () const =0
 Create a new instance of the packet. More...
 
uint64_t GetConnectionId () const
 Get the Connection Id ( eg source of the packet or destination if it's a response) More...
 
void SetConnectionId (uint64_t connection_id)
 Set the Connection Id ( eg source of the packet or destination if it's a response) More...
 

Additional Inherited Members

- Static Public Attributes inherited from IPacket
static const uint32_t STATIC_HEADER_SIZE = sizeof(Type)
 
static const uint32_t DYNAMIC_HEADER_SIZE = sizeof(Type) + sizeof(size_t)
 
- Protected Member Functions inherited from IPacket
virtual void Deserialize (const uint8_t *buffer)=0
 read the packet from the buffer, the buffer must at least be of size Size() More...
 
size_t SerializeHeader (uint8_t *buffer) const
 util function to serialize the header of the packet will serialize the type and the size of the packet if it has a dynamic size More...
 
 IPacket ()
 
- Protected Attributes inherited from IPacket
uint64_t m_connection_id = 0
 

Member Enumeration Documentation

◆ Action

enum class BlockActionPacket::Action : uint8_t
strong
Enumerator
PLACE 

Constructor & Destructor Documentation

◆ BlockActionPacket() [1/4]

BlockActionPacket::BlockActionPacket ( )

◆ BlockActionPacket() [2/4]

BlockActionPacket::BlockActionPacket ( BlockInfo::Type  block_id,
glm::vec3  position,
Action  action 
)

◆ ~BlockActionPacket()

BlockActionPacket::~BlockActionPacket ( )

◆ BlockActionPacket() [3/4]

BlockActionPacket::BlockActionPacket ( const BlockActionPacket other)

◆ BlockActionPacket() [4/4]

BlockActionPacket::BlockActionPacket ( BlockActionPacket &&  other)

Member Function Documentation

◆ Clone()

std::shared_ptr< IPacket > BlockActionPacket::Clone ( ) const
overridevirtual

Create a new instance of the packet.

Returns
std::shared_ptr<IPacket>

Implements IPacket.

◆ Deserialize()

void BlockActionPacket::Deserialize ( const uint8_t *  buffer)
overridevirtual

read the packet from the buffer, the buffer must at least be of size Size()

Note
this is protected because the method the user should call is ExtractMessage
Parameters
buffer

Implements IPacket.

◆ GetAction()

BlockActionPacket::Action BlockActionPacket::GetAction ( ) const

◆ GetBlockID()

BlockInfo::Type BlockActionPacket::GetBlockID ( ) const

◆ GetPosition()

glm::vec3 BlockActionPacket::GetPosition ( ) const

◆ GetType()

IPacket::Type BlockActionPacket::GetType ( ) const
overridevirtual

Get the Type of the packet.

Returns
enum Type

Implements IPacket.

◆ HasDynamicSize()

bool BlockActionPacket::HasDynamicSize ( ) const
overridevirtual

Tell if the packet has a dynamic size.

Returns
true
false

Implements IPacket.

◆ operator=() [1/2]

BlockActionPacket & BlockActionPacket::operator= ( BlockActionPacket &&  other)

◆ operator=() [2/2]

BlockActionPacket & BlockActionPacket::operator= ( const BlockActionPacket other)

◆ Serialize()

void BlockActionPacket::Serialize ( uint8_t *  buffer) const
overridevirtual

will write the packet in the buffer, the buffer must at least be of size Size()

Parameters
buffer

Implements IPacket.

◆ SetAction()

void BlockActionPacket::SetAction ( Action  action)

◆ SetBlockID()

void BlockActionPacket::SetBlockID ( BlockInfo::Type  block_id)

◆ SetPosition()

void BlockActionPacket::SetPosition ( glm::vec3  position)

◆ Size()

uint32_t BlockActionPacket::Size ( ) const
overridevirtual

return the size of the packet in bytes, usually used to reserve the right amount of memory in the send buffer

or to check if a connection contains a complete packet

Warning
if the packet has a dynamic size YOU CANNOT call this method to check if the packet is complete, you MUST read the size from the packet header.

However you can still use it on an instance of a packet that has some data in it to estimate the size of the packet

Returns
uint32_t

Implements IPacket.


The documentation for this class was generated from the following files: