1
0

Encapsulated cWorld functions needed in cWorldStorage into an interface, so that cWorldStorage can actually be used outside of MC-Server (such as storage conversion tools and chunk analyzers)

git-svn-id: http://mc-server.googlecode.com/svn/trunk@427 0a769ca7-a7f5-676a-18bf-c427514a06d6
This commit is contained in:
madmaxoft@gmail.com
2012-03-23 21:12:48 +00:00
parent 389062a1ed
commit be31652c40
18 changed files with 258 additions and 47 deletions

View File

@@ -5,7 +5,6 @@
#include "Globals.h"
#include "WSSCompact.h"
#include "cWorld.h"
#include "zlib.h"
#include <json/json.h>
#include "StringCompression.h"
@@ -68,7 +67,7 @@ bool cWSSCompact::LoadChunk(const cChunkCoords & a_Chunk)
return false;
}
return LoadChunkFromData(a_Chunk, UncompressedSize, ChunkData, m_World);
return LoadChunkFromData(a_Chunk, UncompressedSize, ChunkData, m_WSI);
}
@@ -86,7 +85,7 @@ bool cWSSCompact::SaveChunk(const cChunkCoords & a_Chunk)
LOG("Cannot locate a proper PAK file for chunk [%d, %d]", a_Chunk.m_ChunkX, a_Chunk.m_ChunkZ);
return false;
}
return f->SaveChunk(a_Chunk, m_World);
return f->SaveChunk(a_Chunk, m_WSI);
}
@@ -119,7 +118,7 @@ cWSSCompact::cPAKFile * cWSSCompact::LoadPAKFile(const cChunkCoords & a_Chunk)
// Load it anew:
AString FileName;
Printf(FileName, "%s/X%i_Z%i.pak", m_World->GetName().c_str(), LayerX, LayerZ );
Printf(FileName, "%s/X%i_Z%i.pak", m_WSI->WSIGetFolder().c_str(), LayerX, LayerZ );
cPAKFile * f = new cPAKFile(FileName, LayerX, LayerZ);
if (f == NULL)
{
@@ -188,7 +187,7 @@ bool cWSSCompact::EraseChunkData(const cChunkCoords & a_Chunk)
void cWSSCompact::LoadEntitiesFromJson(Json::Value & a_Value, cEntityList & a_Entities, cBlockEntityList & a_BlockEntities, cWorld * a_World)
void cWSSCompact::LoadEntitiesFromJson(Json::Value & a_Value, cEntityList & a_Entities, cBlockEntityList & a_BlockEntities, cWSInterface * a_WSI)
{
// Load chests
Json::Value AllChests = a_Value.get("Chests", Json::nullValue);
@@ -197,7 +196,7 @@ void cWSSCompact::LoadEntitiesFromJson(Json::Value & a_Value, cEntityList & a_En
for (Json::Value::iterator itr = AllChests.begin(); itr != AllChests.end(); ++itr )
{
Json::Value & Chest = *itr;
cChestEntity * ChestEntity = new cChestEntity(0,0,0, a_World);
cChestEntity * ChestEntity = new cChestEntity(0, 0, 0);
if (!ChestEntity->LoadFromJson( Chest ) )
{
LOGERROR("ERROR READING CHEST FROM JSON!" );
@@ -217,7 +216,7 @@ void cWSSCompact::LoadEntitiesFromJson(Json::Value & a_Value, cEntityList & a_En
for( Json::Value::iterator itr = AllFurnaces.begin(); itr != AllFurnaces.end(); ++itr )
{
Json::Value & Furnace = *itr;
cFurnaceEntity * FurnaceEntity = new cFurnaceEntity(0,0,0, a_World);
cFurnaceEntity * FurnaceEntity = new cFurnaceEntity(0, 0, 0);
if( !FurnaceEntity->LoadFromJson( Furnace ) )
{
LOGERROR("ERROR READING FURNACE FROM JSON!" );
@@ -237,7 +236,7 @@ void cWSSCompact::LoadEntitiesFromJson(Json::Value & a_Value, cEntityList & a_En
for( Json::Value::iterator itr = AllSigns.begin(); itr != AllSigns.end(); ++itr )
{
Json::Value & Sign = *itr;
cSignEntity * SignEntity = new cSignEntity( E_BLOCK_SIGN_POST, 0,0,0, a_World);
cSignEntity * SignEntity = new cSignEntity( E_BLOCK_SIGN_POST, 0, 0, 0);
if ( !SignEntity->LoadFromJson( Sign ) )
{
LOGERROR("ERROR READING SIGN FROM JSON!" );
@@ -382,7 +381,7 @@ bool cWSSCompact::cPAKFile::GetChunkData(const cChunkCoords & a_Chunk, int & a_U
bool cWSSCompact::cPAKFile::SaveChunk(const cChunkCoords & a_Chunk, cWorld * a_World)
bool cWSSCompact::cPAKFile::SaveChunk(const cChunkCoords & a_Chunk, cWSInterface * a_World)
{
if (!SaveChunkToData(a_Chunk, a_World))
{
@@ -681,7 +680,7 @@ void cWSSCompact::cPAKFile::UpdateChunk2To3()
bool cWSSCompact::LoadChunkFromData(const cChunkCoords & a_Chunk, int & a_UncompressedSize, const AString & a_Data, cWorld * a_World)
bool cWSSCompact::LoadChunkFromData(const cChunkCoords & a_Chunk, int & a_UncompressedSize, const AString & a_Data, cWSInterface * a_WSI)
{
// Crude data integrity check:
if (a_UncompressedSize < cChunkDef::BlockDataSize)
@@ -730,13 +729,13 @@ bool cWSSCompact::LoadChunkFromData(const cChunkCoords & a_Chunk, int & a_Uncomp
}
else
{
LoadEntitiesFromJson(root, Entities, BlockEntities, a_World);
LoadEntitiesFromJson(root, Entities, BlockEntities, a_WSI);
}
}
BLOCKTYPE * BlockData = (BLOCKTYPE *)UncompressedData.data();
a_World->ChunkDataLoaded(
a_WSI->WSIChunkDataLoaded(
a_Chunk.m_ChunkX, a_Chunk.m_ChunkY, a_Chunk.m_ChunkZ,
BlockData,
BlockData + cChunkDef::MetaOffset,
@@ -778,11 +777,11 @@ bool cWSSCompact::cPAKFile::EraseChunkData(const cChunkCoords & a_Chunk)
bool cWSSCompact::cPAKFile::SaveChunkToData(const cChunkCoords & a_Chunk, cWorld * a_World)
bool cWSSCompact::cPAKFile::SaveChunkToData(const cChunkCoords & a_Chunk, cWSInterface * a_WSI)
{
// Serialize the chunk:
cJsonChunkSerializer Serializer;
if (!a_World->GetChunkData(a_Chunk.m_ChunkX, a_Chunk.m_ChunkY, a_Chunk.m_ChunkZ, Serializer))
if (!a_WSI->WSIGetChunkData(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);