Exemplo n.º 1
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);
        }
Exemplo n.º 2
0
 public PositionedBlock(Vector3Int position, Block block)
 {
     Position = position;
     Block = block;
 }
Exemplo n.º 3
0
 /// <summary>
 /// Sets a block by given world position.
 /// </summary>
 /// <param name="position">Point/block position.</param>
 /// <returns>Copy of <see cref="Block"/></returns>
 /// <param name="block">Block to set.</param>
 public void SetBlockAt(Vector3Int position, Block block)
 {
     SetBlockAt(position.X, position.Y, position.Z, block);
 }
Exemplo n.º 4
0
 /// <summary>
 /// Sets a block by given world position.
 /// </summary>
 /// <param name="position">Point/block position.</param>
 /// <returns>Copy of <see cref="Block"/></returns>
 /// <param name="block">Block to set.</param>
 public void SetBlockAt(Vector3 position, Block block)
 {
     SetBlockAt((int)position.X, (int)position.Y, (int)position.Z, block);
 }
Exemplo n.º 5
0
        /// <summary>
        /// Sets a block by given world position.
        /// </summary>
        /// <param name="x">Block's x world position.</param>
        /// <param name="y">Block's y world position.</param>
        /// <param name="z">Block's z world position.</param>
        /// <param name="block">Block to set.</param>
        public void SetBlockAt(int x, int y, int z, Block block)
        {
            var chunk = _chunkCache.GetChunkByWorldPosition(x, z); // get the chunk that block is hosted in.
            if (chunk == null) // make sure chuck exists.
                return;

            var flattenIndex = BlockIndexByWorldPosition(x, y, z);

            // set the block
            Blocks[flattenIndex] = block;

            // Check if block is chunk's edges, if so re-process the neighbor chunks too.
            var edgesBlockIsIn = this.GetChunkEdgesBlockIsIn(x, y, z);
            foreach (var edge in edgesBlockIsIn)
            {
                var neighborChunk = this._chunkCache.GetNeighborChunk(chunk, edge);
                neighborChunk.ChunkState = ChunkState.AwaitingRelighting;
            }

            // let the owner chunk get rebuilt.
            // note: we re-process the originally altered chunk last because we wan't neighbor chunk's to get ready before, so we don't see any graphical glitches.
            chunk.ChunkState = ChunkState.AwaitingRelighting;
        }
Exemplo n.º 6
0
 public void Init()
 {
     _emptyBlock = Block.Empty;
 }