Beispiel #1
0
        /// <summary>
        /// Process any active subchunks
        /// </summary>
        public void Process()
        {
            for (int subchunkX = 0; subchunkX < World.SubChunksPerChunkWidth; subchunkX++)
            {
                int activeSubChunksFound = 0;
                if (activeSubChunksInColumn[subchunkX] == 0)
                {
                    continue;
                }
                int activeSubChunks = activeSubChunksInColumn[subchunkX];

                for (int subchunkY = World.SubChunksPerChunkHeight - 1; subchunkY >= 0; subchunkY--)
                {
                    SubChunk subchunk = GetSubChunkAtPosition(subchunkX, subchunkY);
                    if (!subchunk.Active)
                    {
                        continue;
                    }
                    subchunk.Process();

                    activeSubChunksFound += 1;
                    if (activeSubChunksFound >= activeSubChunks)
                    {
                        break;
                    }
                }
            }
        }
Beispiel #2
0
        public Cell GetCellAtPositionIfValid(int x, int y)
        {
            SubChunk subchunk = GetSubChunkAtPositionIfValid(x, y);

            if (subchunk != null)
            {
                return(subchunk.GetCellAtPosition(x % cellsPerSubChunkWidth, y % cellsPerSubChunkHeight));
            }
            return(null);
        }
Beispiel #3
0
        public Cell(SubChunk subChunk, int cellX, int cellY, int cellXLocal, int cellYLocal)
        {
            SubChunk   = subChunk;
            this.cellX = cellX;
            this.cellY = cellY;

            this.cellXLocal = cellXLocal;
            this.cellYLocal = cellYLocal;

            baseSand = new Sand.Air();
            BaseSand = baseSand;
        }
Beispiel #4
0
        /// <summary>
        /// Create a new chunk
        /// </summary>
        /// <param name="world">World the chunk is apart of</param>
        /// <param name="chunkX">X position in world</param>
        /// <param name="chunkY">Y position in world</param>
        /// <param name="chunkXIndex">X index</param>
        /// <param name="chunkYIndex">Y index</param>
        public Chunk(World world, int chunkX, int chunkY, int chunkXIndex, int chunkYIndex)
        {
            World            = world;
            SubChunks        = new SubChunk[world.SubChunksPerChunkWidth, world.SubChunksPerChunkHeight];
            this.chunkXIndex = chunkXIndex;
            this.chunkYIndex = chunkYIndex;

            this.chunkX = chunkX;
            this.chunkY = chunkY;

            activeSubChunksInColumn = new int[World.SubChunksPerChunkWidth];

            for (int x = 0; x < world.SubChunksPerChunkWidth; x++)
            {
                activeSubChunksInColumn[x] = 0;
                for (int y = 0; y < world.SubChunksPerChunkHeight; y++)
                {
                    SubChunk c = new SubChunk(this, x * world.CellsPerSubChunkWidth + ChunkXIndex * world.CellsPerChunkWidth, y * world.CellsPerSubChunkHeight + ChunkYIndex * world.CellsPerChunkHeight, x, y);
                    SubChunks[x, y] = c;
                }
            }
        }
Beispiel #5
0
 /// <summary>
 /// Activate the given subchunk
 /// </summary>
 /// <param name="subChunk">The subchunk to Activate</param>
 internal void SubChunkActivated(SubChunk subChunk)
 {
     ProcessableSubChunks += 1;
     activeSubChunksInColumn[subChunk.SubChunkXIndex] += 1;
 }
Beispiel #6
0
        public Cell GetCellAtPosition(int x, int y)
        {
            SubChunk subChunk = GetSubChunkAtPosition(x, y);

            return(subChunk.GetCellAtPosition(x % cellsPerSubChunkWidth, y % cellsPerSubChunkHeight));
        }