aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Framework/Communications/Cache/AssetCache.cs
diff options
context:
space:
mode:
authorlbsa712007-10-30 09:05:31 +0000
committerlbsa712007-10-30 09:05:31 +0000
commit67e12b95ea7b68f4904a7484d77ecfd787d16d0c (patch)
tree20b00d24c8a7617017960432ec044852e3ad5fa9 /OpenSim/Framework/Communications/Cache/AssetCache.cs
parent* Deleted .user file (diff)
downloadopensim-SC-67e12b95ea7b68f4904a7484d77ecfd787d16d0c.zip
opensim-SC-67e12b95ea7b68f4904a7484d77ecfd787d16d0c.tar.gz
opensim-SC-67e12b95ea7b68f4904a7484d77ecfd787d16d0c.tar.bz2
opensim-SC-67e12b95ea7b68f4904a7484d77ecfd787d16d0c.tar.xz
* Optimized usings
* Shortened type references * Removed redundant 'this' qualifier
Diffstat (limited to 'OpenSim/Framework/Communications/Cache/AssetCache.cs')
-rw-r--r--OpenSim/Framework/Communications/Cache/AssetCache.cs207
1 files changed, 100 insertions, 107 deletions
diff --git a/OpenSim/Framework/Communications/Cache/AssetCache.cs b/OpenSim/Framework/Communications/Cache/AssetCache.cs
index 39e2887..ca2fc35 100644
--- a/OpenSim/Framework/Communications/Cache/AssetCache.cs
+++ b/OpenSim/Framework/Communications/Cache/AssetCache.cs
@@ -29,12 +29,9 @@
29using System; 29using System;
30using System.Collections.Generic; 30using System.Collections.Generic;
31using System.IO; 31using System.IO;
32using System.Reflection;
33using System.Threading; 32using System.Threading;
34using libsecondlife; 33using libsecondlife;
35using libsecondlife.Packets; 34using libsecondlife.Packets;
36using OpenSim.Framework.Interfaces;
37using OpenSim.Framework;
38using OpenSim.Framework.Console; 35using OpenSim.Framework.Console;
39 36
40namespace OpenSim.Framework.Communications.Cache 37namespace OpenSim.Framework.Communications.Cache
@@ -51,18 +48,22 @@ namespace OpenSim.Framework.Communications.Cache
51 public Dictionary<LLUUID, AssetInfo> Assets; 48 public Dictionary<LLUUID, AssetInfo> Assets;
52 public Dictionary<LLUUID, TextureImage> Textures; 49 public Dictionary<LLUUID, TextureImage> Textures;
53 50
54 public List<AssetRequest> AssetRequests = new List<AssetRequest>(); //assets ready to be sent to viewers 51 public List<AssetRequest> AssetRequests = new List<AssetRequest>(); //assets ready to be sent to viewers
55 public List<AssetRequest> TextureRequests = new List<AssetRequest>(); //textures ready to be sent 52 public List<AssetRequest> TextureRequests = new List<AssetRequest>(); //textures ready to be sent
56 53
57 public Dictionary<LLUUID, AssetRequest> RequestedAssets = new Dictionary<LLUUID, AssetRequest>(); //Assets requested from the asset server 54 public Dictionary<LLUUID, AssetRequest> RequestedAssets = new Dictionary<LLUUID, AssetRequest>();
58 public Dictionary<LLUUID, AssetRequest> RequestedTextures = new Dictionary<LLUUID, AssetRequest>(); //Textures requested from the asset server 55 //Assets requested from the asset server
56
57 public Dictionary<LLUUID, AssetRequest> RequestedTextures = new Dictionary<LLUUID, AssetRequest>();
58 //Textures requested from the asset server
59 59
60 public Dictionary<LLUUID, TextureSender> SendingTextures = new Dictionary<LLUUID, TextureSender>(); 60 public Dictionary<LLUUID, TextureSender> SendingTextures = new Dictionary<LLUUID, TextureSender>();
61 private BlockingQueue<TextureSender> QueueTextures = new BlockingQueue<TextureSender>(); 61 private BlockingQueue<TextureSender> QueueTextures = new BlockingQueue<TextureSender>();
62 62
63 private Dictionary<LLUUID, List<LLUUID>> AvatarRecievedTextures = new Dictionary<LLUUID, List<LLUUID>>(); 63 private Dictionary<LLUUID, List<LLUUID>> AvatarRecievedTextures = new Dictionary<LLUUID, List<LLUUID>>();
64 64
65 private Dictionary<LLUUID, Dictionary<LLUUID, int>> TimesTextureSent = new Dictionary<LLUUID, Dictionary<LLUUID, int>>(); 65 private Dictionary<LLUUID, Dictionary<LLUUID, int>> TimesTextureSent =
66 new Dictionary<LLUUID, Dictionary<LLUUID, int>>();
66 67
67 public Dictionary<LLUUID, AssetRequestsList> RequestLists = new Dictionary<LLUUID, AssetRequestsList>(); 68 public Dictionary<LLUUID, AssetRequestsList> RequestLists = new Dictionary<LLUUID, AssetRequestsList>();
68 69
@@ -76,19 +77,18 @@ namespace OpenSim.Framework.Communications.Cache
76 /// </summary> 77 /// </summary>
77 public AssetCache(IAssetServer assetServer) 78 public AssetCache(IAssetServer assetServer)
78 { 79 {
79 OpenSim.Framework.Console.MainLog.Instance.Verbose("ASSETSTORAGE","Creating Asset cache"); 80 MainLog.Instance.Verbose("ASSETSTORAGE", "Creating Asset cache");
80 _assetServer = assetServer; 81 _assetServer = assetServer;
81 _assetServer.SetReceiver(this); 82 _assetServer.SetReceiver(this);
82 Assets = new Dictionary<LLUUID, AssetInfo>(); 83 Assets = new Dictionary<LLUUID, AssetInfo>();
83 Textures = new Dictionary<LLUUID, TextureImage>(); 84 Textures = new Dictionary<LLUUID, TextureImage>();
84 this._assetCacheThread = new Thread(new ThreadStart(RunAssetManager)); 85 _assetCacheThread = new Thread(new ThreadStart(RunAssetManager));
85 this._assetCacheThread.IsBackground = true; 86 _assetCacheThread.IsBackground = true;
86 this._assetCacheThread.Start(); 87 _assetCacheThread.Start();
87
88 this.TextureSenderThread = new Thread(new ThreadStart(this.ProcessTextureSenders));
89 this.TextureSenderThread.IsBackground = true;
90 this.TextureSenderThread.Start();
91 88
89 TextureSenderThread = new Thread(new ThreadStart(ProcessTextureSenders));
90 TextureSenderThread.IsBackground = true;
91 TextureSenderThread.Start();
92 } 92 }
93 93
94 /// <summary> 94 /// <summary>
@@ -100,8 +100,8 @@ namespace OpenSim.Framework.Communications.Cache
100 { 100 {
101 try 101 try
102 { 102 {
103 this.ProcessAssetQueue(); 103 ProcessAssetQueue();
104 this.ProcessTextureQueue(); 104 ProcessTextureQueue();
105 Thread.Sleep(500); 105 Thread.Sleep(500);
106 } 106 }
107 catch (Exception e) 107 catch (Exception e)
@@ -115,13 +115,13 @@ namespace OpenSim.Framework.Communications.Cache
115 public AssetBase GetAsset(LLUUID assetID) 115 public AssetBase GetAsset(LLUUID assetID)
116 { 116 {
117 AssetBase asset = null; 117 AssetBase asset = null;
118 if (this.Textures.ContainsKey(assetID)) 118 if (Textures.ContainsKey(assetID))
119 { 119 {
120 asset = this.Textures[assetID]; 120 asset = Textures[assetID];
121 } 121 }
122 else if (this.Assets.ContainsKey(assetID)) 122 else if (Assets.ContainsKey(assetID))
123 { 123 {
124 asset = this.Assets[assetID]; 124 asset = Assets[assetID];
125 } 125 }
126 return asset; 126 return asset;
127 } 127 }
@@ -129,13 +129,13 @@ namespace OpenSim.Framework.Communications.Cache
129 public void GetAsset(LLUUID assetID, AssetRequestCallback callback) 129 public void GetAsset(LLUUID assetID, AssetRequestCallback callback)
130 { 130 {
131 AssetBase asset = null; 131 AssetBase asset = null;
132 if (this.Textures.ContainsKey(assetID)) 132 if (Textures.ContainsKey(assetID))
133 { 133 {
134 asset = this.Textures[assetID]; 134 asset = Textures[assetID];
135 } 135 }
136 else if (this.Assets.ContainsKey(assetID)) 136 else if (Assets.ContainsKey(assetID))
137 { 137 {
138 asset = this.Assets[assetID]; 138 asset = Assets[assetID];
139 } 139 }
140 140
141 if (asset != null) 141 if (asset != null)
@@ -145,7 +145,7 @@ namespace OpenSim.Framework.Communications.Cache
145 else 145 else
146 { 146 {
147 NewAssetRequest req = new NewAssetRequest(assetID, callback); 147 NewAssetRequest req = new NewAssetRequest(assetID, callback);
148 if (this.RequestLists.ContainsKey(assetID)) 148 if (RequestLists.ContainsKey(assetID))
149 { 149 {
150 lock (RequestLists) 150 lock (RequestLists)
151 { 151 {
@@ -161,7 +161,7 @@ namespace OpenSim.Framework.Communications.Cache
161 RequestLists.Add(assetID, reqList); 161 RequestLists.Add(assetID, reqList);
162 } 162 }
163 } 163 }
164 this._assetServer.FetchAsset(assetID, false); 164 _assetServer.FetchAsset(assetID, false);
165 } 165 }
166 } 166 }
167 167
@@ -171,22 +171,23 @@ namespace OpenSim.Framework.Communications.Cache
171 AssetBase asset = GetAsset(assetID); 171 AssetBase asset = GetAsset(assetID);
172 if (asset == null) 172 if (asset == null)
173 { 173 {
174 this._assetServer.FetchAsset(assetID, isTexture); 174 _assetServer.FetchAsset(assetID, isTexture);
175 } 175 }
176 return asset; 176 return asset;
177 } 177 }
178 178
179 public void AddAsset(AssetBase asset) 179 public void AddAsset(AssetBase asset)
180 { 180 {
181 //System.Console.WriteLine("adding asset " + asset.FullID.ToStringHyphenated()); 181 //System.Console.WriteLine("adding asset " + asset.FullID.ToStringHyphenated());
182 if (asset.Type == 0) 182 if (asset.Type == 0)
183 { 183 {
184 //Console.WriteLine("which is a texture"); 184 //Console.WriteLine("which is a texture");
185 if (!Textures.ContainsKey(asset.FullID)) 185 if (!Textures.ContainsKey(asset.FullID))
186 { //texture 186 {
187 //texture
187 TextureImage textur = new TextureImage(asset); 188 TextureImage textur = new TextureImage(asset);
188 Textures.Add(textur.FullID, textur); 189 Textures.Add(textur.FullID, textur);
189 if(!asset.Temporary) 190 if (!asset.Temporary)
190 _assetServer.StoreAndCommitAsset(asset); 191 _assetServer.StoreAndCommitAsset(asset);
191 } 192 }
192 else 193 else
@@ -219,49 +220,47 @@ namespace OpenSim.Framework.Communications.Cache
219 /// </summary> 220 /// </summary>
220 private void ProcessTextureQueue() 221 private void ProcessTextureQueue()
221 { 222 {
222 if (this.TextureRequests.Count == 0) 223 if (TextureRequests.Count == 0)
223 { 224 {
224 //no requests waiting 225 //no requests waiting
225 return; 226 return;
226 } 227 }
227 int num; 228 int num;
228 num = this.TextureRequests.Count; 229 num = TextureRequests.Count;
229 230
230 AssetRequest req; 231 AssetRequest req;
231 for (int i = 0; i < num; i++) 232 for (int i = 0; i < num; i++)
232 { 233 {
233 req = (AssetRequest)this.TextureRequests[i]; 234 req = (AssetRequest) TextureRequests[i];
234 if (!this.SendingTextures.ContainsKey(req.ImageInfo.FullID)) 235 if (!SendingTextures.ContainsKey(req.ImageInfo.FullID))
235 { 236 {
236 //Console.WriteLine("new texture to send"); 237 //Console.WriteLine("new texture to send");
237 TextureSender sender = new TextureSender(req); 238 TextureSender sender = new TextureSender(req);
238 //sender.OnComplete += this.TextureSent; 239 //sender.OnComplete += this.TextureSent;
239 this.SendingTextures.Add(req.ImageInfo.FullID, sender); 240 SendingTextures.Add(req.ImageInfo.FullID, sender);
240 this.QueueTextures.Enqueue(sender); 241 QueueTextures.Enqueue(sender);
241 } 242 }
242
243 } 243 }
244 244
245 this.TextureRequests.Clear(); 245 TextureRequests.Clear();
246 } 246 }
247 247
248 public void ProcessTextureSenders() 248 public void ProcessTextureSenders()
249 { 249 {
250 while (true) 250 while (true)
251 { 251 {
252 TextureSender sender = this.QueueTextures.Dequeue(); 252 TextureSender sender = QueueTextures.Dequeue();
253 253
254 bool finished = sender.SendTexture(); 254 bool finished = sender.SendTexture();
255 if (finished) 255 if (finished)
256 { 256 {
257 this.TextureSent(sender); 257 TextureSent(sender);
258 } 258 }
259 else 259 else
260 { 260 {
261 // Console.WriteLine("readding texture"); 261 // Console.WriteLine("readding texture");
262 this.QueueTextures.Enqueue(sender); 262 QueueTextures.Enqueue(sender);
263 } 263 }
264
265 } 264 }
266 } 265 }
267 266
@@ -271,16 +270,16 @@ namespace OpenSim.Framework.Communications.Cache
271 /// <param name="sender"></param> 270 /// <param name="sender"></param>
272 public void TextureSent(TextureSender sender) 271 public void TextureSent(TextureSender sender)
273 { 272 {
274 if (this.SendingTextures.ContainsKey(sender.request.ImageInfo.FullID)) 273 if (SendingTextures.ContainsKey(sender.request.ImageInfo.FullID))
275 { 274 {
276 this.SendingTextures.Remove(sender.request.ImageInfo.FullID); 275 SendingTextures.Remove(sender.request.ImageInfo.FullID);
277 // this.AvatarRecievedTextures[sender.request.RequestUser.AgentId].Add(sender.request.ImageInfo.FullID); 276 // this.AvatarRecievedTextures[sender.request.RequestUser.AgentId].Add(sender.request.ImageInfo.FullID);
278 } 277 }
279 } 278 }
280 279
281 public void AssetReceived(AssetBase asset, bool IsTexture) 280 public void AssetReceived(AssetBase asset, bool IsTexture)
282 { 281 {
283 if (asset.FullID != LLUUID.Zero) // if it is set to zero then the asset wasn't found by the server 282 if (asset.FullID != LLUUID.Zero) // if it is set to zero then the asset wasn't found by the server
284 { 283 {
285 //check if it is a texture or not 284 //check if it is a texture or not
286 //then add to the correct cache list 285 //then add to the correct cache list
@@ -292,48 +291,48 @@ namespace OpenSim.Framework.Communications.Cache
292 //Console.WriteLine("asset recieved from asset server"); 291 //Console.WriteLine("asset recieved from asset server");
293 292
294 TextureImage image = new TextureImage(asset); 293 TextureImage image = new TextureImage(asset);
295 if (!this.Textures.ContainsKey(image.FullID)) 294 if (!Textures.ContainsKey(image.FullID))
296 { 295 {
297 this.Textures.Add(image.FullID, image); 296 Textures.Add(image.FullID, image);
298 if (this.RequestedTextures.ContainsKey(image.FullID)) 297 if (RequestedTextures.ContainsKey(image.FullID))
299 { 298 {
300 AssetRequest req = this.RequestedTextures[image.FullID]; 299 AssetRequest req = RequestedTextures[image.FullID];
301 req.ImageInfo = image; 300 req.ImageInfo = image;
302 if (image.Data.LongLength > 600) 301 if (image.Data.LongLength > 600)
303 { 302 {
304 //over 600 bytes so split up file 303 //over 600 bytes so split up file
305 req.NumPackets = 1 + (int)(image.Data.Length - 600) / 1000; 304 req.NumPackets = 1 + (int) (image.Data.Length - 600)/1000;
306 } 305 }
307 else 306 else
308 { 307 {
309 req.NumPackets = 1; 308 req.NumPackets = 1;
310 } 309 }
311 this.RequestedTextures.Remove(image.FullID); 310 RequestedTextures.Remove(image.FullID);
312 this.TextureRequests.Add(req); 311 TextureRequests.Add(req);
313 } 312 }
314 } 313 }
315 } 314 }
316 else 315 else
317 { 316 {
318 AssetInfo assetInf = new AssetInfo(asset); 317 AssetInfo assetInf = new AssetInfo(asset);
319 if (!this.Assets.ContainsKey(assetInf.FullID)) 318 if (!Assets.ContainsKey(assetInf.FullID))
320 { 319 {
321 this.Assets.Add(assetInf.FullID, assetInf); 320 Assets.Add(assetInf.FullID, assetInf);
322 if (this.RequestedAssets.ContainsKey(assetInf.FullID)) 321 if (RequestedAssets.ContainsKey(assetInf.FullID))
323 { 322 {
324 AssetRequest req = this.RequestedAssets[assetInf.FullID]; 323 AssetRequest req = RequestedAssets[assetInf.FullID];
325 req.AssetInf = assetInf; 324 req.AssetInf = assetInf;
326 if (assetInf.Data.LongLength > 600) 325 if (assetInf.Data.LongLength > 600)
327 { 326 {
328 //over 600 bytes so split up file 327 //over 600 bytes so split up file
329 req.NumPackets = 1 + (int)(assetInf.Data.Length - 600 + 999) / 1000; 328 req.NumPackets = 1 + (int) (assetInf.Data.Length - 600 + 999)/1000;
330 } 329 }
331 else 330 else
332 { 331 {
333 req.NumPackets = 1; 332 req.NumPackets = 1;
334 } 333 }
335 this.RequestedAssets.Remove(assetInf.FullID); 334 RequestedAssets.Remove(assetInf.FullID);
336 this.AssetRequests.Add(req); 335 AssetRequests.Add(req);
337 } 336 }
338 } 337 }
339 } 338 }
@@ -345,7 +344,7 @@ namespace OpenSim.Framework.Communications.Cache
345 { 344 {
346 req.Callback(asset.FullID, asset); 345 req.Callback(asset.FullID, asset);
347 } 346 }
348 347
349 lock (RequestLists) 348 lock (RequestLists)
350 { 349 {
351 RequestLists.Remove(asset.FullID); 350 RequestLists.Remove(asset.FullID);
@@ -373,6 +372,7 @@ namespace OpenSim.Framework.Communications.Cache
373 } 372 }
374 373
375 #region Assets 374 #region Assets
375
376 /// <summary> 376 /// <summary>
377 /// 377 ///
378 /// </summary> 378 /// </summary>
@@ -396,11 +396,11 @@ namespace OpenSim.Framework.Communications.Cache
396 } 396 }
397 //check to see if asset is in local cache, if not we need to request it from asset server. 397 //check to see if asset is in local cache, if not we need to request it from asset server.
398 //Console.WriteLine("asset request " + requestID); 398 //Console.WriteLine("asset request " + requestID);
399 if (!this.Assets.ContainsKey(requestID)) 399 if (!Assets.ContainsKey(requestID))
400 { 400 {
401 //not found asset 401 //not found asset
402 // so request from asset server 402 // so request from asset server
403 if (!this.RequestedAssets.ContainsKey(requestID)) 403 if (!RequestedAssets.ContainsKey(requestID))
404 { 404 {
405 AssetRequest request = new AssetRequest(); 405 AssetRequest request = new AssetRequest();
406 request.RequestUser = userInfo; 406 request.RequestUser = userInfo;
@@ -408,13 +408,13 @@ namespace OpenSim.Framework.Communications.Cache
408 request.TransferRequestID = transferRequest.TransferInfo.TransferID; 408 request.TransferRequestID = transferRequest.TransferInfo.TransferID;
409 request.AssetRequestSource = source; 409 request.AssetRequestSource = source;
410 request.Params = transferRequest.TransferInfo.Params; 410 request.Params = transferRequest.TransferInfo.Params;
411 this.RequestedAssets.Add(requestID, request); 411 RequestedAssets.Add(requestID, request);
412 this._assetServer.FetchAsset(requestID, false); 412 _assetServer.FetchAsset(requestID, false);
413 } 413 }
414 return; 414 return;
415 } 415 }
416 //it is in our cache 416 //it is in our cache
417 AssetInfo asset = this.Assets[requestID]; 417 AssetInfo asset = Assets[requestID];
418 418
419 //work out how many packets it should be sent in 419 //work out how many packets it should be sent in
420 // and add to the AssetRequests list 420 // and add to the AssetRequests list
@@ -429,14 +429,14 @@ namespace OpenSim.Framework.Communications.Cache
429 if (asset.Data.LongLength > 600) 429 if (asset.Data.LongLength > 600)
430 { 430 {
431 //over 600 bytes so split up file 431 //over 600 bytes so split up file
432 req.NumPackets = 1 + (int)(asset.Data.Length - 600 + 999) / 1000; 432 req.NumPackets = 1 + (int) (asset.Data.Length - 600 + 999)/1000;
433 } 433 }
434 else 434 else
435 { 435 {
436 req.NumPackets = 1; 436 req.NumPackets = 1;
437 } 437 }
438 438
439 this.AssetRequests.Add(req); 439 AssetRequests.Add(req);
440 } 440 }
441 441
442 /// <summary> 442 /// <summary>
@@ -444,17 +444,17 @@ namespace OpenSim.Framework.Communications.Cache
444 /// </summary> 444 /// </summary>
445 private void ProcessAssetQueue() 445 private void ProcessAssetQueue()
446 { 446 {
447 if (this.AssetRequests.Count == 0) 447 if (AssetRequests.Count == 0)
448 { 448 {
449 //no requests waiting 449 //no requests waiting
450 return; 450 return;
451 } 451 }
452 int num; 452 int num;
453 453
454 if (this.AssetRequests.Count < 5) 454 if (AssetRequests.Count < 5)
455 { 455 {
456 //lower than 5 so do all of them 456 //lower than 5 so do all of them
457 num = this.AssetRequests.Count; 457 num = AssetRequests.Count;
458 } 458 }
459 else 459 else
460 { 460 {
@@ -463,7 +463,7 @@ namespace OpenSim.Framework.Communications.Cache
463 AssetRequest req; 463 AssetRequest req;
464 for (int i = 0; i < num; i++) 464 for (int i = 0; i < num; i++)
465 { 465 {
466 req = (AssetRequest)this.AssetRequests[i]; 466 req = (AssetRequest) AssetRequests[i];
467 //Console.WriteLine("sending asset " + req.RequestAssetID); 467 //Console.WriteLine("sending asset " + req.RequestAssetID);
468 TransferInfoPacket Transfer = new TransferInfoPacket(); 468 TransferInfoPacket Transfer = new TransferInfoPacket();
469 Transfer.TransferInfo.ChannelType = 2; 469 Transfer.TransferInfo.ChannelType = 2;
@@ -473,7 +473,7 @@ namespace OpenSim.Framework.Communications.Cache
473 { 473 {
474 Transfer.TransferInfo.Params = new byte[20]; 474 Transfer.TransferInfo.Params = new byte[20];
475 Array.Copy(req.RequestAssetID.GetBytes(), 0, Transfer.TransferInfo.Params, 0, 16); 475 Array.Copy(req.RequestAssetID.GetBytes(), 0, Transfer.TransferInfo.Params, 0, 16);
476 int assType = (int)req.AssetInf.Type; 476 int assType = (int) req.AssetInf.Type;
477 Array.Copy(Helpers.IntToBytes(assType), 0, Transfer.TransferInfo.Params, 16, 4); 477 Array.Copy(Helpers.IntToBytes(assType), 0, Transfer.TransferInfo.Params, 16, 4);
478 } 478 }
479 else if (req.AssetRequestSource == 3) 479 else if (req.AssetRequestSource == 3)
@@ -483,7 +483,7 @@ namespace OpenSim.Framework.Communications.Cache
483 //Array.Copy(req.RequestUser.AgentId.GetBytes(), 0, Transfer.TransferInfo.Params, 0, 16); 483 //Array.Copy(req.RequestUser.AgentId.GetBytes(), 0, Transfer.TransferInfo.Params, 0, 16);
484 //Array.Copy(req.RequestUser.SessionId.GetBytes(), 0, Transfer.TransferInfo.Params, 16, 16); 484 //Array.Copy(req.RequestUser.SessionId.GetBytes(), 0, Transfer.TransferInfo.Params, 16, 16);
485 } 485 }
486 Transfer.TransferInfo.Size = (int)req.AssetInf.Data.Length; 486 Transfer.TransferInfo.Size = (int) req.AssetInf.Data.Length;
487 Transfer.TransferInfo.TransferID = req.TransferRequestID; 487 Transfer.TransferInfo.TransferID = req.TransferRequestID;
488 req.RequestUser.OutPacket(Transfer); 488 req.RequestUser.OutPacket(Transfer);
489 489
@@ -533,19 +533,19 @@ namespace OpenSim.Framework.Communications.Cache
533 req.RequestUser.OutPacket(TransferPacket); 533 req.RequestUser.OutPacket(TransferPacket);
534 } 534 }
535 } 535 }
536
537 } 536 }
538 537
539 //remove requests that have been completed 538 //remove requests that have been completed
540 for (int i = 0; i < num; i++) 539 for (int i = 0; i < num; i++)
541 { 540 {
542 this.AssetRequests.RemoveAt(0); 541 AssetRequests.RemoveAt(0);
543 } 542 }
544
545 } 543 }
544
546 #endregion 545 #endregion
547 546
548 #region Textures 547 #region Textures
548
549 /// <summary> 549 /// <summary>
550 /// 550 ///
551 /// </summary> 551 /// </summary>
@@ -553,21 +553,21 @@ namespace OpenSim.Framework.Communications.Cache
553 /// <param name="imageID"></param> 553 /// <param name="imageID"></param>
554 public void AddTextureRequest(IClientAPI userInfo, LLUUID imageID, uint packetNumber, int discard) 554 public void AddTextureRequest(IClientAPI userInfo, LLUUID imageID, uint packetNumber, int discard)
555 { 555 {
556 // System.Console.WriteLine("texture request for " + imageID.ToStringHyphenated() + " packetnumber= " + packetNumber); 556 // System.Console.WriteLine("texture request for " + imageID.ToStringHyphenated() + " packetnumber= " + packetNumber);
557 //check to see if texture is in local cache, if not request from asset server 557 //check to see if texture is in local cache, if not request from asset server
558 if (!this.AvatarRecievedTextures.ContainsKey(userInfo.AgentId)) 558 if (!AvatarRecievedTextures.ContainsKey(userInfo.AgentId))
559 { 559 {
560 this.AvatarRecievedTextures.Add(userInfo.AgentId, new List<LLUUID>()); 560 AvatarRecievedTextures.Add(userInfo.AgentId, new List<LLUUID>());
561 } 561 }
562 /* if(this.AvatarRecievedTextures[userInfo.AgentId].Contains(imageID)) 562 /* if(this.AvatarRecievedTextures[userInfo.AgentId].Contains(imageID))
563 { 563 {
564 //Console.WriteLine(userInfo.AgentId +" is requesting a image( "+ imageID+" that has already been sent to them"); 564 //Console.WriteLine(userInfo.AgentId +" is requesting a image( "+ imageID+" that has already been sent to them");
565 return; 565 return;
566 }*/ 566 }*/
567 567
568 if (!this.Textures.ContainsKey(imageID)) 568 if (!Textures.ContainsKey(imageID))
569 { 569 {
570 if (!this.RequestedTextures.ContainsKey(imageID)) 570 if (!RequestedTextures.ContainsKey(imageID))
571 { 571 {
572 //not is cache so request from asset server 572 //not is cache so request from asset server
573 AssetRequest request = new AssetRequest(); 573 AssetRequest request = new AssetRequest();
@@ -575,14 +575,14 @@ namespace OpenSim.Framework.Communications.Cache
575 request.RequestAssetID = imageID; 575 request.RequestAssetID = imageID;
576 request.IsTextureRequest = true; 576 request.IsTextureRequest = true;
577 request.DiscardLevel = discard; 577 request.DiscardLevel = discard;
578 this.RequestedTextures.Add(imageID, request); 578 RequestedTextures.Add(imageID, request);
579 this._assetServer.FetchAsset(imageID, true); 579 _assetServer.FetchAsset(imageID, true);
580 } 580 }
581 return; 581 return;
582 } 582 }
583 583
584 // System.Console.WriteLine("texture already in cache"); 584 // System.Console.WriteLine("texture already in cache");
585 TextureImage imag = this.Textures[imageID]; 585 TextureImage imag = Textures[imageID];
586 AssetRequest req = new AssetRequest(); 586 AssetRequest req = new AssetRequest();
587 req.RequestUser = userInfo; 587 req.RequestUser = userInfo;
588 req.RequestAssetID = imageID; 588 req.RequestAssetID = imageID;
@@ -594,7 +594,7 @@ namespace OpenSim.Framework.Communications.Cache
594 { 594 {
595 //Console.WriteLine("{0}", imag.Data.LongLength); 595 //Console.WriteLine("{0}", imag.Data.LongLength);
596 //over 600 bytes so split up file 596 //over 600 bytes so split up file
597 req.NumPackets = 2 + (int)(imag.Data.Length - 601) / 1000; 597 req.NumPackets = 2 + (int) (imag.Data.Length - 601)/1000;
598 //Console.WriteLine("texture is " + imag.Data.Length + " which we will send in " +req.NumPackets +" packets"); 598 //Console.WriteLine("texture is " + imag.Data.Length + " which we will send in " +req.NumPackets +" packets");
599 } 599 }
600 else 600 else
@@ -603,12 +603,11 @@ namespace OpenSim.Framework.Communications.Cache
603 } 603 }
604 if (packetNumber != 0) 604 if (packetNumber != 0)
605 { 605 {
606 req.PacketCounter = (int)packetNumber; 606 req.PacketCounter = (int) packetNumber;
607 } 607 }
608 this.TextureRequests.Add(req); 608 TextureRequests.Add(req);
609 } 609 }
610 610
611
612 #endregion 611 #endregion
613 612
614 public class AssetRequest 613 public class AssetRequest
@@ -630,7 +629,6 @@ namespace OpenSim.Framework.Communications.Cache
630 629
631 public AssetRequest() 630 public AssetRequest()
632 { 631 {
633
634 } 632 }
635 } 633 }
636 634
@@ -638,7 +636,6 @@ namespace OpenSim.Framework.Communications.Cache
638 { 636 {
639 public AssetInfo() 637 public AssetInfo()
640 { 638 {
641
642 } 639 }
643 640
644 public AssetInfo(AssetBase aBase) 641 public AssetInfo(AssetBase aBase)
@@ -656,7 +653,6 @@ namespace OpenSim.Framework.Communications.Cache
656 { 653 {
657 public TextureImage() 654 public TextureImage()
658 { 655 {
659
660 } 656 }
661 657
662 public TextureImage(AssetBase aBase) 658 public TextureImage(AssetBase aBase)
@@ -678,7 +674,6 @@ namespace OpenSim.Framework.Communications.Cache
678 public TextureSender(AssetRequest req) 674 public TextureSender(AssetRequest req)
679 { 675 {
680 request = req; 676 request = req;
681
682 } 677 }
683 678
684 public bool SendTexture() 679 public bool SendTexture()
@@ -686,7 +681,8 @@ namespace OpenSim.Framework.Communications.Cache
686 SendPacket(); 681 SendPacket();
687 counter++; 682 counter++;
688 683
689 if ((request.PacketCounter >= request.NumPackets) | counter > 100 | (request.NumPackets == 1) | (request.DiscardLevel == -1)) 684 if ((request.PacketCounter >= request.NumPackets) | counter > 100 | (request.NumPackets == 1) |
685 (request.DiscardLevel == -1))
690 { 686 {
691 return true; 687 return true;
692 } 688 }
@@ -707,7 +703,7 @@ namespace OpenSim.Framework.Communications.Cache
707 im.Header.Reliable = false; 703 im.Header.Reliable = false;
708 im.ImageID.Packets = 1; 704 im.ImageID.Packets = 1;
709 im.ImageID.ID = req.ImageInfo.FullID; 705 im.ImageID.ID = req.ImageInfo.FullID;
710 im.ImageID.Size = (uint)req.ImageInfo.Data.Length; 706 im.ImageID.Size = (uint) req.ImageInfo.Data.Length;
711 im.ImageData.Data = req.ImageInfo.Data; 707 im.ImageData.Data = req.ImageInfo.Data;
712 im.ImageID.Codec = 2; 708 im.ImageID.Codec = 2;
713 req.RequestUser.OutPacket(im); 709 req.RequestUser.OutPacket(im);
@@ -721,9 +717,9 @@ namespace OpenSim.Framework.Communications.Cache
721 //more than one packet so split file up 717 //more than one packet so split file up
722 ImageDataPacket im = new ImageDataPacket(); 718 ImageDataPacket im = new ImageDataPacket();
723 im.Header.Reliable = false; 719 im.Header.Reliable = false;
724 im.ImageID.Packets = (ushort)(req.NumPackets); 720 im.ImageID.Packets = (ushort) (req.NumPackets);
725 im.ImageID.ID = req.ImageInfo.FullID; 721 im.ImageID.ID = req.ImageInfo.FullID;
726 im.ImageID.Size = (uint)req.ImageInfo.Data.Length; 722 im.ImageID.Size = (uint) req.ImageInfo.Data.Length;
727 im.ImageData.Data = new byte[600]; 723 im.ImageData.Data = new byte[600];
728 Array.Copy(req.ImageInfo.Data, 0, im.ImageData.Data, 0, 600); 724 Array.Copy(req.ImageInfo.Data, 0, im.ImageData.Data, 0, 600);
729 im.ImageID.Codec = 2; 725 im.ImageID.Codec = 2;
@@ -742,19 +738,18 @@ namespace OpenSim.Framework.Communications.Cache
742 //more than one packet so split file up 738 //more than one packet so split file up
743 ImagePacketPacket im = new ImagePacketPacket(); 739 ImagePacketPacket im = new ImagePacketPacket();
744 im.Header.Reliable = false; 740 im.Header.Reliable = false;
745 im.ImageID.Packet = (ushort)(req.PacketCounter); 741 im.ImageID.Packet = (ushort) (req.PacketCounter);
746 im.ImageID.ID = req.ImageInfo.FullID; 742 im.ImageID.ID = req.ImageInfo.FullID;
747 int size = req.ImageInfo.Data.Length - 600 - (1000 * (req.PacketCounter - 1)); 743 int size = req.ImageInfo.Data.Length - 600 - (1000*(req.PacketCounter - 1));
748 if (size > 1000) size = 1000; 744 if (size > 1000) size = 1000;
749 //Console.WriteLine("length= {0} counter= {1} size= {2}",req.ImageInfo.Data.Length, req.PacketCounter, size); 745 //Console.WriteLine("length= {0} counter= {1} size= {2}",req.ImageInfo.Data.Length, req.PacketCounter, size);
750 im.ImageData.Data = new byte[size]; 746 im.ImageData.Data = new byte[size];
751 Array.Copy(req.ImageInfo.Data, 600 + (1000 * (req.PacketCounter - 1)), im.ImageData.Data, 0, size); 747 Array.Copy(req.ImageInfo.Data, 600 + (1000*(req.PacketCounter - 1)), im.ImageData.Data, 0, size);
752 req.RequestUser.OutPacket(im); 748 req.RequestUser.OutPacket(im);
753 req.PacketCounter++; 749 req.PacketCounter++;
754 //req.ImageInfo.last_used = time; 750 //req.ImageInfo.last_used = time;
755 //System.Console.WriteLine("sent a packet of texture: "+req.ImageInfo.FullID); 751 //System.Console.WriteLine("sent a packet of texture: "+req.ImageInfo.FullID);
756 } 752 }
757
758 } 753 }
759 754
760 private void SaveAssetToFile(string filename, byte[] data) 755 private void SaveAssetToFile(string filename, byte[] data)
@@ -789,7 +784,5 @@ namespace OpenSim.Framework.Communications.Cache
789 AssetID = assetID; 784 AssetID = assetID;
790 Callback = callback; 785 Callback = callback;
791 } 786 }
792
793
794 } 787 }
795} 788} \ No newline at end of file