From 868cd94ee9a5a0638c014a4cc42224f01ff234c8 Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Fri, 5 Mar 2021 13:03:55 +0000 Subject: Prepare ChunkData for BlockState storage (#5105) * Rename ChunkData Creatable test * Add missing Y-check in RedstoneWireHandler * Remove ChunkDef.h dependency in Scoreboard * Prepare ChunkData for BlockState storage + Split chunk block, meta, block & sky light storage + Load the height map from disk - Reduce duplicated code in ChunkData - Remove saving MCSBiomes, there aren't any - Remove the allocation pool, ref #4315, #3864 * fixed build * fixed test * fixed the debug compile Co-authored-by: 12xx12 <44411062+12xx12@users.noreply.github.com> --- src/ByteBuffer.cpp | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) (limited to 'src/ByteBuffer.cpp') diff --git a/src/ByteBuffer.cpp b/src/ByteBuffer.cpp index 3891af247..127227180 100644 --- a/src/ByteBuffer.cpp +++ b/src/ByteBuffer.cpp @@ -856,6 +856,34 @@ bool cByteBuffer::WriteBuf(const void * a_Buffer, size_t a_Count) +bool cByteBuffer::WriteBuf(size_t a_Count, unsigned char a_Value) +{ + CHECK_THREAD + CheckValid(); + PUTBYTES(a_Count); + ASSERT(m_BufferSize >= m_ReadPos); + size_t BytesToEndOfBuffer = m_BufferSize - m_WritePos; + if (BytesToEndOfBuffer <= a_Count) + { + // Reading across the ringbuffer end, read the first part and adjust parameters: + memset(m_Buffer + m_WritePos, a_Value, BytesToEndOfBuffer); + a_Count -= BytesToEndOfBuffer; + m_WritePos = 0; + } + + // Read the rest of the bytes in a single read (guaranteed to fit): + if (a_Count > 0) + { + memset(m_Buffer + m_WritePos, a_Value, a_Count); + m_WritePos += a_Count; + } + return true; +} + + + + + bool cByteBuffer::ReadSome(ContiguousByteBuffer & a_String, size_t a_Count) { CHECK_THREAD -- cgit v1.2.3