Terrain Generation

This commit is contained in:
Ben Kyd
2019-11-05 12:39:18 +00:00
parent 259b6e0a0b
commit 573ad69ee4
6 changed files with 72 additions and 20 deletions

View File

@@ -5,6 +5,7 @@
#include "../renderer/shader.hpp"
#include "../config.hpp"
#include "../util/fastnoise.hpp"
World::World() {
@@ -16,13 +17,21 @@ void World::LoadWorld() {
m_shaders["Basic"]->Load(GameConfig.ResourceBase + "shaders/simple");
m_shaders["Basic"]->Link();
for (int x = -4; x < 4; x++)
m_noiseGenerator = std::make_shared<FastNoise>();
m_noiseGenerator->SetSeed(rand());
m_noiseGenerator->SetNoiseType(FastNoise::SimplexFractal);
m_noiseGenerator->SetFractalOctaves(3);
for (int x = -4; x < 10; x++)
for (int y = -4; y < 4; y++) {
m_chunkLoaderQueue.push({ x, y });
}
//
for (int i = 0; i < 7; i++) {
m_generatorThreads.push_back(std::thread([&]() {
@@ -115,7 +124,7 @@ void World::m_loadChunks() {
m_chunkMutex.unlock();
std::shared_ptr<Chunk> loadingChunk = std::make_shared<Chunk>(coords.x, coords.y);
std::shared_ptr<Chunk> loadingChunk = std::make_shared<Chunk>(coords.x, coords.y, m_noiseGenerator);
std::cout << "Loaded chunk " << coords.x << ":" << coords.y << std::endl;
@@ -130,6 +139,7 @@ void World::m_loadChunks() {
while (m_chunkLoaderQueue.empty()) {
if (!m_generatorRunning) break;
static std::chrono::milliseconds dura(1);
std::this_thread::sleep_for(dura);