1
0
Fork 0

Reduced packet spam when entities idle

* Try not to send look packets when nothing's changed.
This commit is contained in:
Tiger Wang 2020-04-21 23:16:28 +01:00
parent e205d4109b
commit f49f90906c
3 changed files with 12 additions and 4 deletions

View File

@ -39,8 +39,8 @@ cEntity::cEntity(eEntityType a_EntityType, Vector3d a_Pos, double a_Width, doubl
m_MaxHealth(1),
m_AttachedTo(nullptr),
m_Attachee(nullptr),
m_bDirtyHead(true),
m_bDirtyOrientation(true),
m_bDirtyHead(false),
m_bDirtyOrientation(false),
m_bHasSentNoSpeed(true),
m_bOnGround(false),
m_Gravity(-9.81f),

View File

@ -490,14 +490,22 @@ void cMonster::CalcLeashActions(std::chrono::milliseconds a_Dt)
void cMonster::SetPitchAndYawFromDestination(bool a_IsFollowingPath)
{
Vector3d BodyDistance;
if (!a_IsFollowingPath && (GetTarget() != nullptr))
if (!a_IsFollowingPath)
{
if (GetTarget() == nullptr)
{
// Avoid dirtying head position when nothing will change
// Thus avoids creating unnecessary network traffic
return;
}
BodyDistance = GetTarget()->GetPosition() - GetPosition();
}
else
{
BodyDistance = m_NextWayPointPosition - GetPosition();
}
double BodyRotation, BodyPitch;
BodyDistance.Normalize();
VectorToEuler(BodyDistance.x, BodyDistance.y, BodyDistance.z, BodyRotation, BodyPitch);

View File

@ -446,8 +446,8 @@ void cProtocol_1_9_0::SendSpawnMob(const cMonster & a_Mob)
Pkt.WriteBEDouble(LastSentPos.x);
Pkt.WriteBEDouble(LastSentPos.y);
Pkt.WriteBEDouble(LastSentPos.z);
Pkt.WriteByteAngle(a_Mob.GetHeadYaw()); // Doesn't seem to be used
Pkt.WriteByteAngle(a_Mob.GetPitch());
Pkt.WriteByteAngle(a_Mob.GetHeadYaw());
Pkt.WriteByteAngle(a_Mob.GetYaw());
Pkt.WriteBEInt16(static_cast<Int16>(a_Mob.GetSpeedX() * 400));
Pkt.WriteBEInt16(static_cast<Int16>(a_Mob.GetSpeedY() * 400));