Exemple #1
0
        /// <summary>
        ///
        /// </summary>
        void LoadingFunction()
        {
            while (!TaskStopRequest)
            {
                Item item;

                if (!downloadQueue.TryDequeue(out item))
                {
                    continue;
                }

                try {
                    string filePath = item.Path;

                    // Download image if url was given
                    if (item.Path.StartsWith("http", true, CultureInfo.InvariantCulture))
                    {
                        var wds = Game.GetService <WebDownloaderService>();

                        filePath = cachePath + ContentUtils.CalculateMD5Hash(item.Path);

                        if (!File.Exists(filePath))
                        {
                            wds.DownloadImage(item.Path, filePath, Config.NetworkTimeout);
                        }
                    }

                    // Load texture
                    using (var stream = File.OpenRead(filePath)) {
                        item.Texture     = new Texture2D(Game.GraphicsDevice, stream, false);
                        item.SizeInBytes = (int)(item.Texture.Width * item.Texture.Height * 4 * 1.3f);
                    }

                    Interlocked.Add(ref sizeInBytes, (long)item.SizeInBytes);

                    item.Status = TexturePumpStatus.Ready;
                } catch (Exception e) {
                    Log.Warning(e.Message);
                    item.Status = TexturePumpStatus.Failed;
                }
            }
        }