From dbce057f6a452d894b5fa04ba624c3288a535e56 Mon Sep 17 00:00:00 2001 From: Namonay Date: Fri, 30 May 2025 22:22:18 +0200 Subject: [PATCH] Added NoiseCollection --- Application/NoiseCollection.cpp | 28 ++++++++++++++++++++++++++++ Application/NoiseCollection.h | 22 ++++++++++++++++++++++ 2 files changed, 50 insertions(+) create mode 100644 Application/NoiseCollection.cpp create mode 100644 Application/NoiseCollection.h diff --git a/Application/NoiseCollection.cpp b/Application/NoiseCollection.cpp new file mode 100644 index 0000000..f114557 --- /dev/null +++ b/Application/NoiseCollection.cpp @@ -0,0 +1,28 @@ +#include +#include +#include + +NoiseCollection::NoiseCollection(const std::uint32_t seed) +{ + m_collection["terrain"] = std::make_unique(seed); + m_collection["caves"] = std::make_unique(seed); // TODO !!!!!! +} + +void NoiseCollection::AddNoise(const std::string& key, std::unique_ptr noise) +{ + m_collection[key] = std::move(noise); +} + +Noise* NoiseCollection::GetNoise(const std::string key) const +{ + auto it = m_collection.find(key); + if (it != m_collection.end()) + return it->second.get(); + Scop::FatalError("A non existant Noise has been requested"); + return nullptr; +} + +[[nodiscard]] std::array NoiseCollection::GetBlocks(Scop::Vec2i pos) +{ + return m_collection["terrain"]->GetHeight(pos); +} diff --git a/Application/NoiseCollection.h b/Application/NoiseCollection.h new file mode 100644 index 0000000..6dcc45a --- /dev/null +++ b/Application/NoiseCollection.h @@ -0,0 +1,22 @@ +#ifndef NOISECOLLECTION_H +# define NOISECOLLECTION_H + +#include +#include +#include +#include + +class NoiseCollection +{ + public: + NoiseCollection(const std::uint32_t seed); + ~NoiseCollection(void) = default; + void AddNoise(const std::string& key, std::unique_ptr noise); + Noise* GetNoise(const std::string key) const; + [[nodiscard]] std::array GetBlocks(Scop::Vec2i pos); + + private: + std::unordered_map> m_collection; +}; + +#endif