Beispiel #1
0
        private void LoadTexture(string path, Stream stream, bool rawimg)
        {
            try {
                var texTask = rawimg
                                        ? ImageIO.RawToTexture2DAsync(Main.instance.GraphicsDevice, new BinaryReader(stream))
                                        : ImageIO.PngToTexture2DAsync(Main.instance.GraphicsDevice, stream);

                AsyncLoadQueue.Enqueue(texTask.ContinueWith(t => {
                    if (t.Exception != null)
                    {
                        throw new ResourceLoadException(
                            Language.GetTextValue("tModLoader.LoadErrorTextureFailedToLoad", path), t.Exception);
                    }

                    var tex  = t.Result;
                    tex.Name = Name + "/" + path;
                    lock (textures)
                        textures[path] = tex;
                }));
            }
            catch (Exception e) {
                throw new ResourceLoadException(Language.GetTextValue("tModLoader.LoadErrorTextureFailedToLoad", path), e);
            }
            finally {
                stream.Close();
            }
        }
Beispiel #2
0
        private void LoadTexture(string path, int len, BinaryReader reader, bool rawimg)
        {
            try
            {
                var texTask = rawimg
                                        ? ImageIO.RawToTexture2DAsync(Main.instance.GraphicsDevice, reader)
                                        : ImageIO.PngToTexture2DAsync(Main.instance.GraphicsDevice, new MemoryStream(reader.ReadBytes(len)));//needs a seekable stream

                AsyncLoadQueue.Enqueue(texTask.ContinueWith(t =>
                {
                    var tex  = t.Result;
                    tex.Name = Name + "/" + path;
                    lock (textures)
                        textures[path] = tex;
                }));
            }
            catch (Exception e)
            {
                throw new ResourceLoadException(Language.GetTextValue("tModLoader.LoadErrorTextureFailedToLoad", path), e);
            }
        }