diff options
author | madmaxoft@gmail.com <madmaxoft@gmail.com@0a769ca7-a7f5-676a-18bf-c427514a06d6> | 2012-02-20 17:39:00 +0100 |
---|---|---|
committer | madmaxoft@gmail.com <madmaxoft@gmail.com@0a769ca7-a7f5-676a-18bf-c427514a06d6> | 2012-02-20 17:39:00 +0100 |
commit | d592882fe0d1e7762470e6b5eff2b14ed26f1e69 (patch) | |
tree | 2a9a9fc2a7f6efe75c19511425ad611ad1996fed /source/cEntity.cpp | |
parent | Using own ASSERT() that logs to file (diff) | |
download | cuberite-d592882fe0d1e7762470e6b5eff2b14ed26f1e69.tar cuberite-d592882fe0d1e7762470e6b5eff2b14ed26f1e69.tar.gz cuberite-d592882fe0d1e7762470e6b5eff2b14ed26f1e69.tar.bz2 cuberite-d592882fe0d1e7762470e6b5eff2b14ed26f1e69.tar.lz cuberite-d592882fe0d1e7762470e6b5eff2b14ed26f1e69.tar.xz cuberite-d592882fe0d1e7762470e6b5eff2b14ed26f1e69.tar.zst cuberite-d592882fe0d1e7762470e6b5eff2b14ed26f1e69.zip |
Diffstat (limited to 'source/cEntity.cpp')
-rw-r--r-- | source/cEntity.cpp | 83 |
1 files changed, 53 insertions, 30 deletions
diff --git a/source/cEntity.cpp b/source/cEntity.cpp index 00faf5baa..49993c093 100644 --- a/source/cEntity.cpp +++ b/source/cEntity.cpp @@ -106,27 +106,60 @@ void cEntity::MoveToCorrectChunk(bool a_bIgnoreOldChunk) return;
}
- if (!a_bIgnoreOldChunk)
+ class cMover :
+ public cClientDiffCallback
{
- cChunkPtr OldChunk = m_World->GetChunk(m_ChunkX, m_ChunkY, m_ChunkZ);
- OldChunk->RemoveEntity(this);
- cPacket_DestroyEntity DestroyEntity( this );
- OldChunk->Broadcast(DestroyEntity);
- }
+ virtual void Removed(cClientHandle * a_Client) override
+ {
+ if (m_IgnoreOldChunk)
+ {
+ return;
+ }
+ if (m_Destroy == NULL)
+ {
+ m_Destroy = new cPacket_DestroyEntity(m_Entity);
+ }
+ a_Client->Send(m_Destroy);
+ }
+
+ virtual void Added(cClientHandle * a_Client) override
+ {
+ if (m_Spawn == NULL)
+ {
+ m_Spawn = m_Entity->GetSpawnPacket(); // Only create the packet when needed
+ }
+ if (m_Spawn != NULL)
+ {
+ a_Client->Send(m_Spawn);
+ }
+ }
+ cPacket * m_Destroy;
+ cPacket * m_Spawn;
+ bool m_IgnoreOldChunk;
+ cEntity * m_Entity;
+
+ public:
+ cMover(cEntity * a_Entity, bool a_IgnoreOldChunk) :
+ m_Destroy(NULL),
+ m_Spawn(NULL),
+ m_IgnoreOldChunk(a_IgnoreOldChunk),
+ m_Entity(a_Entity)
+ {}
+
+ ~cMover()
+ {
+ delete m_Spawn;
+ delete m_Destroy;
+ }
+ } Mover(this, a_bIgnoreOldChunk);
+
+ m_World->CompareChunkClients(m_ChunkX, m_ChunkY, m_ChunkZ, ChunkX, ChunkY, ChunkZ, Mover);
+ m_World->MoveEntityToChunk(this, ChunkX, ChunkY, ChunkZ);
+
m_ChunkX = ChunkX;
m_ChunkY = ChunkY;
m_ChunkZ = ChunkZ;
- cChunkPtr NewChunk = m_World->GetChunk( m_ChunkX, m_ChunkY, m_ChunkZ );
- if ( NewChunk != NULL )
- {
- NewChunk->AddEntity( this );
- std::auto_ptr<cPacket> SpawnPacket(GetSpawnPacket());
- if (SpawnPacket.get() != NULL)
- {
- NewChunk->Broadcast(SpawnPacket.get());
- }
- }
}
@@ -151,19 +184,13 @@ void cEntity::Destroy() void cEntity::RemoveFromChunk(void)
{
- if ( m_World == NULL )
+ if (m_World == NULL)
{
return;
}
- cChunkPtr Chunk = m_World->GetChunk( m_ChunkX, m_ChunkY, m_ChunkZ );
- if ( Chunk != NULL )
- {
- cPacket_DestroyEntity DestroyEntity( this );
- Chunk->Broadcast( DestroyEntity );
- Chunk->RemoveEntity( this );
- m_bRemovedFromChunk = true;
- }
+ m_World->RemoveEntityFromChunk(this, m_ChunkX, m_ChunkY, m_ChunkZ);
+ m_bRemovedFromChunk = true;
}
@@ -180,11 +207,7 @@ void cEntity::SpawnOn(cClientHandle * a_Client) if (a_Client == NULL)
{
- cChunkPtr Chunk = m_World->GetChunk( m_ChunkX, m_ChunkY, m_ChunkZ );
- if ( Chunk != NULL )
- {
- Chunk->Broadcast(SpawnPacket.get());
- }
+ m_World->BroadcastToChunk(m_ChunkX, m_ChunkY, m_ChunkZ, *SpawnPacket.get(), NULL);
}
else
{
|