summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorpeterbell10 <peterbell10@live.co.uk>2020-03-04 15:47:51 +0100
committerGitHub <noreply@github.com>2020-03-04 15:47:51 +0100
commitd7a726a42399935b89c68c1f1825530df941890e (patch)
treebc65db328bf37bdd59cf7d3946019a650afed861
parentPrevent container item duplication (#4476) (diff)
downloadcuberite-d7a726a42399935b89c68c1f1825530df941890e.tar
cuberite-d7a726a42399935b89c68c1f1825530df941890e.tar.gz
cuberite-d7a726a42399935b89c68c1f1825530df941890e.tar.bz2
cuberite-d7a726a42399935b89c68c1f1825530df941890e.tar.lz
cuberite-d7a726a42399935b89c68c1f1825530df941890e.tar.xz
cuberite-d7a726a42399935b89c68c1f1825530df941890e.tar.zst
cuberite-d7a726a42399935b89c68c1f1825530df941890e.zip
-rw-r--r--src/Entities/Entity.cpp103
1 files changed, 50 insertions, 53 deletions
diff --git a/src/Entities/Entity.cpp b/src/Entities/Entity.cpp
index 9779c90de..57a4680bd 100644
--- a/src/Entities/Entity.cpp
+++ b/src/Entities/Entity.cpp
@@ -1878,72 +1878,69 @@ void cEntity::TeleportToCoords(double a_PosX, double a_PosY, double a_PosZ)
void cEntity::BroadcastMovementUpdate(const cClientHandle * a_Exclude)
{
// Process packet sending every two ticks
- if (GetWorld()->GetWorldAge() % 2 == 0)
+ if (GetWorld()->GetWorldAge() % 2 != 0)
{
- double SpeedSqr = GetSpeed().SqrLength();
- if (SpeedSqr == 0.0)
- {
- // Speed is zero, send this to clients once only as well as an absolute position
- if (!m_bHasSentNoSpeed)
- {
- m_World->BroadcastEntityVelocity(*this, a_Exclude);
- m_World->BroadcastTeleportEntity(*this, a_Exclude);
- m_bHasSentNoSpeed = true;
- }
- }
- else
+ return;
+ }
+
+ if (GetSpeed().HasNonZeroLength())
+ {
+ // Movin'
+ m_World->BroadcastEntityVelocity(*this, a_Exclude);
+ m_bHasSentNoSpeed = false;
+ }
+ else
+ {
+ // Speed is zero, send this to clients once only as well as an absolute position
+ if (!m_bHasSentNoSpeed)
{
- // Movin'
m_World->BroadcastEntityVelocity(*this, a_Exclude);
- m_bHasSentNoSpeed = false;
+ m_World->BroadcastTeleportEntity(*this, a_Exclude);
+ m_LastSentPosition = GetPosition();
+ m_bHasSentNoSpeed = true;
}
+ }
- // Only send movement if speed is not 0 and 'no speed' was sent to client
- if (!m_bHasSentNoSpeed || IsPlayer())
+ // 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
+ Vector3i Diff = (GetPosition() * 32.0).Floor() - (m_LastSentPosition * 32.0).Floor();
+ if (Diff.HasNonZeroLength()) // Have we moved?
+ {
+ if ((abs(Diff.x) <= 127) && (abs(Diff.y) <= 127) && (abs(Diff.z) <= 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
- Vector3i Diff = (GetPosition() * 32.0).Floor() - (m_LastSentPosition * 32.0).Floor();
-
- if (Diff.HasNonZeroLength()) // Have we moved?
+ // Difference within Byte limitations, use a relative move packet
+ if (m_bDirtyOrientation)
{
- if ((abs(Diff.x) <= 127) && (abs(Diff.y) <= 127) && (abs(Diff.z) <= 127)) // Limitations of a Byte
- {
- // Difference within Byte limitations, use a relative move packet
- if (m_bDirtyOrientation)
- {
- m_World->BroadcastEntityRelMoveLook(*this, Vector3<Int8>(Diff), a_Exclude);
- m_bDirtyOrientation = false;
- }
- else
- {
- m_World->BroadcastEntityRelMove(*this, Vector3<Int8>(Diff), 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
- {
- // Too big a movement, do a teleport
- m_World->BroadcastTeleportEntity(*this, a_Exclude);
- m_LastSentPosition = GetPosition(); // See above
- m_bDirtyOrientation = false;
- }
+ m_World->BroadcastEntityRelMoveLook(*this, Vector3<Int8>(Diff), a_Exclude);
+ m_bDirtyOrientation = false;
}
+ else
+ {
+ m_World->BroadcastEntityRelMove(*this, Vector3<Int8>(Diff), 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();
}
-
- if (m_bDirtyHead)
- {
- m_World->BroadcastEntityHeadLook(*this, a_Exclude);
- m_bDirtyHead = false;
- }
- if (m_bDirtyOrientation)
+ else
{
- // Send individual update in case above (sending with rel-move packet) wasn't done
- GetWorld()->BroadcastEntityLook(*this, a_Exclude);
+ // Too big a movement, do a teleport
+ m_World->BroadcastTeleportEntity(*this, a_Exclude);
+ m_LastSentPosition = GetPosition(); // See above
m_bDirtyOrientation = false;
}
}
+
+ if (m_bDirtyHead)
+ {
+ m_World->BroadcastEntityHeadLook(*this, a_Exclude);
+ m_bDirtyHead = false;
+ }
+ if (m_bDirtyOrientation)
+ {
+ // Send individual update in case above (sending with rel-move packet) wasn't done
+ GetWorld()->BroadcastEntityLook(*this, a_Exclude);
+ m_bDirtyOrientation = false;
+ }
}