1
0

Avoid pickups to sink into blocks and disappear (#3739)

* Avoid pickups to sink into blocks and disappear
This commit is contained in:
Pablo Beltrán 2017-06-04 06:35:02 +02:00 committed by Lukas Pioch
parent 832298e7aa
commit 2b699dc749
2 changed files with 35 additions and 24 deletions

View File

@ -1010,6 +1010,7 @@ void cEntity::HandlePhysics(std::chrono::milliseconds a_Dt, cChunk & a_Chunk)
NextPos.y += 0.5; NextPos.y += 0.5;
} }
m_bHasSentNoSpeed = false; // this unlocks movement sending to client in BroadcastMovementUpdate function
m_bOnGround = true; m_bOnGround = true;
/* /*
@ -1915,35 +1916,39 @@ void cEntity::BroadcastMovementUpdate(const cClientHandle * a_Exclude)
m_bHasSentNoSpeed = false; m_bHasSentNoSpeed = false;
} }
// TODO: Pickups move disgracefully if relative move packets are sent as opposed to just velocity. Have a system to send relmove only when SetPosXXX() is called with a large difference in position // Only send movement if speed is not 0 and 'no speed' was sent to client
int DiffX = FloorC(GetPosX() * 32.0) - FloorC(m_LastSentPosition.x * 32.0); if (!m_bHasSentNoSpeed)
int DiffY = FloorC(GetPosY() * 32.0) - FloorC(m_LastSentPosition.y * 32.0);
int DiffZ = FloorC(GetPosZ() * 32.0) - FloorC(m_LastSentPosition.z * 32.0);
if ((DiffX != 0) || (DiffY != 0) || (DiffZ != 0)) // Have we moved?
{ {
if ((abs(DiffX) <= 127) && (abs(DiffY) <= 127) && (abs(DiffZ) <= 127)) // Limitations of a Byte // TODO: Pickups move disgracefully if relative move packets are sent as opposed to just velocity. Have a system to send relmove only when SetPosXXX() is called with a large difference in position
int DiffX = FloorC(GetPosX() * 32.0) - FloorC(m_LastSentPosition.x * 32.0);
int DiffY = FloorC(GetPosY() * 32.0) - FloorC(m_LastSentPosition.y * 32.0);
int DiffZ = FloorC(GetPosZ() * 32.0) - FloorC(m_LastSentPosition.z * 32.0);
if ((DiffX != 0) || (DiffY != 0) || (DiffZ != 0)) // Have we moved?
{ {
// Difference within Byte limitations, use a relative move packet if ((abs(DiffX) <= 127) && (abs(DiffY) <= 127) && (abs(DiffZ) <= 127)) // Limitations of a Byte
if (m_bDirtyOrientation)
{ {
m_World->BroadcastEntityRelMoveLook(*this, static_cast<char>(DiffX), static_cast<char>(DiffY), static_cast<char>(DiffZ), a_Exclude); // Difference within Byte limitations, use a relative move packet
m_bDirtyOrientation = false; if (m_bDirtyOrientation)
{
m_World->BroadcastEntityRelMoveLook(*this, static_cast<char>(DiffX), static_cast<char>(DiffY), static_cast<char>(DiffZ), a_Exclude);
m_bDirtyOrientation = false;
}
else
{
m_World->BroadcastEntityRelMove(*this, static_cast<char>(DiffX), static_cast<char>(DiffY), static_cast<char>(DiffZ), a_Exclude);
}
// Clients seem to store two positions, one for the velocity packet and one for the teleport / relmove packet
// The latter is only changed with a relmove / teleport, and m_LastSentPosition stores this position
m_LastSentPosition = GetPosition();
} }
else else
{ {
m_World->BroadcastEntityRelMove(*this, static_cast<char>(DiffX), static_cast<char>(DiffY), static_cast<char>(DiffZ), a_Exclude); // Too big a movement, do a teleport
m_World->BroadcastTeleportEntity(*this, a_Exclude);
m_LastSentPosition = GetPosition(); // See above
m_bDirtyOrientation = false;
} }
// Clients seem to store two positions, one for the velocity packet and one for the teleport / relmove packet
// The latter is only changed with a relmove / teleport, and m_LastSentPosition stores this position
m_LastSentPosition = GetPosition();
}
else
{
// Too big a movement, do a teleport
m_World->BroadcastTeleportEntity(*this, a_Exclude);
m_LastSentPosition = GetPosition(); // See above
m_bDirtyOrientation = false;
} }
} }

View File

@ -31,7 +31,7 @@ public:
virtual bool Item(cEntity * a_Entity) override virtual bool Item(cEntity * a_Entity) override
{ {
ASSERT(a_Entity->IsTicking()); ASSERT(a_Entity->IsTicking());
if (!a_Entity->IsPickup() || (a_Entity->GetUniqueID() <= m_Pickup->GetUniqueID())) if (!a_Entity->IsPickup() || (a_Entity->GetUniqueID() <= m_Pickup->GetUniqueID()) || !a_Entity->IsOnGround())
{ {
return false; return false;
} }
@ -59,6 +59,12 @@ public:
if (Item.m_ItemCount <= 0) if (Item.m_ItemCount <= 0)
{ {
/* Experimental: show animation pickups getting together */
int DiffX = FloorC(m_Pickup->GetPosX() * 32.0) - FloorC(EntityPos.x * 32.0);
int DiffY = FloorC(m_Pickup->GetPosY() * 32.0) - FloorC(EntityPos.y * 32.0);
int DiffZ = FloorC(m_Pickup->GetPosZ() * 32.0) - FloorC(EntityPos.z * 32.0);
a_Entity->GetWorld()->BroadcastEntityRelMove(*a_Entity, static_cast<char>(DiffX), static_cast<char>(DiffY), static_cast<char>(DiffZ));
/* End of experimental animation */
a_Entity->Destroy(); a_Entity->Destroy();
} }
else else
@ -159,7 +165,7 @@ void cPickup::Tick(std::chrono::milliseconds a_Dt, cChunk & a_Chunk)
} }
// Try to combine the pickup with adjacent same-item pickups: // Try to combine the pickup with adjacent same-item pickups:
if ((m_Item.m_ItemCount < m_Item.GetMaxStackSize())) // Don't combine if already full if ((m_Item.m_ItemCount < m_Item.GetMaxStackSize()) && IsOnGround()) // Don't combine if already full or not on ground
{ {
// By using a_Chunk's ForEachEntity() instead of cWorld's, pickups don't combine across chunk boundaries. // By using a_Chunk's ForEachEntity() instead of cWorld's, pickups don't combine across chunk boundaries.
// That is a small price to pay for not having to traverse the entire world for each entity. // That is a small price to pay for not having to traverse the entire world for each entity.