mirror of
https://github.com/Kbz-8/42_vox.git
synced 2026-01-10 22:23:35 +00:00
Refactor to use NoiseCollection instead of Noise
This commit is contained in:
@@ -47,7 +47,7 @@ void Chunk::GenerateChunk()
|
||||
for(std::uint32_t x = 0; x < CHUNK_SIZE.x; x++)
|
||||
{
|
||||
for(std::uint32_t z = 0; z < CHUNK_SIZE.z; z++)
|
||||
std::memcpy(m_data[POS_TO_INDEX(x, z)].data(), m_world.GetNoiseGenerator().GetHeight(m_position + Scop::Vec2i(x, z)).data(), CHUNK_SIZE.y * sizeof(std::uint32_t));
|
||||
std::memcpy(m_data[POS_TO_INDEX(x, z)].data(), m_world.GetNoiseGenerator().GetBlocks(m_position + Scop::Vec2i(x, z)).data(), CHUNK_SIZE.y * sizeof(std::uint32_t));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -14,7 +14,7 @@ constexpr std::uint32_t WATER_LEVEL = 20;
|
||||
class Noise
|
||||
{
|
||||
public:
|
||||
Noise(const std::uint32_t seed = 42, float frequency = 0.045f, float amplitude = 0.80f, int octaves = 4, float lacunarity = 2.0f, float persistance = 0.7f, int redistribution = 4, float compensatory_factor = 1.2f);
|
||||
Noise(const std::uint32_t seed, float frequency, float amplitude, int octaves, float lacunarity, float persistance, int redistribution, float compensatory_factor);
|
||||
|
||||
[[nodiscard]] std::array<std::uint32_t, CHUNK_SIZE.y> GetHeight(Scop::Vec2i pos);
|
||||
[[nodiscard]] const int Perlin2D(int x, int y) noexcept;
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
#include "Chunk.h"
|
||||
#include "Maths/Vec2.h"
|
||||
#include <NoiseCollection.h>
|
||||
#include <Noise.h>
|
||||
#include <cstdint>
|
||||
#include <memory>
|
||||
|
||||
Noise* NoiseCollection::GetNoise(const std::string& key) const
|
||||
@@ -10,3 +13,8 @@ Noise* NoiseCollection::GetNoise(const std::string& key) const
|
||||
Scop::FatalError("A non existant Noise has been requested");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
const std::array<std::uint32_t, CHUNK_SIZE.y> NoiseCollection::GetBlocks(Scop::Vec2i pos)
|
||||
{
|
||||
return m_collection["terrain"]->GetHeight(pos);
|
||||
}
|
||||
|
||||
@@ -11,15 +11,23 @@ class NoiseCollection
|
||||
public:
|
||||
inline NoiseCollection(const std::uint32_t seed)
|
||||
{
|
||||
m_collection.emplace("terrain", std::make_unique<Noise>(seed));
|
||||
m_collection.emplace("caves", std::make_unique<Noise>(seed)); // TODO !!!!!!
|
||||
m_collection.emplace("terrain", std::make_unique<Noise>(seed, // seed
|
||||
0.045f,
|
||||
0.8f,
|
||||
4,
|
||||
2.0f,
|
||||
0.7f,
|
||||
4,
|
||||
1.2f
|
||||
));
|
||||
//m_collection.emplace("caves", std::make_unique<Noise>(seed)); // TODO !!!!!!
|
||||
}
|
||||
|
||||
Noise* GetNoise(const std::string& key) const;
|
||||
|
||||
inline void AddNoise(std::string key, std::unique_ptr<Noise> noise) { m_collection.emplace(std::move(key), std::move(noise)); }
|
||||
[[nodiscard]] inline std::array<std::uint32_t, CHUNK_SIZE.y> GetBlocks(Scop::Vec2i pos) const { return m_collection.at("terrain")->GetHeight(pos); }
|
||||
|
||||
const std::array<std::uint32_t, CHUNK_SIZE.y> GetBlocks(Scop::Vec2i pos);
|
||||
~NoiseCollection() = default;
|
||||
|
||||
private:
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
#include <World.h>
|
||||
#include <Utils.h>
|
||||
|
||||
World::World(Scop::Scene& scene) : m_scene(scene), m_previous_chunk_position(-1000, 10000)
|
||||
World::World(Scop::Scene& scene) : m_noisecollection(42), m_scene(scene), m_previous_chunk_position(-1000, 10000)
|
||||
{
|
||||
Scop::Vec2ui32 map_size;
|
||||
Scop::MaterialTextures material_params;
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
|
||||
#include <Chunk.h>
|
||||
#include <Utils.h>
|
||||
#include <Noise.h>
|
||||
#include <NoiseCollection.h>
|
||||
|
||||
constexpr std::uint8_t RENDER_DISTANCE = 10;
|
||||
constexpr std::uint8_t CHUNKS_UPLOAD_PER_FRAME = 3;
|
||||
@@ -29,7 +29,7 @@ class World
|
||||
[[nodiscard]] inline Scop::Scene& GetScene() noexcept { return m_scene; }
|
||||
[[nodiscard]] inline std::shared_ptr<Scop::Material> GetBlockMaterial() const { return p_block_material; }
|
||||
[[nodiscard]] Scop::NonOwningPtr<Chunk> GetChunk(Scop::Vec2i position);
|
||||
[[nodiscard]] Noise& GetNoiseGenerator() noexcept { return m_noise; }
|
||||
[[nodiscard]] NoiseCollection& GetNoiseGenerator() noexcept { return m_noisecollection; }
|
||||
|
||||
~World();
|
||||
|
||||
@@ -39,7 +39,7 @@ class World
|
||||
void Upload();
|
||||
|
||||
private:
|
||||
Noise m_noise;
|
||||
NoiseCollection m_noisecollection;
|
||||
std::unordered_map<Scop::Vec2i, Chunk> m_chunks;
|
||||
ThreadSafeQueue<std::reference_wrapper<Chunk>> m_chunks_to_upload;
|
||||
std::shared_ptr<Scop::Material> p_block_material;
|
||||
|
||||
Reference in New Issue
Block a user