opensim – Blame information for rev 1

Subversion Repositories:
Rev:
Rev Author Line No. Line
1 eva 1 /*
2 * Copyright (c) Contributors, http://opensimulator.org/
3 * See CONTRIBUTORS.TXT for a full list of copyright holders.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 * * Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * * Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 * * Neither the name of the OpenSimulator Project nor the
13 * names of its contributors may be used to endorse or promote products
14 * derived from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
17 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
20 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27  
28 using System;
29 using System.Collections.Generic;
30 using OpenMetaverse;
31 using OpenMetaverse.StructuredData;
32  
33 namespace OpenSim.Framework
34 {
35 [Serializable]
36 public class WearableCacheItem
37 {
38 public uint TextureIndex { get; set; }
39 public UUID CacheId { 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 }
154 }
155  
156  
157 }