This commit is contained in:
adman
2026-07-05 10:49:45 +02:00
parent a8b090227b
commit eab050e291
5 changed files with 38 additions and 25 deletions
+26 -18
View File
@@ -26,14 +26,16 @@ var NoiseParamMap = map[NoiseParam]NoiseParamMapV{
NoiseParamWeirdness: {A: []float64{1, 2, 1, 0, 0, 0}, S: "minecraft:ridge", O: -7},
}
func InitClimateSeed(n NoiseParam, x Xoroshiro, large bool, nmax int) DoublePerlin {
func initClimateSeed(n NoiseParam, x Xoroshiro, large bool, nmax int) DoublePerlin {
v := NoiseParamMap[n]
s := v.S
omin := v.O
if large && n != NoiseParamShift && n != NoiseParamWeirdness {
s += "_large"
omin -= 2
}
x.XorString(s) // SLOW potential
return DoublePerlinFromXoroshiro(x, v.A, v.O, len(v.A), nmax)
x.XorString(s)
return DoublePerlinFromXoroshiro(&x, v.A, omin, len(v.A), nmax)
}
type BiomeNoise struct {
@@ -43,28 +45,34 @@ type BiomeNoise struct {
func BiomeNoiseFromXoroshiro(x Xoroshiro, large bool) (v BiomeNoise) {
x = x.Split()
v.Temperature = InitClimateSeed(NoiseParamTemperature, x, large, -1)
v.Humidity = InitClimateSeed(NoiseParamHumidity, x, large, -1)
v.ContinentalNess = InitClimateSeed(NoiseParamContinentalNess, x, large, -1)
v.Erosion = InitClimateSeed(NoiseParamErosion, x, large, -1)
v.Shift = InitClimateSeed(NoiseParamShift, x, large, -1)
v.Weirdness = InitClimateSeed(NoiseParamWeirdness, x, large, -1)
v.Temperature = initClimateSeed(NoiseParamTemperature, x, large, -1)
v.Humidity = initClimateSeed(NoiseParamHumidity, x, large, -1)
v.ContinentalNess = initClimateSeed(NoiseParamContinentalNess, x, large, -1)
v.Erosion = initClimateSeed(NoiseParamErosion, x, large, -1)
v.Shift = initClimateSeed(NoiseParamShift, x, large, -1)
v.Weirdness = initClimateSeed(NoiseParamWeirdness, x, large, -1)
return
}
func (b BiomeNoise) Sample(x, y, z int) {
func (b BiomeNoise) Sample(x, y, z int) (t, h, c, e, d, w float64, combinedData [6]int64, id int) {
px := float64(x)
pz := float64(z)
px += b.Shift.Sample(px, 0, pz) * 4
pz += b.Shift.Sample(pz, float64(x), 0) * 4
c := b.ContinentalNess.Sample(px, 0, pz)
e := b.Erosion.Sample(px, 0, pz)
w := b.Weirdness.Sample(px, 0, pz)
t := b.Temperature.Sample(px, 0, pz)
h := b.Humidity.Sample(px, 0, pz)
c = b.ContinentalNess.Sample(px, 0, pz)
e = b.Erosion.Sample(px, 0, pz)
w = b.Weirdness.Sample(px, 0, pz)
t = b.Temperature.Sample(px, 0, pz)
h = b.Humidity.Sample(px, 0, pz)
d := float64(0) // FIXME
var combinedData = [6]int64{int64(t * 10000), int64(h * 10000), int64(c * 10000), int64(e * 10000), int64(d * 10000), int64(w * 10000)}
_ = combinedData
combinedData = [6]int64{
int64(float32(t) * 10000.0),
int64(float32(h) * 10000.0),
int64(float32(c) * 10000.0),
int64(float32(e) * 10000.0),
int64(float32(d) * 10000.0),
int64(float32(w) * 10000.0),
}
return
}
+4 -4
View File
@@ -6,7 +6,7 @@ type DoublePerlin struct {
B Octave
}
func DoublePerlinFromXoroshiro(x Xoroshiro, amplitudes []float64, omin int, lenn int, nmax int) (d DoublePerlin) {
func DoublePerlinFromXoroshiro(x *Xoroshiro, amplitudes []float64, omin int, lenn int, nmax int) (d DoublePerlin) {
na := -1
nb := -1
if nmax > 0 {
@@ -22,9 +22,9 @@ func DoublePerlinFromXoroshiro(x Xoroshiro, amplitudes []float64, omin int, lenn
for i := 0; amplitudes[i] == 0.0; i++ {
lenn--
}
var ampInits = []float64{ // (5 ./ 3) * len / (len + 1), len = 2..16
0, 5 / 6, 10 / 9, 15 / 12, 20 / 15, 25 / 18, 30 / 21, 35 / 24, 40 / 27, 45 / 30,
50 / 33, 55 / 36, 60 / 39, 65 / 42, 70 / 45, 75 / 48, 80 / 51,
var ampInits = []float64{
0, 5. / 6, 10. / 9, 15. / 12, 20. / 15, 25. / 18, 30. / 21, 35. / 24, 40. / 27, 45. / 30,
50. / 33, 55. / 36, 60. / 39, 65. / 42, 70. / 45, 75. / 48, 80. / 51,
}
d.Amplitude = ampInits[lenn]
return
+1 -1
View File
@@ -127,7 +127,7 @@ func PerlinNoiseFromXoroshiro(x Xoroshiro) (p PerlinNoise) {
p.d[i] = p.d[j]
p.d[j] = n
}
p.d[256] = 0
p.d[256] = p.d[0]
i2 := math.Floor(p.yoffset)
d2 := p.yoffset - i2
p.h2 = uint8(int(i2))
+1 -1
View File
@@ -28,7 +28,7 @@ var octaveLacunaInits = []float64{1, .5, .25, 1. / 8, 1. / 16, 1. / 32, 1. / 64,
var octavePersistInits = []float64{0, 1, 2. / 3, 4. / 7, 8. / 15, 16. / 31, 32. / 63, 64. / 127, 128. / 255, 256. / 511, 512. / 1023,
1024. / 2047, 2048. / 4095, 4096. / 8191, 8192. / 16383, 16384. / 32767, 32768. / 65535}
func OctaveFromXoroshiro(x Xoroshiro, amplitudes []float64, omin int, lenn int, nmax int) (o Octave) {
func OctaveFromXoroshiro(x *Xoroshiro, amplitudes []float64, omin int, lenn int, nmax int) (o Octave) {
if (-omin < 0 || -omin >= len(octaveLacunaInits)) || (lenn < 0 || lenn >= len(octavePersistInits)) {
panic("octave initialization out of range")
}
+6 -1
View File
@@ -36,5 +36,10 @@ func TestBiome(t *testing.T) {
x := XoroshiroFromSeed(worldSeed)
x.Mix()
b := BiomeNoiseFromXoroshiro(x, false)
b.Sample(-1, -16, 0)
_, _, _, _, _, _, combinedData, _ := b.Sample(-1, -16, 0)
expected := [6]int64{3238, 3521, 2364, 1396, 0, 2202}
if combinedData != expected {
t.Errorf("combinedData = %v, want %v", combinedData, expected)
}
}