diff options
author | Howaner <franzi.moos@googlemail.com> | 2014-09-23 14:39:49 +0200 |
---|---|---|
committer | Howaner <franzi.moos@googlemail.com> | 2014-09-23 14:39:49 +0200 |
commit | 4b38e077cf8d27d1c7ef26d4148f7825c5aeaabd (patch) | |
tree | cd86062eb50ba870f73b6f29dec0205f87205bf8 /src/ByteBuffer.cpp | |
parent | Merge branch 'master' into EntityCustomName (diff) | |
parent | QtBiomeVisualiser: Fixed confusion about Globals.h. (diff) | |
download | cuberite-4b38e077cf8d27d1c7ef26d4148f7825c5aeaabd.tar cuberite-4b38e077cf8d27d1c7ef26d4148f7825c5aeaabd.tar.gz cuberite-4b38e077cf8d27d1c7ef26d4148f7825c5aeaabd.tar.bz2 cuberite-4b38e077cf8d27d1c7ef26d4148f7825c5aeaabd.tar.lz cuberite-4b38e077cf8d27d1c7ef26d4148f7825c5aeaabd.tar.xz cuberite-4b38e077cf8d27d1c7ef26d4148f7825c5aeaabd.tar.zst cuberite-4b38e077cf8d27d1c7ef26d4148f7825c5aeaabd.zip |
Diffstat (limited to 'src/ByteBuffer.cpp')
-rw-r--r-- | src/ByteBuffer.cpp | 32 |
1 files changed, 31 insertions, 1 deletions
diff --git a/src/ByteBuffer.cpp b/src/ByteBuffer.cpp index 96556bf61..17e8091c7 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,27 @@ 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; + } + + UInt32 BlockXRaw = (Value >> 38) & 0x3ffffff; + UInt32 BlockYRaw = (Value >> 26) & 0xfff; + UInt32 BlockZRaw = (Value & 0x3ffffff); + a_BlockX = ((BlockXRaw & 0x2000000) == 0) ? BlockXRaw : (~(BlockXRaw & 0x1ffffff)) + 1; + a_BlockY = ((BlockYRaw & 0x800) == 0) ? BlockYRaw : (~(BlockXRaw & 0x7ff)) + 1; + a_BlockZ = ((BlockZRaw & 0x2000000) == 0) ? BlockZRaw : (~(BlockZRaw & 0x1ffffff)) + 1; + return true; +} + + + + + bool cByteBuffer::WriteChar(char a_Value) { CHECK_THREAD; @@ -661,6 +682,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; |