From e69c810486e63e8b4398c7b67e84d73154d2dfcf Mon Sep 17 00:00:00 2001 From: Teravus Ovares Date: Thu, 22 Nov 2007 01:32:13 +0000 Subject: [PATCH] * Added code to capture the draw distance setting from the client. * Added a support function to InnerScene to calculate the distance between two vectors. --- OpenSim/Framework/IClientAPI.cs | 2 +- .../ClientStack/ClientView.ProcessPackets.cs | 3 +- .../Region/Environment/Scenes/InnerScene.cs | 36 +++++++- .../Environment/Scenes/ScenePresence.cs | 82 ++++++++++++++++--- .../Examples/SimpleApp/MyNpcCharacter.cs | 5 +- 5 files changed, 114 insertions(+), 14 deletions(-) diff --git a/OpenSim/Framework/IClientAPI.cs b/OpenSim/Framework/IClientAPI.cs index 0e8b82d066..05adf22017 100644 --- a/OpenSim/Framework/IClientAPI.cs +++ b/OpenSim/Framework/IClientAPI.cs @@ -237,7 +237,7 @@ namespace OpenSim.Framework public delegate void NewAvatar(IClientAPI remoteClient, LLUUID agentID, bool status); - public delegate void UpdateAgent(IClientAPI remoteClient, uint flags, LLQuaternion bodyRotation); + public delegate void UpdateAgent(IClientAPI remoteClient, AgentUpdatePacket agentData); public delegate void AgentRequestSit(IClientAPI remoteClient, LLUUID agentID, LLUUID targetID, LLVector3 offset); diff --git a/OpenSim/Region/ClientStack/ClientView.ProcessPackets.cs b/OpenSim/Region/ClientStack/ClientView.ProcessPackets.cs index f62407d0ad..7f762b65e5 100644 --- a/OpenSim/Region/ClientStack/ClientView.ProcessPackets.cs +++ b/OpenSim/Region/ClientStack/ClientView.ProcessPackets.cs @@ -186,7 +186,8 @@ namespace OpenSim.Region.ClientStack if (OnAgentUpdate != null) { AgentUpdatePacket agenUpdate = (AgentUpdatePacket) Pack; - OnAgentUpdate(this, agenUpdate.AgentData.ControlFlags, agenUpdate.AgentData.BodyRotation); + + OnAgentUpdate(this, agenUpdate); //agenUpdate.AgentData.ControlFlags, agenUpdate.AgentData.BodyRotationa); } break; case PacketType.AgentAnimation: diff --git a/OpenSim/Region/Environment/Scenes/InnerScene.cs b/OpenSim/Region/Environment/Scenes/InnerScene.cs index 1f3bc95d7f..38a8a06b98 100644 --- a/OpenSim/Region/Environment/Scenes/InnerScene.cs +++ b/OpenSim/Region/Environment/Scenes/InnerScene.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.Text; +using Axiom.Math; using libsecondlife; using libsecondlife.Packets; using OpenSim.Framework; @@ -325,7 +326,32 @@ namespace OpenSim.Region.Environment.Scenes { if (ent is SceneObjectGroup) { - ((SceneObjectGroup)ent).ScheduleFullUpdateToAvatar(presence); + // Only send child agents stuff in their draw distance. + // This will need to be done for every agent once we figure out + // what we're going to use to store prim that agents already got + // the initial update for and what we'll use to limit the + // space we check for new objects on movement. + + if (presence.IsChildAgent) + { + //Vector3 avPosition = new Vector3(presence.AbsolutePosition.X,presence.AbsolutePosition.Y,presence.AbsolutePosition.Z); + //LLVector3 oLoc = ((SceneObjectGroup)ent).AbsolutePosition; + //Vector3 objPosition = new Vector3(oLoc.X,oLoc.Y,oLoc.Z); + //float distResult = Vector3Distance(avPosition, objPosition); + //if (distResult > 512) + //{ + //int x = 0; + //} + //if (distResult < presence.DrawDistance) + //{ + ((SceneObjectGroup)ent).ScheduleFullUpdateToAvatar(presence); + //} + + } + else + { + ((SceneObjectGroup)ent).ScheduleFullUpdateToAvatar(presence); + } } } } @@ -642,7 +668,15 @@ namespace OpenSim.Region.Environment.Scenes } } + public float Vector3Distance(Vector3 v1, Vector3 v2) + { + // Calculates the distance between two Vector3s + // We don't really need the double floating point precision... + // so casting it to a single + return (float)Math.Sqrt((v1.x - v2.x) * (v1.x - v2.x) + (v1.y - v2.y) * (v1.y - v2.y) + (v1.z - v2.z) * (v1.z - v2.z)); + + } #endregion } } diff --git a/OpenSim/Region/Environment/Scenes/ScenePresence.cs b/OpenSim/Region/Environment/Scenes/ScenePresence.cs index be21748949..3929f0f592 100644 --- a/OpenSim/Region/Environment/Scenes/ScenePresence.cs +++ b/OpenSim/Region/Environment/Scenes/ScenePresence.cs @@ -79,6 +79,19 @@ namespace OpenSim.Region.Environment.Scenes private LLVector3 lastPhysPos = new LLVector3(); private int m_wearablesSerial = 1; + + // Position of agent's camera in world + protected Vector3 m_CameraCenter = new Vector3(0, 0, 0); + + // Use these three vectors to figure out what the agent is looking at + // Convert it to a Matrix and/or Quaternion + protected Vector3 m_CameraAtAxis = new Vector3(0, 0, 0); + protected Vector3 m_CameraLeftAxis = new Vector3(0, 0, 0); + protected Vector3 m_CameraUpAxis = new Vector3(0, 0, 0); + + // Agent's Draw distance. + protected float m_DrawDistance = 0f; + private readonly List m_knownChildRegions = new List(); //neighbouring regions we have enabled a child agent in private enum Dir_ControlFlags @@ -148,6 +161,11 @@ namespace OpenSim.Region.Environment.Scenes get { return m_lastname; } } + public float DrawDistance + { + get { return m_DrawDistance; } + } + protected bool m_allowMovement = true; public bool AllowMovement { @@ -408,11 +426,11 @@ namespace OpenSim.Region.Environment.Scenes AddToPhysicalScene(); m_physicsActor.Flying = isFlying; - if (!m_gotAllObjectsInScene) - { - m_scene.SendAllSceneObjectsToClient(this); - m_gotAllObjectsInScene = true; - } + //if (!m_gotAllObjectsInScene) + //{ + //m_scene.SendAllSceneObjectsToClient(this); + //m_gotAllObjectsInScene = true; + //} } @@ -526,7 +544,7 @@ namespace OpenSim.Region.Environment.Scenes } } - public void HandleAgentUpdate(IClientAPI remoteClient, uint flags, LLQuaternion bodyRotation) + public void HandleAgentUpdate(IClientAPI remoteClient,AgentUpdatePacket agentData ) { //if (m_isChildAgent) //{ @@ -536,6 +554,54 @@ namespace OpenSim.Region.Environment.Scenes // Must check for standing up even when PhysicsActor is null, // since sitting currently removes avatar from physical scene + + uint flags = agentData.AgentData.ControlFlags; + LLQuaternion bodyRotation = agentData.AgentData.BodyRotation; + + // Camera location in world. We'll need to raytrace + // from this location from time to time. + m_CameraCenter.x = agentData.AgentData.CameraCenter.X; + m_CameraCenter.y = agentData.AgentData.CameraCenter.Y; + m_CameraCenter.z = agentData.AgentData.CameraCenter.Z; + + + // Use these three vectors to figure out what the agent is looking at + // Convert it to a Matrix and/or Quaternion + m_CameraAtAxis.x = agentData.AgentData.CameraAtAxis.X; + m_CameraAtAxis.y = agentData.AgentData.CameraAtAxis.Y; + m_CameraAtAxis.z = agentData.AgentData.CameraAtAxis.Z; + + m_CameraLeftAxis.x = agentData.AgentData.CameraLeftAxis.X; + m_CameraLeftAxis.y = agentData.AgentData.CameraLeftAxis.Y; + m_CameraLeftAxis.z = agentData.AgentData.CameraLeftAxis.Z; + + m_CameraUpAxis.x = agentData.AgentData.CameraUpAxis.X; + m_CameraUpAxis.y = agentData.AgentData.CameraUpAxis.Y; + m_CameraUpAxis.z = agentData.AgentData.CameraUpAxis.Z; + + // The Agent's Draw distance setting + m_DrawDistance = agentData.AgentData.Far; + + // We don't know the agent's draw distance until the first agentUpdate packet + //if (m_DrawDistance > 0) + //{ + //if (!m_gotAllObjectsInScene && m_DrawDistance > 0) + //{ + // This will need to end up being a space based invalidator + // where we send object updates on spaces in 3d space (possibily a cube) + // that the avatar hasn't been surrounding it's draw distance. + // It would be better if the distance increased incrementally + // until there was no space to update because either the avatar's draw + // distance is smaller then the space they've been or the avatar has explored + // all the space in the sim. + + //m_scene.SendAllSceneObjectsToClient(this); + //m_gotAllObjectsInScene = true; + //} + //} + //MainLog.Instance.Verbose("CAMERA", "AtAxis:" + m_CameraAtAxis.ToString() + " Center:" + m_CameraCenter.ToString() + " LeftAxis:" + m_CameraLeftAxis.ToString() + " UpAxis:" + m_CameraUpAxis.ToString() + " Far:" + m_CameraFar); + + if ((flags & (uint) MainAvatar.ControlFlags.AGENT_CONTROL_STAND_UP) != 0) { StandUp(); @@ -999,10 +1065,6 @@ namespace OpenSim.Region.Environment.Scenes { SendOwnWearables( ); - //Ugly hack x.x - Trap set appearence to send all objects in this scene! - - m_scene.SendAllSceneObjectsToClient(this); - m_gotAllObjectsInScene = true; // TODO: remove this once the SunModule is slightly more tested // m_controllingClient.SendViewerTime(m_scene.TimePhase); } diff --git a/OpenSim/Region/Examples/SimpleApp/MyNpcCharacter.cs b/OpenSim/Region/Examples/SimpleApp/MyNpcCharacter.cs index f7af2f2f5c..65c8ee7e20 100644 --- a/OpenSim/Region/Examples/SimpleApp/MyNpcCharacter.cs +++ b/OpenSim/Region/Examples/SimpleApp/MyNpcCharacter.cs @@ -364,7 +364,10 @@ namespace SimpleApp if (OnAgentUpdate != null) { - OnAgentUpdate(this, movementFlag, bodyDirection); + AgentUpdatePacket pack = new AgentUpdatePacket(); + pack.AgentData.ControlFlags = movementFlag; + pack.AgentData.BodyRotation = bodyDirection; + OnAgentUpdate(this, pack); } if (flyState == 0) {