/// <summary>
        /// Loads all BGF from subfolder "bgf" in document root
        /// </summary>
        public static void Load()
        {
            cache.Clear();

            string filePath = HttpRuntime.AppDomainAppPath + "bgf/";

            string[] files = Directory.GetFiles(filePath, "*.bgf");

            uint num = 1;

            foreach (string s in files)
            {
                try
                {
                    // get file info
                    FileInfo info = new FileInfo(s);

                    // read from disk and decompress all (important!)
                    BgfFile bgf = new BgfFile(s);
                    bgf.DecompressAll();

                    Entry entry = new Entry();
                    entry.Bgf = bgf;

                    // get filesystem lastwrite date
                    DateTime fileDate = info.LastWriteTimeUtc;

                    // store truncated to seconds
                    entry.LastModified = fileDate.AddTicks(-(fileDate.Ticks % TimeSpan.TicksPerSecond));
                    entry.Size         = info.Length;

                    // set pseudo id (for appearance hashing)
                    entry.Num = num;
                    num++;

                    // add to cache
                    cache.TryAdd(bgf.Filename, entry);
                }
                catch (Exception) { }
            }

            // save when the cache was filled
            DateTime now = DateTime.UtcNow;

            LastModified      = now.AddTicks(-(now.Ticks % TimeSpan.TicksPerSecond));
            LastModifiedStamp = (now.Ticks - 621355968000000000) / 10000000;

            // save array variant for iteration
            //pairs = BgfCache.cache.ToArray();

            // compact large object heap next run
            GCSettings.LargeObjectHeapCompactionMode =
                GCLargeObjectHeapCompactionMode.CompactOnce;

            // execute maximum GC run
            GC.Collect(GC.MaxGeneration, GCCollectionMode.Forced);
        }
        /// <summary>
        /// Stars loading all roomtextures in a background thread.
        /// </summary>
        protected void LoadThreadRoomTextures()
        {
            IEnumerator <KeyValuePair <string, BgfFile> > it = RoomTextures.GetEnumerator();
            BgfFile file;

            while (it.MoveNext())
            {
                // load
                file = new BgfFile(Path.Combine(RoomTexturesFolder, it.Current.Key));
                file.DecompressAll();

                // update
                RoomTextures.TryUpdate(it.Current.Key, file, null);

                queueAsyncFilesLoaded.Enqueue(it.Current.Key);
            }
        }
Beispiel #3
0
        /// <summary>
        /// Preloads all elements in the RoomTextures dictionary.
        /// </summary>
        public void PreloadRoomTextures()
        {
            IEnumerator <KeyValuePair <string, BgfFile> > it = RoomTextures.GetEnumerator();
            BgfFile file;

            while (it.MoveNext())
            {
                // load
                file = new BgfFile(Path.Combine(Config.RoomTexturesFolder, it.Current.Key));
                file.DecompressAll();

                // update
                RoomTextures.TryUpdate(it.Current.Key, file, null);
            }

            GC.Collect(2);
        }