public void LoadsbMegaTexture(string filename) { FileSystem.IReadOnlyPackage pack; string temp; if (Game.ModData.DefaultFileSystem.TryGetPackageContaining(filename, out pack, out temp)) { using (var stream = Game.ModData.DefaultFileSystem.Open("noise.png")) { Png pic; try { pic = new Png(stream); MegaTextureSprite = sbMegaTexture.Add(pic); } catch (Exception e) { //Console.WriteLine("Error loading char: {0} x {1}", f, Convert.ToInt32(f.Split('.')[0])); } } } }
public Theater(TileSet tileset) { this.tileset = tileset; var allocated = false; //Func<Sheet2D> allocate = () => //{ // if (allocated) // throw new SheetOverflowException("Terrain sheet overflow. Try increasing the tileset SheetSize parameter."); // allocated = true; // SheetBuilder2D shb= Game.worldRenderer.World.Map.Rules.Sequences.SpriteCache.SheetBuilder2D; // return new Sheet2D(SheetType.Indexed, shb., shb.TextureArrayIndex); //}; //SheetBuilder2D shb = Game.OrderManager.World.Map.Rules.Sequences.SpriteCache.SheetBuilder2D; //sheetBuilder2d = Game.OrderManager.World.Map.Rules.Sequences.SpriteCache.SheetBuilder2D; sheetBuilder2d = Game.SheetBuilder2D; if (!string.IsNullOrEmpty(tileset.MegaTexture)) { sbMegaTexture = sheetBuilder2d; LoadsbMegaTexture(tileset.MegaTexture); } random = new MersenneTwister(); var frameCache = new FrameCache(Game.ModData.DefaultFileSystem, Game.ModData.SpriteLoaders); //дл¤ каждого templates есть сво¤ коллекци¤ Sprites , это заполн¤етс¤ в цикле по tileset.Templates ниже foreach (var t in tileset.Templates) { var variants = new List <Sprite[]>(); foreach (var i in t.Value.Images) { var allFrames = frameCache[i]; var frameCount = tileset.EnableDepth ? allFrames.Length / 2 : allFrames.Length; var indices = t.Value.Frames != null ? t.Value.Frames : Enumerable.Range(0, frameCount); variants.Add(indices.Select(j => { var f = allFrames[j]; var tile = t.Value.Contains(j) ? t.Value[j] : null; // The internal z axis is inverted from expectation (negative is closer) var zOffset = tile != null ? -tile.ZOffset : 0; var zRamp = tile != null ? tile.ZRamp : 1f; var offset = new float3(f.Offset, zOffset); var s = sheetBuilder2d.Allocate(f.Size, zRamp, offset); Util.FastCopyIntoChannel(s, f.Data); if (tileset.EnableDepth) { var ss = sheetBuilder2d.Allocate(f.Size, zRamp, offset); Util.FastCopyIntoChannel(ss, allFrames[j + frameCount].Data); // s and ss are guaranteed to use the same sheet // because of the custom terrain sheet allocation s = new SpriteWithSecondaryData(s, s.Sheet, ss.Bounds, ss.Channel); } return(s); }).ToArray()); } var allSprites = variants.SelectMany(s => s); // Ignore the offsets baked into R8 sprites if (tileset.IgnoreTileSpriteOffsets) { allSprites = allSprites.Select(s => new Sprite(s.Sheet2D, s.Bounds, s.ZRamp, new float3(float2.Zero, s.Offset.Z), s.Channel, s.BlendMode)); } if (t.Value.Variants == "Calc") { templates.Add(t.Value.Id, new TheaterTemplate(allSprites.ToArray(), 1, variants.First().Count())); } else { templates.Add(t.Value.Id, new TheaterTemplate(allSprites.ToArray(), variants.First().Count(), t.Value.Images.Length)); } } // 1x1px transparent tile missingTile = sheetBuilder2d.Add(new byte[1], new Size(1, 1)); //Sheet2D.ReleaseBuffer(); }
/// <summary> /// Returns the first set of sprites with the given filename. /// If getUsedFrames is defined then the indices returned by the function call /// are guaranteed to be loaded. The value of other indices in the returned /// array are undefined and should never be accessed. /// </summary> public Sprite[] this[string filename, Func <int, IEnumerable <int> > getThisIndexesSpritesFromFile = null] { get { var allSprites = sprites.GetOrAdd(filename); var sprite = allSprites.FirstOrDefault(); ISpriteFrame[] newFramesFromFile; if (!ParsedFramesStorage.TryGetValue(filename, out newFramesFromFile)) { newFramesFromFile = null; } // This is the first time that the file has been requested // Load all of the frames into the unused buffer and initialize // the loaded cache (initially empty) if (sprite == null) { TypeDictionary fileMetadata = null; using (var stream = fileSystem.Open(filename)) { newFramesFromFile = FrameLoader.GetFrames(stream, filename, loaders, out fileMetadata); //загрузит все спрайты из shp,wsa,... файлов в память } ParsedFramesStorage[filename] = newFramesFromFile; metadata[filename] = fileMetadata; sprite = new Sprite[newFramesFromFile.Length]; allSprites.Add(sprite); } // HACK: The sequency code relies on side-effects from getUsedFrames var indices = getThisIndexesSpritesFromFile != null?getThisIndexesSpritesFromFile(sprite.Length) : Enumerable.Range(0, sprite.Length); // Load any unused frames into the SheetBuilder if (newFramesFromFile != null) { foreach (var i in indices) { if (newFramesFromFile[i] != null) { //sprite[i] = SheetBuilder.Add(framesCandidates[i]); if (filename.Contains("png1")) //for Loaders with 4bytes per pixel { using (var stream = fileSystem.Open(filename)) { sprite[i] = SheetBuilder2D.Add(new Png(stream)); } } else { sprite[i] = SheetBuilder2D.Add(newFramesFromFile[i]); } newFramesFromFile[i] = null; } } // All frames have been loaded if (newFramesFromFile.All(f => f == null)) { ParsedFramesStorage.Remove(filename); } } return(sprite); } }