summaryrefslogtreecommitdiffstats
path: root/src/Entities/Entity.cpp
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/Entities/Entity.cpp63
1 files changed, 24 insertions, 39 deletions
diff --git a/src/Entities/Entity.cpp b/src/Entities/Entity.cpp
index 431d5f54b..8c2b6fea8 100644
--- a/src/Entities/Entity.cpp
+++ b/src/Entities/Entity.cpp
@@ -1917,12 +1917,7 @@ void cEntity::TeleportToCoords(double a_PosX, double a_PosY, double a_PosZ)
// ask the plugins to allow teleport to the new position.
if (!cRoot::Get()->GetPluginManager()->CallHookEntityTeleport(*this, m_LastPosition, Vector3d(a_PosX, a_PosY, a_PosZ)))
{
- ResetPosition({a_PosX, a_PosY, a_PosZ});
- auto world = m_World;
- if (world != nullptr) // The entity might not be in a world yet (just spawned, in cWorld::m_EntitiesToAdd)
- {
- world->BroadcastTeleportEntity(*this);
- }
+ SetPosition({a_PosX, a_PosY, a_PosZ});
}
}
@@ -1938,51 +1933,31 @@ void cEntity::BroadcastMovementUpdate(const cClientHandle * a_Exclude)
return;
}
- if (GetSpeed().HasNonZeroLength())
+ if (GetSpeed().SqrLength() > 0.001)
{
// Movin'
m_World->BroadcastEntityVelocity(*this, a_Exclude);
m_bHasSentNoSpeed = false;
}
- else
+ else if (!m_bHasSentNoSpeed)
{
// 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_LastSentPosition = GetPosition();
- m_bHasSentNoSpeed = true;
- }
+ m_World->BroadcastEntityVelocity(*this, a_Exclude);
+ m_World->BroadcastEntityPosition(*this, a_Exclude);
+ m_LastSentPosition = GetPosition();
+ m_bDirtyOrientation = false;
+ m_bHasSentNoSpeed = true;
}
- // 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
- {
- // 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->BroadcastEntityPosition(*this, 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();
+ m_bDirtyOrientation = false;
}
if (m_bDirtyHead)
@@ -1990,6 +1965,7 @@ void cEntity::BroadcastMovementUpdate(const cClientHandle * a_Exclude)
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
@@ -2076,6 +2052,15 @@ bool cEntity::IsAttachedTo(const cEntity * a_Entity) const
+bool cEntity::IsOrientationDirty() const
+{
+ return m_bDirtyOrientation;
+}
+
+
+
+
+
void cEntity::SetHeadYaw(double a_HeadYaw)
{
m_HeadYaw = a_HeadYaw;