Stabilise MoveToWorld (#4004)

* Stabilise MoveToWorld

* Fix comments and deprecate ScheduleMoveToWorld

* Enhanced thread safety for m_WorldChangeInfo

* Return unique_ptr from cAtomicUniquePtr::exchange

* cWorld now calls entity cEntity::OnAddToWorld and cEntity::OnRemoveFromWorld.

Allows broadcasting entities added to the world from the world's tick thread.
This also factors out some common code from cEntity::DoMoveToWorld and cEntity::Initialize.

As a consequence, cEntity::Destroy(false) (i.e. Destroying the entity without broadcasting) is impossible.
This isn't used anywhere in Cuberite so it's now deprecated.

* Update entity position after removing it from the world.
Fixes broadcasts being sent to the wrong chunk.

* Fix style

* cEntity: Update LastSentPosition when sending spawn packet

* Add Wno-deprecated-declarations to the lua bindings

* Kill uses of ScheduleMoveToWorld
This commit is contained in:
Mat
2020-03-05 12:52:34 +02:00
committed by GitHub
parent d7a726a423
commit 7d4934534e
22 changed files with 406 additions and 222 deletions
+18 -4
View File
@@ -132,12 +132,12 @@ cMonster::~cMonster()
void cMonster::Destroy(bool a_ShouldBroadcast)
void cMonster::OnRemoveFromWorld(cWorld & a_World)
{
if (IsLeashed())
{
cEntity * LeashedTo = GetLeashedTo();
Unleash(false, a_ShouldBroadcast);
Unleash(false, true);
// Remove leash knot if there are no more mobs leashed to
if (!LeashedTo->HasAnyMobLeashed() && LeashedTo->IsLeashKnot())
@@ -146,7 +146,7 @@ void cMonster::Destroy(bool a_ShouldBroadcast)
}
}
super::Destroy(a_ShouldBroadcast);
super::OnRemoveFromWorld(a_World);
}
@@ -282,7 +282,7 @@ void cMonster::Tick(std::chrono::milliseconds a_Dt, cChunk & a_Chunk)
m_DestroyTimer += a_Dt;
if (m_DestroyTimer > std::chrono::seconds(1))
{
Destroy(true);
Destroy();
}
return;
}
@@ -590,6 +590,20 @@ bool cMonster::DoTakeDamage(TakeDamageInfo & a_TDI)
void cMonster::DoMoveToWorld(const cEntity::sWorldChangeInfo & a_WorldChangeInfo)
{
// Stop all mobs from targeting this entity
// Stop this entity from targeting other mobs
SetTarget(nullptr);
StopEveryoneFromTargetingMe();
super::DoMoveToWorld(a_WorldChangeInfo);
}
void cMonster::KilledBy(TakeDamageInfo & a_TDI)
{
super::KilledBy(a_TDI);