/// <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);
            }
        }
Example #2
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);
        }
        /// <summary>
        /// Tries to retrieve a BGF file from the RoomTextures dictionary.
        /// Will load the file from disk, if not yet loaded.
        /// </summary>
        /// <param name="File"></param>
        /// <returns></returns>
        public BgfFile GetRoomTexture(string File)
        {
            BgfFile bgfFile = null;

            // if the file is known
            if (RoomTextures.TryGetValue(File, out bgfFile))
            {
                // haven't loaded it yet?
                if (bgfFile == null)
                {
                    byte[] buffer;

                    // get file byte buffer
                    if (!fileBuffers.TryPop(out buffer))
                    {
                        buffer = new byte[FILEBUFFERSIZE];
                    }

                    string file = RoomTexturesFolder + "/" + File;

                    // load to mem
                    if (Util.LoadFileToBuffer(file, buffer))
                    {
                        // load it
                        bgfFile = new BgfFile(file, buffer);

                        // update the registry
                        if (RoomTextures.TryUpdate(File, bgfFile, null))
                        {
                            numLoadedRoomTextures++;
                        }
                    }
                    else
                    {
                        Logger.Log(MODULENAME, LogType.Error, "Failed to load file (possibly too big?): " + File);
                    }

                    fileBuffers.Push(buffer);
                }
            }

            return(bgfFile);
        }
        /// <summary>
        /// Tries to retrieve a BGF file from the RoomTextures dictionary.
        /// Will load the file from disk, if not yet loaded.
        /// </summary>
        /// <param name="File"></param>
        /// <returns></returns>
        public BgfFile GetRoomTexture(string File)
        {
            BgfFile bgfFile = null;

            // if the file is known
            if (RoomTextures.TryGetValue(File, out bgfFile))
            {
                // haven't loaded it yet?
                if (bgfFile == null)
                {
                    // load it
                    bgfFile = new BgfFile(RoomTexturesFolder + "/" + File);

                    // update the registry
                    RoomTextures.TryUpdate(File, bgfFile, null);
                }
            }

            return(bgfFile);
        }