Implement PacketReader method ReadPosition

This commit is contained in:
Alpyne 2020-10-31 01:18:28 -07:00
parent ac62c9d25e
commit f8e86ab9ba
2 changed files with 15 additions and 1 deletions

View File

@ -105,6 +105,11 @@ namespace Feather
return str;
}
inline BlockPos ReadPosition()
{
return BlockPos(Read<int64_t>());
}
uint32_t Length() const { return m_length; }
uint32_t Size() const { return m_length + m_lengthSize; }

View File

@ -23,10 +23,19 @@ namespace Feather
struct BlockPos
{
const int32_t x, y, z;
int32_t x, y, z;
BlockPos(int32_t x, int32_t y, int32_t z) : x(x), y(y), z(z) {}
// Decodes from packed long
BlockPos(int64_t l)
: x(l << (64 - X_OFFSET - PACKED_X_LENGTH) >> (64 - PACKED_X_LENGTH))
, y(l << (64 - Y_OFFSET - PACKED_Y_LENGTH) >> (64 - PACKED_Y_LENGTH))
, z(l << (64 - Z_OFFSET - PACKED_Z_LENGTH) >> (64 - PACKED_Z_LENGTH))
{}
BlockPos() : BlockPos(0, 0, 0) {}
inline int64_t Encode()
{
int64_t l = 0;