From 499745c1c7a865941b3c102532777c19dfb92ca4 Mon Sep 17 00:00:00 2001 From: "madmaxoft@gmail.com" Date: Sat, 18 Feb 2012 17:53:22 +0000 Subject: Thread-safe chunk generation, storage and generator are queried for progress while initializing server Note that this commit breaks foliage generation - there are no trees in the chunks generated! git-svn-id: http://mc-server.googlecode.com/svn/trunk@292 0a769ca7-a7f5-676a-18bf-c427514a06d6 --- source/cChunkGenerator.cpp | 36 ++++++++++++++++++++++++++++++++---- 1 file changed, 32 insertions(+), 4 deletions(-) (limited to 'source/cChunkGenerator.cpp') diff --git a/source/cChunkGenerator.cpp b/source/cChunkGenerator.cpp index 5c8144f05..c0fea1fae 100644 --- a/source/cChunkGenerator.cpp +++ b/source/cChunkGenerator.cpp @@ -71,6 +71,7 @@ void cChunkGenerator::Stop(void) { mShouldTerminate = true; m_Event.Set(); + m_evtRemoved.Set(); // Wake up anybody waiting for empty queue Wait(); delete m_pWorldGenerator; @@ -109,6 +110,30 @@ void cChunkGenerator::GenerateChunk(int a_ChunkX, int a_ChunkY, int a_ChunkZ) +void cChunkGenerator::WaitForQueueEmpty(void) +{ + cCSLock Lock(m_CS); + while (!mShouldTerminate && !m_Queue.empty()) + { + cCSUnlock Unlock(Lock); + m_evtRemoved.Wait(); + } +} + + + + + +int cChunkGenerator::GetQueueLength(void) +{ + cCSLock Lock(m_CS); + return (int)m_Queue.size(); +} + + + + + void cChunkGenerator::Execute(void) { while (!mShouldTerminate) @@ -128,6 +153,7 @@ void cChunkGenerator::Execute(void) m_Queue.erase( m_Queue.begin() ); // Remove coordinate from queue bool SkipEnabled = (m_Queue.size() > QUEUE_SKIP_LIMIT); Lock.Unlock(); // Unlock ASAP + m_evtRemoved.Set(); if ( m_World->IsChunkValid(coords.m_ChunkX, coords.m_ChunkY, coords.m_ChunkZ) || @@ -138,7 +164,7 @@ void cChunkGenerator::Execute(void) continue; } - LOG("Generating chunk [%d, %d, %d]", coords.m_ChunkX, coords.m_ChunkY, coords.m_ChunkZ); + LOGD("Generating chunk [%d, %d, %d]", coords.m_ChunkX, coords.m_ChunkY, coords.m_ChunkZ); DoGenerate(coords.m_ChunkX, coords.m_ChunkY, coords.m_ChunkZ); // Save the chunk right after generating, so that we don't have to generate it again on next run @@ -151,9 +177,11 @@ void cChunkGenerator::Execute(void) void cChunkGenerator::DoGenerate(int a_ChunkX, int a_ChunkY, int a_ChunkZ) { - // TODO: Convert this not to require the actual cChunkPtr (generate into raw char array) - // char BlockData[cChunk::c_BlockDataSize]; - m_pWorldGenerator->GenerateChunk(a_ChunkX, a_ChunkY, a_ChunkZ); + char BlockData[cChunk::c_BlockDataSize]; + cEntityList Entities; + cBlockEntityList BlockEntities; + m_pWorldGenerator->GenerateChunk(a_ChunkX, a_ChunkY, a_ChunkZ, BlockData, Entities, BlockEntities); + m_World->ChunkDataGenerated(a_ChunkX, a_ChunkY, a_ChunkZ, BlockData, Entities, BlockEntities); } -- cgit v1.2.3