Manage AgentUpdates more sanely:

- The existing event to scene has been split into 2: OnAgentUpdate and OnAgentCameraUpdate, to better reflect the two types of updates that the viewer sends. We can run one without the other, which is what happens when the avie is still but the user is camming around
- Added thresholds (as opposed to equality) to determine whether the update is significant or not. I thin these thresholds are ok, but we can play with them later
- Ignore updates of HeadRotation, which were problematic and aren't being used up stream
This commit is contained in:
Diva Canto
2013-07-20 12:20:35 -07:00
parent 174105ad02
commit d5a1779465
6 changed files with 181 additions and 144 deletions

View File

@@ -801,6 +801,7 @@ namespace OpenSim.Region.Framework.Scenes
{
ControllingClient.OnCompleteMovementToRegion += CompleteMovement;
ControllingClient.OnAgentUpdate += HandleAgentUpdate;
ControllingClient.OnAgentCameraUpdate += HandleAgentCamerasUpdate;
ControllingClient.OnAgentRequestSit += HandleAgentRequestSit;
ControllingClient.OnAgentSit += HandleAgentSit;
ControllingClient.OnSetAlwaysRun += HandleSetAlwaysRun;
@@ -1438,9 +1439,9 @@ namespace OpenSim.Region.Framework.Scenes
/// </summary>
public void HandleAgentUpdate(IClientAPI remoteClient, AgentUpdateArgs agentData)
{
// m_log.DebugFormat(
// "[SCENE PRESENCE]: In {0} received agent update from {1}, flags {2}",
// Scene.RegionInfo.RegionName, remoteClient.Name, (AgentManager.ControlFlags)agentData.ControlFlags);
//m_log.DebugFormat(
// "[SCENE PRESENCE]: In {0} received agent update from {1}, flags {2}",
// Scene.RegionInfo.RegionName, remoteClient.Name, (AgentManager.ControlFlags)agentData.ControlFlags);
if (IsChildAgent)
{
@@ -1448,10 +1449,6 @@ namespace OpenSim.Region.Framework.Scenes
return;
}
++m_movementUpdateCount;
if (m_movementUpdateCount < 1)
m_movementUpdateCount = 1;
#region Sanity Checking
// This is irritating. Really.
@@ -1482,21 +1479,6 @@ namespace OpenSim.Region.Framework.Scenes
AgentManager.ControlFlags flags = (AgentManager.ControlFlags)agentData.ControlFlags;
// Camera location in world. We'll need to raytrace
// from this location from time to time.
CameraPosition = agentData.CameraCenter;
if (Vector3.Distance(m_lastCameraPosition, CameraPosition) >= Scene.RootReprioritizationDistance)
{
ReprioritizeUpdates();
m_lastCameraPosition = CameraPosition;
}
// Use these three vectors to figure out what the agent is looking at
// Convert it to a Matrix and/or Quaternion
CameraAtAxis = agentData.CameraAtAxis;
CameraLeftAxis = agentData.CameraLeftAxis;
CameraUpAxis = agentData.CameraUpAxis;
// The Agent's Draw distance setting
// When we get to the point of re-computing neighbors everytime this
// changes, then start using the agent's drawdistance rather than the
@@ -1504,12 +1486,6 @@ namespace OpenSim.Region.Framework.Scenes
// DrawDistance = agentData.Far;
DrawDistance = Scene.DefaultDrawDistance;
// Check if Client has camera in 'follow cam' or 'build' mode.
Vector3 camdif = (Vector3.One * Rotation - Vector3.One * CameraRotation);
m_followCamAuto = ((CameraUpAxis.Z > 0.959f && CameraUpAxis.Z < 0.98f)
&& (Math.Abs(camdif.X) < 0.4f && Math.Abs(camdif.Y) < 0.4f)) ? true : false;
m_mouseLook = (flags & AgentManager.ControlFlags.AGENT_CONTROL_MOUSELOOK) != 0;
m_leftButtonDown = (flags & AgentManager.ControlFlags.AGENT_CONTROL_LBUTTON_DOWN) != 0;
@@ -1529,17 +1505,6 @@ namespace OpenSim.Region.Framework.Scenes
StandUp();
}
//m_log.DebugFormat("[FollowCam]: {0}", m_followCamAuto);
// Raycast from the avatar's head to the camera to see if there's anything blocking the view
if ((m_movementUpdateCount % NumMovementsBetweenRayCast) == 0 && m_scene.PhysicsScene.SupportsRayCast())
{
if (m_followCamAuto)
{
Vector3 posAdjusted = m_pos + HEAD_ADJUSTMENT;
m_scene.PhysicsScene.RaycastWorld(m_pos, Vector3.Normalize(CameraPosition - posAdjusted), Vector3.Distance(CameraPosition, posAdjusted) + 0.3f, RayCastCameraCallback);
}
}
uint flagsForScripts = (uint)flags;
flags = RemoveIgnoredControls(flags, IgnoredControls);
@@ -1764,9 +1729,74 @@ namespace OpenSim.Region.Framework.Scenes
}
m_scene.EventManager.TriggerOnClientMovement(this);
TriggerScenePresenceUpdated();
}
/// <summary>
/// This is the event handler for client cameras. If a client is moving, or moving the camera, this event is triggering.
/// </summary>
public void HandleAgentCamerasUpdate(IClientAPI remoteClient, AgentUpdateArgs agentData)
{
//m_log.DebugFormat(
// "[SCENE PRESENCE]: In {0} received agent camera update from {1}, flags {2}",
// Scene.RegionInfo.RegionName, remoteClient.Name, (AgentManager.ControlFlags)agentData.ControlFlags);
if (IsChildAgent)
{
// // m_log.Debug("DEBUG: HandleAgentUpdate: child agent");
return;
}
++m_movementUpdateCount;
if (m_movementUpdateCount < 1)
m_movementUpdateCount = 1;
AgentManager.ControlFlags flags = (AgentManager.ControlFlags)agentData.ControlFlags;
// Camera location in world. We'll need to raytrace
// from this location from time to time.
CameraPosition = agentData.CameraCenter;
if (Vector3.Distance(m_lastCameraPosition, CameraPosition) >= Scene.RootReprioritizationDistance)
{
ReprioritizeUpdates();
m_lastCameraPosition = CameraPosition;
}
// Use these three vectors to figure out what the agent is looking at
// Convert it to a Matrix and/or Quaternion
CameraAtAxis = agentData.CameraAtAxis;
CameraLeftAxis = agentData.CameraLeftAxis;
CameraUpAxis = agentData.CameraUpAxis;
// The Agent's Draw distance setting
// When we get to the point of re-computing neighbors everytime this
// changes, then start using the agent's drawdistance rather than the
// region's draw distance.
// DrawDistance = agentData.Far;
DrawDistance = Scene.DefaultDrawDistance;
// Check if Client has camera in 'follow cam' or 'build' mode.
Vector3 camdif = (Vector3.One * Rotation - Vector3.One * CameraRotation);
m_followCamAuto = ((CameraUpAxis.Z > 0.959f && CameraUpAxis.Z < 0.98f)
&& (Math.Abs(camdif.X) < 0.4f && Math.Abs(camdif.Y) < 0.4f)) ? true : false;
//m_log.DebugFormat("[FollowCam]: {0}", m_followCamAuto);
// Raycast from the avatar's head to the camera to see if there's anything blocking the view
if ((m_movementUpdateCount % NumMovementsBetweenRayCast) == 0 && m_scene.PhysicsScene.SupportsRayCast())
{
if (m_followCamAuto)
{
Vector3 posAdjusted = m_pos + HEAD_ADJUSTMENT;
m_scene.PhysicsScene.RaycastWorld(m_pos, Vector3.Normalize(CameraPosition - posAdjusted), Vector3.Distance(CameraPosition, posAdjusted) + 0.3f, RayCastCameraCallback);
}
}
TriggerScenePresenceUpdated();
}
/// <summary>
/// Calculate an update to move the presence to the set target.
/// </summary>