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/ClientStack/LindenUDP/LLClientView.cs | 8 +- .../Avatar/Attachments/AttachmentsModule.cs | 16 +- .../Avatar/AvatarFactory/AvatarFactoryModule.cs | 237 +++++++++++++-------- .../Avatar/LocalAvatarServiceConnector.cs | 11 + .../Region/Examples/SimpleModule/MyNpcCharacter.cs | 2 +- .../Region/Framework/Interfaces/IAvatarFactory.cs | 38 ---- OpenSim/Region/Framework/Scenes/Scene.cs | 7 - OpenSim/Region/Framework/Scenes/ScenePresence.cs | 163 +++++--------- .../Server/IRCClientView.cs | 4 +- .../Region/OptionalModules/World/NPC/NPCAvatar.cs | 2 +- .../Region/OptionalModules/World/NPC/NPCModule.cs | 16 +- 11 files changed, 234 insertions(+), 270 deletions(-) delete mode 100644 OpenSim/Region/Framework/Interfaces/IAvatarFactory.cs (limited to 'OpenSim/Region') diff --git a/OpenSim/Region/ClientStack/LindenUDP/LLClientView.cs b/OpenSim/Region/ClientStack/LindenUDP/LLClientView.cs index 48d5a12..426e1df 100644 --- a/OpenSim/Region/ClientStack/LindenUDP/LLClientView.cs +++ b/OpenSim/Region/ClientStack/LindenUDP/LLClientView.cs @@ -79,7 +79,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP public event DeRezObject OnDeRezObject; public event ModifyTerrain OnModifyTerrain; public event Action OnRegionHandShakeReply; - public event GenericCall2 OnRequestWearables; + public event GenericCall1 OnRequestWearables; public event SetAppearance OnSetAppearance; public event AvatarNowWearing OnAvatarNowWearing; public event RezSingleAttachmentFromInv OnRezSingleAttachmentFromInv; @@ -5647,11 +5647,11 @@ namespace OpenSim.Region.ClientStack.LindenUDP private bool HandlerAgentWearablesRequest(IClientAPI sender, Packet Pack) { - GenericCall2 handlerRequestWearables = OnRequestWearables; + GenericCall1 handlerRequestWearables = OnRequestWearables; if (handlerRequestWearables != null) { - handlerRequestWearables(); + handlerRequestWearables(sender); } Action handlerRequestAvatarsData = OnRequestAvatarsData; @@ -5694,7 +5694,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP if (appear.ObjectData.TextureEntry.Length > 1) te = new Primitive.TextureEntry(appear.ObjectData.TextureEntry, 0, appear.ObjectData.TextureEntry.Length); - handlerSetAppearance(te, visualparams); + handlerSetAppearance(sender, te, visualparams); } catch (Exception e) { diff --git a/OpenSim/Region/CoreModules/Avatar/Attachments/AttachmentsModule.cs b/OpenSim/Region/CoreModules/Avatar/Attachments/AttachmentsModule.cs index 2a0c0b1..ad6b1de 100644 --- a/OpenSim/Region/CoreModules/Avatar/Attachments/AttachmentsModule.cs +++ b/OpenSim/Region/CoreModules/Avatar/Attachments/AttachmentsModule.cs @@ -124,13 +124,13 @@ namespace OpenSim.Region.CoreModules.Avatar.Attachments // Save avatar attachment information ScenePresence presence; - if (m_scene.AvatarFactory != null && m_scene.TryGetScenePresence(remoteClient.AgentId, out presence)) + if (m_scene.AvatarService != null && m_scene.TryGetScenePresence(remoteClient.AgentId, out presence)) { m_log.Info( "[ATTACHMENTS MODULE]: Saving avatar attachment. AgentID: " + remoteClient.AgentId + ", AttachmentPoint: " + AttachmentPt); - m_scene.AvatarFactory.UpdateDatabase(remoteClient.AgentId, presence.Appearance); + m_scene.AvatarService.SetAppearance(remoteClient.AgentId, presence.Appearance); } } } @@ -382,8 +382,8 @@ namespace OpenSim.Region.CoreModules.Avatar.Attachments item = m_scene.InventoryService.GetItem(item); presence.Appearance.SetAttachment((int)AttachmentPt, itemID, item.AssetID /* att.UUID */); - if (m_scene.AvatarFactory != null) - m_scene.AvatarFactory.UpdateDatabase(remoteClient.AgentId, presence.Appearance); + if (m_scene.AvatarService != null) + m_scene.AvatarService.SetAppearance(remoteClient.AgentId, presence.Appearance); } } @@ -405,10 +405,10 @@ namespace OpenSim.Region.CoreModules.Avatar.Attachments presence.Appearance.DetachAttachment(itemID); // Save avatar attachment information - if (m_scene.AvatarFactory != null) + if (m_scene.AvatarService != null) { m_log.Debug("[ATTACHMENTS MODULE]: Detaching from UserID: " + remoteClient.AgentId + ", ItemID: " + itemID); - m_scene.AvatarFactory.UpdateDatabase(remoteClient.AgentId, presence.Appearance); + m_scene.AvatarService.SetAppearance(remoteClient.AgentId, presence.Appearance); } } @@ -435,9 +435,9 @@ namespace OpenSim.Region.CoreModules.Avatar.Attachments presence.Appearance.DetachAttachment(itemID); - if (m_scene.AvatarFactory != null) + if (m_scene.AvatarService != null) { - m_scene.AvatarFactory.UpdateDatabase(remoteClient.AgentId, presence.Appearance); + m_scene.AvatarService.SetAppearance(remoteClient.AgentId, presence.Appearance); } part.ParentGroup.DetachToGround(); diff --git a/OpenSim/Region/CoreModules/Avatar/AvatarFactory/AvatarFactoryModule.cs b/OpenSim/Region/CoreModules/Avatar/AvatarFactory/AvatarFactoryModule.cs index 22c8937..9f7ff7f 100644 --- a/OpenSim/Region/CoreModules/Avatar/AvatarFactory/AvatarFactoryModule.cs +++ b/OpenSim/Region/CoreModules/Avatar/AvatarFactory/AvatarFactoryModule.cs @@ -38,48 +38,20 @@ using OpenSim.Services.Interfaces; namespace OpenSim.Region.CoreModules.Avatar.AvatarFactory { - public class AvatarFactoryModule : IAvatarFactory, IRegionModule + public class AvatarFactoryModule : IRegionModule { 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 Scene m_scene = null; - private static readonly AvatarAppearance def = new AvatarAppearance(); - public bool TryGetAvatarAppearance(UUID avatarId, out AvatarAppearance appearance) - { - AvatarData avatar = m_scene.AvatarService.GetAvatar(avatarId); - //if ((profile != null) && (profile.RootFolder != null)) - if (avatar != null) - { - appearance = avatar.ToAvatarAppearance(avatarId); - return true; - } - - m_log.ErrorFormat("[APPEARANCE]: Appearance not found for {0}, creating default", avatarId); - appearance = CreateDefault(avatarId); - return false; - } - - private AvatarAppearance CreateDefault(UUID avatarId) - { - AvatarAppearance appearance = null; - AvatarWearable[] wearables; - byte[] visualParams; - GetDefaultAvatarAppearance(out wearables, out visualParams); - appearance = new AvatarAppearance(avatarId, wearables, visualParams); - - return appearance; - } + private bool m_startAnimationSet = false; public void Initialise(Scene scene, IConfigSource source) { - scene.RegisterModuleInterface(this); scene.EventManager.OnNewClient += NewClient; if (m_scene == null) - { m_scene = scene; - } - } public void PostInitialise() @@ -102,6 +74,8 @@ namespace OpenSim.Region.CoreModules.Avatar.AvatarFactory public void NewClient(IClientAPI client) { + client.OnRequestWearables += SendWearables; + client.OnSetAppearance += SetAppearance; client.OnAvatarNowWearing += AvatarIsWearing; } @@ -110,42 +84,115 @@ namespace OpenSim.Region.CoreModules.Avatar.AvatarFactory // client.OnAvatarNowWearing -= AvatarIsWearing; } - public void SetAppearanceAssets(UUID userID, ref AvatarAppearance appearance) + /// + /// Set appearance data (textureentry and slider settings) received from the client + /// + /// + /// + public void SetAppearance(IClientAPI client, Primitive.TextureEntry textureEntry, byte[] visualParams) { - IInventoryService invService = m_scene.InventoryService; + ScenePresence sp = m_scene.GetScenePresence(client.AgentId); + if (sp == null) + { + m_log.WarnFormat("[AVFACTORY] SetAppearance unable to find presence for {0}",client.AgentId); + return; + } + +// DEBUG ON + m_log.WarnFormat("[AVFACTORY] SetAppearance for {0}",client.AgentId); +// DEBUG OFF - if (invService.GetRootFolder(userID) != null) +/* + if (m_physicsActor != null) { - for (int i = 0; i < 13; i++) + if (!IsChildAgent) { - if (appearance.Wearables[i].ItemID == UUID.Zero) - { - appearance.Wearables[i].AssetID = UUID.Zero; - } - else - { - InventoryItemBase baseItem = new InventoryItemBase(appearance.Wearables[i].ItemID, userID); - baseItem = invService.GetItem(baseItem); + // 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); - if (baseItem != null) - { - appearance.Wearables[i].AssetID = baseItem.AssetID; - } - else + //PhysicsActor = null; + + AddToPhysicalScene(flyingTemp); + } + } +*/ + #region Bake Cache Check + + bool changed = false; + + // Process the texture entry + 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.ErrorFormat( - "[APPEARANCE]: Can't find inventory item {0} for {1}, setting to default", - appearance.Wearables[i].ItemID, (WearableType)i); - - appearance.Wearables[i].AssetID = def.Wearables[i].AssetID; + m_log.WarnFormat("[AVFACTORY]: Missing baked texture {0} ({1}) for avatar {2}",face.TextureID,j,this.Name); + client.SendRebakeAvatarTextures(face.TextureID); } } } + changed = sp.Appearance.SetTextureEntries(textureEntry); + + } + + #endregion Bake Cache Check + + changed = sp.Appearance.SetVisualParams(visualParams) || changed; + + // If nothing changed (this happens frequently) just return + if (changed) + { +// DEBUG ON + m_log.Warn("[AVFACTORY] Appearance changed"); +// DEBUG OFF + sp.Appearance.SetAppearance(textureEntry, visualParams); + if (sp.Appearance.AvatarHeight > 0) + sp.SetHeight(sp.Appearance.AvatarHeight); + + m_scene.AvatarService.SetAppearance(client.AgentId, sp.Appearance); } +// DEBUG ON else + m_log.Warn("[AVFACTORY] Appearance did not change"); +// DEBUG OFF + + sp.SendAppearanceToAllOtherAgents(); + if (!m_startAnimationSet) + { + sp.Animator.UpdateMovementAnimations(); + m_startAnimationSet = true; + } + + client.SendAvatarDataImmediate(sp); + client.SendAppearance(sp.Appearance.Owner,sp.Appearance.VisualParams,sp.Appearance.Texture.GetBytes()); + } + + /// + /// Tell the client for this scene presence what items it should be wearing now + /// + public void SendWearables(IClientAPI client) + { + ScenePresence sp = m_scene.GetScenePresence(client.AgentId); + if (sp == null) { - m_log.WarnFormat("[APPEARANCE]: user {0} has no inventory, appearance isn't going to work", userID); + m_log.WarnFormat("[AVFACTORY] SendWearables unable to find presence for {0}",client.AgentId); + return; } + +// DEBUG ON + m_log.WarnFormat("[AVFACTORY]: Received request for wearables of {0}", client.AgentId); +// DEBUG OFF + client.SendWearables(sp.Appearance.Wearables,sp.Appearance.Serial++); } /// @@ -153,65 +200,81 @@ namespace OpenSim.Region.CoreModules.Avatar.AvatarFactory /// /// /// - public void AvatarIsWearing(Object sender, AvatarWearingArgs e) + public void AvatarIsWearing(IClientAPI client, AvatarWearingArgs e) { - m_log.DebugFormat("[APPEARANCE]: AvatarIsWearing"); - - IClientAPI clientView = (IClientAPI)sender; - ScenePresence sp = m_scene.GetScenePresence(clientView.AgentId); - - if (sp == null) + ScenePresence sp = m_scene.GetScenePresence(client.AgentId); + if (sp == null) { - m_log.Error("[APPEARANCE]: Avatar is child agent, ignoring AvatarIsWearing event"); + m_log.WarnFormat("[AVFACTORY] AvatarIsWearing unable to find presence for {0}",client.AgentId); return; } + +// DEBUG ON + m_log.WarnFormat("[AVFACTORY]: AvatarIsWearing called for {0}",client.AgentId); +// DEBUG OFF + + AvatarAppearance avatAppearance = new AvatarAppearance(sp.Appearance); - AvatarAppearance avatAppearance = sp.Appearance; - //if (!TryGetAvatarAppearance(clientView.AgentId, out avatAppearance)) + //if (!TryGetAvatarAppearance(client.AgentId, out avatAppearance)) //{ - // m_log.Warn("[APPEARANCE]: We didn't seem to find the appearance, falling back to ScenePresence"); + // m_log.Warn("[AVFACTORY]: We didn't seem to find the appearance, falling back to ScenePresence"); // avatAppearance = sp.Appearance; //} - //m_log.DebugFormat("[APPEARANCE]: Received wearables for {0}", clientView.Name); + //m_log.DebugFormat("[AVFACTORY]: Received wearables for {0}", client.Name); foreach (AvatarWearingArgs.Wearable wear in e.NowWearing) { - if (wear.Type < 13) + if (wear.Type < AvatarWearable.MAX_WEARABLES) { - avatAppearance.Wearables[wear.Type].ItemID = wear.ItemID; + AvatarWearable newWearable = new AvatarWearable(wear.ItemID,UUID.Zero); + avatAppearance.SetWearable(wear.Type, newWearable); } } SetAppearanceAssets(sp.UUID, ref avatAppearance); - AvatarData adata = new AvatarData(avatAppearance); - m_scene.AvatarService.SetAvatar(clientView.AgentId, adata); + m_scene.AvatarService.SetAppearance(client.AgentId, avatAppearance); sp.Appearance = avatAppearance; } - public static void GetDefaultAvatarAppearance(out AvatarWearable[] wearables, out byte[] visualParams) + private void SetAppearanceAssets(UUID userID, ref AvatarAppearance appearance) { - visualParams = GetDefaultVisualParams(); - wearables = AvatarWearable.DefaultWearables; - } + IInventoryService invService = m_scene.InventoryService; - public void UpdateDatabase(UUID user, AvatarAppearance appearance) - { - //m_log.DebugFormat("[APPEARANCE]: UpdateDatabase"); - AvatarData adata = new AvatarData(appearance); - m_scene.AvatarService.SetAvatar(user, adata); - } + if (invService.GetRootFolder(userID) != null) + { + for (int i = 0; i < AvatarWearable.MAX_WEARABLES; i++) + { + if (appearance.Wearables[i].ItemID == UUID.Zero) + { + appearance.Wearables[i].AssetID = UUID.Zero; + } + else + { + InventoryItemBase baseItem = new InventoryItemBase(appearance.Wearables[i].ItemID, userID); + baseItem = invService.GetItem(baseItem); - private static byte[] GetDefaultVisualParams() - { - byte[] visualParams; - visualParams = new byte[218]; - for (int i = 0; i < 218; i++) + if (baseItem != null) + { + appearance.Wearables[i].AssetID = baseItem.AssetID; + } + else + { + m_log.ErrorFormat( + "[AVFACTORY]: Can't find inventory item {0} for {1}, setting to default", + appearance.Wearables[i].ItemID, (WearableType)i); + + appearance.Wearables[i].ItemID = UUID.Zero; + appearance.Wearables[i].AssetID = UUID.Zero; + } + } + } + } + else { - visualParams[i] = 100; + m_log.WarnFormat("[AVFACTORY]: user {0} has no inventory, appearance isn't going to work", userID); } - return visualParams; } } } diff --git a/OpenSim/Region/CoreModules/ServiceConnectorsOut/Avatar/LocalAvatarServiceConnector.cs b/OpenSim/Region/CoreModules/ServiceConnectorsOut/Avatar/LocalAvatarServiceConnector.cs index 47f19a3..9ee19f8 100644 --- a/OpenSim/Region/CoreModules/ServiceConnectorsOut/Avatar/LocalAvatarServiceConnector.cs +++ b/OpenSim/Region/CoreModules/ServiceConnectorsOut/Avatar/LocalAvatarServiceConnector.cs @@ -30,6 +30,7 @@ using System.Collections.Generic; using System.Reflection; using log4net; using Nini.Config; +using OpenSim.Framework; using OpenSim.Region.Framework.Interfaces; using OpenSim.Region.Framework.Scenes; using OpenSim.Server.Base; @@ -137,6 +138,16 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Avatar #region IAvatarService + public AvatarAppearance GetAppearance(UUID userID) + { + return m_AvatarService.GetAppearance(userID); + } + + public bool SetAppearance(UUID userID, AvatarAppearance appearance) + { + return m_AvatarService.SetAppearance(userID,appearance); + } + public AvatarData GetAvatar(UUID userID) { return m_AvatarService.GetAvatar(userID); diff --git a/OpenSim/Region/Examples/SimpleModule/MyNpcCharacter.cs b/OpenSim/Region/Examples/SimpleModule/MyNpcCharacter.cs index 268612e..f128aa2 100644 --- a/OpenSim/Region/Examples/SimpleModule/MyNpcCharacter.cs +++ b/OpenSim/Region/Examples/SimpleModule/MyNpcCharacter.cs @@ -82,7 +82,7 @@ namespace OpenSim.Region.Examples.SimpleModule public event DeRezObject OnDeRezObject; public event Action OnRegionHandShakeReply; - public event GenericCall2 OnRequestWearables; + public event GenericCall1 OnRequestWearables; public event GenericCall1 OnCompleteMovementToRegion; public event UpdateAgent OnPreAgentUpdate; public event UpdateAgent OnAgentUpdate; 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) diff --git a/OpenSim/Region/OptionalModules/Agent/InternetRelayClientView/Server/IRCClientView.cs b/OpenSim/Region/OptionalModules/Agent/InternetRelayClientView/Server/IRCClientView.cs index 159af79..fc17192 100644 --- a/OpenSim/Region/OptionalModules/Agent/InternetRelayClientView/Server/IRCClientView.cs +++ b/OpenSim/Region/OptionalModules/Agent/InternetRelayClientView/Server/IRCClientView.cs @@ -676,7 +676,7 @@ namespace OpenSim.Region.OptionalModules.Agent.InternetRelayClientView.Server public event TeleportLandmarkRequest OnTeleportLandmarkRequest; public event DeRezObject OnDeRezObject; public event Action OnRegionHandShakeReply; - public event GenericCall2 OnRequestWearables; + public event GenericCall1 OnRequestWearables; public event GenericCall1 OnCompleteMovementToRegion; public event UpdateAgent OnPreAgentUpdate; public event UpdateAgent OnAgentUpdate; @@ -899,7 +899,7 @@ namespace OpenSim.Region.OptionalModules.Agent.InternetRelayClientView.Server Scene scene = (Scene)Scene; AvatarAppearance appearance; scene.GetAvatarAppearance(this, out appearance); - OnSetAppearance(appearance.Texture, (byte[])appearance.VisualParams.Clone()); + OnSetAppearance(this, appearance.Texture, (byte[])appearance.VisualParams.Clone()); } public void SendRegionHandshake(RegionInfo regionInfo, RegionHandshakeArgs args) diff --git a/OpenSim/Region/OptionalModules/World/NPC/NPCAvatar.cs b/OpenSim/Region/OptionalModules/World/NPC/NPCAvatar.cs index fae12b6..6928c4e 100644 --- a/OpenSim/Region/OptionalModules/World/NPC/NPCAvatar.cs +++ b/OpenSim/Region/OptionalModules/World/NPC/NPCAvatar.cs @@ -188,7 +188,7 @@ namespace OpenSim.Region.OptionalModules.World.NPC public event DeRezObject OnDeRezObject; public event Action OnRegionHandShakeReply; - public event GenericCall2 OnRequestWearables; + public event GenericCall1 OnRequestWearables; public event GenericCall1 OnCompleteMovementToRegion; public event UpdateAgent OnPreAgentUpdate; public event UpdateAgent OnAgentUpdate; diff --git a/OpenSim/Region/OptionalModules/World/NPC/NPCModule.cs b/OpenSim/Region/OptionalModules/World/NPC/NPCModule.cs index ab0be77..c471636 100644 --- a/OpenSim/Region/OptionalModules/World/NPC/NPCModule.cs +++ b/OpenSim/Region/OptionalModules/World/NPC/NPCModule.cs @@ -64,15 +64,13 @@ namespace OpenSim.Region.OptionalModules.World.NPC if (m_appearanceCache.ContainsKey(target)) return m_appearanceCache[target]; - AvatarData adata = scene.AvatarService.GetAvatar(target); - if (adata != null) + AvatarAppearance appearance = scene.AvatarService.GetAppearance(target); + if (appearance != null) { - AvatarAppearance x = adata.ToAvatarAppearance(target); - - m_appearanceCache.Add(target, x); - - return x; + m_appearanceCache.Add(target, appearance); + return appearance; } + return new AvatarAppearance(); } @@ -169,7 +167,9 @@ namespace OpenSim.Region.OptionalModules.World.NPC { AvatarAppearance x = GetAppearance(p_cloneAppearanceFrom, p_scene); - sp.SetAppearance(x.Texture, (byte[])x.VisualParams.Clone()); + sp.Appearance.SetTextureEntries(x.Texture); + sp.Appearance.SetVisualParams((byte[])x.VisualParams.Clone()); + sp.SendAppearanceToAllOtherAgents(); } m_avatars.Add(npcAvatar.AgentId, npcAvatar); -- cgit v1.1