From 01398f84244c0f4f06c8edb1e741937792f53eb2 Mon Sep 17 00:00:00 2001 From: faketruth Date: Sun, 1 Jan 2012 16:20:52 +0000 Subject: Fixed the numchunks console command. Added some form of reference counting to cChunk to make sure it's not referenced when deleting it. Right now it's only needed due to the generation of chunks in a separate thread and adding it to the spread light list in cWorld git-svn-id: http://mc-server.googlecode.com/svn/trunk@161 0a769ca7-a7f5-676a-18bf-c427514a06d6 --- source/cWorld.cpp | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) (limited to 'source/cWorld.cpp') diff --git a/source/cWorld.cpp b/source/cWorld.cpp index 0b1ee7010..d10d01a0d 100644 --- a/source/cWorld.cpp +++ b/source/cWorld.cpp @@ -434,7 +434,8 @@ void cWorld::Tick(float a_Dt) //LOG("Spreading: %p", Chunk ); Chunk->SpreadLight( Chunk->pGetSkyLight() ); Chunk->SpreadLight( Chunk->pGetLight() ); - m_pState->SpreadQueue.remove( &*Chunk ); + m_pState->SpreadQueue.remove( Chunk ); + Chunk->RemoveReference(); TimesSpreaded++; } if( TimesSpreaded >= 50 ) @@ -676,6 +677,7 @@ void cWorld::UnloadUnusedChunks() m_LastUnload = m_Time; LockChunks(); + LOGINFO("Unloading unused chunks"); m_ChunkMap->UnloadUnusedChunks(); UnlockChunks(); } @@ -1055,13 +1057,18 @@ void cWorld::ReSpreadLighting( cChunk* a_Chunk ) LockChunks(); m_pState->SpreadQueue.remove( a_Chunk ); m_pState->SpreadQueue.push_back( a_Chunk ); +#define STRINGIZE(x) #x + a_Chunk->AddReference( __FILE__ ": " STRINGIZE(__LINE__) ); UnlockChunks(); } void cWorld::RemoveSpread( cChunk* a_Chunk ) { LockChunks(); + size_t SizeBefore = m_pState->SpreadQueue.size(); m_pState->SpreadQueue.remove( a_Chunk ); + if( SizeBefore != m_pState->SpreadQueue.size() ) + a_Chunk->RemoveReference(); UnlockChunks(); } @@ -1102,3 +1109,10 @@ const char* cWorld::GetName() { return m_pState->WorldName.c_str(); } +int cWorld::GetNumChunks() +{ + LockChunks(); + int NumChunks = m_ChunkMap->GetNumChunks(); + UnlockChunks(); + return NumChunks; +} \ No newline at end of file -- cgit v1.2.3