Initial ChunkStay code.
This commit is contained in:
207
src/ChunkMap.cpp
207
src/ChunkMap.cpp
@@ -134,7 +134,7 @@ cChunkMap::cChunkLayer * cChunkMap::GetLayerForChunk(int a_ChunkX, int a_ChunkZ)
|
||||
|
||||
|
||||
|
||||
cChunkPtr cChunkMap::GetChunk( int a_ChunkX, int a_ChunkY, int a_ChunkZ )
|
||||
cChunkPtr cChunkMap::GetChunk(int a_ChunkX, int a_ChunkY, int a_ChunkZ)
|
||||
{
|
||||
// No need to lock m_CSLayers, since it's already locked by the operation that called us
|
||||
ASSERT(m_CSLayers.IsLockedByCurrentThread());
|
||||
@@ -897,17 +897,25 @@ void cChunkMap::SetChunkData(
|
||||
bool a_MarkDirty
|
||||
)
|
||||
{
|
||||
cCSLock Lock(m_CSLayers);
|
||||
cChunkPtr Chunk = GetChunkNoLoad(a_ChunkX, ZERO_CHUNK_Y, a_ChunkZ);
|
||||
if (Chunk == NULL)
|
||||
{
|
||||
return;
|
||||
}
|
||||
Chunk->SetAllData(a_BlockTypes, a_BlockMeta, a_BlockLight, a_BlockSkyLight, a_HeightMap, a_BiomeMap, a_BlockEntities);
|
||||
|
||||
if (a_MarkDirty)
|
||||
{
|
||||
Chunk->MarkDirty();
|
||||
cCSLock Lock(m_CSLayers);
|
||||
cChunkPtr Chunk = GetChunkNoLoad(a_ChunkX, ZERO_CHUNK_Y, a_ChunkZ);
|
||||
if (Chunk == NULL)
|
||||
{
|
||||
return;
|
||||
}
|
||||
Chunk->SetAllData(a_BlockTypes, a_BlockMeta, a_BlockLight, a_BlockSkyLight, a_HeightMap, a_BiomeMap, a_BlockEntities);
|
||||
|
||||
if (a_MarkDirty)
|
||||
{
|
||||
Chunk->MarkDirty();
|
||||
}
|
||||
|
||||
// Notify relevant ChunkStays:
|
||||
for (cChunkStays::iterator itr = m_ChunkStays.begin(), end = m_ChunkStays.end(); itr != end; ++itr)
|
||||
{
|
||||
(*itr)->ChunkAvailable(a_ChunkX, a_ChunkZ);
|
||||
} // for itr - m_ChunkStays[]
|
||||
}
|
||||
|
||||
// Notify plugins of the chunk becoming available
|
||||
@@ -2206,24 +2214,6 @@ bool cChunkMap::SetSignLines(int a_BlockX, int a_BlockY, int a_BlockZ, const ASt
|
||||
|
||||
|
||||
|
||||
void cChunkMap::ChunksStay(const cChunkCoordsList & a_Chunks, bool a_Stay)
|
||||
{
|
||||
cCSLock Lock(m_CSLayers);
|
||||
for (cChunkCoordsList::const_iterator itr = a_Chunks.begin(); itr != a_Chunks.end(); ++itr)
|
||||
{
|
||||
cChunkPtr Chunk = GetChunkNoLoad(itr->m_ChunkX, itr->m_ChunkY, itr->m_ChunkZ);
|
||||
if (Chunk == NULL)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
Chunk->Stay(a_Stay);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
void cChunkMap::MarkChunkRegenerating(int a_ChunkX, int a_ChunkZ)
|
||||
{
|
||||
cCSLock Lock(m_CSLayers);
|
||||
@@ -2810,12 +2800,16 @@ void cChunkMap::cChunkLayer::UnloadUnusedChunks(void)
|
||||
|
||||
|
||||
|
||||
void cChunkMap::FastSetBlock(int a_X, int a_Y, int a_Z, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta)
|
||||
void cChunkMap::FastSetBlock(int a_BlockX, int a_BlockY, int a_BlockZ, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta)
|
||||
{
|
||||
cCSLock Lock(m_CSFastSetBlock);
|
||||
m_FastSetBlockQueue.push_back(sSetBlock(a_X, a_Y, a_Z, a_BlockType, a_BlockMeta));
|
||||
m_FastSetBlockQueue.push_back(sSetBlock(a_BlockX, a_BlockY, a_BlockZ, a_BlockType, a_BlockMeta));
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
void cChunkMap::FastSetQueuedBlocks()
|
||||
{
|
||||
// Asynchronously set blocks:
|
||||
@@ -2834,110 +2828,75 @@ void cChunkMap::FastSetQueuedBlocks()
|
||||
}
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// cChunkStay:
|
||||
|
||||
cChunkStay::cChunkStay(cWorld * a_World) :
|
||||
m_World(a_World),
|
||||
m_IsEnabled(false)
|
||||
|
||||
|
||||
void cChunkMap::AddChunkStay(cChunkStay & a_ChunkStay)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
cChunkStay::~cChunkStay()
|
||||
{
|
||||
Clear();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
void cChunkStay::Clear(void)
|
||||
{
|
||||
if (m_IsEnabled)
|
||||
cCSLock Lock(m_CSLayers);
|
||||
|
||||
// Add it to the list:
|
||||
ASSERT(std::find(m_ChunkStays.begin(), m_ChunkStays.end(), &a_ChunkStay) == m_ChunkStays.end()); // Has not yet been added
|
||||
m_ChunkStays.push_back(&a_ChunkStay);
|
||||
|
||||
// Schedule all chunks to be loaded / generated, and mark each as locked:
|
||||
const cChunkCoordsVector & WantedChunks = a_ChunkStay.GetChunks();
|
||||
for (cChunkCoordsVector::const_iterator itr = WantedChunks.begin(); itr != WantedChunks.end(); ++itr)
|
||||
{
|
||||
Disable();
|
||||
cChunkPtr Chunk = GetChunk(itr->m_ChunkX, itr->m_ChunkY, itr->m_ChunkZ);
|
||||
if (Chunk == NULL)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
Chunk->Stay(true);
|
||||
if (Chunk->IsValid())
|
||||
{
|
||||
a_ChunkStay.ChunkAvailable(itr->m_ChunkX, itr->m_ChunkZ);
|
||||
}
|
||||
} // for itr - WantedChunks[]
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/** Removes the specified cChunkStay descendant from the internal list of ChunkStays. */
|
||||
void cChunkMap::DelChunkStay(cChunkStay & a_ChunkStay)
|
||||
{
|
||||
cCSLock Lock(m_CSLayers);
|
||||
|
||||
// Remove from the list of active chunkstays:
|
||||
bool HasFound = false;
|
||||
for (cChunkStays::iterator itr = m_ChunkStays.begin(), end = m_ChunkStays.end(); itr != end; ++itr)
|
||||
{
|
||||
if (*itr == &a_ChunkStay)
|
||||
{
|
||||
m_ChunkStays.erase(itr);
|
||||
HasFound = true;
|
||||
break;
|
||||
}
|
||||
} // for itr - m_ChunkStays[]
|
||||
|
||||
if (!HasFound)
|
||||
{
|
||||
ASSERT(!"Removing a cChunkStay that hasn't been added!");
|
||||
return;
|
||||
}
|
||||
m_Chunks.clear();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
void cChunkStay::Add(int a_ChunkX, int a_ChunkY, int a_ChunkZ)
|
||||
{
|
||||
ASSERT(!m_IsEnabled);
|
||||
|
||||
for (cChunkCoordsList::const_iterator itr = m_Chunks.begin(); itr != m_Chunks.end(); ++itr)
|
||||
|
||||
// Unmark all contained chunks:
|
||||
const cChunkCoordsVector & Chunks = a_ChunkStay.GetChunks();
|
||||
for (cChunkCoordsVector::const_iterator itr = Chunks.begin(), end = Chunks.end(); itr != end; ++itr)
|
||||
{
|
||||
if ((itr->m_ChunkX == a_ChunkX) && (itr->m_ChunkY == a_ChunkY) && (itr->m_ChunkZ == a_ChunkZ))
|
||||
cChunkPtr Chunk = GetChunkNoLoad(itr->m_ChunkX, itr->m_ChunkY, itr->m_ChunkZ);
|
||||
if (Chunk == NULL)
|
||||
{
|
||||
// Already present
|
||||
return;
|
||||
continue;
|
||||
}
|
||||
Chunk->Stay(false);
|
||||
} // for itr - Chunks[]
|
||||
m_Chunks.push_back(cChunkCoords(a_ChunkX, a_ChunkY, a_ChunkZ));
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
void cChunkStay::Remove(int a_ChunkX, int a_ChunkY, int a_ChunkZ)
|
||||
{
|
||||
ASSERT(!m_IsEnabled);
|
||||
|
||||
for (cChunkCoordsList::iterator itr = m_Chunks.begin(); itr != m_Chunks.end(); ++itr)
|
||||
{
|
||||
if ((itr->m_ChunkX == a_ChunkX) && (itr->m_ChunkY == a_ChunkY) && (itr->m_ChunkZ == a_ChunkZ))
|
||||
{
|
||||
// Found, un-"stay"
|
||||
m_Chunks.erase(itr);
|
||||
return;
|
||||
}
|
||||
} // for itr - m_Chunks[]
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
void cChunkStay::Enable(void)
|
||||
{
|
||||
ASSERT(!m_IsEnabled);
|
||||
|
||||
m_World->ChunksStay(*this, true);
|
||||
m_IsEnabled = true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
void cChunkStay::Load(void)
|
||||
{
|
||||
for (cChunkCoordsList::iterator itr = m_Chunks.begin(); itr != m_Chunks.end(); ++itr)
|
||||
{
|
||||
m_World->TouchChunk(itr->m_ChunkX, itr->m_ChunkY, itr->m_ChunkZ);
|
||||
} // for itr - m_Chunks[]
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
void cChunkStay::Disable(void)
|
||||
{
|
||||
ASSERT(m_IsEnabled);
|
||||
|
||||
m_World->ChunksStay(*this, false);
|
||||
m_IsEnabled = false;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user