split WorldGenerator::generatePrototype
This commit is contained in:
parent
4c697c0f46
commit
a1129ccf38
@ -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
|
||||
|
||||
@ -78,9 +78,7 @@ static inline const Biome* choose_biome(
|
||||
std::unique_ptr<ChunkPrototype> 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<ChunkPrototype> WorldGenerator::generatePrototype(
|
||||
}
|
||||
}
|
||||
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) {
|
||||
// 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();
|
||||
|
||||
@ -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> heightmap;
|
||||
/// @brief chunk biomes matrix
|
||||
std::vector<const Biome*> biomes;
|
||||
|
||||
ChunkPrototype(
|
||||
std::shared_ptr<Heightmap> heightmap, std::vector<const Biome*> biomes
|
||||
) : heightmap(std::move(heightmap)), biomes(std::move(biomes)) {};
|
||||
ChunkPrototypeLevel level,
|
||||
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
|
||||
@ -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<ChunkPrototype> generatePrototype(int x, int z);
|
||||
|
||||
void generateHeightmap(ChunkPrototype* prototype, int x, int z);
|
||||
public:
|
||||
WorldGenerator(
|
||||
const GeneratorDef& def,
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user