AssetCache.cs 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682
  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 OpenSim 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. using System;
  28. using System.Collections.Generic;
  29. using System.Reflection;
  30. using System.Threading;
  31. using GlynnTucker.Cache;
  32. using log4net;
  33. using OpenMetaverse;
  34. using OpenMetaverse.Packets;
  35. using OpenSim.Framework.Statistics;
  36. namespace OpenSim.Framework.Communications.Cache
  37. {
  38. // public delegate void AssetRequestCallback(UUID assetID, AssetBase asset);
  39. /// <summary>
  40. /// Manages local cache of assets and their sending to viewers.
  41. /// </summary>
  42. ///
  43. /// This class actually encapsulates two largely separate mechanisms. One mechanism fetches assets either
  44. /// synchronously or async and passes the data back to the requester. The second mechanism fetches assets and
  45. /// sends packetised data directly back to the client. The only point where they meet is AssetReceived() and
  46. /// AssetNotFound(), which means they do share the same asset and texture caches.I agr
  47. public class AssetCache : IAssetCache
  48. {
  49. #region IPlugin
  50. /// <summary>
  51. /// The methods and properties in this section are needed to
  52. /// support the IPlugin interface. They cann all be overridden
  53. /// as needed by a derived class.
  54. /// </summary>
  55. public virtual string Name
  56. {
  57. get { return "OpenSim.Framework.Communications.Cache.AssetCache"; }
  58. }
  59. public virtual string Version
  60. {
  61. get { return "1.0"; }
  62. }
  63. public virtual void Initialise()
  64. {
  65. m_log.Debug("[ASSET CACHE]: Asset cache null initialisation");
  66. }
  67. public virtual void Initialise(IAssetServer assetServer)
  68. {
  69. m_log.Debug("[ASSET CACHE]: Asset cache server-specified initialisation");
  70. m_log.InfoFormat("[ASSET CACHE]: Asset cache initialisation [{0}/{1}]", Name, Version);
  71. Initialize();
  72. m_assetServer = assetServer;
  73. m_assetServer.SetReceiver(this);
  74. Thread assetCacheThread = new Thread(RunAssetManager);
  75. assetCacheThread.Name = "AssetCacheThread";
  76. assetCacheThread.IsBackground = true;
  77. assetCacheThread.Start();
  78. ThreadTracker.Add(assetCacheThread);
  79. }
  80. public virtual void Initialise(ConfigSettings settings, IAssetServer assetServer)
  81. {
  82. m_log.Debug("[ASSET CACHE]: Asset cache configured initialisation");
  83. Initialise(assetServer);
  84. }
  85. public AssetCache()
  86. {
  87. m_log.Debug("[ASSET CACHE]: Asset cache (plugin constructor)");
  88. }
  89. public void Dispose()
  90. {
  91. }
  92. #endregion
  93. protected ICache m_memcache = new SimpleMemoryCache();
  94. private static readonly ILog m_log
  95. = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
  96. /// <summary>
  97. /// The cache of assets. This does not include textures.
  98. /// </summary>
  99. //private Dictionary<UUID, AssetInfo> Assets;
  100. /// <summary>
  101. /// The cache of textures.
  102. /// </summary>
  103. //private Dictionary<UUID, TextureImage> Textures;
  104. /// <summary>
  105. /// Assets requests which are waiting for asset server data. This includes texture requests
  106. /// </summary>
  107. private Dictionary<UUID, AssetRequest> RequestedAssets;
  108. /// <summary>
  109. /// Asset requests with data which are ready to be sent back to requesters. This includes textures.
  110. /// </summary>
  111. private List<AssetRequest> AssetRequests;
  112. /// <summary>
  113. /// Until the asset request is fulfilled, each asset request is associated with a list of requesters
  114. /// </summary>
  115. private Dictionary<UUID, AssetRequestsList> RequestLists;
  116. /// <summary>
  117. /// The 'server' from which assets can be requested and to which assets are persisted.
  118. /// </summary>
  119. private IAssetServer m_assetServer;
  120. public IAssetServer AssetServer
  121. {
  122. get { return m_assetServer; }
  123. }
  124. /// <summary>
  125. /// Report statistical data.
  126. /// </summary>
  127. public void ShowState()
  128. {
  129. m_log.InfoFormat("Memcache:{0} RequestLists:{1}",
  130. m_memcache.Count,
  131. // AssetRequests.Count,
  132. // RequestedAssets.Count,
  133. RequestLists.Count);
  134. }
  135. /// <summary>
  136. /// Clear the asset cache.
  137. /// </summary>
  138. public void Clear()
  139. {
  140. m_log.Info("[ASSET CACHE]: Clearing Asset cache");
  141. if (StatsManager.SimExtraStats != null)
  142. StatsManager.SimExtraStats.ClearAssetCacheStatistics();
  143. Initialize();
  144. }
  145. /// <summary>
  146. /// Initialize the cache.
  147. /// </summary>
  148. private void Initialize()
  149. {
  150. AssetRequests = new List<AssetRequest>();
  151. RequestedAssets = new Dictionary<UUID, AssetRequest>();
  152. RequestLists = new Dictionary<UUID, AssetRequestsList>();
  153. }
  154. /// <summary>
  155. /// Constructor. Initialize will need to be called separately.
  156. /// </summary>
  157. /// <param name="assetServer"></param>
  158. public AssetCache(IAssetServer assetServer)
  159. {
  160. m_log.Info("[ASSET CACHE]: Asset cache direct constructor");
  161. Initialise(assetServer);
  162. }
  163. /// <summary>
  164. /// Process the asset queue which holds data which is packeted up and sent
  165. /// directly back to the client.
  166. /// </summary>
  167. private void RunAssetManager()
  168. {
  169. while (true)
  170. {
  171. try
  172. {
  173. ProcessAssetQueue();
  174. Thread.Sleep(500);
  175. }
  176. catch (Exception e)
  177. {
  178. m_log.Error("[ASSET CACHE]: " + e.ToString());
  179. }
  180. }
  181. }
  182. /// <summary>
  183. /// Only get an asset if we already have it in the cache.
  184. /// </summary>
  185. /// <param name="assetId"></param>
  186. /// <param name="asset"></param>
  187. /// <returns>true if the asset was in the cache, false if it was not</returns>
  188. public bool TryGetCachedAsset(UUID assetId, out AssetBase asset)
  189. {
  190. Object tmp;
  191. if (m_memcache.TryGet(assetId, out tmp))
  192. {
  193. asset = (AssetBase)tmp;
  194. //m_log.Info("Retrieved from cache " + assetId);
  195. return true;
  196. }
  197. asset = null;
  198. return false;
  199. }
  200. /// <summary>
  201. /// Asynchronously retrieve an asset.
  202. /// </summary>
  203. /// <param name="assetId"></param>
  204. /// <param name="callback">
  205. /// <param name="isTexture"></param>
  206. /// A callback invoked when the asset has either been found or not found.
  207. /// If the asset was found this is called with the asset UUID and the asset data
  208. /// If the asset was not found this is still called with the asset UUID but with a null asset data reference</param>
  209. public void GetAsset(UUID assetId, AssetRequestCallback callback, bool isTexture)
  210. {
  211. //m_log.DebugFormat("[ASSET CACHE]: Requesting {0} {1}", isTexture ? "texture" : "asset", assetId);
  212. // Xantor 20080526:
  213. // if a request is made for an asset which is not in the cache yet, but has already been requested by
  214. // something else, queue up the callbacks on that requestor instead of swamping the assetserver
  215. // with multiple requests for the same asset.
  216. AssetBase asset;
  217. if (TryGetCachedAsset(assetId, out asset))
  218. {
  219. callback(assetId, asset);
  220. }
  221. else
  222. {
  223. // m_log.DebugFormat("[ASSET CACHE]: Adding request for {0} {1}", isTexture ? "texture" : "asset", assetId);
  224. NewAssetRequest req = new NewAssetRequest(callback);
  225. AssetRequestsList requestList;
  226. lock (RequestLists)
  227. {
  228. if (RequestLists.TryGetValue(assetId, out requestList)) // do we already have a request pending?
  229. {
  230. // m_log.DebugFormat("[ASSET CACHE]: Intercepted Duplicate request for {0} {1}", isTexture ? "texture" : "asset", assetId);
  231. // add to callbacks for this assetId
  232. RequestLists[assetId].Requests.Add(req);
  233. }
  234. else
  235. {
  236. // m_log.DebugFormat("[ASSET CACHE]: Adding request for {0} {1}", isTexture ? "texture" : "asset", assetId);
  237. requestList = new AssetRequestsList();
  238. requestList.TimeRequested = DateTime.Now;
  239. requestList.Requests.Add(req);
  240. RequestLists.Add(assetId, requestList);
  241. m_assetServer.RequestAsset(assetId, isTexture);
  242. }
  243. }
  244. }
  245. }
  246. /// <summary>
  247. /// Synchronously retreive an asset. If the asset isn't in the cache, a request will be made to the persistent store to
  248. /// load it into the cache.
  249. /// </summary>
  250. ///
  251. /// XXX We'll keep polling the cache until we get the asset or we exceed
  252. /// the allowed number of polls. This isn't a very good way of doing things since a single thread
  253. /// is processing inbound packets, so if the asset server is slow, we could block this for up to
  254. /// the timeout period. Whereever possible we want to use the asynchronous callback GetAsset()
  255. ///
  256. /// <param name="assetID"></param>
  257. /// <param name="isTexture"></param>
  258. /// <returns>null if the asset could not be retrieved</returns>
  259. public AssetBase GetAsset(UUID assetID, bool isTexture)
  260. {
  261. // I'm not going over 3 seconds since this will be blocking processing of all the other inbound
  262. // packets from the client.
  263. const int pollPeriod = 200;
  264. int maxPolls = 15;
  265. AssetBase asset;
  266. if (TryGetCachedAsset(assetID, out asset))
  267. {
  268. return asset;
  269. }
  270. m_assetServer.RequestAsset(assetID, isTexture);
  271. do
  272. {
  273. Thread.Sleep(pollPeriod);
  274. if (TryGetCachedAsset(assetID, out asset))
  275. {
  276. return asset;
  277. }
  278. }
  279. while (--maxPolls > 0);
  280. m_log.WarnFormat("[ASSET CACHE]: {0} {1} was not received before the retrieval timeout was reached",
  281. isTexture ? "texture" : "asset", assetID.ToString());
  282. return null;
  283. }
  284. /// <summary>
  285. /// Add an asset to both the persistent store and the cache.
  286. /// </summary>
  287. /// <param name="asset"></param>
  288. public void AddAsset(AssetBase asset)
  289. {
  290. if (!m_memcache.Contains(asset.FullID))
  291. {
  292. m_log.Info("[CACHE] Caching " + asset.FullID + " for 24 hours from last access");
  293. // Use 24 hour rolling asset cache.
  294. m_memcache.AddOrUpdate(asset.FullID, asset, TimeSpan.FromHours(24));
  295. // According to http://wiki.secondlife.com/wiki/AssetUploadRequest, Local signifies that the
  296. // information is stored locally. It could disappear, in which case we could send the
  297. // ImageNotInDatabase packet to tell the client this.
  298. //
  299. // However, this doesn't quite appear to work with local textures that are part of an avatar's
  300. // appearance texture set. Whilst sending an ImageNotInDatabase does trigger an automatic rebake
  301. // and reupload by the client, if those assets aren't pushed to the asset server anyway, then
  302. // on crossing onto another region server, other avatars can no longer get the required textures.
  303. // There doesn't appear to be any signal from the sim to the newly region border crossed client
  304. // asking it to reupload its local texture assets to that region server.
  305. //
  306. // One can think of other cunning ways around this. For instance, on a region crossing or teleport,
  307. // the original sim could squirt local assets to the new sim. Or the new sim could have pointers
  308. // to the original sim to fetch the 'local' assets (this is getting more complicated).
  309. //
  310. // But for now, we're going to take the easy way out and store local assets globally.
  311. //
  312. // TODO: Also, Temporary is now deprecated. We should start ignoring it and not passing it out from LLClientView.
  313. if (!asset.Temporary || asset.Local)
  314. {
  315. m_assetServer.StoreAsset(asset);
  316. }
  317. }
  318. }
  319. /// <summary>
  320. /// Allows you to clear a specific asset by uuid out
  321. /// of the asset cache. This is needed because the osdynamic
  322. /// texture code grows the asset cache without bounds. The
  323. /// real solution here is a much better cache archicture, but
  324. /// this is a stop gap measure until we have such a thing.
  325. /// </summary>
  326. public void ExpireAsset(UUID uuid)
  327. {
  328. // uuid is unique, so no need to worry about it showing up
  329. // in the 2 caches differently. Also, locks are probably
  330. // needed in all of this, or move to synchronized non
  331. // generic forms for Dictionaries.
  332. if (m_memcache.Contains(uuid))
  333. {
  334. m_memcache.Remove(uuid);
  335. }
  336. }
  337. // See IAssetReceiver
  338. public virtual void AssetReceived(AssetBase asset, bool IsTexture)
  339. {
  340. AssetInfo assetInf = new AssetInfo(asset);
  341. if (!m_memcache.Contains(assetInf.FullID))
  342. {
  343. m_memcache.AddOrUpdate(assetInf.FullID, assetInf, TimeSpan.FromHours(24));
  344. if (StatsManager.SimExtraStats != null)
  345. {
  346. StatsManager.SimExtraStats.AddAsset(assetInf);
  347. }
  348. if (RequestedAssets.ContainsKey(assetInf.FullID))
  349. {
  350. AssetRequest req = RequestedAssets[assetInf.FullID];
  351. req.AssetInf = assetInf;
  352. req.NumPackets = CalculateNumPackets(assetInf.Data);
  353. RequestedAssets.Remove(assetInf.FullID);
  354. // If it's a direct request for a script, drop it
  355. // because it's a hacked client
  356. if (req.AssetRequestSource != 2 || assetInf.Type != 10)
  357. AssetRequests.Add(req);
  358. }
  359. }
  360. // Notify requesters for this asset
  361. AssetRequestsList reqList;
  362. lock (RequestLists)
  363. {
  364. if (RequestLists.TryGetValue(asset.FullID, out reqList))
  365. RequestLists.Remove(asset.FullID);
  366. }
  367. if (reqList != null)
  368. {
  369. if (StatsManager.SimExtraStats != null)
  370. StatsManager.SimExtraStats.AddAssetRequestTimeAfterCacheMiss(DateTime.Now - reqList.TimeRequested);
  371. foreach (NewAssetRequest req in reqList.Requests)
  372. {
  373. // Xantor 20080526 are we really calling all the callbacks if multiple queued for 1 request? -- Yes, checked
  374. // m_log.DebugFormat("[ASSET CACHE]: Callback for asset {0}", asset.FullID);
  375. req.Callback(asset.FullID, asset);
  376. }
  377. }
  378. }
  379. // See IAssetReceiver
  380. public virtual void AssetNotFound(UUID assetID, bool IsTexture)
  381. {
  382. // m_log.WarnFormat("[ASSET CACHE]: AssetNotFound for {0}", assetID);
  383. // Remember the fact that this asset could not be found to prevent delays from repeated requests
  384. m_memcache.Add(assetID, null, TimeSpan.FromHours(24));
  385. // Notify requesters for this asset
  386. AssetRequestsList reqList;
  387. lock (RequestLists)
  388. {
  389. if (RequestLists.TryGetValue(assetID, out reqList))
  390. RequestLists.Remove(assetID);
  391. }
  392. if (reqList != null)
  393. {
  394. if (StatsManager.SimExtraStats != null)
  395. StatsManager.SimExtraStats.AddAssetRequestTimeAfterCacheMiss(DateTime.Now - reqList.TimeRequested);
  396. foreach (NewAssetRequest req in reqList.Requests)
  397. {
  398. req.Callback(assetID, null);
  399. }
  400. }
  401. }
  402. /// <summary>
  403. /// Calculate the number of packets required to send the asset to the client.
  404. /// </summary>
  405. /// <param name="data"></param>
  406. /// <returns></returns>
  407. private static int CalculateNumPackets(byte[] data)
  408. {
  409. const uint m_maxPacketSize = 600;
  410. int numPackets = 1;
  411. if (data.LongLength > m_maxPacketSize)
  412. {
  413. // over max number of bytes so split up file
  414. long restData = data.LongLength - m_maxPacketSize;
  415. int restPackets = (int)((restData + m_maxPacketSize - 1) / m_maxPacketSize);
  416. numPackets += restPackets;
  417. }
  418. return numPackets;
  419. }
  420. /// <summary>
  421. /// Handle an asset request from the client. The result will be sent back asynchronously.
  422. /// </summary>
  423. /// <param name="userInfo"></param>
  424. /// <param name="transferRequest"></param>
  425. public void AddAssetRequest(IClientAPI userInfo, TransferRequestPacket transferRequest)
  426. {
  427. UUID requestID = UUID.Zero;
  428. byte source = 2;
  429. if (transferRequest.TransferInfo.SourceType == 2)
  430. {
  431. //direct asset request
  432. requestID = new UUID(transferRequest.TransferInfo.Params, 0);
  433. }
  434. else if (transferRequest.TransferInfo.SourceType == 3)
  435. {
  436. //inventory asset request
  437. requestID = new UUID(transferRequest.TransferInfo.Params, 80);
  438. source = 3;
  439. //m_log.Debug("asset request " + requestID);
  440. }
  441. //check to see if asset is in local cache, if not we need to request it from asset server.
  442. //m_log.Debug("asset request " + requestID);
  443. if (!m_memcache.Contains(requestID))
  444. {
  445. //not found asset
  446. // so request from asset server
  447. if (!RequestedAssets.ContainsKey(requestID))
  448. {
  449. AssetRequest request = new AssetRequest();
  450. request.RequestUser = userInfo;
  451. request.RequestAssetID = requestID;
  452. request.TransferRequestID = transferRequest.TransferInfo.TransferID;
  453. request.AssetRequestSource = source;
  454. request.Params = transferRequest.TransferInfo.Params;
  455. RequestedAssets.Add(requestID, request);
  456. m_assetServer.RequestAsset(requestID, false);
  457. }
  458. return;
  459. }
  460. // It has an entry in our cache
  461. AssetBase asset = (AssetBase)m_memcache[requestID];
  462. // FIXME: We never tell the client about assets which do not exist when requested by this transfer mechanism, which can't be right.
  463. if (null == asset)
  464. {
  465. //m_log.DebugFormat("[ASSET CACHE]: Asset transfer request for asset which is {0} already known to be missing. Dropping", requestID);
  466. return;
  467. }
  468. // Scripts cannot be retrieved by direct request
  469. if (transferRequest.TransferInfo.SourceType == 2 && asset.Type == 10)
  470. return;
  471. // The asset is knosn to exist and is in our cache, so add it to the AssetRequests list
  472. AssetRequest req = new AssetRequest();
  473. req.RequestUser = userInfo;
  474. req.RequestAssetID = requestID;
  475. req.TransferRequestID = transferRequest.TransferInfo.TransferID;
  476. req.AssetRequestSource = source;
  477. req.Params = transferRequest.TransferInfo.Params;
  478. req.AssetInf = new AssetInfo(asset);
  479. req.NumPackets = CalculateNumPackets(asset.Data);
  480. AssetRequests.Add(req);
  481. }
  482. /// <summary>
  483. /// Process the asset queue which sends packets directly back to the client.
  484. /// </summary>
  485. private void ProcessAssetQueue()
  486. {
  487. //should move the asset downloading to a module, like has been done with texture downloading
  488. if (AssetRequests.Count == 0)
  489. {
  490. //no requests waiting
  491. return;
  492. }
  493. // if less than 5, do all of them
  494. int num = Math.Min(5, AssetRequests.Count);
  495. AssetRequest req;
  496. AssetRequestToClient req2 = null;
  497. for (int i = 0; i < num; i++)
  498. {
  499. req = AssetRequests[i];
  500. if (req2 == null)
  501. {
  502. req2 = new AssetRequestToClient();
  503. }
  504. // Trying to limit memory usage by only creating AssetRequestToClient if needed
  505. //req2 = new AssetRequestToClient();
  506. req2.AssetInf = req.AssetInf;
  507. req2.AssetRequestSource = req.AssetRequestSource;
  508. req2.DataPointer = req.DataPointer;
  509. req2.DiscardLevel = req.DiscardLevel;
  510. req2.ImageInfo = req.ImageInfo;
  511. req2.IsTextureRequest = req.IsTextureRequest;
  512. req2.NumPackets = req.NumPackets;
  513. req2.PacketCounter = req.PacketCounter;
  514. req2.Params = req.Params;
  515. req2.RequestAssetID = req.RequestAssetID;
  516. req2.TransferRequestID = req.TransferRequestID;
  517. req.RequestUser.SendAsset(req2);
  518. }
  519. //remove requests that have been completed
  520. for (int i = 0; i < num; i++)
  521. {
  522. AssetRequests.RemoveAt(0);
  523. }
  524. }
  525. public class AssetRequest
  526. {
  527. public IClientAPI RequestUser;
  528. public UUID RequestAssetID;
  529. public AssetInfo AssetInf;
  530. public TextureImage ImageInfo;
  531. public UUID TransferRequestID;
  532. public long DataPointer = 0;
  533. public int NumPackets = 0;
  534. public int PacketCounter = 0;
  535. public bool IsTextureRequest;
  536. public byte AssetRequestSource = 2;
  537. public byte[] Params = null;
  538. //public bool AssetInCache;
  539. //public int TimeRequested;
  540. public int DiscardLevel = -1;
  541. }
  542. public class AssetInfo : AssetBase
  543. {
  544. public AssetInfo(AssetBase aBase)
  545. {
  546. Data = aBase.Data;
  547. FullID = aBase.FullID;
  548. Type = aBase.Type;
  549. Name = aBase.Name;
  550. Description = aBase.Description;
  551. }
  552. }
  553. public class TextureImage : AssetBase
  554. {
  555. public TextureImage(AssetBase aBase)
  556. {
  557. Data = aBase.Data;
  558. FullID = aBase.FullID;
  559. Type = aBase.Type;
  560. Name = aBase.Name;
  561. Description = aBase.Description;
  562. }
  563. }
  564. /// <summary>
  565. /// A list of requests for a particular asset.
  566. /// </summary>
  567. public class AssetRequestsList
  568. {
  569. /// <summary>
  570. /// A list of requests for assets
  571. /// </summary>
  572. public List<NewAssetRequest> Requests = new List<NewAssetRequest>();
  573. /// <summary>
  574. /// Record the time that this request was first made.
  575. /// </summary>
  576. public DateTime TimeRequested;
  577. }
  578. /// <summary>
  579. /// Represent a request for an asset that has yet to be fulfilled.
  580. /// </summary>
  581. public class NewAssetRequest
  582. {
  583. public AssetRequestCallback Callback;
  584. public NewAssetRequest(AssetRequestCallback callback)
  585. {
  586. Callback = callback;
  587. }
  588. }
  589. }
  590. }