diff --git a/res/generators/default.lua b/res/generators/default.lua index 75bfb868..e96ea22e 100644 --- a/res/generators/default.lua +++ b/res/generators/default.lua @@ -102,9 +102,11 @@ end function generate_biome_parameters(x, y, w, h, seed) local tempmap = Heightmap(w, h) tempmap.noiseSeed = seed + 5324 - tempmap:noise({x, y}, 0.8, 3) + tempmap:noise({x, y}, 0.4, 4) local hummap = Heightmap(w, h) hummap.noiseSeed = seed + 953 - hummap:noise({x, y}, 0.2, 2) + hummap:noise({x, y}, 0.16, 4) + tempmap:pow(2) + hummap:pow(2) return tempmap, hummap end diff --git a/src/world/generator/WorldGenerator.cpp b/src/world/generator/WorldGenerator.cpp index 53649bf7..1347a10f 100644 --- a/src/world/generator/WorldGenerator.cpp +++ b/src/world/generator/WorldGenerator.cpp @@ -78,9 +78,7 @@ static inline const Biome* choose_biome( std::unique_ptr WorldGenerator::generatePrototype( int chunkX, int chunkZ ) { - timeutil::ScopeLogTimer log(666); - auto heightmap = def.script->generateHeightmap( - {chunkX * CHUNK_W, chunkZ * CHUNK_D}, {CHUNK_W, CHUNK_D}, seed); + // timeutil::ScopeLogTimer log(666); auto biomeParams = def.script->generateParameterMaps( {chunkX * CHUNK_W, chunkZ * CHUNK_D}, {CHUNK_W, CHUNK_D}, seed); const auto& biomes = def.script->getBiomes(); @@ -92,13 +90,25 @@ std::unique_ptr WorldGenerator::generatePrototype( } } return std::make_unique( - std::move(heightmap), std::move(chunkBiomes)); + ChunkPrototypeLevel::HEIGHTMAP, + nullptr, + std::move(chunkBiomes)); +} + +void WorldGenerator::generateHeightmap( + ChunkPrototype* prototype, int chunkX, int chunkZ +) { + prototype->heightmap = def.script->generateHeightmap( + {chunkX * CHUNK_W, chunkZ * CHUNK_D}, {CHUNK_W, CHUNK_D}, seed); + prototype->level = ChunkPrototypeLevel::HEIGHTMAP; } void WorldGenerator::generate(voxel* voxels, int chunkX, int chunkZ) { - // timeutil::ScopeLogTimer log(555); + timeutil::ScopeLogTimer log(555); auto prototype = generatePrototype(chunkX, chunkZ); + generateHeightmap(prototype.get(), chunkX, chunkZ); + const auto values = prototype->heightmap->getValues(); uint seaLevel = def.script->getSeaLevel(); diff --git a/src/world/generator/WorldGenerator.hpp b/src/world/generator/WorldGenerator.hpp index d8a32b16..84c1022a 100644 --- a/src/world/generator/WorldGenerator.hpp +++ b/src/world/generator/WorldGenerator.hpp @@ -13,15 +13,25 @@ struct GeneratorDef; class Heightmap; struct Biome; +enum class ChunkPrototypeLevel { + BIOME, HEIGHTMAP +}; + struct ChunkPrototype { + ChunkPrototypeLevel level; + /// @brief chunk heightmap std::shared_ptr heightmap; /// @brief chunk biomes matrix std::vector biomes; ChunkPrototype( - std::shared_ptr heightmap, std::vector biomes - ) : heightmap(std::move(heightmap)), biomes(std::move(biomes)) {}; + ChunkPrototypeLevel level, + std::shared_ptr heightmap, + std::vector biomes + ) : level(level), + heightmap(std::move(heightmap)), + biomes(std::move(biomes)) {}; }; /// @brief High-level world generation controller @@ -37,6 +47,8 @@ class WorldGenerator { /// @param x chunk position X divided by CHUNK_W /// @param z chunk position Y divided by CHUNK_D std::unique_ptr generatePrototype(int x, int z); + + void generateHeightmap(ChunkPrototype* prototype, int x, int z); public: WorldGenerator( const GeneratorDef& def,