aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/Framework/Scenes/ScenePresence.cs
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Region/Framework/Scenes/ScenePresence.cs')
-rw-r--r--OpenSim/Region/Framework/Scenes/ScenePresence.cs299
1 files changed, 190 insertions, 109 deletions
diff --git a/OpenSim/Region/Framework/Scenes/ScenePresence.cs b/OpenSim/Region/Framework/Scenes/ScenePresence.cs
index c25fa55..d7113bf 100644
--- a/OpenSim/Region/Framework/Scenes/ScenePresence.cs
+++ b/OpenSim/Region/Framework/Scenes/ScenePresence.cs
@@ -28,6 +28,7 @@
28using System; 28using System;
29using System.Collections.Generic; 29using System.Collections.Generic;
30using System.Reflection; 30using System.Reflection;
31using System.Timers;
31using OpenMetaverse; 32using OpenMetaverse;
32using log4net; 33using log4net;
33using OpenSim.Framework; 34using OpenSim.Framework;
@@ -127,8 +128,6 @@ namespace OpenSim.Region.Framework.Scenes
127 128
128 private bool m_setAlwaysRun; 129 private bool m_setAlwaysRun;
129 130
130 private bool m_updatesAllowed = true;
131 private List<AgentUpdateArgs> m_agentUpdates = new List<AgentUpdateArgs>();
132 private string m_movementAnimation = "DEFAULT"; 131 private string m_movementAnimation = "DEFAULT";
133 private long m_animPersistUntil = 0; 132 private long m_animPersistUntil = 0;
134 private bool m_allowFalling = false; 133 private bool m_allowFalling = false;
@@ -172,6 +171,11 @@ namespace OpenSim.Region.Framework.Scenes
172 171
173 // Position of agent's camera in world (region cordinates) 172 // Position of agent's camera in world (region cordinates)
174 protected Vector3 m_CameraCenter = Vector3.Zero; 173 protected Vector3 m_CameraCenter = Vector3.Zero;
174 protected Vector3 m_lastCameraCenter = Vector3.Zero;
175
176 protected Timer m_reprioritization_timer;
177 protected bool m_reprioritizing = false;
178 protected bool m_reprioritization_called = false;
175 179
176 // Use these three vectors to figure out what the agent is looking at 180 // Use these three vectors to figure out what the agent is looking at
177 // Convert it to a Matrix and/or Quaternion 181 // Convert it to a Matrix and/or Quaternion
@@ -403,12 +407,6 @@ namespace OpenSim.Region.Framework.Scenes
403 set { m_parentPosition = value; } 407 set { m_parentPosition = value; }
404 } 408 }
405 409
406 public int MaxPrimsPerFrame
407 {
408 get { return m_sceneViewer.MaxPrimsPerFrame; }
409 set { m_sceneViewer.MaxPrimsPerFrame = value; }
410 }
411
412 /// <summary> 410 /// <summary>
413 /// Absolute position of this avatar in 'region cordinates' 411 /// Absolute position of this avatar in 'region cordinates'
414 /// </summary> 412 /// </summary>
@@ -645,7 +643,14 @@ namespace OpenSim.Region.Framework.Scenes
645 643
646 m_scriptEngines = m_scene.RequestModuleInterfaces<IScriptModule>(); 644 m_scriptEngines = m_scene.RequestModuleInterfaces<IScriptModule>();
647 645
648 AbsolutePosition = m_controllingClient.StartPos; 646 AbsolutePosition = posLastSignificantMove = m_CameraCenter =
647 m_lastCameraCenter = m_controllingClient.StartPos;
648
649 m_reprioritization_timer = new Timer(world.ReprioritizationInterval);
650 m_reprioritization_timer.Elapsed += new ElapsedEventHandler(Reprioritize);
651 m_reprioritization_timer.AutoReset = false;
652
653
649 AdjustKnownSeeds(); 654 AdjustKnownSeeds();
650 655
651 TrySetMovementAnimation("STAND"); // TODO: I think, this won't send anything, as we are still a child here... 656 TrySetMovementAnimation("STAND"); // TODO: I think, this won't send anything, as we are still a child here...
@@ -1083,34 +1088,6 @@ namespace OpenSim.Region.Framework.Scenes
1083 1088
1084 } 1089 }
1085 1090
1086 // These methods allow to queue up agent updates (like key presses)
1087 // until all attachment scripts are running and the animations from
1088 // AgentDataUpdate have been started. It is essential for combat
1089 // devices, weapons and AOs that keypresses are not processed
1090 // until scripts that are potentially interested in them are
1091 // up and running and that animations a script knows to be running
1092 // from before a crossing are running again
1093 //
1094 public void LockAgentUpdates()
1095 {
1096 m_updatesAllowed = false;
1097 }
1098
1099 public void UnlockAgentUpdates()
1100 {
1101 lock (m_agentUpdates)
1102 {
1103 if (m_updatesAllowed == false)
1104 {
1105 foreach (AgentUpdateArgs a in m_agentUpdates)
1106 RealHandleAgentUpdate(ControllingClient, a);
1107 m_agentUpdates.Clear();
1108 m_updatesAllowed = true;
1109 }
1110 }
1111 }
1112
1113
1114 /// <summary> 1091 /// <summary>
1115 /// Callback for the Camera view block check. Gets called with the results of the camera view block test 1092 /// Callback for the Camera view block check. Gets called with the results of the camera view block test
1116 /// hitYN is true when there's something in the way. 1093 /// hitYN is true when there's something in the way.
@@ -1148,43 +1125,30 @@ namespace OpenSim.Region.Framework.Scenes
1148 } 1125 }
1149 } 1126 }
1150 1127
1128 Array m_dirControlFlags = Enum.GetValues(typeof(Dir_ControlFlags));
1129
1151 /// <summary> 1130 /// <summary>
1152 /// This is the event handler for client movement. If a client is moving, this event is triggering. 1131 /// This is the event handler for client movement. If a client is moving, this event is triggering.
1153 /// </summary> 1132 /// </summary>
1154 public void HandleAgentUpdate(IClientAPI remoteClient, AgentUpdateArgs agentData) 1133 public void HandleAgentUpdate(IClientAPI remoteClient, AgentUpdateArgs agentData)
1155 { 1134 {
1156 lock (m_agentUpdates)
1157 {
1158 if (m_updatesAllowed)
1159 {
1160 RealHandleAgentUpdate(remoteClient, agentData);
1161 return;
1162 }
1163
1164 m_agentUpdates.Add(agentData);
1165 }
1166 }
1167
1168 private void RealHandleAgentUpdate(IClientAPI remoteClient, AgentUpdateArgs agentData)
1169 {
1170 //if (m_isChildAgent) 1135 //if (m_isChildAgent)
1171 //{ 1136 //{
1172 // // m_log.Debug("DEBUG: HandleAgentUpdate: child agent"); 1137 // // m_log.Debug("DEBUG: HandleAgentUpdate: child agent");
1173 // return; 1138 // return;
1174 //} 1139 //}
1175 1140
1176 1141 m_perfMonMS = Environment.TickCount;
1177 m_movementUpdateCount++;
1178 if (m_movementUpdateCount >= int.MaxValue)
1179 m_movementUpdateCount = 1;
1180 1142
1143 ++m_movementUpdateCount;
1144 if (m_movementUpdateCount < 1)
1145 m_movementUpdateCount = 1;
1181 1146
1182 // Must check for standing up even when PhysicsActor is null, 1147 // Must check for standing up even when PhysicsActor is null,
1183 // since sitting currently removes avatar from physical scene 1148 // since sitting currently removes avatar from physical scene
1184 //m_log.Debug("agentPos:" + AbsolutePosition.ToString()); 1149 //m_log.Debug("agentPos:" + AbsolutePosition.ToString());
1185 1150
1186 // This is irritating. Really. 1151 // This is irritating. Really.
1187
1188 if (!AbsolutePosition.IsFinite()) 1152 if (!AbsolutePosition.IsFinite())
1189 { 1153 {
1190 RemoveFromPhysicalScene(); 1154 RemoveFromPhysicalScene();
@@ -1205,19 +1169,17 @@ namespace OpenSim.Region.Framework.Scenes
1205 { 1169 {
1206 m_LastFinitePos = m_pos; 1170 m_LastFinitePos = m_pos;
1207 } 1171 }
1208 //m_physicsActor.AddForce(new PhysicsVector(999999999, 99999999, 999999999999999), true);
1209 1172
1173 //m_physicsActor.AddForce(new PhysicsVector(999999999, 99999999, 999999999999999), true);
1210 1174
1211 //ILandObject land = LandChannel.GetLandObject(agent.startpos.X, agent.startpos.Y); 1175 //ILandObject land = LandChannel.GetLandObject(agent.startpos.X, agent.startpos.Y);
1212 //if (land != null) 1176 //if (land != null)
1213 //{ 1177 //{
1214 //if (land.landData.landingType == (byte)1 && land.landData.userLocation != Vector3.Zero) 1178 //if (land.landData.landingType == (byte)1 && land.landData.userLocation != Vector3.Zero)
1215 //{ 1179 //{
1216 // agent.startpos = land.landData.userLocation; 1180 // agent.startpos = land.landData.userLocation;
1217 //} 1181 //}
1218 //} 1182 //}
1219
1220 m_perfMonMS = Environment.TickCount;
1221 1183
1222 uint flags = agentData.ControlFlags; 1184 uint flags = agentData.ControlFlags;
1223 Quaternion bodyRotation = agentData.BodyRotation; 1185 Quaternion bodyRotation = agentData.BodyRotation;
@@ -1225,6 +1187,11 @@ namespace OpenSim.Region.Framework.Scenes
1225 // Camera location in world. We'll need to raytrace 1187 // Camera location in world. We'll need to raytrace
1226 // from this location from time to time. 1188 // from this location from time to time.
1227 m_CameraCenter = agentData.CameraCenter; 1189 m_CameraCenter = agentData.CameraCenter;
1190 if (Vector3.Distance(m_lastCameraCenter, m_CameraCenter) >= Scene.RootReprioritizationDistance)
1191 {
1192 ReprioritizeUpdates();
1193 m_lastCameraCenter = m_CameraCenter;
1194 }
1228 1195
1229 // Use these three vectors to figure out what the agent is looking at 1196 // Use these three vectors to figure out what the agent is looking at
1230 // Convert it to a Matrix and/or Quaternion 1197 // Convert it to a Matrix and/or Quaternion
@@ -1235,7 +1202,7 @@ namespace OpenSim.Region.Framework.Scenes
1235 // The Agent's Draw distance setting 1202 // The Agent's Draw distance setting
1236 m_DrawDistance = agentData.Far; 1203 m_DrawDistance = agentData.Far;
1237 1204
1238 if ((flags & (uint) AgentManager.ControlFlags.AGENT_CONTROL_STAND_UP) != 0) 1205 if ((flags & (uint)AgentManager.ControlFlags.AGENT_CONTROL_STAND_UP) != 0)
1239 { 1206 {
1240 StandUp(); 1207 StandUp();
1241 } 1208 }
@@ -1243,14 +1210,13 @@ namespace OpenSim.Region.Framework.Scenes
1243 // Check if Client has camera in 'follow cam' or 'build' mode. 1210 // Check if Client has camera in 'follow cam' or 'build' mode.
1244 Vector3 camdif = (Vector3.One * m_bodyRot - Vector3.One * CameraRotation); 1211 Vector3 camdif = (Vector3.One * m_bodyRot - Vector3.One * CameraRotation);
1245 1212
1246 m_followCamAuto = ((m_CameraUpAxis.Z > 0.959f && m_CameraUpAxis.Z < 0.98f) 1213 m_followCamAuto = ((m_CameraUpAxis.Z > 0.959f && m_CameraUpAxis.Z < 0.98f)
1247 && (Math.Abs(camdif.X) < 0.4f && Math.Abs(camdif.Y) < 0.4f)) ? true : false; 1214 && (Math.Abs(camdif.X) < 0.4f && Math.Abs(camdif.Y) < 0.4f)) ? true : false;
1248 1215
1249 //m_log.DebugFormat("[FollowCam]: {0}", m_followCamAuto); 1216 //m_log.DebugFormat("[FollowCam]: {0}", m_followCamAuto);
1250 // Raycast from the avatar's head to the camera to see if there's anything blocking the view 1217 // Raycast from the avatar's head to the camera to see if there's anything blocking the view
1251 if ((m_movementUpdateCount % NumMovementsBetweenRayCast) == 0 && m_scene.PhysicsScene.SupportsRayCast()) 1218 if ((m_movementUpdateCount % NumMovementsBetweenRayCast) == 0 && m_scene.PhysicsScene.SupportsRayCast())
1252 { 1219 {
1253
1254 if (m_followCamAuto) 1220 if (m_followCamAuto)
1255 { 1221 {
1256 Vector3 headadjustment = new Vector3(0, 0, 0.3f); 1222 Vector3 headadjustment = new Vector3(0, 0, 0.3f);
@@ -1258,24 +1224,18 @@ namespace OpenSim.Region.Framework.Scenes
1258 } 1224 }
1259 } 1225 }
1260 1226
1261 m_mouseLook = (flags & (uint) AgentManager.ControlFlags.AGENT_CONTROL_MOUSELOOK) != 0; 1227 m_mouseLook = (flags & (uint)AgentManager.ControlFlags.AGENT_CONTROL_MOUSELOOK) != 0;
1262
1263
1264
1265 m_leftButtonDown = (flags & (uint)AgentManager.ControlFlags.AGENT_CONTROL_LBUTTON_DOWN) != 0; 1228 m_leftButtonDown = (flags & (uint)AgentManager.ControlFlags.AGENT_CONTROL_LBUTTON_DOWN) != 0;
1266 1229
1267
1268
1269 lock (scriptedcontrols) 1230 lock (scriptedcontrols)
1270 { 1231 {
1271 if (scriptedcontrols.Count > 0) 1232 if (scriptedcontrols.Count > 0)
1272 { 1233 {
1273 SendControlToScripts(flags); 1234 SendControlToScripts(flags);
1274 flags = RemoveIgnoredControls(flags, IgnoredControls); 1235 flags = RemoveIgnoredControls(flags, IgnoredControls);
1275
1276 } 1236 }
1277 } 1237 }
1278 1238
1279 if (PhysicsActor == null) 1239 if (PhysicsActor == null)
1280 { 1240 {
1281 return; 1241 return;
@@ -1284,7 +1244,7 @@ namespace OpenSim.Region.Framework.Scenes
1284 if (m_autopilotMoving) 1244 if (m_autopilotMoving)
1285 CheckAtSitTarget(); 1245 CheckAtSitTarget();
1286 1246
1287 if ((flags & (uint) AgentManager.ControlFlags.AGENT_CONTROL_SIT_ON_GROUND) != 0) 1247 if ((flags & (uint)AgentManager.ControlFlags.AGENT_CONTROL_SIT_ON_GROUND) != 0)
1288 { 1248 {
1289 // TODO: This doesn't prevent the user from walking yet. 1249 // TODO: This doesn't prevent the user from walking yet.
1290 // Setting parent ID would fix this, if we knew what value 1250 // Setting parent ID would fix this, if we knew what value
@@ -1317,13 +1277,13 @@ namespace OpenSim.Region.Framework.Scenes
1317 PhysicsActor.Flying = false; 1277 PhysicsActor.Flying = false;
1318 else 1278 else
1319 PhysicsActor.Flying = ((flags & (uint)AgentManager.ControlFlags.AGENT_CONTROL_FLY) != 0); 1279 PhysicsActor.Flying = ((flags & (uint)AgentManager.ControlFlags.AGENT_CONTROL_FLY) != 0);
1320 1280
1321 if (PhysicsActor.Flying != oldflying) 1281 if (PhysicsActor.Flying != oldflying)
1322 { 1282 {
1323 update_movementflag = true; 1283 update_movementflag = true;
1324 } 1284 }
1325 } 1285 }
1326 1286
1327 if (q != m_bodyRot) 1287 if (q != m_bodyRot)
1328 { 1288 {
1329 m_bodyRot = q; 1289 m_bodyRot = q;
@@ -1339,15 +1299,15 @@ namespace OpenSim.Region.Framework.Scenes
1339 1299
1340 // use camera up angle when in mouselook and not flying or when holding the left mouse button down and not flying 1300 // use camera up angle when in mouselook and not flying or when holding the left mouse button down and not flying
1341 // this prevents 'jumping' in inappropriate situations. 1301 // this prevents 'jumping' in inappropriate situations.
1342 if ((m_mouseLook && !m_physicsActor.Flying) || (m_leftButtonDown && !m_physicsActor.Flying)) 1302 if ((m_mouseLook && !m_physicsActor.Flying) || (m_leftButtonDown && !m_physicsActor.Flying))
1343 dirVectors = GetWalkDirectionVectors(); 1303 dirVectors = GetWalkDirectionVectors();
1344 else 1304 else
1345 dirVectors = Dir_Vectors; 1305 dirVectors = Dir_Vectors;
1346 1306
1347 1307
1348 foreach (Dir_ControlFlags DCF in Enum.GetValues(typeof (Dir_ControlFlags))) 1308 foreach (Dir_ControlFlags DCF in m_dirControlFlags)
1349 { 1309 {
1350 if ((flags & (uint) DCF) != 0) 1310 if ((flags & (uint)DCF) != 0)
1351 { 1311 {
1352 bResetMoveToPosition = true; 1312 bResetMoveToPosition = true;
1353 DCFlagKeyPressed = true; 1313 DCFlagKeyPressed = true;
@@ -1359,18 +1319,18 @@ namespace OpenSim.Region.Framework.Scenes
1359 { 1319 {
1360 // Why did I get this? 1320 // Why did I get this?
1361 } 1321 }
1362 1322
1363 if ((m_movementflag & (uint) DCF) == 0) 1323 if ((m_movementflag & (uint)DCF) == 0)
1364 { 1324 {
1365 m_movementflag += (byte) (uint) DCF; 1325 m_movementflag += (byte)(uint)DCF;
1366 update_movementflag = true; 1326 update_movementflag = true;
1367 } 1327 }
1368 } 1328 }
1369 else 1329 else
1370 { 1330 {
1371 if ((m_movementflag & (uint) DCF) != 0) 1331 if ((m_movementflag & (uint)DCF) != 0)
1372 { 1332 {
1373 m_movementflag -= (byte) (uint) DCF; 1333 m_movementflag -= (byte)(uint)DCF;
1374 update_movementflag = true; 1334 update_movementflag = true;
1375 } 1335 }
1376 else 1336 else
@@ -1461,14 +1421,12 @@ namespace OpenSim.Region.Framework.Scenes
1461 } 1421 }
1462 catch (Exception) 1422 catch (Exception)
1463 { 1423 {
1464
1465 //Avoid system crash, can be slower but... 1424 //Avoid system crash, can be slower but...
1466 } 1425 }
1467
1468 } 1426 }
1469 } 1427 }
1470 } 1428 }
1471 1429
1472 // Cause the avatar to stop flying if it's colliding 1430 // Cause the avatar to stop flying if it's colliding
1473 // with something with the down arrow pressed. 1431 // with something with the down arrow pressed.
1474 1432
@@ -1476,8 +1434,8 @@ namespace OpenSim.Region.Framework.Scenes
1476 if (m_physicsActor != null && m_physicsActor.Flying && !m_forceFly) 1434 if (m_physicsActor != null && m_physicsActor.Flying && !m_forceFly)
1477 { 1435 {
1478 // Are the landing controls requirements filled? 1436 // Are the landing controls requirements filled?
1479 bool controlland = (((flags & (uint) AgentManager.ControlFlags.AGENT_CONTROL_UP_NEG) != 0) || 1437 bool controlland = (((flags & (uint)AgentManager.ControlFlags.AGENT_CONTROL_UP_NEG) != 0) ||
1480 ((flags & (uint) AgentManager.ControlFlags.AGENT_CONTROL_NUDGE_UP_NEG) != 0)); 1438 ((flags & (uint)AgentManager.ControlFlags.AGENT_CONTROL_NUDGE_UP_NEG) != 0));
1481 1439
1482 // Are the collision requirements fulfilled? 1440 // Are the collision requirements fulfilled?
1483 bool colliding = (m_physicsActor.IsColliding == true); 1441 bool colliding = (m_physicsActor.IsColliding == true);
@@ -1490,10 +1448,10 @@ namespace OpenSim.Region.Framework.Scenes
1490 1448
1491 if (update_movementflag || (update_rotation && DCFlagKeyPressed)) 1449 if (update_movementflag || (update_rotation && DCFlagKeyPressed))
1492 { 1450 {
1493// m_log.DebugFormat("{0} {1}", update_movementflag, (update_rotation && DCFlagKeyPressed)); 1451 // m_log.DebugFormat("{0} {1}", update_movementflag, (update_rotation && DCFlagKeyPressed));
1494// m_log.DebugFormat( 1452 // m_log.DebugFormat(
1495// "In {0} adding velocity to {1} of {2}", m_scene.RegionInfo.RegionName, Name, agent_control_v3); 1453 // "In {0} adding velocity to {1} of {2}", m_scene.RegionInfo.RegionName, Name, agent_control_v3);
1496 1454
1497 AddNewMovement(agent_control_v3, q); 1455 AddNewMovement(agent_control_v3, q);
1498 1456
1499 if (update_movementflag) 1457 if (update_movementflag)
@@ -2456,11 +2414,10 @@ namespace OpenSim.Region.Framework.Scenes
2456 m_perfMonMS = Environment.TickCount; 2414 m_perfMonMS = Environment.TickCount;
2457 2415
2458 Vector3 pos = m_pos; 2416 Vector3 pos = m_pos;
2459 Vector3 vel = Velocity;
2460 Quaternion rot = m_bodyRot;
2461 pos.Z -= m_appearance.HipOffset; 2417 pos.Z -= m_appearance.HipOffset;
2462 remoteClient.SendAvatarTerseUpdate(m_regionHandle, (ushort)(m_scene.TimeDilation * ushort.MaxValue), LocalId, new Vector3(pos.X, pos.Y, pos.Z), 2418
2463 new Vector3(vel.X, vel.Y, vel.Z), rot, m_uuid); 2419 remoteClient.SendAvatarTerseUpdate(new SendAvatarTerseData(m_regionHandle, (ushort)(m_scene.TimeDilation * ushort.MaxValue), LocalId,
2420 pos, m_velocity, Vector3.Zero, m_rotation, Vector4.Zero, m_uuid, null, GetUpdatePriority(remoteClient)));
2464 2421
2465 m_scene.StatsReporter.AddAgentTime(Environment.TickCount - m_perfMonMS); 2422 m_scene.StatsReporter.AddAgentTime(Environment.TickCount - m_perfMonMS);
2466 m_scene.StatsReporter.AddAgentUpdates(1); 2423 m_scene.StatsReporter.AddAgentUpdates(1);
@@ -2474,7 +2431,7 @@ namespace OpenSim.Region.Framework.Scenes
2474 { 2431 {
2475 m_perfMonMS = Environment.TickCount; 2432 m_perfMonMS = Environment.TickCount;
2476 2433
2477 m_scene.Broadcast(SendTerseUpdateToClient); 2434 m_scene.ForEachClient(SendTerseUpdateToClient);
2478 2435
2479 m_lastVelocity = m_velocity; 2436 m_lastVelocity = m_velocity;
2480 lastPhysPos = AbsolutePosition; 2437 lastPhysPos = AbsolutePosition;
@@ -2566,9 +2523,9 @@ namespace OpenSim.Region.Framework.Scenes
2566 Vector3 pos = m_pos; 2523 Vector3 pos = m_pos;
2567 pos.Z -= m_appearance.HipOffset; 2524 pos.Z -= m_appearance.HipOffset;
2568 2525
2569 remoteAvatar.m_controllingClient.SendAvatarData(m_regionInfo.RegionHandle, m_firstname, m_lastname, m_grouptitle, m_uuid, 2526 remoteAvatar.m_controllingClient.SendAvatarData(new SendAvatarData(m_regionInfo.RegionHandle, m_firstname, m_lastname, m_grouptitle, m_uuid,
2570 LocalId, m_pos, m_appearance.Texture.GetBytes(), 2527 LocalId, m_pos, m_appearance.Texture.GetBytes(),
2571 m_parentID, rot); 2528 m_parentID, rot));
2572 m_scene.StatsReporter.AddAgentUpdates(1); 2529 m_scene.StatsReporter.AddAgentUpdates(1);
2573 } 2530 }
2574 2531
@@ -2637,8 +2594,8 @@ namespace OpenSim.Region.Framework.Scenes
2637 Vector3 pos = m_pos; 2594 Vector3 pos = m_pos;
2638 pos.Z -= m_appearance.HipOffset; 2595 pos.Z -= m_appearance.HipOffset;
2639 2596
2640 m_controllingClient.SendAvatarData(m_regionInfo.RegionHandle, m_firstname, m_lastname, m_grouptitle, m_uuid, LocalId, 2597 m_controllingClient.SendAvatarData(new SendAvatarData(m_regionInfo.RegionHandle, m_firstname, m_lastname, m_grouptitle, m_uuid, LocalId,
2641 m_pos, m_appearance.Texture.GetBytes(), m_parentID, rot); 2598 m_pos, m_appearance.Texture.GetBytes(), m_parentID, rot));
2642 2599
2643 if (!m_isChildAgent) 2600 if (!m_isChildAgent)
2644 { 2601 {
@@ -2744,8 +2701,8 @@ namespace OpenSim.Region.Framework.Scenes
2744 } 2701 }
2745 2702
2746 Quaternion rot = m_bodyRot; 2703 Quaternion rot = m_bodyRot;
2747 m_controllingClient.SendAvatarData(m_regionInfo.RegionHandle, m_firstname, m_lastname, m_grouptitle, m_uuid, LocalId, 2704 m_controllingClient.SendAvatarData(new SendAvatarData(m_regionInfo.RegionHandle, m_firstname, m_lastname, m_grouptitle, m_uuid, LocalId,
2748 m_pos, m_appearance.Texture.GetBytes(), m_parentID, rot); 2705 m_pos, m_appearance.Texture.GetBytes(), m_parentID, rot));
2749 2706
2750 } 2707 }
2751 2708
@@ -2776,7 +2733,7 @@ namespace OpenSim.Region.Framework.Scenes
2776 if (m_isChildAgent) 2733 if (m_isChildAgent)
2777 return; 2734 return;
2778 2735
2779 m_scene.Broadcast( 2736 m_scene.ForEachClient(
2780 delegate(IClientAPI client) { client.SendAnimations(animations, seqs, m_controllingClient.AgentId, objectIDs); }); 2737 delegate(IClientAPI client) { client.SendAnimations(animations, seqs, m_controllingClient.AgentId, objectIDs); });
2781 } 2738 }
2782 2739
@@ -2830,7 +2787,7 @@ namespace OpenSim.Region.Framework.Scenes
2830 } 2787 }
2831 2788
2832 // Minimum Draw distance is 64 meters, the Radius of the draw distance sphere is 32m 2789 // Minimum Draw distance is 64 meters, the Radius of the draw distance sphere is 32m
2833 if (Util.GetDistanceTo(AbsolutePosition,m_LastChildAgentUpdatePosition) > 32) 2790 if (Util.GetDistanceTo(AbsolutePosition, m_LastChildAgentUpdatePosition) >= Scene.ChildReprioritizationDistance)
2834 { 2791 {
2835 ChildAgentDataUpdate cadu = new ChildAgentDataUpdate(); 2792 ChildAgentDataUpdate cadu = new ChildAgentDataUpdate();
2836 cadu.ActiveGroupID = UUID.Zero.Guid; 2793 cadu.ActiveGroupID = UUID.Zero.Guid;
@@ -3125,6 +3082,12 @@ namespace OpenSim.Region.Framework.Scenes
3125 if (cAgentData.Position != new Vector3(-1, -1, -1)) // UGH!! 3082 if (cAgentData.Position != new Vector3(-1, -1, -1)) // UGH!!
3126 m_pos = new Vector3(cAgentData.Position.X + shiftx, cAgentData.Position.Y + shifty, cAgentData.Position.Z); 3083 m_pos = new Vector3(cAgentData.Position.X + shiftx, cAgentData.Position.Y + shifty, cAgentData.Position.Z);
3127 3084
3085 if (Vector3.Distance(AbsolutePosition, posLastSignificantMove) >= Scene.ChildReprioritizationDistance)
3086 {
3087 posLastSignificantMove = AbsolutePosition;
3088 ReprioritizeUpdates();
3089 }
3090
3128 // 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 3091 // 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
3129 m_CameraCenter = cAgentData.Center; 3092 m_CameraCenter = cAgentData.Center;
3130 3093
@@ -3487,7 +3450,6 @@ namespace OpenSim.Region.Framework.Scenes
3487 3450
3488 public void Close() 3451 public void Close()
3489 { 3452 {
3490
3491 lock (m_attachments) 3453 lock (m_attachments)
3492 { 3454 {
3493 // Delete attachments from scene 3455 // Delete attachments from scene
@@ -3505,10 +3467,19 @@ namespace OpenSim.Region.Framework.Scenes
3505 { 3467 {
3506 m_knownChildRegions.Clear(); 3468 m_knownChildRegions.Clear();
3507 } 3469 }
3470
3471 lock (m_reprioritization_timer)
3472 {
3473 m_reprioritization_timer.Enabled = false;
3474 m_reprioritization_timer.Elapsed -= new ElapsedEventHandler(Reprioritize);
3475 }
3476 // I don't get it but mono crashes when you try to dispose of this timer,
3477 // unsetting the elapsed callback should be enough to allow for cleanup however.
3478 //m_reprioritizationTimer.Dispose();
3479
3508 m_sceneViewer.Close(); 3480 m_sceneViewer.Close();
3509 3481
3510 RemoveFromPhysicalScene(); 3482 RemoveFromPhysicalScene();
3511 GC.Collect();
3512 } 3483 }
3513 3484
3514 public ScenePresence() 3485 public ScenePresence()
@@ -3884,5 +3855,115 @@ namespace OpenSim.Region.Framework.Scenes
3884 } 3855 }
3885 } 3856 }
3886 } 3857 }
3858
3859 public double GetUpdatePriority(IClientAPI client)
3860 {
3861 switch (Scene.UpdatePrioritizationScheme)
3862 {
3863 case Scene.UpdatePrioritizationSchemes.Time:
3864 return GetPriorityByTime();
3865 case Scene.UpdatePrioritizationSchemes.Distance:
3866 return GetPriorityByDistance(client);
3867 case Scene.UpdatePrioritizationSchemes.SimpleAngularDistance:
3868 return GetPriorityByDistance(client);
3869 default:
3870 throw new InvalidOperationException("UpdatePrioritizationScheme not defined.");
3871 }
3872 }
3873
3874 private double GetPriorityByTime()
3875 {
3876 return DateTime.Now.ToOADate();
3877 }
3878
3879 private double GetPriorityByDistance(IClientAPI client)
3880 {
3881 ScenePresence presence = Scene.GetScenePresence(client.AgentId);
3882 if (presence != null)
3883 {
3884 return GetPriorityByDistance((presence.IsChildAgent) ?
3885 presence.AbsolutePosition : presence.CameraPosition);
3886 }
3887 return double.NaN;
3888 }
3889
3890 private double GetPriorityByDistance(Vector3 position)
3891 {
3892 return Vector3.Distance(AbsolutePosition, position);
3893 }
3894
3895 private double GetSOGUpdatePriority(SceneObjectGroup sog)
3896 {
3897 switch (Scene.UpdatePrioritizationScheme)
3898 {
3899 case Scene.UpdatePrioritizationSchemes.Time:
3900 throw new InvalidOperationException("UpdatePrioritizationScheme for time not supported for reprioritization");
3901 case Scene.UpdatePrioritizationSchemes.Distance:
3902 return sog.GetPriorityByDistance((IsChildAgent) ? AbsolutePosition : CameraPosition);
3903 case Scene.UpdatePrioritizationSchemes.SimpleAngularDistance:
3904 return sog.GetPriorityBySimpleAngularDistance((IsChildAgent) ? AbsolutePosition : CameraPosition);
3905 default:
3906 throw new InvalidOperationException("UpdatePrioritizationScheme not defined");
3907 }
3908 }
3909
3910 private double UpdatePriority(UpdatePriorityData data)
3911 {
3912 EntityBase entity;
3913 SceneObjectGroup group;
3914
3915 if (Scene.Entities.TryGetValue(data.localID, out entity))
3916 {
3917 group = entity as SceneObjectGroup;
3918 if (group != null)
3919 return GetSOGUpdatePriority(group);
3920
3921 ScenePresence presence = entity as ScenePresence;
3922 if (presence == null)
3923 throw new InvalidOperationException("entity found is neither SceneObjectGroup nor ScenePresence");
3924 switch (Scene.UpdatePrioritizationScheme)
3925 {
3926 case Scene.UpdatePrioritizationSchemes.Time:
3927 throw new InvalidOperationException("UpdatePrioritization for time not supported for reprioritization");
3928 case Scene.UpdatePrioritizationSchemes.Distance:
3929 case Scene.UpdatePrioritizationSchemes.SimpleAngularDistance:
3930 return GetPriorityByDistance((IsChildAgent) ? AbsolutePosition : CameraPosition);
3931 default:
3932 throw new InvalidOperationException("UpdatePrioritizationScheme not defined");
3933 }
3934 }
3935 else
3936 {
3937 group = Scene.SceneGraph.GetGroupByPrim(data.localID);
3938 if (group != null)
3939 return GetSOGUpdatePriority(group);
3940 }
3941 return double.NaN;
3942 }
3943
3944 private void ReprioritizeUpdates()
3945 {
3946 if (Scene.IsReprioritizationEnabled && Scene.UpdatePrioritizationScheme != Scene.UpdatePrioritizationSchemes.Time)
3947 {
3948 lock (m_reprioritization_timer)
3949 {
3950 if (!m_reprioritizing)
3951 m_reprioritization_timer.Enabled = m_reprioritizing = true;
3952 else
3953 m_reprioritization_called = true;
3954 }
3955 }
3956 }
3957
3958 private void Reprioritize(object sender, ElapsedEventArgs e)
3959 {
3960 m_controllingClient.ReprioritizeUpdates(StateUpdateTypes.All, UpdatePriority);
3961
3962 lock (m_reprioritization_timer)
3963 {
3964 m_reprioritization_timer.Enabled = m_reprioritizing = m_reprioritization_called;
3965 m_reprioritization_called = false;
3966 }
3967 }
3887 } 3968 }
3888} 3969}