Exemplo n.º 1
0
        public void ShortenHighTiles(Position playerPosition, int range)
        {
            var        bounds             = new BoundsInt(playerPosition.x - range, playerPosition.y - range, 0, range * 2 + 1, range * 2 + 1, 1);
            MatrixByte standingTileMatrix = _contextManager.Current.TileMatricesByLayer[(int)TilemapLayer.Standing];

            OsnowaBaseTile[] tilesByIds = _tileByIdProvider.GetTilesByIds();
            foreach (Vector3Int position3 in bounds.allPositionsWithin)
            {
                var position = position3.ToPosition();
                if (!standingTileMatrix.IsWithinBounds(position))
                {
                    continue;
                }
                byte standingTileAtPosition = standingTileMatrix.Get(position);
                if (standingTileAtPosition <= 0)
                {
                    continue;
                }
                OsnowaBaseTile baseTileAtPosition = tilesByIds[standingTileAtPosition];
                if (baseTileAtPosition.ShorterVariant != null)
                {
                    _positionsToReset.Add(position);
                    _sceneContext.StandingTilemap.SetTile(position3, baseTileAtPosition.ShorterVariant);
                }
            }
        }
Exemplo n.º 2
0
 public OsnowaContext(int xSize, int ySize)
 {
     PositionFlags       = new PositionFlags(xSize, ySize);
     PathfindingData     = new PathfindingDataHolder(xSize, ySize);
     TileMatricesByLayer = new MatrixByte[(int)TilemapLayer.TotalLayersCount];
     Walkability         = new MatrixFloat(xSize, ySize);
     for (int i = 0; i < TileMatricesByLayer.Length; i++)
     {
         TileMatricesByLayer[i] = new MatrixByte(xSize, ySize);
     }
     VisibleEntities = new HashSet <IPositionedEntity>();
 }
Exemplo n.º 3
0
        public override IEnumerator Recalculating()
        {
            OsnowaBaseTile dirtBaseTile   = _worldGeneratorConfig.Tileset.DryDirt;
            MatrixByte     dirtMatrixByte = GameContext.TileMatricesByLayer[(int)dirtBaseTile.Layer];
            float          seaLevel       = GameContext.SeaLevel;

            foreach (Position position in Values.AllCellMiddles())
            {
                float value  = _initialShapeValues.Get(position);
                bool  isLand = value > seaLevel;
                value = isLand ? float.MaxValue : float.MinValue;
                Values.Set(position, value);
                if (isLand)
                {
                    dirtMatrixByte.Set(position, dirtBaseTile.Id);
                }
            }

            yield return(new WaitForSeconds(0.1f));
        }
Exemplo n.º 4
0
    public void Generate()
    {
        var            stopwatch = Stopwatch.StartNew();
        IOsnowaContext context   = _contextManager.Current;
        int            xSize     = context.PositionFlags.XSize;
        int            ySize     = context.PositionFlags.YSize;

        _allTilemaps = _sceneContext.AllTilemapsByLayers.ToArray();

        foreach (Tilemap tilemap in _sceneContext.AllPresentableTilemaps)
        {
            tilemap.ClearAllTiles();
        }

        int totalMapArea = xSize * ySize;

        List <Vector3Int>[] batchPositionsLayers;
        List <TileBase>[]   batchTilesLayers;
        CreateBatchPositionsAndTilesLayers(totalMapArea, out batchPositionsLayers, out batchTilesLayers);

        OsnowaBaseTile[] tilesByIds = _tileByIdFromFolderProvider.GetTilesByIds();

        for (int x = 0; x < xSize; x++)
        {
            for (int y = 0; y < ySize; y++)
            {
                for (int matrixLayer = 0; matrixLayer < context.TileMatricesByLayer.Length; matrixLayer++)
                {
//						if (matrixLayer == TilemapLayers.Roof || matrixLayer == TilemapLayers.OnRoof)
//							continue;
                    MatrixByte tileMatrixByte = context.TileMatricesByLayer[matrixLayer];
                    byte       tileId         = tileMatrixByte.Get(x, y);
                    if (tileId == 0)
                    {
                        continue;
                    }

                    OsnowaBaseTile baseTile = tilesByIds[tileId];
                    if (baseTile == null)
                    {
                        throw new System.Exception($"Tile with ID {tileId} not found in tileset, but placed on map.");
                    }
                    PrepareTileToSet(x, y, batchPositionsLayers, batchTilesLayers, (TilemapLayer)matrixLayer, baseTile);
                }
            }
        }

        var stopwatchBatch = Stopwatch.StartNew();

        for (int tilemapIndex = 0; tilemapIndex < _allTilemaps.Length; tilemapIndex++)
        {
            Tilemap tilemap = _allTilemaps[tilemapIndex];
            tilemap.SetTiles(batchPositionsLayers[tilemapIndex].ToArray(), batchTilesLayers[tilemapIndex].ToArray());
            UnityEngine.Debug.Log(tilemap.name + " tilemap: " + stopwatchBatch.ElapsedMilliseconds + " milliseconds.");
            stopwatchBatch.Restart();
        }

        BoundsInt fogOfWarBounds = _sceneContext.TilemapDefiningOuterBounds.cellBounds;

        OsnowaBaseTile[] fogOfWarToSet = Enumerable.Repeat(_tileset.FogOfWar, fogOfWarBounds.size.x * fogOfWarBounds.size.y).ToArray();
        _sceneContext.FogOfWarTilemap.SetTilesBlock(fogOfWarBounds, fogOfWarToSet);

        BoundsInt maskBounds = _sceneContext.TilemapDefiningOuterBounds.cellBounds;

        OsnowaBaseTile[] unseenMaskToSet = Enumerable.Repeat(_tileset.UnseenMask, maskBounds.size.x * maskBounds.size.y).ToArray();
        _sceneContext.UnseenMaskTilemap.SetTilesBlock(maskBounds, unseenMaskToSet);

        UnityEngine.Debug.Log("Tile generation time for " + xSize * ySize + " positions: " + stopwatch.ElapsedMilliseconds);
        UnityEngine.Debug.Log("Total tiles: " + batchPositionsLayers.Sum(l => l.Count));
    }