Chunk now has an indicator of load failure; Chunk generator uses cChunkStay

git-svn-id: http://mc-server.googlecode.com/svn/trunk@337 0a769ca7-a7f5-676a-18bf-c427514a06d6
master
madmaxoft@gmail.com 2012-02-28 12:11:14 +00:00
parent 230f98a774
commit 013ae71c87
9 changed files with 89 additions and 6 deletions

View File

@ -415,6 +415,9 @@ bool cWorldStorage::LoadChunk(int a_ChunkX, int a_ChunkY, int a_ChunkZ)
}
}
// Notify the chunk owner that the chunk failed to load (sets cChunk::m_HasLoadFailed to true):
m_World->ChunkLoadFailed(a_ChunkX, a_ChunkY, a_ChunkZ);
return false;
}

View File

@ -204,6 +204,20 @@ void cChunk::MarkLoaded(void)
void cChunk::MarkLoadFailed(void)
{
if (m_IsValid)
{
return;
}
m_HasLoadFailed = true;
}
void cChunk::GetAllData(cChunkDataCallback * a_Callback)
{
a_Callback->BlockData(m_BlockData);
@ -262,6 +276,8 @@ void cChunk::SetAllData(const char * a_BlockData, cEntityList & a_Entities, cBlo
CreateBlockEntities();
CalculateHeightmap();
m_HasLoadFailed = false;
}

View File

@ -121,6 +121,7 @@ public:
bool IsValid(void) const {return m_IsValid; } // Returns true if the chunk is valid (loaded / generated)
void SetValid(bool a_SendToClients = true); // Also wakes up all clients attached to this chunk to let them finish logging in
bool IsDirty(void) const {return m_IsDirty; } // Returns true if the chunk has changed since it was last saved
bool HasLoadFailed(void) const {return m_HasLoadFailed; } // Returns true if the chunk failed to load and hasn't been generated since then
bool CanUnload(void);
/*
@ -133,6 +134,7 @@ public:
void MarkSaving(void); // Marks the chunk as being saved.
void MarkSaved(void); // Marks the chunk as saved, if it didn't change from the last call to MarkSaving()
void MarkLoaded(void); // Marks the chunk as freshly loaded. Fails if the chunk is already valid
void MarkLoadFailed(void); // Marks the chunk as failed to load. Ignored is the chunk is already valid
/// Gets all chunk data, calls the a_Callback's methods for each data type
void GetAllData(cChunkDataCallback * a_Callback);
@ -231,6 +233,7 @@ private:
bool m_IsValid; // True if the chunk is loaded / generated
bool m_IsDirty; // True if the chunk has changed since it was last saved
bool m_IsSaving; // True if the chunk is being saved
bool m_HasLoadFailed; // True if chunk failed to load and hasn't been generated yet since then
cCriticalSection m_CSBlockLists;
std::map< unsigned int, int > m_ToTickBlocks;

View File

@ -782,6 +782,11 @@ bool cChunkMap::LoadChunk(int a_ChunkX, int a_ChunkY, int a_ChunkZ)
// Already loaded
return true;
}
if (Chunk->HasLoadFailed())
{
// Already tried loading and it failed
return false;
}
}
return m_World->GetStorage().LoadChunk(a_ChunkX, a_ChunkY, a_ChunkZ);
}
@ -803,6 +808,21 @@ void cChunkMap::LoadChunks(const cChunkCoordsList & a_Chunks)
void cChunkMap::ChunkLoadFailed(int a_ChunkX, int a_ChunkY, int a_ChunkZ)
{
cCSLock Lock(m_CSLayers);
cChunkPtr Chunk = GetChunkNoLoad(a_ChunkX, a_ChunkY, a_ChunkZ);
if (Chunk == NULL)
{
return;
}
Chunk->MarkLoadFailed();
}
void cChunkMap::UpdateSign(int a_X, int a_Y, int a_Z, const AString & a_Line1, const AString & a_Line2, const AString & a_Line3, const AString & a_Line4)
{
cCSLock Lock(m_CSLayers);

View File

@ -89,6 +89,9 @@ public:
/// Loads the chunks specified. Doesn't report failure, other than chunks being !IsValid()
void LoadChunks(const cChunkCoordsList & a_Chunks);
/// Marks the chunk as failed-to-load:
void ChunkLoadFailed(int a_ChunkX, int a_ChunkY, int a_ChunkZ);
void UpdateSign(int a_X, int a_Y, int a_Z, const AString & a_Line1, const AString & a_Line2, const AString & a_Line3, const AString & a_Line4);
/// Marks (a_Stay == true) or unmarks (a_Stay == false) chunks as non-unloadable; to be used only by cChunkStay!

View File

@ -2,21 +2,32 @@
#include "Globals.h"
#include "cFileFormatUpdater.h"
#include "cMCLogger.h"
#include "Vector3d.h"
#include "Vector3f.h"
#include "cItem.h"
#include <json/json.h>
typedef std::list< std::string > StringList;
StringList GetDirectoryContents( const char* a_Directory );
void cFileFormatUpdater::UpdateFileFormat()
{
UpdatePlayersOfWorld("world");
}
// Convert player .bin files to JSON
void cFileFormatUpdater::UpdatePlayersOfWorld( const char* a_WorldName )
{
@ -138,10 +149,6 @@ void cFileFormatUpdater::PlayerBINtoJSON( const char* a_FileName )
// Helper function
StringList GetDirectoryContents( const char* a_Directory )
{
@ -177,4 +184,8 @@ StringList GetDirectoryContents( const char* a_Directory )
#endif
return AllFiles;
}
}

View File

@ -1306,6 +1306,15 @@ void cWorld::LoadChunks(const cChunkCoordsList & a_Chunks)
void cWorld::ChunkLoadFailed(int a_ChunkX, int a_ChunkY, int a_ChunkZ)
{
m_ChunkMap->ChunkLoadFailed(a_ChunkX, a_ChunkY, a_ChunkZ);
}
void cWorld::UpdateSign(int a_X, int a_Y, int a_Z, const AString & a_Line1, const AString & a_Line2, const AString & a_Line3, const AString & a_Line4)
{
m_ChunkMap->UpdateSign(a_X, a_Y, a_Z, a_Line1, a_Line2, a_Line3, a_Line4);

View File

@ -133,6 +133,9 @@ public:
/// Loads the chunks specified. Doesn't report failure, other than chunks being !IsValid()
void LoadChunks(const cChunkCoordsList & a_Chunks);
/// Marks the chunk as failed-to-load:
void ChunkLoadFailed(int a_ChunkX, int a_ChunkY, int a_ChunkZ);
void UpdateSign(int a_X, int a_Y, int a_Z, const AString & a_Line1, const AString & a_Line2, const AString & a_Line3, const AString & a_Line4);
/// Marks (a_Stay == true) or unmarks (a_Stay == false) chunks as non-unloadable. To be used only by cChunkStay!

View File

@ -94,6 +94,21 @@ void cWorldGenerator::GenerateChunk(int a_ChunkX, int a_ChunkY, int a_ChunkZ, ch
void cWorldGenerator::PostGenerateChunk(int a_ChunkX, int a_ChunkY, int a_ChunkZ)
{
// Check the chunk just generated and all its 8-way neighbors
// Make the chunks stay loaded in the surrounding 5x5 area:
cChunkStay Stay(m_World);
Stay.Add(a_ChunkX, a_ChunkY, a_ChunkZ);
for (int x = -2; x <= 2; x++)
{
for (int z = -2; z <= 2; z++)
{
Stay.Add(a_ChunkX + x, a_ChunkY, a_ChunkZ + z);
} // for z
} // for x
Stay.Enable();
m_World->LoadChunks(Stay);
CheckNeighbors(a_ChunkX, a_ChunkY, a_ChunkZ);
for (int i = 0; i < ARRAYCOUNT(g_NeighborCoords); i++)
{