diff options
author | worktycho <work.tycho@gmail.com> | 2014-05-29 18:41:07 +0200 |
---|---|---|
committer | worktycho <work.tycho@gmail.com> | 2014-05-29 18:41:07 +0200 |
commit | 80fe19c0e2e4433d8332dbe5a9c2fcba0be06f68 (patch) | |
tree | 95c91e355987aa8c2c1205e43208bc33ddd87a36 /src/ChunkData.cpp | |
parent | Added comments, reformatted code. (diff) | |
download | cuberite-80fe19c0e2e4433d8332dbe5a9c2fcba0be06f68.tar cuberite-80fe19c0e2e4433d8332dbe5a9c2fcba0be06f68.tar.gz cuberite-80fe19c0e2e4433d8332dbe5a9c2fcba0be06f68.tar.bz2 cuberite-80fe19c0e2e4433d8332dbe5a9c2fcba0be06f68.tar.lz cuberite-80fe19c0e2e4433d8332dbe5a9c2fcba0be06f68.tar.xz cuberite-80fe19c0e2e4433d8332dbe5a9c2fcba0be06f68.tar.zst cuberite-80fe19c0e2e4433d8332dbe5a9c2fcba0be06f68.zip |
Diffstat (limited to 'src/ChunkData.cpp')
-rw-r--r-- | src/ChunkData.cpp | 15 |
1 files changed, 9 insertions, 6 deletions
diff --git a/src/ChunkData.cpp b/src/ChunkData.cpp index cc4793ec3..13be65fd7 100644 --- a/src/ChunkData.cpp +++ b/src/ChunkData.cpp @@ -333,25 +333,28 @@ cChunkData cChunkData::Copy(void) const void cChunkData::CopyBlockTypes(BLOCKTYPE * a_Dest, size_t a_Idx, size_t a_Length) const { - // TODO: This code seems wrong. It always copies into a_Dest[i * SegmentLength], even when a_Idx > 0 + size_t toskip = a_Idx; + for (size_t i = 0; i < NumSections; i++) { const size_t SegmentLength = SectionHeight * 16 * 16; - if (a_Idx > 0) + size_t startpos = 0; + if (toskip > 0) { - a_Idx = std::max(a_Idx - a_Length, (size_t) 0); + toskip = std::max(toskip - SegmentLength, (size_t) 0); + startpos = SegmentLength - toskip; } - if (a_Idx == 0) + if (toskip == 0) { size_t ToCopy = std::min(SegmentLength, a_Length); a_Length -= ToCopy; if (m_Sections[i] != NULL) { - memcpy(&a_Dest[i * SegmentLength], &m_Sections[i]->m_BlockTypes, sizeof(BLOCKTYPE) * ToCopy); + memcpy(&a_Dest[(i * SegmentLength) - a_Idx], (&m_Sections[i]->m_BlockTypes) + startpos, sizeof(BLOCKTYPE) * (ToCopy - startpos)); } else { - memset(&a_Dest[i * SegmentLength], 0, sizeof(BLOCKTYPE) * ToCopy); + memset(&a_Dest[(i * SegmentLength) - a_Idx], 0, sizeof(BLOCKTYPE) * (ToCopy - startpos)); } } } |