diff options
author | John Hurliman | 2009-10-17 18:01:22 -0700 |
---|---|---|
committer | John Hurliman | 2009-10-17 18:01:22 -0700 |
commit | fdb2a75ad357668b860fc5055e0630ef75a3ad20 (patch) | |
tree | df5e554df0215f43fa82acecef7c2df660807bdd /OpenSim/Region/Framework/Scenes/ScenePresence.cs | |
parent | Wrapped the contents of the IncomingPacketHandler loop in a try/catch statement (diff) | |
download | opensim-SC_OLD-fdb2a75ad357668b860fc5055e0630ef75a3ad20.zip opensim-SC_OLD-fdb2a75ad357668b860fc5055e0630ef75a3ad20.tar.gz opensim-SC_OLD-fdb2a75ad357668b860fc5055e0630ef75a3ad20.tar.bz2 opensim-SC_OLD-fdb2a75ad357668b860fc5055e0630ef75a3ad20.tar.xz |
Committing the second part of Jim Greensky @ Intel Lab's patch, re-prioritizing updates
Diffstat (limited to '')
-rw-r--r-- | OpenSim/Region/Framework/Scenes/ScenePresence.cs | 112 |
1 files changed, 110 insertions, 2 deletions
diff --git a/OpenSim/Region/Framework/Scenes/ScenePresence.cs b/OpenSim/Region/Framework/Scenes/ScenePresence.cs index 9d13ad4..f05c3d8 100644 --- a/OpenSim/Region/Framework/Scenes/ScenePresence.cs +++ b/OpenSim/Region/Framework/Scenes/ScenePresence.cs | |||
@@ -28,6 +28,7 @@ | |||
28 | using System; | 28 | using System; |
29 | using System.Collections.Generic; | 29 | using System.Collections.Generic; |
30 | using System.Reflection; | 30 | using System.Reflection; |
31 | using System.Timers; | ||
31 | using OpenMetaverse; | 32 | using OpenMetaverse; |
32 | using log4net; | 33 | using log4net; |
33 | using OpenSim.Framework; | 34 | using OpenSim.Framework; |
@@ -172,6 +173,11 @@ namespace OpenSim.Region.Framework.Scenes | |||
172 | 173 | ||
173 | // Position of agent's camera in world (region cordinates) | 174 | // Position of agent's camera in world (region cordinates) |
174 | protected Vector3 m_CameraCenter = Vector3.Zero; | 175 | protected Vector3 m_CameraCenter = Vector3.Zero; |
176 | protected Vector3 m_lastCameraCenter = Vector3.Zero; | ||
177 | |||
178 | protected Timer m_reprioritization_timer; | ||
179 | protected bool m_reprioritizing = false; | ||
180 | protected bool m_reprioritization_called = false; | ||
175 | 181 | ||
176 | // Use these three vectors to figure out what the agent is looking at | 182 | // Use these three vectors to figure out what the agent is looking at |
177 | // Convert it to a Matrix and/or Quaternion | 183 | // Convert it to a Matrix and/or Quaternion |
@@ -639,7 +645,14 @@ namespace OpenSim.Region.Framework.Scenes | |||
639 | 645 | ||
640 | m_scriptEngines = m_scene.RequestModuleInterfaces<IScriptModule>(); | 646 | m_scriptEngines = m_scene.RequestModuleInterfaces<IScriptModule>(); |
641 | 647 | ||
642 | AbsolutePosition = m_controllingClient.StartPos; | 648 | AbsolutePosition = posLastSignificantMove = m_CameraCenter = |
649 | m_lastCameraCenter = m_controllingClient.StartPos; | ||
650 | |||
651 | m_reprioritization_timer = new Timer(world.ReprioritizationInterval); | ||
652 | m_reprioritization_timer.Elapsed += new ElapsedEventHandler(Reprioritize); | ||
653 | m_reprioritization_timer.AutoReset = false; | ||
654 | |||
655 | |||
643 | AdjustKnownSeeds(); | 656 | AdjustKnownSeeds(); |
644 | 657 | ||
645 | TrySetMovementAnimation("STAND"); // TODO: I think, this won't send anything, as we are still a child here... | 658 | TrySetMovementAnimation("STAND"); // TODO: I think, this won't send anything, as we are still a child here... |
@@ -1219,6 +1232,11 @@ namespace OpenSim.Region.Framework.Scenes | |||
1219 | // Camera location in world. We'll need to raytrace | 1232 | // Camera location in world. We'll need to raytrace |
1220 | // from this location from time to time. | 1233 | // from this location from time to time. |
1221 | m_CameraCenter = agentData.CameraCenter; | 1234 | m_CameraCenter = agentData.CameraCenter; |
1235 | if (Vector3.Distance(m_lastCameraCenter, m_CameraCenter) >= Scene.RootReprioritizationDistance) | ||
1236 | { | ||
1237 | ReprioritizeUpdates(); | ||
1238 | m_lastCameraCenter = m_CameraCenter; | ||
1239 | } | ||
1222 | 1240 | ||
1223 | // Use these three vectors to figure out what the agent is looking at | 1241 | // Use these three vectors to figure out what the agent is looking at |
1224 | // Convert it to a Matrix and/or Quaternion | 1242 | // Convert it to a Matrix and/or Quaternion |
@@ -2823,7 +2841,7 @@ namespace OpenSim.Region.Framework.Scenes | |||
2823 | } | 2841 | } |
2824 | 2842 | ||
2825 | // Minimum Draw distance is 64 meters, the Radius of the draw distance sphere is 32m | 2843 | // Minimum Draw distance is 64 meters, the Radius of the draw distance sphere is 32m |
2826 | if (Util.GetDistanceTo(AbsolutePosition,m_LastChildAgentUpdatePosition) > 32) | 2844 | if (Util.GetDistanceTo(AbsolutePosition, m_LastChildAgentUpdatePosition) >= Scene.ChildReprioritizationDistance) |
2827 | { | 2845 | { |
2828 | ChildAgentDataUpdate cadu = new ChildAgentDataUpdate(); | 2846 | ChildAgentDataUpdate cadu = new ChildAgentDataUpdate(); |
2829 | cadu.ActiveGroupID = UUID.Zero.Guid; | 2847 | cadu.ActiveGroupID = UUID.Zero.Guid; |
@@ -3118,6 +3136,12 @@ namespace OpenSim.Region.Framework.Scenes | |||
3118 | if (cAgentData.Position != new Vector3(-1, -1, -1)) // UGH!! | 3136 | if (cAgentData.Position != new Vector3(-1, -1, -1)) // UGH!! |
3119 | m_pos = new Vector3(cAgentData.Position.X + shiftx, cAgentData.Position.Y + shifty, cAgentData.Position.Z); | 3137 | m_pos = new Vector3(cAgentData.Position.X + shiftx, cAgentData.Position.Y + shifty, cAgentData.Position.Z); |
3120 | 3138 | ||
3139 | if (Vector3.Distance(AbsolutePosition, posLastSignificantMove) >= Scene.ChildReprioritizationDistance) | ||
3140 | { | ||
3141 | posLastSignificantMove = AbsolutePosition; | ||
3142 | ReprioritizeUpdates(); | ||
3143 | } | ||
3144 | |||
3121 | // It's hard to say here.. We can't really tell where the camera position is unless it's in world cordinates from the sending region | 3145 | // It's hard to say here.. We can't really tell where the camera position is unless it's in world cordinates from the sending region |
3122 | m_CameraCenter = cAgentData.Center; | 3146 | m_CameraCenter = cAgentData.Center; |
3123 | 3147 | ||
@@ -3498,6 +3522,16 @@ namespace OpenSim.Region.Framework.Scenes | |||
3498 | { | 3522 | { |
3499 | m_knownChildRegions.Clear(); | 3523 | m_knownChildRegions.Clear(); |
3500 | } | 3524 | } |
3525 | |||
3526 | lock (m_reprioritization_timer) | ||
3527 | { | ||
3528 | m_reprioritization_timer.Enabled = false; | ||
3529 | m_reprioritization_timer.Elapsed -= new ElapsedEventHandler(Reprioritize); | ||
3530 | } | ||
3531 | // I don't get it but mono crashes when you try to dispose of this timer, | ||
3532 | // unsetting the elapsed callback should be enough to allow for cleanup however. | ||
3533 | //m_reprioritizationTimer.Dispose(); | ||
3534 | |||
3501 | m_sceneViewer.Close(); | 3535 | m_sceneViewer.Close(); |
3502 | 3536 | ||
3503 | RemoveFromPhysicalScene(); | 3537 | RemoveFromPhysicalScene(); |
@@ -3913,5 +3947,79 @@ namespace OpenSim.Region.Framework.Scenes | |||
3913 | { | 3947 | { |
3914 | return Vector3.Distance(AbsolutePosition, position); | 3948 | return Vector3.Distance(AbsolutePosition, position); |
3915 | } | 3949 | } |
3950 | |||
3951 | private double GetSOGUpdatePriority(SceneObjectGroup sog) | ||
3952 | { | ||
3953 | switch (Scene.UpdatePrioritizationScheme) | ||
3954 | { | ||
3955 | case Scene.UpdatePrioritizationSchemes.Time: | ||
3956 | throw new InvalidOperationException("UpdatePrioritizationScheme for time not supported for reprioritization"); | ||
3957 | case Scene.UpdatePrioritizationSchemes.Distance: | ||
3958 | return sog.GetPriorityByDistance((IsChildAgent) ? AbsolutePosition : CameraPosition); | ||
3959 | case Scene.UpdatePrioritizationSchemes.SimpleAngularDistance: | ||
3960 | return sog.GetPriorityBySimpleAngularDistance((IsChildAgent) ? AbsolutePosition : CameraPosition); | ||
3961 | default: | ||
3962 | throw new InvalidOperationException("UpdatePrioritizationScheme not defined"); | ||
3963 | } | ||
3964 | } | ||
3965 | |||
3966 | private double UpdatePriority(UpdatePriorityData data) | ||
3967 | { | ||
3968 | EntityBase entity; | ||
3969 | SceneObjectGroup group; | ||
3970 | |||
3971 | if (Scene.Entities.TryGetValue(data.localID, out entity)) | ||
3972 | { | ||
3973 | group = entity as SceneObjectGroup; | ||
3974 | if (group != null) | ||
3975 | return GetSOGUpdatePriority(group); | ||
3976 | |||
3977 | ScenePresence presence = entity as ScenePresence; | ||
3978 | if (presence == null) | ||
3979 | throw new InvalidOperationException("entity found is neither SceneObjectGroup nor ScenePresence"); | ||
3980 | switch (Scene.UpdatePrioritizationScheme) | ||
3981 | { | ||
3982 | case Scene.UpdatePrioritizationSchemes.Time: | ||
3983 | throw new InvalidOperationException("UpdatePrioritization for time not supported for reprioritization"); | ||
3984 | case Scene.UpdatePrioritizationSchemes.Distance: | ||
3985 | case Scene.UpdatePrioritizationSchemes.SimpleAngularDistance: | ||
3986 | return GetPriorityByDistance((IsChildAgent) ? AbsolutePosition : CameraPosition); | ||
3987 | default: | ||
3988 | throw new InvalidOperationException("UpdatePrioritizationScheme not defined"); | ||
3989 | } | ||
3990 | } | ||
3991 | else | ||
3992 | { | ||
3993 | group = Scene.SceneGraph.GetGroupByPrim(data.localID); | ||
3994 | if (group != null) | ||
3995 | return GetSOGUpdatePriority(group); | ||
3996 | } | ||
3997 | return double.NaN; | ||
3998 | } | ||
3999 | |||
4000 | private void ReprioritizeUpdates() | ||
4001 | { | ||
4002 | if (Scene.IsReprioritizationEnabled && Scene.UpdatePrioritizationScheme != Scene.UpdatePrioritizationSchemes.Time) | ||
4003 | { | ||
4004 | lock (m_reprioritization_timer) | ||
4005 | { | ||
4006 | if (!m_reprioritizing) | ||
4007 | m_reprioritization_timer.Enabled = m_reprioritizing = true; | ||
4008 | else | ||
4009 | m_reprioritization_called = true; | ||
4010 | } | ||
4011 | } | ||
4012 | } | ||
4013 | |||
4014 | private void Reprioritize(object sender, ElapsedEventArgs e) | ||
4015 | { | ||
4016 | m_controllingClient.ReprioritizeUpdates(StateUpdateTypes.All, UpdatePriority); | ||
4017 | |||
4018 | lock (m_reprioritization_timer) | ||
4019 | { | ||
4020 | m_reprioritization_timer.Enabled = m_reprioritizing = m_reprioritization_called; | ||
4021 | m_reprioritization_called = false; | ||
4022 | } | ||
4023 | } | ||
3916 | } | 4024 | } |
3917 | } | 4025 | } |