diff options
Diffstat (limited to 'src/World/Generator.hpp')
| -rw-r--r-- | src/World/Generator.hpp | 37 |
1 files changed, 13 insertions, 24 deletions
diff --git a/src/World/Generator.hpp b/src/World/Generator.hpp index 523136a..a90d1bc 100644 --- a/src/World/Generator.hpp +++ b/src/World/Generator.hpp @@ -4,6 +4,7 @@ #include "Chunk.hpp" #include "BiomeType.hpp" #include "../Math/Perlin.hpp" +#include "../Math/Tensor.hpp" namespace MC::World { @@ -12,30 +13,18 @@ public: Generator() = default; Chunk generate(int64_t chunk_x, int64_t chunk_y); private: - template <typename V> - struct ChunkMap2D { - V map[Chunk::Width * Chunk::Width]; - void set(uint x, uint y, V v) { map[x * Chunk::Width + y] = v; } - V get(uint x, uint y) { return map[x * Chunk::Width + y]; } - }; - - template <typename V> - struct ChunkMap3D { - V map[Chunk::Width * Chunk::Width * Chunk::Height]; - void set(uint x, uint y, uint z, V v) { map[pos(x, y, z)] = v; } - V get(uint x, uint y, uint z) { return map[pos(x, y, z)]; } - static uint pos(uint x, uint y, uint z) { return x + Chunk::Width * y + Chunk::Width * Chunk::Height * z; } - }; - - ChunkMap2D<float> generate_landmass_map(int64_t chunk_x, int64_t chunk_y); - ChunkMap2D<float> generate_hill_map(int64_t chunk_x, int64_t chunk_y); - ChunkMap2D<float> generate_height_map(ChunkMap2D<float>& landmass_map, ChunkMap2D<float>& hill_map, int64_t chunk_x, int64_t chunk_y); - - ChunkMap2D<BiomeType> generate_biome_map(ChunkMap2D<float>& landmass_map, ChunkMap2D<float>& hill_map, ChunkMap2D<float>& height_map, int64_t chunk_x, int64_t chunk_y); - - ChunkMap3D<bool> generate_terrain(ChunkMap2D<float>& height_map, int64_t chunk_x, int64_t chunk_y); - - void decorate_soil(Chunk& chunk, ChunkMap2D<BiomeType>& biome_map, ChunkMap3D<bool>& terrain_map); + template <typename V> using Map2D = Matrix<Chunk::Width, Chunk::Width, V>; + template <typename V> using Map3D = Tensor<3, V, Chunk::Width, Chunk::Height, Chunk::Width>; + + Map2D<float> generate_landmass_map(int64_t chunk_x, int64_t chunk_y); + Map2D<float> generate_hill_map(int64_t chunk_x, int64_t chunk_y); + Map2D<float> generate_height_map(Map2D<float>& landmass_map, Map2D<float>& hill_map, int64_t chunk_x, int64_t chunk_y); + + Map2D<BiomeType> generate_biome_map(Map2D<float>& landmass_map, Map2D<float>& hill_map, Map2D<float>& height_map, int64_t chunk_x, int64_t chunk_y); + + Map3D<bool> generate_terrain(Map2D<float>& height_map, int64_t chunk_x, int64_t chunk_y); + + void decorate_soil(Chunk& chunk, Map2D<BiomeType>& biome_map, Map3D<bool>& terrain_map); [[nodiscard]] float get_landmass(Vector<2> pos) const; [[nodiscard]] float get_hill(Vector<2> pos) const; |
