1
0
Fork 0

cSetChunkData constructor explicitly requires std::move() instead of

unsafely stealing data
This commit is contained in:
Woazboat 2015-04-27 21:18:21 +02:00
parent 0bfcd62556
commit 6caf08da99
4 changed files with 12 additions and 10 deletions

View File

@ -33,8 +33,8 @@ cSetChunkData::cSetChunkData(
const NIBBLETYPE * a_SkyLight,
const cChunkDef::HeightMap * a_HeightMap,
const cChunkDef::BiomeMap * a_Biomes,
cEntityList & a_Entities,
cBlockEntityList & a_BlockEntities,
cEntityList && a_Entities,
cBlockEntityList && a_BlockEntities,
bool a_ShouldMarkDirty
) :
m_ChunkX(a_ChunkX),
@ -84,8 +84,8 @@ cSetChunkData::cSetChunkData(
}
// Move entities and blockentities:
std::swap(m_Entities, a_Entities);
std::swap(m_BlockEntities, a_BlockEntities);
m_Entities = std::move(a_Entities);
m_BlockEntities = std::move(a_BlockEntities);
}

View File

@ -24,8 +24,10 @@ public:
/** Constructs a new instance based on data existing elsewhere, will copy all the memory. Prefer to use the
other constructor as much as possible.
Will move the entity and blockentity lists into the internal storage, and empty the a_Entities and
a_BlockEntities lists.
Will move the entity and blockentity lists into the internal storage, and invalidate a_Entities and
a_BlockEntities.
When passing an lvalue, a_Entities and a_BlockEntities must be explicitly converted to an rvalue beforehand
with std::move().
a_BlockTypes and a_BlockMetas must always be valid.
If either of the light arrays are nullptr, the chunk data will be marked as not having any light at all and
will be scheduled for re-lighting once it is set into the chunkmap.
@ -41,8 +43,8 @@ public:
const NIBBLETYPE * a_SkyLight,
const cChunkDef::HeightMap * a_HeightMap,
const cChunkDef::BiomeMap * a_Biomes,
cEntityList & a_Entities,
cBlockEntityList & a_BlockEntities,
cEntityList && a_Entities,
cBlockEntityList && a_BlockEntities,
bool a_ShouldMarkDirty
);

View File

@ -3712,7 +3712,7 @@ void cWorld::cChunkGeneratorCallbacks::OnChunkGenerated(cChunkDesc & a_ChunkDesc
a_ChunkDesc.GetBlockTypes(), BlockMetas,
nullptr, nullptr, // We don't have lighting, chunk will be lighted when needed
&a_ChunkDesc.GetHeightMap(), &a_ChunkDesc.GetBiomeMap(),
a_ChunkDesc.GetEntities(), a_ChunkDesc.GetBlockEntities(),
std::move(a_ChunkDesc.GetEntities()), std::move(a_ChunkDesc.GetBlockEntities()),
true
));
SetChunkData->RemoveInvalidBlockEntities();

View File

@ -431,7 +431,7 @@ bool cWSSAnvil::LoadChunkFromNBT(const cChunkCoords & a_Chunk, const cParsedNBT
IsLightValid ? BlockLight : nullptr,
IsLightValid ? SkyLight : nullptr,
nullptr, Biomes,
Entities, BlockEntities,
std::move(Entities), std::move(BlockEntities),
false
));
m_World->QueueSetChunkData(SetChunkData);