예제 #1
0
        public void SetArea(Vector3I start, Vector3I end, BlockVoxel voxel)
        {
            GetAreaFromPoints(start, end, out Vector3I areaStart,
                              out Vector3I areaScale);

            RootChunk.TraverseToChunk(areaStart, true, out var startChunk);
            RootChunk.TraverseToChunk(areaStart + areaScale, true,
                                      out var endChunk);
            int      chunkSideLength = RootChunk.SideLength;
            Vector3I wholeChunkArea  = Vector3I.One +
                                       ((endChunk.Offset - startChunk.Offset) / chunkSideLength);

            Chunk <BlockVoxel>[,,] chunkCache = new Chunk <BlockVoxel> [
                wholeChunkArea.X, wholeChunkArea.Y, wholeChunkArea.Z];
            chunkCache[0, 0, 0] = startChunk;
            chunkCache[chunkCache.GetLength(0) - 1,
                       chunkCache.GetLength(1) - 1,
                       chunkCache.GetLength(2) - 1] = endChunk;

            Chunk <BlockVoxel> currentChunk;

            for (int x = 0; x < areaScale.X; x++)
            {
                for (int y = 0; y < areaScale.Y; y++)
                {
                    for (int z = 0; z < areaScale.Z; z++)
                    {
                        Vector3I offset      = new Vector3I(x, y, z);
                        Vector3I cacheOffset =
                            ((areaStart - startChunk.Offset) + offset) /
                            chunkSideLength;

                        if (chunkCache[cacheOffset.X, cacheOffset.Y,
                                       cacheOffset.Z] == null)
                        {
                            RootChunk.TraverseToChunk(areaStart + offset,
                                                      true, out chunkCache[cacheOffset.X,
                                                                           cacheOffset.Y, cacheOffset.Z]);
                        }

                        currentChunk = chunkCache[cacheOffset.X,
                                                  cacheOffset.Y, cacheOffset.Z];

                        if (currentChunk.Availability !=
                            ChunkAvailability.None)
                        {
                            currentChunk.Unlock();
                            currentChunk.SetVoxel(areaStart + offset -
                                                  currentChunk.Offset, voxel);
                        }
                    }
                }
            }
        }
예제 #2
0
 private bool IsBlockSolid(Vector3 position)
 {
     if (RootChunk.TraverseToChunk((Vector3I)position, false,
                                   out var chunk))
     {
         if (chunk.TryGetVoxel(position - chunk.Offset,
                               out var voxel, false))
         {
             var voxelBlock = Blocks.GetBlock(voxel.BlockKey);
             return(voxelBlock.Properties.Type ==
                    BlockColliderType.Solid);
         }
         else
         {
             return(false);
         }
     }