add chunk_height parameter to place_structures

This commit is contained in:
MihailRis
2024-09-29 23:39:42 +03:00
parent abc8eccab8
commit 16fac768c8
4 changed files with 9 additions and 7 deletions
@@ -1,10 +1,10 @@
function place_structures(x, z, w, d, seed, hmap) function place_structures(x, z, w, d, seed, hmap, chunk_height)
local placements = {} local placements = {}
for i=1,10 do for i=1,10 do
local sx = math.random() * w local sx = math.random() * w
local sz = math.random() * d local sz = math.random() * d
local sy = math.random() * 128 local sy = math.random() * (chunk_height * 0.5)
if sy < hmap:at(sx, sz) * 256 - 6 then if sy < hmap:at(sx, sz) * chunk_height - 6 then
table.insert(placements, {"coal_ore0", {sx, sy, sz}, math.random()*4}) table.insert(placements, {"coal_ore0", {sx, sy, sz}, math.random()*4})
end end
end end
@@ -76,7 +76,7 @@ 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 const std::shared_ptr<Heightmap>& heightmap, uint chunkHeight
) override { ) override {
std::vector<StructurePlacement> placements; std::vector<StructurePlacement> placements;
@@ -88,7 +88,8 @@ public:
lua::pushivec_stack(L, size); lua::pushivec_stack(L, size);
lua::pushinteger(L, seed); lua::pushinteger(L, seed);
lua::newuserdata<lua::LuaHeightmap>(L, heightmap); lua::newuserdata<lua::LuaHeightmap>(L, heightmap);
if (lua::call_nothrow(L, 6, 1)) { lua::pushinteger(L, chunkHeight);
if (lua::call_nothrow(L, 7, 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);
+2 -1
View File
@@ -155,10 +155,11 @@ public:
/// @param size size of the area (blocks) /// @param size size of the area (blocks)
/// @param seed world seed /// @param seed world seed
/// @param heightmap area heightmap /// @param heightmap area heightmap
/// @param chunkHeight chunk height to use as heights multiplier
/// @return structure placements /// @return structure placements
virtual std::vector<StructurePlacement> placeStructures( virtual 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) = 0; const std::shared_ptr<Heightmap>& heightmap, uint chunkHeight) = 0;
}; };
/// @brief Structure voxel fragments and metadata /// @brief Structure voxel fragments and metadata
+1 -1
View File
@@ -177,7 +177,7 @@ void WorldGenerator::generateStructures(
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,
heightmap heightmap, CHUNK_H
)); ));
for (const auto& placement : prototype.structures) { for (const auto& placement : prototype.structures) {
const auto& offset = placement.position; const auto& offset = placement.position;