private void SendCoarseLocations(object sender, System.Timers.ElapsedEventArgs e) { const int MAX_LOCATIONS = 60; const int INTERVAL_SECONDS = 3; if (++m_coarseLocationSeconds >= INTERVAL_SECONDS) { m_coarseLocationSeconds = 0; IScenePresence[] presences = m_scene.GetPresences(); if (presences.Length == 0) { return; } // Prune out child agents List <IScenePresence> rootPresences = new List <IScenePresence>(presences.Length); for (int i = 0; i < presences.Length; i++) { if (!presences[i].IsChildPresence) { rootPresences.Add(presences[i]); } } // Clamp the maximum locations to put in this packet int count = Math.Min(rootPresences.Count, MAX_LOCATIONS); if (count == 0) { return; } // Create the location and agentID blocks CoarseLocationUpdatePacket.AgentDataBlock[] uuids = new CoarseLocationUpdatePacket.AgentDataBlock[count]; CoarseLocationUpdatePacket.LocationBlock[] locations = new CoarseLocationUpdatePacket.LocationBlock[count]; for (int i = 0; i < count; i++) { IScenePresence presence = rootPresences[i]; Vector3 pos = presence.ScenePosition; uuids[i] = new CoarseLocationUpdatePacket.AgentDataBlock { AgentID = presence.ID }; locations[i] = new CoarseLocationUpdatePacket.LocationBlock { X = (byte)pos.X, Y = (byte)pos.Y, Z = (byte)pos.Z }; } for (int i = 0; i < rootPresences.Count; i++) { if (rootPresences[i] is LLAgent) { LLAgent agent = (LLAgent)rootPresences[i]; CoarseLocationUpdatePacket packet = new CoarseLocationUpdatePacket(); packet.Header.Reliable = false; packet.AgentData = uuids; packet.Location = locations; // Only the first MAX_COUNT avatars are in the list int you = (i < count) ? i : -1; packet.Index.You = (short)you; // TODO: Support Prey packet.Index.Prey = -1; m_udp.SendPacket(agent, packet, ThrottleCategory.Task, false); } } } }
private void SendCoarseLocations(object sender, System.Timers.ElapsedEventArgs e) { const int MAX_LOCATIONS = 60; const int INTERVAL_SECONDS = 3; if (++m_coarseLocationSeconds >= INTERVAL_SECONDS) { m_coarseLocationSeconds = 0; IScenePresence[] presences = m_scene.GetPresences(); if (presences.Length == 0) return; // Prune out child agents List<IScenePresence> rootPresences = new List<IScenePresence>(presences.Length); for (int i = 0; i < presences.Length; i++) { if (!presences[i].IsChildPresence) rootPresences.Add(presences[i]); } // Clamp the maximum locations to put in this packet int count = Math.Min(rootPresences.Count, MAX_LOCATIONS); if (count == 0) return; // Create the location and agentID blocks CoarseLocationUpdatePacket.AgentDataBlock[] uuids = new CoarseLocationUpdatePacket.AgentDataBlock[count]; CoarseLocationUpdatePacket.LocationBlock[] locations = new CoarseLocationUpdatePacket.LocationBlock[count]; for (int i = 0; i < count; i++) { IScenePresence presence = rootPresences[i]; Vector3 pos = presence.ScenePosition; uuids[i] = new CoarseLocationUpdatePacket.AgentDataBlock { AgentID = presence.ID }; locations[i] = new CoarseLocationUpdatePacket.LocationBlock { X = (byte)pos.X, Y = (byte)pos.Y, Z = (byte)pos.Z }; } for (int i = 0; i < rootPresences.Count; i++) { if (rootPresences[i] is LLAgent) { LLAgent agent = (LLAgent)rootPresences[i]; CoarseLocationUpdatePacket packet = new CoarseLocationUpdatePacket(); packet.Header.Reliable = false; packet.AgentData = uuids; packet.Location = locations; // Only the first MAX_COUNT avatars are in the list int you = (i < count) ? i : -1; packet.Index.You = (short)you; // TODO: Support Prey packet.Index.Prey = -1; m_udp.SendPacket(agent, packet, ThrottleCategory.Task, false); } } } }