update world generation pipeline

This commit is contained in:
MihailRis
2024-09-21 23:29:19 +03:00
parent f4793ac9db
commit 001b930212
9 changed files with 28 additions and 20 deletions
@@ -39,6 +39,7 @@ namespace lua {
std::shared_ptr<Heightmap> map;
std::unique_ptr<fnl_state> noise;
public:
LuaHeightmap(const std::shared_ptr<Heightmap>& map);
LuaHeightmap(uint width, uint height);
virtual ~LuaHeightmap();
@@ -16,6 +16,10 @@
using namespace lua;
LuaHeightmap::LuaHeightmap(const std::shared_ptr<Heightmap>& map)
: map(map), noise(std::make_unique<fnl_state>(fnlCreateState())) {
}
LuaHeightmap::LuaHeightmap(uint width, uint height)
: map(std::make_shared<Heightmap>(width, height)),
noise(std::make_unique<fnl_state>(fnlCreateState()))
@@ -13,6 +13,8 @@
#include "data/dv.hpp"
#include "world/generator/GeneratorDef.hpp"
#include "util/timeutil.hpp"
class LuaGeneratorScript : public GeneratorScript {
scriptenv env;
std::vector<Biome> biomes;
@@ -99,7 +101,8 @@ public:
}
std::vector<StructurePlacement> placeStructures(
const glm::ivec2& offset, const glm::ivec2& size, uint64_t seed
const glm::ivec2& offset, const glm::ivec2& size, uint64_t seed,
const std::shared_ptr<Heightmap>& heightmap
) override {
std::vector<StructurePlacement> placements;
@@ -110,7 +113,8 @@ public:
lua::pushivec_stack(L, offset);
lua::pushivec_stack(L, size);
lua::pushinteger(L, seed);
if (lua::call_nothrow(L, 5, 1)) {
lua::newuserdata<lua::LuaHeightmap>(L, heightmap);
if (lua::call_nothrow(L, 6, 1)) {
int len = lua::objlen(L, -1);
for (int i = 1; i <= len; i++) {
lua::rawgeti(L, i);
+2 -1
View File
@@ -116,7 +116,8 @@ public:
const glm::ivec2& offset, const glm::ivec2& size, uint64_t seed) = 0;
virtual std::vector<StructurePlacement> placeStructures(
const glm::ivec2& offset, const glm::ivec2& size, uint64_t seed) = 0;
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;
+6 -9
View File
@@ -41,18 +41,14 @@ WorldGenerator::WorldGenerator(
prototypes[{x, z}] = generatePrototype(x, z);
});
surroundMap.setLevelCallback(2, [this](int const x, int const z) {
const auto& found = prototypes.find({x, z});
if (found == prototypes.end()) {
throw std::runtime_error("prototype not found");
}
generateStructures(requirePrototype(x, z), x, z);
});
surroundMap.setLevelCallback(3, [this](int const x, int const z) {
generateBiomes(requirePrototype(x, z), x, z);
});
surroundMap.setLevelCallback(4, [this](int const x, int const z) {
surroundMap.setLevelCallback(3, [this](int const x, int const z) {
generateHeightmap(requirePrototype(x, z), x, z);
});
surroundMap.setLevelCallback(4, [this](int const x, int const z) {
generateStructures(requirePrototype(x, z), x, z);
});
structures = def.script->loadStructures();
for (auto& structure : structures) {
@@ -145,7 +141,8 @@ void WorldGenerator::generateStructures(
return;
}
util::concat(prototype.structures, def.script->placeStructures(
{chunkX * CHUNK_W, chunkZ * CHUNK_D}, {CHUNK_W, CHUNK_D}, seed
{chunkX * CHUNK_W, chunkZ * CHUNK_D}, {CHUNK_W, CHUNK_D}, seed,
prototype.heightmap
));
for (const auto& placement : prototype.structures) {
const auto& offset = placement.position;
+1 -1
View File
@@ -18,7 +18,7 @@ struct Biome;
class VoxelStructure;
enum class ChunkPrototypeLevel {
VOID=0, STRUCTURES, BIOMES, HEIGHTMAP
VOID=0, BIOMES, HEIGHTMAP, STRUCTURES
};
struct ChunkPrototype {