add placements priority
This commit is contained in:
parent
fb53b3941c
commit
b5c1050f43
@ -1,3 +1,3 @@
|
|||||||
[
|
[
|
||||||
{"struct": "coal_ore0", "rarity": 22000}
|
{"struct": "coal_ore0", "rarity": 4400}
|
||||||
]
|
]
|
||||||
|
|||||||
@ -17,7 +17,7 @@ local function place_ores(placements, x, z, w, d, seed, hmap, chunk_height)
|
|||||||
local sz = math.random() * d
|
local sz = math.random() * d
|
||||||
local sy = math.random() * (chunk_height * 0.5)
|
local sy = math.random() * (chunk_height * 0.5)
|
||||||
if sy < hmap:at(sx, sz) * chunk_height - 6 then
|
if sy < hmap:at(sx, sz) * chunk_height - 6 then
|
||||||
table.insert(placements, {ore.struct, {sx, sy, sz}, math.random()*4})
|
table.insert(placements, {ore.struct, {sx, sy, sz}, math.random()*4, -1})
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -33,7 +33,7 @@ function place_structures_wide(x, z, w, d, seed, chunk_height)
|
|||||||
local placements = {}
|
local placements = {}
|
||||||
if math.random() < 0.05 then -- generate caves
|
if math.random() < 0.05 then -- generate caves
|
||||||
local sx = x + math.random() * 10 - 5
|
local sx = x + math.random() * 10 - 5
|
||||||
local sy = math.random() * (chunk_height / 4) + 27
|
local sy = math.random() * (chunk_height / 4) + 10
|
||||||
local sz = z + math.random() * 10 - 5
|
local sz = z + math.random() * 10 - 5
|
||||||
|
|
||||||
local dir = math.random() * math.pi * 2
|
local dir = math.random() * math.pi * 2
|
||||||
|
|||||||
@ -84,7 +84,7 @@ public:
|
|||||||
return maps;
|
return maps;
|
||||||
}
|
}
|
||||||
|
|
||||||
void perform_line(lua::State* L, PrototypePlacements& placements) {
|
void perform_line(lua::State* L, std::vector<Placement>& placements) {
|
||||||
rawgeti(L, 2);
|
rawgeti(L, 2);
|
||||||
blockid_t block = touinteger(L, -1);
|
blockid_t block = touinteger(L, -1);
|
||||||
pop(L);
|
pop(L);
|
||||||
@ -101,10 +101,17 @@ public:
|
|||||||
int radius = touinteger(L, -1);
|
int radius = touinteger(L, -1);
|
||||||
pop(L);
|
pop(L);
|
||||||
|
|
||||||
placements.lines.emplace_back(block, a, b, radius);
|
int priority = 0;
|
||||||
|
if (objlen(L, -1) >= 6) {
|
||||||
|
rawgeti(L, 6);
|
||||||
|
priority = tointeger(L, -1);
|
||||||
|
pop(L);
|
||||||
|
}
|
||||||
|
|
||||||
|
placements.emplace_back(priority, LinePlacement {block, a, b, radius});
|
||||||
}
|
}
|
||||||
|
|
||||||
void perform_placement(lua::State* L, PrototypePlacements& placements) {
|
void perform_placement(lua::State* L, std::vector<Placement>& placements) {
|
||||||
rawgeti(L, 1);
|
rawgeti(L, 1);
|
||||||
int structIndex = 0;
|
int structIndex = 0;
|
||||||
if (isstring(L, -1)) {
|
if (isstring(L, -1)) {
|
||||||
@ -129,19 +136,28 @@ public:
|
|||||||
pop(L);
|
pop(L);
|
||||||
|
|
||||||
rawgeti(L, 3);
|
rawgeti(L, 3);
|
||||||
int rotation = tointeger(L, -1) & 0b11;
|
uint8_t rotation = tointeger(L, -1) & 0b11;
|
||||||
pop(L);
|
pop(L);
|
||||||
|
|
||||||
placements.structs.emplace_back(structIndex, pos, rotation);
|
int priority = 1;
|
||||||
|
if (objlen(L, -1) >= 4) {
|
||||||
|
rawgeti(L, 4);
|
||||||
|
priority = tointeger(L, -1);
|
||||||
|
pop(L);
|
||||||
|
}
|
||||||
|
|
||||||
|
placements.emplace_back(
|
||||||
|
priority, StructurePlacement {structIndex, pos, rotation}
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
PrototypePlacements placeStructuresWide(
|
std::vector<Placement> placeStructuresWide(
|
||||||
const glm::ivec2& offset,
|
const glm::ivec2& offset,
|
||||||
const glm::ivec2& size,
|
const glm::ivec2& size,
|
||||||
uint64_t seed,
|
uint64_t seed,
|
||||||
uint chunkHeight
|
uint chunkHeight
|
||||||
) override {
|
) override {
|
||||||
PrototypePlacements placements {};
|
std::vector<Placement> placements {};
|
||||||
|
|
||||||
stackguard _(L);
|
stackguard _(L);
|
||||||
pushenv(L, *env);
|
pushenv(L, *env);
|
||||||
@ -165,11 +181,11 @@ public:
|
|||||||
return placements;
|
return placements;
|
||||||
}
|
}
|
||||||
|
|
||||||
PrototypePlacements placeStructures(
|
std::vector<Placement> 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, uint chunkHeight
|
const std::shared_ptr<Heightmap>& heightmap, uint chunkHeight
|
||||||
) override {
|
) override {
|
||||||
PrototypePlacements placements {};
|
std::vector<Placement> placements {};
|
||||||
|
|
||||||
stackguard _(L);
|
stackguard _(L);
|
||||||
pushenv(L, *env);
|
pushenv(L, *env);
|
||||||
|
|||||||
@ -118,11 +118,6 @@ struct Biome {
|
|||||||
BlocksLayers seaLayers;
|
BlocksLayers seaLayers;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct PrototypePlacements {
|
|
||||||
std::vector<StructurePlacement> structs {};
|
|
||||||
std::vector<LinePlacement> lines {};
|
|
||||||
};
|
|
||||||
|
|
||||||
/// @brief Generator behaviour and settings interface
|
/// @brief Generator behaviour and settings interface
|
||||||
class GeneratorScript {
|
class GeneratorScript {
|
||||||
public:
|
public:
|
||||||
@ -154,7 +149,7 @@ public:
|
|||||||
uint bpd
|
uint bpd
|
||||||
) = 0;
|
) = 0;
|
||||||
|
|
||||||
virtual PrototypePlacements placeStructuresWide(
|
virtual std::vector<Placement> placeStructuresWide(
|
||||||
const glm::ivec2& offset,
|
const glm::ivec2& offset,
|
||||||
const glm::ivec2& size,
|
const glm::ivec2& size,
|
||||||
uint64_t seed,
|
uint64_t seed,
|
||||||
@ -169,7 +164,7 @@ public:
|
|||||||
/// @param heightmap area heightmap
|
/// @param heightmap area heightmap
|
||||||
/// @param chunkHeight chunk height to use as heights multiplier
|
/// @param chunkHeight chunk height to use as heights multiplier
|
||||||
/// @return structure & line placements
|
/// @return structure & line placements
|
||||||
virtual PrototypePlacements placeStructures(
|
virtual std::vector<Placement> 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, uint chunkHeight) = 0;
|
const std::shared_ptr<Heightmap>& heightmap, uint chunkHeight) = 0;
|
||||||
};
|
};
|
||||||
|
|||||||
@ -1,5 +1,6 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include <variant>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <glm/glm.hpp>
|
#include <glm/glm.hpp>
|
||||||
|
|
||||||
@ -25,3 +26,13 @@ struct LinePlacement {
|
|||||||
: block(block), a(std::move(a)), b(std::move(b)), radius(radius) {
|
: block(block), a(std::move(a)), b(std::move(b)), radius(radius) {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct Placement {
|
||||||
|
int priority;
|
||||||
|
std::variant<StructurePlacement, LinePlacement> placement;
|
||||||
|
|
||||||
|
Placement(
|
||||||
|
int priority,
|
||||||
|
std::variant<StructurePlacement, LinePlacement> placement
|
||||||
|
) : priority(priority), placement(std::move(placement)) {}
|
||||||
|
};
|
||||||
|
|||||||
@ -1,6 +1,7 @@
|
|||||||
#include "WorldGenerator.hpp"
|
#include "WorldGenerator.hpp"
|
||||||
|
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
|
#include <algorithm>
|
||||||
|
|
||||||
#include "maths/util.hpp"
|
#include "maths/util.hpp"
|
||||||
#include "content/Content.hpp"
|
#include "content/Content.hpp"
|
||||||
@ -147,34 +148,36 @@ inline AABB gen_chunk_aabb(int chunkX, int chunkZ) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void WorldGenerator::placeStructure(
|
void WorldGenerator::placeStructure(
|
||||||
const glm::ivec3& offset, size_t structureId, uint8_t rotation,
|
const StructurePlacement& placement, int priority,
|
||||||
int chunkX, int chunkZ
|
int chunkX, int chunkZ
|
||||||
) {
|
) {
|
||||||
auto& structure = *def.structures[structureId]->fragments[rotation];
|
auto& structure =
|
||||||
auto position = glm::ivec3(chunkX * CHUNK_W, 0, chunkZ * CHUNK_D)+offset;
|
*def.structures[placement.structure]->fragments[placement.rotation];
|
||||||
|
auto position =
|
||||||
|
glm::ivec3(chunkX * CHUNK_W, 0, chunkZ * CHUNK_D) + placement.position;
|
||||||
auto size = structure.getSize() + glm::ivec3(0, CHUNK_H, 0);
|
auto size = structure.getSize() + glm::ivec3(0, CHUNK_H, 0);
|
||||||
AABB aabb(position, position + size);
|
AABB aabb(position, position + size);
|
||||||
for (int lcz = -1; lcz <= 1; lcz++) {
|
for (int lcz = -1; lcz <= 1; lcz++) {
|
||||||
for (int lcx = -1; lcx <= 1; lcx++) {
|
for (int lcx = -1; lcx <= 1; lcx++) {
|
||||||
if (lcx == 0 && lcz == 0) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
auto& otherPrototype = requirePrototype(
|
auto& otherPrototype = requirePrototype(
|
||||||
chunkX + lcx, chunkZ + lcz
|
chunkX + lcx, chunkZ + lcz
|
||||||
);
|
);
|
||||||
auto chunkAABB = gen_chunk_aabb(chunkX + lcx, chunkZ + lcz);
|
auto chunkAABB = gen_chunk_aabb(chunkX + lcx, chunkZ + lcz);
|
||||||
if (chunkAABB.intersect(aabb)) {
|
if (chunkAABB.intersect(aabb)) {
|
||||||
otherPrototype.structures.emplace_back(
|
otherPrototype.placements.emplace_back(
|
||||||
structureId,
|
priority,
|
||||||
offset - glm::ivec3(lcx * CHUNK_W, 0, lcz * CHUNK_D),
|
StructurePlacement {
|
||||||
rotation
|
placement.structure,
|
||||||
|
placement.position -
|
||||||
|
glm::ivec3(lcx * CHUNK_W, 0, lcz * CHUNK_D),
|
||||||
|
placement.rotation}
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void WorldGenerator::placeLine(const LinePlacement& line) {
|
void WorldGenerator::placeLine(const LinePlacement& line, int priority) {
|
||||||
AABB aabb(line.a, line.b);
|
AABB aabb(line.a, line.b);
|
||||||
aabb.fix();
|
aabb.fix();
|
||||||
aabb.a -= line.radius;
|
aabb.a -= line.radius;
|
||||||
@ -187,30 +190,29 @@ void WorldGenerator::placeLine(const LinePlacement& line) {
|
|||||||
for (int cx = cxa; cx <= cxb; cx++) {
|
for (int cx = cxa; cx <= cxb; cx++) {
|
||||||
const auto& found = prototypes.find({cx, cz});
|
const auto& found = prototypes.find({cx, cz});
|
||||||
if (found != prototypes.end()) {
|
if (found != prototypes.end()) {
|
||||||
found->second->lines.push_back(line);
|
found->second->placements.emplace_back(priority, line);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void WorldGenerator::placeStructures(
|
void WorldGenerator::placeStructures(
|
||||||
const PrototypePlacements& placements,
|
const std::vector<Placement>& placements,
|
||||||
ChunkPrototype& prototype,
|
ChunkPrototype& prototype,
|
||||||
int chunkX,
|
int chunkX,
|
||||||
int chunkZ
|
int chunkZ
|
||||||
) {
|
) {
|
||||||
util::concat(prototype.structures, placements.structs);
|
for (const auto& placement : placements) {
|
||||||
for (const auto& placement : prototype.structures) {
|
if (auto sp = std::get_if<StructurePlacement>(&placement.placement)) {
|
||||||
const auto& offset = placement.position;
|
if (sp->structure < 0 || sp->structure >= def.structures.size()) {
|
||||||
if (placement.structure < 0 || placement.structure >= def.structures.size()) {
|
logger.error() << "invalid structure index " << sp->structure;
|
||||||
logger.error() << "invalid structure index " << placement.structure;
|
continue;
|
||||||
continue;
|
}
|
||||||
|
placeStructure(*sp, placement.priority, chunkX, chunkZ);
|
||||||
|
} else {
|
||||||
|
const auto& line = std::get<LinePlacement>(placement.placement);
|
||||||
|
placeLine(line, placement.priority);
|
||||||
}
|
}
|
||||||
placeStructure(
|
|
||||||
offset, placement.structure, placement.rotation, chunkX, chunkZ);
|
|
||||||
}
|
|
||||||
for (const auto& line : placements.lines) {
|
|
||||||
placeLine(line);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -251,7 +253,7 @@ void WorldGenerator::generateStructures(
|
|||||||
for (uint x = 0; x < CHUNK_W; x++) {
|
for (uint x = 0; x < CHUNK_W; x++) {
|
||||||
float rand = structsRand.randFloat();
|
float rand = structsRand.randFloat();
|
||||||
const Biome* biome = biomes[z * CHUNK_W + x];
|
const Biome* biome = biomes[z * CHUNK_W + x];
|
||||||
size_t structureId = biome->structures.choose(rand, -1);
|
int structureId = biome->structures.choose(rand, -1);
|
||||||
if (structureId == -1) {
|
if (structureId == -1) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@ -264,12 +266,16 @@ void WorldGenerator::generateStructures(
|
|||||||
glm::ivec3 position {x, height, z};
|
glm::ivec3 position {x, height, z};
|
||||||
position.x -= structure.getSize().x / 2;
|
position.x -= structure.getSize().x / 2;
|
||||||
position.z -= structure.getSize().z / 2;
|
position.z -= structure.getSize().z / 2;
|
||||||
prototype.structures.push_back({
|
prototype.placements.emplace_back(
|
||||||
static_cast<int>(structureId), position, rotation});
|
1, StructurePlacement {structureId, position, rotation}
|
||||||
|
);
|
||||||
placeStructure(
|
placeStructure(
|
||||||
position,
|
StructurePlacement {
|
||||||
structureId,
|
structureId,
|
||||||
rotation,
|
position,
|
||||||
|
rotation
|
||||||
|
},
|
||||||
|
1,
|
||||||
chunkX,
|
chunkX,
|
||||||
chunkZ
|
chunkZ
|
||||||
);
|
);
|
||||||
@ -361,6 +367,9 @@ void WorldGenerator::generatePlants(
|
|||||||
blockid_t plant = biome->plants.choose(rand);
|
blockid_t plant = biome->plants.choose(rand);
|
||||||
if (plant) {
|
if (plant) {
|
||||||
auto& voxel = voxels[vox_index(x, height+1, z)];
|
auto& voxel = voxels[vox_index(x, height+1, z)];
|
||||||
|
if (voxel.id) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
auto& groundVoxel = voxels[vox_index(x, height, z)];
|
auto& groundVoxel = voxels[vox_index(x, height, z)];
|
||||||
if (indices.get(groundVoxel.id)->rt.solid) {
|
if (indices.get(groundVoxel.id)->rt.solid) {
|
||||||
voxel = {plant, {}};
|
voxel = {plant, {}};
|
||||||
@ -422,9 +431,8 @@ void WorldGenerator::generate(voxel* voxels, int chunkX, int chunkZ) {
|
|||||||
generate_pole(groundLayers, height, 0, seaLevel, voxels, x, z);
|
generate_pole(groundLayers, height, 0, seaLevel, voxels, x, z);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
generateLines(prototype, voxels, chunkX, chunkZ);
|
generatePlacements(prototype, voxels, chunkX, chunkZ);
|
||||||
generatePlants(prototype, values, voxels, chunkX, chunkZ, biomes);
|
generatePlants(prototype, values, voxels, chunkX, chunkZ, biomes);
|
||||||
generateStructures(prototype, voxels, chunkX, chunkZ);
|
|
||||||
|
|
||||||
#ifndef NDEBUG
|
#ifndef NDEBUG
|
||||||
for (uint i = 0; i < CHUNK_VOL; i++) {
|
for (uint i = 0; i < CHUNK_VOL; i++) {
|
||||||
@ -436,42 +444,64 @@ void WorldGenerator::generate(voxel* voxels, int chunkX, int chunkZ) {
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void WorldGenerator::generateStructures(
|
void WorldGenerator::generatePlacements(
|
||||||
const ChunkPrototype& prototype, voxel* voxels, int chunkX, int chunkZ
|
const ChunkPrototype& prototype, voxel* voxels, int chunkX, int chunkZ
|
||||||
) {
|
) {
|
||||||
for (const auto& placement : prototype.structures) {
|
auto placements = prototype.placements;
|
||||||
if (placement.structure < 0 || placement.structure >= def.structures.size()) {
|
std::stable_sort(
|
||||||
logger.error() << "invalid structure index " << placement.structure;
|
placements.begin(),
|
||||||
|
placements.end(),
|
||||||
|
[](const auto& a, const auto& b) {
|
||||||
|
return a.priority < b.priority;
|
||||||
|
}
|
||||||
|
);
|
||||||
|
for (const auto& placement : placements) {
|
||||||
|
if (auto structure = std::get_if<StructurePlacement>(&placement.placement)) {
|
||||||
|
generateStructure(prototype, *structure, voxels, chunkX, chunkZ);
|
||||||
|
} else {
|
||||||
|
const auto& line = std::get<LinePlacement>(placement.placement);
|
||||||
|
generateLine(prototype, line, voxels, chunkX, chunkZ);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void WorldGenerator::generateStructure(
|
||||||
|
const ChunkPrototype& prototype,
|
||||||
|
const StructurePlacement& placement,
|
||||||
|
voxel* voxels,
|
||||||
|
int chunkX, int chunkZ
|
||||||
|
) {
|
||||||
|
if (placement.structure < 0 || placement.structure >= def.structures.size()) {
|
||||||
|
logger.error() << "invalid structure index " << placement.structure;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
auto& generatingStructure = def.structures[placement.structure];
|
||||||
|
auto& structure = *generatingStructure->fragments[placement.rotation];
|
||||||
|
auto& structVoxels = structure.getRuntimeVoxels();
|
||||||
|
const auto& offset = placement.position;
|
||||||
|
const auto& size = structure.getSize();
|
||||||
|
for (int y = 0; y < size.y; y++) {
|
||||||
|
int sy = y + offset.y;
|
||||||
|
if (sy < 0 || sy >= CHUNK_H) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
auto& generatingStructure = def.structures[placement.structure];
|
for (int z = 0; z < size.z; z++) {
|
||||||
auto& structure = *generatingStructure->fragments[placement.rotation];
|
int sz = z + offset.z;
|
||||||
auto& structVoxels = structure.getRuntimeVoxels();
|
if (sz < 0 || sz >= CHUNK_D) {
|
||||||
const auto& offset = placement.position;
|
|
||||||
const auto& size = structure.getSize();
|
|
||||||
for (int y = 0; y < size.y; y++) {
|
|
||||||
int sy = y + offset.y;
|
|
||||||
if (sy < 0 || sy >= CHUNK_H) {
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
for (int z = 0; z < size.z; z++) {
|
for (int x = 0; x < size.x; x++) {
|
||||||
int sz = z + offset.z;
|
int sx = x + offset.x;
|
||||||
if (sz < 0 || sz >= CHUNK_D) {
|
if (sx < 0 || sx >= CHUNK_W) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
for (int x = 0; x < size.x; x++) {
|
const auto& structVoxel =
|
||||||
int sx = x + offset.x;
|
structVoxels[vox_index(x, y, z, size.x, size.z)];
|
||||||
if (sx < 0 || sx >= CHUNK_W) {
|
if (structVoxel.id) {
|
||||||
continue;
|
if (structVoxel.id == BLOCK_STRUCT_AIR) {
|
||||||
}
|
voxels[vox_index(sx, sy, sz)] = {0, {}};
|
||||||
const auto& structVoxel =
|
} else {
|
||||||
structVoxels[vox_index(x, y, z, size.x, size.z)];
|
voxels[vox_index(sx, sy, sz)] = structVoxel;
|
||||||
if (structVoxel.id) {
|
|
||||||
if (structVoxel.id == BLOCK_STRUCT_AIR) {
|
|
||||||
voxels[vox_index(sx, sy, sz)] = {0, {}};
|
|
||||||
} else {
|
|
||||||
voxels[vox_index(sx, sy, sz)] = structVoxel;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -479,51 +509,56 @@ void WorldGenerator::generateStructures(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void WorldGenerator::generateLines(
|
void WorldGenerator::generateLine(
|
||||||
const ChunkPrototype& prototype, voxel* voxels, int chunkX, int chunkZ
|
const ChunkPrototype& prototype,
|
||||||
|
const LinePlacement& line,
|
||||||
|
voxel* voxels,
|
||||||
|
int chunkX, int chunkZ
|
||||||
) {
|
) {
|
||||||
const auto& indices = content->getIndices()->blocks;
|
const auto& indices = content->getIndices()->blocks;
|
||||||
for (const auto& line : prototype.lines) {
|
|
||||||
int cgx = chunkX * CHUNK_W;
|
|
||||||
int cgz = chunkZ * CHUNK_D;
|
|
||||||
|
|
||||||
int const radius = line.radius;
|
int cgx = chunkX * CHUNK_W;
|
||||||
|
int cgz = chunkZ * CHUNK_D;
|
||||||
|
|
||||||
auto a = line.a;
|
int const radius = line.radius;
|
||||||
auto b = line.b;
|
|
||||||
|
|
||||||
int minX = std::max(0, std::min(a.x-radius-cgx, b.x-radius-cgx));
|
auto a = line.a;
|
||||||
int maxX = std::min(CHUNK_W, std::max(a.x+radius-cgx, b.x+radius-cgx));
|
auto b = line.b;
|
||||||
|
|
||||||
int minZ = std::max(0, std::min(a.z-radius-cgz, b.z-radius-cgz));
|
int minX = std::max(0, std::min(a.x-radius-cgx, b.x-radius-cgx));
|
||||||
int maxZ = std::min(CHUNK_D, std::max(a.z+radius-cgz, b.z+radius-cgz));
|
int maxX = std::min(CHUNK_W, std::max(a.x+radius-cgx, b.x+radius-cgx));
|
||||||
|
|
||||||
int minY = std::max(0, std::min(a.y-radius, b.y-radius));
|
int minZ = std::max(0, std::min(a.z-radius-cgz, b.z-radius-cgz));
|
||||||
int maxY = std::min(CHUNK_H, std::max(a.y+radius, b.y+radius));
|
int maxZ = std::min(CHUNK_D, std::max(a.z+radius-cgz, b.z+radius-cgz));
|
||||||
|
|
||||||
for (int y = minY; y < maxY; y++) {
|
int minY = std::max(0, std::min(a.y-radius, b.y-radius));
|
||||||
for (int z = minZ; z < maxZ; z++) {
|
int maxY = std::min(CHUNK_H, std::max(a.y+radius, b.y+radius));
|
||||||
for (int x = minX; x < maxX; x++) {
|
|
||||||
int gx = x + cgx;
|
for (int y = minY; y < maxY; y++) {
|
||||||
int gz = z + cgz;
|
for (int z = minZ; z < maxZ; z++) {
|
||||||
glm::ivec3 point {gx, y, gz};
|
for (int x = minX; x < maxX; x++) {
|
||||||
glm::ivec3 closest = util::closest_point_on_segment(
|
int gx = x + cgx;
|
||||||
a, b, point
|
int gz = z + cgz;
|
||||||
|
glm::ivec3 point {gx, y, gz};
|
||||||
|
glm::ivec3 closest = util::closest_point_on_segment(
|
||||||
|
a, b, point
|
||||||
|
);
|
||||||
|
if (y > 0 &&
|
||||||
|
util::distance2(closest, point) <= radius * radius &&
|
||||||
|
line.block == BLOCK_AIR
|
||||||
|
) {
|
||||||
|
auto& voxel = voxels[vox_index(x, y, z)];
|
||||||
|
if (!indices.require(voxel.id).replaceable) {
|
||||||
|
voxel = {line.block, {}};
|
||||||
|
}
|
||||||
|
auto& below = voxels[vox_index(x, y-1, z)];
|
||||||
|
glm::ivec3 closest2 = util::closest_point_on_segment(
|
||||||
|
a, b, {gx, y-1, gz}
|
||||||
);
|
);
|
||||||
if (y > 0 && util::distance2(closest, point) <= radius*radius && line.block == BLOCK_AIR) {
|
if (util::distance2(closest2, {gx, y-1, gz}) > radius*radius) {
|
||||||
auto& voxel = voxels[vox_index(x, y, z)];
|
const auto& def = indices.require(below.id);
|
||||||
if (!indices.require(voxel.id).replaceable) {
|
if (def.rt.surfaceReplacement != below.id) {
|
||||||
voxel = {line.block, {}};
|
below = {def.rt.surfaceReplacement, {}};
|
||||||
}
|
|
||||||
auto& below = voxels[vox_index(x, y-1, z)];
|
|
||||||
glm::ivec3 closest2 = util::closest_point_on_segment(
|
|
||||||
a, b, {gx, y-1, gz}
|
|
||||||
);
|
|
||||||
if (util::distance2(closest2, {gx, y-1, gz}) > radius*radius) {
|
|
||||||
const auto& def = indices.require(below.id);
|
|
||||||
if (def.rt.surfaceReplacement != below.id) {
|
|
||||||
below = {def.rt.surfaceReplacement, {}};
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -17,7 +17,6 @@ struct GeneratorDef;
|
|||||||
class Heightmap;
|
class Heightmap;
|
||||||
struct Biome;
|
struct Biome;
|
||||||
class VoxelFragment;
|
class VoxelFragment;
|
||||||
struct PrototypePlacements;
|
|
||||||
|
|
||||||
enum class ChunkPrototypeLevel {
|
enum class ChunkPrototypeLevel {
|
||||||
VOID=0, WIDE_STRUCTS, BIOMES, HEIGHTMAP, STRUCTURES
|
VOID=0, WIDE_STRUCTS, BIOMES, HEIGHTMAP, STRUCTURES
|
||||||
@ -32,9 +31,7 @@ struct ChunkPrototype {
|
|||||||
/// @brief chunk heightmap
|
/// @brief chunk heightmap
|
||||||
std::shared_ptr<Heightmap> heightmap;
|
std::shared_ptr<Heightmap> heightmap;
|
||||||
|
|
||||||
std::vector<StructurePlacement> structures;
|
std::vector<Placement> placements;
|
||||||
|
|
||||||
std::vector<LinePlacement> lines;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
struct WorldGenDebugInfo {
|
struct WorldGenDebugInfo {
|
||||||
@ -69,22 +66,32 @@ class WorldGenerator {
|
|||||||
|
|
||||||
void generateStructures(ChunkPrototype& prototype, int x, int z);
|
void generateStructures(ChunkPrototype& prototype, int x, int z);
|
||||||
|
|
||||||
|
void generatePlacements(
|
||||||
|
const ChunkPrototype& prototype, voxel* voxels, int x, int z
|
||||||
|
);
|
||||||
|
|
||||||
void generateBiomes(ChunkPrototype& prototype, int x, int z);
|
void generateBiomes(ChunkPrototype& prototype, int x, int z);
|
||||||
|
|
||||||
void generateHeightmap(ChunkPrototype& prototype, int x, int z);
|
void generateHeightmap(ChunkPrototype& prototype, int x, int z);
|
||||||
|
|
||||||
void placeStructure(
|
void placeStructure(
|
||||||
const glm::ivec3& offset, size_t structure, uint8_t rotation,
|
const StructurePlacement& placement, int priority,
|
||||||
int chunkX, int chunkZ
|
int chunkX, int chunkZ
|
||||||
);
|
);
|
||||||
|
|
||||||
void placeLine(const LinePlacement& line);
|
void placeLine(const LinePlacement& line, int priority);
|
||||||
|
|
||||||
void generateLines(
|
void generateLine(
|
||||||
const ChunkPrototype& prototype, voxel* voxels, int x, int z
|
const ChunkPrototype& prototype,
|
||||||
|
const LinePlacement& placement,
|
||||||
|
voxel* voxels,
|
||||||
|
int x, int z
|
||||||
);
|
);
|
||||||
void generateStructures(
|
void generateStructure(
|
||||||
const ChunkPrototype& prototype, voxel* voxels, int x, int z
|
const ChunkPrototype& prototype,
|
||||||
|
const StructurePlacement& placement,
|
||||||
|
voxel* voxels,
|
||||||
|
int x, int z
|
||||||
);
|
);
|
||||||
void generatePlants(
|
void generatePlants(
|
||||||
const ChunkPrototype& prototype,
|
const ChunkPrototype& prototype,
|
||||||
@ -104,7 +111,7 @@ class WorldGenerator {
|
|||||||
);
|
);
|
||||||
|
|
||||||
void placeStructures(
|
void placeStructures(
|
||||||
const PrototypePlacements& placements,
|
const std::vector<Placement>& placements,
|
||||||
ChunkPrototype& prototype,
|
ChunkPrototype& prototype,
|
||||||
int x, int z);
|
int x, int z);
|
||||||
public:
|
public:
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user