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. --- .../Avatar/Attachments/AttachmentsModule.cs | 16 +- .../Avatar/AvatarFactory/AvatarFactoryModule.cs | 237 +++++++++++++-------- 2 files changed, 158 insertions(+), 95 deletions(-) (limited to 'OpenSim/Region/CoreModules/Avatar') 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; } } } -- cgit v1.1 From 6e58c3d563b50c5797d1cfffbaec3fe82f18c2ea Mon Sep 17 00:00:00 2001 From: Master ScienceSim Date: Mon, 25 Oct 2010 14:11:47 -0700 Subject: Half of the compatibility is working. Login into a new region with old data works. Teleport out of a new region with old data works. Teleport into a new region with old data does not trigger the necessary rebake. --- OpenSim/Region/CoreModules/Avatar/AvatarFactory/AvatarFactoryModule.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'OpenSim/Region/CoreModules/Avatar') diff --git a/OpenSim/Region/CoreModules/Avatar/AvatarFactory/AvatarFactoryModule.cs b/OpenSim/Region/CoreModules/Avatar/AvatarFactory/AvatarFactoryModule.cs index 9f7ff7f..b74cdc9 100644 --- a/OpenSim/Region/CoreModules/Avatar/AvatarFactory/AvatarFactoryModule.cs +++ b/OpenSim/Region/CoreModules/Avatar/AvatarFactory/AvatarFactoryModule.cs @@ -136,7 +136,7 @@ namespace OpenSim.Region.CoreModules.Avatar.AvatarFactory { if (m_scene.AssetService.Get(face.TextureID.ToString()) == null) { - m_log.WarnFormat("[AVFACTORY]: Missing baked texture {0} ({1}) for avatar {2}",face.TextureID,j,this.Name); + m_log.WarnFormat("[AVFACTORY]: Missing baked texture {0} ({1}) for avatar {2}",face.TextureID,j,client.Name); client.SendRebakeAvatarTextures(face.TextureID); } } -- cgit v1.1 From 9132e251aa0d0d7395dc4868fd57799dd679cdb7 Mon Sep 17 00:00:00 2001 From: Master ScienceSim Date: Tue, 26 Oct 2010 12:53:15 -0700 Subject: Made the check for texture assets asynchronous. This is one part of a bigger clean up that needs to happen around locks on appearance. --- .../Avatar/AvatarFactory/AvatarFactoryModule.cs | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) (limited to 'OpenSim/Region/CoreModules/Avatar') diff --git a/OpenSim/Region/CoreModules/Avatar/AvatarFactory/AvatarFactoryModule.cs b/OpenSim/Region/CoreModules/Avatar/AvatarFactory/AvatarFactoryModule.cs index b74cdc9..5444f80 100644 --- a/OpenSim/Region/CoreModules/Avatar/AvatarFactory/AvatarFactoryModule.cs +++ b/OpenSim/Region/CoreModules/Avatar/AvatarFactory/AvatarFactoryModule.cs @@ -84,6 +84,15 @@ namespace OpenSim.Region.CoreModules.Avatar.AvatarFactory // client.OnAvatarNowWearing -= AvatarIsWearing; } + public void CheckBakedTextureAssets(IClientAPI client, UUID textureID, int idx) + { + if (m_scene.AssetService.Get(textureID.ToString()) == null) + { + m_log.WarnFormat("[AVFACTORY]: Missing baked texture {0} ({1}) for avatar {2}",textureID,idx,client.Name); + client.SendRebakeAvatarTextures(textureID); + } + } + /// /// Set appearance data (textureentry and slider settings) received from the client /// @@ -133,13 +142,7 @@ namespace OpenSim.Region.CoreModules.Avatar.AvatarFactory 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.WarnFormat("[AVFACTORY]: Missing baked texture {0} ({1}) for avatar {2}",face.TextureID,j,client.Name); - client.SendRebakeAvatarTextures(face.TextureID); - } - } + Util.FireAndForget(delegate(object o) { CheckBakedTextureAssets(client,face.TextureID,j); }); } changed = sp.Appearance.SetTextureEntries(textureEntry); -- cgit v1.1 From a331fd4e24012a246bea9ac11689afe933e7968e Mon Sep 17 00:00:00 2001 From: Jeff Ames Date: Wed, 27 Oct 2010 00:01:03 -0400 Subject: Formatting cleanup. --- OpenSim/Region/CoreModules/Avatar/Chat/ChatModule.cs | 2 +- .../Avatar/Inventory/Archiver/InventoryArchiveReadRequest.cs | 8 ++++---- .../Avatar/Inventory/Archiver/InventoryArchiveWriteRequest.cs | 4 ++-- 3 files changed, 7 insertions(+), 7 deletions(-) (limited to 'OpenSim/Region/CoreModules/Avatar') diff --git a/OpenSim/Region/CoreModules/Avatar/Chat/ChatModule.cs b/OpenSim/Region/CoreModules/Avatar/Chat/ChatModule.cs index d76ff47..4359c01 100644 --- a/OpenSim/Region/CoreModules/Avatar/Chat/ChatModule.cs +++ b/OpenSim/Region/CoreModules/Avatar/Chat/ChatModule.cs @@ -238,7 +238,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Chat } (scene as Scene).EventManager.TriggerOnChatToClients( - fromID, receiverIDs, message, c.Type, fromPos, fromName, sourceType, ChatAudibleLevel.Fully); + fromID, receiverIDs, message, c.Type, fromPos, fromName, sourceType, ChatAudibleLevel.Fully); } static private Vector3 CenterOfRegion = new Vector3(128, 128, 30); diff --git a/OpenSim/Region/CoreModules/Avatar/Inventory/Archiver/InventoryArchiveReadRequest.cs b/OpenSim/Region/CoreModules/Avatar/Inventory/Archiver/InventoryArchiveReadRequest.cs index 5500557..046b05f 100644 --- a/OpenSim/Region/CoreModules/Avatar/Inventory/Archiver/InventoryArchiveReadRequest.cs +++ b/OpenSim/Region/CoreModules/Avatar/Inventory/Archiver/InventoryArchiveReadRequest.cs @@ -143,7 +143,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver if (filePath == ArchiveConstants.CONTROL_FILE_PATH) { LoadControlFile(filePath, data); - } + } else if (filePath.StartsWith(ArchiveConstants.ASSETS_PATH)) { if (LoadAsset(filePath, data)) @@ -479,11 +479,11 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver /// /// protected void LoadControlFile(string path, byte[] data) - { + { XDocument doc = XDocument.Parse(Encoding.ASCII.GetString(data)); XElement archiveElement = doc.Element("archive"); int majorVersion = int.Parse(archiveElement.Attribute("major_version").Value); - int minorVersion = int.Parse(archiveElement.Attribute("minor_version").Value); + int minorVersion = int.Parse(archiveElement.Attribute("minor_version").Value); string version = string.Format("{0}.{1}", majorVersion, minorVersion); if (majorVersion > MAX_MAJOR_VERSION) @@ -492,7 +492,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver string.Format( "The IAR you are trying to load has major version number of {0} but this version of OpenSim can only load IARs with major version number {1} and below", majorVersion, MAX_MAJOR_VERSION)); - } + } m_log.InfoFormat("[INVENTORY ARCHIVER]: Loading IAR with version {0}", version); } diff --git a/OpenSim/Region/CoreModules/Avatar/Inventory/Archiver/InventoryArchiveWriteRequest.cs b/OpenSim/Region/CoreModules/Avatar/Inventory/Archiver/InventoryArchiveWriteRequest.cs index 249a8b4..9080e1c 100644 --- a/OpenSim/Region/CoreModules/Avatar/Inventory/Archiver/InventoryArchiveWriteRequest.cs +++ b/OpenSim/Region/CoreModules/Avatar/Inventory/Archiver/InventoryArchiveWriteRequest.cs @@ -213,7 +213,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver public void Execute() { try - { + { InventoryFolderBase inventoryFolder = null; InventoryItemBase inventoryItem = null; InventoryFolderBase rootFolder = m_scene.InventoryService.GetRootFolder(m_userInfo.PrincipalID); @@ -277,7 +277,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver // Write out control file. This has to be done first so that subsequent loaders will see this file first // XXX: I know this is a weak way of doing it since external non-OAR aware tar executables will not do this m_archiveWriter.WriteFile(ArchiveConstants.CONTROL_FILE_PATH, Create0p1ControlFile()); - m_log.InfoFormat("[INVENTORY ARCHIVER]: Added control file to archive."); + m_log.InfoFormat("[INVENTORY ARCHIVER]: Added control file to archive."); if (inventoryFolder != null) { -- cgit v1.1 From 0f28fa400d1f853cc3c3ebd2707b08ed06d2f127 Mon Sep 17 00:00:00 2001 From: Master ScienceSim Date: Thu, 28 Oct 2010 09:00:39 -0700 Subject: Added background thread to handle delayed send and save of appearance to accommodate batching of the many updates that happen on login and teleport. Fixed handling of the serial property in appearance. --- .../Avatar/AvatarFactory/AvatarFactoryModule.cs | 219 +++++++++++++++------ 1 file changed, 164 insertions(+), 55 deletions(-) (limited to 'OpenSim/Region/CoreModules/Avatar') diff --git a/OpenSim/Region/CoreModules/Avatar/AvatarFactory/AvatarFactoryModule.cs b/OpenSim/Region/CoreModules/Avatar/AvatarFactory/AvatarFactoryModule.cs index 5444f80..903e94b 100644 --- a/OpenSim/Region/CoreModules/Avatar/AvatarFactory/AvatarFactoryModule.cs +++ b/OpenSim/Region/CoreModules/Avatar/AvatarFactory/AvatarFactoryModule.cs @@ -32,6 +32,10 @@ using Nini.Config; using OpenMetaverse; using OpenSim.Framework; +using System.Threading; +using System.Timers; +using System.Collections.Generic; + using OpenSim.Region.Framework.Interfaces; using OpenSim.Region.Framework.Scenes; using OpenSim.Services.Interfaces; @@ -44,7 +48,15 @@ namespace OpenSim.Region.CoreModules.Avatar.AvatarFactory private static readonly byte[] BAKE_INDICES = new byte[] { 8, 9, 10, 11, 19, 20 }; private Scene m_scene = null; - private bool m_startAnimationSet = false; + private static readonly int m_savetime = 5; // seconds to wait before saving changed appearance + private static readonly int m_sendtime = 2; // seconds to wait before sending changed appearance + + private static readonly int m_checkTime = 500; // milliseconds to wait between checks for appearance updates + private System.Timers.Timer m_updateTimer = new System.Timers.Timer(); + private Dictionary m_savequeue = new Dictionary(); + private Dictionary m_sendqueue = new Dictionary(); + + #region RegionModule Members public void Initialise(Scene scene, IConfigSource source) { @@ -56,6 +68,10 @@ namespace OpenSim.Region.CoreModules.Avatar.AvatarFactory public void PostInitialise() { + m_updateTimer.Enabled = false; + m_updateTimer.AutoReset = true; + m_updateTimer.Interval = m_checkTime; // 500 milliseconds wait to start async ops + m_updateTimer.Elapsed += new ElapsedEventHandler(HandleAppearanceUpdateTimer); } public void Close() @@ -84,15 +100,8 @@ namespace OpenSim.Region.CoreModules.Avatar.AvatarFactory // client.OnAvatarNowWearing -= AvatarIsWearing; } - public void CheckBakedTextureAssets(IClientAPI client, UUID textureID, int idx) - { - if (m_scene.AssetService.Get(textureID.ToString()) == null) - { - m_log.WarnFormat("[AVFACTORY]: Missing baked texture {0} ({1}) for avatar {2}",textureID,idx,client.Name); - client.SendRebakeAvatarTextures(textureID); - } - } - + #endregion + /// /// Set appearance data (textureentry and slider settings) received from the client /// @@ -100,6 +109,10 @@ namespace OpenSim.Region.CoreModules.Avatar.AvatarFactory /// public void SetAppearance(IClientAPI client, Primitive.TextureEntry textureEntry, byte[] visualParams) { +// DEBUG ON + m_log.WarnFormat("[AVFACTORY] SetAppearance for {0}",client.AgentId); +// DEBUG OFF + ScenePresence sp = m_scene.GetScenePresence(client.AgentId); if (sp == null) { @@ -107,79 +120,175 @@ namespace OpenSim.Region.CoreModules.Avatar.AvatarFactory return; } -// DEBUG ON - m_log.WarnFormat("[AVFACTORY] SetAppearance for {0}",client.AgentId); -// DEBUG OFF - -/* - 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 - bool changed = false; // Process the texture entry if (textureEntry != null) { + changed = sp.Appearance.SetTextureEntries(textureEntry); + for (int i = 0; i < BAKE_INDICES.Length; i++) { - int j = BAKE_INDICES[i]; - Primitive.TextureEntryFace face = textureEntry.FaceTextures[j]; - + int idx = BAKE_INDICES[i]; + Primitive.TextureEntryFace face = sp.Appearance.Texture.FaceTextures[idx]; if (face != null && face.TextureID != AppearanceManager.DEFAULT_AVATAR_TEXTURE) - Util.FireAndForget(delegate(object o) { CheckBakedTextureAssets(client,face.TextureID,j); }); + Util.FireAndForget(delegate(object o) { CheckBakedTextureAssets(client,face.TextureID,idx); }); } - changed = sp.Appearance.SetTextureEntries(textureEntry); - } - #endregion Bake Cache Check - - changed = sp.Appearance.SetVisualParams(visualParams) || changed; - - // If nothing changed (this happens frequently) just return + // Process the visual params, this may change height as well + if (visualParams != null) + { + if (sp.Appearance.SetVisualParams(visualParams)) + { + changed = true; + if (sp.Appearance.AvatarHeight > 0) + sp.SetHeight(sp.Appearance.AvatarHeight); + } + } + + // If something changed in the appearance then queue an appearance save if (changed) + QueueAppearanceSave(client.AgentId); + + // And always queue up an appearance update to send out + QueueAppearanceSend(client.AgentId); + + // Send the appearance back to the avatar + AvatarAppearance avp = sp.Appearance; + sp.ControllingClient.SendAvatarDataImmediate(sp); + sp.ControllingClient.SendAppearance(avp.Owner,avp.VisualParams,avp.Texture.GetBytes()); + } + + /// + /// Checks for the existance of a baked texture asset and + /// requests the viewer rebake if the asset is not found + /// + /// + /// + /// + private void CheckBakedTextureAssets(IClientAPI client, UUID textureID, int idx) + { + if (m_scene.AssetService.Get(textureID.ToString()) == null) + { + m_log.WarnFormat("[AVFACTORY]: Missing baked texture {0} ({1}) for avatar {2}", + textureID,idx,client.Name); + client.SendRebakeAvatarTextures(textureID); + } + } + + #region UpdateAppearanceTimer + + public void QueueAppearanceSend(UUID agentid) + { +// DEBUG ON + m_log.WarnFormat("[AVFACTORY] Queue appearance send for {0}",agentid); +// DEBUG OFF + + // 100 nanoseconds (ticks) we should wait + long timestamp = DateTime.Now.Ticks + Convert.ToInt64(m_sendtime * 10000000); + lock (m_sendqueue) { + m_sendqueue[agentid] = timestamp; + m_updateTimer.Start(); + } + } + + public void QueueAppearanceSave(UUID agentid) + { // DEBUG ON - m_log.Warn("[AVFACTORY] Appearance changed"); + m_log.WarnFormat("[AVFACTORY] Queue appearance save for {0}",agentid); // 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); + // 100 nanoseconds (ticks) we should wait + long timestamp = DateTime.Now.Ticks + Convert.ToInt64(m_savetime * 10000000); + lock (m_savequeue) + { + m_savequeue[agentid] = timestamp; + m_updateTimer.Start(); + } + } + + private void HandleAppearanceSend(UUID agentid) + { + ScenePresence sp = m_scene.GetScenePresence(agentid); + if (sp == null) + { + m_log.WarnFormat("[AVFACTORY] Agent {0} no longer in the scene",agentid); + return; } + // DEBUG ON - else - m_log.Warn("[AVFACTORY] Appearance did not change"); -// DEBUG OFF + m_log.WarnFormat("[AVFACTORY] Handle appearance send for {0}\n{1}",agentid,sp.Appearance.ToString()); +// DEBUG OFF + // Send the appearance to everyone in the scene sp.SendAppearanceToAllOtherAgents(); + + // Send the appearance back to the avatar + AvatarAppearance avp = sp.Appearance; + sp.ControllingClient.SendAvatarDataImmediate(sp); + sp.ControllingClient.SendAppearance(avp.Owner,avp.VisualParams,avp.Texture.GetBytes()); + +/* +// this needs to be fixed, the flag should be on scene presence not the region module + // Start the animations if necessary if (!m_startAnimationSet) { sp.Animator.UpdateMovementAnimations(); m_startAnimationSet = true; } +*/ + } - client.SendAvatarDataImmediate(sp); - client.SendAppearance(sp.Appearance.Owner,sp.Appearance.VisualParams,sp.Appearance.Texture.GetBytes()); + private void HandleAppearanceSave(UUID agentid) + { + ScenePresence sp = m_scene.GetScenePresence(agentid); + if (sp == null) + { + m_log.WarnFormat("[AVFACTORY] Agent {0} no longer in the scene",agentid); + return; + } + + m_scene.AvatarService.SetAppearance(agentid, sp.Appearance); } + private void HandleAppearanceUpdateTimer(object sender, EventArgs ea) + { + long now = DateTime.Now.Ticks; + + lock (m_sendqueue) + { + Dictionary sends = new Dictionary(m_sendqueue); + foreach (KeyValuePair kvp in sends) + { + if (kvp.Value < now) + { + Util.FireAndForget(delegate(object o) { HandleAppearanceSend(kvp.Key); }); + m_sendqueue.Remove(kvp.Key); + } + } + } + + lock (m_savequeue) + { + Dictionary saves = new Dictionary(m_savequeue); + foreach (KeyValuePair kvp in saves) + { + if (kvp.Value < now) + { + Util.FireAndForget(delegate(object o) { HandleAppearanceSave(kvp.Key); }); + m_savequeue.Remove(kvp.Key); + } + } + } + + if (m_savequeue.Count == 0 && m_sendqueue.Count == 0) + m_updateTimer.Stop(); + } + + #endregion + /// /// Tell the client for this scene presence what items it should be wearing now /// -- cgit v1.1 From 68666efd25f4d094949f31eae08ee17fd821b7e4 Mon Sep 17 00:00:00 2001 From: Master ScienceSim Date: Thu, 28 Oct 2010 12:00:04 -0700 Subject: Configuration of persistent baked textures and save/send delays. --- .../Avatar/AvatarFactory/AvatarFactoryModule.cs | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) (limited to 'OpenSim/Region/CoreModules/Avatar') diff --git a/OpenSim/Region/CoreModules/Avatar/AvatarFactory/AvatarFactoryModule.cs b/OpenSim/Region/CoreModules/Avatar/AvatarFactory/AvatarFactoryModule.cs index 903e94b..5f8b4f6 100644 --- a/OpenSim/Region/CoreModules/Avatar/AvatarFactory/AvatarFactoryModule.cs +++ b/OpenSim/Region/CoreModules/Avatar/AvatarFactory/AvatarFactoryModule.cs @@ -48,20 +48,30 @@ namespace OpenSim.Region.CoreModules.Avatar.AvatarFactory private static readonly byte[] BAKE_INDICES = new byte[] { 8, 9, 10, 11, 19, 20 }; private Scene m_scene = null; - private static readonly int m_savetime = 5; // seconds to wait before saving changed appearance - private static readonly int m_sendtime = 2; // seconds to wait before sending changed appearance + private int m_savetime = 5; // seconds to wait before saving changed appearance + private int m_sendtime = 2; // seconds to wait before sending changed appearance - private static readonly int m_checkTime = 500; // milliseconds to wait between checks for appearance updates + private int m_checkTime = 500; // milliseconds to wait between checks for appearance updates private System.Timers.Timer m_updateTimer = new System.Timers.Timer(); private Dictionary m_savequeue = new Dictionary(); private Dictionary m_sendqueue = new Dictionary(); #region RegionModule Members - public void Initialise(Scene scene, IConfigSource source) + public void Initialise(Scene scene, IConfigSource config) { scene.EventManager.OnNewClient += NewClient; + if (config != null) + { + IConfig sconfig = config.Configs["Startup"]; + if (sconfig != null) + { + m_savetime = Convert.ToInt32(sconfig.GetString("DelayBeforeAppearanceSave",Convert.ToString(m_savetime))); + m_sendtime = Convert.ToInt32(sconfig.GetString("DelayBeforeAppearanceSend",Convert.ToString(m_sendtime))); + } + } + if (m_scene == null) m_scene = scene; } -- cgit v1.1