From b1c8d0588829dfa76f89460eeb8406d9c4fc479f Mon Sep 17 00:00:00 2001 From: Master ScienceSim Date: Wed, 20 Oct 2010 16:17:54 -0700 Subject: Major refactoring of appearance handling. AvatarService -- add two new methods, GetAppearance and SetAppearance to get around the lossy encoding in AvatarData. Preseve the old functions to avoid changing the behavior for ROBUST services. AvatarAppearance -- major refactor, moved the various encoding methods used by AgentCircuitData, ClientAgentUpdate and ScenePresence into one location. Changed initialization. AvatarAttachments -- added a class specifically to handle attachments in preparation for additional functionality that will be needed for viewer 2. AvatarFactory -- removed a number of unused or methods duplicated in other locations. Moved in all appearance event handling from ScenePresence. Required a change to IClientAPI that propogated throughout all the IClientAPI implementations. --- .../Region/Framework/Interfaces/IAvatarFactory.cs | 38 ----- OpenSim/Region/Framework/Scenes/Scene.cs | 7 - OpenSim/Region/Framework/Scenes/ScenePresence.cs | 163 +++++++-------------- 3 files changed, 49 insertions(+), 159 deletions(-) delete mode 100644 OpenSim/Region/Framework/Interfaces/IAvatarFactory.cs (limited to 'OpenSim/Region/Framework') diff --git a/OpenSim/Region/Framework/Interfaces/IAvatarFactory.cs b/OpenSim/Region/Framework/Interfaces/IAvatarFactory.cs deleted file mode 100644 index c967f30..0000000 --- a/OpenSim/Region/Framework/Interfaces/IAvatarFactory.cs +++ /dev/null @@ -1,38 +0,0 @@ -/* - * Copyright (c) Contributors, http://opensimulator.org/ - * See CONTRIBUTORS.TXT for a full list of copyright holders. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * * Neither the name of the OpenSimulator Project nor the - * names of its contributors may be used to endorse or promote products - * derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY - * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY - * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -using OpenMetaverse; -using OpenSim.Framework; - -namespace OpenSim.Region.Framework.Interfaces -{ - public interface IAvatarFactory - { - bool TryGetAvatarAppearance(UUID avatarId, out AvatarAppearance appearance); - void UpdateDatabase(UUID userID, AvatarAppearance avatAppearance); - } -} diff --git a/OpenSim/Region/Framework/Scenes/Scene.cs b/OpenSim/Region/Framework/Scenes/Scene.cs index 0cfc235..c69c9b1 100644 --- a/OpenSim/Region/Framework/Scenes/Scene.cs +++ b/OpenSim/Region/Framework/Scenes/Scene.cs @@ -119,7 +119,6 @@ namespace OpenSim.Region.Framework.Scenes protected IXMLRPC m_xmlrpcModule; protected IWorldComm m_worldCommModule; - protected IAvatarFactory m_AvatarFactory; protected IConfigSource m_config; protected IRegionSerialiserModule m_serialiser; protected IDialogModule m_dialogModule; @@ -399,11 +398,6 @@ namespace OpenSim.Region.Framework.Scenes public IAttachmentsModule AttachmentsModule { get; set; } - public IAvatarFactory AvatarFactory - { - get { return m_AvatarFactory; } - } - public ICapabilitiesModule CapsModule { get { return m_capsModule; } @@ -1161,7 +1155,6 @@ namespace OpenSim.Region.Framework.Scenes m_xmlrpcModule = RequestModuleInterface(); m_worldCommModule = RequestModuleInterface(); XferManager = RequestModuleInterface(); - m_AvatarFactory = RequestModuleInterface(); AttachmentsModule = RequestModuleInterface(); m_serialiser = RequestModuleInterface(); m_dialogModule = RequestModuleInterface(); diff --git a/OpenSim/Region/Framework/Scenes/ScenePresence.cs b/OpenSim/Region/Framework/Scenes/ScenePresence.cs index 13d9964..5dc48d7 100644 --- a/OpenSim/Region/Framework/Scenes/ScenePresence.cs +++ b/OpenSim/Region/Framework/Scenes/ScenePresence.cs @@ -75,7 +75,6 @@ namespace OpenSim.Region.Framework.Scenes private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); - private static readonly byte[] BAKE_INDICES = new byte[] { 8, 9, 10, 11, 19, 20 }; // private static readonly byte[] DEFAULT_TEXTURE = AvatarAppearance.GetDefaultTexture().GetBytes(); private static readonly Array DIR_CONTROL_FLAGS = Enum.GetValues(typeof(Dir_ControlFlags)); private static readonly Vector3 HEAD_ADJUSTMENT = new Vector3(0f, 0f, 0.3f); @@ -137,8 +136,6 @@ namespace OpenSim.Region.Framework.Scenes private SendCourseLocationsMethod m_sendCourseLocationsMethod; - private bool m_startAnimationSet; - //private Vector3 m_requestedSitOffset = new Vector3(); private Vector3 m_LastFinitePos; @@ -713,13 +710,14 @@ namespace OpenSim.Region.Framework.Scenes SetDirectionVectors(); } +/* public ScenePresence(IClientAPI client, Scene world, RegionInfo reginfo, byte[] visualParams, AvatarWearable[] wearables) : this(client, world, reginfo) { m_appearance = new AvatarAppearance(m_uuid, wearables, visualParams); } - +*/ public ScenePresence(IClientAPI client, Scene world, RegionInfo reginfo, AvatarAppearance appearance) : this(client, world, reginfo) { @@ -733,8 +731,6 @@ namespace OpenSim.Region.Framework.Scenes public void RegisterToEvents() { - m_controllingClient.OnRequestWearables += SendWearables; - m_controllingClient.OnSetAppearance += SetAppearance; m_controllingClient.OnCompleteMovementToRegion += CompleteMovement; //m_controllingClient.OnCompleteMovementToRegion += SendInitialData; m_controllingClient.OnAgentUpdate += HandleAgentUpdate; @@ -1068,7 +1064,7 @@ namespace OpenSim.Region.Framework.Scenes /// /// Sets avatar height in the phyiscs plugin /// - internal void SetHeight(float height) + public void SetHeight(float height) { m_avHeight = height; if (PhysicsActor != null && !IsChildAgent) @@ -1133,7 +1129,6 @@ namespace OpenSim.Region.Framework.Scenes if (friendsModule != null) friendsModule.SendFriendsOnlineIfNeeded(ControllingClient); } - } /// @@ -2392,9 +2387,12 @@ namespace OpenSim.Region.Framework.Scenes if (m_appearance.Texture == null) return; - Vector3 pos = m_pos; - pos.Z += m_appearance.HipOffset; - + if (IsChildAgent) + { + m_log.WarnFormat("[SCENEPRESENCE] A child agent is attempting to send out avatar data"); + return; + } + remoteAvatar.m_controllingClient.SendAvatarDataImmediate(this); m_scene.StatsReporter.AddAgentUpdates(1); } @@ -2437,6 +2435,12 @@ namespace OpenSim.Region.Framework.Scenes m_perfMonMS = Util.EnvironmentTickCount(); // only send update from root agents to other clients; children are only "listening posts" + if (IsChildAgent) + { + m_log.Warn("[SCENEPRESENCE] attempt to send update from a childagent"); + return; + } + int count = 0; m_scene.ForEachScenePresence(delegate(ScenePresence sp) { @@ -2460,29 +2464,20 @@ namespace OpenSim.Region.Framework.Scenes // the inventory arrives // m_scene.GetAvatarAppearance(m_controllingClient, out m_appearance); - Vector3 pos = m_pos; - pos.Z += m_appearance.HipOffset; - m_controllingClient.SendAvatarDataImmediate(this); + m_controllingClient.SendAppearance(m_appearance.Owner,m_appearance.VisualParams,m_appearance.Texture.GetBytes()); SendInitialFullUpdateToAllClients(); } /// - /// Tell the client for this scene presence what items it should be wearing now - /// - public void SendWearables() - { - m_log.DebugFormat("[SCENE]: Received request for wearables of {0}", Name); - - ControllingClient.SendWearables(m_appearance.Wearables, m_appearance.Serial++); - } - - /// /// /// public void SendAppearanceToAllOtherAgents() { +// DEBUG ON + m_log.WarnFormat("[SP] Send appearance from {0} to all other agents",m_uuid); +// DEBUG OFF m_perfMonMS = Util.EnvironmentTickCount(); m_scene.ForEachScenePresence(delegate(ScenePresence scenePresence) @@ -2502,87 +2497,13 @@ namespace OpenSim.Region.Framework.Scenes /// public void SendAppearanceToOtherAgent(ScenePresence avatar) { +// DEBUG ON + m_log.WarnFormat("[SP] Send appearance from {0} to {1}",m_uuid,avatar.ControllingClient.AgentId); +// DEBUG OFF avatar.ControllingClient.SendAppearance( m_appearance.Owner, m_appearance.VisualParams, m_appearance.Texture.GetBytes()); } - /// - /// Set appearance data (textureentry and slider settings) received from the client - /// - /// - /// - public void SetAppearance(Primitive.TextureEntry textureEntry, byte[] visualParams) - { - if (m_physicsActor != null) - { - if (!IsChildAgent) - { - // This may seem like it's redundant, remove the avatar from the physics scene - // just to add it back again, but it saves us from having to update - // 3 variables 10 times a second. - bool flyingTemp = m_physicsActor.Flying; - RemoveFromPhysicalScene(); - //m_scene.PhysicsScene.RemoveAvatar(m_physicsActor); - - //PhysicsActor = null; - - AddToPhysicalScene(flyingTemp); - } - } - - #region Bake Cache Check - - if (textureEntry != null) - { - for (int i = 0; i < BAKE_INDICES.Length; i++) - { - int j = BAKE_INDICES[i]; - Primitive.TextureEntryFace face = textureEntry.FaceTextures[j]; - - if (face != null && face.TextureID != AppearanceManager.DEFAULT_AVATAR_TEXTURE) - { - if (m_scene.AssetService.Get(face.TextureID.ToString()) == null) - { - m_log.Warn("[APPEARANCE]: Missing baked texture " + face.TextureID + " (" + j + ") for avatar " + this.Name); - this.ControllingClient.SendRebakeAvatarTextures(face.TextureID); - } - } - } - - } - - - #endregion Bake Cache Check - - m_appearance.SetAppearance(textureEntry, visualParams); - if (m_appearance.AvatarHeight > 0) - SetHeight(m_appearance.AvatarHeight); - - // This is not needed, because only the transient data changed - //AvatarData adata = new AvatarData(m_appearance); - //m_scene.AvatarService.SetAvatar(m_controllingClient.AgentId, adata); - - SendAppearanceToAllOtherAgents(); - if (!m_startAnimationSet) - { - Animator.UpdateMovementAnimations(); - m_startAnimationSet = true; - } - - Vector3 pos = m_pos; - pos.Z += m_appearance.HipOffset; - - m_controllingClient.SendAvatarDataImmediate(this); - } - - public void SetWearable(int wearableId, AvatarWearable wearable) - { - m_appearance.SetWearable(wearableId, wearable); - AvatarData adata = new AvatarData(m_appearance); - m_scene.AvatarService.SetAvatar(m_controllingClient.AgentId, adata); - m_controllingClient.SendWearables(m_appearance.Wearables, m_appearance.Serial++); - } - // Because appearance setting is in a module, we actually need // to give it access to our appearance directly, otherwise we // get a synchronization issue. @@ -2976,6 +2897,9 @@ namespace OpenSim.Region.Framework.Scenes public void CopyTo(AgentData cAgent) { +// DEBUG ON + m_log.ErrorFormat("[SCENEPRESENCE] CALLING COPYTO"); +// DEBUG OFF cAgent.AgentID = UUID; cAgent.RegionID = Scene.RegionInfo.RegionID; @@ -3015,6 +2939,9 @@ namespace OpenSim.Region.Framework.Scenes cAgent.AlwaysRun = m_setAlwaysRun; + cAgent.Appearance = new AvatarAppearance(m_appearance); + +/* try { // We might not pass the Wearables in all cases... @@ -3054,14 +2981,14 @@ namespace OpenSim.Region.Framework.Scenes { //m_log.DebugFormat("[SCENE PRESENCE]: attachments {0}", attPoints.Count); int i = 0; - AttachmentData[] attachs = new AttachmentData[attPoints.Count]; + AvatarAttachment[] attachs = new AvatarAttachment[attPoints.Count]; foreach (int point in attPoints) { - attachs[i++] = new AttachmentData(point, m_appearance.GetAttachedItem(point), m_appearance.GetAttachedAsset(point)); + attachs[i++] = new AvatarAttachment(point, m_appearance.GetAttachedItem(point), m_appearance.GetAttachedAsset(point)); } cAgent.Attachments = attachs; } - +*/ lock (scriptedcontrols) { ControllerData[] controls = new ControllerData[scriptedcontrols.Count]; @@ -3088,6 +3015,9 @@ namespace OpenSim.Region.Framework.Scenes public void CopyFrom(AgentData cAgent) { +// DEBUG ON + m_log.ErrorFormat("[SCENEPRESENCE] CALLING COPYFROM"); +// DEBUG OFF m_originRegionID = cAgent.RegionID; m_callbackURI = cAgent.CallbackURI; @@ -3113,6 +3043,9 @@ namespace OpenSim.Region.Framework.Scenes m_godLevel = cAgent.GodLevel; m_setAlwaysRun = cAgent.AlwaysRun; + m_appearance = new AvatarAppearance(cAgent.Appearance); + +/* uint i = 0; try { @@ -3125,15 +3058,17 @@ namespace OpenSim.Region.Framework.Scenes UUID assetId = cAgent.Wearables[n + 1]; wears[i++] = new AvatarWearable(itemId, assetId); } - m_appearance.Wearables = wears; - Primitive.TextureEntry te; + // m_appearance.Wearables = wears; + Primitive.TextureEntry textures = null; if (cAgent.AgentTextures != null && cAgent.AgentTextures.Length > 1) - te = new Primitive.TextureEntry(cAgent.AgentTextures, 0, cAgent.AgentTextures.Length); - else - te = AvatarAppearance.GetDefaultTexture(); - if ((cAgent.VisualParams == null) || (cAgent.VisualParams.Length < AvatarAppearance.VISUALPARAM_COUNT)) - cAgent.VisualParams = AvatarAppearance.GetDefaultVisualParams(); - m_appearance.SetAppearance(te, (byte[])cAgent.VisualParams.Clone()); + textures = new Primitive.TextureEntry(cAgent.AgentTextures, 0, cAgent.AgentTextures.Length); + + byte[] visuals = null; + + if ((cAgent.VisualParams != null) && (cAgent.VisualParams.Length < AvatarAppearance.VISUALPARAM_COUNT)) + visuals = (byte[])cAgent.VisualParams.Clone(); + + m_appearance = new AvatarAppearance(cAgent.AgentID,wears,textures,visuals); } catch (Exception e) { @@ -3146,14 +3081,14 @@ namespace OpenSim.Region.Framework.Scenes if (cAgent.Attachments != null) { m_appearance.ClearAttachments(); - foreach (AttachmentData att in cAgent.Attachments) + foreach (AvatarAttachment att in cAgent.Attachments) { m_appearance.SetAttachment(att.AttachPoint, att.ItemID, att.AssetID); } } } catch { } - +*/ try { lock (scriptedcontrols) -- cgit v1.1