package terrain import "sync" import "github.com/larspensjo/Go-simplex-noise/simplexnoise" import "github.com/CasualSuperman/dfc/items" const chunk_horiz_dim = 64 const chunk_vert_dim = 128 type chunk struct { // Temperature is at a slightly lower res than discrete tiles are. temperature [chunk_horiz_dim / 4][chunk_horiz_dim / 4][chunk_vert_dim / 4]items.Temperature fluids [chunk_horiz_dim][chunk_horiz_dim][chunk_vert_dim]Fluid tickCount uint8 } type Chunk interface { Tick(*sync.WaitGroup) } var _ = simplexnoise.Noise1(0)
func DoTestSimplexNoise() { var min, max float64 min, max = 1, -1 const iter = 1e7 var sum float64 for i := 0; i < iter; i++ { switch rnd := simplexnoise.Noise1(float64(i) * 1.827231321); { case rnd < min: min = rnd sum += rnd case rnd > max: max = rnd sum += rnd default: sum += rnd } } // fmt.Printf("DoTestSimplexNoise simplexnoise.Noise1 min %v, max %v, average %v\n", min, max, sum/iter) DoTestCheck("DoTestSimplexNoise simplexnoise.Noise1 min=-1.0", math.Abs(min+1) < 1e-3) DoTestCheck("DoTestSimplexNoise simplexnoise.Noise1 max=1.0", math.Abs(max-1) < 1e-3) DoTestCheck("DoTestSimplexNoise simplexnoise.Noise1 average=0.0", math.Abs(sum/iter) < 0.04) // Not very good, off by more than 3% min, max = 1, -1 sum = 0 for i := 0; i < iter; i++ { switch rnd := simplexnoise.Noise2(float64(i)*1.827411321, float64(i)*7.12312781); { case rnd < min: min = rnd sum += rnd case rnd > max: max = rnd sum += rnd default: sum += rnd } } // fmt.Printf("DoTestSimplexNoise simplexnoise.Noise2 min %v, max %v, average %v\n", min, max, sum/iter) DoTestCheck("DoTestSimplexNoise simplexnoise.Noise2 min=-1.0", math.Abs(min+1) < 1e-3) DoTestCheck("DoTestSimplexNoise simplexnoise.Noise2 max=1.0", math.Abs(max-1) < 1e-3) DoTestCheck("DoTestSimplexNoise simplexnoise.Noise2 average=0.0", math.Abs(sum/iter) < 1e-4) min, max = 1, -1 sum = 0 for i := 0; i < iter; i++ { switch rnd := simplexnoise.Noise3(float64(i)*1.827131321, float64(i)*7.12372381, float64(i)*4.923716223); { case rnd < min: min = rnd sum += rnd case rnd > max: max = rnd sum += rnd default: sum += rnd } } // fmt.Printf("DoTestSimplexNoise simplexnoise.Noise3 min %v, max %v, average %v\n", min, max, sum/iter) DoTestCheck("DoTestSimplexNoise simplexnoise.Noise3 min=-1.0", math.Abs(min+1) < 1e-3) DoTestCheck("DoTestSimplexNoise simplexnoise.Noise3 max=1.0", math.Abs(max-1) < 1e-3) DoTestCheck("DoTestSimplexNoise simplexnoise.Noise3 average=0.0", math.Abs(sum/iter) < 1e-4) }