Esempio n. 1
0
    public ChunkedGrid(ChunkedGrid <T> cloneFrom)
    {
        this.chunkSize      = cloneFrom.chunkSize;
        this.totalchunkSize = chunkSize * chunkSize;

        var cloneBuffer = cloneFrom.buffer;

        this.buffer = new NativeList <T>(cloneBuffer.Length, Allocator.Persistent);
        for (int i = 0; i < cloneBuffer.Length; i++)
        {
            this.buffer.Add(cloneBuffer[i]);
        }

        var cloneHashMap     = cloneFrom.hashMap;
        var cloneHashMapKeys = cloneFrom.hashMap.GetKeyArray(Allocator.Temp);

        this.hashMap = new NativeHashMap <int2, int>(cloneHashMap.Length, Allocator.Persistent);

        foreach (var key in cloneHashMapKeys)
        {
            this.hashMap.TryAdd(key, cloneHashMap[key]);
        }

        cloneHashMapKeys.Dispose();

        lastChunkIndex = cloneFrom.lastChunkIndex;
    }
Esempio n. 2
0
    public static AtmosSimulation FromTilemap(Tilemap tilemapVisual, int chunkSize = 3)
    {
        var tilemapSize   = tilemapVisual.size;
        var tilemapOrigin = tilemapVisual.origin;

        var worstCaseSize = tilemapSize.x * tilemapSize.y;
        var grid          = new ChunkedGrid <AtmosCell>(chunkSize, worstCaseSize);

        for (int x = tilemapOrigin.x; x < tilemapSize.x + tilemapOrigin.x; x++)
        {
            for (int y = tilemapOrigin.y; y < tilemapSize.y + tilemapOrigin.y; y++)
            {
                var pos = new Vector3Int(x, y, 0);

                // Is there any tile?
                var tile = tilemapVisual.GetTile <GridTile>(pos);
                if (tile != null)
                {
                    var atmosCell = new AtmosCell()
                    {
                        pressure = tile.pressure,
                        isWall   = tile.isWall
                    };

                    grid.AddCell(x, y, atmosCell);
                }
            }
        }

        return(new AtmosSimulation(grid));
    }
Esempio n. 3
0
 public Chunk(ChunkedGrid <T> grid, int2 chunkPos)
 {
     this.grid     = grid;
     this.chunkPos = chunkPos;
 }
Esempio n. 4
0
 public AtmosSimulation(ChunkedGrid <AtmosCell> grid)
 {
     currentState = grid;
     nextState    = grid.Clone();
 }