diff options
author | faketruth <faketruth@0a769ca7-a7f5-676a-18bf-c427514a06d6> | 2011-11-02 21:19:57 +0100 |
---|---|---|
committer | faketruth <faketruth@0a769ca7-a7f5-676a-18bf-c427514a06d6> | 2011-11-02 21:19:57 +0100 |
commit | dada2bea27bbc0b5dec68e8089ce5b8c296baabd (patch) | |
tree | c87790fa9c5ce89bddb126c94a3a90fb13ce9478 /source/cEntity.cpp | |
parent | Fixed player spawn teleport postion. (diff) | |
download | cuberite-dada2bea27bbc0b5dec68e8089ce5b8c296baabd.tar cuberite-dada2bea27bbc0b5dec68e8089ce5b8c296baabd.tar.gz cuberite-dada2bea27bbc0b5dec68e8089ce5b8c296baabd.tar.bz2 cuberite-dada2bea27bbc0b5dec68e8089ce5b8c296baabd.tar.lz cuberite-dada2bea27bbc0b5dec68e8089ce5b8c296baabd.tar.xz cuberite-dada2bea27bbc0b5dec68e8089ce5b8c296baabd.tar.zst cuberite-dada2bea27bbc0b5dec68e8089ce5b8c296baabd.zip |
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 )
|