diff --git a/src/Chunk.cpp b/src/Chunk.cpp new file mode 100644 index 0000000..2e04fe4 --- /dev/null +++ b/src/Chunk.cpp @@ -0,0 +1,27 @@ +#include "Chunk.h" + +Chunk::Chunk(FastNoise::SmartNode<> &noiseGenerator, TerrainInfo ti) { + this->fnGenerator = &noiseGenerator; + // Create location to store noise values. + std::vector noiseOutput((ti.xRange[1] - ti.xRange[0]) * + (ti.yRange[1] - ti.yRange[0]) * + (ti.zRange[1] - ti.zRange[0])); + + // Generate noise to the outputs dimentions + noiseGenerator->GenUniformGrid3D( + noiseOutput.data(), ti.xRange[0], ti.yRange[0], ti.zRange[0], + ti.xRange[1] - ti.xRange[0], ti.yRange[1] - ti.yRange[0], + ti.zRange[1] - ti.zRange[0], ti.frequency, ti.seed); + + // do stuff with values + int index = 0; + for (int z = 0; z < 16; z++) { + for (int y = 0; y < 16; y++) { + for (int x = 0; x < 16; x++) { + error.log(std::to_string(x) + " " + std::to_string(y) + " " + + std::to_string(z) + ": " + + std::to_string(noiseOutput[index++])); + } + } + } +} diff --git a/src/Chunk.h b/src/Chunk.h new file mode 100644 index 0000000..8d467b6 --- /dev/null +++ b/src/Chunk.h @@ -0,0 +1,23 @@ +#pragma once +#include "Error.h" +#include +#include + +struct TerrainInfo { + int xRange[2]; + int yRange[2]; + int zRange[2]; + float frequency; + int seed; +}; + +class Chunk { +private: + Error error = Error("Chunk"); + + // Favourite noise generated values using the NoiseTool for now: + FastNoise::SmartNode<> *fnGenerator; + +public: + Chunk(FastNoise::SmartNode<> &noiseGenerator, TerrainInfo ti); +}; diff --git a/src/Terrain.cpp b/src/Terrain.cpp index 7e7df64..32a6294 100644 --- a/src/Terrain.cpp +++ b/src/Terrain.cpp @@ -1,21 +1,15 @@ #include "Terrain.h" Terrain::Terrain() { - // Create location to store noise values. - std::vector noiseOutput(16 * 16 * 16); + TerrainInfo ti; + ti.xRange[0] = 0; + ti.xRange[1] = 16; + ti.yRange[0] = 0; + ti.yRange[1] = 16; + ti.zRange[0] = 0; + ti.zRange[1] = 16; + ti.frequency = 0.2f; + ti.seed = 0; - // Generate noise to the outputs dimentions - this->fnGenerator->GenUniformGrid3D(noiseOutput.data(), 0, 0, 0, 16, 16, 16, - 0.2f, 0); - - int index = 0; - for (int z = 0; z < 16; z++) { - for (int y = 0; y < 16; y++) { - for (int x = 0; x < 16; x++) { - error.log(std::to_string(x) + " " + std::to_string(y) + " " + - std::to_string(z) + ": " + - std::to_string(noiseOutput[index++])); - } - } - } + chunks.push_back(Chunk(fnGenerator, ti)); } diff --git a/src/Terrain.h b/src/Terrain.h index cd676db..183b600 100644 --- a/src/Terrain.h +++ b/src/Terrain.h @@ -1,4 +1,5 @@ #pragma once +#include "Chunk.h" #include "Error.h" #include #include @@ -11,6 +12,9 @@ private: FastNoise::SmartNode<> fnGenerator = FastNoise::NewFromEncodedNodeTree( "DgAIAAAAAAAAQBkAAwAAAIA/AQcAAAAAAD8AAAAAAAAAAABA"); + // Currently used chunks + std::vector chunks; + public: Terrain(); };