Example #1
0
 private void ClearItemsBetween(long startTimestamp, long endTimestamp)
 {
     if (endTimestamp >= startTimestamp)
     {
         HashSet <string> set = new HashSet <string>();
         foreach (KeyValuePair <string, CachedAsset> pair in this.m_assetMap)
         {
             CachedAsset asset = pair.Value;
             if (!asset.IsPersistent())
             {
                 long lastRequestTimestamp = asset.GetLastRequestTimestamp();
                 if ((startTimestamp <= lastRequestTimestamp) && (lastRequestTimestamp <= endTimestamp))
                 {
                     set.Add(pair.Key);
                 }
             }
         }
         foreach (KeyValuePair <string, CacheRequest> pair2 in this.m_assetRequestMap)
         {
             CacheRequest request = pair2.Value;
             if (!request.IsPersistent())
             {
                 long num2 = request.GetLastRequestTimestamp();
                 if ((startTimestamp <= num2) && (num2 <= endTimestamp))
                 {
                     set.Add(pair2.Key);
                 }
             }
         }
         foreach (string str in set)
         {
             this.ClearItem(str);
         }
     }
 }
Example #2
0
 private void AddItem(string name, CachedAsset item)
 {
     if (this.m_assetMap.ContainsKey(name))
     {
         Debug.LogWarning(string.Format("AssetCache: Loaded asset {0} twice.  This probably happened because it was loaded asynchronously and synchronously.", name));
     }
     else
     {
         this.m_assetMap.Add(name, item);
     }
 }
Example #3
0
    public Object GetAsset(string assetName)
    {
#if ENABLE_RESOURCE_CACHE_LOG
        Debug.Log("[ResourceCache] Load asset from cache : " + assetName);
#endif
        CachedAsset cachedAsset = null;
        if (cachedAssets.TryGetValue(assetName, out cachedAsset) == false)
        {
            return(null);
        }

        return(cachedAsset.obj);
    }
Example #4
0
    public void AddAsset(string assetName, Object obj)
    {
#if ENABLE_RESOURCE_CACHE_LOG
        Debug.Log("[ResourceCache] Add asset to cache : " + assetName);
#endif
        Debug.Assert(Contains(assetName) == false);

        CachedAsset cachedAsset = new CachedAsset();
        cachedAsset.assetName = assetName;
        cachedAsset.obj       = obj;
        cachedAsset.refCount  = 0;

        cachedAssets.Add(assetName, cachedAsset);
    }
Example #5
0
            /// <summary>
            /// Compresses each asset in the list for later use
            /// </summary>
            public void prepareCache(List <AssetInfo> assets)
            {                   //For each asset..
                foreach (AssetInfo asset in assets)
                {               //Insert some details
                    CachedAsset cache = new CachedAsset();

                    cache.filepath = asset.filepath;
                    cache.bCached  = false;
                    cache.checksum = asset.checksum;

                    //Duplicate?
                    if (_cache.ContainsKey(Path.GetFileName(cache.filepath)))
                    {
                        continue;
                    }

                    //Add it
                    _cache.Add(Path.GetFileName(asset.filepath), cache);
                }
            }
Example #6
0
            /// <summary>
            /// Compresses each asset in the list for later use
            /// </summary>
            private CachedAsset cacheFile(CachedAsset asset)
            {                   //Does it exist?
                if (!File.Exists(asset.filepath))
                {
                    Log.write(TLog.Error, "Unable to cache asset '{0}', file was not found.", asset.filepath);
                    return(null);
                }

                //Quickly compare the checksum
                if (asset.checksum != Assets.CRC32.fileChecksum(asset.filepath))
                {
                    //Global files? if so don't bother with the checksum
                    if (!asset.filepath.Contains("Global"))
                    {
                        Log.write(TLog.Error, "Checksum mismatch on asset '{0}' while attempting to cache.", asset.filepath);
                        return(null);
                    }
                }

                //Load the file into memory
                FileStream fs = new FileStream(asset.filepath, FileMode.Open);

                //Compress it with zlib
                MemoryStream buf  = new MemoryStream();
                ZlibStream   zlib = new ZlibStream(buf, CompressionMode.Compress);

                copyStream(fs, zlib);
                zlib.Close();

                //Store our cached asset data
                asset.data             = buf.ToArray();
                asset.uncompressedSize = (int)fs.Length;
                asset.bCached          = true;

                fs.Close();
                buf.Close();

                return(asset);
            }
Example #7
0
 public static void Add(Asset asset, CachedAsset item)
 {
     s_cacheTable[asset.GetFamily()].AddItem(asset.GetName(), item);
 }
Example #8
0
 public void AddItem(string name, CachedAsset item)
 {
     object[] objArray1 = new object[] { name, item };
     base.method_8("AddItem", objArray1);
 }
Example #9
0
 public static void Add(Asset asset, CachedAsset item)
 {
     object[] objArray1 = new object[] { asset, item };
     MonoClass.smethod_18(TritonHs.MainAssemblyPath, "", "AssetCache", "Add", objArray1);
 }