diff options
Diffstat (limited to 'OpenSim/Framework/WearableCacheItem.cs')
-rw-r--r-- | OpenSim/Framework/WearableCacheItem.cs | 118 |
1 files changed, 118 insertions, 0 deletions
diff --git a/OpenSim/Framework/WearableCacheItem.cs b/OpenSim/Framework/WearableCacheItem.cs index 83b1346..1aecf79 100644 --- a/OpenSim/Framework/WearableCacheItem.cs +++ b/OpenSim/Framework/WearableCacheItem.cs | |||
@@ -26,14 +26,132 @@ | |||
26 | */ | 26 | */ |
27 | 27 | ||
28 | using System; | 28 | using System; |
29 | using System.Collections.Generic; | ||
29 | using OpenMetaverse; | 30 | using OpenMetaverse; |
31 | using OpenMetaverse.StructuredData; | ||
30 | 32 | ||
31 | namespace OpenSim.Framework | 33 | namespace OpenSim.Framework |
32 | { | 34 | { |
35 | [Serializable] | ||
33 | public class WearableCacheItem | 36 | public class WearableCacheItem |
34 | { | 37 | { |
35 | public uint TextureIndex { get; set; } | 38 | public uint TextureIndex { get; set; } |
36 | public UUID CacheId { get; set; } | 39 | public UUID CacheId { get; set; } |
37 | public UUID TextureID { get; set; } | 40 | public UUID TextureID { get; set; } |
41 | public AssetBase TextureAsset { get; set; } | ||
42 | |||
43 | |||
44 | public static WearableCacheItem[] GetDefaultCacheItem() | ||
45 | { | ||
46 | int itemmax = 21; | ||
47 | WearableCacheItem[] retitems = new WearableCacheItem[itemmax]; | ||
48 | for (uint i=0;i<itemmax;i++) | ||
49 | retitems[i] = new WearableCacheItem() {CacheId = UUID.Zero, TextureID = UUID.Zero, TextureIndex = i + 1}; | ||
50 | return retitems; | ||
51 | } | ||
52 | public static WearableCacheItem[] FromOSD(OSD pInput, IImprovedAssetCache dataCache) | ||
53 | { | ||
54 | List<WearableCacheItem> ret = new List<WearableCacheItem>(); | ||
55 | if (pInput.Type == OSDType.Array) | ||
56 | { | ||
57 | OSDArray itemarray = (OSDArray) pInput; | ||
58 | foreach (OSDMap item in itemarray) | ||
59 | { | ||
60 | ret.Add(new WearableCacheItem() | ||
61 | { | ||
62 | TextureIndex = item["textureindex"].AsUInteger(), | ||
63 | CacheId = item["cacheid"].AsUUID(), | ||
64 | TextureID = item["textureid"].AsUUID() | ||
65 | }); | ||
66 | |||
67 | if (dataCache != null && item.ContainsKey("assetdata")) | ||
68 | { | ||
69 | AssetBase asset = new AssetBase(item["textureid"].AsUUID(),"BakedTexture",(sbyte)AssetType.Texture,UUID.Zero.ToString()); | ||
70 | asset.Temporary = true; | ||
71 | asset.Data = item["assetdata"].AsBinary(); | ||
72 | dataCache.Cache(asset); | ||
73 | } | ||
74 | } | ||
75 | } | ||
76 | else if (pInput.Type == OSDType.Map) | ||
77 | { | ||
78 | OSDMap item = (OSDMap) pInput; | ||
79 | ret.Add(new WearableCacheItem(){ | ||
80 | TextureIndex = item["textureindex"].AsUInteger(), | ||
81 | CacheId = item["cacheid"].AsUUID(), | ||
82 | TextureID = item["textureid"].AsUUID() | ||
83 | }); | ||
84 | if (dataCache != null && item.ContainsKey("assetdata")) | ||
85 | { | ||
86 | string assetCreator = item["assetcreator"].AsString(); | ||
87 | string assetName = item["assetname"].AsString(); | ||
88 | AssetBase asset = new AssetBase(item["textureid"].AsUUID(), assetName, (sbyte)AssetType.Texture, assetCreator); | ||
89 | asset.Temporary = true; | ||
90 | asset.Data = item["assetdata"].AsBinary(); | ||
91 | dataCache.Cache(asset); | ||
92 | } | ||
93 | } | ||
94 | else | ||
95 | { | ||
96 | return new WearableCacheItem[0]; | ||
97 | } | ||
98 | return ret.ToArray(); | ||
99 | |||
100 | } | ||
101 | public static OSD ToOSD(WearableCacheItem[] pcacheItems, IImprovedAssetCache dataCache) | ||
102 | { | ||
103 | OSDArray arr = new OSDArray(); | ||
104 | foreach (WearableCacheItem item in pcacheItems) | ||
105 | { | ||
106 | OSDMap itemmap = new OSDMap(); | ||
107 | itemmap.Add("textureindex", OSD.FromUInteger(item.TextureIndex)); | ||
108 | itemmap.Add("cacheid", OSD.FromUUID(item.CacheId)); | ||
109 | itemmap.Add("textureid", OSD.FromUUID(item.TextureID)); | ||
110 | if (dataCache != null) | ||
111 | { | ||
112 | if (dataCache.Check(item.TextureID.ToString())) | ||
113 | { | ||
114 | AssetBase assetItem = dataCache.Get(item.TextureID.ToString()); | ||
115 | if (assetItem != null) | ||
116 | { | ||
117 | itemmap.Add("assetdata", OSD.FromBinary(assetItem.Data)); | ||
118 | itemmap.Add("assetcreator", OSD.FromString(assetItem.CreatorID)); | ||
119 | itemmap.Add("assetname", OSD.FromString(assetItem.Name)); | ||
120 | } | ||
121 | } | ||
122 | } | ||
123 | arr.Add(itemmap); | ||
124 | } | ||
125 | return arr; | ||
126 | } | ||
127 | public static WearableCacheItem SearchTextureIndex(uint pTextureIndex,WearableCacheItem[] pcacheItems) | ||
128 | { | ||
129 | for (int i = 0; i < pcacheItems.Length; i++) | ||
130 | { | ||
131 | if (pcacheItems[i].TextureIndex == pTextureIndex) | ||
132 | return pcacheItems[i]; | ||
133 | } | ||
134 | return null; | ||
135 | } | ||
136 | public static WearableCacheItem SearchTextureCacheId(UUID pCacheId, WearableCacheItem[] pcacheItems) | ||
137 | { | ||
138 | for (int i = 0; i < pcacheItems.Length; i++) | ||
139 | { | ||
140 | if (pcacheItems[i].CacheId == pCacheId) | ||
141 | return pcacheItems[i]; | ||
142 | } | ||
143 | return null; | ||
144 | } | ||
145 | public static WearableCacheItem SearchTextureTextureId(UUID pTextureId, WearableCacheItem[] pcacheItems) | ||
146 | { | ||
147 | for (int i = 0; i < pcacheItems.Length; i++) | ||
148 | { | ||
149 | if (pcacheItems[i].TextureID == pTextureId) | ||
150 | return pcacheItems[i]; | ||
151 | } | ||
152 | return null; | ||
153 | } | ||
38 | } | 154 | } |
155 | |||
156 | |||
39 | } | 157 | } |