refactor WorldGenerator & update test generator script

This commit is contained in:
MihailRis
2024-08-23 03:07:02 +03:00
parent f2395dede8
commit f40ff7cd28
4 changed files with 23 additions and 18 deletions
+10 -12
View File
@@ -7,23 +7,24 @@
#include "content/Content.hpp"
#include "voxels/Block.hpp"
#include "voxels/Chunk.hpp"
#include "voxels/voxel.hpp"
#include "world/generator/GeneratorDef.hpp"
#include "util/timeutil.hpp"
static inline constexpr uint MAX_PARAMETERS = 16;
WorldGenerator::WorldGenerator(const GeneratorDef& def, const Content* content)
: def(def), content(content) {
WorldGenerator::WorldGenerator(
const GeneratorDef& def, const Content* content, uint64_t seed
)
: def(def), content(content), seed(seed) {
voxel voxels[CHUNK_VOL];
}
static inline void generate_pole(
const BlocksLayers& layers,
int top,
int bottom,
int top, int bottom,
int seaLevel,
voxel* voxels,
int x,
int z
int x, int z
) {
uint y = top;
uint layerExtension = 0;
@@ -75,11 +76,8 @@ static inline const Biome* choose_biome(
return chosenBiome;
}
#include "util/timeutil.hpp"
void WorldGenerator::generate(
voxel* voxels, int chunkX, int chunkZ, uint64_t seed
) {
timeutil::ScopeLogTimer log(555);
void WorldGenerator::generate(voxel* voxels, int chunkX, int chunkZ) {
// timeutil::ScopeLogTimer log(555);
auto heightmap = def.script->generateHeightmap(
{chunkX * CHUNK_W, chunkZ * CHUNK_D}, {CHUNK_W, CHUNK_D}, seed
);
+9 -3
View File
@@ -1,8 +1,10 @@
#pragma once
#include <string>
#include <memory>
#include "typedefs.hpp"
#include "voxels/voxel.hpp"
struct voxel;
class Content;
@@ -12,10 +14,15 @@ struct GeneratorDef;
class WorldGenerator {
const GeneratorDef& def;
const Content* content;
uint64_t seed;
public:
/// @param def generator definition
/// @param content world content
/// @param seed world seed
WorldGenerator(
const GeneratorDef& def,
const Content* content
const Content* content,
uint64_t seed
);
virtual ~WorldGenerator() = default;
@@ -23,8 +30,7 @@ public:
/// @param voxels destinatiopn chunk voxels buffer
/// @param x chunk position X divided by CHUNK_W
/// @param z chunk position Y divided by CHUNK_D
/// @param seed world seed
virtual void generate(voxel* voxels, int x, int z, uint64_t seed);
virtual void generate(voxel* voxels, int x, int z);
inline static std::string DEFAULT = "core:default";
};