-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c7d2f3e
commit d03b708
Showing
13 changed files
with
252 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,121 @@ | ||
#include "BlockActionPacket.hpp" | ||
|
||
BlockActionPacket::BlockActionPacket() | ||
{ | ||
} | ||
|
||
BlockActionPacket::BlockActionPacket(BlockID block_id, glm::ivec3 position, Action action) | ||
: m_block_id(block_id), m_position(position), m_action(action) | ||
{ | ||
} | ||
|
||
BlockActionPacket::BlockActionPacket(const BlockActionPacket & other) | ||
: IPacket(other), m_block_id(other.m_block_id), m_position(other.m_position), m_action(other.m_action) | ||
{ | ||
} | ||
|
||
BlockActionPacket & BlockActionPacket::operator=(const BlockActionPacket & other) | ||
{ | ||
if (this != &other) | ||
{ | ||
m_block_id = other.m_block_id; | ||
m_position = other.m_position; | ||
m_action = other.m_action; | ||
::IPacket::operator=(other); | ||
} | ||
return *this; | ||
} | ||
|
||
BlockActionPacket::BlockActionPacket(BlockActionPacket && other) | ||
: IPacket(other), m_block_id(other.m_block_id), m_position(other.m_position), m_action(other.m_action) | ||
{ | ||
} | ||
|
||
BlockActionPacket & BlockActionPacket::operator=(BlockActionPacket && other) | ||
{ | ||
if (this != &other) | ||
{ | ||
m_block_id = other.m_block_id; | ||
m_position = other.m_position; | ||
m_action = other.m_action; | ||
::IPacket::operator=(other); | ||
} | ||
return *this; | ||
} | ||
|
||
BlockActionPacket::~BlockActionPacket() | ||
{ | ||
} | ||
|
||
void BlockActionPacket::Serialize(uint8_t * buffer) const | ||
{ | ||
uint32_t type = static_cast<uint32_t>(GetType()); | ||
memcpy(buffer, &type, sizeof(uint32_t)); | ||
buffer += sizeof(uint32_t); | ||
|
||
memcpy(buffer, &m_block_id, sizeof(m_block_id)); | ||
buffer += sizeof(m_block_id); | ||
|
||
memcpy(buffer, &m_position, sizeof(m_position)); | ||
buffer += sizeof(m_position); | ||
|
||
memcpy(buffer, &m_action, sizeof(m_action)); | ||
buffer += sizeof(m_action); | ||
} | ||
|
||
void BlockActionPacket::Deserialize(const uint8_t * buffer) | ||
{ | ||
memcpy(&m_block_id, buffer, sizeof(m_block_id)); | ||
buffer += sizeof(m_block_id); | ||
|
||
memcpy(&m_position, buffer, sizeof(m_position)); | ||
buffer += sizeof(m_position); | ||
|
||
memcpy(&m_action, buffer, sizeof(m_action)); | ||
buffer += sizeof(m_action); | ||
} | ||
|
||
uint32_t BlockActionPacket::Size() const | ||
{ | ||
return sizeof(IPacket::Type) + sizeof(m_block_id) + sizeof(m_position) + sizeof(m_action); | ||
} | ||
|
||
IPacket::Type BlockActionPacket::GetType() const | ||
{ | ||
return IPacket::Type::BLOCK_ACTION; | ||
} | ||
|
||
std::shared_ptr<IPacket> BlockActionPacket::Clone() const | ||
{ | ||
return std::make_shared<BlockActionPacket>(); | ||
} | ||
|
||
BlockID BlockActionPacket::GetBlockID() const | ||
{ | ||
return m_block_id; | ||
} | ||
|
||
glm::ivec3 BlockActionPacket::GetPosition() const | ||
{ | ||
return m_position; | ||
} | ||
|
||
BlockActionPacket::Action BlockActionPacket::GetAction() const | ||
{ | ||
return m_action; | ||
} | ||
|
||
void BlockActionPacket::SetBlockID(BlockID block_id) | ||
{ | ||
m_block_id = block_id; | ||
} | ||
|
||
void BlockActionPacket::SetPosition(glm::ivec3 position) | ||
{ | ||
m_position = position; | ||
} | ||
|
||
void BlockActionPacket::SetAction(Action action) | ||
{ | ||
m_action = action; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
#pragma once | ||
|
||
#include "IPacket.hpp" | ||
#include "Block.hpp" | ||
|
||
class BlockActionPacket : public IPacket | ||
{ | ||
public: | ||
enum class Action : uint8_t | ||
{ | ||
PLACE | ||
}; | ||
|
||
BlockActionPacket(); | ||
BlockActionPacket(BlockID block_id, glm::ivec3 position, Action action); | ||
~BlockActionPacket(); | ||
|
||
BlockActionPacket(const BlockActionPacket& other); | ||
BlockActionPacket& operator=(const BlockActionPacket& other); | ||
|
||
BlockActionPacket(BlockActionPacket&& other); | ||
BlockActionPacket& operator=(BlockActionPacket&& other); | ||
|
||
|
||
virtual void Serialize(uint8_t * buffer) const override; | ||
virtual void Deserialize(const uint8_t * buffer) override; | ||
virtual uint32_t Size() const override; | ||
virtual IPacket::Type GetType() const override; | ||
|
||
virtual std::shared_ptr<IPacket> Clone() const override; | ||
|
||
BlockID GetBlockID() const; | ||
glm::ivec3 GetPosition() const; | ||
Action GetAction() const; | ||
|
||
void SetBlockID(BlockID block_id); | ||
void SetPosition(glm::ivec3 position); | ||
void SetAction(Action action); | ||
private: | ||
BlockID m_block_id; | ||
glm::ivec3 m_position; | ||
Action m_action; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.