mirror of
https://github.com/MihailRis/voxelcore.git
synced 2026-10-09 13:01:49 +00:00
move biomes definition to a json file
This commit is contained in:
parent
d62d66cf85
commit
3784b57eed
10 changed files with 183 additions and 184 deletions
|
|
@ -1,6 +1,9 @@
|
|||
#include "GeneratorDef.hpp"
|
||||
|
||||
#include "VoxelFragment.hpp"
|
||||
#include "content/Content.hpp"
|
||||
#include "util/stringutil.hpp"
|
||||
#include "voxels/Block.hpp"
|
||||
|
||||
GeneratingVoxelStructure::GeneratingVoxelStructure(
|
||||
VoxelStructureMeta meta,
|
||||
|
|
@ -9,3 +12,25 @@ GeneratingVoxelStructure::GeneratingVoxelStructure(
|
|||
|
||||
|
||||
GeneratorDef::GeneratorDef(std::string name) : name(std::move(name)) {}
|
||||
|
||||
void GeneratorDef::prepare(const Content* content) {
|
||||
for (auto& biome : biomes) {
|
||||
for (auto& layer : biome.groundLayers.layers) {
|
||||
layer.rt.id = content->blocks.require(layer.block).rt.id;
|
||||
}
|
||||
for (auto& layer : biome.seaLayers.layers) {
|
||||
layer.rt.id = content->blocks.require(layer.block).rt.id;
|
||||
}
|
||||
for (auto& plant : biome.plants.entries) {
|
||||
plant.rt.id = content->blocks.require(plant.name).rt.id;
|
||||
}
|
||||
for (auto& structure : biome.structures.entries) {
|
||||
const auto& found = structuresIndices.find(structure.name);
|
||||
if (found == structuresIndices.end()) {
|
||||
throw std::runtime_error(
|
||||
"no structure "+util::quote(structure.name)+" found");
|
||||
}
|
||||
structure.rt.id = found->second;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -137,13 +137,6 @@ public:
|
|||
virtual std::vector<StructurePlacement> placeStructures(
|
||||
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;
|
||||
|
||||
/// @brief Build the runtime cache
|
||||
/// @param content built content
|
||||
virtual void prepare(const GeneratorDef& def, const Content* content) = 0;
|
||||
};
|
||||
|
||||
struct GeneratingVoxelStructure {
|
||||
|
|
@ -170,7 +163,10 @@ struct GeneratorDef {
|
|||
|
||||
std::unordered_map<std::string, size_t> structuresIndices;
|
||||
std::vector<std::unique_ptr<GeneratingVoxelStructure>> structures;
|
||||
std::vector<Biome> biomes;
|
||||
|
||||
GeneratorDef(std::string name);
|
||||
GeneratorDef(const GeneratorDef&) = delete;
|
||||
|
||||
void prepare(const Content* content);
|
||||
};
|
||||
|
|
|
|||
|
|
@ -231,7 +231,7 @@ void WorldGenerator::generateBiomes(
|
|||
}
|
||||
auto biomeParams = def.script->generateParameterMaps(
|
||||
{chunkX * CHUNK_W, chunkZ * CHUNK_D}, {CHUNK_W, CHUNK_D}, seed);
|
||||
const auto& biomes = def.script->getBiomes();
|
||||
const auto& biomes = def.biomes;
|
||||
|
||||
auto chunkBiomes = std::make_unique<const Biome*[]>(CHUNK_W*CHUNK_D);
|
||||
for (uint z = 0; z < CHUNK_D; z++) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue