add StructurePlacement & add SurroundMap visualization test

This commit is contained in:
MihailRis
2024-09-20 23:43:54 +03:00
parent 88b0f8e3d6
commit 4f882a3ca3
5 changed files with 72 additions and 9 deletions
+1 -1
View File
@@ -62,7 +62,7 @@ namespace util {
return &firstBuffer[ly * sizeX + lx];
}
T get(TCoord x, TCoord y) {
T get(TCoord x, TCoord y) const {
auto lx = x - offsetX;
auto ly = y - offsetY;
if (lx < 0 || ly < 0 || lx >= sizeX || ly >= sizeY) {
+5 -1
View File
@@ -7,6 +7,7 @@
#include "maths/Heightmap.hpp"
class Content;
class VoxelStructure;
struct BlocksLayer {
/// @brief Layer block
@@ -99,8 +100,11 @@ class GeneratorScript {
public:
virtual ~GeneratorScript() = default;
/// @brief Load all structures
//virtual std::vector<std::shared_ptr<VoxelStructure>> loadStructures() = 0;
/// @brief Generates a heightmap with values in range 0..1
/// @param offset position of the heightmap top left corner in the world
/// @param offset position of the heightmap in the world
/// @param size size of the heightmap
/// @param seed world seed
/// @return generated heightmap of given size (can't be nullptr)
+7 -5
View File
@@ -14,8 +14,8 @@
static debug::Logger logger("world-generator");
static inline constexpr uint MAX_PARAMETERS = 8;
static inline constexpr uint MAX_CHUNK_PROTOTYPE_LEVELS = 8;
static inline constexpr uint MAX_PARAMETERS = 4;
static inline constexpr uint MAX_CHUNK_PROTOTYPE_LEVELS = 3;
WorldGenerator::WorldGenerator(
const GeneratorDef& def, const Content* content, uint64_t seed
@@ -114,10 +114,11 @@ std::unique_ptr<ChunkPrototype> WorldGenerator::generatePrototype(
{chunkX * CHUNK_W, chunkZ * CHUNK_D}, {CHUNK_W, CHUNK_D}, seed);
const auto& biomes = def.script->getBiomes();
std::vector<const Biome*> chunkBiomes(CHUNK_W*CHUNK_D);
auto chunkBiomes = std::make_unique<const Biome*[]>(CHUNK_W*CHUNK_D);
for (uint z = 0; z < CHUNK_D; z++) {
for (uint x = 0; x < CHUNK_W; x++) {
chunkBiomes[z * CHUNK_W + x] = choose_biome(biomes, biomeParams, x, z);
chunkBiomes.get()[z * CHUNK_W + x] =
choose_biome(biomes, biomeParams, x, z);
}
}
return std::make_unique<ChunkPrototype>(
@@ -162,9 +163,10 @@ void WorldGenerator::generate(voxel* voxels, int chunkX, int chunkZ) {
PseudoRandom plantsRand;
plantsRand.setSeed(chunkX, chunkZ);
const auto& biomes = prototype->biomes.get();
for (uint z = 0; z < CHUNK_D; z++) {
for (uint x = 0; x < CHUNK_W; x++) {
const Biome* biome = prototype->biomes[z * CHUNK_W + x];
const Biome* biome = biomes[z * CHUNK_W + x];
int height = values[z * CHUNK_W + x] * CHUNK_H;
height = std::max(0, height);
+13 -2
View File
@@ -20,18 +20,29 @@ enum class ChunkPrototypeLevel {
BIOMES, HEIGHTMAP
};
struct StructurePlacement {
VoxelStructure& structure;
glm::ivec3 position;
StructurePlacement(VoxelStructure& structure, glm::ivec3 position)
: structure(structure), position(std::move(position)) {}
};
struct ChunkPrototype {
ChunkPrototypeLevel level;
/// @brief chunk biomes matrix
std::vector<const Biome*> biomes;
std::unique_ptr<const Biome*[]> biomes;
/// @brief chunk heightmap
std::shared_ptr<Heightmap> heightmap;
std::vector<StructurePlacement> structures;
ChunkPrototype(
ChunkPrototypeLevel level,
std::vector<const Biome*> biomes,
std::unique_ptr<const Biome*[]> biomes,
std::shared_ptr<Heightmap> heightmap
) : level(level),
biomes(std::move(biomes)),