From 0b24efeb005e293a026f2ac8666020cea8316578 Mon Sep 17 00:00:00 2001 From: "madmaxoft@gmail.com" Date: Wed, 14 Mar 2012 20:56:09 +0000 Subject: Split chunk data into separate arrays; decoupled most sources from cChunk.h dependency git-svn-id: http://mc-server.googlecode.com/svn/trunk@411 0a769ca7-a7f5-676a-18bf-c427514a06d6 --- source/WSSCompact.cpp | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) (limited to 'source/WSSCompact.cpp') diff --git a/source/WSSCompact.cpp b/source/WSSCompact.cpp index bafa3ced1..ae920e55f 100644 --- a/source/WSSCompact.cpp +++ b/source/WSSCompact.cpp @@ -458,7 +458,7 @@ void cWSSCompact::cPAKFile::UpdateChunk1To2() // Old version is 128 blocks high with YZX axis order - char ConvertedData[cChunk::c_BlockDataSize]; + char ConvertedData[cChunkDef::BlockDataSize]; int Index = 0; unsigned int InChunkOffset = 0; for( int x = 0; x < 16; ++x ) for( int z = 0; z < 16; ++z ) @@ -684,11 +684,11 @@ void cWSSCompact::cPAKFile::UpdateChunk2To3() bool cWSSCompact::LoadChunkFromData(const cChunkCoords & a_Chunk, int & a_UncompressedSize, const AString & a_Data, cWorld * a_World) { // Crude data integrity check: - if (a_UncompressedSize < cChunk::c_BlockDataSize) + if (a_UncompressedSize < cChunkDef::BlockDataSize) { LOGWARNING("Chunk [%d, %d] has too short decompressed data (%d bytes out of %d needed), erasing", a_Chunk.m_ChunkX, a_Chunk.m_ChunkZ, - a_UncompressedSize, cChunk::c_BlockDataSize + a_UncompressedSize, cChunkDef::BlockDataSize ); EraseChunkData(a_Chunk); return false; @@ -718,11 +718,11 @@ bool cWSSCompact::LoadChunkFromData(const cChunkCoords & a_Chunk, int & a_Uncomp cEntityList Entities; cBlockEntityList BlockEntities; - if (a_UncompressedSize > cChunk::c_BlockDataSize) + if (a_UncompressedSize > cChunkDef::BlockDataSize) { Json::Value root; // will contain the root value after parsing. Json::Reader reader; - if ( !reader.parse( UncompressedData.data() + cChunk::c_BlockDataSize, root, false ) ) + if ( !reader.parse( UncompressedData.data() + cChunkDef::BlockDataSize, root, false ) ) { LOGERROR("Failed to parse trailing JSON in chunk [%d, %d]!", a_Chunk.m_ChunkX, a_Chunk.m_ChunkZ @@ -734,7 +734,16 @@ bool cWSSCompact::LoadChunkFromData(const cChunkCoords & a_Chunk, int & a_Uncomp } } - a_World->ChunkDataLoaded(a_Chunk.m_ChunkX, a_Chunk.m_ChunkY, a_Chunk.m_ChunkZ, UncompressedData.data(), Entities, BlockEntities); + a_World->ChunkDataLoaded( + a_Chunk.m_ChunkX, a_Chunk.m_ChunkY, a_Chunk.m_ChunkZ, + UncompressedData.data(), + UncompressedData.data() + cChunkDef::MetaOffset, + UncompressedData.data() + cChunkDef::LightOffset, + UncompressedData.data() + cChunkDef::SkyLightOffset, + NULL, + Entities, + BlockEntities + ); return true; } @@ -771,8 +780,7 @@ bool cWSSCompact::cPAKFile::SaveChunkToData(const cChunkCoords & a_Chunk, cWorld { // Serialize the chunk: cJsonChunkSerializer Serializer; - a_World->GetChunkData(a_Chunk.m_ChunkX, a_Chunk.m_ChunkY, a_Chunk.m_ChunkZ, Serializer); - if (Serializer.GetBlockData().empty()) + if (!a_World->GetChunkData(a_Chunk.m_ChunkX, a_Chunk.m_ChunkY, a_Chunk.m_ChunkZ, Serializer)) { // Chunk not valid LOG("cWSSCompact: Trying to save chunk [%d, %d, %d] that has no data, ignoring request.", a_Chunk.m_ChunkX, a_Chunk.m_ChunkY, a_Chunk.m_ChunkZ); @@ -780,7 +788,7 @@ bool cWSSCompact::cPAKFile::SaveChunkToData(const cChunkCoords & a_Chunk, cWorld } AString Data; - std::swap(Serializer.GetBlockData(), Data); + Data.assign(Serializer.GetBlockData(), cChunkDef::BlockDataSize); if (Serializer.HasJsonData()) { AString JsonData; -- cgit v1.2.3