示例#1
0
        public void CalculateHeightIndexes()
        {
            for (byte x = 0; x < Chunk.WidthInBlocks; x++)
            {
                var worldPositionX = this.WorldPosition.X + x;

                for (byte z = 0; z < Chunk.LengthInBlocks; z++)
                {
                    int worldPositionZ = this.WorldPosition.Z + z;

                    var offset = BlockStorage.BlockIndexByWorldPosition(worldPositionX, worldPositionZ);
                    for (int y = Chunk.MaxHeightIndexInBlocks; y >= 0; y--)
                    {
                        if ((y > this.HighestSolidBlockOffset) && (BlockStorage.Blocks[offset + y].Exists))
                        {
                            this.HighestSolidBlockOffset = (byte)y;
                        }
                        else if ((this.LowestEmptyBlockOffset > y) && (!BlockStorage.Blocks[offset + y].Exists))
                        {
                            this.LowestEmptyBlockOffset = (byte)y;
                        }
                    }
                }
            }

            this.LowestEmptyBlockOffset--;
        }
示例#2
0
        protected virtual void GenerateBlocks(Chunk chunk, int worldPositionX, int worldPositionZ)
        {
            var rockHeight = this.GetRockHeight(worldPositionX, worldPositionZ);
            var dirtHeight = this.GetDirtHeight(worldPositionX, worldPositionZ, rockHeight);

            var offset = BlockStorage.BlockIndexByWorldPosition(worldPositionX, worldPositionZ);

            for (int y = Chunk.MaxHeightIndexInBlocks; y >= 0; y--)
            {
                if (y > dirtHeight) // air
                {
                    BlockStorage.Blocks[offset + y] = new Block(BlockType.None);
                }
                else if (y > rockHeight) // dirt level
                {
                    BlockStorage.Blocks[offset + y] = new Block(BlockType.Dirt);
                }
                else // rock level
                {
                    BlockStorage.Blocks[offset + y] = new Block(BlockType.Rock);
                }
            }

            // apply the biome generator on x-z column.
            this.BiomeGenerator.ApplyBiome(chunk, dirtHeight, offset + dirtHeight, worldPositionX, worldPositionZ);
        }
示例#3
0
        protected override void GenerateBlocks(Chunk chunk, int worldPositionX, int worldPositionZ)
        {
            var offset = BlockStorage.BlockIndexByWorldPosition(worldPositionX, worldPositionZ);

            for (int y = Chunk.MaxHeightIndexInBlocks; y >= 0; y--)
            {
                if (y >= DirtHeight)
                {
                    BlockStorage.Blocks[offset + y] = new Block(BlockType.None);
                }
                else
                {
                    BlockStorage.Blocks[offset + y] = new Block(BlockType.Dirt);
                }
            }

            // apply the biome generator on x-z column.
            this.BiomeGenerator.ApplyBiome(chunk, DirtHeight - 1, offset + DirtHeight - 1, worldPositionX + this.Seed, worldPositionZ);
        }
示例#4
0
        public void Init()
        {
            _game        = new GameClient();
            this._config = new EngineConfig();
            this._engine = new Engine.Core.Engine(this._game, this._config);

            var cacheWidthInBlocks  = ((_config.Cache.CacheRange * 2) + 1) * _config.Chunk.WidthInBlocks;
            var cacheLenghtInBlocks = ((_config.Cache.CacheRange * 2) + 1) * _config.Chunk.LengthInBlocks;

            this._cacheXStartIndex = -cacheWidthInBlocks / 2;
            this._cacheXEndIndex   = cacheWidthInBlocks / 2;

            this._cacheZStartIndex = -cacheLenghtInBlocks / 2;
            this._cacheZEndIndex   = cacheLenghtInBlocks / 2;

            this._directlyIndexedValidationDictionary = new Dictionary <int, BlockType>();

            // set the initial values.
            for (var x = this._cacheXStartIndex; x < this._cacheXEndIndex; x++)
            {
                for (var z = this._cacheZStartIndex; z < this._cacheZEndIndex; z++)
                {
                    var offset = BlockStorage.BlockIndexByWorldPosition(x, z);

                    for (var y = 0; y < _config.Chunk.HeightInBlocks; y++)
                    {
                        var index = offset + y;
                        var block = new Block().RandomizeType();

                        this._directlyIndexedValidationDictionary.Add(index, block.Type);

                        BlockStorage.Blocks[index] = block;
                    }
                }
            }

            // check if validationDictionaries item count is equal to CacheRange's volume.
            Assert.AreEqual(this._directlyIndexedValidationDictionary.Values.Count, _config.Cache.CacheRangeVolume);
        }
示例#5
0
        protected override void GenerateBlocks(Chunk chunk, int worldPositionX, int worldPositionZ)
        {
            var rockHeight = this.GetRockHeight(worldPositionX, worldPositionZ);
            var dirtHeight = this.GetDirtHeight(worldPositionX, worldPositionZ, rockHeight);

            var offset = BlockStorage.BlockIndexByWorldPosition(worldPositionX, worldPositionZ);

            for (int y = Chunk.MaxHeightIndexInBlocks; y >= 0; y--)
            {
                if (y > dirtHeight) // air
                {
                    BlockStorage.Blocks[offset + y] = new Block(BlockType.None);
                    if (chunk.LowestEmptyBlockOffset > y)
                    {
                        chunk.LowestEmptyBlockOffset = (byte)y;
                    }
                }
                else if (y > rockHeight) // dirt
                {
                    var valleyNoise = this.GenerateValleyNoise(worldPositionX, worldPositionZ, y);
                    BlockStorage.Blocks[offset + y] = new Block(valleyNoise > 0.2f ? BlockType.None : BlockType.Dirt);
                    if (y > chunk.HighestSolidBlockOffset)
                    {
                        chunk.HighestSolidBlockOffset = (byte)y;
                    }
                }
                else // rock level
                {
                    BlockStorage.Blocks[offset + y] = new Block(BlockType.Rock);
                    if (y > chunk.HighestSolidBlockOffset)
                    {
                        chunk.HighestSolidBlockOffset = (byte)y;
                    }
                }
            }

            // apply the biome generator on x-z column.
            this.BiomeGenerator.ApplyBiome(chunk, dirtHeight, offset + dirtHeight, worldPositionX + this.Seed, worldPositionZ);
        }
示例#6
0
        public static void PopulateTree(int worldPositionX, int worldPositionZ, int groundLevel)
        {
            var trunkHeight = 5;
            var trunkOffset = BlockStorage.BlockIndexByWorldPosition(worldPositionX, worldPositionZ);

            for (int y = trunkHeight + groundLevel; y > groundLevel; y--)
            {
                BlockStorage.Blocks[trunkOffset + y] = new Block(BlockType.Tree);
            }

            var radius = 3;

            for (int i = -radius; i < radius; i++)
            {
                for (int j = -radius; j < radius; j++)
                {
                    var offset = BlockStorage.BlockIndexByWorldPosition(worldPositionX + i, worldPositionZ + j);
                    for (int k = radius * 2; k > 0; k--)
                    {
                        BlockStorage.Blocks[offset + k + trunkHeight + 1] = new Block(BlockType.Leaves);
                    }
                }
            }
        }
示例#7
0
        public void TestAllBlocksInCacheRange()
        {
            // read them back
            for (var x = this._cacheXStartIndex; x < this._cacheXEndIndex; x++)
            {
                for (var z = this._cacheZStartIndex; z < this._cacheZEndIndex; z++)
                {
                    var offset = BlockStorage.BlockIndexByWorldPosition(x, z);

                    for (var y = 0; y < _config.Chunk.HeightInBlocks; y++)
                    {
                        var index = offset + y;

                        var expectedType = this._directlyIndexedValidationDictionary[index];

                        var blockIndexed = BlockStorage.Blocks[index];
                        Assert.AreEqual(expectedType, blockIndexed.Type);

                        var blockAt = BlockStorage.BlockAt(x, y, z);
                        Assert.AreEqual(expectedType, blockAt.Type);
                    }
                }
            }
        }