diff options
author | madmaxoft@gmail.com <madmaxoft@gmail.com@0a769ca7-a7f5-676a-18bf-c427514a06d6> | 2012-02-16 14:42:35 +0100 |
---|---|---|
committer | madmaxoft@gmail.com <madmaxoft@gmail.com@0a769ca7-a7f5-676a-18bf-c427514a06d6> | 2012-02-16 14:42:35 +0100 |
commit | 423f49d175d8db6283232bd8bdc106e26bdcff4d (patch) | |
tree | 5c5cc58d1061c91d2cb39021853ce72ab59839ae /source/cChunkMap.cpp | |
parent | Chunks are properly saved before being unloaded now (diff) | |
download | cuberite-423f49d175d8db6283232bd8bdc106e26bdcff4d.tar cuberite-423f49d175d8db6283232bd8bdc106e26bdcff4d.tar.gz cuberite-423f49d175d8db6283232bd8bdc106e26bdcff4d.tar.bz2 cuberite-423f49d175d8db6283232bd8bdc106e26bdcff4d.tar.lz cuberite-423f49d175d8db6283232bd8bdc106e26bdcff4d.tar.xz cuberite-423f49d175d8db6283232bd8bdc106e26bdcff4d.tar.zst cuberite-423f49d175d8db6283232bd8bdc106e26bdcff4d.zip |
Diffstat (limited to 'source/cChunkMap.cpp')
-rw-r--r-- | source/cChunkMap.cpp | 111 |
1 files changed, 105 insertions, 6 deletions
diff --git a/source/cChunkMap.cpp b/source/cChunkMap.cpp index 6f422b3bd..7b249dcae 100644 --- a/source/cChunkMap.cpp +++ b/source/cChunkMap.cpp @@ -106,7 +106,7 @@ cChunkPtr cChunkMap::GetChunk( int a_ChunkX, int a_ChunkY, int a_ChunkZ ) cChunkPtr Chunk = Layer->GetChunk(a_ChunkX, a_ChunkZ);
if (!(Chunk->IsValid()))
{
- m_World->GetStorage().QueueLoadChunk(Chunk);
+ m_World->GetStorage().QueueLoadChunk(a_ChunkX, a_ChunkZ);
}
return Chunk;
}
@@ -174,6 +174,108 @@ void cChunkMap::UseBlockEntity(cPlayer * a_Player, int a_X, int a_Y, int a_Z) +void cChunkMap::MarkChunkDirty (int a_ChunkX, int a_ChunkY, int a_ChunkZ)
+{
+ cCSLock Lock(m_CSLayers);
+ cChunkPtr Chunk = GetChunkNoGen(a_ChunkX, a_ChunkY, a_ChunkZ);
+ if ((Chunk == NULL) || !Chunk->IsValid())
+ {
+ return;
+ }
+ Chunk->MarkDirty();
+}
+
+
+
+
+
+void cChunkMap::MarkChunkSaving(int a_ChunkX, int a_ChunkY, int a_ChunkZ)
+{
+ cCSLock Lock(m_CSLayers);
+ cChunkPtr Chunk = GetChunkNoGen(a_ChunkX, a_ChunkY, a_ChunkZ);
+ if ((Chunk == NULL) || !Chunk->IsValid())
+ {
+ return;
+ }
+ Chunk->MarkSaving();
+}
+
+
+
+
+
+void cChunkMap::MarkChunkSaved (int a_ChunkX, int a_ChunkY, int a_ChunkZ)
+{
+ cCSLock Lock(m_CSLayers);
+ cChunkPtr Chunk = GetChunkNoGen(a_ChunkX, a_ChunkY, a_ChunkZ);
+ if ((Chunk == NULL) || !Chunk->IsValid())
+ {
+ return;
+ }
+ Chunk->MarkSaved();
+}
+
+
+
+
+
+void cChunkMap::ChunkDataLoaded(int a_ChunkX, int a_ChunkY, int a_ChunkZ, const char * a_BlockData, cEntityList & a_Entities, cBlockEntityList & a_BlockEntities)
+{
+ cCSLock Lock(m_CSLayers);
+ cChunkPtr Chunk = GetChunkNoGen(a_ChunkX, a_ChunkY, a_ChunkZ);
+ if (Chunk == NULL)
+ {
+ return;
+ }
+ Chunk->SetAllData(a_BlockData, a_Entities, a_BlockEntities);
+ Chunk->MarkLoaded();
+}
+
+
+
+
+
+void cChunkMap::SetChunkData(int a_ChunkX, int a_ChunkY, int a_ChunkZ, const char * a_BlockData, cEntityList & a_Entities, cBlockEntityList & a_BlockEntities)
+{
+ cCSLock Lock(m_CSLayers);
+ cChunkPtr Chunk = GetChunkNoGen(a_ChunkX, a_ChunkY, a_ChunkZ);
+ if (Chunk == NULL)
+ {
+ return;
+ }
+ Chunk->SetAllData(a_BlockData, a_Entities, a_BlockEntities);
+}
+
+
+
+
+
+void cChunkMap::GetChunkData(int a_ChunkX, int a_ChunkY, int a_ChunkZ, cChunkDataCallback * a_Callback)
+{
+ cCSLock Lock(m_CSLayers);
+ cChunkPtr Chunk = GetChunkNoGen(a_ChunkX, a_ChunkY, a_ChunkZ);
+ if ((Chunk == NULL) || !Chunk->IsValid())
+ {
+ return;
+ }
+ Chunk->GetAllData(a_Callback);
+}
+
+
+
+
+
+bool cChunkMap::IsChunkValid(int a_ChunkX, int a_ChunkY, int a_ChunkZ)
+{
+ cCSLock Lock(m_CSLayers);
+ cChunkPtr Chunk = GetChunkNoGen(a_ChunkX, a_ChunkY, a_ChunkZ);
+ return (Chunk != NULL) && Chunk->IsValid();
+}
+
+
+
+
+
void cChunkMap::Tick( float a_Dt, MTRand & a_TickRandom )
{
cCSLock Lock(m_CSLayers);
@@ -274,9 +376,9 @@ void cChunkMap::cChunkLayer::Save(void) cWorld * World = m_Parent->GetWorld();
for (int i = 0; i < ARRAYCOUNT(m_Chunks); ++i)
{
- if ((m_Chunks[i] != NULL) && m_Chunks[i]->IsValid())
+ if ((m_Chunks[i] != NULL) && m_Chunks[i]->IsValid() && m_Chunks[i]->IsDirty())
{
- World->GetStorage().QueueSaveChunk(m_Chunks[i]);
+ World->GetStorage().QueueSaveChunk(m_Chunks[i]->GetPosX(), m_Chunks[i]->GetPosZ());
}
} // for i - m_Chunks[]
}
@@ -292,9 +394,6 @@ void cChunkMap::cChunkLayer::UnloadUnusedChunks(void) {
if ((m_Chunks[i] != NULL) && (m_Chunks[i]->CanUnload()))
{
- // TODO: Save the chunk if it was changed
- World->GetStorage().QueueSaveChunk(m_Chunks[i]); // _FT: FIXME: Right now it saves chunks even though it might not have changed.
- // Also I'm not sure what's going on when I queue this chunks and the next line says reset the pointer.. =/
m_Chunks[i].reset();
}
} // for i - m_Chunks[]
|