aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim
diff options
context:
space:
mode:
authorJohn Hurliman2009-10-28 23:10:16 -0700
committerJohn Hurliman2009-10-28 23:10:16 -0700
commit59eb378d16fd8a9e887560a2744cc798fef08263 (patch)
tree4bcb0d1f3b00ecbc17ee220928646aaba09d334c /OpenSim
parentAlways send a time dilation of 1.0 while we debug rubberbanding issues (diff)
downloadopensim-SC_OLD-59eb378d16fd8a9e887560a2744cc798fef08263.zip
opensim-SC_OLD-59eb378d16fd8a9e887560a2744cc798fef08263.tar.gz
opensim-SC_OLD-59eb378d16fd8a9e887560a2744cc798fef08263.tar.bz2
opensim-SC_OLD-59eb378d16fd8a9e887560a2744cc798fef08263.tar.xz
Small performance tweaks to code called by the heartbeat loop
Diffstat (limited to 'OpenSim')
-rw-r--r--OpenSim/Region/Framework/Scenes/Scene.cs60
-rw-r--r--OpenSim/Region/Framework/Scenes/SceneGraph.cs14
-rw-r--r--OpenSim/Region/Framework/Scenes/SceneObjectGroup.cs17
-rw-r--r--OpenSim/Region/Framework/Scenes/ScenePresence.cs79
4 files changed, 53 insertions, 117 deletions
diff --git a/OpenSim/Region/Framework/Scenes/Scene.cs b/OpenSim/Region/Framework/Scenes/Scene.cs
index 8b0431c..78ccb55 100644
--- a/OpenSim/Region/Framework/Scenes/Scene.cs
+++ b/OpenSim/Region/Framework/Scenes/Scene.cs
@@ -257,7 +257,7 @@ namespace OpenSim.Region.Framework.Scenes
257 // Central Update Loop 257 // Central Update Loop
258 258
259 protected int m_fps = 10; 259 protected int m_fps = 10;
260 protected int m_frame; 260 protected uint m_frame;
261 protected float m_timespan = 0.089f; 261 protected float m_timespan = 0.089f;
262 protected DateTime m_lastupdate = DateTime.UtcNow; 262 protected DateTime m_lastupdate = DateTime.UtcNow;
263 263
@@ -1018,36 +1018,24 @@ namespace OpenSim.Region.Framework.Scenes
1018 /// </summary> 1018 /// </summary>
1019 public override void Update() 1019 public override void Update()
1020 { 1020 {
1021 int maintc = 0; 1021 float physicsFPS;
1022 int maintc;
1023
1022 while (!shuttingdown) 1024 while (!shuttingdown)
1023 { 1025 {
1024//#if DEBUG
1025// int w = 0, io = 0;
1026// ThreadPool.GetAvailableThreads(out w, out io);
1027// if ((w < 10) || (io < 10))
1028// m_log.DebugFormat("[WARNING]: ThreadPool reaching exhaustion. workers = {0}; io = {1}", w, io);
1029//#endif
1030 maintc = Environment.TickCount;
1031
1032 TimeSpan SinceLastFrame = DateTime.UtcNow - m_lastupdate; 1026 TimeSpan SinceLastFrame = DateTime.UtcNow - m_lastupdate;
1033 float physicsFPS = 0; 1027 physicsFPS = 0f;
1034 1028
1035 frameMS = Environment.TickCount; 1029 maintc = maintc = frameMS = otherMS = Environment.TickCount;
1030
1031 // Increment the frame counter
1032 ++m_frame;
1036 1033
1037 try 1034 try
1038 { 1035 {
1039 // Increment the frame counter
1040 m_frame++;
1041
1042 // Loop it
1043 if (m_frame == Int32.MaxValue)
1044 m_frame = 0;
1045
1046 otherMS = Environment.TickCount;
1047
1048 // Check if any objects have reached their targets 1036 // Check if any objects have reached their targets
1049 CheckAtTargets(); 1037 CheckAtTargets();
1050 1038
1051 // Update SceneObjectGroups that have scheduled themselves for updates 1039 // Update SceneObjectGroups that have scheduled themselves for updates
1052 // Objects queue their updates onto all scene presences 1040 // Objects queue their updates onto all scene presences
1053 if (m_frame % m_update_objects == 0) 1041 if (m_frame % m_update_objects == 0)
@@ -1067,13 +1055,13 @@ namespace OpenSim.Region.Framework.Scenes
1067 m_sceneGraph.UpdateScenePresenceMovement(); 1055 m_sceneGraph.UpdateScenePresenceMovement();
1068 1056
1069 physicsMS = Environment.TickCount; 1057 physicsMS = Environment.TickCount;
1070 if ((m_frame % m_update_physics == 0) && m_physics_enabled) 1058 if (m_frame % m_update_physics == 0)
1071 physicsFPS = m_sceneGraph.UpdatePhysics( 1059 {
1072 Math.Max(SinceLastFrame.TotalSeconds, m_timespan) 1060 if (m_physics_enabled)
1073 ); 1061 physicsFPS = m_sceneGraph.UpdatePhysics(Math.Max(SinceLastFrame.TotalSeconds, m_timespan));
1074 if (m_frame % m_update_physics == 0 && SynchronizeScene != null) 1062 if (SynchronizeScene != null)
1075 SynchronizeScene(this); 1063 SynchronizeScene(this);
1076 1064 }
1077 physicsMS = Environment.TickCount - physicsMS; 1065 physicsMS = Environment.TickCount - physicsMS;
1078 physicsMS += physicsMS2; 1066 physicsMS += physicsMS2;
1079 1067
@@ -1095,25 +1083,27 @@ namespace OpenSim.Region.Framework.Scenes
1095 if (m_frame % m_update_land == 0) 1083 if (m_frame % m_update_land == 0)
1096 UpdateLand(); 1084 UpdateLand();
1097 1085
1098 otherMS = Environment.TickCount - otherMS; 1086 int tickCount = Environment.TickCount;
1087 otherMS = tickCount - otherMS;
1088 frameMS = tickCount - frameMS;
1089
1099 // if (m_frame%m_update_avatars == 0) 1090 // if (m_frame%m_update_avatars == 0)
1100 // UpdateInWorldTime(); 1091 // UpdateInWorldTime();
1101 StatsReporter.AddPhysicsFPS(physicsFPS); 1092 StatsReporter.AddPhysicsFPS(physicsFPS);
1102 StatsReporter.AddTimeDilation(TimeDilation); 1093 StatsReporter.AddTimeDilation(TimeDilation);
1103 StatsReporter.AddFPS(1); 1094 StatsReporter.AddFPS(1);
1104 StatsReporter.AddInPackets(0);
1105 StatsReporter.SetRootAgents(m_sceneGraph.GetRootAgentCount()); 1095 StatsReporter.SetRootAgents(m_sceneGraph.GetRootAgentCount());
1106 StatsReporter.SetChildAgents(m_sceneGraph.GetChildAgentCount()); 1096 StatsReporter.SetChildAgents(m_sceneGraph.GetChildAgentCount());
1107 StatsReporter.SetObjects(m_sceneGraph.GetTotalObjectsCount()); 1097 StatsReporter.SetObjects(m_sceneGraph.GetTotalObjectsCount());
1108 StatsReporter.SetActiveObjects(m_sceneGraph.GetActiveObjectsCount()); 1098 StatsReporter.SetActiveObjects(m_sceneGraph.GetActiveObjectsCount());
1109 frameMS = Environment.TickCount - frameMS;
1110 StatsReporter.addFrameMS(frameMS); 1099 StatsReporter.addFrameMS(frameMS);
1111 StatsReporter.addPhysicsMS(physicsMS); 1100 StatsReporter.addPhysicsMS(physicsMS);
1112 StatsReporter.addOtherMS(otherMS); 1101 StatsReporter.addOtherMS(otherMS);
1113 StatsReporter.SetActiveScripts(m_sceneGraph.GetActiveScriptsCount()); 1102 StatsReporter.SetActiveScripts(m_sceneGraph.GetActiveScriptsCount());
1114 StatsReporter.addScriptLines(m_sceneGraph.GetScriptLPS()); 1103 StatsReporter.addScriptLines(m_sceneGraph.GetScriptLPS());
1115 } 1104 }
1116 if (loginsdisabled && (m_frame > 20)) 1105
1106 if (loginsdisabled && m_frame > 20)
1117 { 1107 {
1118 // In 99.9% of cases it is a bad idea to manually force garbage collection. However, 1108 // In 99.9% of cases it is a bad idea to manually force garbage collection. However,
1119 // this is a rare case where we know we have just went through a long cycle of heap 1109 // this is a rare case where we know we have just went through a long cycle of heap
@@ -1176,9 +1166,9 @@ namespace OpenSim.Region.Framework.Scenes
1176 { 1166 {
1177 lock (m_groupsWithTargets) 1167 lock (m_groupsWithTargets)
1178 { 1168 {
1179 foreach (KeyValuePair<UUID, SceneObjectGroup> kvp in m_groupsWithTargets) 1169 foreach (SceneObjectGroup entry in m_groupsWithTargets.Values)
1180 { 1170 {
1181 kvp.Value.checkAtTargets(); 1171 entry.checkAtTargets();
1182 } 1172 }
1183 } 1173 }
1184 } 1174 }
diff --git a/OpenSim/Region/Framework/Scenes/SceneGraph.cs b/OpenSim/Region/Framework/Scenes/SceneGraph.cs
index db055f9..2fdb48d 100644
--- a/OpenSim/Region/Framework/Scenes/SceneGraph.cs
+++ b/OpenSim/Region/Framework/Scenes/SceneGraph.cs
@@ -369,26 +369,30 @@ namespace OpenSim.Region.Framework.Scenes
369 /// </summary> 369 /// </summary>
370 protected internal void UpdateObjectGroups() 370 protected internal void UpdateObjectGroups()
371 { 371 {
372 Dictionary<UUID, SceneObjectGroup> updates; 372 List<SceneObjectGroup> updates;
373
373 // Some updates add more updates to the updateList. 374 // Some updates add more updates to the updateList.
374 // Get the current list of updates and clear the list before iterating 375 // Get the current list of updates and clear the list before iterating
375 lock (m_updateList) 376 lock (m_updateList)
376 { 377 {
377 updates = new Dictionary<UUID, SceneObjectGroup>(m_updateList); 378 updates = new List<SceneObjectGroup>(m_updateList.Values);
378 m_updateList.Clear(); 379 m_updateList.Clear();
379 } 380 }
381
380 // Go through all updates 382 // Go through all updates
381 foreach (KeyValuePair<UUID, SceneObjectGroup> kvp in updates) 383 for (int i = 0; i < updates.Count; i++)
382 { 384 {
385 SceneObjectGroup sog = updates[i];
386
383 // Don't abort the whole update if one entity happens to give us an exception. 387 // Don't abort the whole update if one entity happens to give us an exception.
384 try 388 try
385 { 389 {
386 kvp.Value.Update(); 390 sog.Update();
387 } 391 }
388 catch (Exception e) 392 catch (Exception e)
389 { 393 {
390 m_log.ErrorFormat( 394 m_log.ErrorFormat(
391 "[INNER SCENE]: Failed to update {0}, {1} - {2}", kvp.Value.Name, kvp.Value.UUID, e); 395 "[INNER SCENE]: Failed to update {0}, {1} - {2}", sog.Name, sog.UUID, e);
392 } 396 }
393 } 397 }
394 } 398 }
diff --git a/OpenSim/Region/Framework/Scenes/SceneObjectGroup.cs b/OpenSim/Region/Framework/Scenes/SceneObjectGroup.cs
index dbb06f8..0b752c9 100644
--- a/OpenSim/Region/Framework/Scenes/SceneObjectGroup.cs
+++ b/OpenSim/Region/Framework/Scenes/SceneObjectGroup.cs
@@ -1857,28 +1857,15 @@ namespace OpenSim.Region.Framework.Scenes
1857 { 1857 {
1858 bool UsePhysics = ((RootPart.Flags & PrimFlags.Physics) != 0); 1858 bool UsePhysics = ((RootPart.Flags & PrimFlags.Physics) != 0);
1859 1859
1860 //if (IsAttachment) 1860 if (UsePhysics && !AbsolutePosition.ApproxEquals(lastPhysGroupPos, 0.02f))
1861 //{
1862 //foreach (SceneObjectPart part in m_parts.Values)
1863 //{
1864 //part.SendScheduledUpdates();
1865 //}
1866 //return;
1867 //}
1868
1869 if (UsePhysics && Util.DistanceLessThan(lastPhysGroupPos, AbsolutePosition, 0.02))
1870 { 1861 {
1871 m_rootPart.UpdateFlag = 1; 1862 m_rootPart.UpdateFlag = 1;
1872 lastPhysGroupPos = AbsolutePosition; 1863 lastPhysGroupPos = AbsolutePosition;
1873 } 1864 }
1874 1865
1875 if (UsePhysics && ((Math.Abs(lastPhysGroupRot.W - GroupRotation.W) > 0.1) 1866 if (UsePhysics && !GroupRotation.ApproxEquals(lastPhysGroupRot, 0.1f))
1876 || (Math.Abs(lastPhysGroupRot.X - GroupRotation.X) > 0.1)
1877 || (Math.Abs(lastPhysGroupRot.Y - GroupRotation.Y) > 0.1)
1878 || (Math.Abs(lastPhysGroupRot.Z - GroupRotation.Z) > 0.1)))
1879 { 1867 {
1880 m_rootPart.UpdateFlag = 1; 1868 m_rootPart.UpdateFlag = 1;
1881
1882 lastPhysGroupRot = GroupRotation; 1869 lastPhysGroupRot = GroupRotation;
1883 } 1870 }
1884 1871
diff --git a/OpenSim/Region/Framework/Scenes/ScenePresence.cs b/OpenSim/Region/Framework/Scenes/ScenePresence.cs
index 63c979f..1ea4585 100644
--- a/OpenSim/Region/Framework/Scenes/ScenePresence.cs
+++ b/OpenSim/Region/Framework/Scenes/ScenePresence.cs
@@ -76,8 +76,7 @@ namespace OpenSim.Region.Framework.Scenes
76 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); 76 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
77 77
78 private static readonly byte[] BAKE_INDICES = new byte[] { 8, 9, 10, 11, 19, 20 }; 78 private static readonly byte[] BAKE_INDICES = new byte[] { 8, 9, 10, 11, 19, 20 };
79 79 public static readonly byte[] DEFAULT_TEXTURE = AvatarAppearance.GetDefaultTexture().GetBytes();
80 public static byte[] DefaultTexture;
81 80
82 public UUID currentParcelUUID = UUID.Zero; 81 public UUID currentParcelUUID = UUID.Zero;
83 82
@@ -100,9 +99,9 @@ namespace OpenSim.Region.Framework.Scenes
100 99
101 private bool m_updateflag; 100 private bool m_updateflag;
102 private byte m_movementflag; 101 private byte m_movementflag;
103 private readonly List<NewForce> m_forcesList = new List<NewForce>(); 102 private Vector3? m_forceToApply;
104 private uint m_requestedSitTargetID; 103 private uint m_requestedSitTargetID;
105 private UUID m_requestedSitTargetUUID = UUID.Zero; 104 private UUID m_requestedSitTargetUUID;
106 private SendCourseLocationsMethod m_sendCourseLocationsMethod; 105 private SendCourseLocationsMethod m_sendCourseLocationsMethod;
107 106
108 private bool m_startAnimationSet; 107 private bool m_startAnimationSet;
@@ -456,12 +455,9 @@ namespace OpenSim.Region.Framework.Scenes
456 { 455 {
457 get 456 get
458 { 457 {
459 if (m_physicsActor != null) 458 PhysicsActor actor = m_physicsActor;
460 { 459 if (actor != null)
461 m_velocity.X = m_physicsActor.Velocity.X; 460 m_velocity = m_physicsActor.Velocity;
462 m_velocity.Y = m_physicsActor.Velocity.Y;
463 m_velocity.Z = m_physicsActor.Velocity.Z;
464 }
465 461
466 return m_velocity; 462 return m_velocity;
467 } 463 }
@@ -2278,7 +2274,7 @@ namespace OpenSim.Region.Framework.Scenes
2278 { 2274 {
2279 if (m_isChildAgent) 2275 if (m_isChildAgent)
2280 { 2276 {
2281 m_log.Debug("DEBUG: AddNewMovement: child agent, Making root agent!"); 2277 m_log.Debug("[SCENEPRESENCE]: AddNewMovement() called on child agent, making root agent!");
2282 2278
2283 // we have to reset the user's child agent connections. 2279 // we have to reset the user's child agent connections.
2284 // Likely, here they've lost the eventqueue for other regions so border 2280 // Likely, here they've lost the eventqueue for other regions so border
@@ -2287,7 +2283,7 @@ namespace OpenSim.Region.Framework.Scenes
2287 List<ulong> regions = new List<ulong>(KnownChildRegionHandles); 2283 List<ulong> regions = new List<ulong>(KnownChildRegionHandles);
2288 regions.Remove(m_scene.RegionInfo.RegionHandle); 2284 regions.Remove(m_scene.RegionInfo.RegionHandle);
2289 2285
2290 MakeRootAgent(new Vector3(127, 127, 127), true); 2286 MakeRootAgent(new Vector3(127f, 127f, 127f), true);
2291 2287
2292 // Async command 2288 // Async command
2293 if (m_scene.SceneGridService != null) 2289 if (m_scene.SceneGridService != null)
@@ -2299,28 +2295,24 @@ namespace OpenSim.Region.Framework.Scenes
2299 System.Threading.Thread.Sleep(500); 2295 System.Threading.Thread.Sleep(500);
2300 } 2296 }
2301 2297
2302
2303 if (m_scene.SceneGridService != null) 2298 if (m_scene.SceneGridService != null)
2304 { 2299 {
2305 m_scene.SceneGridService.EnableNeighbourChildAgents(this, new List<RegionInfo>()); 2300 m_scene.SceneGridService.EnableNeighbourChildAgents(this, new List<RegionInfo>());
2306 } 2301 }
2307 2302
2308
2309
2310 return; 2303 return;
2311 } 2304 }
2312 2305
2313 m_perfMonMS = Environment.TickCount; 2306 m_perfMonMS = Environment.TickCount;
2314 2307
2315 m_rotation = rotation; 2308 m_rotation = rotation;
2316 NewForce newVelocity = new NewForce();
2317 Vector3 direc = vec * rotation; 2309 Vector3 direc = vec * rotation;
2318 direc.Normalize(); 2310 direc.Normalize();
2319 2311
2320 direc *= 0.03f * 128f * m_speedModifier; 2312 direc *= 0.03f * 128f * m_speedModifier;
2321 if (m_physicsActor.Flying) 2313 if (m_physicsActor.Flying)
2322 { 2314 {
2323 direc *= 4; 2315 direc *= 4.0f;
2324 //bool controlland = (((m_AgentControlFlags & (uint)AgentManager.ControlFlags.AGENT_CONTROL_UP_NEG) != 0) || ((m_AgentControlFlags & (uint)AgentManager.ControlFlags.AGENT_CONTROL_NUDGE_UP_NEG) != 0)); 2316 //bool controlland = (((m_AgentControlFlags & (uint)AgentManager.ControlFlags.AGENT_CONTROL_UP_NEG) != 0) || ((m_AgentControlFlags & (uint)AgentManager.ControlFlags.AGENT_CONTROL_NUDGE_UP_NEG) != 0));
2325 //bool colliding = (m_physicsActor.IsColliding==true); 2317 //bool colliding = (m_physicsActor.IsColliding==true);
2326 //if (controlland) 2318 //if (controlland)
@@ -2348,10 +2340,8 @@ namespace OpenSim.Region.Framework.Scenes
2348 } 2340 }
2349 } 2341 }
2350 2342
2351 newVelocity.X = direc.X; 2343 // TODO: Add the force instead of only setting it to support multiple forces per frame?
2352 newVelocity.Y = direc.Y; 2344 m_forceToApply = direc;
2353 newVelocity.Z = direc.Z;
2354 m_forcesList.Add(newVelocity);
2355 2345
2356 m_scene.StatsReporter.AddAgentTime(Environment.TickCount - m_perfMonMS); 2346 m_scene.StatsReporter.AddAgentTime(Environment.TickCount - m_perfMonMS);
2357 } 2347 }
@@ -3298,47 +3288,18 @@ namespace OpenSim.Region.Framework.Scenes
3298 /// </summary> 3288 /// </summary>
3299 public override void UpdateMovement() 3289 public override void UpdateMovement()
3300 { 3290 {
3301 lock (m_forcesList) 3291 if (m_forceToApply.HasValue)
3302 { 3292 {
3303 if (m_forcesList.Count > 0) 3293 Vector3 force = m_forceToApply.Value;
3304 {
3305 //we are only interested in the last velocity added to the list [Although they are called forces, they are actually velocities]
3306 NewForce force = m_forcesList[m_forcesList.Count - 1];
3307 3294
3308 m_updateflag = true; 3295 m_updateflag = true;
3309 try 3296 movementvector = force;
3310 { 3297 Velocity = force;
3311 movementvector.X = force.X;
3312 movementvector.Y = force.Y;
3313 movementvector.Z = force.Z;
3314 Velocity = movementvector;
3315 }
3316 catch (NullReferenceException)
3317 {
3318 // Under extreme load, this returns a NullReference Exception that we can ignore.
3319 // Ignoring this causes no movement to be sent to the physics engine...
3320 // which when the scene is moving at 1 frame every 10 seconds, it doesn't really matter!
3321 }
3322 3298
3323 m_forcesList.Clear(); 3299 m_forceToApply = null;
3324 }
3325 } 3300 }
3326 } 3301 }
3327 3302
3328 static ScenePresence()
3329 {
3330 Primitive.TextureEntry textu = AvatarAppearance.GetDefaultTexture();
3331 DefaultTexture = textu.GetBytes();
3332
3333 }
3334
3335 public class NewForce
3336 {
3337 public float X;
3338 public float Y;
3339 public float Z;
3340 }
3341
3342 public override void SetText(string text, Vector3 color, double alpha) 3303 public override void SetText(string text, Vector3 color, double alpha)
3343 { 3304 {
3344 throw new Exception("Can't set Text on avatar."); 3305 throw new Exception("Can't set Text on avatar.");
@@ -3349,7 +3310,6 @@ namespace OpenSim.Region.Framework.Scenes
3349 /// </summary> 3310 /// </summary>
3350 public void AddToPhysicalScene(bool isFlying) 3311 public void AddToPhysicalScene(bool isFlying)
3351 { 3312 {
3352
3353 PhysicsScene scene = m_scene.PhysicsScene; 3313 PhysicsScene scene = m_scene.PhysicsScene;
3354 3314
3355 Vector3 pVec = AbsolutePosition; 3315 Vector3 pVec = AbsolutePosition;
@@ -3478,11 +3438,6 @@ namespace OpenSim.Region.Framework.Scenes
3478 3438
3479 public ScenePresence() 3439 public ScenePresence()
3480 { 3440 {
3481 if (DefaultTexture == null)
3482 {
3483 Primitive.TextureEntry textu = AvatarAppearance.GetDefaultTexture();
3484 DefaultTexture = textu.GetBytes();
3485 }
3486 m_sendCourseLocationsMethod = SendCoarseLocationsDefault; 3441 m_sendCourseLocationsMethod = SendCoarseLocationsDefault;
3487 CreateSceneViewer(); 3442 CreateSceneViewer();
3488 } 3443 }