refactor(Minecraft.World): Implement LCEMP changes.
This commit is contained in:
@@ -9,6 +9,7 @@
|
||||
|
||||
StructureFeature::StructureFeature()
|
||||
{
|
||||
InitializeCriticalSectionAndSpinCount(&m_csCachedStructures, 4000);
|
||||
#ifdef ENABLE_STRUCTURE_SAVING
|
||||
savedData = nullptr;
|
||||
#endif
|
||||
@@ -16,10 +17,13 @@ StructureFeature::StructureFeature()
|
||||
|
||||
StructureFeature::~StructureFeature()
|
||||
{
|
||||
EnterCriticalSection(&m_csCachedStructures);
|
||||
for( AUTO_VAR(it, cachedStructures.begin()); it != cachedStructures.end(); it++ )
|
||||
{
|
||||
delete it->second;
|
||||
}
|
||||
LeaveCriticalSection(&m_csCachedStructures);
|
||||
DeleteCriticalSection(&m_csCachedStructures);
|
||||
}
|
||||
|
||||
void StructureFeature::addFeature(Level *level, int x, int z, int xOffs, int zOffs, byteArray blocks)
|
||||
@@ -30,10 +34,13 @@ void StructureFeature::addFeature(Level *level, int x, int z, int xOffs, int zOf
|
||||
|
||||
restoreSavedData(level);
|
||||
|
||||
EnterCriticalSection(&m_csCachedStructures);
|
||||
if (cachedStructures.find(ChunkPos::hashCode(x, z)) != cachedStructures.end())
|
||||
{
|
||||
LeaveCriticalSection(&m_csCachedStructures);
|
||||
return;
|
||||
}
|
||||
LeaveCriticalSection(&m_csCachedStructures);
|
||||
|
||||
// clear random key
|
||||
random->nextInt();
|
||||
@@ -41,8 +48,10 @@ void StructureFeature::addFeature(Level *level, int x, int z, int xOffs, int zOf
|
||||
if (isFeatureChunk(x, z,level->getLevelData()->getGenerator() == LevelType::lvl_flat))
|
||||
{
|
||||
StructureStart *start = createStructureStart(x, z);
|
||||
EnterCriticalSection(&m_csCachedStructures);
|
||||
cachedStructures[ChunkPos::hashCode(x, z)] = start;
|
||||
saveFeature(x, z, start);
|
||||
LeaveCriticalSection(&m_csCachedStructures);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -58,6 +67,7 @@ bool StructureFeature::postProcess(Level *level, Random *random, int chunkX, int
|
||||
int cz = (chunkZ << 4); // + 8;
|
||||
|
||||
bool intersection = false;
|
||||
EnterCriticalSection(&m_csCachedStructures);
|
||||
for( AUTO_VAR(it, cachedStructures.begin()); it != cachedStructures.end(); it++ )
|
||||
{
|
||||
StructureStart *structureStart = it->second;
|
||||
@@ -76,6 +86,7 @@ bool StructureFeature::postProcess(Level *level, Random *random, int chunkX, int
|
||||
}
|
||||
}
|
||||
}
|
||||
LeaveCriticalSection(&m_csCachedStructures);
|
||||
|
||||
return intersection;
|
||||
}
|
||||
@@ -84,6 +95,7 @@ bool StructureFeature::isIntersection(int cellX, int cellZ)
|
||||
{
|
||||
restoreSavedData(level);
|
||||
|
||||
EnterCriticalSection(&m_csCachedStructures);
|
||||
for( AUTO_VAR(it, cachedStructures.begin()); it != cachedStructures.end(); it++ )
|
||||
{
|
||||
StructureStart *structureStart = it->second;
|
||||
@@ -97,12 +109,14 @@ bool StructureFeature::isIntersection(int cellX, int cellZ)
|
||||
StructurePiece *next = *it2++;
|
||||
if (next->getBoundingBox()->intersects(cellX, cellZ, cellX, cellZ))
|
||||
{
|
||||
LeaveCriticalSection(&m_csCachedStructures);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
LeaveCriticalSection(&m_csCachedStructures);
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -115,6 +129,7 @@ bool StructureFeature::isInsideFeature(int cellX, int cellY, int cellZ)
|
||||
StructureStart *StructureFeature::getStructureAt(int cellX, int cellY, int cellZ)
|
||||
{
|
||||
//for (StructureStart structureStart : cachedStructures.values())
|
||||
EnterCriticalSection(&m_csCachedStructures);
|
||||
for(AUTO_VAR(it, cachedStructures.begin()); it != cachedStructures.end(); ++it)
|
||||
{
|
||||
StructureStart *pStructureStart = it->second;
|
||||
@@ -138,12 +153,14 @@ StructureStart *StructureFeature::getStructureAt(int cellX, int cellY, int cellZ
|
||||
StructurePiece* piece = *it2;
|
||||
if ( piece->getBoundingBox()->isInside(cellX, cellY, cellZ) )
|
||||
{
|
||||
LeaveCriticalSection(&m_csCachedStructures);
|
||||
return pStructureStart;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
LeaveCriticalSection(&m_csCachedStructures);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@@ -182,6 +199,7 @@ TilePos *StructureFeature::getNearestGeneratedFeature(Level *level, int cellX, i
|
||||
double minDistance = DBL_MAX;
|
||||
TilePos *selected = NULL;
|
||||
|
||||
EnterCriticalSection(&m_csCachedStructures);
|
||||
for(AUTO_VAR(it, cachedStructures.begin()); it != cachedStructures.end(); ++it)
|
||||
{
|
||||
StructureStart *pStructureStart = it->second;
|
||||
@@ -205,6 +223,7 @@ TilePos *StructureFeature::getNearestGeneratedFeature(Level *level, int cellX, i
|
||||
}
|
||||
}
|
||||
}
|
||||
LeaveCriticalSection(&m_csCachedStructures);
|
||||
if (selected != NULL)
|
||||
{
|
||||
return selected;
|
||||
|
||||
Reference in New Issue
Block a user