refactor WorldGenerator & update test generator script
This commit is contained in:
parent
f2395dede8
commit
f40ff7cd28
@ -19,7 +19,7 @@ biomes = {
|
||||
{block="base:stone", height=-1},
|
||||
{block="base:bazalt", height=1},
|
||||
},
|
||||
plant_chance = 0.5,
|
||||
plant_chance = 0.3,
|
||||
plants = {
|
||||
{block="base:grass", weight=1},
|
||||
{block="base:flower", weight=0.03},
|
||||
|
||||
@ -29,7 +29,8 @@ ChunksController::ChunksController(Level* level, uint padding)
|
||||
padding(padding),
|
||||
generator(std::make_unique<WorldGenerator>(
|
||||
level->content->generators.require(level->getWorld()->getGenerator()),
|
||||
level->content
|
||||
level->content,
|
||||
level->getWorld()->getSeed()
|
||||
)) {}
|
||||
|
||||
ChunksController::~ChunksController() = default;
|
||||
@ -116,7 +117,7 @@ void ChunksController::createChunk(int x, int z) {
|
||||
auto& chunkFlags = chunk->flags;
|
||||
|
||||
if (!chunkFlags.loaded) {
|
||||
generator->generate(chunk->voxels, x, z, level->getWorld()->getSeed());
|
||||
generator->generate(chunk->voxels, x, z);
|
||||
chunkFlags.unsaved = true;
|
||||
}
|
||||
chunk->updateHeights();
|
||||
|
||||
@ -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
|
||||
);
|
||||
|
||||
@ -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";
|
||||
};
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user