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.cs117
1 files changed, 52 insertions, 65 deletions
diff --git a/OpenSim/Region/Framework/Scenes/ScenePresence.cs b/OpenSim/Region/Framework/Scenes/ScenePresence.cs
index d354c0a..719f2da 100644
--- a/OpenSim/Region/Framework/Scenes/ScenePresence.cs
+++ b/OpenSim/Region/Framework/Scenes/ScenePresence.cs
@@ -75,6 +75,11 @@ namespace OpenSim.Region.Framework.Scenes
75 75
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 /// <summary>
79 /// What type of presence is this? User, NPC, etc.
80 /// </summary>
81 public PresenceType PresenceType { get; private set; }
82
78// private static readonly byte[] DEFAULT_TEXTURE = AvatarAppearance.GetDefaultTexture().GetBytes(); 83// private static readonly byte[] DEFAULT_TEXTURE = AvatarAppearance.GetDefaultTexture().GetBytes();
79 private static readonly Array DIR_CONTROL_FLAGS = Enum.GetValues(typeof(Dir_ControlFlags)); 84 private static readonly Array DIR_CONTROL_FLAGS = Enum.GetValues(typeof(Dir_ControlFlags));
80 private static readonly Vector3 HEAD_ADJUSTMENT = new Vector3(0f, 0f, 0.3f); 85 private static readonly Vector3 HEAD_ADJUSTMENT = new Vector3(0f, 0f, 0.3f);
@@ -173,7 +178,7 @@ namespace OpenSim.Region.Framework.Scenes
173 178
174 private float m_speedModifier = 1.0f; 179 private float m_speedModifier = 1.0f;
175 180
176 private Quaternion m_bodyRot= Quaternion.Identity; 181 private Quaternion m_bodyRot = Quaternion.Identity;
177 182
178 private Quaternion m_bodyRotPrevious = Quaternion.Identity; 183 private Quaternion m_bodyRotPrevious = Quaternion.Identity;
179 184
@@ -708,15 +713,13 @@ namespace OpenSim.Region.Framework.Scenes
708 713
709 #region Constructor(s) 714 #region Constructor(s)
710 715
711 public ScenePresence() 716 public ScenePresence(
717 IClientAPI client, Scene world, RegionInfo reginfo, AvatarAppearance appearance, PresenceType type)
712 { 718 {
713 m_sendCourseLocationsMethod = SendCoarseLocationsDefault; 719 m_sendCourseLocationsMethod = SendCoarseLocationsDefault;
714 CreateSceneViewer(); 720 m_sceneViewer = new SceneViewer(this);
715 m_animator = new ScenePresenceAnimator(this); 721 m_animator = new ScenePresenceAnimator(this);
716 } 722 PresenceType = type;
717
718 private ScenePresence(IClientAPI client, Scene world, RegionInfo reginfo) : this()
719 {
720 m_DrawDistance = world.DefaultDrawDistance; 723 m_DrawDistance = world.DefaultDrawDistance;
721 m_rootRegionHandle = reginfo.RegionHandle; 724 m_rootRegionHandle = reginfo.RegionHandle;
722 m_controllingClient = client; 725 m_controllingClient = client;
@@ -762,19 +765,10 @@ namespace OpenSim.Region.Framework.Scenes
762 765
763 RegisterToEvents(); 766 RegisterToEvents();
764 SetDirectionVectors(); 767 SetDirectionVectors();
765 }
766 768
767 public ScenePresence(IClientAPI client, Scene world, RegionInfo reginfo, AvatarAppearance appearance)
768 : this(client, world, reginfo)
769 {
770 m_appearance = appearance; 769 m_appearance = appearance;
771 } 770 }
772 771
773 private void CreateSceneViewer()
774 {
775 m_sceneViewer = new SceneViewer(this);
776 }
777
778 public void RegisterToEvents() 772 public void RegisterToEvents()
779 { 773 {
780 m_controllingClient.OnCompleteMovementToRegion += CompleteMovement; 774 m_controllingClient.OnCompleteMovementToRegion += CompleteMovement;
@@ -1144,10 +1138,14 @@ namespace OpenSim.Region.Framework.Scenes
1144 1138
1145 /// <summary> 1139 /// <summary>
1146 /// Complete Avatar's movement into the region. 1140 /// Complete Avatar's movement into the region.
1147 /// This is called upon a very important packet sent from the client,
1148 /// so it's client-controlled. Never call this method directly.
1149 /// </summary> 1141 /// </summary>
1150 public void CompleteMovement(IClientAPI client) 1142 /// <param name="client"></param>
1143 /// <param name="openChildAgents">
1144 /// If true, send notification to neighbour regions to expect
1145 /// a child agent from the client. These neighbours can be some distance away, depending right now on the
1146 /// configuration of DefaultDrawDistance in the [Startup] section of config
1147 /// </param>
1148 public void CompleteMovement(IClientAPI client, bool openChildAgents)
1151 { 1149 {
1152// DateTime startTime = DateTime.Now; 1150// DateTime startTime = DateTime.Now;
1153 1151
@@ -1188,15 +1186,11 @@ namespace OpenSim.Region.Framework.Scenes
1188 SendInitialData(); 1186 SendInitialData();
1189 1187
1190 // Create child agents in neighbouring regions 1188 // Create child agents in neighbouring regions
1191 if (!m_isChildAgent) 1189 if (openChildAgents && !m_isChildAgent)
1192 { 1190 {
1193 IEntityTransferModule m_agentTransfer = m_scene.RequestModuleInterface<IEntityTransferModule>(); 1191 IEntityTransferModule m_agentTransfer = m_scene.RequestModuleInterface<IEntityTransferModule>();
1194 if (m_agentTransfer != null) 1192 if (m_agentTransfer != null)
1195 m_agentTransfer.EnableChildAgents(this); 1193 m_agentTransfer.EnableChildAgents(this);
1196 else
1197 m_log.DebugFormat(
1198 "[SCENE PRESENCE]: Unable to create child agents in neighbours, because AgentTransferModule is not active for region {0}",
1199 m_scene.RegionInfo.RegionName);
1200 1194
1201 IFriendsModule friendsModule = m_scene.RequestModuleInterface<IFriendsModule>(); 1195 IFriendsModule friendsModule = m_scene.RequestModuleInterface<IFriendsModule>();
1202 if (friendsModule != null) 1196 if (friendsModule != null)
@@ -1294,7 +1288,6 @@ namespace OpenSim.Region.Framework.Scenes
1294 #region Inputs 1288 #region Inputs
1295 1289
1296 AgentManager.ControlFlags flags = (AgentManager.ControlFlags)agentData.ControlFlags; 1290 AgentManager.ControlFlags flags = (AgentManager.ControlFlags)agentData.ControlFlags;
1297 Quaternion bodyRotation = agentData.BodyRotation;
1298 1291
1299 // Camera location in world. We'll need to raytrace 1292 // Camera location in world. We'll need to raytrace
1300 // from this location from time to time. 1293 // from this location from time to time.
@@ -1380,6 +1373,15 @@ namespace OpenSim.Region.Framework.Scenes
1380 1373
1381 if (m_allowMovement && !SitGround) 1374 if (m_allowMovement && !SitGround)
1382 { 1375 {
1376 Quaternion bodyRotation = agentData.BodyRotation;
1377 bool update_rotation = false;
1378
1379 if (bodyRotation != m_bodyRot)
1380 {
1381 Rotation = bodyRotation;
1382 update_rotation = true;
1383 }
1384
1383 bool update_movementflag = false; 1385 bool update_movementflag = false;
1384 1386
1385 if (agentData.UseClientAgentPosition) 1387 if (agentData.UseClientAgentPosition)
@@ -1389,11 +1391,8 @@ namespace OpenSim.Region.Framework.Scenes
1389 } 1391 }
1390 1392
1391 int i = 0; 1393 int i = 0;
1392
1393 bool update_rotation = false;
1394 bool DCFlagKeyPressed = false; 1394 bool DCFlagKeyPressed = false;
1395 Vector3 agent_control_v3 = Vector3.Zero; 1395 Vector3 agent_control_v3 = Vector3.Zero;
1396 Quaternion q = bodyRotation;
1397 1396
1398 bool oldflying = PhysicsActor.Flying; 1397 bool oldflying = PhysicsActor.Flying;
1399 1398
@@ -1407,12 +1406,6 @@ namespace OpenSim.Region.Framework.Scenes
1407 if (actor.Flying != oldflying) 1406 if (actor.Flying != oldflying)
1408 update_movementflag = true; 1407 update_movementflag = true;
1409 1408
1410 if (q != m_bodyRot)
1411 {
1412 m_bodyRot = q;
1413 update_rotation = true;
1414 }
1415
1416 if (m_parentID == 0) 1409 if (m_parentID == 0)
1417 { 1410 {
1418 bool bAllowUpdateMoveToPosition = false; 1411 bool bAllowUpdateMoveToPosition = false;
@@ -1464,8 +1457,8 @@ namespace OpenSim.Region.Framework.Scenes
1464 ) // This or is for Nudge forward 1457 ) // This or is for Nudge forward
1465 { 1458 {
1466 m_movementflag -= ((byte)(uint)DCF); 1459 m_movementflag -= ((byte)(uint)DCF);
1467
1468 update_movementflag = true; 1460 update_movementflag = true;
1461
1469 /* 1462 /*
1470 if ((DCF == Dir_ControlFlags.DIR_CONTROL_FLAG_FORWARD_NUDGE || DCF == Dir_ControlFlags.DIR_CONTROL_FLAG_BACKWARD_NUDGE) 1463 if ((DCF == Dir_ControlFlags.DIR_CONTROL_FLAG_FORWARD_NUDGE || DCF == Dir_ControlFlags.DIR_CONTROL_FLAG_BACKWARD_NUDGE)
1471 && ((m_movementflag & (byte)nudgehack) == nudgehack)) 1464 && ((m_movementflag & (byte)nudgehack) == nudgehack))
@@ -1493,7 +1486,7 @@ namespace OpenSim.Region.Framework.Scenes
1493 } 1486 }
1494 else if (bAllowUpdateMoveToPosition) 1487 else if (bAllowUpdateMoveToPosition)
1495 { 1488 {
1496 if (HandleMoveToTargetUpdate(ref agent_control_v3, bodyRotation)) 1489 if (HandleMoveToTargetUpdate(ref agent_control_v3))
1497 update_movementflag = true; 1490 update_movementflag = true;
1498 } 1491 }
1499 } 1492 }
@@ -1531,13 +1524,10 @@ namespace OpenSim.Region.Framework.Scenes
1531 // m_log.DebugFormat( 1524 // m_log.DebugFormat(
1532 // "In {0} adding velocity to {1} of {2}", m_scene.RegionInfo.RegionName, Name, agent_control_v3); 1525 // "In {0} adding velocity to {1} of {2}", m_scene.RegionInfo.RegionName, Name, agent_control_v3);
1533 1526
1534 AddNewMovement(agent_control_v3, q); 1527 AddNewMovement(agent_control_v3);
1535 } 1528 }
1536 1529
1537 if (update_movementflag 1530 if (update_movementflag && m_parentID == 0)
1538 && ((flags & AgentManager.ControlFlags.AGENT_CONTROL_SIT_ON_GROUND) == 0)
1539 && (m_parentID == 0)
1540 && !SitGround)
1541 Animator.UpdateMovementAnimations(); 1531 Animator.UpdateMovementAnimations();
1542 } 1532 }
1543 1533
@@ -1553,9 +1543,8 @@ namespace OpenSim.Region.Framework.Scenes
1553 /// This doesn't actually perform the movement. Instead, it adds its vector to agent_control_v3. 1543 /// This doesn't actually perform the movement. Instead, it adds its vector to agent_control_v3.
1554 /// </remarks> 1544 /// </remarks>
1555 /// <param value="agent_control_v3">Cumulative agent movement that this method will update.</param> 1545 /// <param value="agent_control_v3">Cumulative agent movement that this method will update.</param>
1556 /// <param value="bodyRotation">New body rotation of the avatar.</param>
1557 /// <returns>True if movement has been updated in some way. False otherwise.</returns> 1546 /// <returns>True if movement has been updated in some way. False otherwise.</returns>
1558 public bool HandleMoveToTargetUpdate(ref Vector3 agent_control_v3, Quaternion bodyRotation) 1547 public bool HandleMoveToTargetUpdate(ref Vector3 agent_control_v3)
1559 { 1548 {
1560// m_log.DebugFormat("[SCENE PRESENCE]: Called HandleMoveToTargetUpdate() for {0}", Name); 1549// m_log.DebugFormat("[SCENE PRESENCE]: Called HandleMoveToTargetUpdate() for {0}", Name);
1561 1550
@@ -1591,7 +1580,7 @@ namespace OpenSim.Region.Framework.Scenes
1591 // to such forces, but the following simple approach seems to works fine. 1580 // to such forces, but the following simple approach seems to works fine.
1592 Vector3 LocalVectorToTarget3D = 1581 Vector3 LocalVectorToTarget3D =
1593 (MoveToPositionTarget - AbsolutePosition) // vector from cur. pos to target in global coords 1582 (MoveToPositionTarget - AbsolutePosition) // vector from cur. pos to target in global coords
1594 * Matrix4.CreateFromQuaternion(Quaternion.Inverse(bodyRotation)); // change to avatar coords 1583 * Matrix4.CreateFromQuaternion(Quaternion.Inverse(Rotation)); // change to avatar coords
1595 // Ignore z component of vector 1584 // Ignore z component of vector
1596// Vector3 LocalVectorToTarget2D = new Vector3((float)(LocalVectorToTarget3D.X), (float)(LocalVectorToTarget3D.Y), 0f); 1585// Vector3 LocalVectorToTarget2D = new Vector3((float)(LocalVectorToTarget3D.X), (float)(LocalVectorToTarget3D.Y), 0f);
1597 LocalVectorToTarget3D.Normalize(); 1586 LocalVectorToTarget3D.Normalize();
@@ -1680,7 +1669,12 @@ namespace OpenSim.Region.Framework.Scenes
1680 /// Move to the given target over time. 1669 /// Move to the given target over time.
1681 /// </summary> 1670 /// </summary>
1682 /// <param name="pos"></param> 1671 /// <param name="pos"></param>
1683 public void MoveToTarget(Vector3 pos) 1672 /// <param name="noFly">
1673 /// If true, then don't allow the avatar to fly to the target, even if it's up in the air.
1674 /// This is to allow movement to targets that are known to be on an elevated platform with a continuous path
1675 /// from start to finish.
1676 /// </param>
1677 public void MoveToTarget(Vector3 pos, bool noFly)
1684 { 1678 {
1685// m_log.DebugFormat( 1679// m_log.DebugFormat(
1686// "[SCENE PRESENCE]: Avatar {0} received request to move to position {1} in {2}", 1680// "[SCENE PRESENCE]: Avatar {0} received request to move to position {1} in {2}",
@@ -1714,15 +1708,17 @@ namespace OpenSim.Region.Framework.Scenes
1714 "[SCENE PRESENCE]: Avatar {0} set move to target {1} (terrain height {2}) in {3}", 1708 "[SCENE PRESENCE]: Avatar {0} set move to target {1} (terrain height {2}) in {3}",
1715 Name, pos, terrainHeight, m_scene.RegionInfo.RegionName); 1709 Name, pos, terrainHeight, m_scene.RegionInfo.RegionName);
1716 1710
1717 if (pos.Z > terrainHeight) 1711 if (noFly)
1712 PhysicsActor.Flying = false;
1713 else if (pos.Z > terrainHeight)
1718 PhysicsActor.Flying = true; 1714 PhysicsActor.Flying = true;
1719 1715
1720 MovingToTarget = true; 1716 MovingToTarget = true;
1721 MoveToPositionTarget = pos; 1717 MoveToPositionTarget = pos;
1722 1718
1723 Vector3 agent_control_v3 = new Vector3(); 1719 Vector3 agent_control_v3 = new Vector3();
1724 HandleMoveToTargetUpdate(ref agent_control_v3, Rotation); 1720 HandleMoveToTargetUpdate(ref agent_control_v3);
1725 AddNewMovement(agent_control_v3, Rotation); 1721 AddNewMovement(agent_control_v3);
1726 } 1722 }
1727 1723
1728 /// <summary> 1724 /// <summary>
@@ -1734,6 +1730,12 @@ namespace OpenSim.Region.Framework.Scenes
1734 1730
1735 MovingToTarget = false; 1731 MovingToTarget = false;
1736 MoveToPositionTarget = Vector3.Zero; 1732 MoveToPositionTarget = Vector3.Zero;
1733
1734 // We need to reset the control flag as the ScenePresenceAnimator uses this to determine the correct
1735 // resting animation (e.g. hover or stand). NPCs don't have a client that will quickly reset this flag.
1736 // However, the line is here rather than in the NPC module since it also appears necessary to stop a
1737 // viewer that uses "go here" from juddering on all subsequent avatar movements.
1738 AgentControlFlags = (uint)AgentManager.ControlFlags.NONE;
1737 } 1739 }
1738 1740
1739 private void CheckAtSitTarget() 1741 private void CheckAtSitTarget()
@@ -2295,20 +2297,11 @@ namespace OpenSim.Region.Framework.Scenes
2295 /// Rotate the avatar to the given rotation and apply a movement in the given relative vector 2297 /// Rotate the avatar to the given rotation and apply a movement in the given relative vector
2296 /// </summary> 2298 /// </summary>
2297 /// <param name="vec">The vector in which to move. This is relative to the rotation argument</param> 2299 /// <param name="vec">The vector in which to move. This is relative to the rotation argument</param>
2298 /// <param name="rotation">The direction in which this avatar should now face. 2300 public void AddNewMovement(Vector3 vec)
2299 public void AddNewMovement(Vector3 vec, Quaternion rotation)
2300 { 2301 {
2301 if (m_isChildAgent)
2302 {
2303 // WHAT???
2304 m_log.Debug("[SCENEPRESENCE]: AddNewMovement() called on child agent, making root agent!");
2305 return;
2306 }
2307
2308 m_perfMonMS = Util.EnvironmentTickCount(); 2302 m_perfMonMS = Util.EnvironmentTickCount();
2309 2303
2310 Rotation = rotation; 2304 Vector3 direc = vec * Rotation;
2311 Vector3 direc = vec * rotation;
2312 direc.Normalize(); 2305 direc.Normalize();
2313 2306
2314 direc *= 0.03f * 128f * m_speedModifier; 2307 direc *= 0.03f * 128f * m_speedModifier;
@@ -2513,13 +2506,7 @@ namespace OpenSim.Region.Framework.Scenes
2513 // We have an appearance but we may not have the baked textures. Check the asset cache 2506 // We have an appearance but we may not have the baked textures. Check the asset cache
2514 // to see if all the baked textures are already here. 2507 // to see if all the baked textures are already here.
2515 if (m_scene.AvatarFactory != null) 2508 if (m_scene.AvatarFactory != null)
2516 {
2517 cachedappearance = m_scene.AvatarFactory.ValidateBakedTextureCache(m_controllingClient); 2509 cachedappearance = m_scene.AvatarFactory.ValidateBakedTextureCache(m_controllingClient);
2518 }
2519 else
2520 {
2521 m_log.WarnFormat("[SCENEPRESENCE]: AvatarFactory not set for {0}", Name);
2522 }
2523 2510
2524 // If we aren't using a cached appearance, then clear out the baked textures 2511 // If we aren't using a cached appearance, then clear out the baked textures
2525 if (!cachedappearance) 2512 if (!cachedappearance)