mirror of
https://github.com/Kbz-8/42_vox.git
synced 2026-01-11 14:43:34 +00:00
Added caves
This commit is contained in:
@@ -4,6 +4,7 @@
|
|||||||
#include "Maths/Vec2.h"
|
#include "Maths/Vec2.h"
|
||||||
#include <NoiseCollection.h>
|
#include <NoiseCollection.h>
|
||||||
#include <Noise.h>
|
#include <Noise.h>
|
||||||
|
#include <algorithm>
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
|
||||||
@@ -16,18 +17,34 @@ Noise* NoiseCollection::GetNoise(const std::string& key) const
|
|||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const std::array<std::uint32_t, CHUNK_SIZE.y> NoiseCollection::CarveCaves(std::array<std::uint32_t, CHUNK_SIZE.y> &data, std::uint32_t threshold, std::uint32_t cave_radius, std::uint32_t coef)
|
||||||
|
{
|
||||||
|
if (threshold > 90)
|
||||||
|
{
|
||||||
|
for(std::uint32_t y = coef; y < coef + cave_radius / 2; y++)
|
||||||
|
{
|
||||||
|
data[y] = static_cast<std::uint32_t>(BlockType::Air);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return data;
|
||||||
|
}
|
||||||
const std::array<std::uint32_t, CHUNK_SIZE.y> NoiseCollection::GetBlocks(Scop::Vec2i pos)
|
const std::array<std::uint32_t, CHUNK_SIZE.y> NoiseCollection::GetBlocks(Scop::Vec2i pos)
|
||||||
{
|
{
|
||||||
const std::uint32_t height = m_collection["terrain"]->Perlin2D(pos.x, pos.y) + ARTIFICIAL_ELEVATION;
|
const std::uint32_t height = m_collection["terrain"]->Perlin2D(pos.x, pos.y) + ARTIFICIAL_ELEVATION;
|
||||||
std::array<std::uint32_t, CHUNK_SIZE.y> data;
|
|
||||||
const std::uint32_t biome_value = m_collection["biomes"]->Perlin2D(pos.x, pos.y);
|
|
||||||
const std::uint32_t temperature = m_collection["temperature"]->Perlin2D(pos.x, pos.y);
|
const std::uint32_t temperature = m_collection["temperature"]->Perlin2D(pos.x, pos.y);
|
||||||
const std::uint32_t humidity = m_collection["humidity"]->Perlin2D(pos.x, pos.y);
|
const std::uint32_t humidity = m_collection["humidity"]->Perlin2D(pos.x, pos.y);
|
||||||
if (temperature < 85 && humidity <= 110)
|
const std::uint32_t cave_value = m_collection["caves_depth"]->Perlin2D(pos.x, pos.y);
|
||||||
return c_biomecollection.GetBiomeBlocks("tundra", height, pos);
|
const std::uint32_t cave_radius = m_collection["caves_radius"]->Perlin2D(pos.x, pos.y);
|
||||||
if (temperature >= 85 && temperature <= 145 && humidity >= 85)
|
std::array<std::uint32_t, CHUNK_SIZE.y> data;
|
||||||
return c_biomecollection.GetBiomeBlocks("grassland", height, pos);
|
|
||||||
if (temperature >= 145)
|
if (temperature < 95 && humidity <= 110)
|
||||||
return c_biomecollection.GetBiomeBlocks("desert", height, pos);
|
data = c_biomecollection.GetBiomeBlocks("tundra", height, pos);
|
||||||
return c_biomecollection.GetBiomeBlocks("grassland", height, pos);
|
else if (temperature >= 95 && temperature <= 130 && humidity >= 85)
|
||||||
|
data = c_biomecollection.GetBiomeBlocks("grassland", height, pos);
|
||||||
|
else if (temperature >= 130)
|
||||||
|
data = c_biomecollection.GetBiomeBlocks("desert", height, pos);
|
||||||
|
else
|
||||||
|
data = c_biomecollection.GetBiomeBlocks("grassland", height, pos);
|
||||||
|
data = CarveCaves(data, cave_value, cave_radius, std::clamp(static_cast<std::uint32_t>((humidity + temperature) / 5), static_cast<std::uint32_t>(0), static_cast<std::uint32_t>(255)));
|
||||||
|
return data;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ class NoiseCollection
|
|||||||
public:
|
public:
|
||||||
inline NoiseCollection(const std::uint32_t seed): c_biomecollection()
|
inline NoiseCollection(const std::uint32_t seed): c_biomecollection()
|
||||||
{
|
{
|
||||||
m_collection.emplace("terrain", std::make_unique<Noise>(seed, // seed
|
m_collection.emplace("terrain", std::make_unique<Noise>(seed,
|
||||||
0.045f,
|
0.045f,
|
||||||
0.8f,
|
0.8f,
|
||||||
4,
|
4,
|
||||||
@@ -25,7 +25,7 @@ class NoiseCollection
|
|||||||
4,
|
4,
|
||||||
1.2f
|
1.2f
|
||||||
));
|
));
|
||||||
m_collection.emplace("humidity", std::make_unique<Noise>(seed, // seed
|
m_collection.emplace("humidity", std::make_unique<Noise>(seed,
|
||||||
0.02f,
|
0.02f,
|
||||||
0.3f,
|
0.3f,
|
||||||
1,
|
1,
|
||||||
@@ -34,15 +34,24 @@ class NoiseCollection
|
|||||||
2,
|
2,
|
||||||
1.0f
|
1.0f
|
||||||
));
|
));
|
||||||
m_collection.emplace("caves", std::make_unique<Noise>(seed,
|
m_collection.emplace("caves_depth", std::make_unique<Noise>(seed + 2,
|
||||||
0.02f,
|
0.15f,
|
||||||
1.0f,
|
1.0f,
|
||||||
5,
|
2,
|
||||||
2.0f,
|
2.0f,
|
||||||
0.5f,
|
0.5f,
|
||||||
3,
|
2,
|
||||||
1.0f
|
1.0f
|
||||||
)); // TODO !!!!!!
|
));
|
||||||
|
m_collection.emplace("caves_radius", std::make_unique<Noise>(seed + 3,
|
||||||
|
0.15f,
|
||||||
|
1.0f,
|
||||||
|
4,
|
||||||
|
2.0f,
|
||||||
|
0.7f,
|
||||||
|
4,
|
||||||
|
1.0f
|
||||||
|
));
|
||||||
m_collection.emplace("biomes", std::make_unique<Noise>(seed + 1,
|
m_collection.emplace("biomes", std::make_unique<Noise>(seed + 1,
|
||||||
0.05f,
|
0.05f,
|
||||||
0.1f,
|
0.1f,
|
||||||
@@ -67,6 +76,7 @@ class NoiseCollection
|
|||||||
|
|
||||||
inline void AddNoise(std::string key, std::unique_ptr<Noise> noise) { m_collection.emplace(std::move(key), std::move(noise)); }
|
inline void AddNoise(std::string key, std::unique_ptr<Noise> noise) { m_collection.emplace(std::move(key), std::move(noise)); }
|
||||||
const std::array<std::uint32_t, CHUNK_SIZE.y> GetBlocks(Scop::Vec2i pos);
|
const std::array<std::uint32_t, CHUNK_SIZE.y> GetBlocks(Scop::Vec2i pos);
|
||||||
|
const std::array<std::uint32_t, CHUNK_SIZE.y> CarveCaves(std::array<std::uint32_t, CHUNK_SIZE.y> &data, std::uint32_t threshold, std::uint32_t cave_radius, std::uint32_t coef);
|
||||||
~NoiseCollection() = default;
|
~NoiseCollection() = default;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|||||||
Reference in New Issue
Block a user