Ejemplo n.º 1
0
        public bool UpdateBackUV(int tileX, int tileY, bool updateVariation, bool rebakeChunk, bool updateAdjacentUVs)
        {
            if (!InTileBounds(tileX, tileY))
            {
                return(false);
            }
            int  chunkX     = (tileX >> Chunk.Bits);
            int  chunkY     = (tileY >> Chunk.Bits);
            int  chunkTileX = (tileX & Chunk.Modulo);
            int  chunkTileY = (tileY & Chunk.Modulo);
            Tile tile       = Chunks[chunkX, chunkY].Tiles[chunkTileX, chunkTileY];

            if (tile.Back == Tile.Backs.None)
            {
                if (UpdateAdjacentBackUVs(tileX, tileY, chunkX, chunkY))
                {
                    BakeBack();
                }
                return(false);
            }
            BackTileData tileData = Game1.BackTileData[tile.Back];

            if (updateVariation)
            {
                RandomizeBackVariation(chunkX, chunkY, chunkTileX, chunkTileY, tile, tileData);
            }
            if (UpdateBackUV(tileX, tileY, chunkX, chunkY, chunkTileX, chunkTileY, tile))
            {
                if (updateAdjacentUVs && UpdateAdjacentBackUVs(tileX, tileY, chunkX, chunkY))
                {
                    BakeBack();
                }
                if (rebakeChunk)
                {
                    if (Chunks[chunkX, chunkY].BackTexture != null)
                    {
                        Chunks[chunkX, chunkY].BakeBack();
                        BakeBack();
                    }
                }
                return(true);
            }
            return(false);
        }
Ejemplo n.º 2
0
        public bool RandomizeBackVariation(int tileX, int tileY)
        {
            if (!InTileBounds(tileX, tileY))
            {
                return(false);
            }
            int  chunkX     = (tileX >> Chunk.Bits);
            int  chunkY     = (tileY >> Chunk.Bits);
            int  chunkTileX = (tileX & Chunk.Modulo);
            int  chunkTileY = (tileY & Chunk.Modulo);
            Tile tile       = Chunks[chunkX, chunkY].Tiles[chunkTileX, chunkTileY];

            if (tile.Back == Tile.Backs.None)
            {
                return(false);
            }
            BackTileData tileData = Game1.BackTileData[tile.Back];

            RandomizeBackVariation(chunkX, chunkY, chunkTileX, chunkTileY, tile, tileData);
            return(true);
        }
Ejemplo n.º 3
0
        public void BakeBack()
        {
            if (BackTexture == null)
            {
                BackTexture              = new RenderTarget2D(Program.Game.GraphicsDevice, BackTextureSize, BackTextureSize, false, SurfaceFormat.Color, DepthFormat.None, 0, RenderTargetUsage.PreserveContents);
                BackTexture.ContentLost += Back_ContentLost;
            }
            SpriteBatch spriteBatch = Program.Game.Services.GetService <SpriteBatch>();

            Program.Game.GraphicsDevice.SetRenderTarget(BackTexture);
            Program.Game.GraphicsDevice.Clear(Color.TransparentBlack);
            spriteBatch.Begin(SpriteSortMode.Deferred, null, SamplerState.PointClamp, null, null, null, null);
            for (int x = 0; x < Size; x++)
            {
                for (int y = 0; y < Size; y++)
                {
                    if (Tiles[x, y].Back != Tile.Backs.None)
                    {
                        BackTileData tileData = Game1.BackTileData[Tiles[x, y].Back];
                        spriteBatch.Draw(tileData.Texture, new Rectangle((x * Tile.Size), (y * Tile.Size), Tile.BackTextureSize, Tile.BackTextureSize), BackTileData.UV[Tiles[x, y].BackUV][Tiles[x, y].BackVariation], Color.White);
                    }
                }
            }
#if DEBUG
            Game1.WorldBakeDrawCount      += (Program.Game.GraphicsDevice.Metrics.DrawCount - Game1.WorldBakeDrawCount);
            Game1.WorldBakeTextureCount   += (Program.Game.GraphicsDevice.Metrics.TextureCount - Game1.WorldBakeTextureCount);
            Game1.WorldBakeSpriteCount    += (Program.Game.GraphicsDevice.Metrics.SpriteCount - Game1.WorldBakeSpriteCount);
            Game1.WorldBakePrimitiveCount += (Program.Game.GraphicsDevice.Metrics.PrimitiveCount - Game1.WorldBakePrimitiveCount);
            Game1.WorldBakeTargetCount    += (Program.Game.GraphicsDevice.Metrics.TargetCount - Game1.WorldBakeTargetCount);
            Color color = (Color.Blue * .5f);
            spriteBatch.Draw(Game1.Pixel, new Rectangle(0, 0, BackTextureSize, 1), null, color, 0, Vector2.Zero, SpriteEffects.None, 0);
            spriteBatch.Draw(Game1.Pixel, new Rectangle((BackTextureSize - 1), 1, 1, (BackTextureSize - 1)), null, color, 0, Vector2.Zero, SpriteEffects.None, 0);
            spriteBatch.Draw(Game1.Pixel, new Rectangle(0, (BackTextureSize - 1), (BackTextureSize - 1), 1), null, color, 0, Vector2.Zero, SpriteEffects.None, 0);
            spriteBatch.Draw(Game1.Pixel, new Rectangle(0, 1, 1, (BackTextureSize - 2)), null, color, 0, Vector2.Zero, SpriteEffects.None, 0);
#endif
            spriteBatch.End();
        }
Ejemplo n.º 4
0
        internal void RandomizeBackVariation(int chunkX, int chunkY, int chunkTileX, int chunkTileY, Tile tile, BackTileData tileData)
        {
            int maxVariations = BackTileData.UV[tile.BackUV].Length;

            Chunks[chunkX, chunkY].Tiles[chunkTileX, chunkTileY].BackVariation = (byte)Enumerable.Range(0, maxVariations).ElementAt(Game1.Random.Next(maxVariations));
        }