change pending messages for scripts listeners queue type

master
UbitUmarov 2020-02-24 03:06:35 +00:00
parent 72d38b267e
commit 1de010e969
1 changed files with 11 additions and 25 deletions

View File

@ -27,6 +27,7 @@
using System; using System;
using System.Collections; using System.Collections;
using System.Collections.Concurrent;
using System.Collections.Generic; using System.Collections.Generic;
using System.Text.RegularExpressions; using System.Text.RegularExpressions;
@ -99,8 +100,7 @@ namespace OpenSim.Region.CoreModules.Scripting.WorldComm
private const int DEBUG_CHANNEL = 2147483647; private const int DEBUG_CHANNEL = 2147483647;
private ListenerManager m_listenerManager; private ListenerManager m_listenerManager;
private Queue m_pending; private ConcurrentQueue<ListenerInfo> m_pending;
private Queue m_pendingQ;
private Scene m_scene; private Scene m_scene;
private int m_whisperdistance = 10; private int m_whisperdistance = 10;
private int m_saydistance = 20; private int m_saydistance = 20;
@ -140,8 +140,7 @@ namespace OpenSim.Region.CoreModules.Scripting.WorldComm
maxlisteners = maxhandles; maxlisteners = maxhandles;
m_listenerManager = new ListenerManager(maxlisteners, maxhandles); m_listenerManager = new ListenerManager(maxlisteners, maxhandles);
m_pendingQ = new Queue(); m_pending = new ConcurrentQueue<ListenerInfo>();
m_pending = Queue.Synchronized(m_pendingQ);
} }
public void PostInitialise() public void PostInitialise()
@ -319,35 +318,31 @@ namespace OpenSim.Region.CoreModules.Scripting.WorldComm
// in a limited set of listeners, each belonging a host. If the host is in range, add them // in a limited set of listeners, each belonging a host. If the host is in range, add them
// to the pending queue. // to the pending queue.
foreach (ListenerInfo li foreach (ListenerInfo li in m_listenerManager.GetListeners(UUID.Zero, channel, name, id, msg))
in m_listenerManager.GetListeners(UUID.Zero, channel,
name, id, msg))
{ {
// Dont process if this message is from yourself! // Dont process if this message is from yourself!
if (li.GetHostID().Equals(id)) if (li.GetHostID().Equals(id))
continue; continue;
SceneObjectPart sPart = m_scene.GetSceneObjectPart( SceneObjectPart sPart = m_scene.GetSceneObjectPart(li.GetHostID());
li.GetHostID());
if (sPart == null) if (sPart == null)
continue; continue;
double dis = Util.GetDistanceTo(sPart.AbsolutePosition, double dis = Vector3.DistanceSquared(sPart.AbsolutePosition, position);
position);
switch (type) switch (type)
{ {
case ChatTypeEnum.Whisper: case ChatTypeEnum.Whisper:
if (dis < m_whisperdistance) if (dis < m_whisperdistance * m_whisperdistance)
QueueMessage(new ListenerInfo(li, name, id, msg)); QueueMessage(new ListenerInfo(li, name, id, msg));
break; break;
case ChatTypeEnum.Say: case ChatTypeEnum.Say:
if (dis < m_saydistance) if (dis < m_saydistance * m_saydistance)
QueueMessage(new ListenerInfo(li, name, id, msg)); QueueMessage(new ListenerInfo(li, name, id, msg));
break; break;
case ChatTypeEnum.Shout: case ChatTypeEnum.Shout:
if (dis < m_shoutdistance) if (dis < m_shoutdistance * m_shoutdistance)
QueueMessage(new ListenerInfo(li, name, id, msg)); QueueMessage(new ListenerInfo(li, name, id, msg));
break; break;
@ -453,10 +448,7 @@ namespace OpenSim.Region.CoreModules.Scripting.WorldComm
protected void QueueMessage(ListenerInfo li) protected void QueueMessage(ListenerInfo li)
{ {
lock (m_pending.SyncRoot) m_pending.Enqueue(li);
{
m_pending.Enqueue(li);
}
} }
/// <summary> /// <summary>
@ -474,13 +466,7 @@ namespace OpenSim.Region.CoreModules.Scripting.WorldComm
/// <returns>ListenerInfo with filter filled in</returns> /// <returns>ListenerInfo with filter filled in</returns>
public IWorldCommListenerInfo GetNextMessage() public IWorldCommListenerInfo GetNextMessage()
{ {
ListenerInfo li = null; m_pending.TryDequeue(out ListenerInfo li);
lock (m_pending.SyncRoot)
{
li = (ListenerInfo)m_pending.Dequeue();
}
return li; return li;
} }