From 10752d2f35b729b1e84219b4075c9e77727ab1b4 Mon Sep 17 00:00:00 2001 From: "madmaxoft@gmail.com" Date: Wed, 8 Feb 2012 19:49:57 +0000 Subject: Removed unused code git-svn-id: http://mc-server.googlecode.com/svn/trunk@249 0a769ca7-a7f5-676a-18bf-c427514a06d6 --- source/cChunk.cpp | 157 ++++++++++++++++++++++++++++++++++++--------------- source/cChunk.h | 8 ++- source/cChunkMap.cpp | 23 +++----- source/cChunkMap.h | 1 - 4 files changed, 126 insertions(+), 63 deletions(-) (limited to 'source') diff --git a/source/cChunk.cpp b/source/cChunk.cpp index 6bf5172ae..3b0dd519c 100644 --- a/source/cChunk.cpp +++ b/source/cChunk.cpp @@ -436,6 +436,10 @@ char cChunk::GetHeight( int a_X, int a_Z ) return 0; } + + + + void cChunk::CreateBlockEntities() { m_pState->BlockListCriticalSection.Lock(); @@ -475,6 +479,10 @@ void cChunk::CreateBlockEntities() m_pState->BlockListCriticalSection.Unlock(); } + + + + void cChunk::CalculateHeightmap() { m_bCalculateHeightmap = false; @@ -495,6 +503,10 @@ void cChunk::CalculateHeightmap() } } + + + + void cChunk::CalculateLighting() { // Calculate sunlight @@ -538,6 +550,10 @@ void cChunk::CalculateLighting() m_bCalculateLighting = false; } + + + + void cChunk::SpreadLight(char* a_LightBuffer) { // Spread the sunlight @@ -643,12 +659,20 @@ void cChunk::SpreadLight(char* a_LightBuffer) if( bCalcBack ) m_World->ReSpreadLighting( BackChunk ); } + + + + void cChunk::AsyncUnload( cClientHandle* a_Client ) { m_pState->UnloadQuery.remove( a_Client ); // Make sure this client is only in the list once m_pState->UnloadQuery.push_back( a_Client ); } + + + + void cChunk::Send( cClientHandle* a_Client ) { cPacket_PreChunk PreChunk; @@ -666,12 +690,15 @@ void cChunk::Send( cClientHandle* a_Client ) m_pState->BlockListCriticalSection.Unlock(); } + + + + void cChunk::SetBlock( int a_X, int a_Y, int a_Z, char a_BlockType, char a_BlockMeta ) { - if(a_X < 0 || a_X >= 16 || a_Y < 0 || a_Y >= 128 || a_Z < 0 || a_Z >= 16) + if (a_X < 0 || a_X >= 16 || a_Y < 0 || a_Y >= 128 || a_Z < 0 || a_Z >= 16) { - //printf(">>>>>>>>>>>>>>>> CLIPPED SETBLOCK %i %i %i\n", a_X, a_Y, a_Z ); - return; // Clip + return; // Clip } int index = a_Y + (a_Z * 128) + (a_X * 128 * 16); @@ -681,49 +708,54 @@ void cChunk::SetBlock( int a_X, int a_Y, int a_Z, char a_BlockType, char a_Block SetLight( m_BlockMeta, index, a_BlockMeta ); - if( OldBlockType != a_BlockType || OldBlockMeta != a_BlockMeta ) + if ((OldBlockType == a_BlockType) && (OldBlockMeta == a_BlockMeta)) + { + return; + } + + //LOG("Old: %i %i New: %i %i", OldBlockType, OldBlockMeta, a_BlockType, a_BlockMeta ); + cCSLock Lock(m_pState->BlockListCriticalSection); + m_pState->PendingSendBlocks.push_back( index ); + + m_pState->ToTickBlocks[ MakeIndex( a_X, a_Y, a_Z ) ]++; + m_pState->ToTickBlocks[ MakeIndex( a_X+1, a_Y, a_Z ) ]++; + m_pState->ToTickBlocks[ MakeIndex( a_X-1, a_Y, a_Z ) ]++; + m_pState->ToTickBlocks[ MakeIndex( a_X, a_Y+1, a_Z ) ]++; + m_pState->ToTickBlocks[ MakeIndex( a_X, a_Y-1, a_Z ) ]++; + m_pState->ToTickBlocks[ MakeIndex( a_X, a_Y, a_Z+1 ) ]++; + m_pState->ToTickBlocks[ MakeIndex( a_X, a_Y, a_Z-1 ) ]++; + + cBlockEntity* BlockEntity = GetBlockEntity( a_X + m_PosX*16, a_Y+m_PosY*128, a_Z+m_PosZ*16 ); + if( BlockEntity ) + { + BlockEntity->Destroy(); + RemoveBlockEntity( BlockEntity ); + delete BlockEntity; + } + switch( a_BlockType ) { - //LOG("Old: %i %i New: %i %i", OldBlockType, OldBlockMeta, a_BlockType, a_BlockMeta ); - m_pState->BlockListCriticalSection.Lock(); - m_pState->PendingSendBlocks.push_back( index ); - - m_pState->ToTickBlocks[ MakeIndex( a_X, a_Y, a_Z ) ]++; - m_pState->ToTickBlocks[ MakeIndex( a_X+1, a_Y, a_Z ) ]++; - m_pState->ToTickBlocks[ MakeIndex( a_X-1, a_Y, a_Z ) ]++; - m_pState->ToTickBlocks[ MakeIndex( a_X, a_Y+1, a_Z ) ]++; - m_pState->ToTickBlocks[ MakeIndex( a_X, a_Y-1, a_Z ) ]++; - m_pState->ToTickBlocks[ MakeIndex( a_X, a_Y, a_Z+1 ) ]++; - m_pState->ToTickBlocks[ MakeIndex( a_X, a_Y, a_Z-1 ) ]++; - - cBlockEntity* BlockEntity = GetBlockEntity( a_X + m_PosX*16, a_Y+m_PosY*128, a_Z+m_PosZ*16 ); - if( BlockEntity ) - { - BlockEntity->Destroy(); - RemoveBlockEntity( BlockEntity ); - delete BlockEntity; - } - switch( a_BlockType ) - { case E_BLOCK_CHEST: + { AddBlockEntity( new cChestEntity( a_X + m_PosX*16, a_Y + m_PosY*128, a_Z + m_PosZ*16, this ) ); break; + } case E_BLOCK_FURNACE: + { AddBlockEntity( new cFurnaceEntity( a_X + m_PosX*16, a_Y + m_PosY*128, a_Z + m_PosZ*16, this ) ); break; + } case E_BLOCK_SIGN_POST: case E_BLOCK_WALLSIGN: + { AddBlockEntity( new cSignEntity( (ENUM_BLOCK_ID)a_BlockType, a_X + m_PosX*16, a_Y + m_PosY*128, a_Z + m_PosZ*16, this ) ); break; - default: - break; - }; + } + } // switch (a_BlockType) +} + + - m_pState->BlockListCriticalSection.Unlock(); - } - //RecalculateHeightmap(); - //RecalculateLighting(); -} void cChunk::FastSetBlock( int a_X, int a_Y, int a_Z, char a_BlockType, char a_BlockMeta ) { @@ -754,6 +786,10 @@ void cChunk::FastSetBlock( int a_X, int a_Y, int a_Z, char a_BlockType, char a_B RecalculateHeightmap(); } + + + + void cChunk::SendBlockTo( int a_X, int a_Y, int a_Z, cClientHandle* a_Client ) { if( a_Client == 0 ) @@ -781,6 +817,10 @@ void cChunk::SendBlockTo( int a_X, int a_Y, int a_Z, cClientHandle* a_Client ) } } + + + + void cChunk::AddBlockEntity( cBlockEntity* a_BlockEntity ) { m_pState->BlockListCriticalSection.Lock(); @@ -788,6 +828,10 @@ void cChunk::AddBlockEntity( cBlockEntity* a_BlockEntity ) m_pState->BlockListCriticalSection.Unlock(); } + + + + void cChunk::RemoveBlockEntity( cBlockEntity* a_BlockEntity ) { m_pState->BlockListCriticalSection.Lock(); @@ -795,6 +839,10 @@ void cChunk::RemoveBlockEntity( cBlockEntity* a_BlockEntity ) m_pState->BlockListCriticalSection.Unlock(); } + + + + void cChunk::AddClient( cClientHandle* a_Client ) { m_pState->LoadedByClient.remove( a_Client ); @@ -809,6 +857,10 @@ void cChunk::AddClient( cClientHandle* a_Client ) UnlockEntities(); } + + + + void cChunk::RemoveClient( cClientHandle* a_Client ) { m_pState->LoadedByClient.remove( a_Client ); @@ -826,6 +878,10 @@ void cChunk::RemoveClient( cClientHandle* a_Client ) } } + + + + void cChunk::AddEntity( cEntity & a_Entity ) { LockEntities(); @@ -833,6 +889,10 @@ void cChunk::AddEntity( cEntity & a_Entity ) UnlockEntities(); } + + + + bool cChunk::RemoveEntity( cEntity & a_Entity, cChunk* a_CalledFrom /* = 0 */ ) { LockEntities(); @@ -853,16 +913,28 @@ bool cChunk::RemoveEntity( cEntity & a_Entity, cChunk* a_CalledFrom /* = 0 */ ) return true; } + + + + void cChunk::LockEntities() { m_EntitiesCriticalSection->Lock(); } + + + + void cChunk::UnlockEntities() { m_EntitiesCriticalSection->Unlock(); } + + + + char cChunk::GetBlock( int a_X, int a_Y, int a_Z ) { if(a_X < 0 || a_X >= 16 || a_Y < 0 || a_Y >= 128 || a_Z < 0 || a_Z >= 16) return 0; // Clip @@ -871,12 +943,20 @@ char cChunk::GetBlock( int a_X, int a_Y, int a_Z ) return m_BlockType[index]; } + + + + char cChunk::GetBlock( int a_BlockIdx ) { if( a_BlockIdx < 0 || a_BlockIdx >= c_NumBlocks ) return 0; return m_BlockType[ a_BlockIdx ]; } + + + + cBlockEntity* cChunk::GetBlockEntity( int a_X, int a_Y, int a_Z ) { m_pState->BlockListCriticalSection.Lock(); @@ -992,17 +1072,6 @@ bool cChunk::LoadFromDisk() -bool cChunk::SaveToDisk() -{ - assert(!"Old save format not supported anymore"); // Remove the call to this function - - return false; //no more saving old format! -} - - - - - void cChunk::Broadcast( const cPacket & a_Packet, cClientHandle* a_Exclude /* = 0 */ ) const { for( std::list< cClientHandle* >::const_iterator itr = m_pState->LoadedByClient.begin(); itr != m_pState->LoadedByClient.end(); ++itr ) diff --git a/source/cChunk.h b/source/cChunk.h index cd1122922..d18f09160 100644 --- a/source/cChunk.h +++ b/source/cChunk.h @@ -77,7 +77,6 @@ public: inline void RecalculateHeightmap() { m_bCalculateHeightmap = true; } // Recalculate heightmap next tick void SpreadLight(char* a_LightBuffer); - bool SaveToDisk(); bool LoadFromDisk(); // Broadcasts to all clients that have loaded this chunk @@ -121,8 +120,6 @@ private: void LoadFromJson( const Json::Value & a_Value ); void SaveToJson( Json::Value & a_Value ); - void GenerateTerrain(); - void GenerateFoliage(); void CalculateLighting(); // Recalculate right now void CalculateHeightmap(); void SpreadLightOfBlock(char* a_LightBuffer, int a_X, int a_Y, int a_Z, char a_Falloff); @@ -152,6 +149,11 @@ private: cCriticalSection* m_EntitiesCriticalSection; }; + + + + + #if C_CHUNK_USE_INLINE # include "cChunk.inl.h" #endif \ No newline at end of file diff --git a/source/cChunkMap.cpp b/source/cChunkMap.cpp index 424b26b5f..2d3aabd7b 100644 --- a/source/cChunkMap.cpp +++ b/source/cChunkMap.cpp @@ -59,6 +59,7 @@ cChunkMap::cChunkMap(cWorld* a_World ) cChunkMap::~cChunkMap() { + // TODO: delete layers } @@ -127,11 +128,6 @@ cChunkMap::cChunkLayer* cChunkMap::AddLayer( const cChunkLayer & a_Layer ) void cChunkMap::AddChunk( cChunk* a_Chunk ) { - /* // OLD - m_Nodes[ MakeHash( a_Chunk->GetPosX(), a_Chunk->GetPosZ() ) ].push_back( a_Chunk ); - */ - - // NEW const int LayerX = (int)(floorf((float)a_Chunk->GetPosX() / (float)(LAYER_SIZE))); const int LayerZ = (int)(floorf((float)a_Chunk->GetPosZ() / (float)(LAYER_SIZE))); cChunkLayer* FoundLayer = GetLayer( LayerX, LayerZ ); @@ -141,16 +137,20 @@ void cChunkMap::AddChunk( cChunk* a_Chunk ) NewLayer.m_X = LayerX; NewLayer.m_Z = LayerZ; FoundLayer = AddLayer( NewLayer ); - LOGWARN("Created new layer %i %i (total layers %i)", LayerX, LayerZ, m_NumLayers ); + LOG("Created new layer [%i %i] (total layers %i)", LayerX, LayerZ, m_NumLayers ); } //Get local coordinates in layer const int LocalX = a_Chunk->GetPosX() - LayerX * LAYER_SIZE; const int LocalZ = a_Chunk->GetPosZ() - LayerZ * LAYER_SIZE; if( FoundLayer->m_Chunks[ LocalX + LocalZ * LAYER_SIZE ].m_LiveChunk ) + { LOGWARN("WARNING: Added chunk to layer while it was already loaded!"); + } if( FoundLayer->m_Chunks[ LocalX + LocalZ * LAYER_SIZE ].m_Compressed ) + { LOGWARN("WARNING: Added chunk to layer while a compressed version exists!"); + } FoundLayer->m_Chunks[ LocalX + LocalZ * LAYER_SIZE ].m_LiveChunk = a_Chunk; FoundLayer->m_NumChunksLoaded++; } @@ -161,11 +161,6 @@ void cChunkMap::AddChunk( cChunk* a_Chunk ) void cChunkMap::RemoveChunk( cChunk* a_Chunk ) { - /* // OLD - m_Nodes[ MakeHash( a_Chunk->GetPosX(), a_Chunk->GetPosZ() ) ].erase( a_Chunk ); - */ - - // NEW cChunkLayer* Layer = GetLayerForChunk( a_Chunk->GetPosX(), a_Chunk->GetPosZ() ); if( Layer ) { @@ -392,10 +387,8 @@ void cChunkMap::UnloadUnusedChunks() SaveLayer( &Layer ); for( int i = 0; i < LAYER_SIZE*LAYER_SIZE; ++i ) // Free all chunk data for layer { - if( Layer.m_Chunks[i].m_Compressed ) - delete [] Layer.m_Chunks[i].m_Compressed; - if( Layer.m_Chunks[i].m_LiveChunk ) - delete Layer.m_Chunks[i].m_LiveChunk; + delete [] Layer.m_Chunks[i].m_Compressed; + delete Layer.m_Chunks[i].m_LiveChunk; } if( RemoveLayer( &Layer ) ) l--; } diff --git a/source/cChunkMap.h b/source/cChunkMap.h index 9cab98221..dfccf8213 100644 --- a/source/cChunkMap.h +++ b/source/cChunkMap.h @@ -21,7 +21,6 @@ public: ~cChunkMap(); void AddChunk( cChunk* a_Chunk ); - unsigned int MakeHash( int a_X, int a_Z ); cChunk* GetChunk( int a_X, int a_Y, int a_Z ); void RemoveChunk( cChunk* a_Chunk ); -- cgit v1.2.3