diff --git a/include/Cubed/gameplay/biome.hpp b/include/Cubed/gameplay/biome.hpp index 8837347..4fe8f21 100644 --- a/include/Cubed/gameplay/biome.hpp +++ b/include/Cubed/gameplay/biome.hpp @@ -5,7 +5,7 @@ namespace Cubed { -constexpr float BIOME_NOISE_FREQUENCY = 0.003f; +constexpr float BIOME_NOISE_FREQUENCY = 0.03f; constexpr float PLAIN_FREQ = 0.4f; constexpr float FOREST_FREQ = 1.2f; diff --git a/include/Cubed/gameplay/chunk.hpp b/include/Cubed/gameplay/chunk.hpp index 3fb2f7a..9e5aef4 100644 --- a/include/Cubed/gameplay/chunk.hpp +++ b/include/Cubed/gameplay/chunk.hpp @@ -47,9 +47,6 @@ private: void clear_dirty(); - void resolve_biome(); - void resolve_blocks(); - public: Chunk(World& world, ChunkPos chunk_pos); ~Chunk(); @@ -64,7 +61,7 @@ public: HeightMapArray get_heightmap() const; static int get_index(int x, int y, int z); static int get_index(const glm::vec3& pos); - void init_chunk(); + // Init Chunk // Generate Biome void gen_phase_one(); // Adjust Biome diff --git a/src/gameplay/chunk.cpp b/src/gameplay/chunk.cpp index 9e6e225..4dfc3d4 100644 --- a/src/gameplay/chunk.cpp +++ b/src/gameplay/chunk.cpp @@ -212,13 +212,13 @@ size_t Chunk::get_vertex_sum() const { return m_vertex_sum.load(); } -void Chunk::init_chunk() { - resolve_biome(); - resolve_blocks(); -} void Chunk::gen_phase_one() { - resolve_biome(); + float x = static_cast(m_chunk_pos.x); + float z = static_cast(m_chunk_pos.z); + float temp = PerlinNoise::noise(x * BIOME_NOISE_FREQUENCY, 0.0f, z * BIOME_NOISE_FREQUENCY); + float humid = PerlinNoise::noise(x * BIOME_NOISE_FREQUENCY, 1.0f, z * BIOME_NOISE_FREQUENCY); + m_biome = get_biome_from_noise(temp, humid); } void Chunk::gen_phase_two(const std::array& adj_chunks) { @@ -438,91 +438,4 @@ void Chunk::set_chunk_block(int index ,unsigned id) { mark_dirty(); } - -void Chunk::resolve_biome() { - float cx = (m_chunk_pos.x + 0.5f) * CHUCK_SIZE; - float cz = (m_chunk_pos.z + 0.5f) * CHUCK_SIZE; - float temp = PerlinNoise::noise(cx * BIOME_NOISE_FREQUENCY, 0.0f, cz * BIOME_NOISE_FREQUENCY); - float humid = PerlinNoise::noise(cx * BIOME_NOISE_FREQUENCY, 1.0f, cz * BIOME_NOISE_FREQUENCY); - m_biome = get_biome_from_noise(temp, humid); -} - -void Chunk::resolve_blocks() { - m_blocks.assign(CHUCK_SIZE * CHUCK_SIZE * WORLD_SIZE_Y, 0); - for (int x = 0; x < CHUCK_SIZE; x++) { - for (int y = 0; y < 5; y++) { - for (int z = 0; z < CHUCK_SIZE; z++) { - m_blocks[get_index(x, y, z)] = 3; - } - } - } - std::array, SIZE_X> heights; - for (int x = 0; x < CHUCK_SIZE; x++) { - for (int z = 0; z < CHUCK_SIZE; z++) { - - float world_x = static_cast(x + m_chunk_pos.x * CHUCK_SIZE); - float world_z = static_cast(z + m_chunk_pos.z * CHUCK_SIZE); - - float temp = PerlinNoise::noise(world_x * BIOME_NOISE_FREQUENCY, 0.0f, world_z * BIOME_NOISE_FREQUENCY); - float humid = PerlinNoise::noise(world_x * BIOME_NOISE_FREQUENCY, 1.0f, world_z * BIOME_NOISE_FREQUENCY); - int height = get_interpolated_height(world_x, world_z, temp, humid); - - auto biome = get_biome_from_noise(temp, humid); - if (height >= SIZE_Y) { - Logger::warn("height: {} is exceed max_height", height); - height = SIZE_Y - 1; - } - heights[x][z] = height; - for (int y = 5; y < height - 5; y++) { - m_blocks[get_index(x, y, z)] = 3; - } - if (biome == Biome::MOUNTAIN) { - for (int y = height - 5; y <= height - 1; y++) { - if (y > 101) { - m_blocks[get_index(x, y, z)] = 3; - } else { - m_blocks[get_index(x, y, z)] = 2; - } - - } - if (height > 101) { - m_blocks[get_index(x, height - 1, z)] = 3; - } else { - m_blocks[get_index(x, height - 1, z)] = 1; - } - } else if (biome == Biome::DESERT) { - for (int y = height - 5; y <= height; y++) { - m_blocks[get_index(x, y, z)] = 4; - } - } else { - for (int y = height - 5; y <= height - 1; y++) { - m_blocks[get_index(x, y, z)] = 2; - } - for (int y = height; y <= height; y++) { - m_blocks[get_index(x, y, z)] = 1; - } - } - - } - } - if (m_biome == Biome::FOREST) { - std::array x_arr; - std::iota(x_arr.begin(), x_arr.end(), 0); - std::shuffle(x_arr.begin(), x_arr.end(), Cubed::Random::get().engine()); - std::array z_arr; - std::iota(z_arr.begin(), z_arr.end(), 0); - std::shuffle(z_arr.begin(), z_arr.end(), Cubed::Random::get().engine()); - for (auto x : x_arr) { - for (auto z : z_arr) { - if (Cubed::Random::get().random_bool(0.8)) { - build_tree(*this, {x, heights[x][z], z}); - } - - } - } - } - - mark_dirty(); -} - }