diff options
Diffstat (limited to '')
-rw-r--r-- | source/cEntity.cpp | 39 |
1 files changed, 29 insertions, 10 deletions
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 )
|