1
0

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
This commit is contained in:
faketruth
2012-01-01 16:20:52 +00:00
parent d7068b35a8
commit 01398f8424
10 changed files with 187 additions and 14 deletions

View File

@@ -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;
}