diff options
Diffstat (limited to 'OpenSim/Region/Framework')
-rw-r--r-- | OpenSim/Region/Framework/Scenes/Prioritizer.cs | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/OpenSim/Region/Framework/Scenes/Prioritizer.cs b/OpenSim/Region/Framework/Scenes/Prioritizer.cs index e6a4642..1eb0c28 100644 --- a/OpenSim/Region/Framework/Scenes/Prioritizer.cs +++ b/OpenSim/Region/Framework/Scenes/Prioritizer.cs | |||
@@ -4,6 +4,7 @@ using log4net; | |||
4 | using Nini.Config; | 4 | using Nini.Config; |
5 | using OpenSim.Framework; | 5 | using OpenSim.Framework; |
6 | using OpenMetaverse; | 6 | using OpenMetaverse; |
7 | using OpenSim.Region.Physics.Manager; | ||
7 | 8 | ||
8 | /* | 9 | /* |
9 | * Steps to add a new prioritization policy: | 10 | * Steps to add a new prioritization policy: |
@@ -25,6 +26,7 @@ namespace OpenSim.Region.Framework.Scenes | |||
25 | Distance = 1, | 26 | Distance = 1, |
26 | SimpleAngularDistance = 2, | 27 | SimpleAngularDistance = 2, |
27 | FrontBack = 3, | 28 | FrontBack = 3, |
29 | BestAvatarResponsiveness = 4, | ||
28 | } | 30 | } |
29 | 31 | ||
30 | public class Prioritizer | 32 | public class Prioritizer |
@@ -50,6 +52,8 @@ namespace OpenSim.Region.Framework.Scenes | |||
50 | return GetPriorityByDistance(client, entity); // TODO: Reimplement SimpleAngularDistance | 52 | return GetPriorityByDistance(client, entity); // TODO: Reimplement SimpleAngularDistance |
51 | case UpdatePrioritizationSchemes.FrontBack: | 53 | case UpdatePrioritizationSchemes.FrontBack: |
52 | return GetPriorityByFrontBack(client, entity); | 54 | return GetPriorityByFrontBack(client, entity); |
55 | case UpdatePrioritizationSchemes.BestAvatarResponsiveness: | ||
56 | return GetPriorityByBestAvatarResponsiveness(client, entity); | ||
53 | default: | 57 | default: |
54 | throw new InvalidOperationException("UpdatePrioritizationScheme not defined."); | 58 | throw new InvalidOperationException("UpdatePrioritizationScheme not defined."); |
55 | } | 59 | } |
@@ -130,5 +134,58 @@ namespace OpenSim.Region.Framework.Scenes | |||
130 | 134 | ||
131 | return double.NaN; | 135 | return double.NaN; |
132 | } | 136 | } |
137 | |||
138 | private double GetPriorityByBestAvatarResponsiveness(IClientAPI client, ISceneEntity entity) | ||
139 | { | ||
140 | ScenePresence presence = m_scene.GetScenePresence(client.AgentId); | ||
141 | if (presence != null) | ||
142 | { | ||
143 | // If this is an update for our own avatar give it the highest priority | ||
144 | if (presence == entity) | ||
145 | return 0.0; | ||
146 | |||
147 | // Use group position for child prims | ||
148 | Vector3 entityPos = entity.AbsolutePosition; | ||
149 | if (entity is SceneObjectPart) | ||
150 | entityPos = m_scene.GetGroupByPrim(entity.LocalId).AbsolutePosition; | ||
151 | else | ||
152 | entityPos = entity.AbsolutePosition; | ||
153 | |||
154 | if (!presence.IsChildAgent) | ||
155 | { | ||
156 | if (entity is ScenePresence) | ||
157 | return 1.0; | ||
158 | |||
159 | // Root agent. Use distance from camera and a priority decrease for objects behind us | ||
160 | Vector3 camPosition = presence.CameraPosition; | ||
161 | Vector3 camAtAxis = presence.CameraAtAxis; | ||
162 | |||
163 | // Distance | ||
164 | double priority = Vector3.DistanceSquared(camPosition, entityPos); | ||
165 | |||
166 | // Plane equation | ||
167 | float d = -Vector3.Dot(camPosition, camAtAxis); | ||
168 | float p = Vector3.Dot(camAtAxis, entityPos) + d; | ||
169 | if (p < 0.0f) priority *= 2.0; | ||
170 | |||
171 | if (entity is SceneObjectPart) | ||
172 | { | ||
173 | PhysicsActor physActor = ((SceneObjectPart)entity).ParentGroup.RootPart.PhysActor; | ||
174 | if (physActor == null || !physActor.IsPhysical) | ||
175 | priority+=100; | ||
176 | } | ||
177 | return priority; | ||
178 | } | ||
179 | else | ||
180 | { | ||
181 | // Child agent. Use the normal distance method | ||
182 | Vector3 presencePos = presence.AbsolutePosition; | ||
183 | |||
184 | return Vector3.DistanceSquared(presencePos, entityPos); | ||
185 | } | ||
186 | } | ||
187 | |||
188 | return double.NaN; | ||
189 | } | ||
133 | } | 190 | } |
134 | } | 191 | } |