private ChunkCellData[,] GetNearbyChunksOrGenerateGhostChunks(out List <GhostChunkCellData> ghostChunks)
        {
            ChunkCellData[,] chunks = new ChunkCellData[3, 3];
            ghostChunks             = new List <GhostChunkCellData>();

            for (int i = 0; i < 3; i++)
            {
                for (int j = 0; j < 3; j++)
                {
                    if (i == 1 && j == 1)
                    {
                        chunks[i, j] = this;

                        continue;
                    }

                    Vector3Int coordinate = new Vector3Int(ChunkCoordinate.x - 1 + i, ChunkCoordinate.y - 1 + j, 0);

                    if (_chunkManager.GeneratedChunks.TryGetValue(coordinate, out CaveChunk chunk))
                    {
                        //chunks[i, j] = chunk.CellData;
                    }
                    else
                    {
                        GhostChunkCellData ghostChunk = new GhostChunkCellData(Settings, _chunkManager, coordinate);
                        chunks[i, j] = ghostChunk;

                        ghostChunks.Add(ghostChunk);
                    }
                }
            }

            return(chunks);
        }
        public void FindNearbyChunks(List <GhostChunkCellData> ghostChunks)
        {
            ChunkCellData[,] chunks = new ChunkCellData[3, 3];

            for (int i = 0; i < 3; i++)
            {
                for (int j = 0; j < 3; j++)
                {
                    if (i == 1 && j == 1)
                    {
                        chunks[i, j] = this;

                        continue;
                    }

                    Vector3Int coordinate = new Vector3Int(ChunkCoordinate.x - 1 + i, ChunkCoordinate.y - 1 + j, 0);

                    if (_chunkManager.GeneratedChunks.TryGetValue(coordinate, out CaveChunk chunk))
                    {
                        //chunks[i, j] = chunk.CellData;
                    }
                    else
                    {
                        chunks[i, j] = ghostChunks.Find(ghostChunk => ghostChunk.ChunkCoordinate == coordinate);
                    }
                }
            }

            NearbyChunks = chunks;
        }
Пример #3
0
        private CellType GetCellFromNearbyChunks(CellType[,,] cells, ChunkCellData[,] nearbyChunks, int previousIteration, int i, int j, int k)
        {
            int height = cells.GetLength(0);
            int width  = cells.GetLength(1);

            int chosenMatrixI = (i + height) / height;
            int chosenMatrixJ = (j + width) / width;

            ChunkCellData chosenChunk = nearbyChunks[chosenMatrixI, chosenMatrixJ];

            if (chosenChunk == null)
            {
                return(CellType.Hollow);
            }

            int relativeI = i - (chosenMatrixI - 1) * height;
            int relativeJ = j - (chosenMatrixJ - 1) * width;

            CellType[,,] chosenMatrix = chosenChunk.Iterations[previousIteration];

            return(chosenMatrix[relativeI, relativeJ, k]);
        }