Clean out some crufty in AvatarFactoryModule
Fix RequestUpdateInventoryItem so that asset changes generate a new asset, which is needed for editing appearance to do the right thing. Persistant appearance seems to work after this, except you need to rebake textures some times.0.6.0-stable
							parent
							
								
									53bcf2139e
								
							
						
					
					
						commit
						9389429ed3
					
				| 
						 | 
				
			
			@ -347,6 +347,8 @@ namespace OpenSim.Region.Environment.Modules.Agent.AssetTransaction
 | 
			
		|||
 | 
			
		||||
                        if (asset != null && asset.FullID == assetID)
 | 
			
		||||
                        {
 | 
			
		||||
                            // Assets never get updated, new ones get created
 | 
			
		||||
                            asset.FullID = LLUUID.Random();
 | 
			
		||||
                            asset.Name = item.Name;
 | 
			
		||||
                            asset.Description = item.Description;
 | 
			
		||||
                            asset.InvType = (sbyte) item.InvType;
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1456,17 +1456,7 @@ namespace OpenSim.Region.Environment.Scenes
 | 
			
		|||
 | 
			
		||||
            SendFullUpdateToAllClients();
 | 
			
		||||
            SendAppearanceToAllOtherAgents();
 | 
			
		||||
            SendOwnAppearance();
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
        public void SetWearable(IClientAPI client, int wearableId, AvatarWearable wearable)
 | 
			
		||||
        {
 | 
			
		||||
            m_log.Info("[APPEARANCE] Setting wearable with client, wearableid, wearable");
 | 
			
		||||
            m_appearance.SetWearable(wearableId, wearable);
 | 
			
		||||
            m_scene.CommsManager.UserService.UpdateUserAppearance(client.AgentId, m_appearance);
 | 
			
		||||
            client.SendWearables(m_appearance.Wearables, m_appearance.Serial++);
 | 
			
		||||
        }
 | 
			
		||||
         }
 | 
			
		||||
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        ///
 | 
			
		||||
| 
						 | 
				
			
			@ -1476,6 +1466,11 @@ namespace OpenSim.Region.Environment.Scenes
 | 
			
		|||
        {
 | 
			
		||||
            m_log.Info("[APPEARANCE] Sending Own Appearance");
 | 
			
		||||
            ControllingClient.SendWearables(m_appearance.Wearables, m_appearance.Serial++);
 | 
			
		||||
            ControllingClient.SendAppearance(
 | 
			
		||||
                                            m_appearance.Owner,
 | 
			
		||||
                                            m_appearance.VisualParams,
 | 
			
		||||
                                            m_appearance.Texture.ToBytes()
 | 
			
		||||
                                            );
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        /// <summary>
 | 
			
		||||
| 
						 | 
				
			
			@ -1483,6 +1478,7 @@ namespace OpenSim.Region.Environment.Scenes
 | 
			
		|||
        /// </summary>
 | 
			
		||||
        public void SendAppearanceToAllOtherAgents()
 | 
			
		||||
        {
 | 
			
		||||
            m_log.Info("[APPEARANCE] Sending Appearance to All Other Agents");
 | 
			
		||||
            m_perfMonMS=System.Environment.TickCount;
 | 
			
		||||
 | 
			
		||||
            m_scene.ForEachScenePresence(delegate(ScenePresence scenePresence)
 | 
			
		||||
| 
						 | 
				
			
			@ -1506,7 +1502,7 @@ namespace OpenSim.Region.Environment.Scenes
 | 
			
		|||
 | 
			
		||||
        public void SetAppearance(byte[] texture, List<byte> visualParam)
 | 
			
		||||
        {
 | 
			
		||||
            m_log.Warn("[APPEARANCE] Setting Appearance");
 | 
			
		||||
            m_log.Info("[APPEARANCE] Setting Appearance");
 | 
			
		||||
            m_appearance.SetAppearance(texture, visualParam);
 | 
			
		||||
            SetHeight(m_appearance.AvatarHeight);
 | 
			
		||||
            m_scene.CommsManager.UserService.UpdateUserAppearance(m_controllingClient.AgentId, m_appearance);
 | 
			
		||||
| 
						 | 
				
			
			@ -1517,9 +1513,10 @@ namespace OpenSim.Region.Environment.Scenes
 | 
			
		|||
 | 
			
		||||
        public void SetWearable(int wearableId, AvatarWearable wearable)
 | 
			
		||||
        {
 | 
			
		||||
            m_log.Warn("[APPEARANCE] Setting Wearable");
 | 
			
		||||
            m_log.Info("[APPEARANCE] Setting Wearable");
 | 
			
		||||
            m_appearance.SetWearable(wearableId, wearable);
 | 
			
		||||
            m_scene.CommsManager.UserService.UpdateUserAppearance(m_controllingClient.AgentId, m_appearance);
 | 
			
		||||
            m_controllingClient.SendWearables(m_appearance.Wearables, m_appearance.Serial++);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        // Because appearance setting is in a module, we actually need
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -46,22 +46,13 @@ namespace OpenSim.Region.Modules.AvatarFactory
 | 
			
		|||
    {
 | 
			
		||||
        private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
 | 
			
		||||
        private Scene m_scene = null;
 | 
			
		||||
        private readonly Dictionary<LLUUID, AvatarAppearance> m_avatarsAppearance = new Dictionary<LLUUID, AvatarAppearance>();
 | 
			
		||||
 | 
			
		||||
        private bool m_enablePersist = false;
 | 
			
		||||
        private string m_connectionString;
 | 
			
		||||
        private bool m_configured = false;
 | 
			
		||||
        private BaseDatabaseConnector m_databaseMapper;
 | 
			
		||||
        private AppearanceTableMapper m_appearanceMapper;
 | 
			
		||||
 | 
			
		||||
        private Dictionary<LLUUID, EventWaitHandle> m_fetchesInProgress = new Dictionary<LLUUID, EventWaitHandle>();
 | 
			
		||||
        private object m_syncLock = new object();
 | 
			
		||||
 | 
			
		||||
        public bool TryGetAvatarAppearance(LLUUID avatarId, out AvatarAppearance appearance)
 | 
			
		||||
        {
 | 
			
		||||
            appearance = m_scene.CommsManager.UserService.GetUserAppearance(avatarId);
 | 
			
		||||
            if (appearance != null) 
 | 
			
		||||
            {
 | 
			
		||||
                m_log.InfoFormat("[APPEARANCE] found : {0}", appearance.ToString());
 | 
			
		||||
                return true;
 | 
			
		||||
            }
 | 
			
		||||
            else
 | 
			
		||||
| 
						 | 
				
			
			@ -69,112 +60,6 @@ namespace OpenSim.Region.Modules.AvatarFactory
 | 
			
		|||
                m_log.InfoFormat("[APPEARANCE] appearance not found for {0}", avatarId.ToString());
 | 
			
		||||
                return false;
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            // //should only let one thread at a time do this part
 | 
			
		||||
            // EventWaitHandle waitHandle = null;
 | 
			
		||||
            // bool fetchInProgress = false;
 | 
			
		||||
            // lock (m_syncLock)
 | 
			
		||||
            // {
 | 
			
		||||
            //     appearance = CheckCache(avatarId);
 | 
			
		||||
            //     if (appearance != null)
 | 
			
		||||
            //     {
 | 
			
		||||
            //         return true;
 | 
			
		||||
            //     }
 | 
			
		||||
 | 
			
		||||
            //     //not in cache so check to see if another thread is already fetching it
 | 
			
		||||
            //     if (m_fetchesInProgress.TryGetValue(avatarId, out waitHandle))
 | 
			
		||||
            //     {
 | 
			
		||||
            //         fetchInProgress = true;
 | 
			
		||||
            //     }
 | 
			
		||||
            //     else
 | 
			
		||||
            //     {
 | 
			
		||||
            //         fetchInProgress = false;
 | 
			
		||||
 | 
			
		||||
            //         //no thread already fetching this appearance, so add a wait handle to list
 | 
			
		||||
            //         //for any following threads that want the same appearance
 | 
			
		||||
            //         waitHandle = new EventWaitHandle(false, EventResetMode.ManualReset);
 | 
			
		||||
            //         m_fetchesInProgress.Add(avatarId, waitHandle);
 | 
			
		||||
            //     }
 | 
			
		||||
            // }
 | 
			
		||||
 | 
			
		||||
            // if (fetchInProgress)
 | 
			
		||||
            // {
 | 
			
		||||
            //     waitHandle.WaitOne();
 | 
			
		||||
            //     appearance = CheckCache(avatarId);
 | 
			
		||||
            //     if (appearance != null)
 | 
			
		||||
            //     {
 | 
			
		||||
            //         waitHandle = null;
 | 
			
		||||
            //         return true;
 | 
			
		||||
            //     }
 | 
			
		||||
            //     else
 | 
			
		||||
            //     {
 | 
			
		||||
            //         waitHandle = null;
 | 
			
		||||
            //         return false;
 | 
			
		||||
            //     }
 | 
			
		||||
            // }
 | 
			
		||||
            // else
 | 
			
		||||
            // {
 | 
			
		||||
            //     // BUG: !? (Reduced from 5000 to 500 by Adam)
 | 
			
		||||
            //     Thread.Sleep(500); //why is this here?
 | 
			
		||||
 | 
			
		||||
            //     //this is the first thread to request this appearance
 | 
			
		||||
            //     //so let it check the db and if not found then create a default appearance
 | 
			
		||||
            //     //and add that to the cache
 | 
			
		||||
            //     appearance = CheckDatabase(avatarId);
 | 
			
		||||
            //     if (appearance != null)
 | 
			
		||||
            //     {
 | 
			
		||||
            //         //appearance has now been added to cache so lets pulse any waiting threads
 | 
			
		||||
            //         lock (m_syncLock)
 | 
			
		||||
            //         {
 | 
			
		||||
            //             m_fetchesInProgress.Remove(avatarId);
 | 
			
		||||
            //             waitHandle.Set();
 | 
			
		||||
            //         }
 | 
			
		||||
            //         // waitHandle.Close();
 | 
			
		||||
            //         waitHandle = null;
 | 
			
		||||
            //         return true;
 | 
			
		||||
            //     }
 | 
			
		||||
 | 
			
		||||
            //     //not found a appearance for the user, so create a new default one
 | 
			
		||||
            //     appearance = CreateDefault(avatarId);
 | 
			
		||||
            //     if (appearance != null)
 | 
			
		||||
            //     {
 | 
			
		||||
            //         //update database
 | 
			
		||||
            //         if (m_enablePersist)
 | 
			
		||||
            //         {
 | 
			
		||||
            //             m_appearanceMapper.Add(avatarId.UUID, appearance);
 | 
			
		||||
            //         }
 | 
			
		||||
 | 
			
		||||
            //         //add appearance to dictionary cache
 | 
			
		||||
            //         lock (m_avatarsAppearance)
 | 
			
		||||
            //         {
 | 
			
		||||
            //             m_avatarsAppearance[avatarId] = appearance;
 | 
			
		||||
            //         }
 | 
			
		||||
 | 
			
		||||
            //         //appearance has now been added to cache so lets pulse any waiting threads
 | 
			
		||||
            //         lock (m_syncLock)
 | 
			
		||||
            //         {
 | 
			
		||||
            //             m_fetchesInProgress.Remove(avatarId);
 | 
			
		||||
            //             waitHandle.Set();
 | 
			
		||||
            //         }
 | 
			
		||||
            //         // waitHandle.Close();
 | 
			
		||||
            //         waitHandle = null;
 | 
			
		||||
            //         return true;
 | 
			
		||||
            //     }
 | 
			
		||||
            //     else
 | 
			
		||||
            //     {
 | 
			
		||||
            //         //something went wrong, so release the wait handle and remove it
 | 
			
		||||
            //         //all waiting threads will fail to find cached appearance
 | 
			
		||||
            //         //but its better for them to fail than wait for ever
 | 
			
		||||
            //         lock (m_syncLock)
 | 
			
		||||
            //         {
 | 
			
		||||
            //             m_fetchesInProgress.Remove(avatarId);
 | 
			
		||||
            //             waitHandle.Set();
 | 
			
		||||
            //         }
 | 
			
		||||
            //         //waitHandle.Close();
 | 
			
		||||
            //         waitHandle = null;
 | 
			
		||||
            //         return false;
 | 
			
		||||
            //     }
 | 
			
		||||
            // }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        private AvatarAppearance CreateDefault(LLUUID avatarId)
 | 
			
		||||
| 
						 | 
				
			
			@ -188,37 +73,6 @@ namespace OpenSim.Region.Modules.AvatarFactory
 | 
			
		|||
            return appearance;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        private AvatarAppearance CheckDatabase(LLUUID avatarId)
 | 
			
		||||
        {
 | 
			
		||||
            AvatarAppearance appearance = null;
 | 
			
		||||
            if (m_enablePersist)
 | 
			
		||||
            {
 | 
			
		||||
                if (m_appearanceMapper.TryGetValue(avatarId.UUID, out appearance))
 | 
			
		||||
                {
 | 
			
		||||
                    appearance.VisualParams = GetDefaultVisualParams();
 | 
			
		||||
                    appearance.Texture = AvatarAppearance.GetDefaultTexture();
 | 
			
		||||
                    lock (m_avatarsAppearance)
 | 
			
		||||
                    {
 | 
			
		||||
                        m_avatarsAppearance[avatarId] = appearance;
 | 
			
		||||
                    }
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
            return appearance;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        private AvatarAppearance CheckCache(LLUUID avatarId)
 | 
			
		||||
        {
 | 
			
		||||
            AvatarAppearance appearance = null;
 | 
			
		||||
            lock (m_avatarsAppearance)
 | 
			
		||||
            {
 | 
			
		||||
                if (m_avatarsAppearance.ContainsKey(avatarId))
 | 
			
		||||
                {
 | 
			
		||||
                    appearance = m_avatarsAppearance[avatarId];
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
            return appearance;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        public void Initialise(Scene scene, IConfigSource source)
 | 
			
		||||
        {
 | 
			
		||||
            scene.RegisterModuleInterface<IAvatarFactory>(this);
 | 
			
		||||
| 
						 | 
				
			
			@ -229,31 +83,6 @@ namespace OpenSim.Region.Modules.AvatarFactory
 | 
			
		|||
                m_scene = scene;
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            // if (!m_configured)
 | 
			
		||||
            // {
 | 
			
		||||
            //     m_configured = true;
 | 
			
		||||
            //     try
 | 
			
		||||
            //     {
 | 
			
		||||
            //         m_enablePersist = source.Configs["Startup"].GetBoolean("appearance_persist", false);
 | 
			
		||||
            //     }
 | 
			
		||||
            //     catch (Exception)
 | 
			
		||||
            //     {
 | 
			
		||||
            //     }
 | 
			
		||||
            //     if (m_enablePersist)
 | 
			
		||||
            //     {
 | 
			
		||||
            //         m_connectionString = source.Configs["Startup"].GetString("appearance_connection_string", "");
 | 
			
		||||
 | 
			
		||||
            //         string mapperTypeStr = source.Configs["Startup"].GetString("appearance_database", "MySQL");
 | 
			
		||||
 | 
			
		||||
            //         DataMapperFactory.MAPPER_TYPE mapperType =
 | 
			
		||||
            //             (DataMapperFactory.MAPPER_TYPE)
 | 
			
		||||
            //             Enum.Parse(typeof (DataMapperFactory.MAPPER_TYPE), mapperTypeStr);
 | 
			
		||||
 | 
			
		||||
            //         m_databaseMapper = DataMapperFactory.GetDataBaseMapper(mapperType, m_connectionString);
 | 
			
		||||
 | 
			
		||||
            //         m_appearanceMapper = new AppearanceTableMapper(m_databaseMapper, "AvatarAppearance");
 | 
			
		||||
            //     }
 | 
			
		||||
            // }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        public void PostInitialise()
 | 
			
		||||
| 
						 | 
				
			
			@ -338,20 +167,17 @@ namespace OpenSim.Region.Modules.AvatarFactory
 | 
			
		|||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        public void UpdateDatabase(LLUUID userID, AvatarAppearance avatAppearance)
 | 
			
		||||
        {
 | 
			
		||||
            if (m_enablePersist)
 | 
			
		||||
            {
 | 
			
		||||
                m_appearanceMapper.Update(userID.UUID, avatAppearance);
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        public static void GetDefaultAvatarAppearance(out AvatarWearable[] wearables, out byte[] visualParams)
 | 
			
		||||
        {
 | 
			
		||||
            visualParams = GetDefaultVisualParams();
 | 
			
		||||
            wearables = AvatarWearable.DefaultWearables;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        public void UpdateDatabase(LLUUID user, AvatarAppearance appearance)
 | 
			
		||||
        { 
 | 
			
		||||
            m_scene.CommsManager.UserService.UpdateUserAppearance(user, appearance);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        private static byte[] GetDefaultVisualParams()
 | 
			
		||||
        {
 | 
			
		||||
            byte[] visualParams;
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in New Issue