add ChunkPrototype
This commit is contained in:
@@ -16,7 +16,6 @@ WorldGenerator::WorldGenerator(
|
|||||||
const GeneratorDef& def, const Content* content, uint64_t seed
|
const GeneratorDef& def, const Content* content, uint64_t seed
|
||||||
)
|
)
|
||||||
: def(def), content(content), seed(seed) {
|
: def(def), content(content), seed(seed) {
|
||||||
voxel voxels[CHUNK_VOL];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void generate_pole(
|
static inline void generate_pole(
|
||||||
@@ -76,16 +75,31 @@ static inline const Biome* choose_biome(
|
|||||||
return chosenBiome;
|
return chosenBiome;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::unique_ptr<ChunkPrototype> WorldGenerator::generatePrototype(
|
||||||
|
int chunkX, int chunkZ
|
||||||
|
) {
|
||||||
|
timeutil::ScopeLogTimer log(666);
|
||||||
|
auto heightmap = def.script->generateHeightmap(
|
||||||
|
{chunkX * CHUNK_W, chunkZ * CHUNK_D}, {CHUNK_W, CHUNK_D}, seed);
|
||||||
|
auto biomeParams = def.script->generateParameterMaps(
|
||||||
|
{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);
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return std::make_unique<ChunkPrototype>(
|
||||||
|
std::move(heightmap), std::move(chunkBiomes));
|
||||||
|
}
|
||||||
|
|
||||||
void WorldGenerator::generate(voxel* voxels, int chunkX, int chunkZ) {
|
void WorldGenerator::generate(voxel* voxels, int chunkX, int chunkZ) {
|
||||||
// timeutil::ScopeLogTimer log(555);
|
// timeutil::ScopeLogTimer log(555);
|
||||||
auto heightmap = def.script->generateHeightmap(
|
|
||||||
{chunkX * CHUNK_W, chunkZ * CHUNK_D}, {CHUNK_W, CHUNK_D}, seed
|
auto prototype = generatePrototype(chunkX, chunkZ);
|
||||||
);
|
const auto values = prototype->heightmap->getValues();
|
||||||
auto biomeParams = def.script->generateParameterMaps(
|
|
||||||
{chunkX * CHUNK_W, chunkZ * CHUNK_D}, {CHUNK_W, CHUNK_D}, seed
|
|
||||||
);
|
|
||||||
auto values = heightmap->getValues();
|
|
||||||
const auto& biomes = def.script->getBiomes();
|
|
||||||
|
|
||||||
uint seaLevel = def.script->getSeaLevel();
|
uint seaLevel = def.script->getSeaLevel();
|
||||||
|
|
||||||
@@ -96,7 +110,7 @@ void WorldGenerator::generate(voxel* voxels, int chunkX, int chunkZ) {
|
|||||||
|
|
||||||
for (uint z = 0; z < CHUNK_D; z++) {
|
for (uint z = 0; z < CHUNK_D; z++) {
|
||||||
for (uint x = 0; x < CHUNK_W; x++) {
|
for (uint x = 0; x < CHUNK_W; x++) {
|
||||||
const Biome* biome = choose_biome(biomes, biomeParams, x, z);
|
const Biome* biome = prototype->biomes[z * CHUNK_W + x];
|
||||||
|
|
||||||
int height = values[z * CHUNK_W + x] * CHUNK_H;
|
int height = values[z * CHUNK_W + x] * CHUNK_H;
|
||||||
height = std::max(0, height);
|
height = std::max(0, height);
|
||||||
|
|||||||
@@ -2,19 +2,37 @@
|
|||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
#include "constants.hpp"
|
||||||
#include "typedefs.hpp"
|
#include "typedefs.hpp"
|
||||||
#include "voxels/voxel.hpp"
|
#include "voxels/voxel.hpp"
|
||||||
|
|
||||||
struct voxel;
|
|
||||||
class Content;
|
class Content;
|
||||||
struct GeneratorDef;
|
struct GeneratorDef;
|
||||||
|
class Heightmap;
|
||||||
|
struct Biome;
|
||||||
|
|
||||||
|
struct ChunkPrototype {
|
||||||
|
/// @brief chunk heightmap
|
||||||
|
std::shared_ptr<Heightmap> heightmap;
|
||||||
|
/// @brief chunk biomes matrix
|
||||||
|
std::vector<const Biome*> biomes;
|
||||||
|
|
||||||
|
ChunkPrototype(
|
||||||
|
std::shared_ptr<Heightmap> heightmap, std::vector<const Biome*> biomes
|
||||||
|
) : heightmap(std::move(heightmap)), biomes(std::move(biomes)) {};
|
||||||
|
};
|
||||||
|
|
||||||
/// @brief High-level world generation controller
|
/// @brief High-level world generation controller
|
||||||
class WorldGenerator {
|
class WorldGenerator {
|
||||||
const GeneratorDef& def;
|
const GeneratorDef& def;
|
||||||
const Content* content;
|
const Content* content;
|
||||||
uint64_t seed;
|
uint64_t seed;
|
||||||
|
|
||||||
|
std::vector<std::unique_ptr<ChunkPrototype>> chunks;
|
||||||
|
|
||||||
|
std::unique_ptr<ChunkPrototype> generatePrototype(int x, int z);
|
||||||
public:
|
public:
|
||||||
/// @param def generator definition
|
/// @param def generator definition
|
||||||
/// @param content world content
|
/// @param content world content
|
||||||
|
|||||||
Reference in New Issue
Block a user