diff --git a/src/game.cpp b/src/game.cpp index 5f9610c..332418f 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -84,7 +84,7 @@ void Game::Setup(int w, int h) { m_cameras["Default"] = std::make_shared(w, h); m_activeCamera = m_cameras["Default"]; - m_activeCamera->Position = { 0, 64, 0 }; + m_activeCamera->Position = { 0, 70, 0 }; m_activeCamera->UpdateView(); std::shared_ptr BlockDictionary = CBlockDictionary::GetInstance(); diff --git a/src/world/chunk/chunk.cpp b/src/world/chunk/chunk.cpp index 09b28c3..8284e0d 100644 --- a/src/world/chunk/chunk.cpp +++ b/src/world/chunk/chunk.cpp @@ -37,20 +37,71 @@ Chunk::Chunk(int x, int z, std::vector voxels) { Chunk::Chunk(int x, int z, std::shared_ptr terrainGenerator) { X = x, Z = z; + int y; for (x = 0; x < CHUNK_WIDTH; x++) - for (int y = 0; y < CHUNK_HEIGHT; y++) + for (y = 0; y < CHUNK_HEIGHT; y++) for (z = 0; z < CHUNK_DEPTH; z++) { - if (pow(y / (float)CHUNK_HEIGHT, 1.1024f) + terrainGenerator->GetValueFractal(x + (Z * CHUNK_WIDTH), y, z + (X * CHUNK_DEPTH)) * 0.60f < 0.3f) { + if (y == 0) { + Voxels.push_back((uint8_t)EBlockType::Bedrock); + continue; + } + + if (y == 1 && (float)rand() / (float)RAND_MAX > 0.5f) { + Voxels.push_back((uint8_t)EBlockType::Bedrock); + continue; + } + + if (pow(y / (float)CHUNK_HEIGHT, 1.1024f) + terrainGenerator->GetValueFractal(x + (Z * CHUNK_WIDTH), y, z + (X * CHUNK_DEPTH)) * 0.60f < 0.5f) { Voxels.push_back((uint8_t)EBlockType::Grass); - - } else { - - Voxels.push_back((uint8_t)EBlockType::Air); - + continue; + } + + Voxels.push_back((uint8_t)EBlockType::Air); + + } + + for (x = 0; x < CHUNK_WIDTH; x++) + for (y = 0; y < CHUNK_HEIGHT; y++) + for (z = 0; z < CHUNK_DEPTH; z++) { + + if (BlockAt(x, y, z) == EBlockType::Bedrock) + continue; + + // No need for bounds checking as a closed loop + if (BlockAt(x, y + 1, z) == EBlockType::Grass) + Voxels[x + CHUNK_WIDTH * (y + CHUNK_HEIGHT * z)] = EBlockType::Dirt; + + } + + // Add stone 3 layers below dirt + for (x = 0; x < CHUNK_WIDTH; x++) + for (y = 0; y < CHUNK_HEIGHT; y++) + for (z = 0; z < CHUNK_DEPTH; z++) { + + if (BlockAt(x, y, z) == EBlockType::Bedrock) + continue; + + if (BlockAt(x, y + 1, z) == EBlockType::Dirt) + if (BlockAt(x, y + 2, z) == EBlockType::Dirt) + // if (BlockAt(x, y + 3, z) == EBlockType::Dirt) + Voxels[x + CHUNK_WIDTH * (y + CHUNK_HEIGHT * z)] = EBlockType::Stone; + + } + + // Add the rest of the stone + for (x = 0; x < CHUNK_WIDTH; x++) + for (y = 0; y < CHUNK_HEIGHT; y++) + for (z = 0; z < CHUNK_DEPTH; z++) { + + if (BlockAt(x, y, z) == EBlockType::Bedrock) + continue; + + if (BlockAt(x, y + 1, z) == EBlockType::Stone) + Voxels[x + CHUNK_WIDTH * (y + CHUNK_HEIGHT * z)] = EBlockType::Stone; } diff --git a/src/world/world.cpp b/src/world/world.cpp index f3519c5..cf5a755 100644 --- a/src/world/world.cpp +++ b/src/world/world.cpp @@ -17,12 +17,14 @@ void World::LoadWorld() { m_shaders["Basic"]->Load(GameConfig.ResourceBase + "shaders/simple"); m_shaders["Basic"]->Link(); + srand(time(NULL)); + m_noiseGenerator = std::make_shared(); m_noiseGenerator->SetSeed(rand()); m_noiseGenerator->SetNoiseType(FastNoise::SimplexFractal); - m_noiseGenerator->SetFractalOctaves(3); + m_noiseGenerator->SetFractalOctaves(5); for (int x = -4; x < 10; x++) for (int y = -4; y < 4; y++) { @@ -31,7 +33,7 @@ void World::LoadWorld() { } - // + // Spawn generator threads for (int i = 0; i < 7; i++) { m_generatorThreads.push_back(std::thread([&]() {