// Decompiled with JetBrains decompiler // Type: Terraria.Graphics.TextureManager // Assembly: Terraria, Version=1.3.5.3, Culture=neutral, PublicKeyToken=null // MVID: 68659D26-2BE6-448F-8663-74FA559E6F08 // Assembly location: C:\Users\mikeyisbaeyt\Downloads\depotdownloader-2.4.5\depots\105601\6707058\Terraria.exe using Microsoft.Xna.Framework.Graphics; using System; using System.Collections.Concurrent; using System.Threading; namespace Terraria.Graphics { public static class TextureManager { private static ConcurrentDictionary _textures = new ConcurrentDictionary(); private static ConcurrentQueue _loadQueue = new ConcurrentQueue(); private static Thread _loadThread; private static readonly object _loadThreadLock = new object(); public static Texture2D BlankTexture; public static void Initialize() => TextureManager.BlankTexture = new Texture2D(Main.graphics.GraphicsDevice, 4, 4); public static Texture2D Load(string name) { if (TextureManager._textures.ContainsKey(name)) return TextureManager._textures[name]; Texture2D texture2D = TextureManager.BlankTexture; if (name != "") { if (name != null) { try { texture2D = Main.instance.OurLoad(name); } catch (Exception ex) { texture2D = TextureManager.BlankTexture; } } } TextureManager._textures[name] = texture2D; return texture2D; } public static Ref AsyncLoad(string name) => new Ref(TextureManager.Load(name)); private static void Run(object context) { bool looping = true; Main.instance.Exiting += (EventHandler) ((obj, args) => { looping = false; if (!Monitor.TryEnter(TextureManager._loadThreadLock)) return; Monitor.Pulse(TextureManager._loadThreadLock); Monitor.Exit(TextureManager._loadThreadLock); }); Monitor.Enter(TextureManager._loadThreadLock); while (looping) { if (TextureManager._loadQueue.Count != 0) { TextureManager.LoadPair result; if (TextureManager._loadQueue.TryDequeue(out result)) result.TextureRef.Value = TextureManager.Load(result.Path); } else Monitor.Wait(TextureManager._loadThreadLock); } Monitor.Exit(TextureManager._loadThreadLock); } private struct LoadPair { public string Path; public Ref TextureRef; public LoadPair(string path, Ref textureRef) { this.Path = path; this.TextureRef = textureRef; } } } }