コード例 #1
0
ファイル: BlockStorageTests.cs プロジェクト: hach-que/voxeliq
        public void Init()
        {
            _game = new SampleGame();
            this._config = new EngineConfig();
            this._engine = new Engine(this._game, this._config);

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

            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);
        }
コード例 #2
0
ファイル: ChunkCache.cs プロジェクト: knocte/voxeliq
        // Sets a block in given x-y-z coordinate.
        public void SetBlockAt(int x, int y, int z, Block block)
        {
            var chunk = this.GetChunk(x, z);
            if (chunk == null)
                return;

            chunk.FastSetBlockAt((byte) (x%Chunk.WidthInBlocks), (byte) y, (byte) (z%Chunk.LenghtInBlocks), block); // use FastSetBlock as we already do bounds check by finding the chunk block is owned by.
        }
コード例 #3
0
ファイル: ChunkCache.cs プロジェクト: knocte/voxeliq
 // Sets a block in given x-y-z coordinate.
 public void SetBlockAt(Vector3Int position, Block block)
 {
     this.SetBlockAt(position.X, position.Y, position.Z, block);
 }
コード例 #4
0
ファイル: BlockStorage.cs プロジェクト: hach-que/voxeliq
 /// <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 static void SetBlockAt(Vector3 position, Block block)
 {
     SetBlockAt((int)position.X, (int)position.Y, (int)position.Z, block);
 }
コード例 #5
0
ファイル: BlockStorage.cs プロジェクト: hach-que/voxeliq
        /// <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 static void SetBlockAt(int x, int y, int z, Block block)
        {
            // make sure given coordinates are in chunk cache's bounds.
            if (!ChunkCache.IsInBounds(x, y, z))
                return; // if it's out of bounds, just return;

            // wrap x coordinate.
            var wrapX = x % CacheWidthInBlocks;
            if (wrapX < 0)
                wrapX += CacheWidthInBlocks;

            // wrap z coordinate.
            var wrapZ = z % CacheLenghtInBlocks;
            if (wrapZ < 0)
                wrapZ += CacheLenghtInBlocks;

            // calculate the flatten index.
            var flattenIndex = wrapX * XStep + wrapZ * ZStep + y;

            // set the block
            Blocks[flattenIndex] = block;
        }
コード例 #6
0
ファイル: BlockStorage.cs プロジェクト: hach-que/voxeliq
 /// <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>
 /// <remarks>This method will not check if given point/block coordinates are in chunk-cache's bounds. If you need a reliable & safe way, use <see cref="SetBlockAt"/> instead.</remarks>
 public static void FastSetBlockAt(Vector3Int position, Block block)
 {
     FastSetBlockAt(position.X, position.Y, position.Z, block);
 }
コード例 #7
0
ファイル: BlockStorage.cs プロジェクト: hach-que/voxeliq
        /// <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>
        /// <remarks>This method will not check if given point/block coordinates are in chunk-cache's bounds. If you need a reliable & safe way, use <see cref="SetBlockAt"/> instead.</remarks>
        public static void FastSetBlockAt(int x, int y, int z, Block block)
        {
            // wrap x coordinate.
            var wrapX = x % CacheWidthInBlocks;
            if (wrapX < 0)
                wrapX += CacheWidthInBlocks;

            // wrap z coordinate.
            var wrapZ = z % CacheLenghtInBlocks;
            if (wrapZ < 0)
                wrapZ += CacheLenghtInBlocks;

            // calculate the flatten index.
            var flattenIndex = wrapX * XStep + wrapZ * ZStep + y;

            // sett the block
            Blocks[flattenIndex] = block;
        }
コード例 #8
0
ファイル: PositionedBlock.cs プロジェクト: nerdshark/voxeliq
 public PositionedBlock(Vector3Int position, Block block)
 {
     Position = position;
     Block = block;
 }
コード例 #9
0
ファイル: Chunk.cs プロジェクト: nerdshark/voxeliq
        /// <summary>
        /// Sets block at given relative position.
        /// </summary>
        /// <param name="x"></param>
        /// <param name="y"></param>
        /// <param name="z"></param>
        /// <param name="block"></param>
        public void FastSetBlockAt(byte x, byte y, byte z, Block block)
        {
            switch (block.Exists)
            {
                case false:
                    if (this.LowestEmptyBlockOffset > y && y > 0)
                        this.LowestEmptyBlockOffset = (byte) (y - 1);
                    break;
                case true:
                    if (y > this.HighestSolidBlockOffset && y < MaxHeightIndexInBlocks)
                        this.HighestSolidBlockOffset = (byte) (y + 1);
                    break;
            }

            BlockStorage.FastSetBlockAt(this.WorldPosition.X + x, y, this.WorldPosition.Z + z, block);
            this.ChunkState = ChunkState.AwaitingRelighting;
        }
コード例 #10
0
ファイル: Chunk.cs プロジェクト: hach-que/voxeliq
        /// <summary>
        /// Sets a block by given relative 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>        
        /// <remarks>This method will not check if given point/block coordinates are in chunk-cache's bounds. If you need a reliable & safe way, use <see cref="SetBlockAt"/> instead.</remarks>
        public void FastSetBlockAt(sbyte x, sbyte y, sbyte z, Block block)
        {
            if (x < 0)
                x += (sbyte)Chunk.WidthInBlocks;
            if (z < 0)
                z += (sbyte) Chunk.LenghtInBlocks;

            BlockStorage.FastSetBlockAt(this.WorldPosition.X + x, y, this.WorldPosition.Z + z, block);
            this.ChunkState = ChunkState.AwaitingRelighting;
        }