Rename Algorithm -> TerrainGenerator
This commit is contained in:
parent
c62ae41fc0
commit
a58241cd13
2 changed files with 7 additions and 7 deletions
|
@ -14,7 +14,7 @@ enum KernelError: Error {
|
||||||
case textureCreationFailed
|
case textureCreationFailed
|
||||||
}
|
}
|
||||||
|
|
||||||
protocol Algorithm {
|
protocol TerrainGenerator {
|
||||||
var name: String { get }
|
var name: String { get }
|
||||||
var outTexture: MTLTexture { get }
|
var outTexture: MTLTexture { get }
|
||||||
|
|
||||||
|
@ -75,7 +75,7 @@ class Kernel {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// "Compute" zero for every value of the height map.
|
/// "Compute" zero for every value of the height map.
|
||||||
class ZeroAlgorithm: Kernel, Algorithm {
|
class ZeroAlgorithm: Kernel, TerrainGenerator {
|
||||||
let name = "Zero"
|
let name = "Zero"
|
||||||
|
|
||||||
init?(device: MTLDevice, library: MTLLibrary) {
|
init?(device: MTLDevice, library: MTLLibrary) {
|
||||||
|
@ -93,7 +93,7 @@ class ZeroAlgorithm: Kernel, Algorithm {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Randomly generate heights that are independent of all others.
|
/// Randomly generate heights that are independent of all others.
|
||||||
class RandomAlgorithm: Kernel, Algorithm {
|
class RandomAlgorithm: Kernel, TerrainGenerator {
|
||||||
let name = "Random"
|
let name = "Random"
|
||||||
|
|
||||||
private var uniforms: UnsafeMutablePointer<RandomAlgorithmUniforms>
|
private var uniforms: UnsafeMutablePointer<RandomAlgorithmUniforms>
|
||||||
|
@ -124,7 +124,7 @@ class RandomAlgorithm: Kernel, Algorithm {
|
||||||
|
|
||||||
/// Implementation of the Diamond-Squares algorithm.
|
/// Implementation of the Diamond-Squares algorithm.
|
||||||
/// - https://en.wikipedia.org/wiki/Diamond-square_algorithm
|
/// - https://en.wikipedia.org/wiki/Diamond-square_algorithm
|
||||||
public class DiamondSquareAlgorithm: Algorithm {
|
public class DiamondSquareAlgorithm: TerrainGenerator {
|
||||||
public struct Box {
|
public struct Box {
|
||||||
public typealias Point = (x: Int, y: Int)
|
public typealias Point = (x: Int, y: Int)
|
||||||
public typealias Size = (w: Int, h: Int)
|
public typealias Size = (w: Int, h: Int)
|
||||||
|
|
|
@ -75,7 +75,7 @@ class Terrain: NSObject {
|
||||||
let vertexDescriptor: MTLVertexDescriptor
|
let vertexDescriptor: MTLVertexDescriptor
|
||||||
let mesh: MTKMesh
|
let mesh: MTKMesh
|
||||||
|
|
||||||
var algorithm: Algorithm
|
var generator: TerrainGenerator
|
||||||
|
|
||||||
init?(dimensions dim: float2, segments seg: uint2, device: MTLDevice, library: MTLLibrary) {
|
init?(dimensions dim: float2, segments seg: uint2, device: MTLDevice, library: MTLLibrary) {
|
||||||
dimensions = dim
|
dimensions = dim
|
||||||
|
@ -89,11 +89,11 @@ class Terrain: NSObject {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
guard let alg = RandomAlgorithm(device: device, library: library) else {
|
guard let gen = RandomAlgorithm(device: device, library: library) else {
|
||||||
print("Couldn't create algorithm")
|
print("Couldn't create algorithm")
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
algorithm = alg
|
generator = gen
|
||||||
|
|
||||||
super.init()
|
super.init()
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue