split WorldGenerator::generatePrototype

This commit is contained in:
MihailRis 2024-08-24 07:56:54 +03:00
parent 4c697c0f46
commit a1129ccf38
3 changed files with 33 additions and 9 deletions

View File

@ -102,9 +102,11 @@ end
function generate_biome_parameters(x, y, w, h, seed) function generate_biome_parameters(x, y, w, h, seed)
local tempmap = Heightmap(w, h) local tempmap = Heightmap(w, h)
tempmap.noiseSeed = seed + 5324 tempmap.noiseSeed = seed + 5324
tempmap:noise({x, y}, 0.8, 3) tempmap:noise({x, y}, 0.4, 4)
local hummap = Heightmap(w, h) local hummap = Heightmap(w, h)
hummap.noiseSeed = seed + 953 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 return tempmap, hummap
end end

View File

@ -78,9 +78,7 @@ static inline const Biome* choose_biome(
std::unique_ptr<ChunkPrototype> WorldGenerator::generatePrototype( std::unique_ptr<ChunkPrototype> WorldGenerator::generatePrototype(
int chunkX, int chunkZ int chunkX, int chunkZ
) { ) {
timeutil::ScopeLogTimer log(666); // timeutil::ScopeLogTimer log(666);
auto heightmap = def.script->generateHeightmap(
{chunkX * CHUNK_W, chunkZ * CHUNK_D}, {CHUNK_W, CHUNK_D}, seed);
auto biomeParams = def.script->generateParameterMaps( auto biomeParams = def.script->generateParameterMaps(
{chunkX * CHUNK_W, chunkZ * CHUNK_D}, {CHUNK_W, CHUNK_D}, seed); {chunkX * CHUNK_W, chunkZ * CHUNK_D}, {CHUNK_W, CHUNK_D}, seed);
const auto& biomes = def.script->getBiomes(); const auto& biomes = def.script->getBiomes();
@ -92,13 +90,25 @@ std::unique_ptr<ChunkPrototype> WorldGenerator::generatePrototype(
} }
} }
return std::make_unique<ChunkPrototype>( return std::make_unique<ChunkPrototype>(
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) { void WorldGenerator::generate(voxel* voxels, int chunkX, int chunkZ) {
// timeutil::ScopeLogTimer log(555); timeutil::ScopeLogTimer log(555);
auto prototype = generatePrototype(chunkX, chunkZ); auto prototype = generatePrototype(chunkX, chunkZ);
generateHeightmap(prototype.get(), chunkX, chunkZ);
const auto values = prototype->heightmap->getValues(); const auto values = prototype->heightmap->getValues();
uint seaLevel = def.script->getSeaLevel(); uint seaLevel = def.script->getSeaLevel();

View File

@ -13,15 +13,25 @@ struct GeneratorDef;
class Heightmap; class Heightmap;
struct Biome; struct Biome;
enum class ChunkPrototypeLevel {
BIOME, HEIGHTMAP
};
struct ChunkPrototype { struct ChunkPrototype {
ChunkPrototypeLevel level;
/// @brief chunk heightmap /// @brief chunk heightmap
std::shared_ptr<Heightmap> heightmap; std::shared_ptr<Heightmap> heightmap;
/// @brief chunk biomes matrix /// @brief chunk biomes matrix
std::vector<const Biome*> biomes; std::vector<const Biome*> biomes;
ChunkPrototype( ChunkPrototype(
std::shared_ptr<Heightmap> heightmap, std::vector<const Biome*> biomes ChunkPrototypeLevel level,
) : heightmap(std::move(heightmap)), biomes(std::move(biomes)) {}; std::shared_ptr<Heightmap> heightmap,
std::vector<const Biome*> biomes
) : level(level),
heightmap(std::move(heightmap)),
biomes(std::move(biomes)) {};
}; };
/// @brief High-level world generation controller /// @brief High-level world generation controller
@ -37,6 +47,8 @@ class WorldGenerator {
/// @param x chunk position X divided by CHUNK_W /// @param x chunk position X divided by CHUNK_W
/// @param z chunk position Y divided by CHUNK_D /// @param z chunk position Y divided by CHUNK_D
std::unique_ptr<ChunkPrototype> generatePrototype(int x, int z); std::unique_ptr<ChunkPrototype> generatePrototype(int x, int z);
void generateHeightmap(ChunkPrototype* prototype, int x, int z);
public: public:
WorldGenerator( WorldGenerator(
const GeneratorDef& def, const GeneratorDef& def,