コード例 #1
0
ファイル: ChunkAnalyzer.cs プロジェクト: hengtek/Bones3
        /// <summary>
        /// Loads the block properties from the world into the chunk properties object.
        /// </summary>
        /// <param name="properties">The chunk properties to write to.</param>
        /// <param name="blockList">The block list to reference.</param>
        /// <param name="world">The world to load from.</param>
        /// <param name="chunkPos">The target chunk.</param>
        internal static void LoadProperties(ChunkProperties properties, BlockList blockList, World world, ChunkPosition chunkPos)
        {
            GetChunkGrid(world, chunkPos);
            properties.ChunkPosition = chunkPos;

            int size         = world.ChunkSize.Value;
            int intBits      = world.ChunkSize.IntBits;
            int extendedSize = size + 2;

            for (int x = -1; x <= size; x++)
            {
                for (int y = -1; y <= size; y++)
                {
                    for (int z = -1; z <= size; z++)
                    {
                        var local = (x & world.ChunkSize.Mask) * size * size
                                    + (y & world.ChunkSize.Mask) * size
                                    + (z & world.ChunkSize.Mask);

                        var chunkIndex = ((x >> intBits) + 1) * 3 * 3
                                         + ((y >> intBits) + 1) * 3
                                         + ((z >> intBits) + 1);

                        var index = (x + 1) * extendedSize * extendedSize
                                    + (y + 1) * extendedSize
                                    + (z + 1);

                        var blockId   = m_ChunkBuffer[chunkIndex]?.Blocks[local] ?? 0;
                        var blockType = blockList.GetBlockType(blockId);
                        properties.Blocks[index] = blockType;
                    }
                }
            }
        }