split split mix sixty four

This commit is contained in:
2024-09-01 02:09:49 +10:00
parent c99155fb47
commit 1f74b79ea2
6 changed files with 62 additions and 60 deletions

View File

@ -3,13 +3,11 @@ struct WorldGenerator {
public mutating func reset(seed: UInt64) {
var random: any RandomProvider
let initialState = SplitMix64.createState(seed: seed)
#if true
random = Xoroshiro128PlusPlus(seed: seed)
random = Xoroshiro128PlusPlus(state: initialState)
#else
//TODO: Fill seed with a hash
random = PCG32Random(state: (
UInt64(Arc4Random.instance.next()) | UInt64(Arc4Random.instance.next()) << 32,
UInt64(Arc4Random.instance.next()) | UInt64(Arc4Random.instance.next()) << 32))
random = PCG32Random(seed: initialState)
#endif
self.noise = ImprovedPerlin<Float>(random: &random)
@ -38,3 +36,11 @@ struct WorldGenerator {
return chunk
}
}
fileprivate 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
}
}