コード例 #1
0
    private NativeArray <ushort> BuildMapMirroredDimensions(SparseGridIndexer indexer)
    {
        NativeArray <ushort> returnValue = new NativeArray <ushort>(indexer.RawCount() * 4, Allocator.Persistent);

        for (int x = 0; x < indexer.columnCount; x++)
        {
            for (int y = 0; y < indexer.rowCount; y++)
            {
                int    dimensionalRawIndex = indexer.RawIndexFor(x, y) * 4;
                ushort mirroredX           = (ushort)SparseGridIndexer.MirroredIndexFor(x, (ushort)indexer.columnCount);
                ushort mirroredY           = (ushort)SparseGridIndexer.MirroredIndexFor(y, (ushort)indexer.rowCount);

                ushort firstIndex  = (ushort)indexer.RawIndexFor(x, y);
                ushort secondIndex = (ushort)indexer.RawIndexFor(mirroredX, y);
                ushort thirdIndex  = (ushort)indexer.RawIndexFor(mirroredX, mirroredY);
                ushort fourthIndex = (ushort)indexer.RawIndexFor(x, mirroredY);

                returnValue[dimensionalRawIndex + 0] = firstIndex;
                returnValue[dimensionalRawIndex + 1] = secondIndex;
                returnValue[dimensionalRawIndex + 2] = thirdIndex;
                returnValue[dimensionalRawIndex + 3] = fourthIndex;
            }
        }
        return(returnValue);
    }
コード例 #2
0
    private NativeArray <ushort> BuildAdjacents(SparseGridIndexer indexer, NativeArray <CellOffset> offsets)
    {
        int adjacentsLength = indexer.RawCount() * 8;

        NativeArray <ushort> returnValue = new NativeArray <ushort>(adjacentsLength, Allocator.Persistent);

        //      Debug.Log("BuildAdjacents returnValue Length: " + returnValue.Length);

        int columnCount = indexer.columnCount;
        int rowCount    = indexer.rowCount;

        for (int x = 0; x < columnCount; x++)
        {
            for (int y = 0; y < rowCount; y++)
            {
                int conwayBaseIndex    = indexer.RawIndexFor(x, y);
                int adjacentsBaseIndex = conwayBaseIndex * 8;

                for (int i = 0; i < offsets.Length; i++)
                {
                    int adjacentOffsetX = offsets[i].XFrom(x);
                    int adjacentOffsetY = offsets[i].YFrom(y);

                    int    adjustedX        = SparseGridIndexer.WrappedIndexFor(adjacentOffsetX, (ushort)columnCount);
                    int    adjustedY        = SparseGridIndexer.WrappedIndexFor(adjacentOffsetY, (ushort)rowCount);
                    ushort adjustedRawValue = (ushort)indexer.RawIndexFor(adjustedX, adjustedY);

                    returnValue[adjacentsBaseIndex + i] = adjustedRawValue;
                }
            }
        }
//        Debug.Log("BuildAdjacents returnValue (2) Length: " + returnValue.Length);
        return(returnValue);
    }
コード例 #3
0
    private void SetCellColorIndex(int rawIndex, int colorIndex)
    {
        GameObject cell = CellFor(rawIndex);
        Color      cellColor;
        int        colorsLength       = colors.Length;
        int        adjustedColorIndex = SparseGridIndexer.BoundedIndexFor(state[rawIndex], (ushort)colorsLength);

        cellColor = colors[adjustedColorIndex];

        cellRenderers[rawIndex].color = cellColor;
    }
コード例 #4
0
    public void InitializeData(SparseGridIndexer index, NativeArray <byte> displayState, Color[] colorarray)
    {
        gridIndexer = index;
        state       = displayState;
        colors      = colorarray;
        backupState = new NativeArray <byte>(state.Length, Allocator.Persistent);

        cells         = new GameObject[gridIndexer.RawCount()];
        cellRenderers = new SpriteRenderer[gridIndexer.RawCount()];
        GenerateGrid();
    }
コード例 #5
0
    private void AllocateData(ushort colCount, ushort rowCount)
    {
        ColumnCount = colCount;
        RowCount    = rowCount;
        RawCount    = ColumnCount * RowCount;

        _indexer = new SparseGridIndexer(ColumnCount, RowCount);

        _conwayState = new NativeArray <bool>(RawCount, Allocator.Persistent);
        //Debug.Log("_conwayState length: " + _conwayState.Length);
        _needsRecalc = new NativeArray <bool>(RawCount, Allocator.Persistent);
        //Debug.Log("_needsRecalc  length: " + _needsRecalc.Length);
        _previousConwayState = new NativeArray <bool>(RawCount, Allocator.Persistent);
        //Debug.Log("_previousConwayState length: " + _previousConwayState.Length);


        _adjacentOffsets = BuildAdjacentOffsets();
        //Debug.Log("_adjacentOffsets length: " + _adjacentOffsets.Length);
        //_mapAdjacents = BuildAdjacents(_indexer, _adjacentOffsets);
        //Debug.Log("_mapAdjacents length: " + _mapAdjacents.Length);
    }
コード例 #6
0
 public ConwayDisplayState(NativeArray <byte> displayState, SparseGridIndexer indexer)
 {
     this.indexer           = indexer;
     DisplayState           = displayState;
     MirroredDisplayIndices = BuildMapMirroredDimensions(indexer);
 }