Rewritten chunk status to specify whether the chunk is in queue.
This fixes #1370.
This commit is contained in:
@@ -71,7 +71,7 @@ cChunk::cChunk(
|
||||
cChunk * a_NeighborXM, cChunk * a_NeighborXP, cChunk * a_NeighborZM, cChunk * a_NeighborZP,
|
||||
cAllocationPool<cChunkData::sChunkSection> & a_Pool
|
||||
) :
|
||||
m_IsValid(false),
|
||||
m_Presence(cpInvalid),
|
||||
m_IsLightValid(false),
|
||||
m_IsDirty(false),
|
||||
m_IsSaving(false),
|
||||
@@ -165,11 +165,22 @@ cChunk::~cChunk()
|
||||
|
||||
|
||||
|
||||
void cChunk::SetValid(void)
|
||||
void cChunk::SetPresence(cChunk::ePresence a_Presence)
|
||||
{
|
||||
m_IsValid = true;
|
||||
|
||||
m_World->GetChunkMap()->ChunkValidated();
|
||||
m_Presence = a_Presence;
|
||||
if (a_Presence == cpPresent)
|
||||
{
|
||||
m_World->GetChunkMap()->ChunkValidated();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
void cChunk::SetShouldGenerateIfLoadFailed(bool a_ShouldGenerateIfLoadFailed)
|
||||
{
|
||||
m_ShouldGenerateIfLoadFailed = a_ShouldGenerateIfLoadFailed;
|
||||
}
|
||||
|
||||
|
||||
@@ -178,6 +189,9 @@ void cChunk::SetValid(void)
|
||||
|
||||
void cChunk::MarkRegenerating(void)
|
||||
{
|
||||
// Set as queued again:
|
||||
SetPresence(cpQueued);
|
||||
|
||||
// Tell all clients attached to this chunk that they want this chunk:
|
||||
for (cClientHandleList::iterator itr = m_LoadedByClient.begin(); itr != m_LoadedByClient.end(); ++itr)
|
||||
{
|
||||
@@ -191,7 +205,11 @@ void cChunk::MarkRegenerating(void)
|
||||
|
||||
bool cChunk::CanUnload(void)
|
||||
{
|
||||
return m_LoadedByClient.empty() && !m_IsDirty && (m_StayCount == 0);
|
||||
return
|
||||
m_LoadedByClient.empty() && // The chunk is not used by any client
|
||||
!m_IsDirty && // The chunk has been saved properly or hasn't been touched since the load / gen
|
||||
(m_StayCount == 0) && // The chunk is not in a ChunkStay
|
||||
(m_Presence != cpQueued) ; // The chunk is not queued for loading / generating (otherwise multi-load / multi-gen could occur)
|
||||
}
|
||||
|
||||
|
||||
@@ -223,7 +241,7 @@ void cChunk::MarkSaved(void)
|
||||
void cChunk::MarkLoaded(void)
|
||||
{
|
||||
m_IsDirty = false;
|
||||
SetValid();
|
||||
SetPresence(cpPresent);
|
||||
}
|
||||
|
||||
|
||||
@@ -232,12 +250,17 @@ void cChunk::MarkLoaded(void)
|
||||
|
||||
void cChunk::MarkLoadFailed(void)
|
||||
{
|
||||
if (m_IsValid)
|
||||
ASSERT(m_Presence == cpQueued);
|
||||
|
||||
// If the chunk is marked as needed, generate it:
|
||||
if (m_ShouldGenerateIfLoadFailed)
|
||||
{
|
||||
return;
|
||||
m_World->GetGenerator().QueueGenerateChunk(m_PosX, m_PosZ, false);
|
||||
}
|
||||
else
|
||||
{
|
||||
m_Presence = cpInvalid;
|
||||
}
|
||||
|
||||
m_HasLoadFailed = true;
|
||||
}
|
||||
|
||||
|
||||
@@ -246,6 +269,8 @@ void cChunk::MarkLoadFailed(void)
|
||||
|
||||
void cChunk::GetAllData(cChunkDataCallback & a_Callback)
|
||||
{
|
||||
ASSERT(m_Presence == cpPresent);
|
||||
|
||||
a_Callback.HeightMap(&m_HeightMap);
|
||||
a_Callback.BiomeData(&m_BiomeMap);
|
||||
|
||||
@@ -272,6 +297,7 @@ void cChunk::SetAllData(cSetChunkData & a_SetChunkData)
|
||||
{
|
||||
ASSERT(a_SetChunkData.IsHeightMapValid());
|
||||
ASSERT(a_SetChunkData.AreBiomesValid());
|
||||
ASSERT(IsQueued());
|
||||
|
||||
memcpy(m_BiomeMap, a_SetChunkData.GetBiomes(), sizeof(m_BiomeMap));
|
||||
memcpy(m_HeightMap, a_SetChunkData.GetHeightMap(), sizeof(m_HeightMap));
|
||||
@@ -317,7 +343,7 @@ void cChunk::SetAllData(cSetChunkData & a_SetChunkData)
|
||||
CreateBlockEntities();
|
||||
|
||||
// Set the chunk data as valid. This may be needed for some simulators that perform actions upon block adding (Vaporize)
|
||||
SetValid();
|
||||
SetPresence(cpPresent);
|
||||
|
||||
// Wake up all simulators for their respective blocks:
|
||||
WakeUpSimulators();
|
||||
|
||||
Reference in New Issue
Block a user