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 ) ) else
{ {
LOGERROR("ERROR READING DISPENSER FROM JSON!" ); a_BlockEntities.push_back(DispenserEntity.release());
delete DispenserEntity; }
} } // for itr - AllDispensers[]
else
{
a_BlockEntities.push_back( DispenserEntity );
}
} // 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 ) // TODO: The block type and meta aren't correct, there's no way to get them here
std::auto_ptr<cFurnaceEntity> FurnaceEntity(new cFurnaceEntity(0, 0, 0, E_BLOCK_FURNACE, 0, a_World));
if (!FurnaceEntity->LoadFromJson(*itr))
{ {
Json::Value & Furnace = *itr; LOGWARNING("ERROR READING FURNACE FROM JSON!" );
// 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); else
if (!FurnaceEntity->LoadFromJson(Furnace)) {
{ a_BlockEntities.push_back(FurnaceEntity.release());
LOGERROR("ERROR READING FURNACE FROM JSON!" ); }
delete FurnaceEntity; } // for itr - AllFurnaces[]
}
else
{
a_BlockEntities.push_back(FurnaceEntity);
}
} // 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 ) ) else
{ {
LOGERROR("ERROR READING SIGN FROM JSON!" ); a_BlockEntities.push_back(SignEntity.release());
delete SignEntity; }
} } // for itr - AllSigns[]
else
{
a_BlockEntities.push_back( SignEntity );
}
} // 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 ) std::auto_ptr<cNoteEntity> NoteEntity(new cNoteEntity(0, 0, 0, a_World));
if (!NoteEntity->LoadFromJson(*itr))
{ {
Json::Value & Note = *itr; LOGWARNING("ERROR READING NOTE BLOCK FROM JSON!" );
cNoteEntity * NoteEntity = new cNoteEntity(0, 0, 0, a_World); }
if ( !NoteEntity->LoadFromJson( Note ) ) else
{ {
LOGERROR("ERROR READING NOTE BLOCK FROM JSON!" ); a_BlockEntities.push_back(NoteEntity.release());
delete NoteEntity; }
} } // for itr - AllNotes[]
else
{
a_BlockEntities.push_back( NoteEntity );
}
} // 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 ) std::auto_ptr<cJukeboxEntity> JukeboxEntity(new cJukeboxEntity(0, 0, 0, a_World));
if (!JukeboxEntity->LoadFromJson(*itr))
{ {
Json::Value & Jukebox = *itr; LOGWARNING("ERROR READING JUKEBOX FROM JSON!" );
cJukeboxEntity * JukeboxEntity = new cJukeboxEntity(0, 0, 0, a_World); }
if ( !JukeboxEntity->LoadFromJson( Jukebox ) ) else
{ {
LOGERROR("ERROR READING JUKEBOX FROM JSON!" ); a_BlockEntities.push_back(JukeboxEntity.release());
delete JukeboxEntity; }
} } // for itr - AllJukeboxes[]
else
{
a_BlockEntities.push_back( JukeboxEntity );
}
} // 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 ) std::auto_ptr<cCommandBlockEntity> CommandBlockEntity(new cCommandBlockEntity(0, 0, 0, a_World));
if (!CommandBlockEntity->LoadFromJson(*itr))
{ {
Json::Value & CommandBlock = *itr; LOGWARNING("ERROR READING COMMAND BLOCK FROM JSON!" );
cCommandBlockEntity * CommandBlockEntity = new cCommandBlockEntity(0, 0, 0, a_World); }
if ( !CommandBlockEntity->LoadFromJson( CommandBlock ) ) else
{ {
LOGERROR("ERROR READING COMMAND BLOCK FROM JSON!" ); a_BlockEntities.push_back(CommandBlockEntity.release());
delete CommandBlockEntity; }
} } // for itr - AllCommandBlocks[]
else
{
a_BlockEntities.push_back( CommandBlockEntity );
}
} // for itr - AllCommandBlocks[]
}
} }