Merge branch 'master' of ssh://justincc@opensimulator.org/var/git/opensim

soprefactor
Justin Clark-Casey (justincc) 2010-05-21 21:58:55 +01:00
commit 89f1ddb0a5
15 changed files with 207 additions and 315 deletions

View File

@ -1065,7 +1065,7 @@ namespace OpenSim.Client.MXP.ClientStack
throw new System.NotImplementedException();
}
public void ReprioritizeUpdates(UpdatePriorityHandler handler)
public void ReprioritizeUpdates()
{
}

View File

@ -609,7 +609,7 @@ namespace OpenSim.Client.Sirikata.ClientStack
throw new System.NotImplementedException();
}
public void ReprioritizeUpdates(UpdatePriorityHandler handler)
public void ReprioritizeUpdates()
{
throw new System.NotImplementedException();
}

View File

@ -615,7 +615,7 @@ namespace OpenSim.Client.VWoHTTP.ClientStack
throw new System.NotImplementedException();
}
public void ReprioritizeUpdates(UpdatePriorityHandler handler)
public void ReprioritizeUpdates()
{
throw new System.NotImplementedException();
}

View File

@ -458,8 +458,6 @@ namespace OpenSim.Framework
public delegate void PlacesQuery(UUID QueryID, UUID TransactionID, string QueryText, uint QueryFlags, byte Category, string SimName, IClientAPI client);
public delegate void AgentFOV(IClientAPI client, float verticalAngle);
public delegate double UpdatePriorityHandler(UpdatePriorityData data);
public delegate void MuteListEntryUpdate(IClientAPI client, UUID MuteID, string Name, int Flags,UUID AgentID);
@ -571,17 +569,16 @@ namespace OpenSim.Framework
public float dwell;
}
public struct UpdatePriorityData {
private double m_priority;
private uint m_localID;
public class EntityUpdate
{
public ISceneEntity Entity;
public PrimUpdateFlags Flags;
public UpdatePriorityData(double priority, uint localID) {
this.m_priority = priority;
this.m_localID = localID;
public EntityUpdate(ISceneEntity entity, PrimUpdateFlags flags)
{
Entity = entity;
Flags = flags;
}
public double priority { get { return this.m_priority; } }
public uint localID { get { return this.m_localID; } }
}
/// <summary>
@ -1024,7 +1021,7 @@ namespace OpenSim.Framework
void SendAvatarDataImmediate(ISceneEntity avatar);
void SendPrimUpdate(ISceneEntity entity, PrimUpdateFlags updateFlags);
void ReprioritizeUpdates(UpdatePriorityHandler handler);
void ReprioritizeUpdates();
void FlushPrimUpdates();
void SendInventoryFolderDetails(UUID ownerID, UUID folderID, List<InventoryItemBase> items,

View File

@ -33,5 +33,6 @@ namespace OpenSim.Framework
{
UUID UUID { get; }
uint LocalId { get; }
Vector3 AbsolutePosition { get; }
}
}

View File

@ -50,18 +50,6 @@ using Nini.Config;
namespace OpenSim.Region.ClientStack.LindenUDP
{
public class EntityUpdate
{
public ISceneEntity Entity;
public PrimUpdateFlags Flags;
public EntityUpdate(ISceneEntity entity, PrimUpdateFlags flags)
{
Entity = entity;
Flags = flags;
}
}
public delegate bool PacketMethod(IClientAPI simClient, Packet packet);
/// <summary>
@ -325,6 +313,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP
private int m_cachedTextureSerial;
private PriorityQueue m_entityUpdates;
private Prioritizer m_prioritizer;
/// <value>
/// List used in construction of data blocks for an object update packet. This is to stop us having to
@ -462,6 +451,8 @@ namespace OpenSim.Region.ClientStack.LindenUDP
m_propertiesPacketTimer = new Timer(100);
m_propertiesPacketTimer.Elapsed += ProcessObjectPropertiesPacket;
m_prioritizer = new Prioritizer(m_scene);
RegisterLocalPacketHandlers();
}
@ -3457,14 +3448,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP
/// </summary>
public void SendPrimUpdate(ISceneEntity entity, PrimUpdateFlags updateFlags)
{
double priority;
if (entity is SceneObjectPart)
priority = ((SceneObjectPart)entity).ParentGroup.GetUpdatePriority(this);
else if (entity is ScenePresence)
priority = ((ScenePresence)entity).GetUpdatePriority(this);
else
priority = 0.0d;
double priority = m_prioritizer.GetUpdatePriority(this, entity);
lock (m_entityUpdates.SyncRoot)
m_entityUpdates.Enqueue(priority, new EntityUpdate(entity, updateFlags), entity.LocalId);
@ -3613,19 +3597,23 @@ namespace OpenSim.Region.ClientStack.LindenUDP
#endregion Packet Sending
}
public void ReprioritizeUpdates(UpdatePriorityHandler handler)
public void ReprioritizeUpdates()
{
//m_log.Debug("[CLIENT]: Reprioritizing prim updates for " + m_firstName + " " + m_lastName);
PriorityQueue.UpdatePriorityHandler update_priority_handler =
delegate(ref double priority, uint local_id)
{
priority = handler(new UpdatePriorityData(priority, local_id));
return priority != double.NaN;
};
lock (m_entityUpdates.SyncRoot)
m_entityUpdates.Reprioritize(update_priority_handler);
m_entityUpdates.Reprioritize(UpdatePriorityHandler);
}
private bool UpdatePriorityHandler(ref double priority, uint localID)
{
EntityBase entity;
if (m_scene.Entities.TryGetValue(localID, out entity))
{
priority = m_prioritizer.GetUpdatePriority(this, entity);
}
return priority != double.NaN;
}
public void FlushPrimUpdates()

View File

@ -548,7 +548,7 @@ namespace OpenSim.Region.Examples.SimpleModule
{
}
public void ReprioritizeUpdates(UpdatePriorityHandler handler)
public void ReprioritizeUpdates()
{
}

View File

@ -28,11 +28,12 @@
using System;
using System.Runtime.Serialization;
using System.Security.Permissions;
using OpenSim.Framework;
using OpenMetaverse;
namespace OpenSim.Region.Framework.Scenes
{
public abstract class EntityBase
public abstract class EntityBase : ISceneEntity
{
/// <summary>
/// The scene to which this entity belongs

View File

@ -0,0 +1,122 @@
using System;
using System.Collections.Generic;
using log4net;
using Nini.Config;
using OpenSim.Framework;
using OpenMetaverse;
namespace OpenSim.Region.Framework.Scenes
{
public enum UpdatePrioritizationSchemes
{
Time = 0,
Distance = 1,
SimpleAngularDistance = 2,
FrontBack = 3,
}
public class Prioritizer
{
private static readonly ILog m_log = LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
private Scene m_scene;
public Prioritizer(Scene scene)
{
m_scene = scene;
}
public double GetUpdatePriority(IClientAPI client, ISceneEntity entity)
{
switch (m_scene.UpdatePrioritizationScheme)
{
case UpdatePrioritizationSchemes.Time:
return GetPriorityByTime();
case UpdatePrioritizationSchemes.Distance:
return GetPriorityByDistance(client, entity);
case UpdatePrioritizationSchemes.SimpleAngularDistance:
return GetPriorityByDistance(client, entity);
case UpdatePrioritizationSchemes.FrontBack:
return GetPriorityByFrontBack(client, entity);
default:
throw new InvalidOperationException("UpdatePrioritizationScheme not defined.");
}
}
private double GetPriorityByTime()
{
return DateTime.UtcNow.ToOADate();
}
private double GetPriorityByDistance(IClientAPI client, ISceneEntity entity)
{
ScenePresence presence = m_scene.GetScenePresence(client.AgentId);
if (presence != null)
{
// If this is an update for our own avatar give it the highest priority
if (presence == entity)
return 0.0;
// Use the camera position for local agents and avatar position for remote agents
Vector3 presencePos = (presence.IsChildAgent) ?
presence.AbsolutePosition :
presence.CameraPosition;
// Use group position for child prims
Vector3 entityPos;
if (entity is SceneObjectPart)
entityPos = m_scene.GetGroupByPrim(entity.LocalId).AbsolutePosition;
else
entityPos = entity.AbsolutePosition;
return Vector3.DistanceSquared(presencePos, entityPos);
}
return double.NaN;
}
private double GetPriorityByFrontBack(IClientAPI client, ISceneEntity entity)
{
ScenePresence presence = m_scene.GetScenePresence(client.AgentId);
if (presence != null)
{
// If this is an update for our own avatar give it the highest priority
if (presence == entity)
return 0.0;
// Use group position for child prims
Vector3 entityPos = entity.AbsolutePosition;
if (entity is SceneObjectPart)
entityPos = m_scene.GetGroupByPrim(entity.LocalId).AbsolutePosition;
else
entityPos = entity.AbsolutePosition;
if (!presence.IsChildAgent)
{
// Root agent. Use distance from camera and a priority decrease for objects behind us
Vector3 camPosition = presence.CameraPosition;
Vector3 camAtAxis = presence.CameraAtAxis;
// Distance
double priority = Vector3.DistanceSquared(camPosition, entityPos);
// Plane equation
float d = -Vector3.Dot(camPosition, camAtAxis);
float p = Vector3.Dot(camAtAxis, entityPos) + d;
if (p < 0.0f) priority *= 2.0;
return priority;
}
else
{
// Child agent. Use the normal distance method
Vector3 presencePos = presence.AbsolutePosition;
return Vector3.DistanceSquared(presencePos, entityPos);
}
}
return double.NaN;
}
}
}

View File

@ -58,13 +58,6 @@ namespace OpenSim.Region.Framework.Scenes
public partial class Scene : SceneBase
{
public enum UpdatePrioritizationSchemes {
Time = 0,
Distance = 1,
SimpleAngularDistance = 2,
FrontBack = 3,
}
public delegate void SynchronizeSceneHandler(Scene scene);
public SynchronizeSceneHandler SynchronizeScene = null;
@ -388,12 +381,6 @@ namespace OpenSim.Region.Framework.Scenes
private int m_lastUpdate;
private bool m_firstHeartbeat = true;
private UpdatePrioritizationSchemes m_update_prioritization_scheme = UpdatePrioritizationSchemes.Time;
private bool m_reprioritization_enabled = true;
private double m_reprioritization_interval = 5000.0;
private double m_root_reprioritization_distance = 10.0;
private double m_child_reprioritization_distance = 20.0;
private object m_deleting_scene_object = new object();
// the minimum time that must elapse before a changed object will be considered for persisted
@ -401,15 +388,21 @@ namespace OpenSim.Region.Framework.Scenes
// the maximum time that must elapse before a changed object will be considered for persisted
public long m_persistAfter = DEFAULT_MAX_TIME_FOR_PERSISTENCE * 10000000L;
private UpdatePrioritizationSchemes m_priorityScheme = UpdatePrioritizationSchemes.Time;
private bool m_reprioritizationEnabled = true;
private double m_reprioritizationInterval = 5000.0;
private double m_rootReprioritizationDistance = 10.0;
private double m_childReprioritizationDistance = 20.0;
#endregion
#region Properties
public UpdatePrioritizationSchemes UpdatePrioritizationScheme { get { return this.m_update_prioritization_scheme; } }
public bool IsReprioritizationEnabled { get { return m_reprioritization_enabled; } }
public double ReprioritizationInterval { get { return m_reprioritization_interval; } }
public double RootReprioritizationDistance { get { return m_root_reprioritization_distance; } }
public double ChildReprioritizationDistance { get { return m_child_reprioritization_distance; } }
public UpdatePrioritizationSchemes UpdatePrioritizationScheme { get { return m_priorityScheme; } }
public bool IsReprioritizationEnabled { get { return m_reprioritizationEnabled; } }
public double ReprioritizationInterval { get { return m_reprioritizationInterval; } }
public double RootReprioritizationDistance { get { return m_rootReprioritizationDistance; } }
public double ChildReprioritizationDistance { get { return m_childReprioritizationDistance; } }
public AgentCircuitManager AuthenticateHandler
{
@ -611,6 +604,8 @@ namespace OpenSim.Region.Framework.Scenes
m_asyncSceneObjectDeleter = new AsyncSceneObjectGroupDeleter(this);
m_asyncSceneObjectDeleter.Enabled = true;
#region Region Settings
// Load region settings
m_regInfo.RegionSettings = m_storageManager.DataStore.LoadRegionSettings(m_regInfo.RegionID);
if (m_storageManager.EstateDataStore != null)
@ -657,6 +652,8 @@ namespace OpenSim.Region.Framework.Scenes
}
}
#endregion Region Settings
MainConsole.Instance.Commands.AddCommand("region", false, "reload estate",
"reload estate",
"Reload the estate data", HandleReloadEstate);
@ -701,6 +698,8 @@ namespace OpenSim.Region.Framework.Scenes
m_simulatorVersion = simulatorVersion + " (" + Util.GetRuntimeInformation() + ")";
#region Region Config
try
{
// Region config overrides global config
@ -754,38 +753,6 @@ namespace OpenSim.Region.Framework.Scenes
m_strictAccessControl = startupConfig.GetBoolean("StrictAccessControl", m_strictAccessControl);
IConfig interest_management_config = m_config.Configs["InterestManagement"];
if (interest_management_config != null)
{
string update_prioritization_scheme = interest_management_config.GetString("UpdatePrioritizationScheme", "Time").Trim().ToLower();
switch (update_prioritization_scheme)
{
case "time":
m_update_prioritization_scheme = UpdatePrioritizationSchemes.Time;
break;
case "distance":
m_update_prioritization_scheme = UpdatePrioritizationSchemes.Distance;
break;
case "simpleangulardistance":
m_update_prioritization_scheme = UpdatePrioritizationSchemes.SimpleAngularDistance;
break;
case "frontback":
m_update_prioritization_scheme = UpdatePrioritizationSchemes.FrontBack;
break;
default:
m_log.Warn("[SCENE]: UpdatePrioritizationScheme was not recognized, setting to default settomg of Time");
m_update_prioritization_scheme = UpdatePrioritizationSchemes.Time;
break;
}
m_reprioritization_enabled = interest_management_config.GetBoolean("ReprioritizationEnabled", true);
m_reprioritization_interval = interest_management_config.GetDouble("ReprioritizationInterval", 5000.0);
m_root_reprioritization_distance = interest_management_config.GetDouble("RootReprioritizationDistance", 10.0);
m_child_reprioritization_distance = interest_management_config.GetDouble("ChildReprioritizationDistance", 20.0);
}
m_log.Info("[SCENE]: Using the " + m_update_prioritization_scheme + " prioritization scheme");
#region BinaryStats
try
@ -822,6 +789,35 @@ namespace OpenSim.Region.Framework.Scenes
{
m_log.Warn("[SCENE]: Failed to load StartupConfig");
}
#endregion Region Config
#region Interest Management
IConfig interestConfig = m_config.Configs["InterestManagement"];
if (interestConfig != null)
{
string update_prioritization_scheme = interestConfig.GetString("UpdatePrioritizationScheme", "Time").Trim().ToLower();
try
{
m_priorityScheme = (UpdatePrioritizationSchemes)Enum.Parse(typeof(UpdatePrioritizationSchemes), update_prioritization_scheme, true);
}
catch (Exception)
{
m_log.Warn("[PRIORITIZER]: UpdatePrioritizationScheme was not recognized, setting to default prioritizer Time");
m_priorityScheme = UpdatePrioritizationSchemes.Time;
}
m_reprioritizationEnabled = interestConfig.GetBoolean("ReprioritizationEnabled", true);
m_reprioritizationInterval = interestConfig.GetDouble("ReprioritizationInterval", 5000.0);
m_rootReprioritizationDistance = interestConfig.GetDouble("RootReprioritizationDistance", 10.0);
m_childReprioritizationDistance = interestConfig.GetDouble("ChildReprioritizationDistance", 20.0);
}
m_log.Info("[SCENE]: Using the " + m_priorityScheme + " prioritization scheme");
#endregion Interest Management
}
/// <summary>

View File

@ -3602,106 +3602,7 @@ namespace OpenSim.Region.Framework.Scenes
SetFromItemID(uuid);
}
#endregion
public double GetUpdatePriority(IClientAPI client)
{
switch (Scene.UpdatePrioritizationScheme)
{
case Scene.UpdatePrioritizationSchemes.Time:
return GetPriorityByTime();
case Scene.UpdatePrioritizationSchemes.Distance:
return GetPriorityByDistance(client);
case Scene.UpdatePrioritizationSchemes.SimpleAngularDistance:
return GetPriorityBySimpleAngularDistance(client);
case Scenes.Scene.UpdatePrioritizationSchemes.FrontBack:
return GetPriorityByFrontBack(client);
default:
throw new InvalidOperationException("UpdatePrioritizationScheme not defined");
}
}
private double GetPriorityByTime()
{
return DateTime.Now.ToOADate();
}
private double GetPriorityByDistance(IClientAPI client)
{
ScenePresence presence = Scene.GetScenePresence(client.AgentId);
if (presence != null)
{
return GetPriorityByDistance((presence.IsChildAgent) ?
presence.AbsolutePosition : presence.CameraPosition);
}
return double.NaN;
}
private double GetPriorityBySimpleAngularDistance(IClientAPI client)
{
ScenePresence presence = Scene.GetScenePresence(client.AgentId);
if (presence != null)
{
return GetPriorityBySimpleAngularDistance((presence.IsChildAgent) ?
presence.AbsolutePosition : presence.CameraPosition);
}
return double.NaN;
}
private double GetPriorityByFrontBack(IClientAPI client)
{
ScenePresence presence = Scene.GetScenePresence(client.AgentId);
if (presence != null)
{
return GetPriorityByFrontBack(presence.CameraPosition, presence.CameraAtAxis);
}
return double.NaN;
}
public double GetPriorityByDistance(Vector3 position)
{
return Vector3.Distance(AbsolutePosition, position);
}
public double GetPriorityBySimpleAngularDistance(Vector3 position)
{
double distance = Vector3.Distance(position, AbsolutePosition);
if (distance >= double.Epsilon)
{
float height;
Vector3 box = GetAxisAlignedBoundingBox(out height);
double angle = box.X / distance;
double max = angle;
angle = box.Y / distance;
if (max < angle)
max = angle;
angle = box.Z / distance;
if (max < angle)
max = angle;
return -max;
}
else
return double.MinValue;
}
public double GetPriorityByFrontBack(Vector3 camPosition, Vector3 camAtAxis)
{
// Distance
double priority = Vector3.Distance(camPosition, AbsolutePosition);
// Scale
//priority -= GroupScale().Length();
// Plane equation
float d = -Vector3.Dot(camPosition, camAtAxis);
float p = Vector3.Dot(camAtAxis, AbsolutePosition) + d;
if (p < 0.0f) priority *= 2.0f;
return priority;
}
#endregion
}
}

View File

@ -3777,123 +3777,9 @@ namespace OpenSim.Region.Framework.Scenes
}
}
public double GetUpdatePriority(IClientAPI client)
{
switch (Scene.UpdatePrioritizationScheme)
{
case Scene.UpdatePrioritizationSchemes.Time:
return GetPriorityByTime();
case Scene.UpdatePrioritizationSchemes.Distance:
return GetPriorityByDistance(client);
case Scene.UpdatePrioritizationSchemes.SimpleAngularDistance:
return GetPriorityByDistance(client);
case Scenes.Scene.UpdatePrioritizationSchemes.FrontBack:
return GetPriorityByFrontBack(client);
default:
throw new InvalidOperationException("UpdatePrioritizationScheme not defined.");
}
}
private double GetPriorityByTime()
{
return DateTime.Now.ToOADate();
}
private double GetPriorityByDistance(IClientAPI client)
{
ScenePresence presence = Scene.GetScenePresence(client.AgentId);
if (presence != null)
{
return GetPriorityByDistance((presence.IsChildAgent) ?
presence.AbsolutePosition : presence.CameraPosition);
}
return double.NaN;
}
private double GetPriorityByFrontBack(IClientAPI client)
{
ScenePresence presence = Scene.GetScenePresence(client.AgentId);
if (presence != null)
{
return GetPriorityByFrontBack(presence.CameraPosition, presence.CameraAtAxis);
}
return double.NaN;
}
private double GetPriorityByDistance(Vector3 position)
{
return Vector3.Distance(AbsolutePosition, position);
}
private double GetPriorityByFrontBack(Vector3 camPosition, Vector3 camAtAxis)
{
// Distance
double priority = Vector3.Distance(camPosition, AbsolutePosition);
// Plane equation
float d = -Vector3.Dot(camPosition, camAtAxis);
float p = Vector3.Dot(camAtAxis, AbsolutePosition) + d;
if (p < 0.0f) priority *= 2.0f;
return priority;
}
private double GetSOGUpdatePriority(SceneObjectGroup sog)
{
switch (Scene.UpdatePrioritizationScheme)
{
case Scene.UpdatePrioritizationSchemes.Time:
throw new InvalidOperationException("UpdatePrioritizationScheme for time not supported for reprioritization");
case Scene.UpdatePrioritizationSchemes.Distance:
return sog.GetPriorityByDistance((IsChildAgent) ? AbsolutePosition : CameraPosition);
case Scene.UpdatePrioritizationSchemes.SimpleAngularDistance:
return sog.GetPriorityBySimpleAngularDistance((IsChildAgent) ? AbsolutePosition : CameraPosition);
case Scenes.Scene.UpdatePrioritizationSchemes.FrontBack:
return sog.GetPriorityByFrontBack(CameraPosition, CameraAtAxis);
default:
throw new InvalidOperationException("UpdatePrioritizationScheme not defined");
}
}
private double UpdatePriority(UpdatePriorityData data)
{
EntityBase entity;
SceneObjectGroup group;
if (Scene.Entities.TryGetValue(data.localID, out entity))
{
group = entity as SceneObjectGroup;
if (group != null)
return GetSOGUpdatePriority(group);
ScenePresence presence = entity as ScenePresence;
if (presence == null)
throw new InvalidOperationException("entity found is neither SceneObjectGroup nor ScenePresence");
switch (Scene.UpdatePrioritizationScheme)
{
case Scene.UpdatePrioritizationSchemes.Time:
throw new InvalidOperationException("UpdatePrioritization for time not supported for reprioritization");
case Scene.UpdatePrioritizationSchemes.Distance:
case Scene.UpdatePrioritizationSchemes.SimpleAngularDistance:
return GetPriorityByDistance((IsChildAgent) ? AbsolutePosition : CameraPosition);
case Scenes.Scene.UpdatePrioritizationSchemes.FrontBack:
return GetPriorityByFrontBack(CameraPosition, CameraAtAxis);
default:
throw new InvalidOperationException("UpdatePrioritizationScheme not defined");
}
}
else
{
group = Scene.GetGroupByPrim(data.localID);
if (group != null)
return GetSOGUpdatePriority(group);
}
return double.NaN;
}
private void ReprioritizeUpdates()
{
if (Scene.IsReprioritizationEnabled && Scene.UpdatePrioritizationScheme != Scene.UpdatePrioritizationSchemes.Time)
if (Scene.IsReprioritizationEnabled && Scene.UpdatePrioritizationScheme != UpdatePrioritizationSchemes.Time)
{
lock (m_reprioritization_timer)
{
@ -3907,7 +3793,7 @@ namespace OpenSim.Region.Framework.Scenes
private void Reprioritize(object sender, ElapsedEventArgs e)
{
m_controllingClient.ReprioritizeUpdates(UpdatePriority);
m_controllingClient.ReprioritizeUpdates();
lock (m_reprioritization_timer)
{

View File

@ -1065,7 +1065,7 @@ namespace OpenSim.Region.OptionalModules.Agent.InternetRelayClientView.Server
}
public void ReprioritizeUpdates(UpdatePriorityHandler handler)
public void ReprioritizeUpdates()
{
}

View File

@ -638,7 +638,7 @@ namespace OpenSim.Region.OptionalModules.World.NPC
{
}
public void ReprioritizeUpdates(UpdatePriorityHandler handler)
public void ReprioritizeUpdates()
{
}

View File

@ -641,7 +641,7 @@ namespace OpenSim.Tests.Common.Mock
{
}
public void ReprioritizeUpdates(UpdatePriorityHandler handler)
public void ReprioritizeUpdates()
{
}