mirror of
				https://github.com/GayPizzaSpecifications/voxelotl-engine.git
				synced 2025-11-03 18:49:38 +00:00 
			
		
		
		
	tower world gen
This commit is contained in:
		
							
								
								
									
										38
									
								
								Sources/Voxelotl/Generator/StandardWorldGenerator.swift
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										38
									
								
								Sources/Voxelotl/Generator/StandardWorldGenerator.swift
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,38 @@
 | 
			
		||||
struct StandardWorldGenerator: WorldGenerator {
 | 
			
		||||
  var noise: ImprovedPerlin<Float>!, noise2: SimplexNoise<Float>!
 | 
			
		||||
 | 
			
		||||
  public mutating func reset(seed: UInt64) {
 | 
			
		||||
    var random: any RandomProvider
 | 
			
		||||
    let initialState = SplitMix64.createState(seed: seed)
 | 
			
		||||
#if true
 | 
			
		||||
    random = Xoroshiro128PlusPlus(state: initialState)
 | 
			
		||||
#else
 | 
			
		||||
    random = PCG32Random(seed: initialState)
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
    self.noise = ImprovedPerlin<Float>(random: &random)
 | 
			
		||||
    self.noise2 = SimplexNoise<Float>(random: &random)
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  public func makeChunk(id chunkID: SIMD3<Int>) -> Chunk {
 | 
			
		||||
    let chunkOrigin = chunkID &<< Chunk.shift
 | 
			
		||||
    var chunk = Chunk(position: chunkOrigin)
 | 
			
		||||
    chunk.fill(allBy: { position in
 | 
			
		||||
      let fpos = SIMD3<Float>(position)
 | 
			
		||||
        let threshold: Float = 0.6
 | 
			
		||||
        let value = fpos.y / 16.0
 | 
			
		||||
          + self.noise.get(fpos * 0.05) * 1.1
 | 
			
		||||
          + self.noise.get(fpos * 0.10) * 0.5
 | 
			
		||||
          + self.noise.get(fpos * 0.30) * 0.23
 | 
			
		||||
      return if value < threshold {
 | 
			
		||||
        .solid(.init(
 | 
			
		||||
          hue:        Float(180 + self.noise2.get(fpos * 0.05) * 180),
 | 
			
		||||
          saturation: Float(0.5 + self.noise2.get(SIMD4(fpos * 0.05, 4)) * 0.5),
 | 
			
		||||
          value:      Float(0.5 + self.noise2.get(SIMD4(fpos * 0.05, 9)) * 0.5).lerp(0.5, 1)).linear)
 | 
			
		||||
      } else {
 | 
			
		||||
        .air
 | 
			
		||||
      }
 | 
			
		||||
    })
 | 
			
		||||
    return chunk
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										33
									
								
								Sources/Voxelotl/Generator/TerrorTowerGenerator.swift
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										33
									
								
								Sources/Voxelotl/Generator/TerrorTowerGenerator.swift
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,33 @@
 | 
			
		||||
import simd
 | 
			
		||||
 | 
			
		||||
struct TerrorTowerGenerator: WorldGenerator {
 | 
			
		||||
  var noise1: LayeredNoise<ImprovedPerlin<Float>>!
 | 
			
		||||
  var noise2: LayeredNoise<SimplexNoise<Float>>!
 | 
			
		||||
 | 
			
		||||
  public mutating func reset(seed: UInt64) {
 | 
			
		||||
    var random = Xoroshiro128PlusPlus(state: SplitMix64.createState(seed: seed))
 | 
			
		||||
    self.noise1 = LayeredNoise(random: &random, octaves: 4, frequency: 0.05, amplitude: 1.1)
 | 
			
		||||
    self.noise2 = LayeredNoise(random: &random, octaves: 3, frequency: 0.1, amplitude: 0.5)
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  public func makeChunk(id chunkID: SIMD3<Int>) -> Chunk {
 | 
			
		||||
    let chunkOrigin = chunkID &<< Chunk.shift
 | 
			
		||||
    var chunk = Chunk(position: chunkOrigin)
 | 
			
		||||
    chunk.fill(allBy: { position in
 | 
			
		||||
      let fpos = SIMD3<Float>(position)
 | 
			
		||||
        let threshold: Float = 0.6
 | 
			
		||||
        let gradient = simd_length(fpos.xz) / 14.0
 | 
			
		||||
        let value = self.noise1.get(fpos) - 0.25
 | 
			
		||||
      return if gradient + value < threshold {
 | 
			
		||||
        .solid(.init(
 | 
			
		||||
          hue: ((fpos.x * 0.5 + fpos.y) / 30.0) * 360.0,
 | 
			
		||||
          saturation: 0.2 + noise2.get(fpos) * 0.2,
 | 
			
		||||
          value: 0.75 + noise2.get(SIMD4(fpos, 1) * 0.25)
 | 
			
		||||
        ).linear)
 | 
			
		||||
      } else {
 | 
			
		||||
        .air
 | 
			
		||||
      }
 | 
			
		||||
    })
 | 
			
		||||
    return chunk
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										12
									
								
								Sources/Voxelotl/Generator/WorldGenerator.swift
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										12
									
								
								Sources/Voxelotl/Generator/WorldGenerator.swift
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,12 @@
 | 
			
		||||
protocol WorldGenerator {
 | 
			
		||||
  mutating func reset(seed: UInt64)
 | 
			
		||||
  func makeChunk(id: SIMD3<Int>) -> Chunk
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
internal extension RandomProvider where Output == UInt64, Self: RandomSeedable, SeedType == UInt64 {
 | 
			
		||||
  static func createState(seed value: UInt64) -> (UInt64, UInt64) {
 | 
			
		||||
    var hash = Self(seed: value)
 | 
			
		||||
    let state = (hash.next(), hash.next())
 | 
			
		||||
    return state
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
		Reference in New Issue
	
	Block a user