1
0

Improved code safety for the Compact world storage.

That was a huge chunk of smelly code.
This commit is contained in:
Mattes D 2014-01-23 14:21:56 +01:00
parent 97ee3340e3
commit 9ae31d913c

View File

@ -265,146 +265,114 @@ 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, cWorld * a_World)
{ {
// Load chests // Load chests:
Json::Value AllChests = a_Value.get("Chests", Json::nullValue); Json::Value AllChests = a_Value.get("Chests", Json::nullValue);
if (!AllChests.empty()) if (!AllChests.empty())
{ {
for (Json::Value::iterator itr = AllChests.begin(); itr != AllChests.end(); ++itr ) for (Json::Value::iterator itr = AllChests.begin(); itr != AllChests.end(); ++itr )
{ {
Json::Value & Chest = *itr; std::auto_ptr<cChestEntity> ChestEntity(new cChestEntity(0, 0, 0, a_World));
cChestEntity * ChestEntity = new cChestEntity(0,0,0, a_World); if (!ChestEntity->LoadFromJson(*itr))
if (!ChestEntity->LoadFromJson( Chest ) )
{ {
LOGERROR("ERROR READING CHEST FROM JSON!" ); LOGWARNING("ERROR READING CHEST FROM JSON!" );
delete ChestEntity;
} }
else else
{ {
a_BlockEntities.push_back( ChestEntity ); a_BlockEntities.push_back(ChestEntity.release());
} }
} // for itr - AllChests[] } // for itr - AllChests[]
} }
// Load dispensers // Load dispensers:
Json::Value AllDispensers = a_Value.get("Dispensers", Json::nullValue); Json::Value AllDispensers = a_Value.get("Dispensers", Json::nullValue);
if( !AllDispensers.empty() ) for (Json::Value::iterator itr = AllDispensers.begin(); itr != AllDispensers.end(); ++itr)
{ {
for( Json::Value::iterator itr = AllDispensers.begin(); itr != AllDispensers.end(); ++itr ) std::auto_ptr<cDispenserEntity> DispenserEntity(new cDispenserEntity(0, 0, 0, a_World));
if (!DispenserEntity->LoadFromJson(*itr))
{ {
Json::Value & Dispenser = *itr; LOGWARNING("ERROR READING DISPENSER FROM JSON!" );
cDispenserEntity * DispenserEntity = new cDispenserEntity(0,0,0, a_World);
if( !DispenserEntity->LoadFromJson( Dispenser ) )
{
LOGERROR("ERROR READING DISPENSER FROM JSON!" );
delete DispenserEntity;
} }
else else
{ {
a_BlockEntities.push_back( DispenserEntity ); a_BlockEntities.push_back(DispenserEntity.release());
} }
} // for itr - AllDispensers[] } // for itr - AllDispensers[]
}
// Load furnaces // Load furnaces:
Json::Value AllFurnaces = a_Value.get("Furnaces", Json::nullValue); Json::Value AllFurnaces = a_Value.get("Furnaces", Json::nullValue);
if( !AllFurnaces.empty() ) for (Json::Value::iterator itr = AllFurnaces.begin(); itr != AllFurnaces.end(); ++itr)
{ {
for( Json::Value::iterator itr = AllFurnaces.begin(); itr != AllFurnaces.end(); ++itr )
{
Json::Value & Furnace = *itr;
// TODO: The block type and meta aren't correct, there's no way to get them here // TODO: The block type and meta aren't correct, there's no way to get them here
cFurnaceEntity * FurnaceEntity = new cFurnaceEntity(0, 0, 0, E_BLOCK_FURNACE, 0, a_World); std::auto_ptr<cFurnaceEntity> FurnaceEntity(new cFurnaceEntity(0, 0, 0, E_BLOCK_FURNACE, 0, a_World));
if (!FurnaceEntity->LoadFromJson(Furnace)) if (!FurnaceEntity->LoadFromJson(*itr))
{ {
LOGERROR("ERROR READING FURNACE FROM JSON!" ); LOGWARNING("ERROR READING FURNACE FROM JSON!" );
delete FurnaceEntity;
} }
else else
{ {
a_BlockEntities.push_back(FurnaceEntity); a_BlockEntities.push_back(FurnaceEntity.release());
} }
} // for itr - AllFurnaces[] } // for itr - AllFurnaces[]
}
// Load signs // Load signs:
Json::Value AllSigns = a_Value.get("Signs", Json::nullValue); Json::Value AllSigns = a_Value.get("Signs", Json::nullValue);
if( !AllSigns.empty() ) for (Json::Value::iterator itr = AllSigns.begin(); itr != AllSigns.end(); ++itr)
{ {
for( Json::Value::iterator itr = AllSigns.begin(); itr != AllSigns.end(); ++itr ) std::auto_ptr<cSignEntity> SignEntity(new cSignEntity(E_BLOCK_SIGN_POST, 0, 0, 0, a_World));
if (!SignEntity->LoadFromJson(*itr))
{ {
Json::Value & Sign = *itr; LOGWARNING("ERROR READING SIGN FROM JSON!");
cSignEntity * SignEntity = new cSignEntity( E_BLOCK_SIGN_POST, 0,0,0, a_World);
if ( !SignEntity->LoadFromJson( Sign ) )
{
LOGERROR("ERROR READING SIGN FROM JSON!" );
delete SignEntity;
} }
else else
{ {
a_BlockEntities.push_back( SignEntity ); a_BlockEntities.push_back(SignEntity.release());
} }
} // for itr - AllSigns[] } // for itr - AllSigns[]
}
// Load note blocks // Load note blocks:
Json::Value AllNotes = a_Value.get("Notes", Json::nullValue); Json::Value AllNotes = a_Value.get("Notes", Json::nullValue);
if( !AllNotes.empty() )
{
for( Json::Value::iterator itr = AllNotes.begin(); itr != AllNotes.end(); ++itr ) for( Json::Value::iterator itr = AllNotes.begin(); itr != AllNotes.end(); ++itr )
{ {
Json::Value & Note = *itr; std::auto_ptr<cNoteEntity> NoteEntity(new cNoteEntity(0, 0, 0, a_World));
cNoteEntity * NoteEntity = new cNoteEntity(0, 0, 0, a_World); if (!NoteEntity->LoadFromJson(*itr))
if ( !NoteEntity->LoadFromJson( Note ) )
{ {
LOGERROR("ERROR READING NOTE BLOCK FROM JSON!" ); LOGWARNING("ERROR READING NOTE BLOCK FROM JSON!" );
delete NoteEntity;
} }
else else
{ {
a_BlockEntities.push_back( NoteEntity ); a_BlockEntities.push_back(NoteEntity.release());
} }
} // for itr - AllNotes[] } // for itr - AllNotes[]
}
// Load jukeboxes // Load jukeboxes:
Json::Value AllJukeboxes = a_Value.get("Jukeboxes", Json::nullValue); Json::Value AllJukeboxes = a_Value.get("Jukeboxes", Json::nullValue);
if( !AllJukeboxes.empty() )
{
for( Json::Value::iterator itr = AllJukeboxes.begin(); itr != AllJukeboxes.end(); ++itr ) for( Json::Value::iterator itr = AllJukeboxes.begin(); itr != AllJukeboxes.end(); ++itr )
{ {
Json::Value & Jukebox = *itr; std::auto_ptr<cJukeboxEntity> JukeboxEntity(new cJukeboxEntity(0, 0, 0, a_World));
cJukeboxEntity * JukeboxEntity = new cJukeboxEntity(0, 0, 0, a_World); if (!JukeboxEntity->LoadFromJson(*itr))
if ( !JukeboxEntity->LoadFromJson( Jukebox ) )
{ {
LOGERROR("ERROR READING JUKEBOX FROM JSON!" ); LOGWARNING("ERROR READING JUKEBOX FROM JSON!" );
delete JukeboxEntity;
} }
else else
{ {
a_BlockEntities.push_back( JukeboxEntity ); a_BlockEntities.push_back(JukeboxEntity.release());
} }
} // for itr - AllJukeboxes[] } // for itr - AllJukeboxes[]
}
// Load command blocks // Load command blocks:
Json::Value AllCommandBlocks = a_Value.get("CommandBlocks", Json::nullValue); Json::Value AllCommandBlocks = a_Value.get("CommandBlocks", Json::nullValue);
if( !AllCommandBlocks.empty() )
{
for( Json::Value::iterator itr = AllCommandBlocks.begin(); itr != AllCommandBlocks.end(); ++itr ) for( Json::Value::iterator itr = AllCommandBlocks.begin(); itr != AllCommandBlocks.end(); ++itr )
{ {
Json::Value & CommandBlock = *itr; std::auto_ptr<cCommandBlockEntity> CommandBlockEntity(new cCommandBlockEntity(0, 0, 0, a_World));
cCommandBlockEntity * CommandBlockEntity = new cCommandBlockEntity(0, 0, 0, a_World); if (!CommandBlockEntity->LoadFromJson(*itr))
if ( !CommandBlockEntity->LoadFromJson( CommandBlock ) )
{ {
LOGERROR("ERROR READING COMMAND BLOCK FROM JSON!" ); LOGWARNING("ERROR READING COMMAND BLOCK FROM JSON!" );
delete CommandBlockEntity;
} }
else else
{ {
a_BlockEntities.push_back( CommandBlockEntity ); a_BlockEntities.push_back(CommandBlockEntity.release());
} }
} // for itr - AllCommandBlocks[] } // for itr - AllCommandBlocks[]
}
} }