diff --git a/Application/Chunk.cpp b/Application/Chunk.cpp index fa1b04c..42e266c 100644 --- a/Application/Chunk.cpp +++ b/Application/Chunk.cpp @@ -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)); } } diff --git a/Application/Noise.h b/Application/Noise.h index 4113396..7f4e84c 100644 --- a/Application/Noise.h +++ b/Application/Noise.h @@ -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 GetHeight(Scop::Vec2i pos); [[nodiscard]] const int Perlin2D(int x, int y) noexcept; diff --git a/Application/NoiseCollection.cpp b/Application/NoiseCollection.cpp index aaff9a7..6b9f2ac 100644 --- a/Application/NoiseCollection.cpp +++ b/Application/NoiseCollection.cpp @@ -1,5 +1,8 @@ +#include "Chunk.h" +#include "Maths/Vec2.h" #include #include +#include #include 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 NoiseCollection::GetBlocks(Scop::Vec2i pos) +{ + return m_collection["terrain"]->GetHeight(pos); +} diff --git a/Application/NoiseCollection.h b/Application/NoiseCollection.h index 2c360f7..826c6bd 100644 --- a/Application/NoiseCollection.h +++ b/Application/NoiseCollection.h @@ -11,15 +11,23 @@ class NoiseCollection public: inline NoiseCollection(const std::uint32_t seed) { - m_collection.emplace("terrain", std::make_unique(seed)); - m_collection.emplace("caves", std::make_unique(seed)); // TODO !!!!!! + m_collection.emplace("terrain", std::make_unique(seed, // seed + 0.045f, + 0.8f, + 4, + 2.0f, + 0.7f, + 4, + 1.2f + )); + //m_collection.emplace("caves", std::make_unique(seed)); // TODO !!!!!! } Noise* GetNoise(const std::string& key) const; inline void AddNoise(std::string key, std::unique_ptr noise) { m_collection.emplace(std::move(key), std::move(noise)); } [[nodiscard]] inline std::array GetBlocks(Scop::Vec2i pos) const { return m_collection.at("terrain")->GetHeight(pos); } - + const std::array GetBlocks(Scop::Vec2i pos); ~NoiseCollection() = default; private: diff --git a/Application/World.cpp b/Application/World.cpp index ca8d421..82ef53f 100644 --- a/Application/World.cpp +++ b/Application/World.cpp @@ -6,7 +6,7 @@ #include #include -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; diff --git a/Application/World.h b/Application/World.h index ce61351..74e77db 100644 --- a/Application/World.h +++ b/Application/World.h @@ -8,7 +8,7 @@ #include #include -#include +#include 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 GetBlockMaterial() const { return p_block_material; } [[nodiscard]] Scop::NonOwningPtr 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 m_chunks; ThreadSafeQueue> m_chunks_to_upload; std::shared_ptr p_block_material;