Ejemplo n.º 1
0
            public void doWork()
            {
                VoxelSource biome           = GetBiomeForChunk(adjustment.chunkID, level.seed);
                int         solidVoxelCount = GenerateTerrainDataForChunk(biome, adjustment.chunkID, out byte[] generatedVoxels);
                Chunk       chunk           = level.getChunk(adjustment.chunkID);

                chunk.setVoxelData(generatedVoxels, solidVoxelCount);
                chunk.unlock((adjustment.resolution, adjustment.type));
            }
Ejemplo n.º 2
0
    /// <summary>
    /// Generate all the voxels for the given chunk id using the provided biome
    /// </summary>
    /// <param name="biome"></param>
    /// <param name="chunkID"></param>
    /// <param name="generatedVoxels"></param>
    /// <returns>the number of solid voxels generated</returns>
    static int GenerateTerrainDataForChunk(VoxelSource biome, Chunk.ID chunkID, out byte[] generatedVoxels) {
      int solidVoxelCount = 0;
      generatedVoxels = null;
      byte[] voxels = new byte[Chunk.Diameter * Chunk.Diameter * Chunk.Diameter];
      Coordinate chunkWorldLocation = chunkID.toWorldLocation();

      chunkWorldLocation.until(chunkWorldLocation + Chunk.Diameter, currentWorldLocation => {
        byte voxelValue = biome.getVoxelValueAt(currentWorldLocation);
        if (voxelValue != Voxel.Types.Empty.Id) {
          solidVoxelCount++;
          Coordinate localChunkVoxelLocation = currentWorldLocation - chunkWorldLocation;
          voxels[localChunkVoxelLocation.flatten(Chunk.Diameter)] = voxelValue;
        }
      });

      generatedVoxels = voxels;
      return solidVoxelCount;
    }
Ejemplo n.º 3
0
 /// <summary>
 /// Get the biome and generate the chunk data for it
 /// </summary>
 public void Execute() {
   VoxelSource biome = GetBiomeForChunk(chunkID, levelSeed);
   solidVoxelCount[0] = GenerateTerrainDataForChunk(biome, chunkID, out byte[] generatedVoxels);
   outVoxels.CopyFrom(generatedVoxels);
 }