MCPcopy Create free account
hub / github.com/cuberite/cuberite / BroadcastMovementUpdate

Method BroadcastMovementUpdate

src/Entities/Entity.cpp:1100–1169  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1098
1099
1100void cEntity::BroadcastMovementUpdate(const cClientHandle * a_Exclude)
1101{
1102 //We need to keep updating the clients when there is movement or if there was a change in speed and after 2 ticks
1103 if( (m_Speed.SqrLength() > 0.0004f || m_bDirtySpeed) && (m_World->GetWorldAge() - m_TimeLastSpeedPacket >= 2))
1104 {
1105 m_World->BroadcastEntityVelocity(*this,a_Exclude);
1106 m_bDirtySpeed = false;
1107 m_TimeLastSpeedPacket = m_World->GetWorldAge();
1108 }
1109
1110 //Have to process position related packets this every two ticks
1111 if (m_World->GetWorldAge() % 2 == 0)
1112 {
1113 int DiffX = (int) (floor(GetPosX() * 32.0) - floor(m_LastPosX * 32.0));
1114 int DiffY = (int) (floor(GetPosY() * 32.0) - floor(m_LastPosY * 32.0));
1115 int DiffZ = (int) (floor(GetPosZ() * 32.0) - floor(m_LastPosZ * 32.0));
1116 Int64 DiffTeleportPacket = m_World->GetWorldAge() - m_TimeLastTeleportPacket;
1117 // 4 blocks is max Relative So if the Diff is greater than 127 or. Send an absolute position every 20 seconds
1118 if (DiffTeleportPacket >= 400 ||
1119 ((DiffX > 127) || (DiffX < -128) ||
1120 (DiffY > 127) || (DiffY < -128) ||
1121 (DiffZ > 127) || (DiffZ < -128)))
1122 {
1123 //
1124 m_World->BroadcastTeleportEntity(*this,a_Exclude);
1125 m_TimeLastTeleportPacket = m_World->GetWorldAge();
1126 m_TimeLastMoveReltPacket = m_TimeLastTeleportPacket; //Must synchronize.
1127 m_LastPosX = GetPosX();
1128 m_LastPosY = GetPosY();
1129 m_LastPosZ = GetPosZ();
1130 m_bDirtyPosition = false;
1131 m_bDirtyOrientation = false;
1132 }
1133 else
1134 {
1135 Int64 DiffMoveRelPacket = m_World->GetWorldAge() - m_TimeLastMoveReltPacket;
1136 //if the change is big enough.
1137 if ((abs(DiffX) >= 4 || abs(DiffY) >= 4 || abs(DiffZ) >= 4 || DiffMoveRelPacket >= 60) && m_bDirtyPosition)
1138 {
1139 if (m_bDirtyOrientation)
1140 {
1141 m_World->BroadcastEntityRelMoveLook(*this, (char)DiffX, (char)DiffY, (char)DiffZ,a_Exclude);
1142 m_bDirtyOrientation = false;
1143 }
1144 else
1145 {
1146 m_World->BroadcastEntityRelMove(*this, (char)DiffX, (char)DiffY, (char)DiffZ,a_Exclude);
1147 }
1148 m_LastPosX = GetPosX();
1149 m_LastPosY = GetPosY();
1150 m_LastPosZ = GetPosZ();
1151 m_bDirtyPosition = false;
1152 m_TimeLastMoveReltPacket = m_World->GetWorldAge();
1153 }
1154 else
1155 {
1156 if (m_bDirtyOrientation)
1157 {

Callers

nothing calls this directly

Calls 8

SqrLengthMethod · 0.80
GetWorldAgeMethod · 0.80
BroadcastEntityLookMethod · 0.45

Tested by

no test coverage detected