diff options
author | Samuel Bronson <naesten@gmail.com> | 2013-03-04 18:17:30 -0500 |
---|---|---|
committer | Samuel Bronson <naesten@gmail.com> | 2013-03-04 18:17:30 -0500 |
commit | e213781413358fef60753736cda92e30a652e67e (patch) | |
tree | c9016b2188d14ebf7cc50756811b16679f5d753b /crawl-ref/source/perlin.cc | |
parent | 3f51693d96c2f3feb76a564ad1d85c4da8f32445 (diff) | |
download | crawl-ref-e213781413358fef60753736cda92e30a652e67e.tar.gz crawl-ref-e213781413358fef60753736cda92e30a652e67e.zip |
Widen the domain of perlin::noise to cover at least all of uint32_t.
Diffstat (limited to 'crawl-ref/source/perlin.cc')
-rw-r--r-- | crawl-ref/source/perlin.cc | 25 |
1 files changed, 14 insertions, 11 deletions
diff --git a/crawl-ref/source/perlin.cc b/crawl-ref/source/perlin.cc index 54d1b254c9..99bb046468 100644 --- a/crawl-ref/source/perlin.cc +++ b/crawl-ref/source/perlin.cc @@ -100,8 +100,11 @@ namespace perlin const double F4 = (sqrt(5.0)-1.0)/4.0; const double G4 = (5.0-sqrt(5.0))/20.0; - static int fastfloor(const double x) { - int xi = (int)x; + // Use long long so that noise() can work sensibly for + // coordinates from the full range of uint32_t; otherwise scaling, + // signedness, and skew will give us considerably less than that. + static long long fastfloor(const double x) { + long long xi = (long long)x; return x<xi ? xi-1 : xi; } @@ -121,8 +124,8 @@ namespace perlin double n0, n1, n2; // Noise contributions from the three corners // Skew the input space to determine which simplex cell we're in double s = (xin+yin)*F2; // Hairy factor for 2D - int i = fastfloor(xin+s); - int j = fastfloor(yin+s); + long long i = fastfloor(xin+s); + long long j = fastfloor(yin+s); double t = (i+j)*G2; double X0 = i-t; // Unskew the cell origin back to (x,y) space double Y0 = j-t; @@ -175,9 +178,9 @@ namespace perlin double n0, n1, n2, n3; // Noise contributions from the four corners // Skew the input space to determine which simplex cell we're in double s = (xin+yin+zin)*F3; // Very nice and simple skew factor for 3D - int i = fastfloor(xin+s); - int j = fastfloor(yin+s); - int k = fastfloor(zin+s); + long long i = fastfloor(xin+s); + long long j = fastfloor(yin+s); + long long k = fastfloor(zin+s); double t = (i+j+k)*G3; double X0 = i-t; // Unskew the cell origin back to (x,y,z) space double Y0 = j-t; @@ -258,10 +261,10 @@ namespace perlin double n0, n1, n2, n3, n4; // Noise contributions from the five corners // Skew the (x,y,z,w) space to determine which cell of 24 simplices we're in double s = (x + y + z + w) * F4; // Factor for 4D skewing - int i = fastfloor(x + s); - int j = fastfloor(y + s); - int k = fastfloor(z + s); - int l = fastfloor(w + s); + long long i = fastfloor(x + s); + long long j = fastfloor(y + s); + long long k = fastfloor(z + s); + long long l = fastfloor(w + s); double t = (i + j + k + l) * G4; // Factor for 4D unskewing double X0 = i - t; // Unskew the cell origin back to (x,y,z,w) space double Y0 = j - t; |