mirror of
https://github.com/zhenyan121/Cubed.git
synced 2026-06-18 00:27:02 +08:00
refactor: use fBM for heightmap generation
This commit is contained in:
@@ -6,7 +6,7 @@
|
||||
namespace Cubed {
|
||||
|
||||
constexpr float BIOME_NOISE_FREQUENCY = 0.03f;
|
||||
|
||||
constexpr float HEIGHTMAP_NOISE_FREQUENCY = 0.001f;
|
||||
enum class BiomeType { PLAIN = 0, FOREST, DESERT, MOUNTAIN, RIVER, NONE };
|
||||
|
||||
struct BiomeHeightRange {
|
||||
|
||||
@@ -48,12 +48,21 @@ public:
|
||||
Chunk(Chunk&&) noexcept;
|
||||
Chunk& operator=(Chunk&&) noexcept;
|
||||
|
||||
static std::tuple<int, int, int> world_to_block(int world_x, int world_y,
|
||||
int world_z, int chunk_x,
|
||||
int chunk_z);
|
||||
static std::tuple<int, int, int> world_to_block(const glm::ivec3& block_pos,
|
||||
ChunkPos chunk_pos);
|
||||
static std::tuple<int, int, int> block_to_world(int x, int y, int z,
|
||||
int chunk_x, int chunk_z);
|
||||
static std::tuple<int, int, int> block_to_world(const glm::ivec3& block_pos,
|
||||
ChunkPos chunk_pos);
|
||||
BiomeType get_biome() const;
|
||||
ChunkPos get_chunk_pos() const;
|
||||
const std::vector<BlockType>& get_chunk_blocks() const;
|
||||
HeightMapArray get_heightmap() const;
|
||||
static int get_index(int x, int y, int z);
|
||||
static int get_index(const glm::vec3& pos);
|
||||
static int index(int x, int y, int z);
|
||||
static int index(const glm::vec3& pos);
|
||||
// Init Chunk
|
||||
// Determine biome from temperature and humidity noise
|
||||
void gen_phase_one();
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
|
||||
namespace Cubed {
|
||||
|
||||
class PerlinNoise {
|
||||
class PerlinNoise3D {
|
||||
public:
|
||||
static void init(unsigned seed);
|
||||
static float noise(float x, float y, float z);
|
||||
@@ -18,4 +18,19 @@ private:
|
||||
static float grad(int hash, float x, float y, float z);
|
||||
};
|
||||
|
||||
class PerlinNoise2D {
|
||||
public:
|
||||
static void init(unsigned seed);
|
||||
static float noise(float x, float y);
|
||||
static void reload(unsigned seed);
|
||||
|
||||
private:
|
||||
static inline std::atomic<bool> is_init = false;
|
||||
static inline std::vector<int> p;
|
||||
|
||||
static float fade(float t);
|
||||
static float lerp(float t, float a, float b);
|
||||
static float grad(int hash, float x, float y);
|
||||
};
|
||||
|
||||
} // namespace Cubed
|
||||
Reference in New Issue
Block a user