aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorUbitUmarov2014-08-07 05:20:45 +0100
committerUbitUmarov2014-08-07 05:20:45 +0100
commitc3f9c99fb32d15e57b24502b71c79fe028ed3007 (patch)
tree0b7cef6c028edfff0e09ca6d5442141221bc85a2
parentbakemodule didnt like last changes (diff)
downloadopensim-SC_OLD-c3f9c99fb32d15e57b24502b71c79fe028ed3007.zip
opensim-SC_OLD-c3f9c99fb32d15e57b24502b71c79fe028ed3007.tar.gz
opensim-SC_OLD-c3f9c99fb32d15e57b24502b71c79fe028ed3007.tar.bz2
opensim-SC_OLD-c3f9c99fb32d15e57b24502b71c79fe028ed3007.tar.xz
DANGER... changed bakedtextures caching. Assuming grid baking is cache
only, reduced number of accesses to it. TESTING
-rw-r--r--OpenSim/Framework/WearableCacheItem.cs2
-rw-r--r--OpenSim/Region/ClientStack/Linden/Caps/UploadBakedTextureModule.cs124
-rw-r--r--OpenSim/Region/ClientStack/Linden/UDP/LLClientView.cs110
-rw-r--r--OpenSim/Region/CoreModules/Avatar/AvatarFactory/AvatarFactoryModule.cs279
-rw-r--r--OpenSim/Region/Framework/Scenes/ScenePresence.cs2
5 files changed, 299 insertions, 218 deletions
diff --git a/OpenSim/Framework/WearableCacheItem.cs b/OpenSim/Framework/WearableCacheItem.cs
index 1aecf79..cde2862 100644
--- a/OpenSim/Framework/WearableCacheItem.cs
+++ b/OpenSim/Framework/WearableCacheItem.cs
@@ -46,7 +46,7 @@ namespace OpenSim.Framework
46 int itemmax = 21; 46 int itemmax = 21;
47 WearableCacheItem[] retitems = new WearableCacheItem[itemmax]; 47 WearableCacheItem[] retitems = new WearableCacheItem[itemmax];
48 for (uint i=0;i<itemmax;i++) 48 for (uint i=0;i<itemmax;i++)
49 retitems[i] = new WearableCacheItem() {CacheId = UUID.Zero, TextureID = UUID.Zero, TextureIndex = i + 1}; 49 retitems[i] = new WearableCacheItem() {CacheId = UUID.Zero, TextureID = UUID.Zero, TextureIndex = i};
50 return retitems; 50 return retitems;
51 } 51 }
52 public static WearableCacheItem[] FromOSD(OSD pInput, IImprovedAssetCache dataCache) 52 public static WearableCacheItem[] FromOSD(OSD pInput, IImprovedAssetCache dataCache)
diff --git a/OpenSim/Region/ClientStack/Linden/Caps/UploadBakedTextureModule.cs b/OpenSim/Region/ClientStack/Linden/Caps/UploadBakedTextureModule.cs
index 2da653d..50e9275 100644
--- a/OpenSim/Region/ClientStack/Linden/Caps/UploadBakedTextureModule.cs
+++ b/OpenSim/Region/ClientStack/Linden/Caps/UploadBakedTextureModule.cs
@@ -96,9 +96,7 @@ namespace OpenSim.Region.ClientStack.Linden
96 s.EventManager.OnRemovePresence -= DeRegisterPresence; 96 s.EventManager.OnRemovePresence -= DeRegisterPresence;
97 m_BakedTextureModule = null; 97 m_BakedTextureModule = null;
98 m_scene = null; 98 m_scene = null;
99 } 99 }
100
101
102 100
103 public void RegionLoaded(Scene s) 101 public void RegionLoaded(Scene s)
104 { 102 {
@@ -110,44 +108,58 @@ namespace OpenSim.Region.ClientStack.Linden
110 108
111 private void DeRegisterPresence(UUID agentId) 109 private void DeRegisterPresence(UUID agentId)
112 { 110 {
113 ScenePresence presence = null; 111// ScenePresence presence = null;
114 if (m_scene.TryGetScenePresence(agentId, out presence)) 112// if (m_scene.TryGetScenePresence(agentId, out presence))
115 { 113 {
116 presence.ControllingClient.OnSetAppearance -= CaptureAppearanceSettings; 114// presence.ControllingClient.OnSetAppearance -= CaptureAppearanceSettings;
117 } 115 }
118 116
119 } 117 }
120 118
121 private void RegisterNewPresence(ScenePresence presence) 119 private void RegisterNewPresence(ScenePresence presence)
122 { 120 {
123 presence.ControllingClient.OnSetAppearance += CaptureAppearanceSettings; 121// presence.ControllingClient.OnSetAppearance += CaptureAppearanceSettings;
124
125 } 122 }
126 123
127 private void CaptureAppearanceSettings(IClientAPI remoteClient, Primitive.TextureEntry textureEntry, byte[] visualParams, Vector3 avSize, WearableCacheItem[] cacheItems) 124/* not in use. work done in AvatarFactoryModule ValidateBakedTextureCache() and UpdateBakedTextureCache()
128 { 125 private void CaptureAppearanceSettings(IClientAPI remoteClient, Primitive.TextureEntry textureEntry, byte[] visualParams, Vector3 avSize, WearableCacheItem[] cacheItems)
129 int maxCacheitemsLoop = cacheItems.Length;
130 if (maxCacheitemsLoop > AvatarWearable.MAX_WEARABLES)
131 {
132 maxCacheitemsLoop = AvatarWearable.MAX_WEARABLES;
133 m_log.WarnFormat("[CACHEDBAKES]: Too Many Cache items Provided {0}, the max is {1}. Truncating!", cacheItems.Length, AvatarWearable.MAX_WEARABLES);
134 }
135
136 m_BakedTextureModule = m_scene.RequestModuleInterface<IBakedTextureModule>();
137 if (cacheItems.Length > 0)
138 {
139 m_log.Debug("[Cacheitems]: " + cacheItems.Length);
140 for (int iter = 0; iter < maxCacheitemsLoop; iter++)
141 {
142 m_log.Debug("[Cacheitems] {" + iter + "/" + cacheItems[iter].TextureIndex + "}: c-" + cacheItems[iter].CacheId + ", t-" +
143 cacheItems[iter].TextureID);
144 }
145
146 ScenePresence p = null;
147 if (m_scene.TryGetScenePresence(remoteClient.AgentId, out p))
148 { 126 {
127 // if cacheItems.Length > 0 viewer is giving us current textures information.
128 // baked ones should had been uploaded and in assets cache as local itens
129
130
131 if (cacheItems.Length == 0)
132 return; // no textures information, nothing to do
133
134 ScenePresence p = null;
135 if (!m_scene.TryGetScenePresence(remoteClient.AgentId, out p))
136 return; // what are we doing if there is no presence to cache for?
137
138 if (p.IsDeleted)
139 return; // does this really work?
140
141 int maxCacheitemsLoop = cacheItems.Length;
142 if (maxCacheitemsLoop > 20)
143 {
144 maxCacheitemsLoop = AvatarWearable.MAX_WEARABLES;
145 m_log.WarnFormat("[CACHEDBAKES]: Too Many Cache items Provided {0}, the max is {1}. Truncating!", cacheItems.Length, AvatarWearable.MAX_WEARABLES);
146 }
147
148 m_BakedTextureModule = m_scene.RequestModuleInterface<IBakedTextureModule>();
149
150
151 // some nice debug
152 m_log.Debug("[Cacheitems]: " + cacheItems.Length);
153 for (int iter = 0; iter < maxCacheitemsLoop; iter++)
154 {
155 m_log.Debug("[Cacheitems] {" + iter + "/" + cacheItems[iter].TextureIndex + "}: c-" + cacheItems[iter].CacheId + ", t-" +
156 cacheItems[iter].TextureID);
157 }
158
159 // p.Appearance.WearableCacheItems is in memory primary cashID to textures mapper
149 160
150 WearableCacheItem[] existingitems = p.Appearance.WearableCacheItems; 161 WearableCacheItem[] existingitems = p.Appearance.WearableCacheItems;
162
151 if (existingitems == null) 163 if (existingitems == null)
152 { 164 {
153 if (m_BakedTextureModule != null) 165 if (m_BakedTextureModule != null)
@@ -161,38 +173,22 @@ namespace OpenSim.Region.ClientStack.Linden
161 p.Appearance.WearableCacheItems = savedcache; 173 p.Appearance.WearableCacheItems = savedcache;
162 p.Appearance.WearableCacheItemsDirty = false; 174 p.Appearance.WearableCacheItemsDirty = false;
163 } 175 }
164
165 } 176 }
166 /* 177
167 * The following Catch types DO NOT WORK with m_BakedTextureModule.Get
168 * it jumps to the General Packet Exception Handler if you don't catch Exception!
169 *
170 catch (System.Net.Sockets.SocketException)
171 {
172 cacheItems = null;
173 }
174 catch (WebException)
175 {
176 cacheItems = null;
177 }
178 catch (InvalidOperationException)
179 {
180 cacheItems = null;
181 } */
182 catch (Exception) 178 catch (Exception)
183 { 179 {
184 // The service logs a sufficient error message. 180 // The service logs a sufficient error message.
185 } 181 }
186 182
187 183
188 if (savedcache != null) 184 if (savedcache != null)
189 existingitems = savedcache; 185 existingitems = savedcache;
190 } 186 }
191 } 187 }
188
192 // Existing items null means it's a fully new appearance 189 // Existing items null means it's a fully new appearance
193 if (existingitems == null) 190 if (existingitems == null)
194 { 191 {
195
196 for (int i = 0; i < maxCacheitemsLoop; i++) 192 for (int i = 0; i < maxCacheitemsLoop; i++)
197 { 193 {
198 if (textureEntry.FaceTextures.Length > cacheItems[i].TextureIndex) 194 if (textureEntry.FaceTextures.Length > cacheItems[i].TextureIndex)
@@ -205,7 +201,7 @@ namespace OpenSim.Region.ClientStack.Linden
205 AppearanceManager.DEFAULT_AVATAR_TEXTURE; 201 AppearanceManager.DEFAULT_AVATAR_TEXTURE;
206 continue; 202 continue;
207 } 203 }
208 cacheItems[i].TextureID =face.TextureID; 204 cacheItems[i].TextureID = face.TextureID;
209 if (m_scene.AssetService != null) 205 if (m_scene.AssetService != null)
210 cacheItems[i].TextureAsset = 206 cacheItems[i].TextureAsset =
211 m_scene.AssetService.GetCached(cacheItems[i].TextureID.ToString()); 207 m_scene.AssetService.GetCached(cacheItems[i].TextureID.ToString());
@@ -214,15 +210,10 @@ namespace OpenSim.Region.ClientStack.Linden
214 { 210 {
215 m_log.WarnFormat("[CACHEDBAKES]: Invalid Texture Index Provided, Texture doesn't exist or hasn't been uploaded yet {0}, the max is {1}. Skipping!", cacheItems[i].TextureIndex, textureEntry.FaceTextures.Length); 211 m_log.WarnFormat("[CACHEDBAKES]: Invalid Texture Index Provided, Texture doesn't exist or hasn't been uploaded yet {0}, the max is {1}. Skipping!", cacheItems[i].TextureIndex, textureEntry.FaceTextures.Length);
216 } 212 }
217
218
219 } 213 }
220 } 214 }
221 else 215 else
222 216 {
223
224 {
225 // for each uploaded baked texture
226 for (int i = 0; i < maxCacheitemsLoop; i++) 217 for (int i = 0; i < maxCacheitemsLoop; i++)
227 { 218 {
228 if (textureEntry.FaceTextures.Length > cacheItems[i].TextureIndex) 219 if (textureEntry.FaceTextures.Length > cacheItems[i].TextureIndex)
@@ -253,27 +244,24 @@ namespace OpenSim.Region.ClientStack.Linden
253 } 244 }
254 } 245 }
255 } 246 }
256
257 p.Appearance.WearableCacheItems = cacheItems; 247 p.Appearance.WearableCacheItems = cacheItems;
258 248
259 if (m_BakedTextureModule != null) 249 if (m_BakedTextureModule != null)
260 { 250 {
261 m_BakedTextureModule.Store(remoteClient.AgentId, cacheItems); 251 m_BakedTextureModule.Store(remoteClient.AgentId, cacheItems);
262 p.Appearance.WearableCacheItemsDirty = true; 252 p.Appearance.WearableCacheItemsDirty = true;
263 253
264 } 254 }
265 else 255 else
266 p.Appearance.WearableCacheItemsDirty = false; 256 p.Appearance.WearableCacheItemsDirty = false;
267 }
268 }
269
270 for (int iter = 0; iter < maxCacheitemsLoop; iter++)
271 {
272 m_log.Debug("[CacheitemsLeaving] {" + iter + "/" + cacheItems[iter].TextureIndex + "}: c-" + cacheItems[iter].CacheId + ", t-" +
273 cacheItems[iter].TextureID);
274 }
275 }
276 257
258 for (int iter = 0; iter < maxCacheitemsLoop; iter++)
259 {
260 m_log.Debug("[CacheitemsLeaving] {" + iter + "/" + cacheItems[iter].TextureIndex + "}: c-" + cacheItems[iter].CacheId + ", t-" +
261 cacheItems[iter].TextureID);
262 }
263 }
264 */
277 public void PostInitialise() 265 public void PostInitialise()
278 { 266 {
279 } 267 }
diff --git a/OpenSim/Region/ClientStack/Linden/UDP/LLClientView.cs b/OpenSim/Region/ClientStack/Linden/UDP/LLClientView.cs
index 08b6cb4..38a9af3 100644
--- a/OpenSim/Region/ClientStack/Linden/UDP/LLClientView.cs
+++ b/OpenSim/Region/ClientStack/Linden/UDP/LLClientView.cs
@@ -3684,6 +3684,11 @@ namespace OpenSim.Region.ClientStack.LindenUDP
3684 avp.Sender.IsTrial = false; 3684 avp.Sender.IsTrial = false;
3685 avp.Sender.ID = agentID; 3685 avp.Sender.ID = agentID;
3686 avp.AppearanceData = new AvatarAppearancePacket.AppearanceDataBlock[0]; 3686 avp.AppearanceData = new AvatarAppearancePacket.AppearanceDataBlock[0];
3687
3688 // this need be use in future
3689 // avp.AppearanceData[0].AppearanceVersion = 0;
3690 // avp.AppearanceData[0].CofVersion = 0;
3691
3687 //m_log.DebugFormat("[CLIENT]: Sending appearance for {0} to {1}", agentID.ToString(), AgentId.ToString()); 3692 //m_log.DebugFormat("[CLIENT]: Sending appearance for {0} to {1}", agentID.ToString(), AgentId.ToString());
3688 OutPacket(avp, ThrottleOutPacketType.Task); 3693 OutPacket(avp, ThrottleOutPacketType.Task);
3689 } 3694 }
@@ -12006,8 +12011,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP
12006 AgentCachedTextureResponsePacket cachedresp = (AgentCachedTextureResponsePacket)PacketPool.Instance.GetPacket(PacketType.AgentCachedTextureResponse); 12011 AgentCachedTextureResponsePacket cachedresp = (AgentCachedTextureResponsePacket)PacketPool.Instance.GetPacket(PacketType.AgentCachedTextureResponse);
12007 12012
12008 if (cachedtex.AgentData.SessionID != SessionId) 12013 if (cachedtex.AgentData.SessionID != SessionId)
12009 return false; 12014 return false;
12010
12011 12015
12012 // TODO: don't create new blocks if recycling an old packet 12016 // TODO: don't create new blocks if recycling an old packet
12013 cachedresp.AgentData.AgentID = AgentId; 12017 cachedresp.AgentData.AgentID = AgentId;
@@ -12022,23 +12026,27 @@ namespace OpenSim.Region.ClientStack.LindenUDP
12022 //WearableCacheItem[] items = fac.GetCachedItems(AgentId); 12026 //WearableCacheItem[] items = fac.GetCachedItems(AgentId);
12023 12027
12024 IAssetService cache = m_scene.AssetService; 12028 IAssetService cache = m_scene.AssetService;
12025 IBakedTextureModule bakedTextureModule = m_scene.RequestModuleInterface<IBakedTextureModule>();
12026 //bakedTextureModule = null; 12029 //bakedTextureModule = null;
12027 int maxWearablesLoop = cachedtex.WearableData.Length; 12030 int maxWearablesLoop = cachedtex.WearableData.Length;
12028 if (maxWearablesLoop > AvatarWearable.MAX_WEARABLES) 12031 if (maxWearablesLoop > AvatarWearable.MAX_WEARABLES)
12029 maxWearablesLoop = AvatarWearable.MAX_WEARABLES; 12032 maxWearablesLoop = AvatarWearable.MAX_WEARABLES;
12030 12033
12031// if (bakedTextureModule != null && cache != null) 12034 int cacheHits = 0;
12035
12032 if (cache != null) 12036 if (cache != null)
12033 { 12037 {
12034 // We need to make sure the asset stored in the bake is available on this server also by it's assetid before we map it to a Cacheid 12038 // We need to make sure the asset stored in the bake is available on this server also by it's assetid before we map it to a Cacheid
12035 12039
12036 WearableCacheItem[] cacheItems = null; 12040 WearableCacheItem[] cacheItems = null;
12041
12037 ScenePresence p = m_scene.GetScenePresence(AgentId); 12042 ScenePresence p = m_scene.GetScenePresence(AgentId);
12038 if (p.Appearance != null) 12043
12044 if (p!= null && p.Appearance != null)
12039 { 12045 {
12040 if (p.Appearance.WearableCacheItems == null || p.Appearance.WearableCacheItemsDirty) 12046 /* we should only check bakedTextureModule at login or when appearance changes
12047 if (p.Appearance.WearableCacheItems == null) // currently with a caching only bakemodule Appearance.Wearables.dirty as no use
12041 { 12048 {
12049 IBakedTextureModule bakedTextureModule = m_scene.RequestModuleInterface<IBakedTextureModule>();
12042 if (bakedTextureModule != null) 12050 if (bakedTextureModule != null)
12043 { 12051 {
12044 m_log.Debug("[ HandleAgentTextureCached] bakedTextureModule"); 12052 m_log.Debug("[ HandleAgentTextureCached] bakedTextureModule");
@@ -12047,23 +12055,21 @@ namespace OpenSim.Region.ClientStack.LindenUDP
12047 cacheItems = bakedTextureModule.Get(AgentId); 12055 cacheItems = bakedTextureModule.Get(AgentId);
12048 p.Appearance.WearableCacheItems = cacheItems; 12056 p.Appearance.WearableCacheItems = cacheItems;
12049 p.Appearance.WearableCacheItemsDirty = false; 12057 p.Appearance.WearableCacheItemsDirty = false;
12050 }
12051 12058
12052 /* 12059 if (cacheItems != null)
12053 * The following Catch types DO NOT WORK, it jumps to the General Packet Exception Handler if you don't catch Exception! 12060 {
12054 * 12061 foreach (WearableCacheItem item in cacheItems)
12055 catch (System.Net.Sockets.SocketException) 12062 {
12056 { 12063 if (item.TextureAsset != null)
12057 cacheItems = null; 12064 {
12058 } 12065 item.TextureAsset.Temporary = true;
12059 catch (WebException) 12066 item.TextureAsset.Local = true;
12060 { 12067 cache.Store(item.TextureAsset);
12061 cacheItems = null; 12068 }
12069 }
12070 }
12062 } 12071 }
12063 catch (InvalidOperationException) 12072
12064 {
12065 cacheItems = null;
12066 } */
12067 catch (Exception) 12073 catch (Exception)
12068 { 12074 {
12069 cacheItems = null; 12075 cacheItems = null;
@@ -12075,36 +12081,23 @@ namespace OpenSim.Region.ClientStack.LindenUDP
12075 { 12081 {
12076 cacheItems = p.Appearance.WearableCacheItems; 12082 cacheItems = p.Appearance.WearableCacheItems;
12077 } 12083 }
12084*/
12085 cacheItems = p.Appearance.WearableCacheItems;
12078 } 12086 }
12079 12087
12080 if (cache != null && cacheItems != null)
12081 {
12082 foreach (WearableCacheItem item in cacheItems)
12083 {
12084
12085 if (cache.GetCached(item.TextureID.ToString()) == null)
12086 {
12087 item.TextureAsset.Temporary = true;
12088 cache.Store(item.TextureAsset);
12089 }
12090 }
12091 }
12092
12093 if (cacheItems != null) 12088 if (cacheItems != null)
12094 { 12089 {
12095
12096 for (int i = 0; i < maxWearablesLoop; i++) 12090 for (int i = 0; i < maxWearablesLoop; i++)
12097 { 12091 {
12098 WearableCacheItem item = 12092 int idx = cachedtex.WearableData[i].TextureIndex;
12099 WearableCacheItem.SearchTextureIndex(cachedtex.WearableData[i].TextureIndex,cacheItems);
12100 12093
12101 cachedresp.WearableData[i] = new AgentCachedTextureResponsePacket.WearableDataBlock(); 12094 cachedresp.WearableData[i] = new AgentCachedTextureResponsePacket.WearableDataBlock();
12102 cachedresp.WearableData[i].TextureIndex= cachedtex.WearableData[i].TextureIndex; 12095 cachedresp.WearableData[i].TextureIndex = cachedtex.WearableData[i].TextureIndex;
12103 cachedresp.WearableData[i].HostName = new byte[0]; 12096 cachedresp.WearableData[i].HostName = new byte[0];
12104 if (item != null && cachedtex.WearableData[i].ID == item.CacheId) 12097 if (cachedtex.WearableData[i].ID == cacheItems[idx].CacheId)
12105 { 12098 {
12106 12099 cachedresp.WearableData[i].TextureID = cacheItems[idx].TextureID;
12107 cachedresp.WearableData[i].TextureID = item.TextureID; 12100 cacheHits++;
12108 } 12101 }
12109 else 12102 else
12110 { 12103 {
@@ -12124,36 +12117,19 @@ namespace OpenSim.Region.ClientStack.LindenUDP
12124 } 12117 }
12125 } 12118 }
12126 } 12119 }
12127 else 12120 else // no cache
12128 { 12121 {
12129 if (cache == null) 12122 for (int i = 0; i < maxWearablesLoop; i++)
12130 { 12123 {
12131 for (int i = 0; i < maxWearablesLoop; i++) 12124 cachedresp.WearableData[i] = new AgentCachedTextureResponsePacket.WearableDataBlock();
12132 { 12125 cachedresp.WearableData[i].TextureIndex = cachedtex.WearableData[i].TextureIndex;
12133 cachedresp.WearableData[i] = new AgentCachedTextureResponsePacket.WearableDataBlock(); 12126 cachedresp.WearableData[i].TextureID = UUID.Zero;
12134 cachedresp.WearableData[i].TextureIndex = cachedtex.WearableData[i].TextureIndex; 12127 cachedresp.WearableData[i].HostName = new byte[0];
12135 cachedresp.WearableData[i].TextureID = UUID.Zero;
12136 //UUID.Parse("8334fb6e-c2f5-46ee-807d-a435f61a8d46");
12137 cachedresp.WearableData[i].HostName = new byte[0];
12138 }
12139 }
12140 else
12141 {
12142 for (int i = 0; i < maxWearablesLoop; i++)
12143 {
12144 cachedresp.WearableData[i] = new AgentCachedTextureResponsePacket.WearableDataBlock();
12145 cachedresp.WearableData[i].TextureIndex = cachedtex.WearableData[i].TextureIndex;
12146
12147 if (cache.GetCached(cachedresp.WearableData[i].TextureID.ToString()) == null)
12148 cachedresp.WearableData[i].TextureID = UUID.Zero;
12149 //UUID.Parse("8334fb6e-c2f5-46ee-807d-a435f61a8d46");
12150// else
12151// cachedresp.WearableData[i].TextureID = UUID.Zero;
12152 // UUID.Parse("8334fb6e-c2f5-46ee-807d-a435f61a8d46");
12153 cachedresp.WearableData[i].HostName = new byte[0];
12154 }
12155 } 12128 }
12156 } 12129 }
12130
12131 m_log.DebugFormat("texture cached: hits {0}", cacheHits);
12132
12157 cachedresp.Header.Zerocoded = true; 12133 cachedresp.Header.Zerocoded = true;
12158 OutPacket(cachedresp, ThrottleOutPacketType.Task); 12134 OutPacket(cachedresp, ThrottleOutPacketType.Task);
12159 12135
diff --git a/OpenSim/Region/CoreModules/Avatar/AvatarFactory/AvatarFactoryModule.cs b/OpenSim/Region/CoreModules/Avatar/AvatarFactory/AvatarFactoryModule.cs
index 09cc998..b4aefce 100644
--- a/OpenSim/Region/CoreModules/Avatar/AvatarFactory/AvatarFactoryModule.cs
+++ b/OpenSim/Region/CoreModules/Avatar/AvatarFactory/AvatarFactoryModule.cs
@@ -188,27 +188,7 @@ namespace OpenSim.Region.CoreModules.Avatar.AvatarFactory
188 // Process the visual params, this may change height as well 188 // Process the visual params, this may change height as well
189 if (visualParams != null) 189 if (visualParams != null)
190 { 190 {
191 // string[] visualParamsStrings = new string[visualParams.Length];
192 // for (int i = 0; i < visualParams.Length; i++)
193 // visualParamsStrings[i] = visualParams[i].ToString();
194 // m_log.DebugFormat(
195 // "[AVFACTORY]: Setting visual params for {0} to {1}",
196 // client.Name, string.Join(", ", visualParamsStrings));
197/*
198 float oldHeight = sp.Appearance.AvatarHeight;
199 changed = sp.Appearance.SetVisualParams(visualParams);
200
201 if (sp.Appearance.AvatarHeight != oldHeight && sp.Appearance.AvatarHeight > 0)
202 ((ScenePresence)sp).SetHeight(sp.Appearance.AvatarHeight);
203 */
204// float oldoff = sp.Appearance.AvatarFeetOffset;
205// Vector3 oldbox = sp.Appearance.AvatarBoxSize;
206 changed = sp.Appearance.SetVisualParams(visualParams); 191 changed = sp.Appearance.SetVisualParams(visualParams);
207// float off = sp.Appearance.AvatarFeetOffset;
208// Vector3 box = sp.Appearance.AvatarBoxSize;
209// if(oldoff != off || oldbox != box)
210// ((ScenePresence)sp).SetSize(box,off);
211
212 } 192 }
213 193
214 // Process the baked texture array 194 // Process the baked texture array
@@ -222,9 +202,15 @@ namespace OpenSim.Region.CoreModules.Avatar.AvatarFactory
222 202
223// WriteBakedTexturesReport(sp, m_log.DebugFormat); 203// WriteBakedTexturesReport(sp, m_log.DebugFormat);
224 204
205
225 // If bake textures are missing and this is not an NPC, request a rebake from client 206 // If bake textures are missing and this is not an NPC, request a rebake from client
226 if (!ValidateBakedTextureCache(sp) && (((ScenePresence)sp).PresenceType != PresenceType.Npc)) 207 // rebake may messup caching, and should not be needed
227 RequestRebake(sp, true); 208
209
210// if (!UpdateBakedTextureCache(sp,cacheItems) && (((ScenePresence)sp).PresenceType != PresenceType.Npc))
211// RequestRebake(sp, true);
212
213 UpdateBakedTextureCache(sp, cacheItems);
228 214
229 // This appears to be set only in the final stage of the appearance 215 // This appears to be set only in the final stage of the appearance
230 // update transaction. In theory, we should be able to do an immediate 216 // update transaction. In theory, we should be able to do an immediate
@@ -377,13 +363,138 @@ namespace OpenSim.Region.CoreModules.Avatar.AvatarFactory
377 } 363 }
378 } 364 }
379 365
366 // called on textures update
367 public bool UpdateBakedTextureCache(IScenePresence sp, WearableCacheItem[] cacheItems)
368 {
369 bool defonly = true; // are we only using default textures
370
371 // uploaded baked textures will be in assets local cache
372 IAssetService cache = m_scene.AssetService;
373
374 int validDirtyBakes = 0;
375 int hits = 0;
376
377 // our main cacheIDs mapper is p.Appearance.WearableCacheItems
378 WearableCacheItem[] wearableCache = sp.Appearance.WearableCacheItems;
379
380 if (wearableCache == null)
381 {
382 wearableCache = WearableCacheItem.GetDefaultCacheItem();
383 }
384
385 // Process received baked textures
386 for (int i = 0; i < cacheItems.Length; i++)
387 {
388 int idx = (int)cacheItems[i].TextureIndex;
389 Primitive.TextureEntryFace face = sp.Appearance.Texture.FaceTextures[idx];
390
391 // No face
392 if (face == null)
393 {
394 // for some reason viewer is cleaning this
395 sp.Appearance.Texture.FaceTextures[idx] = sp.Appearance.Texture.CreateFace((uint) idx);
396 sp.Appearance.Texture.FaceTextures[idx].TextureID = AppearanceManager.DEFAULT_AVATAR_TEXTURE;
397 wearableCache[idx].CacheId = UUID.Zero;
398 wearableCache[idx].TextureID = UUID.Zero;
399 wearableCache[idx].TextureAsset = null;
400 continue;
401 }
402 else
403 {
404 if (face.TextureID == UUID.Zero || face.TextureID == AppearanceManager.DEFAULT_AVATAR_TEXTURE)
405 {
406 wearableCache[idx].CacheId = UUID.Zero;
407 wearableCache[idx].TextureID = UUID.Zero;
408 wearableCache[idx].TextureAsset = null;
409 continue;
410 }
411
412 defonly = false; // found a non-default texture reference
413
414 if(sp.Appearance.Texture.FaceTextures[idx].TextureID == wearableCache[idx].TextureID)
415 {
416 if(wearableCache[idx].CacheId != cacheItems[i].CacheId)
417 {
418 wearableCache[idx].CacheId = cacheItems[i].CacheId;
419 validDirtyBakes++;
420 hits++;
421 //assuming this can only happen if asset is in cache
422 }
423 continue;
424 }
425
426
427 wearableCache[idx].TextureAsset = null;
428 if (cache != null)
429 wearableCache[idx].TextureAsset = cache.GetCached(face.TextureID.ToString());
430
431 if (wearableCache[idx].TextureAsset != null)
432 {
433 wearableCache[idx].CacheId = cacheItems[i].CacheId;
434 wearableCache[idx].TextureID = sp.Appearance.Texture.FaceTextures[idx].TextureID;
435 validDirtyBakes++;
436 hits++;
437 }
438 else
439 {
440 wearableCache[idx].CacheId = UUID.Zero;
441 wearableCache[idx].TextureID = UUID.Zero;
442 wearableCache[idx].TextureAsset = null;
443 continue;
444 }
445 }
446 }
447
448 sp.Appearance.WearableCacheItems = wearableCache;
449
450 // if we got a full set of baked textures save all in BakedTextureModule
451
452 if (validDirtyBakes == cacheItems.Length)
453 {
454 IBakedTextureModule m_BakedTextureModule = m_scene.RequestModuleInterface<IBakedTextureModule>();
455 if (m_BakedTextureModule != null)
456 {
457 m_log.Debug("[UpdateBakedCache] uploading to bakedModule cache");
458
459 m_BakedTextureModule.Store(sp.UUID, wearableCache);
460 }
461 }
462
463 // debug
464 for (int iter = 0; iter < AvatarAppearance.BAKE_INDICES.Length; iter++)
465 {
466 int j = AvatarAppearance.BAKE_INDICES[iter];
467 m_log.Debug("[UpdateBCache] {" + iter + "/" +
468 sp.Appearance.WearableCacheItems[j].TextureIndex + "}: c-" +
469 sp.Appearance.WearableCacheItems[j].CacheId + ", t-" +
470 sp.Appearance.WearableCacheItems[j].TextureID);
471 }
472
473 // If we only found default textures, then the appearance is not cached
474 return (defonly ? false : true);
475 }
476
477 // called when we get a new root avatar
380 public bool ValidateBakedTextureCache(IScenePresence sp) 478 public bool ValidateBakedTextureCache(IScenePresence sp)
381 { 479 {
382 bool defonly = true; // are we only using default textures 480 bool defonly = true; // are we only using default textures
383 IImprovedAssetCache cache = m_scene.RequestModuleInterface<IImprovedAssetCache>(); 481 IAssetService cache = m_scene.AssetService;
384 IBakedTextureModule bakedModule = m_scene.RequestModuleInterface<IBakedTextureModule>(); 482 IBakedTextureModule bakedModule = m_scene.RequestModuleInterface<IBakedTextureModule>();
385 WearableCacheItem[] wearableCache = null; 483 WearableCacheItem[] wearableCache = null;
386 484
485 // debug
486 for (int iter = 0; iter < AvatarAppearance.BAKE_INDICES.Length; iter++)
487 {
488 int j = AvatarAppearance.BAKE_INDICES[iter];
489 Primitive.TextureEntryFace face = sp.Appearance.Texture.FaceTextures[iter];
490 if(face != null)
491 m_log.Debug("[ValidateBakedCache] {" + iter + "/" + j + " t - " + face.TextureID);
492 else
493 m_log.Debug("[ValidateBakedCache] {" + iter + "/" + j + " t - No texture");
494 }
495
496
497 int hits = 0;
387 // Cache wearable data for teleport. 498 // Cache wearable data for teleport.
388 // Only makes sense if there's a bake module and a cache module 499 // Only makes sense if there's a bake module and a cache module
389 if (bakedModule != null && cache != null) 500 if (bakedModule != null && cache != null)
@@ -394,41 +505,35 @@ namespace OpenSim.Region.CoreModules.Avatar.AvatarFactory
394 } 505 }
395 catch (Exception) 506 catch (Exception)
396 { 507 {
397 508 wearableCache = null;
398 } 509 }
510
399 if (wearableCache != null) 511 if (wearableCache != null)
400 { 512 {
401 for (int i = 0; i < wearableCache.Length; i++) 513 for (int i = 0; i < wearableCache.Length; i++)
402 { 514 {
403 cache.Cache(wearableCache[i].TextureAsset); 515
404 } 516 m_log.Debug("[ValidateBakedCache] got bakedModule cache");
405 } 517
406 } 518 if (wearableCache[i].TextureAsset != null)
407 /*
408 IBakedTextureModule bakedModule = m_scene.RequestModuleInterface<IBakedTextureModule>();
409 if (invService.GetRootFolder(userID) != null)
410 {
411 WearableCacheItem[] wearableCache = null;
412 if (bakedModule != null)
413 {
414 try
415 {
416 wearableCache = bakedModule.Get(userID);
417 appearance.WearableCacheItems = wearableCache;
418 appearance.WearableCacheItemsDirty = false;
419 foreach (WearableCacheItem item in wearableCache)
420 { 519 {
421 appearance.Texture.FaceTextures[item.TextureIndex].TextureID = item.TextureID; 520 wearableCache[i].TextureAsset.Temporary = true;
521 wearableCache[i].TextureAsset.Local = true;
522 cache.Store(wearableCache[i].TextureAsset);
523 }
524 else
525 {
526 wearableCache[i].TextureID = UUID.Zero;
527 wearableCache[i].CacheId = UUID.Zero;
422 } 528 }
423 }
424 catch (Exception)
425 {
426
427 } 529 }
428 } 530 }
429 */ 531 }
532
533 if(wearableCache == null)
534 wearableCache = WearableCacheItem.GetDefaultCacheItem();
430 535
431 // Process the texture entry 536 // Process the baked textures
432 for (int i = 0; i < AvatarAppearance.BAKE_INDICES.Length; i++) 537 for (int i = 0; i < AvatarAppearance.BAKE_INDICES.Length; i++)
433 { 538 {
434 int idx = AvatarAppearance.BAKE_INDICES[i]; 539 int idx = AvatarAppearance.BAKE_INDICES[i];
@@ -437,61 +542,73 @@ namespace OpenSim.Region.CoreModules.Avatar.AvatarFactory
437 // No face, so lets check our baked service cache, teleport or login. 542 // No face, so lets check our baked service cache, teleport or login.
438 if (face == null) 543 if (face == null)
439 { 544 {
440 if (wearableCache != null) 545 sp.Appearance.Texture.FaceTextures[idx] = sp.Appearance.Texture.CreateFace((uint)idx);
546 if (wearableCache[idx].TextureID != UUID.Zero)
441 { 547 {
442 // If we find the an appearance item, set it as the textureentry and the face 548 sp.Appearance.Texture.FaceTextures[idx].TextureID = wearableCache[idx].TextureID;
443 WearableCacheItem searchitem = WearableCacheItem.SearchTextureIndex((uint) idx, wearableCache); 549 face = sp.Appearance.Texture.FaceTextures[idx];
444 if (searchitem != null) 550 // let run to end of loop to check cache
445 {
446 sp.Appearance.Texture.FaceTextures[idx] = sp.Appearance.Texture.CreateFace((uint) idx);
447 sp.Appearance.Texture.FaceTextures[idx].TextureID = searchitem.TextureID;
448 face = sp.Appearance.Texture.FaceTextures[idx];
449 }
450 else
451 {
452 // if there is no texture entry and no baked cache, skip it
453 continue;
454 }
455 } 551 }
456 else 552 else
457 { 553 {
458 //No texture entry face and no cache. Skip this face. 554 sp.Appearance.Texture.FaceTextures[idx].TextureID = AppearanceManager.DEFAULT_AVATAR_TEXTURE;
555 face = sp.Appearance.Texture.FaceTextures[idx];
556 wearableCache[idx].CacheId = UUID.Zero;
557 wearableCache[idx].TextureID = UUID.Zero;
558 wearableCache[idx].TextureAsset = null;
459 continue; 559 continue;
460 } 560 }
461 } 561 }
462 562
463
464// m_log.DebugFormat(
465// "[AVFACTORY]: Looking for texture {0}, id {1} for {2} {3}",
466// face.TextureID, idx, client.Name, client.AgentId);
467 563
468 // if the texture is one of the "defaults" then skip it
469 // this should probably be more intelligent (skirt texture doesnt matter
470 // if the avatar isnt wearing a skirt) but if any of the main baked
471 // textures is default then the rest should be as well
472 if (face.TextureID == UUID.Zero || face.TextureID == AppearanceManager.DEFAULT_AVATAR_TEXTURE) 564 if (face.TextureID == UUID.Zero || face.TextureID == AppearanceManager.DEFAULT_AVATAR_TEXTURE)
565 {
566 wearableCache[idx].CacheId = UUID.Zero;
567 wearableCache[idx].TextureID = UUID.Zero;
568 wearableCache[idx].TextureAsset = null;
473 continue; 569 continue;
474 570 }
571
475 defonly = false; // found a non-default texture reference 572 defonly = false; // found a non-default texture reference
476 573
477 if (cache != null) 574 if(wearableCache[idx].TextureID != sp.Appearance.Texture.FaceTextures[idx].TextureID)
478 { 575 {
479 if (!cache.Check(face.TextureID.ToString())) 576 wearableCache[idx].CacheId = UUID.Zero;
480 return false; 577 wearableCache[idx].TextureID = UUID.Zero;
578 wearableCache[idx].TextureAsset = null;
579 continue;
481 } 580 }
482 else 581
582 wearableCache[idx].TextureAsset = null;
583 if (cache != null)
483 { 584 {
484 if (m_scene.AssetService.Get(face.TextureID.ToString()) == null) 585 wearableCache[idx].TextureAsset = m_scene.AssetService.Get(face.TextureID.ToString());
485 return false; 586 if (wearableCache[idx].TextureAsset == null)
587 {
588 wearableCache[idx].CacheId = UUID.Zero;
589 wearableCache[idx].TextureID = UUID.Zero;
590 }
591 else
592 hits++;
486 } 593 }
487 } 594 }
488 595
489// m_log.DebugFormat("[AVFACTORY]: Completed texture check for {0} {1}", sp.Name, sp.UUID); 596 sp.Appearance.WearableCacheItems = wearableCache;
597
598 m_log.DebugFormat("[AVFACTORY]: Completed texture check for {0} {1} {2} {3}", sp.Name, sp.UUID, hits, defonly.ToString());
599 // debug
600 for (int iter = 0; iter < AvatarAppearance.BAKE_INDICES.Length; iter++)
601 {
602 int j = AvatarAppearance.BAKE_INDICES[iter];
603 m_log.Debug("[ValidateBakedCache] {" + iter + "/" +
604 sp.Appearance.WearableCacheItems[j].TextureIndex + "}: c-" +
605 sp.Appearance.WearableCacheItems[j].CacheId + ", t-" +
606 sp.Appearance.WearableCacheItems[j].TextureID);
607 }
490 608
491 // If we only found default textures, then the appearance is not cached 609 // If we only found default textures, then the appearance is not cached
492 return (defonly ? false : true); 610 return (defonly ? false : true);
493 } 611 }
494
495 public int RequestRebake(IScenePresence sp, bool missingTexturesOnly) 612 public int RequestRebake(IScenePresence sp, bool missingTexturesOnly)
496 { 613 {
497 int texturesRebaked = 0; 614 int texturesRebaked = 0;
diff --git a/OpenSim/Region/Framework/Scenes/ScenePresence.cs b/OpenSim/Region/Framework/Scenes/ScenePresence.cs
index f41a828..965d7c2 100644
--- a/OpenSim/Region/Framework/Scenes/ScenePresence.cs
+++ b/OpenSim/Region/Framework/Scenes/ScenePresence.cs
@@ -3502,7 +3502,7 @@ namespace OpenSim.Region.Framework.Scenes
3502 // If we aren't using a cached appearance, then clear out the baked textures 3502 // If we aren't using a cached appearance, then clear out the baked textures
3503 if (!cachedappearance) 3503 if (!cachedappearance)
3504 { 3504 {
3505 Appearance.ResetAppearance(); 3505// Appearance.ResetAppearance();
3506// save what ???? 3506// save what ????
3507// maybe needed so the tryretry repair works? 3507// maybe needed so the tryretry repair works?
3508 if (m_scene.AvatarFactory != null) 3508 if (m_scene.AvatarFactory != null)