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);
    }
    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);
    }
    private void SetNeedsRecalc(int parallelGrain)//this method not fully jobbed up, parallelGrain just used for copy function
    {
        NativeArrayUtil.CopyNativeArray(_conwayState, _needsRecalc, parallelGrain);

        for (int i = 0; i < _conwayState.Length; i++)
        {
            if (_conwayState[i])
            {
                //int adjacentsIndex = i * 8;
                for (int j = 0; j < 8; j++)
                {
                    int currentAdjacentIndex = _indexer.RawIndexFor(i, _adjacentOffsets[j]);
                    _needsRecalc[currentAdjacentIndex] = true;
                    //Debug.Log("i: " + i + " adjacentIndex: " + j + " value:  " + currentAdjacentIndex);
                }
            }
        }
    }
Ejemplo n.º 4
0
 private GameObject CellFor(int x, int y)
 {
     return(cells[gridIndexer.RawIndexFor(x, y)]);
 }