add heightmap-based test generation

This commit is contained in:
MihailRis
2024-08-14 18:44:32 +03:00
parent 95cf451cc8
commit ae5671364a
18 changed files with 82 additions and 440 deletions
+3 -2
View File
@@ -15,7 +15,8 @@
#include "voxels/Chunk.hpp"
#include "voxels/Chunks.hpp"
#include "voxels/ChunksStorage.hpp"
#include "WorldGenerators.hpp"
#include "voxels/WorldGenerator.hpp"
#include "world/generator/GeneratorDef.hpp"
#include "Level.hpp"
static debug::Logger logger("world");
@@ -205,7 +206,7 @@ void WorldInfo::deserialize(dynamic::Map* root) {
seed = root->get("seed", seed);
if (generator.empty()) {
generator = WorldGenerators::getDefaultGeneratorID();
generator = WorldGenerator::DEFAULT;
}
if (auto verobj = root->map("version")) {
verobj->num("major", major);
-29
View File
@@ -1,29 +0,0 @@
#include "WorldGenerators.hpp"
#include <iostream>
#include "content/Content.hpp"
#include "voxels/FlatWorldGenerator.hpp"
#include "voxels/WorldGenerator.hpp"
std::vector<std::string> WorldGenerators::getGeneratorsIDs() {
std::vector<std::string> ids;
for (auto& entry : generators) {
ids.push_back(entry.first);
}
return ids;
}
std::string WorldGenerators::getDefaultGeneratorID() {
return "core:default";
}
std::unique_ptr<WorldGenerator> WorldGenerators::createGenerator(
const std::string& id, const Content* content
) {
auto found = generators.find(id);
if (found == generators.end()) {
throw std::runtime_error("unknown generator id: " + id);
}
return std::unique_ptr<WorldGenerator>(found->second(content));
}
-33
View File
@@ -1,33 +0,0 @@
#pragma once
#include <map>
#include <string>
#include <vector>
#include "voxels/WorldGenerator.hpp"
class Content;
typedef WorldGenerator* (*gen_constructor)(const Content*);
class WorldGenerators {
static inline std::map<std::string, gen_constructor> generators;
public:
template <typename T>
static void addGenerator(std::string id);
static std::vector<std::string> getGeneratorsIDs();
static std::string getDefaultGeneratorID();
static std::unique_ptr<WorldGenerator> createGenerator(
const std::string& id, const Content* content
);
};
template <typename T>
void WorldGenerators::addGenerator(std::string id) {
generators[id] = [](const Content* content) {
return (WorldGenerator*)new T(content);
};
}