Offloaded the terrain work into a chunk object so we can manage spaces in chunks in the future.
This commit is contained in:
parent
9fa18286cb
commit
38b1d8c92e
4 changed files with 64 additions and 16 deletions
27
src/Chunk.cpp
Normal file
27
src/Chunk.cpp
Normal file
|
|
@ -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<float> 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++]));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
23
src/Chunk.h
Normal file
23
src/Chunk.h
Normal file
|
|
@ -0,0 +1,23 @@
|
||||||
|
#pragma once
|
||||||
|
#include "Error.h"
|
||||||
|
#include <FastNoise/FastNoise.h>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
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);
|
||||||
|
};
|
||||||
|
|
@ -1,21 +1,15 @@
|
||||||
#include "Terrain.h"
|
#include "Terrain.h"
|
||||||
|
|
||||||
Terrain::Terrain() {
|
Terrain::Terrain() {
|
||||||
// Create location to store noise values.
|
TerrainInfo ti;
|
||||||
std::vector<float> noiseOutput(16 * 16 * 16);
|
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
|
chunks.push_back(Chunk(fnGenerator, ti));
|
||||||
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++]));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,5 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
#include "Chunk.h"
|
||||||
#include "Error.h"
|
#include "Error.h"
|
||||||
#include <FastNoise/FastNoise.h>
|
#include <FastNoise/FastNoise.h>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
@ -11,6 +12,9 @@ private:
|
||||||
FastNoise::SmartNode<> fnGenerator = FastNoise::NewFromEncodedNodeTree(
|
FastNoise::SmartNode<> fnGenerator = FastNoise::NewFromEncodedNodeTree(
|
||||||
"DgAIAAAAAAAAQBkAAwAAAIA/AQcAAAAAAD8AAAAAAAAAAABA");
|
"DgAIAAAAAAAAQBkAAwAAAIA/AQcAAAAAAD8AAAAAAAAAAABA");
|
||||||
|
|
||||||
|
// Currently used chunks
|
||||||
|
std::vector<Chunk> chunks;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
Terrain();
|
Terrain();
|
||||||
};
|
};
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue