update world generation pipeline
This commit is contained in:
parent
f4793ac9db
commit
001b930212
BIN
res/generators/default.files/tree1.vox
Normal file
BIN
res/generators/default.files/tree1.vox
Normal file
Binary file not shown.
BIN
res/generators/default.files/tree2.vox
Normal file
BIN
res/generators/default.files/tree2.vox
Normal file
Binary file not shown.
@ -45,10 +45,12 @@ biomes = {
|
|||||||
{value=0.2, weight=0.5},
|
{value=0.2, weight=0.5},
|
||||||
},
|
},
|
||||||
sea_layers = {
|
sea_layers = {
|
||||||
|
{block="base:brick", height=1},
|
||||||
{block="base:water", height=-1},
|
{block="base:water", height=-1},
|
||||||
},
|
},
|
||||||
layers = {
|
layers = {
|
||||||
{block="base:stone", height=6},
|
{block="base:grass_block", height=1, below_sea_level=false},
|
||||||
|
{block="base:dirt", height=3, below_sea_level=false},
|
||||||
{block="base:stone", height=-1},
|
{block="base:stone", height=-1},
|
||||||
{block="base:bazalt", height=1},
|
{block="base:bazalt", height=1},
|
||||||
}
|
}
|
||||||
@ -57,7 +59,7 @@ biomes = {
|
|||||||
|
|
||||||
function load_structures()
|
function load_structures()
|
||||||
local structures = {}
|
local structures = {}
|
||||||
local names = {"tree0", "tower"}
|
local names = {"tree0", "tree1", "tree2", "tower"}
|
||||||
for i, name in ipairs(names) do
|
for i, name in ipairs(names) do
|
||||||
local filename = "core:default.files/"..name
|
local filename = "core:default.files/"..name
|
||||||
debug.log("loading structure "..filename)
|
debug.log("loading structure "..filename)
|
||||||
@ -66,9 +68,8 @@ function load_structures()
|
|||||||
return structures
|
return structures
|
||||||
end
|
end
|
||||||
|
|
||||||
function place_structures(x, z, w, d, seed)
|
function place_structures(x, z, w, d, seed, hmap)
|
||||||
local placements = {}
|
local placements = {}
|
||||||
local hmap = generate_heightmap(x, z, w, d, seed)
|
|
||||||
for i=0,math.floor(math.random()*3) do
|
for i=0,math.floor(math.random()*3) do
|
||||||
local px = math.random() * w
|
local px = math.random() * w
|
||||||
local pz = math.random() * d
|
local pz = math.random() * d
|
||||||
@ -76,15 +77,15 @@ function place_structures(x, z, w, d, seed)
|
|||||||
if py <= sea_level then
|
if py <= sea_level then
|
||||||
goto continue
|
goto continue
|
||||||
end
|
end
|
||||||
table.insert(placements, {0, {px-8, py, pz-8}})
|
table.insert(placements, {math.floor(math.random() * 3), {px-8, py, pz-8}})
|
||||||
::continue::
|
::continue::
|
||||||
end
|
end
|
||||||
|
|
||||||
if math.random() < 0.03 then
|
if math.random() < 0.01 then
|
||||||
local px = math.random() * w
|
local px = math.random() * w
|
||||||
local pz = math.random() * d
|
local pz = math.random() * d
|
||||||
local py = hmap:at(px, pz) * 256
|
local py = hmap:at(px, pz) * 256
|
||||||
table.insert(placements, {1, {px-8, py, pz-8}})
|
table.insert(placements, {3, {px-8, py, pz-8}})
|
||||||
end
|
end
|
||||||
return placements
|
return placements
|
||||||
end
|
end
|
||||||
|
|||||||
@ -39,6 +39,7 @@ namespace lua {
|
|||||||
std::shared_ptr<Heightmap> map;
|
std::shared_ptr<Heightmap> map;
|
||||||
std::unique_ptr<fnl_state> noise;
|
std::unique_ptr<fnl_state> noise;
|
||||||
public:
|
public:
|
||||||
|
LuaHeightmap(const std::shared_ptr<Heightmap>& map);
|
||||||
LuaHeightmap(uint width, uint height);
|
LuaHeightmap(uint width, uint height);
|
||||||
|
|
||||||
virtual ~LuaHeightmap();
|
virtual ~LuaHeightmap();
|
||||||
|
|||||||
@ -16,6 +16,10 @@
|
|||||||
|
|
||||||
using namespace lua;
|
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)
|
LuaHeightmap::LuaHeightmap(uint width, uint height)
|
||||||
: map(std::make_shared<Heightmap>(width, height)),
|
: map(std::make_shared<Heightmap>(width, height)),
|
||||||
noise(std::make_unique<fnl_state>(fnlCreateState()))
|
noise(std::make_unique<fnl_state>(fnlCreateState()))
|
||||||
|
|||||||
@ -13,6 +13,8 @@
|
|||||||
#include "data/dv.hpp"
|
#include "data/dv.hpp"
|
||||||
#include "world/generator/GeneratorDef.hpp"
|
#include "world/generator/GeneratorDef.hpp"
|
||||||
|
|
||||||
|
#include "util/timeutil.hpp"
|
||||||
|
|
||||||
class LuaGeneratorScript : public GeneratorScript {
|
class LuaGeneratorScript : public GeneratorScript {
|
||||||
scriptenv env;
|
scriptenv env;
|
||||||
std::vector<Biome> biomes;
|
std::vector<Biome> biomes;
|
||||||
@ -99,7 +101,8 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
std::vector<StructurePlacement> placeStructures(
|
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 {
|
) override {
|
||||||
std::vector<StructurePlacement> placements;
|
std::vector<StructurePlacement> placements;
|
||||||
|
|
||||||
@ -110,7 +113,8 @@ public:
|
|||||||
lua::pushivec_stack(L, offset);
|
lua::pushivec_stack(L, offset);
|
||||||
lua::pushivec_stack(L, size);
|
lua::pushivec_stack(L, size);
|
||||||
lua::pushinteger(L, seed);
|
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);
|
int len = lua::objlen(L, -1);
|
||||||
for (int i = 1; i <= len; i++) {
|
for (int i = 1; i <= len; i++) {
|
||||||
lua::rawgeti(L, i);
|
lua::rawgeti(L, i);
|
||||||
|
|||||||
@ -116,7 +116,8 @@ public:
|
|||||||
const glm::ivec2& offset, const glm::ivec2& size, uint64_t seed) = 0;
|
const glm::ivec2& offset, const glm::ivec2& size, uint64_t seed) = 0;
|
||||||
|
|
||||||
virtual std::vector<StructurePlacement> placeStructures(
|
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
|
/// @brief Get generator biomes
|
||||||
virtual const std::vector<Biome>& getBiomes() const = 0;
|
virtual const std::vector<Biome>& getBiomes() const = 0;
|
||||||
|
|||||||
@ -41,18 +41,14 @@ WorldGenerator::WorldGenerator(
|
|||||||
prototypes[{x, z}] = generatePrototype(x, z);
|
prototypes[{x, z}] = generatePrototype(x, z);
|
||||||
});
|
});
|
||||||
surroundMap.setLevelCallback(2, [this](int const x, int const 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);
|
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);
|
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();
|
structures = def.script->loadStructures();
|
||||||
for (auto& structure : structures) {
|
for (auto& structure : structures) {
|
||||||
@ -145,7 +141,8 @@ void WorldGenerator::generateStructures(
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
util::concat(prototype.structures, def.script->placeStructures(
|
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) {
|
for (const auto& placement : prototype.structures) {
|
||||||
const auto& offset = placement.position;
|
const auto& offset = placement.position;
|
||||||
|
|||||||
@ -18,7 +18,7 @@ struct Biome;
|
|||||||
class VoxelStructure;
|
class VoxelStructure;
|
||||||
|
|
||||||
enum class ChunkPrototypeLevel {
|
enum class ChunkPrototypeLevel {
|
||||||
VOID=0, STRUCTURES, BIOMES, HEIGHTMAP
|
VOID=0, BIOMES, HEIGHTMAP, STRUCTURES
|
||||||
};
|
};
|
||||||
|
|
||||||
struct ChunkPrototype {
|
struct ChunkPrototype {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user