From d07134e6212ea39f0d23c7edcfb22573d5b58b77 Mon Sep 17 00:00:00 2001 From: Alexander Harkness Date: Sat, 23 Aug 2014 16:06:34 +0100 Subject: Assume POWER is big-endian, so it compiles. [reference](http://nadeausoftware.com/articles/2012/02/c_c_tip_how_detect_processor_type_using_compiler_predefined_macros#POWER) We may want to come back and figure out if the processor is running in little-endian mode, but for now assume they're big-endian. --- src/ByteBuffer.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/ByteBuffer.cpp') diff --git a/src/ByteBuffer.cpp b/src/ByteBuffer.cpp index 64b31c60b..96556bf61 100644 --- a/src/ByteBuffer.cpp +++ b/src/ByteBuffer.cpp @@ -27,7 +27,7 @@ ) #define IS_LITTLE_ENDIAN #elif ( \ - defined (__ARMEB__) || defined(__sparc) \ + defined (__ARMEB__) || defined(__sparc) || defined(__powerpc__) || defined(__POWERPC__) \ ) #define IS_BIG_ENDIAN #else -- cgit v1.2.3 From 8f8693a71eb896ccc7c14c4033ae8d07dae27ac3 Mon Sep 17 00:00:00 2001 From: Howaner Date: Mon, 8 Sep 2014 17:02:54 +0200 Subject: Fixed more 1.8 packets. --- src/ByteBuffer.cpp | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) (limited to 'src/ByteBuffer.cpp') diff --git a/src/ByteBuffer.cpp b/src/ByteBuffer.cpp index 96556bf61..94684afb8 100644 --- a/src/ByteBuffer.cpp +++ b/src/ByteBuffer.cpp @@ -489,6 +489,24 @@ 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; + } + + a_BlockX = Value >> 38; + a_BlockY = Value << 26 >> 52; + a_BlockZ = Value << 38 >> 38; + return true; +} + + + + + bool cByteBuffer::WriteChar(char a_Value) { CHECK_THREAD; @@ -661,6 +679,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; @@ -792,6 +819,23 @@ bool cByteBuffer::SkipRead(size_t a_Count) +bool cByteBuffer::ReverseRead(size_t a_Count) +{ + CHECK_THREAD; + CheckValid(); + if (m_ReadPos < a_Count) + { + return false; + } + + m_ReadPos -= a_Count; + return true; +} + + + + + void cByteBuffer::ReadAll(AString & a_Data) { CHECK_THREAD; -- cgit v1.2.3 From 34bcd3dd589cca6d525633ad4445ec7700578995 Mon Sep 17 00:00:00 2001 From: Howaner Date: Fri, 12 Sep 2014 02:42:04 +0200 Subject: 1.8: Fixed ReadItem() --- src/ByteBuffer.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/ByteBuffer.cpp') diff --git a/src/ByteBuffer.cpp b/src/ByteBuffer.cpp index 94684afb8..851c63858 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; } -- cgit v1.2.3 From 3ee211bbbaa4673b2f38846fadb1d2bfba93b1a3 Mon Sep 17 00:00:00 2001 From: Howaner Date: Wed, 17 Sep 2014 17:53:42 +0200 Subject: Use xofts ReadPosition() code. --- src/ByteBuffer.cpp | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'src/ByteBuffer.cpp') diff --git a/src/ByteBuffer.cpp b/src/ByteBuffer.cpp index 851c63858..262e0e3b5 100644 --- a/src/ByteBuffer.cpp +++ b/src/ByteBuffer.cpp @@ -497,9 +497,12 @@ bool cByteBuffer::ReadPosition(int & a_BlockX, int & a_BlockY, int & a_BlockZ) return false; } - a_BlockX = Value >> 38; - a_BlockY = Value << 26 >> 52; - a_BlockZ = Value << 38 >> 38; + 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; } -- cgit v1.2.3 From be6d4a5912abcfe36a1f0fcee9d76e050a58c0ce Mon Sep 17 00:00:00 2001 From: Howaner Date: Thu, 18 Sep 2014 16:04:03 +0200 Subject: 1.8: Simplified item metadata reading. --- src/ByteBuffer.cpp | 17 ----------------- 1 file changed, 17 deletions(-) (limited to 'src/ByteBuffer.cpp') diff --git a/src/ByteBuffer.cpp b/src/ByteBuffer.cpp index 262e0e3b5..17e8091c7 100644 --- a/src/ByteBuffer.cpp +++ b/src/ByteBuffer.cpp @@ -822,23 +822,6 @@ bool cByteBuffer::SkipRead(size_t a_Count) -bool cByteBuffer::ReverseRead(size_t a_Count) -{ - CHECK_THREAD; - CheckValid(); - if (m_ReadPos < a_Count) - { - return false; - } - - m_ReadPos -= a_Count; - return true; -} - - - - - void cByteBuffer::ReadAll(AString & a_Data) { CHECK_THREAD; -- cgit v1.2.3 From 8f4cc27e39188d302f6575e7324002e2515fd789 Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Thu, 25 Sep 2014 20:46:50 +0200 Subject: Added cByteBuffer::WriteBEUShort(). --- src/ByteBuffer.cpp | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'src/ByteBuffer.cpp') diff --git a/src/ByteBuffer.cpp b/src/ByteBuffer.cpp index 17e8091c7..5bf98eda9 100644 --- a/src/ByteBuffer.cpp +++ b/src/ByteBuffer.cpp @@ -547,6 +547,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; -- cgit v1.2.3 From 0443f5d531b21917b3605254b17475569573fc48 Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Thu, 25 Sep 2014 21:23:05 +0200 Subject: cByteBuffer: Fixed position reading. --- src/ByteBuffer.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src/ByteBuffer.cpp') diff --git a/src/ByteBuffer.cpp b/src/ByteBuffer.cpp index 5bf98eda9..e61a90bbc 100644 --- a/src/ByteBuffer.cpp +++ b/src/ByteBuffer.cpp @@ -500,9 +500,9 @@ bool cByteBuffer::ReadPosition(int & a_BlockX, int & a_BlockY, int & a_BlockZ) 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; + a_BlockX = ((BlockXRaw & 0x2000000) == 0) ? BlockXRaw : -(0x03ffffff - (int)BlockXRaw + 1); + a_BlockY = ((BlockYRaw & 0x800) == 0) ? BlockYRaw : -(0x07ff - (int)BlockYRaw + 1); + a_BlockZ = ((BlockZRaw & 0x2000000) == 0) ? BlockZRaw : -(0x03ffffff - (int)BlockZRaw + 1); return true; } -- cgit v1.2.3 From 6b260f06ba8ec773e4a81fea38fb123b1ea09081 Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Thu, 25 Sep 2014 23:06:21 +0200 Subject: cByteBuffer: Simplified ReadPosition(). Also, by popular demand, added more comments to the code. --- src/ByteBuffer.cpp | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) (limited to 'src/ByteBuffer.cpp') diff --git a/src/ByteBuffer.cpp b/src/ByteBuffer.cpp index e61a90bbc..70fdc008c 100644 --- a/src/ByteBuffer.cpp +++ b/src/ByteBuffer.cpp @@ -497,12 +497,15 @@ bool cByteBuffer::ReadPosition(int & a_BlockX, int & a_BlockY, int & a_BlockZ) return false; } - UInt32 BlockXRaw = (Value >> 38) & 0x3ffffff; - UInt32 BlockYRaw = (Value >> 26) & 0xfff; - UInt32 BlockZRaw = (Value & 0x3ffffff); - a_BlockX = ((BlockXRaw & 0x2000000) == 0) ? BlockXRaw : -(0x03ffffff - (int)BlockXRaw + 1); - a_BlockY = ((BlockYRaw & 0x800) == 0) ? BlockYRaw : -(0x07ff - (int)BlockYRaw + 1); - a_BlockZ = ((BlockZRaw & 0x2000000) == 0) ? BlockZRaw : -(0x03ffffff - (int)BlockZRaw + 1); + // 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; } -- cgit v1.2.3 From 1f8ee70d55d0d076583e14329ca09377c41b12e0 Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Sat, 27 Sep 2014 22:13:37 +0100 Subject: Bug fix --- src/ByteBuffer.cpp | 17 ----------------- 1 file changed, 17 deletions(-) (limited to 'src/ByteBuffer.cpp') diff --git a/src/ByteBuffer.cpp b/src/ByteBuffer.cpp index 70fdc008c..dc6b32a44 100644 --- a/src/ByteBuffer.cpp +++ b/src/ByteBuffer.cpp @@ -627,23 +627,6 @@ bool cByteBuffer::WriteBool(bool a_Value) -bool cByteBuffer::WriteBEUTF16String16(const AString & a_Value) -{ - CHECK_THREAD; - CheckValid(); - PUTBYTES(2); - AString UTF16BE; - UTF8ToRawBEUTF16(a_Value.data(), a_Value.size(), UTF16BE); - WriteBEShort((short)(UTF16BE.size() / 2)); - PUTBYTES(UTF16BE.size()); - WriteBuf(UTF16BE.data(), UTF16BE.size()); - return true; -} - - - - - bool cByteBuffer::WriteVarInt(UInt32 a_Value) { CHECK_THREAD; -- cgit v1.2.3