try save a few ns on chat to avatars

master
UbitUmarov 2020-02-24 05:36:05 +00:00
parent 1de010e969
commit df2536c407
1 changed files with 39 additions and 15 deletions

View File

@ -51,6 +51,11 @@ namespace OpenSim.Region.CoreModules.Avatar.Chat
protected int m_saydistance = 20;
protected int m_shoutdistance = 100;
protected int m_whisperdistance = 10;
protected float m_saydistanceSQ;
protected float m_shoutdistanceSQ;
protected float m_whisperdistanceSQ;
protected List<Scene> m_scenes = new List<Scene>();
protected List<string> FreezeCache = new List<string>();
protected string m_adminPrefix = "";
@ -74,7 +79,12 @@ namespace OpenSim.Region.CoreModules.Avatar.Chat
m_saydistance = m_config.GetInt("say_distance", m_saydistance);
m_shoutdistance = m_config.GetInt("shout_distance", m_shoutdistance);
m_adminPrefix = m_config.GetString("admin_prefix", "");
}
m_saydistanceSQ = m_saydistance * m_saydistance;
m_shoutdistanceSQ = m_shoutdistance * m_shoutdistance;
m_whisperdistanceSQ = m_whisperdistance *m_whisperdistance;
}
public virtual void AddRegion(Scene scene)
@ -407,21 +417,35 @@ namespace OpenSim.Region.CoreModules.Avatar.Chat
UUID fromAgentID, UUID ownerID, string fromName, ChatTypeEnum type,
string message, ChatSourceType src, bool ignoreDistance)
{
if (presence.LifecycleState != ScenePresenceState.Running)
if (presence.IsDeleted || presence.IsInTransit || !presence.ControllingClient.IsActive)
return false;
if (!ignoreDistance)
{
float maxDistSQ;
switch(type)
{
case ChatTypeEnum.Whisper:
maxDistSQ = m_whisperdistanceSQ;
break;
case ChatTypeEnum.Say:
maxDistSQ = m_saydistanceSQ;
break;
case ChatTypeEnum.Shout:
maxDistSQ = m_shoutdistanceSQ;
break;
default:
maxDistSQ = -1f;
break;
}
if(maxDistSQ > 0)
{
Vector3 fromRegionPos = fromPos + regionPos;
Vector3 toRegionPos = presence.AbsolutePosition +
new Vector3(presence.Scene.RegionInfo.WorldLocX, presence.Scene.RegionInfo.WorldLocY, 0);
int dis = (int)Util.GetDistanceTo(toRegionPos, fromRegionPos);
if (type == ChatTypeEnum.Whisper && dis > m_whisperdistance ||
type == ChatTypeEnum.Say && dis > m_saydistance ||
type == ChatTypeEnum.Shout && dis > m_shoutdistance)
{
if(maxDistSQ < Vector3.DistanceSquared(toRegionPos, fromRegionPos))
return false;
}
}