add generator definition file (.toml)

This commit is contained in:
MihailRis
2024-09-26 22:26:01 +03:00
parent d839da7dab
commit 3d478aef08
12 changed files with 76 additions and 54 deletions
+6 -7
View File
@@ -135,19 +135,12 @@ public:
const glm::ivec2& offset, const glm::ivec2& size, uint64_t seed) = 0;
virtual std::vector<StructurePlacement> placeStructures(
const GeneratorDef& def,
const glm::ivec2& offset, const glm::ivec2& size, uint64_t seed,
const std::shared_ptr<Heightmap>& heightmap) = 0;
/// @brief Get generator biomes
virtual const std::vector<Biome>& getBiomes() const = 0;
/// @return Number of biome parameters, that biome choosing depending on
virtual uint getBiomeParameters() const = 0;
/// @return Sea level (top of seaLayers)
virtual uint getSeaLevel() const = 0;
/// @brief Build the runtime cache
/// @param content built content
virtual void prepare(const GeneratorDef& def, const Content* content) = 0;
@@ -169,6 +162,12 @@ struct GeneratorDef {
std::string name;
std::unique_ptr<GeneratorScript> script;
/// @brief Sea level (top of seaLayers)
uint seaLevel = 0;
/// @brief Number of biome parameters, that biome choosing depending on
uint biomeParameters = 0;
std::unordered_map<std::string, size_t> structuresIndices;
std::vector<std::unique_ptr<GeneratingVoxelStructure>> structures;
+3 -3
View File
@@ -175,7 +175,7 @@ void WorldGenerator::generateStructures(
const auto& heightmap = prototype.heightmap;
util::concat(prototype.structures, def.script->placeStructures(
def, {chunkX * CHUNK_W, chunkZ * CHUNK_D}, {CHUNK_W, CHUNK_D}, seed,
{chunkX * CHUNK_W, chunkZ * CHUNK_D}, {CHUNK_W, CHUNK_D}, seed,
heightmap
));
for (const auto& placement : prototype.structures) {
@@ -202,7 +202,7 @@ void WorldGenerator::generateStructures(
}
uint8_t rotation = structsRand.randU32() % 4;
int height = heights[z * CHUNK_W + x] * CHUNK_H;
if (height < def.script->getSeaLevel()) {
if (height < def.seaLevel) {
continue;
}
auto& structure = *def.structures[structureId]->fragments[rotation];
@@ -268,7 +268,7 @@ void WorldGenerator::generate(voxel* voxels, int chunkX, int chunkZ) {
const auto& prototype = requirePrototype(chunkX, chunkZ);
const auto values = prototype.heightmap->getValues();
uint seaLevel = def.script->getSeaLevel();
uint seaLevel = def.seaLevel;
std::memset(voxels, 0, sizeof(voxel) * CHUNK_VOL);