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

soprefactor
Justin Clark-Casey (justincc) 2010-05-21 23:12:47 +01:00
commit 9e61e120a1
1 changed files with 57 additions and 0 deletions

View File

@ -4,6 +4,7 @@ using log4net;
using Nini.Config;
using OpenSim.Framework;
using OpenMetaverse;
using OpenSim.Region.Physics.Manager;
/*
* Steps to add a new prioritization policy:
@ -25,6 +26,7 @@ namespace OpenSim.Region.Framework.Scenes
Distance = 1,
SimpleAngularDistance = 2,
FrontBack = 3,
BestAvatarResponsiveness = 4,
}
public class Prioritizer
@ -50,6 +52,8 @@ namespace OpenSim.Region.Framework.Scenes
return GetPriorityByDistance(client, entity); // TODO: Reimplement SimpleAngularDistance
case UpdatePrioritizationSchemes.FrontBack:
return GetPriorityByFrontBack(client, entity);
case UpdatePrioritizationSchemes.BestAvatarResponsiveness:
return GetPriorityByBestAvatarResponsiveness(client, entity);
default:
throw new InvalidOperationException("UpdatePrioritizationScheme not defined.");
}
@ -130,5 +134,58 @@ namespace OpenSim.Region.Framework.Scenes
return double.NaN;
}
private double GetPriorityByBestAvatarResponsiveness(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)
{
if (entity is ScenePresence)
return 1.0;
// 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;
if (entity is SceneObjectPart)
{
PhysicsActor physActor = ((SceneObjectPart)entity).ParentGroup.RootPart.PhysActor;
if (physActor == null || !physActor.IsPhysical)
priority+=100;
}
return priority;
}
else
{
// Child agent. Use the normal distance method
Vector3 presencePos = presence.AbsolutePosition;
return Vector3.DistanceSquared(presencePos, entityPos);
}
}
return double.NaN;
}
}
}