mirror of
https://github.com/Kbz-8/42_vox.git
synced 2026-01-10 22:23:35 +00:00
Added NoiseCollection
This commit is contained in:
28
Application/NoiseCollection.cpp
git.filemode.normal_file
28
Application/NoiseCollection.cpp
git.filemode.normal_file
@@ -0,0 +1,28 @@
|
||||
#include <NoiseCollection.h>
|
||||
#include <Noise.h>
|
||||
#include <memory>
|
||||
|
||||
NoiseCollection::NoiseCollection(const std::uint32_t seed)
|
||||
{
|
||||
m_collection["terrain"] = std::make_unique<Noise>(seed);
|
||||
m_collection["caves"] = std::make_unique<Noise>(seed); // TODO !!!!!!
|
||||
}
|
||||
|
||||
void NoiseCollection::AddNoise(const std::string& key, std::unique_ptr<Noise> 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<std::uint32_t, CHUNK_SIZE.y> NoiseCollection::GetBlocks(Scop::Vec2i pos)
|
||||
{
|
||||
return m_collection["terrain"]->GetHeight(pos);
|
||||
}
|
||||
22
Application/NoiseCollection.h
git.filemode.normal_file
22
Application/NoiseCollection.h
git.filemode.normal_file
@@ -0,0 +1,22 @@
|
||||
#ifndef NOISECOLLECTION_H
|
||||
# define NOISECOLLECTION_H
|
||||
|
||||
#include <Noise.h>
|
||||
#include <cstdint>
|
||||
#include <memory>
|
||||
#include <unordered_map>
|
||||
|
||||
class NoiseCollection
|
||||
{
|
||||
public:
|
||||
NoiseCollection(const std::uint32_t seed);
|
||||
~NoiseCollection(void) = default;
|
||||
void AddNoise(const std::string& key, std::unique_ptr<Noise> noise);
|
||||
Noise* GetNoise(const std::string key) const;
|
||||
[[nodiscard]] std::array<std::uint32_t, CHUNK_SIZE.y> GetBlocks(Scop::Vec2i pos);
|
||||
|
||||
private:
|
||||
std::unordered_map<std::string, std::unique_ptr<Noise>> m_collection;
|
||||
};
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user