/// <summary> /// This method is called by the LLUDPServer and should never be called by anyone else /// It loops through the available updates and sends them out (no waiting) /// </summary> /// <param name = "numUpdates">The number of updates to send</param> public void SendPrimUpdates(int numPrimUpdates, int numAvaUpdates) { if (m_numberOfLoops < NUMBER_OF_LOOPS_TO_WAIT) //Wait for the client to finish connecting fully before sending out bunches of updates { m_numberOfLoops++; return; } if (m_inUse || m_presence.IsInTransit) { return; } m_inUse = true; //This is for stats int AgentMS = Util.EnvironmentTickCount(); #region New client entering the Scene, requires all objects in the Scene ///If we havn't started processing this client yet, we need to send them ALL the prims that we have in this Scene (and deal with culling as well...) if (!m_SentInitialObjects && m_presence.DrawDistance != 0.0f) { SendInitialObjects(); } int presenceNumToSend = numAvaUpdates; List <EntityUpdate> updates = new List <EntityUpdate>(); lock (m_presenceUpdatesToSendLock) { //Send the numUpdates of them if that many // if we don't have that many, we send as many as possible, then switch to objects if (m_presenceUpdatesToSend.Count != 0) { try { #if UseDictionaryForEntityUpdates Dictionary <uint, EntityUpdate> .Enumerator e = m_presenceUpdatesToSend.GetEnumerator(); e.MoveNext(); List <uint> entitiesToRemove = new List <uint>(); #endif int count = m_presenceUpdatesToSend.Count > presenceNumToSend ? presenceNumToSend : m_presenceUpdatesToSend.Count; for (int i = 0; i < count; i++) { #if UseRemovingEntityUpdates EntityUpdate update = ((EntityUpdate)m_presenceUpdatesToSend[0]); /*if (m_EntitiesInPacketQueue.Contains (update.Entity.UUID)) * { * m_presenceUpdatesToSend.RemoveAt (0); * m_presenceUpdatesToSend.Insert (m_presenceUpdatesToSend.Count, update.Entity.UUID, update); * continue; * } * m_EntitiesInPacketQueue.Add (update.Entity.UUID);*/ m_presenceUpdatesToSend.RemoveAt(0); if (update.Flags == PrimUpdateFlags.ForcedFullUpdate) { SendFullUpdateForPresence((IScenePresence)update.Entity); } else { updates.Add(update); } #elif UseDictionaryForEntityUpdates EntityUpdate update = e.Current.Value; entitiesToRemove.Add(update.Entity.LocalId); //Remove it later if (update.Flags == PrimUpdateFlags.ForcedFullUpdate) { SendFullUpdateForPresence((IScenePresence)update.Entity); } else { updates.Add(update); } e.MoveNext(); #else EntityUpdate update = m_presenceUpdatesToSend.Dequeue(); if (update.Flags == PrimUpdateFlags.ForcedFullUpdate) { SendFullUpdateForPresence((IScenePresence)update.Entity); } else { updates.Add(update); } #endif } #if UseDictionaryForEntityUpdates foreach (uint id in entitiesToRemove) { m_presenceUpdatesToSend.Remove(id); } #endif } catch (Exception ex) { MainConsole.Instance.WarnFormat("[SceneViewer]: Exception while running presence loop: {0}", ex); } } } if (updates.Count != 0) { presenceNumToSend -= updates.Count; m_presence.ControllingClient.SendAvatarUpdate(updates); } updates.Clear(); List <AnimationGroup> animationsToSend = new List <AnimationGroup>(); lock (m_presenceAnimationsToSendLock) { //Send the numUpdates of them if that many // if we don't have that many, we send as many as possible, then switch to objects if (m_presenceAnimationsToSend.Count != 0 && presenceNumToSend > 0) { try { int count = m_presenceAnimationsToSend.Count > presenceNumToSend ? presenceNumToSend : m_presenceAnimationsToSend.Count; for (int i = 0; i < count; i++) { AnimationGroup update = m_presenceAnimationsToSend.Dequeue(); /*if (m_AnimationsInPacketQueue.Contains (update.AvatarID)) * { * m_presenceAnimationsToSend.RemoveAt (0); * m_presenceAnimationsToSend.Insert (m_presenceAnimationsToSend.Count, update.AvatarID, update); * continue; * } * m_AnimationsInPacketQueue.Add (update.AvatarID);*/ animationsToSend.Add(update); } } catch (Exception ex) { MainConsole.Instance.WarnFormat("[SceneViewer]: Exception while running presence loop: {0}", ex); } } } foreach (AnimationGroup update in animationsToSend) { m_presence.ControllingClient.SendAnimations(update); } animationsToSend.Clear(); int primsNumToSend = numPrimUpdates; List <IEntity> entities = new List <IEntity>(); lock (m_objectPropertiesToSendLock) { //Send the numUpdates of them if that many // if we don't have that many, we send as many as possible, then switch to objects if (m_objectPropertiesToSend.Count != 0) { try { int count = m_objectPropertiesToSend.Count > primsNumToSend ? primsNumToSend : m_objectPropertiesToSend.Count; for (int i = 0; i < count; i++) { ISceneChildEntity entity = ((ISceneChildEntity)m_objectPropertiesToSend[0]); /*if (m_PropertiesInPacketQueue.Contains (entity.UUID)) * { * m_objectPropertiesToSend.RemoveAt (0); * m_objectPropertiesToSend.Insert (m_objectPropertiesToSend.Count, entity.UUID, entity); * continue; * } * m_PropertiesInPacketQueue.Add (entity.UUID);*/ m_objectPropertiesToSend.RemoveAt(0); entities.Add(entity); } } catch (Exception ex) { MainConsole.Instance.WarnFormat("[SceneViewer]: Exception while running presence loop: {0}", ex); } } } if (entities.Count > 0) { primsNumToSend -= entities.Count; m_presence.ControllingClient.SendObjectPropertiesReply(entities); } updates = new List <EntityUpdate>(); lock (m_objectUpdatesToSendLock) { if (m_objectUpdatesToSend.Count != 0) { try { int count = m_objectUpdatesToSend.Count > primsNumToSend ? primsNumToSend : m_objectUpdatesToSend.Count; for (int i = 0; i < count; i++) { EntityUpdate update = ((EntityUpdate)m_objectUpdatesToSend[0]); /*if (m_EntitiesInPacketQueue.Contains (update.Entity.UUID)) * { * m_objectUpdatesToSend.RemoveAt (0); * m_objectUpdatesToSend.Insert (m_objectUpdatesToSend.Count, update.Entity.UUID, update); * continue; * } * m_EntitiesInPacketQueue.Add (update.Entity.UUID);*/ //Fix the CRC for this update //Increment the CRC code so that the client won't be sent a cached update for this if (update.Flags != PrimUpdateFlags.PrimFlags) { ((ISceneChildEntity)update.Entity).CRC++; } updates.Add(update); m_objectUpdatesToSend.RemoveAt(0); } } catch (Exception ex) { MainConsole.Instance.WarnFormat("[SceneViewer]: Exception while running object loop: {0}", ex); } m_presence.ControllingClient.SendPrimUpdate(updates); } } //Add the time to the stats tracker IAgentUpdateMonitor reporter = (IAgentUpdateMonitor) m_presence.Scene.RequestModuleInterface <IMonitorModule>().GetMonitor( m_presence.Scene.RegionInfo.RegionID.ToString(), MonitorModuleHelper.AgentUpdateCount); if (reporter != null) { reporter.AddAgentTime(Util.EnvironmentTickCountSubtract(AgentMS)); } m_inUse = false; }
/// <summary> /// This method is called by the LLUDPServer and should never be called by anyone else /// It loops through the available updates and sends them out (no waiting) /// </summary> /// <param name="numUpdates">The number of updates to send</param> public void SendPrimUpdates(int numUpdates) { if (m_inUse) { return; } m_inUse = true; //This is for stats int AgentMS = Util.EnvironmentTickCount(); #region New client entering the Scene, requires all objects in the Scene ///If we havn't started processing this client yet, we need to send them ALL the prims that we have in this Scene (and deal with culling as well...) if (!m_SentInitialObjects) { m_SentInitialObjects = true; //If they are not in this region, we check to make sure that we allow seeing into neighbors if (!m_presence.IsChildAgent || (m_presence.Scene.RegionInfo.SeeIntoThisSimFromNeighbor) && Culler != null && m_prioritizer != null) { ISceneEntity[] entities = m_presence.Scene.Entities.GetEntities(); PriorityQueue <EntityUpdate, double> m_entsqueue = new PriorityQueue <EntityUpdate, double> (entities.Length); // build a prioritized list of things we need to send foreach (ISceneEntity e in entities) { if (e != null && e is SceneObjectGroup) { if (e.IsDeleted) { continue; } //Check for culling here! if (!Culler.ShowEntityToClient(m_presence, e)) { continue; } double priority = m_prioritizer.GetUpdatePriority(m_presence, e); //Send the root object first! EntityUpdate rootupdate = new EntityUpdate(e.RootChild, PrimUpdateFlags.FullUpdate); PriorityQueueItem <EntityUpdate, double> rootitem = new PriorityQueueItem <EntityUpdate, double> (); rootitem.Value = rootupdate; rootitem.Priority = priority; m_entsqueue.Enqueue(rootitem); foreach (ISceneChildEntity child in e.ChildrenEntities()) { if (child == e.RootChild) { continue; //Already sent } EntityUpdate update = new EntityUpdate(child, PrimUpdateFlags.FullUpdate); PriorityQueueItem <EntityUpdate, double> item = new PriorityQueueItem <EntityUpdate, double> (); item.Value = update; item.Priority = priority; m_entsqueue.Enqueue(item); } } } entities = null; // send them SendQueued(m_entsqueue); } } lock (m_presenceUpdatesToSend) { int numToSend = (int)(numUpdates * PresenceSendPercentage); //Send the numUpdates of them if that many // if we don't have that many, we send as many as possible, then switch to objects if (m_presenceUpdatesToSend.Count != 0) { int count = m_presenceUpdatesToSend.Count > numToSend ? numToSend : m_presenceUpdatesToSend.Count; List <EntityUpdate> updates = new List <EntityUpdate> (); for (int i = 0; i < count; i++) { updates.Add((EntityUpdate)m_presenceUpdatesToSend[0]); m_presenceUpdatesToSend.RemoveAt(0); } //If we're first, we definitely got set, so we don't need to check this at all m_ourPresenceHasUpdate = false; m_presence.ControllingClient.SendPrimUpdate(updates); } } lock (m_objectUpdatesToSend) { int numToSend = (int)(numUpdates * PrimSendPercentage); if (m_objectUpdatesToSend.Count != 0) { int count = m_objectUpdatesToSend.Count > numToSend ? numToSend : m_objectUpdatesToSend.Count; List <EntityUpdate> updates = new List <EntityUpdate> (); for (int i = 0; i < count; i++) { updates.Add((EntityUpdate)m_objectUpdatesToSend[0]); m_objectUpdatesToSend.RemoveAt(0); } m_presence.ControllingClient.SendPrimUpdate(updates); } } //Add the time to the stats tracker IAgentUpdateMonitor reporter = (IAgentUpdateMonitor)m_presence.Scene.RequestModuleInterface <IMonitorModule> ().GetMonitor(m_presence.Scene.RegionInfo.RegionID.ToString(), "Agent Update Count"); if (reporter != null) { reporter.AddAgentTime(Util.EnvironmentTickCountSubtract(AgentMS)); } m_inUse = false; }