示例#1
0
 public void Execute(ref ChunkMap chunkMap, ref Chunk chunk) //Entity entity, int index,
 {
     if (chunkMap.isBiome == 0 && chunkMap.dirty == 1)
     {
         chunkMap.dirty = 2;
         // get all the top voxels
         //int xzIndex = 0;
         for (int i = 0; i < chunk.Value.voxelDimensions.x; i++)
         {
             for (int j = 0; j < chunk.Value.voxelDimensions.z; j++)
             {
                 byte topMostVoxel  = 0;
                 byte highestHeight = 0;
                 int  xzIndex       = i + j * chunkMap.height;
                 for (int k = (int)chunk.Value.voxelDimensions.y - 1; k >= 0; k--)
                 {
                     int xyzIndex = VoxelRaycastSystem.GetVoxelArrayIndex(new int3(i, k, j), chunk.Value.voxelDimensions);
                     if (chunk.Value.voxels[xyzIndex] != 0)
                     {
                         topMostVoxel  = chunk.Value.voxels[xyzIndex];
                         highestHeight = (byte)k;
                         break;
                     }
                 }
                 chunkMap.topVoxels[xzIndex] = topMostVoxel;
                 chunkMap.heights[xzIndex]   = highestHeight;
                 //xzIndex++;
             }
         }
     }
 }
示例#2
0
        private int3 FindNewPosition(ref Chunk chunk)
        {
            //float3 chunkPosition = chunk.Value.chunkPosition;
            var voxelDimensions = chunk.Value.voxelDimensions;
            // int worldID = chunk.worldID;
            // find first y position of value not air
            int  voxelIndex;
            int3 checkVoxelPosition;
            int  randomPositionX = (int)math.floor(UnityEngine.Random.Range(0, voxelDimensions.x - 1));
            int  randomPositionZ = (int)math.floor(UnityEngine.Random.Range(0, voxelDimensions.z - 1));

            for (int j = (int)chunk.Value.voxelDimensions.y - 1; j >= 0; j--)
            {
                // if not air, pick j + 1
                checkVoxelPosition = new int3(randomPositionX, j, randomPositionZ);
                voxelIndex         = VoxelRaycastSystem.GetVoxelArrayIndex(checkVoxelPosition, voxelDimensions);
                if (chunk.Value.voxels[voxelIndex] != 0)
                {
                    int3 newPosition = new int3(checkVoxelPosition.x, j + 1, checkVoxelPosition.z);
                    //return chunk.GetVoxelPosition() + newPosition;
                    return(newPosition);
                }
            }
            Debug.LogError("No solid ground found for character spawning at.");
            return(int3.Zero());
        }
        private byte GetVoxelType(Voxels.World world, WorldBound worldBound, int3 voxelPosition)
        {
            var   chunkPosition = VoxelRaycastSystem.GetChunkPosition(voxelPosition, worldBound.voxelDimensions);
            Chunk chunk;

            if (GetChunk(world, chunkPosition, out chunk) && chunk.Value.voxels.Length > 0)
            {
                if (chunk.isGenerating == 1)
                {
                    return(1);
                }
                int voxelIndex = VoxelRaycastSystem.GetVoxelArrayIndex(voxelPosition - chunk.GetVoxelPosition(), worldBound.voxelDimensions);
                if (voxelIndex >= chunk.Value.voxels.Length)
                {
                    return(1);
                }
                return(chunk.Value.voxels[voxelIndex]);
            }
            return(1);
        }