summaryrefslogtreecommitdiffstats
path: root/src/ByteBuffer.cpp
diff options
context:
space:
mode:
authorMasy98 <masy@antheruscraft.de>2014-09-26 18:32:31 +0200
committerMasy98 <masy@antheruscraft.de>2014-09-26 18:32:31 +0200
commit2feee3b316bf5cad87f9b9540c6b49f1775ada6e (patch)
tree7e508a2cc3d2c8586327e8074337da537cbbad5f /src/ByteBuffer.cpp
parentAdded slime block to slime balls recipe (diff)
parentFixed issue with casting (diff)
downloadcuberite-2feee3b316bf5cad87f9b9540c6b49f1775ada6e.tar
cuberite-2feee3b316bf5cad87f9b9540c6b49f1775ada6e.tar.gz
cuberite-2feee3b316bf5cad87f9b9540c6b49f1775ada6e.tar.bz2
cuberite-2feee3b316bf5cad87f9b9540c6b49f1775ada6e.tar.lz
cuberite-2feee3b316bf5cad87f9b9540c6b49f1775ada6e.tar.xz
cuberite-2feee3b316bf5cad87f9b9540c6b49f1775ada6e.tar.zst
cuberite-2feee3b316bf5cad87f9b9540c6b49f1775ada6e.zip
Diffstat (limited to 'src/ByteBuffer.cpp')
-rw-r--r--src/ByteBuffer.cpp48
1 files changed, 47 insertions, 1 deletions
diff --git a/src/ByteBuffer.cpp b/src/ByteBuffer.cpp
index 96556bf61..70fdc008c 100644
--- a/src/ByteBuffer.cpp
+++ b/src/ByteBuffer.cpp
@@ -267,7 +267,7 @@ size_t cByteBuffer::GetReadableSpace(void) const
}
// Single readable space partition:
ASSERT(m_WritePos >= m_ReadPos);
- return m_WritePos - m_ReadPos ;
+ return m_WritePos - m_ReadPos;
}
@@ -489,6 +489,30 @@ bool cByteBuffer::ReadLEInt(int & a_Value)
+bool cByteBuffer::ReadPosition(int & a_BlockX, int & a_BlockY, int & a_BlockZ)
+{
+ Int64 Value;
+ if (!ReadBEInt64(Value))
+ {
+ return false;
+ }
+
+ // Convert the 64 received bits into 3 coords:
+ UInt32 BlockXRaw = (Value >> 38) & 0x03ffffff; // Top 26 bits
+ UInt32 BlockYRaw = (Value >> 26) & 0x0fff; // Middle 12 bits
+ UInt32 BlockZRaw = (Value & 0x03ffffff); // Bottom 26 bits
+
+ // If the highest bit in the number's range is set, convert the number into negative:
+ a_BlockX = ((BlockXRaw & 0x02000000) == 0) ? BlockXRaw : -(0x04000000 - (int)BlockXRaw);
+ a_BlockY = ((BlockYRaw & 0x0800) == 0) ? BlockYRaw : -(0x0800 - (int)BlockYRaw);
+ a_BlockZ = ((BlockZRaw & 0x02000000) == 0) ? BlockZRaw : -(0x04000000 - (int)BlockZRaw);
+ return true;
+}
+
+
+
+
+
bool cByteBuffer::WriteChar(char a_Value)
{
CHECK_THREAD;
@@ -526,6 +550,19 @@ bool cByteBuffer::WriteBEShort(short a_Value)
+bool cByteBuffer::WriteBEUShort(unsigned short a_Value)
+{
+ CHECK_THREAD;
+ CheckValid();
+ PUTBYTES(2);
+ u_short Converted = htons((u_short)a_Value);
+ return WriteBuf(&Converted, 2);
+}
+
+
+
+
+
bool cByteBuffer::WriteBEInt(int a_Value)
{
CHECK_THREAD;
@@ -661,6 +698,15 @@ bool cByteBuffer::WriteLEInt(int a_Value)
+bool cByteBuffer::WritePosition(int a_BlockX, int a_BlockY, int a_BlockZ)
+{
+ return WriteBEInt64(((Int64)a_BlockX & 0x3FFFFFF) << 38 | ((Int64)a_BlockY & 0xFFF) << 26 | ((Int64)a_BlockZ & 0x3FFFFFF));
+}
+
+
+
+
+
bool cByteBuffer::ReadBuf(void * a_Buffer, size_t a_Count)
{
CHECK_THREAD;