/// <summary> /// Gets the texture object for a specific texture name. /// </summary> /// <param name="texturename">The name of the texture.</param> /// <param name="twidth">The texture width, if any.</param> /// <returns>A valid texture object.</returns> public Texture GetTexture(string texturename, int twidth = 0) { texturename = FileHandler.CleanFileName(texturename); for (int i = 0; i < LoadedTextures.Count; i++) { if (LoadedTextures[i].Name == texturename && (twidth == 0 || LoadedTextures[i].Width == twidth)) { return(LoadedTextures[i]); } } Texture Loaded = LoadTexture(texturename, twidth); if (Loaded == null && twidth == 0) { Loaded = new Texture() { Engine = this, Name = texturename, Internal_Texture = White.Original_InternalID, Original_InternalID = White.Original_InternalID, LoadedProperly = false, Width = White.Width, Height = White.Height, }; } if (Loaded == null) { Loaded = LoadTexture("white", twidth); Loaded.Name = texturename; Loaded.LoadedProperly = false; } LoadedTextures.Add(Loaded); OnTextureLoaded?.Invoke(this, new TextureLoadedEventArgs(Loaded)); return(Loaded); }
/// <summary> /// Gets the texture object for a specific texture name. /// </summary> /// <param name="texturename">The name of the texture.</param> /// <returns>A valid texture object.</returns> public Texture GetTexture(string texturename) { texturename = FileEngine.CleanFileName(texturename); if (LoadedTextures.TryGetValue(texturename, out Texture foundTexture)) { return(foundTexture); } Texture Loaded = LoadTexture(texturename, 0); if (Loaded == null) { Loaded = new Texture() { Engine = this, Name = texturename, Internal_Texture = White.Original_InternalID, Original_InternalID = White.Original_InternalID, LoadedProperly = false, Width = White.Width, Height = White.Height, }; } LoadedTextures.Add(texturename, Loaded); OnTextureLoaded?.Invoke(this, new TextureLoadedEventArgs(Loaded)); return(Loaded); }
public void LoadTextures() { foreach (string file in Directory.EnumerateFiles("assets/textures", "*.*", SearchOption.AllDirectories)) { var texture = new Texture(file); Textures.Add(file.Substring("assets/textures".Length + 1).Replace("\\", "/"), texture); OnTextureLoaded?.Invoke(file, texture); } }
/// <summary> /// Gets the texture object for a specific texture name. /// </summary> /// <param name="textureName">The name of the texture.</param> /// <returns>A valid texture object.</returns> public Texture GetTexture(string textureName) { textureName = FileEngine.CleanFileName(textureName); if (LoadedTextures.TryGetValue(textureName, out Texture foundTexture)) { return(foundTexture); } Texture loaded = DynamicLoadTexture(textureName); LoadedTextures.Add(textureName, loaded); OnTextureLoaded?.Invoke(this, new TextureLoadedEventArgs(loaded)); return(loaded); }
void thread_LoadTexture(SceneNode node, string path, Dimension2Di size) { Texture t; Dimension2Di si; Image i = irrDevice.DriverNoCheck.CreateImage(path); if (i != null) { Image j = irrDevice.DriverNoCheck.CreateImage(ColorFormat.A8R8G8B8, size); i.CopyToScaling(j); irrDevice.Lock(); t = irrDevice.Driver.AddTexture(path + "|" + size.ToString(), j); irrDevice.Unlock(); si = i.Dimension; i.Drop(); j.Drop(); lock (loadedTextures) { loadedTextures.Add(t.Name.Path); } } else { t = noPreviewTexture; si = noPreviewTexture.Size; } irrDevice.Lock(); node.SetMaterialTexture(0, t); irrDevice.Unlock(); OnTextureLoaded?.Invoke(node, t, si); node.Drop(); }
public async void LoadParallax() { if (!_configurationManager.GetCVar <bool>("parallax.enabled")) { return; } Stream configStream = null; string contents; TomlTable table; try { // Load normal config into memory if (!_resourceCache.TryContentFileRead(ParallaxConfigPath, out configStream)) { Logger.ErrorS("parallax", "Parallax config not found."); return; } using (var reader = new StreamReader(configStream, EncodingHelpers.UTF8)) { contents = reader.ReadToEnd(); } if (_resourceCache.UserData.Exists(ParallaxConfigOld)) { bool match; using (var data = _resourceCache.UserData.Open(ParallaxConfigOld, FileMode.Open)) using (var reader = new StreamReader(data, EncodingHelpers.UTF8)) { match = reader.ReadToEnd() == contents; } if (match) { using (var stream = _resourceCache.UserData.Open(ParallaxPath, FileMode.Open)) { ParallaxTexture = Texture.LoadFromPNGStream(stream, "Parallax"); } OnTextureLoaded?.Invoke(ParallaxTexture); return; } } table = Toml.ReadString(contents); } finally { configStream?.Dispose(); } var sawmill = _logManager.GetSawmill("parallax"); // Generate the parallax in the thread pool. var image = await Task.Run(() => ParallaxGenerator.GenerateParallax(table, new Size(1920, 1080), sawmill)); // And load it in the main thread for safety reasons. ParallaxTexture = Texture.LoadFromImage(image, "Parallax"); // Store it and CRC so further game starts don't need to regenerate it. using (var stream = _resourceCache.UserData.Open(ParallaxPath, FileMode.Create)) { image.SaveAsPng(stream); } using (var stream = _resourceCache.UserData.Open(ParallaxConfigOld, FileMode.Create)) using (var writer = new StreamWriter(stream, EncodingHelpers.UTF8)) { writer.Write(contents); } OnTextureLoaded?.Invoke(ParallaxTexture); }
public async void LoadParallax() { if (!_configurationManager.GetCVar <bool>("parallax.enabled")) { return; } var debugParallax = _configurationManager.GetCVar <bool>("parallax.debug"); string contents; TomlTable table; // Load normal config into memory if (!_resourceCache.TryContentFileRead(ParallaxConfigPath, out var configStream)) { Logger.ErrorS("parallax", "Parallax config not found."); return; } using (configStream) { using (var reader = new StreamReader(configStream, EncodingHelpers.UTF8)) { contents = reader.ReadToEnd(); } if (!debugParallax && _resourceCache.UserData.Exists(ParallaxConfigOld)) { var match = _resourceCache.UserData.ReadAllText(ParallaxConfigOld) == contents; if (match) { using (var stream = _resourceCache.UserData.OpenRead(ParallaxPath)) { ParallaxTexture = Texture.LoadFromPNGStream(stream, "Parallax"); } OnTextureLoaded?.Invoke(ParallaxTexture); return; } } table = Toml.ReadString(contents); } List <Image <Rgba32> > debugImages = null; if (debugParallax) { debugImages = new List <Image <Rgba32> >(); } var sawmill = _logManager.GetSawmill("parallax"); // Generate the parallax in the thread pool. var image = await Task.Run(() => ParallaxGenerator.GenerateParallax(table, new Size(1920, 1080), sawmill, debugImages)); // And load it in the main thread for safety reasons. ParallaxTexture = Texture.LoadFromImage(image, "Parallax"); // Store it and CRC so further game starts don't need to regenerate it. using (var stream = _resourceCache.UserData.Create(ParallaxPath)) { image.SaveAsPng(stream); } if (debugParallax) { var i = 0; foreach (var debugImage in debugImages) { using (var stream = _resourceCache.UserData.Create(new ResourcePath($"/parallax_debug_{i}.png"))) { debugImage.SaveAsPng(stream); } i += 1; } } image.Dispose(); using (var stream = _resourceCache.UserData.Create(ParallaxConfigOld)) using (var writer = new StreamWriter(stream, EncodingHelpers.UTF8)) { writer.Write(contents); } OnTextureLoaded?.Invoke(ParallaxTexture); }