Biomes classes

This commit is contained in:
Namonay
2025-06-01 18:50:01 +02:00
parent 0ec004b145
commit e5f2631427
5 changed files with 23 additions and 9 deletions

View File

@@ -1,8 +1,7 @@
#include <Biome.h> #include "Biome.h"
#include "Block.h" #include "Block.h"
#include "Chunk.h" #include "Chunk.h"
#include "Maths/Vec3.h"
#include <utility> #include <utility>
Biome::Biome(std::uint32_t filler, std::uint32_t water_level, std::map<std::uint32_t, std::pair<BlockPlacementType, std::vector<BlockType>>> blocks): filler(filler), water_level(water_level), c_blockmap(blocks) Biome::Biome(std::uint32_t filler, std::uint32_t water_level, std::map<std::uint32_t, std::pair<BlockPlacementType, std::vector<BlockType>>> blocks): filler(filler), water_level(water_level), c_blockmap(blocks)
@@ -27,8 +26,6 @@ const std::array<std::uint32_t, CHUNK_SIZE.y> Biome::GetBiomeBlocks(const std::u
{ {
if(y > std::min(height, CHUNK_SIZE.y) - 2) if(y > std::min(height, CHUNK_SIZE.y) - 2)
{ {
data[y] = static_cast<std::uint32_t>(BlockType::Dirt);
continue;
const auto& [placementType, blockTypes] = it->second; const auto& [placementType, blockTypes] = it->second;
switch (static_cast<std::uint8_t>(placementType)) switch (static_cast<std::uint8_t>(placementType))
{ {

View File

@@ -1,7 +1,7 @@
#ifndef BIOME_H #ifndef BIOME_H
#define BIOME_H #define BIOME_H
#include <Block.h> #include "Block.h"
#include "Chunk.h" #include "Chunk.h"
#include "Maths/Vec2.h" #include "Maths/Vec2.h"
#include <map> #include <map>

View File

@@ -14,13 +14,13 @@ class BiomeCollection
public: public:
inline BiomeCollection() inline BiomeCollection()
{ {
m_collection.emplace("grassland", std::make_unique<Biome>(Biome( m_collection.emplace("grassland", std::make_unique<Biome>(
static_cast<std::uint32_t>(BlockType::Stone), static_cast<std::uint32_t>(BlockType::Stone),
0, 0,
{ {
{20, {BlockPlacementType::Simple, {BlockType::Sand}}}, {20, {BlockPlacementType::Simple, {BlockType::Sand}}},
{255, {BlockPlacementType::Simple, {BlockType::Snow}}} {255, {BlockPlacementType::Simple, {BlockType::Snow}}}
}) }
)); ));
}; };
const std::array<std::uint32_t, CHUNK_SIZE.y> GetBiomeBlocks(std::string biome, std::uint32_t height, Scop::Vec2i pos) const; const std::array<std::uint32_t, CHUNK_SIZE.y> GetBiomeBlocks(std::string biome, std::uint32_t height, Scop::Vec2i pos) const;

View File

@@ -23,6 +23,8 @@ const std::array<std::uint32_t, CHUNK_SIZE.y> NoiseCollection::GetBlocks(Scop::V
std::memset(data.data(), static_cast<std::uint32_t>(BlockType::Air), data.size() * sizeof(std::uint32_t)); std::memset(data.data(), static_cast<std::uint32_t>(BlockType::Air), data.size() * sizeof(std::uint32_t));
data = c_biomecollection.GetBiomeBlocks("grassland", height, pos);
return data;
for(std::uint32_t y = 0; y < std::min(height, CHUNK_SIZE.y); y++) for(std::uint32_t y = 0; y < std::min(height, CHUNK_SIZE.y); y++)
{ {
// const std::uint32_t value = Perlin3D(pos.x, y, pos.y); // const std::uint32_t value = Perlin3D(pos.x, y, pos.y);
@@ -59,5 +61,9 @@ const std::array<std::uint32_t, CHUNK_SIZE.y> NoiseCollection::GetBlocks(Scop::V
if(data[y] == static_cast<std::uint32_t>(BlockType::Air)) if(data[y] == static_cast<std::uint32_t>(BlockType::Air))
data[y] = static_cast<std::uint32_t>(BlockType::Water); data[y] = static_cast<std::uint32_t>(BlockType::Water);
} }
const std::uint32_t biome_value = m_collection["biomes"]->Perlin2D(pos.x, pos.y);
if (biome_value > 20)
data[240] = static_cast<std::uint32_t>(BlockType::Stone);
return data; return data;
} }

View File

@@ -1,6 +1,7 @@
#ifndef NOISECOLLECTION_H #ifndef NOISECOLLECTION_H
# define NOISECOLLECTION_H # define NOISECOLLECTION_H
#include <BiomeCollection.h>
#include <Noise.h> #include <Noise.h>
#include <cstdint> #include <cstdint>
#include <memory> #include <memory>
@@ -13,7 +14,7 @@ constexpr std::uint32_t WATER_LEVEL = 20;
class NoiseCollection class NoiseCollection
{ {
public: public:
inline NoiseCollection(const std::uint32_t seed) 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, // seed
0.045f, 0.045f,
@@ -33,6 +34,15 @@ class NoiseCollection
3, 3,
1.0f 1.0f
)); // TODO !!!!!! )); // TODO !!!!!!
m_collection.emplace("biomes", std::make_unique<Noise>(seed,
0.05f,
1.0f,
1,
2.0f,
0.5f,
1,
1.0f
));
} }
Noise* GetNoise(const std::string& key) const; Noise* GetNoise(const std::string& key) const;
@@ -43,6 +53,7 @@ class NoiseCollection
private: private:
std::unordered_map<std::string, std::unique_ptr<Noise>> m_collection; std::unordered_map<std::string, std::unique_ptr<Noise>> m_collection;
const BiomeCollection c_biomecollection;
}; };
#endif #endif