feat: add tree generation

This commit is contained in:
2026-04-18 10:59:37 +08:00
parent 63930dcdc7
commit bb888fd7b7
27 changed files with 224 additions and 30 deletions

View File

@@ -6,6 +6,7 @@
#include <Cubed/renderer.hpp>
#include <Cubed/texture_manager.hpp>
#include <Cubed/window.hpp>
namespace Cubed {
class App {
public:
@@ -35,7 +36,6 @@ private:
inline static double fps_time_count = 0.0f;
inline static int frame_count = 0;
inline static int fps = 0;
inline static unsigned int m_seed = 0;
void init();
@@ -46,4 +46,6 @@ private:
void render();
void run();
void update();
};
};
}

View File

@@ -1,6 +1,6 @@
#pragma once
constexpr int WORLD_SIZE_Y = 256;
constexpr int MAX_BLOCK_NUM = 5;
constexpr int MAX_BLOCK_NUM = 7;
constexpr int MAX_UI_NUM = 1;
constexpr int CHUCK_SIZE = 16;

View File

@@ -4,9 +4,9 @@
constexpr float BIOME_NOISE_FREQUENCY = 0.003f;
constexpr float PLAIN_FREQ = 0.5f;
constexpr float FOREST_FREQ = 1.0f;
constexpr float DESERT_FREQ = 1.0f;
constexpr float PLAIN_FREQ = 0.4f;
constexpr float FOREST_FREQ = 1.2f;
constexpr float DESERT_FREQ = 1.2f;
constexpr float MOUNTAIN_FREQ = 2.0f;
enum class Biome {

View File

@@ -47,7 +47,7 @@ public:
const std::vector<uint8_t>& get_chunk_blocks() const;
static int get_index(int x, int y, int z);
static int get_index(const glm::vec3& pos);
void init_chunk();
void gen_vertex_data();
// 0 : (1, 0)

View File

@@ -0,0 +1,12 @@
#pragma once
#include <glm/glm.hpp>
class Chunk;
struct TreeStructNode {
glm::ivec3 offset{0, 0, 0};
unsigned id = 0;
};
bool build_tree(Chunk& chunk, const glm::ivec3& pos);

View File

@@ -0,0 +1,21 @@
#pragma once
#include <random>
namespace Cubed {
class Random {
public:
Random();
static Random& get();
bool random_bool(double probability);
std::mt19937& engine();
unsigned seed();
private:
unsigned int m_seed = 0;
std::mt19937 m_engine;
};
}

View File

@@ -4,7 +4,7 @@
class PerlinNoise {
public:
static void init(unsigned int seed);
static void init();
static float noise(float x, float y, float z);
private:
static inline bool is_init = false;