lludp: direct encode CoarseLocationUpdate

0.9.1.0-post-fixes
UbitUmarov 2019-03-16 17:44:34 +00:00
parent 5428b4799d
commit 2ff5b322be
1 changed files with 43 additions and 28 deletions

View File

@ -4180,46 +4180,61 @@ namespace OpenSim.Region.ClientStack.LindenUDP
m_udpServer.SendUDPPacket(m_udpClient, buf, ThrottleOutPacketType.Task, null, false, true); m_udpServer.SendUDPPacket(m_udpClient, buf, ThrottleOutPacketType.Task, null, false, true);
} }
static private readonly byte[] CoarseLocationUpdateHeader = new byte[] {
0, // no acks plz
0, 0, 0, 0, // sequence number
0, // extra
0xff, 6 // ID 6 (medium frequency)
};
public void SendCoarseLocationUpdate(List<UUID> users, List<Vector3> CoarseLocations) public void SendCoarseLocationUpdate(List<UUID> users, List<Vector3> CoarseLocations)
{ {
// We don't need to update inactive clients. // We don't need to update inactive clients.
if (!IsActive) if (!IsActive)
return; return;
CoarseLocationUpdatePacket loc = (CoarseLocationUpdatePacket)PacketPool.Instance.GetPacket(PacketType.CoarseLocationUpdate); int totalLocations = Math.Min(CoarseLocations.Count, 60);
loc.Header.Reliable = false; int totalAgents = Math.Min(users.Count, 60);
if(totalAgents > totalLocations)
// Each packet can only hold around 60 avatar positions and the client clears the mini-map each time totalAgents = totalLocations;
// a CoarseLocationUpdate packet is received. Oh well.
int total = Math.Min(CoarseLocations.Count, 60);
CoarseLocationUpdatePacket.IndexBlock ib = new CoarseLocationUpdatePacket.IndexBlock();
loc.Location = new CoarseLocationUpdatePacket.LocationBlock[total];
loc.AgentData = new CoarseLocationUpdatePacket.AgentDataBlock[total];
int selfindex = -1; int selfindex = -1;
for (int i = 0; i < total; i++) int preyindex = -1;
UDPPacketBuffer buf = m_udpServer.GetNewUDPBuffer(m_udpClient.RemoteEndPoint);
Buffer.BlockCopy(CoarseLocationUpdateHeader, 0, buf.Data, 0, 8);
byte[] data = buf.Data;
data[8] = (byte)totalLocations;
int pos = 9;
for (int i = 0; i < totalLocations; ++i)
{ {
CoarseLocationUpdatePacket.LocationBlock lb = data[pos++] = (byte)CoarseLocations[i].X;
new CoarseLocationUpdatePacket.LocationBlock(); data[pos++] = (byte)CoarseLocations[i].Y;
data[pos++] = CoarseLocations[i].Z > 1024 ? (byte)0 : (byte)(CoarseLocations[i].Z * 0.25f);
lb.X = (byte)CoarseLocations[i].X; if (i < totalAgents)
lb.Y = (byte)CoarseLocations[i].Y; {
if (users[i] == AgentId)
lb.Z = CoarseLocations[i].Z > 1024 ? (byte)0 : (byte)(CoarseLocations[i].Z * 0.25f); selfindex = i;
loc.Location[i] = lb; //if (users[i] == PreyId)
loc.AgentData[i] = new CoarseLocationUpdatePacket.AgentDataBlock(); // preyindex = -1;
loc.AgentData[i].AgentID = users[i]; }
if (users[i] == AgentId)
selfindex = i;
} }
ib.You = (short)selfindex; Utils.Int16ToBytes((short)selfindex, data, pos); pos += 2;
ib.Prey = -1; Utils.Int16ToBytes((short)preyindex, data, pos); pos += 2;
loc.Index = ib;
OutPacket(loc, ThrottleOutPacketType.Task); data[pos++] = (byte)totalAgents;
for (int i = 0; i < totalAgents; ++i)
{
users[i].ToBytes(data, pos);
pos += 16;
}
buf.DataLength = pos;
m_udpServer.SendUDPPacket(m_udpClient, buf, ThrottleOutPacketType.Task, null, false, false);
} }
#endregion Avatar Packet/Data Sending Methods #endregion Avatar Packet/Data Sending Methods