mirror of
https://github.com/Kbz-8/42_vox.git
synced 2026-01-10 22:23:35 +00:00
Biomes classes
This commit is contained in:
@@ -1,8 +1,7 @@
|
||||
|
||||
#include <Biome.h>
|
||||
#include "Biome.h"
|
||||
#include "Block.h"
|
||||
#include "Chunk.h"
|
||||
#include "Maths/Vec3.h"
|
||||
#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)
|
||||
@@ -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)
|
||||
{
|
||||
data[y] = static_cast<std::uint32_t>(BlockType::Dirt);
|
||||
continue;
|
||||
const auto& [placementType, blockTypes] = it->second;
|
||||
switch (static_cast<std::uint8_t>(placementType))
|
||||
{
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#ifndef BIOME_H
|
||||
#define BIOME_H
|
||||
|
||||
#include <Block.h>
|
||||
#include "Block.h"
|
||||
#include "Chunk.h"
|
||||
#include "Maths/Vec2.h"
|
||||
#include <map>
|
||||
|
||||
@@ -14,13 +14,13 @@ class BiomeCollection
|
||||
public:
|
||||
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),
|
||||
0,
|
||||
{
|
||||
{20, {BlockPlacementType::Simple, {BlockType::Sand}}},
|
||||
{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;
|
||||
|
||||
@@ -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));
|
||||
|
||||
data = c_biomecollection.GetBiomeBlocks("grassland", height, pos);
|
||||
return data;
|
||||
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);
|
||||
@@ -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))
|
||||
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;
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
#ifndef NOISECOLLECTION_H
|
||||
# define NOISECOLLECTION_H
|
||||
# define NOISECOLLECTION_H
|
||||
|
||||
#include <BiomeCollection.h>
|
||||
#include <Noise.h>
|
||||
#include <cstdint>
|
||||
#include <memory>
|
||||
@@ -13,7 +14,7 @@ constexpr std::uint32_t WATER_LEVEL = 20;
|
||||
class NoiseCollection
|
||||
{
|
||||
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
|
||||
0.045f,
|
||||
@@ -33,6 +34,15 @@ class NoiseCollection
|
||||
3,
|
||||
1.0f
|
||||
)); // 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;
|
||||
@@ -43,6 +53,7 @@ class NoiseCollection
|
||||
|
||||
private:
|
||||
std::unordered_map<std::string, std::unique_ptr<Noise>> m_collection;
|
||||
const BiomeCollection c_biomecollection;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user