From dada2bea27bbc0b5dec68e8089ce5b8c296baabd Mon Sep 17 00:00:00 2001 From: faketruth Date: Wed, 2 Nov 2011 20:19:57 +0000 Subject: Fixed some "Entity was not found in any chunk!" warnings Player's current world is saved in the player file. When a player joins the server, the player joins the last world he was in. It seems MCServer can finally run multiple worlds! It just needs functionality to switch between them git-svn-id: http://mc-server.googlecode.com/svn/trunk@46 0a769ca7-a7f5-676a-18bf-c427514a06d6 --- source/cEntity.cpp | 39 +++++++++++++++++++++++++++++---------- 1 file changed, 29 insertions(+), 10 deletions(-) (limited to 'source/cEntity.cpp') diff --git a/source/cEntity.cpp b/source/cEntity.cpp index c22be3def..b9cbbd9f6 100644 --- a/source/cEntity.cpp +++ b/source/cEntity.cpp @@ -28,6 +28,7 @@ cEntity::cEntity(const double & a_X, const double & a_Y, const double & a_Z) , m_bDestroyed( false ) , m_EntityType( E_ENTITY ) , m_World( 0 ) + , m_bRemovedFromChunk( false ) { m_EntityCount++; m_UniqueID = m_EntityCount; @@ -35,18 +36,12 @@ cEntity::cEntity(const double & a_X, const double & a_Y, const double & a_Z) cEntity::~cEntity() { - delete m_Referencers; - delete m_References; - if( m_World ) + if( !m_bDestroyed || !m_bRemovedFromChunk ) { - cChunk* Chunk = m_World->GetChunkUnreliable( m_ChunkX, m_ChunkY, m_ChunkZ ); - if( Chunk ) - { - cPacket_DestroyEntity DestroyEntity( this ); - Chunk->Broadcast( DestroyEntity ); - Chunk->RemoveEntity( *this ); - } + LOGERROR("ERROR: Entity deallocated without being destroyed %i or unlinked %i", m_bDestroyed, m_bRemovedFromChunk ); } + delete m_Referencers; + delete m_References; delete m_Pos; delete m_Rot; } @@ -143,6 +138,30 @@ void cEntity::MoveToCorrectChunk() } } +void cEntity::Destroy() +{ + if( !m_bDestroyed ) + { + m_bDestroyed = true; + if( !m_bRemovedFromChunk ) + RemoveFromChunk(0); + } +} + +void cEntity::RemoveFromChunk( cChunk* a_Chunk ) +{ + if( m_World ) + { + cChunk* Chunk = ( a_Chunk ? a_Chunk : m_World->GetChunkUnreliable( m_ChunkX, m_ChunkY, m_ChunkZ ) ); + if( Chunk ) + { + cPacket_DestroyEntity DestroyEntity( this ); + Chunk->Broadcast( DestroyEntity ); + Chunk->RemoveEntity( *this ); + m_bRemovedFromChunk = true; + } + } +} CLASS_DEF_GETCLASS( cEntity ); bool cEntity::IsA( const char* a_EntityType ) -- cgit v1.2.3