Exemplo n.º 1
0
        /// <summary>
        /// Determines the overall geometry of a single <see cref="Tileset"/> visual layer. This involves
        /// tile boundaries in source and target data, as well as texture sizes and similar.
        /// </summary>
        /// <param name="renderInput"></param>
        /// <param name="layerData"></param>
        private LayerGeometry CalculateLayerGeometry(TilesetRenderInput renderInput, PixelData layerData)
        {
            LayerGeometry geometry;

            // What's the space requirement for each tile?
            geometry.SourceTileAdvance = renderInput.SourceTileAdvance;
            geometry.TargetTileAdvance = renderInput.TargetTileAdvance;

            // How many tiles will we have?
            Point2 tileCount = renderInput.GetSourceTileCount(layerData.Width, layerData.Height);

            geometry.SourceTilesPerRow    = tileCount.X;
            geometry.SourceTilesPerColumn = tileCount.Y;
            geometry.SourceTileCount      = geometry.SourceTilesPerRow * geometry.SourceTilesPerColumn;
            geometry.TargetTileCount      = geometry.SourceTileCount + this.generateTileSchedule.Count;

            // What's the optimal texture size to include them all?
            int minTilesPerLine = MathF.Max(1, (int)MathF.Sqrt(geometry.TargetTileCount));

            geometry.TargetTextureSize.X = MathF.NextPowerOfTwo(geometry.TargetTileAdvance.X * minTilesPerLine);

            int actualTilesPerLine = geometry.TargetTextureSize.X / geometry.TargetTileAdvance.X;
            int requiredLineCount  = 1 + (geometry.TargetTileCount / actualTilesPerLine);

            geometry.TargetTextureSize.Y = MathF.NextPowerOfTwo(geometry.TargetTileAdvance.Y * requiredLineCount);

            return(geometry);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Looks up the source pixel coordinates for the specified input layer and tile.
        /// </summary>
        /// <param name="renderConfigIndex"></param>
        /// <param name="tileIndex"></param>
        /// <param name="pos"></param>
        /// <param name="size"></param>
        public void LookupTileSourceRect(int renderConfigIndex, int tileIndex, out Point2 pos, out Point2 size)
        {
            TilesetRenderInput input = this.renderConfig[renderConfigIndex];

            Point2 advance   = input.SourceTileAdvance;
            Point2 tileCount = input.GetSourceTileCount(
                input.SourceData.Res.Width,
                input.SourceData.Res.Height);
            Point2 tileCoords = new Point2(
                tileIndex % tileCount.X,
                tileIndex / tileCount.X);

            size = input.SourceTileSize;
            pos  = new Point2(
                tileCoords.X * advance.X,
                tileCoords.Y * advance.Y);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Determines the overall geometry of a single <see cref="Tileset"/> visual layer. This involves
        /// tile boundaries in source and target data, as well as texture sizes and similar.
        /// </summary>
        /// <param name="renderInput"></param>
        /// <param name="layerData"></param>
        /// <returns></returns>
        private LayerGeometry CalculateLayerGeometry(TilesetRenderInput renderInput, PixelData layerData)
        {
            LayerGeometry geometry;

            // What's the space requirement for each tile?
            geometry.SourceTileAdvance = renderInput.SourceTileAdvance;
            geometry.TargetTileAdvance = renderInput.TargetTileAdvance;

            // How many tiles will we have?
            Point2 tileCount = renderInput.GetSourceTileCount(layerData.Width, layerData.Height);
            geometry.SourceTilesPerRow = tileCount.X;
            geometry.SourceTilesPerColumn = tileCount.Y;
            geometry.SourceTileCount = geometry.SourceTilesPerRow * geometry.SourceTilesPerColumn;
            geometry.TargetTileCount = geometry.SourceTileCount; // ToDo: Account for expanded AutoTiles

            // What's the optimal texture size to include them all?
            int minTilesPerLine = MathF.Max(1, (int)MathF.Sqrt(geometry.TargetTileCount));
            geometry.TargetTextureSize.X = MathF.NextPowerOfTwo(geometry.TargetTileAdvance.X * minTilesPerLine);

            int actualTilesPerLine = geometry.TargetTextureSize.X / geometry.TargetTileAdvance.X;
            int requiredLineCount = 1 + (geometry.TargetTileCount / actualTilesPerLine);
            geometry.TargetTextureSize.Y = MathF.NextPowerOfTwo(geometry.TargetTileAdvance.Y * requiredLineCount);

            return geometry;
        }