From 89f2589f6c12e7cd265c25f7f83bd1b3f1e98d7e Mon Sep 17 00:00:00 2001 From: Justin Clarke Casey Date: Wed, 18 Feb 2009 21:02:43 +0000 Subject: * Change AssetGatherer method access so that only methods which are worth calling from the outside are public --- .../Archiver/InventoryArchiveWriteRequest.cs | 5 +- .../Archiver/ArchiveWriteRequestPreparation.cs | 2 +- OpenSim/Region/Framework/Scenes/AssetGatherer.cs | 182 +++++++++++---------- 3 files changed, 101 insertions(+), 88 deletions(-) (limited to 'OpenSim/Region') diff --git a/OpenSim/Region/CoreModules/Avatar/Inventory/Archiver/InventoryArchiveWriteRequest.cs b/OpenSim/Region/CoreModules/Avatar/Inventory/Archiver/InventoryArchiveWriteRequest.cs index 1152a1e..7f228e4 100644 --- a/OpenSim/Region/CoreModules/Avatar/Inventory/Archiver/InventoryArchiveWriteRequest.cs +++ b/OpenSim/Region/CoreModules/Avatar/Inventory/Archiver/InventoryArchiveWriteRequest.cs @@ -37,6 +37,7 @@ using OpenSim.Framework; using OpenSim.Framework.Communications; using OpenSim.Framework.Communications.Cache; using OpenSim.Region.CoreModules.World.Archiver; +using OpenSim.Region.Framework.Scenes; namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver { @@ -45,6 +46,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); protected TarArchiveWriter archive = new TarArchiveWriter(); + protected AssetGatherer m_assetGatherer; protected Dictionary assetUuids = new Dictionary(); private InventoryArchiverModule m_module; @@ -78,7 +80,8 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver m_module = module; m_userInfo = userInfo; m_invPath = invPath; - m_saveStream = saveStream; + m_saveStream = saveStream; + m_assetGatherer = new AssetGatherer(m_module.CommsManager.AssetCache); } protected void ReceivedAllAssets(IDictionary assetsFound, ICollection assetsNotFoundUuids) diff --git a/OpenSim/Region/CoreModules/World/Archiver/ArchiveWriteRequestPreparation.cs b/OpenSim/Region/CoreModules/World/Archiver/ArchiveWriteRequestPreparation.cs index d78acdd..1edd2dc 100644 --- a/OpenSim/Region/CoreModules/World/Archiver/ArchiveWriteRequestPreparation.cs +++ b/OpenSim/Region/CoreModules/World/Archiver/ArchiveWriteRequestPreparation.cs @@ -100,7 +100,7 @@ namespace OpenSim.Region.CoreModules.World.Archiver foreach (SceneObjectGroup sceneObject in sceneObjects) { - assetGatherer.GetSceneObjectAssetUuids(sceneObject, assetUuids); + assetGatherer.GatherAssetUuids(sceneObject, assetUuids); } m_log.DebugFormat( diff --git a/OpenSim/Region/Framework/Scenes/AssetGatherer.cs b/OpenSim/Region/Framework/Scenes/AssetGatherer.cs index 2726bd8..00a4398 100644 --- a/OpenSim/Region/Framework/Scenes/AssetGatherer.cs +++ b/OpenSim/Region/Framework/Scenes/AssetGatherer.cs @@ -67,12 +67,101 @@ namespace OpenSim.Region.Framework.Scenes public AssetGatherer(IAssetCache assetCache) { m_assetCache = assetCache; - } + } + + /// + /// Gather all the asset uuids associated with the asset referenced by a given uuid + /// + /// + /// This includes both those directly associated with + /// it (e.g. face textures) and recursively, those of items within it's inventory (e.g. objects contained + /// within this object). + /// + /// The uuid of the asset for which to gather referenced assets + /// The type of the asset for the uuid given + /// The assets gathered + public void GatherAssetUuids(UUID assetUuid, AssetType assetType, IDictionary assetUuids) + { + assetUuids[assetUuid] = 1; + + if (AssetType.Bodypart == assetType || AssetType.Clothing == assetType) + { + GetWearableAssetUuids(assetUuid, assetUuids); + } + else if (AssetType.LSLText == assetType) + { + GetScriptAssetUuids(assetUuid, assetUuids); + } + else if (AssetType.Object == assetType) + { + GetSceneObjectAssetUuids(assetUuid, assetUuids); + } + } + + /// + /// Gather all the asset uuids associated with a given object. + /// + /// + /// This includes both those directly associated with + /// it (e.g. face textures) and recursively, those of items within it's inventory (e.g. objects contained + /// within this object). + /// + /// The scene object for which to gather assets + /// The assets gathered + public void GatherAssetUuids(SceneObjectGroup sceneObject, IDictionary assetUuids) + { + m_log.DebugFormat( + "[ASSET GATHERER]: Getting assets for object {0}, {1}", sceneObject.Name, sceneObject.UUID); + + foreach (SceneObjectPart part in sceneObject.GetParts()) + { + //m_log.DebugFormat( + // "[ARCHIVER]: Getting part {0}, {1} for object {2}", part.Name, part.UUID, sceneObject.UUID); + + try + { + Primitive.TextureEntry textureEntry = part.Shape.Textures; + + // Get the prim's default texture. This will be used for faces which don't have their own texture + assetUuids[textureEntry.DefaultTexture.TextureID] = 1; + + // XXX: Not a great way to iterate through face textures, but there's no + // other method available to tell how many faces there actually are + //int i = 0; + foreach (Primitive.TextureEntryFace texture in textureEntry.FaceTextures) + { + if (texture != null) + { + //m_log.DebugFormat("[ARCHIVER]: Got face {0}", i++); + assetUuids[texture.TextureID] = 1; + } + } + + // If the prim is a sculpt then preserve this information too + if (part.Shape.SculptTexture != UUID.Zero) + assetUuids[part.Shape.SculptTexture] = 1; + + // Now analyze this prim's inventory items to preserve all the uuids that they reference + foreach (TaskInventoryItem tii in part.TaskInventory.Values) + { + //m_log.DebugFormat("[ARCHIVER]: Analysing item asset type {0}", tii.Type); + + if (!assetUuids.ContainsKey(tii.AssetID)) + GatherAssetUuids(tii.AssetID, (AssetType)tii.Type, assetUuids); + } + } + catch (Exception e) + { + m_log.ErrorFormat("[ASSET GATHERER]: Failed to get part - {0}", e); + m_log.DebugFormat("[ASSET GATHERER]: Texture entry length for prim was {0} (min is 46)", part.Shape.TextureEntry.Length); + } + } + } /// /// The callback made when we request the asset for an object from the asset service. /// - public void AssetRequestCallback(UUID assetID, AssetBase asset) + protected void AssetRequestCallback(UUID assetID, AssetBase asset) { lock (this) { @@ -116,7 +205,7 @@ namespace OpenSim.Region.Framework.Scenes /// /// /// Dictionary in which to record the references - public void GetScriptAssetUuids(UUID scriptUuid, IDictionary assetUuids) + protected void GetScriptAssetUuids(UUID scriptUuid, IDictionary assetUuids) { AssetBase scriptAsset = GetAsset(scriptUuid); @@ -141,7 +230,7 @@ namespace OpenSim.Region.Framework.Scenes /// /// /// Dictionary in which to record the references - public void GetWearableAssetUuids(UUID wearableAssetUuid, IDictionary assetUuids) + protected void GetWearableAssetUuids(UUID wearableAssetUuid, IDictionary assetUuids) { AssetBase assetBase = GetAsset(wearableAssetUuid); //m_log.Debug(new System.Text.ASCIIEncoding().GetString(bodypartAsset.Data)); @@ -165,7 +254,7 @@ namespace OpenSim.Region.Framework.Scenes /// /// /// - public void GetSceneObjectAssetUuids(UUID sceneObjectUuid, IDictionary assetUuids) + protected void GetSceneObjectAssetUuids(UUID sceneObjectUuid, IDictionary assetUuids) { AssetBase objectAsset = GetAsset(sceneObjectUuid); @@ -173,87 +262,8 @@ namespace OpenSim.Region.Framework.Scenes { string xml = Utils.BytesToString(objectAsset.Data); SceneObjectGroup sog = new SceneObjectGroup(xml, true); - GetSceneObjectAssetUuids(sog, assetUuids); - } - } - - /// - /// Get all the asset uuids associated with a given object. - /// - /// - /// This includes both those directly associated with - /// it (e.g. face textures) and recursively, those of items within it's inventory (e.g. objects contained - /// within this object). - /// - /// The scene object for which to gather assets - /// The assets gathered - public void GetSceneObjectAssetUuids(SceneObjectGroup sceneObject, IDictionary assetUuids) - { - m_log.DebugFormat( - "[ASSET GATHERER]: Getting assets for object {0}, {1}", sceneObject.Name, sceneObject.UUID); - - foreach (SceneObjectPart part in sceneObject.GetParts()) - { - //m_log.DebugFormat( - // "[ARCHIVER]: Getting part {0}, {1} for object {2}", part.Name, part.UUID, sceneObject.UUID); - - try - { - Primitive.TextureEntry textureEntry = part.Shape.Textures; - - // Get the prim's default texture. This will be used for faces which don't have their own texture - assetUuids[textureEntry.DefaultTexture.TextureID] = 1; - - // XXX: Not a great way to iterate through face textures, but there's no - // other method available to tell how many faces there actually are - //int i = 0; - foreach (Primitive.TextureEntryFace texture in textureEntry.FaceTextures) - { - if (texture != null) - { - //m_log.DebugFormat("[ARCHIVER]: Got face {0}", i++); - assetUuids[texture.TextureID] = 1; - } - } - - // If the prim is a sculpt then preserve this information too - if (part.Shape.SculptTexture != UUID.Zero) - assetUuids[part.Shape.SculptTexture] = 1; - - // Now analyze this prim's inventory items to preserve all the uuids that they reference - foreach (TaskInventoryItem tii in part.TaskInventory.Values) - { - //m_log.DebugFormat("[ARCHIVER]: Analysing item asset type {0}", tii.Type); - - if (!assetUuids.ContainsKey(tii.AssetID)) - { - assetUuids[tii.AssetID] = 1; - - if ((int)AssetType.Bodypart == tii.Type || ((int)AssetType.Clothing == tii.Type)) - { - GetWearableAssetUuids(tii.AssetID, assetUuids); - } - else if ((int)AssetType.LSLText == tii.Type) - { - GetScriptAssetUuids(tii.AssetID, assetUuids); - } - else if ((int)AssetType.Object == tii.Type) - { - GetSceneObjectAssetUuids(tii.AssetID, assetUuids); - } - //else - //{ - //m_log.DebugFormat("[ARCHIVER]: Recording asset {0} in object {1}", tii.AssetID, part.UUID); - //} - } - } - } - catch (Exception e) - { - m_log.ErrorFormat("[ASSET GATHERER]: Failed to get part - {0}", e); - m_log.DebugFormat("[ASSET GATHERER]: Texture entry length for prim was {0} (min is 46)", part.Shape.TextureEntry.Length); - } + GatherAssetUuids(sog, assetUuids); } - } + } } } -- cgit v1.1