summaryrefslogtreecommitdiff
path: root/src/procgen.cpp
diff options
context:
space:
mode:
authorPaweł Redman <pawel.redman@gmail.com>2017-10-17 16:39:13 +0200
committerPaweł Redman <pawel.redman@gmail.com>2017-10-17 16:39:13 +0200
commitf66cf28c8b4d80122896c87dba8af74ea1872eba (patch)
tree6d84c736463a3c210ba3791dc074df8565eb6559 /src/procgen.cpp
parent672180b2ee3ed9b9ff984538a85e6eaf2e1c91bc (diff)
New vectors. Start refactoring to use it.
Diffstat (limited to 'src/procgen.cpp')
-rw-r--r--src/procgen.cpp15
1 files changed, 7 insertions, 8 deletions
diff --git a/src/procgen.cpp b/src/procgen.cpp
index b5e1d6f..bfff2c4 100644
--- a/src/procgen.cpp
+++ b/src/procgen.cpp
@@ -35,7 +35,7 @@ void prng_t::unit_vec(float out[2])
void perlin_noise_t::generate(prng_t *prng, size_t size_)
{
if (table)
- delete table;
+ delete[] table;
size = size_;
table = new float[size * size][2];
@@ -55,22 +55,21 @@ static float smooth_step(float x)
return 3 * x * x - 2 * x * x * x;
}
-float perlin_noise_t::get(float x, float y, float scale)
+float perlin_noise_t::get(v2f_t x, float scale)
{
size_t nx, ny, nx1, ny1;
float s, t, a, b, c, d;
x /= scale;
- y /= scale;
- nx = (ssize_t)floor(x) & (size - 1);
- ny = (ssize_t)floor(y) & (size - 1);
+ nx = (ssize_t)floor(x[0]) & (size - 1);
+ ny = (ssize_t)floor(x[1]) & (size - 1);
nx1 = (nx == size - 1 ? 0 : nx + 1);
ny1 = (ny == size - 1 ? 0 : ny + 1);
- s = smooth_step(x - floor(x));
- t = smooth_step(y - floor(y));
+ s = smooth_step(x[0] - floor(x[0]));
+ t = smooth_step(x[1] - floor(x[1]));
a = table_dot(nx, ny, -s, -t);
b = table_dot(nx1, ny, -s + 1.0f, -t);
@@ -82,7 +81,7 @@ float perlin_noise_t::get(float x, float y, float scale)
perlin_noise_t::~perlin_noise_t()
{
- delete table;
+ delete[] table;
}
} // namespace procgen