public void Execute(int i)
            {
                Entity        tile = tileBufferMapKeys[i];
                TileBuffer    updatedTileBuffer    = tileBufferMap[tile];
                TileComponent curTileComponent     = tileComponentLookup[tile];
                var           updatedTileComponent = new TileComponent
                {
                    Position      = curTileComponent.Position,
                    State         = curTileComponent.State,
                    AdjacentTiles = updatedTileBuffer
                };

                ecbWriter.SetComponent(i, tile, updatedTileComponent);
            }
        public virtual void Generate(MapContainer map, TerrainId terrain)
        {
            _map     = map;
            _terrain = terrain;
            _buffer  = new TileBuffer(_map);

            int targetMass  = CalculateTargetTerrainMass();
            int currentMass = GenerateSeeds();

            while (currentMass < targetMass)
            {
                ModifyTerrain(_buffer.GetRandom);
                currentMass++;
            }
        }
            public void Execute(int i)
            {
                Entity tileKey = nodes[i];

                NativeMultiHashMap <Entity, TileLink> .Enumerator tileLinksEnumerator =
                    nodesTileLinksMap.GetValuesForKey(tileKey);

                TileBuffer tileBuffer = tileComponentLookup[tileKey]
                                        .AdjacentTiles.Clone();

                while (tileLinksEnumerator.MoveNext())
                {
                    TileLink curTilelink = tileLinksEnumerator.Current;
                    tileBuffer[curTilelink.index] = curTilelink.adjTile;
                }

                tileBufferMapWriter.TryAdd(tileKey, tileBuffer);
            }
            public void Execute()
            {
                for (var i = 0; i < adjTileLinksKeys.Length; ++i)
                {
                    GridPosition tileKey = adjTileLinksKeys[i];
                    NativeMultiHashMap <GridPosition, TileLink> .Enumerator tileLinksEnumerator =
                        adjTileLinksMap.GetValuesForKey(tileKey);
                    tileLinksEnumerator.MoveNext();

                    TileLink curTileLink = tileLinksEnumerator.Current;
                    Entity   tile        = ecbWriter.Instantiate(curTileLink.tile);

                    var offset          = new float3(0f, 0.3f, 0f);
                    var tileTranslation = new Translation {
                        Value = tileKey + offset
                    };

                    TileBuffer tileBuffer = TileBuffer.Empty;

                    do
                    {
                        curTileLink = tileLinksEnumerator.Current;
                        tileBuffer[(curTileLink.index + 3) % 6] = curTileLink.tile;
                    } while (tileLinksEnumerator.MoveNext());

                    var tileCmpnt = new TileComponent
                    {
                        Position = tileKey, State = 0, AdjacentTiles = tileBuffer
                    };
                    ecbWriter.SetComponent(tile, tileCmpnt);
                    ecbWriter.SetComponent(tile, tileTranslation);
                    ecbWriter.SetSharedComponent(
                        tile,
                        GridGenerationComponent.OuterNodeLinkingPhase
                        );
                }
            }
            public void Execute(int i)
            {
                Entity     tile       = centerNodes[i];
                TileBuffer tileBuffer = tileBufferMap[tile];

                for (var j = 0; j < 6; ++j)
                {
                    Entity adjTileN0 = tileBuffer[j];
                    Entity adjTileN1 = tileBuffer[(j + 1) % 6];

                    if (adjTileN1 == Entity.Null)
                    {
                        ++j;
                    }
                    else if (adjTileN0 == Entity.Null)
                    {
                    }
                    else if (linkingTilesArray.Contains(adjTileN0) ||
                             linkingTilesArray.Contains(adjTileN1))
                    {
                        var adjTileLinkN0 = new TileLink
                        {
                            tile    = adjTileN0,
                            index   = (j + 2) % 6,
                            adjTile = adjTileN1
                        };
                        var adjTileLinkN1 = new TileLink
                        {
                            tile    = adjTileN1,
                            index   = (j + 5) % 6,
                            adjTile = adjTileN0
                        };
                        outerNodesMapWriter.Add(adjTileN0, adjTileLinkN0);
                        outerNodesMapWriter.Add(adjTileN1, adjTileLinkN1);
                    }
                }
            }
            public void Execute(ArchetypeChunk chunk, int chunkIndex, int firstEntityInIndex)
            {
                NativeArray <TileComponent> tileComponentArray =
                    chunk.GetNativeArray(tileComponentTypeHandle);
                BufferAccessor <TileLinkUpdate> tileLinkUpdateBufferAccessor =
                    chunk.GetBufferAccessor(tileLinkUpdateBufferTypeHandle);
                var markedNodes = new NativeHashSet <Entity>(chunk.Count * 6, Allocator.Temp);

                for (var i = 0; i < chunk.Count; ++i)
                {
                    TileComponent tileComponent = tileComponentArray[i];
                    DynamicBuffer <TileLinkUpdate> tileLinkUpdateBuffer =
                        tileLinkUpdateBufferAccessor[i];
                    TileBuffer tileBuffer = tileComponent.AdjacentTiles.Clone();

                    foreach (TileLinkUpdate tileLinkUpdate in tileLinkUpdateBuffer)
                    {
                        tileBuffer[tileLinkUpdate.Index] = tileLinkUpdate.AdjTile;
                    }

                    foreach (TileLinkUpdate tileLinkUpdate in tileLinkUpdateBuffer)
                    {
                        var index = tileLinkUpdate.Index;

                        Entity adjTile      = tileLinkUpdate.AdjTile;
                        Entity adjTileRight = tileBuffer[(index + 1) % 6];
                        Entity adjTileLeft  = tileBuffer[(index + 5) % 6];

                        var adjTileLinkUpdates =
                            new NativeList <TileLinkUpdate>(4, Allocator.Temp)
                        {
                            new TileLinkUpdate
                            {
                                Tile = adjTile, Index = (index + 2) % 6, AdjTile = adjTileRight
                            },
                            new TileLinkUpdate
                            {
                                Tile = adjTileRight, Index = (index + 5) % 6, AdjTile = adjTile
                            },
                            new TileLinkUpdate
                            {
                                Tile = adjTileLeft, Index = (index + 2) % 6, AdjTile = adjTile
                            },
                            new TileLinkUpdate
                            {
                                Tile = adjTile, Index = (index + 5) % 6, AdjTile = adjTileLeft
                            }
                        };

                        foreach (TileLinkUpdate adjTileLinkUpdate in adjTileLinkUpdates)
                        {
                            if (!markedNodes.Contains(adjTileLinkUpdate.Tile))
                            {
                                markedNodes.Add(adjTileLinkUpdate.Tile);
                                ecb.AddBuffer <TileLinkUpdate>(adjTileLinkUpdate.Tile);
                            }

                            ecb.AppendToBuffer(adjTileLinkUpdate.Tile, adjTileLinkUpdate);
                        }

                        adjTileLinkUpdates.Dispose();
                    }
                }

                markedNodes.Dispose();
            }
Beispiel #7
0
        /// <summary>
        /// 指定位置を基点として、スキャンライン・シードフィルに基づく塗りつぶしを行います。
        /// 塗りつぶしを行ったタイルのリストを返値とします。
        /// </summary>
        public List <TileBuffer> FillTiles(int x, int y, bool absolutely)
        {
            var list = new List <TileBuffer>();

            if (!Enum.IsDefined(typeof(Map.Layer), this.CurrentLayer))
            {
                //無効なレイヤー
                return(list);
            }

            var   buf      = new Queue <Point>();
            var   baseTile = this.MapData.LayerTiles[this.CurrentLayer, x, y].PalletPosition;
            Point fillTile;

            if (this.ClippingTiles == null)
            {
                fillTile = this.SelectedPalletRange.Location;
            }
            else
            {
                fillTile = this.ClippingTiles[0, 0].PalletPosition;
            }

            //始点が既に塗りつぶすタイルである場合は処理しない
            if (baseTile == fillTile)
            {
                return(null);
            }

            //初動を追加
            buf.Enqueue(new Point(x, y));

            //バッファにデータが残っている限り処理し続ける
            while (buf.Count > 0)
            {
                var p = buf.Dequeue();      //バッファの先頭を取り出す
                int left;
                int right;

                //既に塗ったタイルは処理しない
                if (this.MapData.LayerTiles[this.CurrentLayer, p.X, p.Y].PalletPosition == fillTile)
                {
                    continue;
                }

                //左端を探索
                for (left = p.X; 0 < left; left--)
                {
                    if (this.MapData.LayerTiles[this.CurrentLayer, left - 1, p.Y].PalletPosition != baseTile)
                    {
                        break;
                    }
                }

                //右端を探索
                for (right = p.X; right < this.MapData.MapSize.Width - 1; right++)
                {
                    if (this.MapData.LayerTiles[this.CurrentLayer, right + 1, p.Y].PalletPosition != baseTile)
                    {
                        break;
                    }
                }

                //左端から右端までを塗る
                for (var i = left; i <= right; i++)
                {
                    //一連の操作に追加する
                    var put = new TileBuffer((Map.Layer) this.CurrentLayer, new Point(i, p.Y), this.MapData.LayerTiles[this.CurrentLayer, i, p.Y]);
                    this.putTile(i, p.Y, absolutely);
                    put.After = this.MapData.LayerTiles[this.CurrentLayer, i, p.Y];
                    list.Add(put);
                }

                //下側の位置を探索
                if (p.Y + 1 < this.MapData.MapSize.Height)
                {
                    this.scanLine(left, right, p.Y + 1, baseTile, buf);
                }

                //上側の位置を探索
                if (0 <= p.Y - 1)
                {
                    this.scanLine(left, right, p.Y - 1, baseTile, buf);
                }
            }

            return(list);
        }
Beispiel #8
0
        /// <summary>
        /// 指定したタイル座標にパレットで選択されたタイルを配置します。
        /// 鉛筆ツールのときのみ、配置したタイルの前後情報をリストにして返します。
        /// </summary>
        /// <param name="absolutely">オートタイルを更新せずに原形を留めるかどうか</param>
        public List <TileBuffer> PutTiles(int dx, int dy, bool absolutely)
        {
            var list = new List <TileBuffer>();

            if (!Enum.IsDefined(typeof(Map.Layer), this.CurrentLayer))
            {
                //無効なレイヤー
                return(list);
            }

            //編集モードに従った処理
            switch (this.EditMode)
            {
            case TileEditMode.Pencil:
                if (this.ClippingTiles == null)
                {
                    //パレットの選択領域を使って配置する
                    var put = new TileBuffer((Map.Layer) this.CurrentLayer, new Point(dx, dy), this.MapData.LayerTiles[this.CurrentLayer, dx, dy]);
                    this.MapData.LayerTiles[this.CurrentLayer, dx, dy].PalletPosition = this.SelectedPalletRange.Location;
                    if (!absolutely)
                    {
                        this.ApplyAutoTile((Map.Layer) this.CurrentLayer, dx, dy);
                    }
                    put.After = this.MapData.LayerTiles[this.CurrentLayer, dx, dy];
                    list.Add(put);
                }
                else
                {
                    //クリッピング領域を使って配置する
                    for (var x = 0; x < this.ClippingTiles.GetLength(0) && dx + x < this.MapData.MapSize.Width; x++)
                    {
                        for (var y = 0; y < this.ClippingTiles.GetLength(1) && dy + y < this.MapData.MapSize.Height; y++)
                        {
                            var put = new TileBuffer((Map.Layer) this.CurrentLayer, new Point(dx + x, dy + y), this.MapData.LayerTiles[this.CurrentLayer, dx + x, dy + y]);
                            this.MapData.LayerTiles[this.CurrentLayer, dx + x, dy + y].PalletPosition = this.ClippingTiles[x, y].PalletPosition;
                            this.MapData.LayerTiles[this.CurrentLayer, dx + x, dy + y].SetQuarters(this.ClippingTiles[x, y].GetQuarters());
                            if (!absolutely)
                            {
                                this.ApplyAutoTile((Map.Layer) this.CurrentLayer, dx + x, dy + y);
                            }
                            put.After = this.MapData.LayerTiles[this.CurrentLayer, dx + x, dy + y];
                            list.Add(put);
                        }
                    }
                }
                break;

            case TileEditMode.Rectangle:
            case TileEditMode.Ellipse:
                //確定前矩形領域の有効範囲を生成する
                var tempPath = new System.Drawing.Drawing2D.GraphicsPath();
                switch (this.EditMode)
                {
                case TileEditMode.Rectangle:
                    tempPath.AddRectangle(this.PuttingTileRange);
                    break;

                case TileEditMode.Ellipse:
                    tempPath.AddEllipse(this.PuttingTileRange.X - 1, this.PuttingTileRange.Y - 1, this.PuttingTileRange.Width + 1, this.PuttingTileRange.Height + 1);
                    break;
                }

                //有効範囲内にタイルを配置する
                for (int a = 0, x = this.PuttingTileRange.Left; x < this.PuttingTileRange.Right; x++, a++)
                {
                    for (int b = 0, y = this.PuttingTileRange.Top; y < this.PuttingTileRange.Bottom; y++, b++)
                    {
                        if (!tempPath.IsVisible(x, y))
                        {
                            continue;           //描画範囲外
                        }
                        else if (this.ClippingTiles == null)
                        {
                            //パレットの選択領域を使って配置する
                            this.MapData.LayerTiles[this.CurrentLayer, x, y].PalletPosition = this.SelectedPalletRange.Location;
                        }
                        else
                        {
                            //クリッピング領域を使って配置する
                            this.MapData.LayerTiles[this.CurrentLayer, x, y].PalletPosition = this.ClippingTiles[a % this.ClippingTiles.GetLength(0), b % this.ClippingTiles.GetLength(1)].PalletPosition;
                            this.MapData.LayerTiles[this.CurrentLayer, x, y].SetQuarters(this.ClippingTiles[a % this.ClippingTiles.GetLength(0), b % this.ClippingTiles.GetLength(1)].GetQuarters());
                        }
                        if (!absolutely)
                        {
                            this.ApplyAutoTile((Map.Layer) this.CurrentLayer, x, y);
                        }
                    }
                }
                break;
            }

            return(list);
        }