Ejemplo n.º 1
0
        public ShroudRenderer(World world, ShroudRendererInfo info)
        {
            this.info = info;
            map       = world.Map;

            tiles = new CellLayer <ShroudTile>(map);

            // Force update on first render
            shroudHash = -1;

            // Load sprite variants
            if (info.ShroudVariants.Length != info.FogVariants.Length)
            {
                throw new InvalidOperationException("ShroudRenderer must define the same number of shroud and fog variants!");
            }

            if ((info.OverrideFullFog == null) ^ (info.OverrideFullShroud == null))
            {
                throw new InvalidOperationException("ShroudRenderer cannot define overrides for only one of shroud or fog!");
            }

            var variantCount = info.ShroudVariants.Length;

            variantStride = info.Index.Length + (info.OverrideFullShroud != null ? 1 : 0);
            shroudSprites = new Sprite[variantCount * variantStride];
            fogSprites    = new Sprite[variantCount * variantStride];

            for (var j = 0; j < variantCount; j++)
            {
                var shroud = map.SequenceProvider.GetSequence(info.Sequence, info.ShroudVariants[j]);
                var fog    = map.SequenceProvider.GetSequence(info.Sequence, info.FogVariants[j]);
                for (var i = 0; i < info.Index.Length; i++)
                {
                    shroudSprites[j * variantStride + i] = shroud.GetSprite(i);
                    fogSprites[j * variantStride + i]    = fog.GetSprite(i);
                }

                if (info.OverrideFullShroud != null)
                {
                    var i = (j + 1) * variantStride - 1;
                    shroudSprites[i] = map.SequenceProvider.GetSequence(info.Sequence, info.OverrideFullShroud).GetSprite(0);
                    fogSprites[i]    = map.SequenceProvider.GetSequence(info.Sequence, info.OverrideFullFog).GetSprite(0);
                }
            }

            // Mapping of shrouded directions -> sprite index
            spriteMap = new int[info.UseExtendedIndex ? 256 : 16];
            for (var i = 0; i < info.Index.Length; i++)
            {
                spriteMap[info.Index[i]] = i;
            }

            if (info.OverrideFullShroud != null)
            {
                spriteMap[info.OverrideShroudIndex] = variantStride - 1;
            }
        }
Ejemplo n.º 2
0
        public ShroudRenderer(World world, ShroudRendererInfo info)
        {
            if (info.ShroudVariants.Length != info.FogVariants.Length)
                throw new ArgumentException("ShroudRenderer must define the same number of shroud and fog variants!", "info");

            if ((info.OverrideFullFog == null) ^ (info.OverrideFullShroud == null))
                throw new ArgumentException("ShroudRenderer cannot define overrides for only one of shroud or fog!", "info");

            if (info.ShroudVariants.Length > byte.MaxValue)
                throw new ArgumentException("ShroudRenderer cannot define this many shroud and fog variants.", "info");

            if (info.Index.Length >= byte.MaxValue)
                throw new ArgumentException("ShroudRenderer cannot define this many indexes for shroud directions.", "info");

            this.info = info;
            map = world.Map;

            tiles = new CellLayer<ShroudTile>(map);

            // Load sprite variants
            var variantCount = info.ShroudVariants.Length;
            variantStride = (byte)(info.Index.Length + (info.OverrideFullShroud != null ? 1 : 0));
            shroudSprites = new Sprite[variantCount * variantStride];
            fogSprites = new Sprite[variantCount * variantStride];

            for (var j = 0; j < variantCount; j++)
            {
                var shroud = map.SequenceProvider.GetSequence(info.Sequence, info.ShroudVariants[j]);
                var fog = map.SequenceProvider.GetSequence(info.Sequence, info.FogVariants[j]);
                for (var i = 0; i < info.Index.Length; i++)
                {
                    shroudSprites[j * variantStride + i] = shroud.GetSprite(i);
                    fogSprites[j * variantStride + i] = fog.GetSprite(i);
                }

                if (info.OverrideFullShroud != null)
                {
                    var i = (j + 1) * variantStride - 1;
                    shroudSprites[i] = map.SequenceProvider.GetSequence(info.Sequence, info.OverrideFullShroud).GetSprite(0);
                    fogSprites[i] = map.SequenceProvider.GetSequence(info.Sequence, info.OverrideFullFog).GetSprite(0);
                }
            }

            // Mapping of shrouded directions -> sprite index
            spriteMap = new byte[(byte)(info.UseExtendedIndex ? Edges.All : Edges.AllCorners) + 1];
            for (var i = 0; i < info.Index.Length; i++)
                spriteMap[info.Index[i]] = (byte)i;

            if (info.OverrideFullShroud != null)
                spriteMap[info.OverrideShroudIndex] = (byte)(variantStride - 1);

            notVisibleEdges = info.UseExtendedIndex ? Edges.AllSides : Edges.AllCorners;
        }
Ejemplo n.º 3
0
        public ShroudRenderer(World world, ShroudRendererInfo info)
        {
            var map = world.Map;

            bounds           = map.Bounds;
            useExtendedIndex = info.UseExtendedIndex;

            tiles      = new ShroudTile[map.MapSize.X * map.MapSize.Y];
            tileStride = map.MapSize.X;

            // Force update on first render
            shroudHash = -1;

            // Load sprite variants
            sprites       = new Sprite[info.Variants.Length * info.Index.Length];
            variantStride = info.Index.Length;
            for (var j = 0; j < info.Variants.Length; j++)
            {
                var seq = SequenceProvider.GetSequence(info.Sequence, info.Variants[j]);
                for (var i = 0; i < info.Index.Length; i++)
                {
                    sprites[j * variantStride + i] = seq.GetSprite(i);
                }
            }

            // Mapping of shrouded directions -> sprite index
            spriteMap = new int[useExtendedIndex ? 256 : 16];
            for (var i = 0; i < info.Index.Length; i++)
            {
                spriteMap[info.Index[i]] = i;
            }

            // Set individual tile variants to reduce tiling
            for (var i = 0; i < tiles.Length; i++)
            {
                tiles[i].Variant = Game.CosmeticRandom.Next(info.Variants.Length);
            }

            // Synthesize unexplored tile if it isn't defined
            if (!info.Index.Contains(0))
            {
                var size = new Size(Game.modData.Manifest.TileSize, Game.modData.Manifest.TileSize);
                var data = Exts.MakeArray <byte>(size.Width * size.Height, _ => (byte)info.ShroudColor);
                var s    = Game.modData.SheetBuilder.Add(data, size);
                unexploredTile = new Sprite(s.sheet, s.bounds, s.offset, s.channel, info.ShroudBlend);
            }
            else
            {
                unexploredTile = sprites[spriteMap[0]];
            }
        }
Ejemplo n.º 4
0
		public ShroudRenderer(World world, ShroudRendererInfo info)
		{
			this.info = info;
			map = world.Map;

			tiles = new CellLayer<ShroudTile>(map);

			// Force update on first render
			shroudHash = -1;

			// Load sprite variants
			if (info.ShroudVariants.Length != info.FogVariants.Length)
				throw new InvalidOperationException("ShroudRenderer must define the same number of shroud and fog variants!");

			if ((info.OverrideFullFog == null) ^ (info.OverrideFullShroud == null))
				throw new InvalidOperationException("ShroudRenderer cannot define overrides for only one of shroud or fog!");

			var variantCount = info.ShroudVariants.Length;
			variantStride = info.Index.Length + (info.OverrideFullShroud != null ? 1 : 0);
			shroudSprites = new Sprite[variantCount * variantStride];
			fogSprites = new Sprite[variantCount * variantStride];

			for (var j = 0; j < variantCount; j++)
			{
				var shroud = map.SequenceProvider.GetSequence(info.Sequence, info.ShroudVariants[j]);
				var fog = map.SequenceProvider.GetSequence(info.Sequence, info.FogVariants[j]);
				for (var i = 0; i < info.Index.Length; i++)
				{
					shroudSprites[j * variantStride + i] = shroud.GetSprite(i);
					fogSprites[j * variantStride + i] = fog.GetSprite(i);
				}

				if (info.OverrideFullShroud != null)
				{
					var i = (j + 1) * variantStride - 1;
					shroudSprites[i] = map.SequenceProvider.GetSequence(info.Sequence, info.OverrideFullShroud).GetSprite(0);
					fogSprites[i] = map.SequenceProvider.GetSequence(info.Sequence, info.OverrideFullFog).GetSprite(0);
				}
			}

			// Mapping of shrouded directions -> sprite index
			spriteMap = new int[info.UseExtendedIndex ? 256 : 16];
			for (var i = 0; i < info.Index.Length; i++)
				spriteMap[info.Index[i]] = i;

			if (info.OverrideFullShroud != null)
				spriteMap[info.OverrideShroudIndex] = variantStride - 1;
		}
Ejemplo n.º 5
0
        public ShroudRenderer(World world, ShroudRendererInfo info)
        {
            var map = world.Map;
            bounds = map.Bounds;
            useExtendedIndex = info.UseExtendedIndex;

            tiles = new ShroudTile[map.MapSize.X * map.MapSize.Y];
            tileStride = map.MapSize.X;

            // Force update on first render
            shroudHash = -1;

            // Load sprite variants
            sprites = new Sprite[info.Variants.Length * info.Index.Length];
            variantStride = info.Index.Length;
            for (var j = 0; j < info.Variants.Length; j++)
            {
                var seq = SequenceProvider.GetSequence(info.Sequence, info.Variants[j]);
                for (var i = 0; i < info.Index.Length; i++)
                    sprites[j * variantStride + i] = seq.GetSprite(i);
            }

            // Mapping of shrouded directions -> sprite index
            spriteMap = new int[useExtendedIndex ? 256 : 16];
            for (var i = 0; i < info.Index.Length; i++)
                spriteMap[info.Index[i]] = i;

            // Set individual tile variants to reduce tiling
            for (var i = 0; i < tiles.Length; i++)
                tiles[i].Variant = Game.CosmeticRandom.Next(info.Variants.Length);

            // Synthesize unexplored tile if it isn't defined
            if (!info.Index.Contains(0))
            {
                var size = new Size(Game.modData.Manifest.TileSize, Game.modData.Manifest.TileSize);
                var data = Exts.MakeArray<byte>(size.Width * size.Height, _ => (byte)info.ShroudColor);
                var s = Game.modData.SheetBuilder.Add(data, size);
                unexploredTile = new Sprite(s.sheet, s.bounds, s.offset, s.channel, info.ShroudBlend);
            }
            else
                unexploredTile = sprites[spriteMap[0]];
        }
Ejemplo n.º 6
0
        public ShroudRenderer(World world, ShroudRendererInfo info)
        {
            if (info.ShroudVariants.Length != info.FogVariants.Length)
            {
                throw new ArgumentException("ShroudRenderer must define the same number of shroud and fog variants!", "info");
            }

            if ((info.OverrideFullFog == null) ^ (info.OverrideFullShroud == null))
            {
                throw new ArgumentException("ShroudRenderer cannot define overrides for only one of shroud or fog!", "info");
            }

            if (info.ShroudVariants.Length > byte.MaxValue)
            {
                throw new ArgumentException("ShroudRenderer cannot define this many shroud and fog variants.", "info");
            }

            if (info.Index.Length >= byte.MaxValue)
            {
                throw new ArgumentException("ShroudRenderer cannot define this many indexes for shroud directions.", "info");
            }

            this.info = info;
            map       = world.Map;

            tiles = new CellLayer <ShroudTile>(map);

            // Load sprite variants
            var variantCount = info.ShroudVariants.Length;

            variantStride = (byte)(info.Index.Length + (info.OverrideFullShroud != null ? 1 : 0));
            shroudSprites = new Sprite[variantCount * variantStride];
            fogSprites    = new Sprite[variantCount * variantStride];

            for (var j = 0; j < variantCount; j++)
            {
                var shroud = map.SequenceProvider.GetSequence(info.Sequence, info.ShroudVariants[j]);
                var fog    = map.SequenceProvider.GetSequence(info.Sequence, info.FogVariants[j]);
                for (var i = 0; i < info.Index.Length; i++)
                {
                    shroudSprites[j * variantStride + i] = shroud.GetSprite(i);
                    fogSprites[j * variantStride + i]    = fog.GetSprite(i);
                }

                if (info.OverrideFullShroud != null)
                {
                    var i = (j + 1) * variantStride - 1;
                    shroudSprites[i] = map.SequenceProvider.GetSequence(info.Sequence, info.OverrideFullShroud).GetSprite(0);
                    fogSprites[i]    = map.SequenceProvider.GetSequence(info.Sequence, info.OverrideFullFog).GetSprite(0);
                }
            }

            // Mapping of shrouded directions -> sprite index
            spriteMap = new byte[(byte)(info.UseExtendedIndex ? Edges.All : Edges.AllCorners) + 1];
            for (var i = 0; i < info.Index.Length; i++)
            {
                spriteMap[info.Index[i]] = (byte)i;
            }

            if (info.OverrideFullShroud != null)
            {
                spriteMap[info.OverrideShroudIndex] = (byte)(variantStride - 1);
            }

            notVisibleEdges = info.UseExtendedIndex ? Edges.AllSides : Edges.AllCorners;
        }