summary refs log tree commit diff
path: root/src/World/Generator.cpp
diff options
context:
space:
mode:
authorMel <einebeere@gmail.com>2023-07-01 22:03:51 +0200
committerMel <einebeere@gmail.com>2023-07-01 22:03:51 +0200
commit221f632d6600ce03e09c2a44074ae100a507dd92 (patch)
tree462663c1f03582e8a0b5df753bc7c45cbe702aad /src/World/Generator.cpp
parent424d00eaf7335e1c6427f40260d55782c3fd902c (diff)
downloadmeowcraft-221f632d6600ce03e09c2a44074ae100a507dd92.tar.zst
meowcraft-221f632d6600ce03e09c2a44074ae100a507dd92.zip
Replace bespoke Generator maps with tensors and matrices
Diffstat (limited to 'src/World/Generator.cpp')
-rw-r--r--src/World/Generator.cpp49
1 files changed, 25 insertions, 24 deletions
diff --git a/src/World/Generator.cpp b/src/World/Generator.cpp
index f528278..ada2b7b 100644
--- a/src/World/Generator.cpp
+++ b/src/World/Generator.cpp
@@ -16,62 +16,63 @@ Chunk Generator::generate(int64_t chunk_x, int64_t chunk_y) {
 
     decorate_soil(chunk, biome_map, terrain_map);
 
-    chunk.set_details({{landmass_map.map}, {hill_map.map}, {biome_map.map}});
+    chunk.set_details({{landmass_map}, {hill_map}, {biome_map}});
 
     return chunk;
 }
 
-Generator::ChunkMap2D<float> Generator::generate_landmass_map(int64_t chunk_x, int64_t chunk_y) {
-    ChunkMap2D<float> landmass_map{};
+Generator::Map2D<float> Generator::generate_landmass_map(int64_t chunk_x, int64_t chunk_y) {
+    Matrix<Chunk::Width, Chunk::Width> landmass_map{};
 
     for (uint x = 0; x < Chunk::Width; x++) {
         for (uint y = 0; y < Chunk::Width; y++) {
-            landmass_map.set(x, y, get_landmass(chunk_position_to_world_vector(chunk_x, chunk_y, x, y)));
+            auto world_pos = chunk_position_to_world_vector(chunk_x, chunk_y, x, y);
+            landmass_map(x, y) = get_landmass(world_pos);
         }
     }
 
     return landmass_map;
 }
 
-Generator::ChunkMap2D<float> Generator::generate_hill_map(int64_t chunk_x, int64_t chunk_y) {
-    ChunkMap2D<float> hill_map{};
+Generator::Map2D<float> Generator::generate_hill_map(int64_t chunk_x, int64_t chunk_y) {
+    Map2D<float> hill_map{};
 
     for (uint x = 0; x < Chunk::Width; x++) {
         for (uint y = 0; y < Chunk::Width; y++) {
-            hill_map.set(x, y, get_hill(chunk_position_to_world_vector(chunk_x, chunk_y, x, y)));
+            hill_map(x, y) = get_hill(chunk_position_to_world_vector(chunk_x, chunk_y, x, y));
         }
     }
 
     return hill_map;
 }
 
-Generator::ChunkMap2D<float> Generator::generate_height_map(ChunkMap2D<float>& landmass_map, ChunkMap2D<float>& hill_map, int64_t chunk_x, int64_t chunk_y) {
-    ChunkMap2D<float> height_map{};
+Generator::Map2D<float> Generator::generate_height_map(Map2D<float>& landmass_map, Map2D<float>& hill_map, int64_t chunk_x, int64_t chunk_y) {
+    Map2D<float> height_map{};
 
     for (uint x = 0; x < Chunk::Width; x++) {
         for (uint y = 0; y < Chunk::Width; y++) {
-            auto landmass_effect = landmass_map.get(x, y);
-            auto hill_effect = hill_map.get(x, y);
+            auto landmass_effect = landmass_map(x, y);
+            auto hill_effect = hill_map(x, y);
 
             auto hill = hill_effect * landmass_effect * 1.4 - 0.4;
             auto landmass = landmass_effect * 0.6 + 0.4;
 
             auto height = (hill + landmass) / 2.0f;
 
-            height_map.set(x, y, height);
+            height_map(x, y) = height;
         }
     }
 
     return height_map;
 }
 
-Generator::ChunkMap2D<BiomeType> Generator::generate_biome_map(ChunkMap2D<float>& landmass_map, ChunkMap2D<float>& hill_map, ChunkMap2D<float>& height_map, int64_t chunk_x, int64_t chunk_y) {
-    ChunkMap2D<BiomeType> biome_map{};
+Generator::Map2D<BiomeType> Generator::generate_biome_map(Map2D<float>& landmass_map, Map2D<float>& hill_map, Map2D<float>& height_map, int64_t chunk_x, int64_t chunk_y) {
+    Map2D<BiomeType> biome_map{};
 
     for (uint x = 0; x < Chunk::Width; x++) {
         for (uint y = 0; y < Chunk::Width; y++) {
-            float landmass = landmass_map.get(x, y);
-            float hill = hill_map.get(x, y);
+            float landmass = landmass_map(x, y);
+            float hill = hill_map(x, y);
 
             auto world_pos = chunk_position_to_world_vector(chunk_x, chunk_y, x, y);
             float temperature = get_temperature(world_pos);
@@ -98,27 +99,27 @@ Generator::ChunkMap2D<BiomeType> Generator::generate_biome_map(ChunkMap2D<float>
             else { humidity_zone = HumidityZone::Dry; }
 
             auto biome = lookup_biome(hill_slice, landmass_slice, temparature_zone, humidity_zone);
-            biome_map.set(x, y, biome);
+            biome_map(x, y) = biome;
         }
     }
 
     return biome_map;
 }
 
-Generator::ChunkMap3D<bool> Generator::generate_terrain(ChunkMap2D<float>& height_map, int64_t chunk_x, int64_t chunk_y) {
+Generator::Map3D<bool> Generator::generate_terrain(Map2D<float>& height_map, int64_t chunk_x, int64_t chunk_y) {
     float jaggedness = 0.10f;
 
-    ChunkMap3D<bool> terrain_map{};
+    Map3D<bool> terrain_map{};
     for (uint x = 0; x < Chunk::Width; x++) {
         for (uint z = 0; z < Chunk::Width; z++) {
-            auto height = height_map.get(x, z);
+            auto height = height_map(x, z);
 
             for (uint y = 0; y < Chunk::Height; y++) {
                 float density = get_density({Chunk::Width * chunk_x + (float)x, (float)y, Chunk::Width * chunk_y + (float)z});
                 float threshold = Math::sigmoid(((float)y / (Chunk::Height * height * 2) - 0.5f) / jaggedness);
 
                 if (density > threshold) {
-                    terrain_map.set(x, y, z, true);
+                    terrain_map(x, y, z) = true;
                 }
             }
         }
@@ -127,13 +128,13 @@ Generator::ChunkMap3D<bool> Generator::generate_terrain(ChunkMap2D<float>& heigh
     return terrain_map;
 }
 
-void Generator::decorate_soil(Chunk& chunk, ChunkMap2D<BiomeType>& biome_map, ChunkMap3D<bool>& terrain_map) {
+void Generator::decorate_soil(Chunk& chunk, Map2D<BiomeType>& biome_map, Map3D<bool>& terrain_map) {
     constexpr uint dirt_depth = 4;
     constexpr uint water_height = 39;
 
     for (uint x = 0; x < Chunk::Width; x++) {
         for (uint z = 0; z < Chunk::Width; z++) {
-            auto biome = biome_map.get(x, z);
+            auto biome = biome_map(x, z);
 
             BlockType top_block{};
             BlockType soil_block{};
@@ -159,7 +160,7 @@ void Generator::decorate_soil(Chunk& chunk, ChunkMap2D<BiomeType>& biome_map, Ch
 
             auto column_depth = 0;
             for (uint y = Chunk::Height - 1; y > 0; y--) {
-                auto block = terrain_map.get(x, y, z);
+                auto block = terrain_map(x, y, z);
                 if (block) {
                     if (column_depth == 0 && y >= water_height - 1) {
                         chunk.set(x, y, z, {top_block});